mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Implement element.innerText setter
This commit is contained in:
parent
7945dff8ea
commit
d64bf623f6
4 changed files with 60 additions and 370 deletions
|
@ -17,10 +17,12 @@ use dom::bindings::root::{Dom, DomRoot, MutNullableDom, RootedReference};
|
|||
use dom::bindings::str::DOMString;
|
||||
use dom::cssstyledeclaration::{CSSModificationAccess, CSSStyleDeclaration, CSSStyleOwner};
|
||||
use dom::document::{Document, FocusType};
|
||||
use dom::documentfragment::DocumentFragment;
|
||||
use dom::domstringmap::DOMStringMap;
|
||||
use dom::element::{AttributeMutation, Element};
|
||||
use dom::eventtarget::EventTarget;
|
||||
use dom::htmlbodyelement::HTMLBodyElement;
|
||||
use dom::htmlbrelement::HTMLBRElement;
|
||||
use dom::htmlframesetelement::HTMLFrameSetElement;
|
||||
use dom::htmlhtmlelement::HTMLHtmlElement;
|
||||
use dom::htmlinputelement::{HTMLInputElement, InputType};
|
||||
|
@ -28,6 +30,7 @@ use dom::htmllabelelement::HTMLLabelElement;
|
|||
use dom::node::{Node, NodeFlags};
|
||||
use dom::node::{document_from_node, window_from_node};
|
||||
use dom::nodelist::NodeList;
|
||||
use dom::text::Text;
|
||||
use dom::virtualmethods::VirtualMethods;
|
||||
use dom::window::ReflowReason;
|
||||
use dom_struct::dom_struct;
|
||||
|
@ -421,9 +424,62 @@ impl HTMLElementMethods for HTMLElement {
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#the-innertext-idl-attribute
|
||||
fn SetInnerText(&self, _: DOMString) {
|
||||
// XXX (ferjm) implement this.
|
||||
fn SetInnerText(&self, input: DOMString) {
|
||||
// Step 1.
|
||||
let document = document_from_node(self);
|
||||
|
||||
// Step 2.
|
||||
let fragment = DocumentFragment::new(&document);
|
||||
|
||||
// Step 3. The given value is already named 'input'.
|
||||
|
||||
// Step 4.
|
||||
let mut position = input.chars().peekable();
|
||||
|
||||
// Step 5.
|
||||
let mut text = String::new();
|
||||
|
||||
// Step 6.
|
||||
while let Some(ch) = position.next() {
|
||||
match ch {
|
||||
'\u{000A}' | '\u{000D}' => {
|
||||
if ch == '\u{000D}' && position.peek() == Some(&'\u{000A}') {
|
||||
// a \r\n pair should only generate one <br>,
|
||||
// so just skip the \r.
|
||||
position.next();
|
||||
}
|
||||
|
||||
if !text.is_empty() {
|
||||
append_text_node_to_fragment(&document, &fragment, text);
|
||||
text = String::new();
|
||||
}
|
||||
|
||||
let br = HTMLBRElement::new(local_name!("br"), None, &document);
|
||||
fragment.upcast::<Node>().AppendChild(&br.upcast()).unwrap();
|
||||
},
|
||||
_ => {
|
||||
text.push(ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !text.is_empty() {
|
||||
append_text_node_to_fragment(&document, &fragment, text);
|
||||
}
|
||||
|
||||
// Step 7.
|
||||
Node::replace_all(Some(fragment.upcast()), self.upcast::<Node>());
|
||||
}
|
||||
}
|
||||
|
||||
fn append_text_node_to_fragment(
|
||||
document: &Document,
|
||||
fragment: &DocumentFragment,
|
||||
text: String
|
||||
) {
|
||||
let text = Text::new(DOMString::from(text), document);
|
||||
let node = DomRoot::upcast::<Node>(text);
|
||||
fragment.upcast::<Node>().AppendChild(&node).unwrap();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#attr-data-*
|
||||
|
|
|
@ -564479,7 +564479,7 @@
|
|||
"support"
|
||||
],
|
||||
"innerText/setter.html": [
|
||||
"6a9362dc28615ae2667131e44fcdb2589f87d9d2",
|
||||
"8e78f2b7641a609b692a55ad8f4979dd852b706c",
|
||||
"testharness"
|
||||
],
|
||||
"input-events/OWNERS": [
|
||||
|
|
|
@ -1,367 +0,0 @@
|
|||
[setter.html]
|
||||
[Simplest possible test]
|
||||
expected: FAIL
|
||||
|
||||
[Simplest possible test, detached]
|
||||
expected: FAIL
|
||||
|
||||
[Newlines convert to <br> in non-white-space:pre elements]
|
||||
expected: FAIL
|
||||
|
||||
[Newlines convert to <br> in non-white-space:pre elements, detached]
|
||||
expected: FAIL
|
||||
|
||||
[Newlines convert to <br> in <pre> element]
|
||||
expected: FAIL
|
||||
|
||||
[Newlines convert to <br> in <pre> element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[Newlines convert to <br> in <textarea> element]
|
||||
expected: FAIL
|
||||
|
||||
[Newlines convert to <br> in <textarea> element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[Newlines convert to <br> in white-space:pre element]
|
||||
expected: FAIL
|
||||
|
||||
[Newlines convert to <br> in white-space:pre element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[CRs convert to <br> in non-white-space:pre elements]
|
||||
expected: FAIL
|
||||
|
||||
[CRs convert to <br> in non-white-space:pre elements, detached]
|
||||
expected: FAIL
|
||||
|
||||
[CRs convert to <br> in <pre> element]
|
||||
expected: FAIL
|
||||
|
||||
[CRs convert to <br> in <pre> element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[Newline/CR pair converts to <br> in non-white-space:pre element]
|
||||
expected: FAIL
|
||||
|
||||
[Newline/CR pair converts to <br> in non-white-space:pre element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[Newline/newline pair converts to two <br>s in non-white-space:pre element]
|
||||
expected: FAIL
|
||||
|
||||
[Newline/newline pair converts to two <br>s in non-white-space:pre element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[CR/CR pair converts to two <br>s in non-white-space:pre element]
|
||||
expected: FAIL
|
||||
|
||||
[CR/CR pair converts to two <br>s in non-white-space:pre element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[CRs convert to <br> in white-space:pre element]
|
||||
expected: FAIL
|
||||
|
||||
[CRs convert to <br> in white-space:pre element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[< preserved]
|
||||
expected: FAIL
|
||||
|
||||
[< preserved, detached]
|
||||
expected: FAIL
|
||||
|
||||
[> preserved]
|
||||
expected: FAIL
|
||||
|
||||
[> preserved, detached]
|
||||
expected: FAIL
|
||||
|
||||
[& preserved]
|
||||
expected: FAIL
|
||||
|
||||
[& preserved, detached]
|
||||
expected: FAIL
|
||||
|
||||
[" preserved]
|
||||
expected: FAIL
|
||||
|
||||
[" preserved, detached]
|
||||
expected: FAIL
|
||||
|
||||
[' preserved]
|
||||
expected: FAIL
|
||||
|
||||
[' preserved, detached]
|
||||
expected: FAIL
|
||||
|
||||
[innerText not supported on SVG elements]
|
||||
expected: FAIL
|
||||
|
||||
[innerText not supported on MathML elements]
|
||||
expected: FAIL
|
||||
|
||||
[Null characters preserved]
|
||||
expected: FAIL
|
||||
|
||||
[Null characters preserved, detached]
|
||||
expected: FAIL
|
||||
|
||||
[Tabs preserved]
|
||||
expected: FAIL
|
||||
|
||||
[Tabs preserved, detached]
|
||||
expected: FAIL
|
||||
|
||||
[Leading whitespace preserved]
|
||||
expected: FAIL
|
||||
|
||||
[Leading whitespace preserved, detached]
|
||||
expected: FAIL
|
||||
|
||||
[Trailing whitespace preserved]
|
||||
expected: FAIL
|
||||
|
||||
[Trailing whitespace preserved, detached]
|
||||
expected: FAIL
|
||||
|
||||
[Whitespace not compressed]
|
||||
expected: FAIL
|
||||
|
||||
[Whitespace not compressed, detached]
|
||||
expected: FAIL
|
||||
|
||||
[Existing text deleted]
|
||||
expected: FAIL
|
||||
|
||||
[Existing text deleted, detached]
|
||||
expected: FAIL
|
||||
|
||||
[Existing <br> deleted]
|
||||
expected: FAIL
|
||||
|
||||
[Existing <br> deleted, detached]
|
||||
expected: FAIL
|
||||
|
||||
[Assigning the empty string]
|
||||
expected: FAIL
|
||||
|
||||
[Assigning null]
|
||||
expected: FAIL
|
||||
|
||||
[Assigning undefined]
|
||||
expected: FAIL
|
||||
|
||||
[Assigning undefined, detached]
|
||||
expected: FAIL
|
||||
|
||||
[Start with CR]
|
||||
expected: FAIL
|
||||
|
||||
[Start with CR, detached]
|
||||
expected: FAIL
|
||||
|
||||
[Start with LF]
|
||||
expected: FAIL
|
||||
|
||||
[Start with LF, detached]
|
||||
expected: FAIL
|
||||
|
||||
[Start with CRLF]
|
||||
expected: FAIL
|
||||
|
||||
[Start with CRLF, detached]
|
||||
expected: FAIL
|
||||
|
||||
[End with CR]
|
||||
expected: FAIL
|
||||
|
||||
[End with CR, detached]
|
||||
expected: FAIL
|
||||
|
||||
[End with LF]
|
||||
expected: FAIL
|
||||
|
||||
[End with LF, detached]
|
||||
expected: FAIL
|
||||
|
||||
[End with CRLF]
|
||||
expected: FAIL
|
||||
|
||||
[End with CRLF, detached]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <area> element]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <area> element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <base> element]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <base> element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <basefont> element]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <basefont> element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <bgsound> element]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <bgsound> element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <br> element]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <br> element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <col> element]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <col> element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <embed> element]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <embed> element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <frame> element]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <frame> element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <hr> element]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <hr> element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <image> element]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <image> element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <img> element]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <img> element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <input> element]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <input> element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <keygen> element]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <keygen> element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <link> element]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <link> element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <menuitem> element]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <menuitem> element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <meta> element]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <meta> element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <param> element]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <param> element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <source> element]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <source> element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <track> element]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <track> element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <wbr> element]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <wbr> element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <colgroup> element]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <colgroup> element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <frameset> element]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <frameset> element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <head> element]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <head> element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <html> element]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <html> element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <table> element]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <table> element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <tbody> element]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <tbody> element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <tfoot> element]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <tfoot> element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <thead> element]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <thead> element, detached]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <tr> element]
|
||||
expected: FAIL
|
||||
|
||||
[innerText on <tr> element, detached]
|
||||
expected: FAIL
|
||||
|
|
@ -9,6 +9,7 @@
|
|||
// tests a not-rendered case.
|
||||
|
||||
function setupTest(context, plain) {
|
||||
var container = document.getElementById("container");
|
||||
// context is either a string or an element node
|
||||
if (typeof context === "string") {
|
||||
container.innerHTML = context;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue