aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeongeun Kim <je_julie.kim@samsung.com>2014-09-16 21:46:17 +0900
committerJeongeun Kim <je_julie.kim@samsung.com>2014-09-20 23:49:20 +0900
commitdad77f0d2525834f2490b0ea4be12817a55865d2 (patch)
treeb5d83385857e64e791c7a02f58425f605b9f85bc
parent249638da8f01a66b98be857fba7755c8625480f5 (diff)
downloadservo-dad77f0d2525834f2490b0ea4be12817a55865d2.tar.gz
servo-dad77f0d2525834f2490b0ea4be12817a55865d2.zip
Implement HTMLOptionElement.text#3023
Signed-off-by: Jeongeun Kim <je00julie.kim@gmail.com> Implement HTMLOptionElement.text#3023 (2nd trial) Implement HTMLOptionElement.text#3023 (3rd trial) delete metadata for skipping option tests fix conflict
-rw-r--r--components/script/dom/htmloptionelement.rs44
-rw-r--r--components/script/dom/webidls/HTMLOptionElement.webidl2
-rw-r--r--tests/wpt/metadata/html/semantics/forms/the-option-element/option-text-backslash.html.ini5
-rw-r--r--tests/wpt/metadata/html/semantics/forms/the-option-element/option-text-recurse.html.ini29
-rw-r--r--tests/wpt/metadata/html/semantics/forms/the-option-element/option-text-spaces.html.ini149
5 files changed, 42 insertions, 187 deletions
diff --git a/components/script/dom/htmloptionelement.rs b/components/script/dom/htmloptionelement.rs
index bb40b4c5b7c..4cfaa96daa0 100644
--- a/components/script/dom/htmloptionelement.rs
+++ b/components/script/dom/htmloptionelement.rs
@@ -2,12 +2,16 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+use dom::bindings::codegen::Bindings::CharacterDataBinding::CharacterDataMethods;
use dom::bindings::codegen::Bindings::HTMLOptionElementBinding;
use dom::bindings::codegen::Bindings::HTMLOptionElementBinding::HTMLOptionElementMethods;
-use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, NodeCast};
-use dom::bindings::codegen::InheritTypes::HTMLOptionElementDerived;
+use dom::bindings::codegen::InheritTypes::{CharacterDataCast, ElementCast, HTMLElementCast, NodeCast};
+use dom::bindings::codegen::InheritTypes::{HTMLOptionElementDerived};
+use dom::bindings::codegen::InheritTypes::{HTMLScriptElementDerived};
+use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector};
+use dom::characterdata::CharacterData;
use dom::document::Document;
use dom::element::{AttributeHandlers, Element, HTMLOptionElementTypeId};
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
@@ -16,7 +20,8 @@ use dom::node::{DisabledStateHelpers, Node, NodeHelpers, ElementNodeTypeId};
use dom::virtualmethods::VirtualMethods;
use servo_util::atom::Atom;
-use servo_util::str::DOMString;
+use servo_util::namespace;
+use servo_util::str::{DOMString, split_html_space_chars};
#[deriving(Encodable)]
#[must_root]
@@ -44,6 +49,24 @@ impl HTMLOptionElement {
}
}
+fn collect_text(node: &JSRef<Node>, value: &mut DOMString) {
+ let elem: JSRef<Element> = ElementCast::to_ref(*node).unwrap();
+ let svg_script = elem.namespace == namespace::SVG && elem.local_name.as_slice() == "script";
+ let html_script = node.is_htmlscriptelement();
+ if svg_script || html_script {
+ return;
+ } else {
+ for child in node.children() {
+ if child.is_text() {
+ let characterdata: JSRef<CharacterData> = CharacterDataCast::to_ref(child).unwrap();
+ value.push_str(characterdata.Data().as_slice());
+ } else {
+ collect_text(&child, value);
+ }
+ }
+ }
+}
+
impl<'a> HTMLOptionElementMethods for JSRef<'a, HTMLOptionElement> {
// http://www.whatwg.org/html/#dom-option-disabled
make_bool_getter!(Disabled)
@@ -53,6 +76,21 @@ impl<'a> HTMLOptionElementMethods for JSRef<'a, HTMLOptionElement> {
let elem: JSRef<Element> = ElementCast::from_ref(*self);
elem.set_bool_attribute("disabled", disabled)
}
+
+ // http://www.whatwg.org/html/#dom-option-text
+ fn Text(&self) -> DOMString {
+ let node: JSRef<Node> = NodeCast::from_ref(*self);
+ let mut content = String::new();
+ collect_text(&node, &mut content);
+ let v: Vec<&str> = split_html_space_chars(content.as_slice()).collect();
+ v.connect(" ")
+ }
+
+ // http://www.whatwg.org/html/#dom-option-text
+ fn SetText(&self, value: DOMString) {
+ let node: JSRef<Node> = NodeCast::from_ref(*self);
+ node.SetTextContent(Some(value))
+ }
}
impl<'a> VirtualMethods for JSRef<'a, HTMLOptionElement> {
diff --git a/components/script/dom/webidls/HTMLOptionElement.webidl b/components/script/dom/webidls/HTMLOptionElement.webidl
index 7855449c6f4..5c3f4b37f6a 100644
--- a/components/script/dom/webidls/HTMLOptionElement.webidl
+++ b/components/script/dom/webidls/HTMLOptionElement.webidl
@@ -13,6 +13,6 @@ interface HTMLOptionElement : HTMLElement {
// attribute boolean selected;
// attribute DOMString value;
- // attribute DOMString text;
+ attribute DOMString text;
//readonly attribute long index;
};
diff --git a/tests/wpt/metadata/html/semantics/forms/the-option-element/option-text-backslash.html.ini b/tests/wpt/metadata/html/semantics/forms/the-option-element/option-text-backslash.html.ini
deleted file mode 100644
index 274d48a2be5..00000000000
--- a/tests/wpt/metadata/html/semantics/forms/the-option-element/option-text-backslash.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[option-text-backslash.html]
- type: testharness
- [Test for the backslash sign in option.text]
- expected: FAIL
-
diff --git a/tests/wpt/metadata/html/semantics/forms/the-option-element/option-text-recurse.html.ini b/tests/wpt/metadata/html/semantics/forms/the-option-element/option-text-recurse.html.ini
deleted file mode 100644
index 1a1061185b5..00000000000
--- a/tests/wpt/metadata/html/semantics/forms/the-option-element/option-text-recurse.html.ini
+++ /dev/null
@@ -1,29 +0,0 @@
-[option-text-recurse.html]
- type: testharness
- [option.text should recurse]
- expected: FAIL
-
- [option.text should not recurse into HTML script elements]
- expected: FAIL
-
- [option.text should not recurse into SVG script elements]
- expected: FAIL
-
- [option.text should recurse into MathML script elements]
- expected: FAIL
-
- [option.text should recurse into null script elements]
- expected: FAIL
-
- [option.text should work if a child of the option ends with a script]
- expected: FAIL
-
- [option.text should work if the option is in an HTML script element]
- expected: FAIL
-
- [option.text should work if the option is in an SVG script element]
- expected: FAIL
-
- [option.text should work if the option is in a MathML script element]
- expected: FAIL
-
diff --git a/tests/wpt/metadata/html/semantics/forms/the-option-element/option-text-spaces.html.ini b/tests/wpt/metadata/html/semantics/forms/the-option-element/option-text-spaces.html.ini
deleted file mode 100644
index 78c1fb81f5e..00000000000
--- a/tests/wpt/metadata/html/semantics/forms/the-option-element/option-text-spaces.html.ini
+++ /dev/null
@@ -1,149 +0,0 @@
-[option-text-spaces.html]
- type: testharness
- [option.text should strip leading space characters (" ")]
- expected: FAIL
-
- [option.text should strip leading space characters ("\\t")]
- expected: FAIL
-
- [option.text should strip leading space characters ("\\n")]
- expected: FAIL
-
- [option.text should strip leading space characters ("\\f")]
- expected: FAIL
-
- [option.text should strip leading space characters ("\\r")]
- expected: FAIL
-
- [option.text should strip trailing space characters (" ")]
- expected: FAIL
-
- [option.text should strip trailing space characters ("\\t")]
- expected: FAIL
-
- [option.text should strip trailing space characters ("\\n")]
- expected: FAIL
-
- [option.text should strip trailing space characters ("\\f")]
- expected: FAIL
-
- [option.text should strip trailing space characters ("\\r")]
- expected: FAIL
-
- [option.text should strip leading and trailing space characters (" ")]
- expected: FAIL
-
- [option.text should strip leading and trailing space characters ("\\t")]
- expected: FAIL
-
- [option.text should strip leading and trailing space characters ("\\n")]
- expected: FAIL
-
- [option.text should strip leading and trailing space characters ("\\f")]
- expected: FAIL
-
- [option.text should strip leading and trailing space characters ("\\r")]
- expected: FAIL
-
- [option.text should replace single internal space characters (" ")]
- expected: FAIL
-
- [option.text should replace single internal space characters ("\\t")]
- expected: FAIL
-
- [option.text should replace single internal space characters ("\\n")]
- expected: FAIL
-
- [option.text should replace single internal space characters ("\\f")]
- expected: FAIL
-
- [option.text should replace single internal space characters ("\\r")]
- expected: FAIL
-
- [option.text should replace multiple internal space characters (" ", " ")]
- expected: FAIL
-
- [option.text should replace multiple internal space characters (" ", "\\t")]
- expected: FAIL
-
- [option.text should replace multiple internal space characters (" ", "\\n")]
- expected: FAIL
-
- [option.text should replace multiple internal space characters (" ", "\\f")]
- expected: FAIL
-
- [option.text should replace multiple internal space characters (" ", "\\r")]
- expected: FAIL
-
- [option.text should replace multiple internal space characters ("\\t", " ")]
- expected: FAIL
-
- [option.text should replace multiple internal space characters ("\\t", "\\t")]
- expected: FAIL
-
- [option.text should replace multiple internal space characters ("\\t", "\\n")]
- expected: FAIL
-
- [option.text should replace multiple internal space characters ("\\t", "\\f")]
- expected: FAIL
-
- [option.text should replace multiple internal space characters ("\\t", "\\r")]
- expected: FAIL
-
- [option.text should replace multiple internal space characters ("\\n", " ")]
- expected: FAIL
-
- [option.text should replace multiple internal space characters ("\\n", "\\t")]
- expected: FAIL
-
- [option.text should replace multiple internal space characters ("\\n", "\\n")]
- expected: FAIL
-
- [option.text should replace multiple internal space characters ("\\n", "\\f")]
- expected: FAIL
-
- [option.text should replace multiple internal space characters ("\\n", "\\r")]
- expected: FAIL
-
- [option.text should replace multiple internal space characters ("\\f", " ")]
- expected: FAIL
-
- [option.text should replace multiple internal space characters ("\\f", "\\t")]
- expected: FAIL
-
- [option.text should replace multiple internal space characters ("\\f", "\\n")]
- expected: FAIL
-
- [option.text should replace multiple internal space characters ("\\f", "\\f")]
- expected: FAIL
-
- [option.text should replace multiple internal space characters ("\\f", "\\r")]
- expected: FAIL
-
- [option.text should replace multiple internal space characters ("\\r", " ")]
- expected: FAIL
-
- [option.text should replace multiple internal space characters ("\\r", "\\t")]
- expected: FAIL
-
- [option.text should replace multiple internal space characters ("\\r", "\\n")]
- expected: FAIL
-
- [option.text should replace multiple internal space characters ("\\r", "\\f")]
- expected: FAIL
-
- [option.text should replace multiple internal space characters ("\\r", "\\r")]
- expected: FAIL
-
- [option.text should leave leading NBSP alone.]
- expected: FAIL
-
- [option.text should leave trailing NBSP alone.]
- expected: FAIL
-
- [option.text should leave a single internal NBSP alone.]
- expected: FAIL
-
- [option.text should leave two internal NBSPs alone.]
- expected: FAIL
-