diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2018-02-13 03:41:48 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-13 03:41:48 -0500 |
commit | 9e64008e759a678a3971d04977c2b20b66fa8229 (patch) | |
tree | 9f996cd73fbd35d1802899ac82f208c2806b5a69 /components/script | |
parent | 3d6ce6c36aab3229929db3d49a8fec94dcf16f66 (diff) | |
parent | 2a4535f43e5566a9773ed9a31931e8ec9523a22b (diff) | |
download | servo-9e64008e759a678a3971d04977c2b20b66fa8229.tar.gz servo-9e64008e759a678a3971d04977c2b20b66fa8229.zip |
Auto merge of #19754 - ferjm:innertext, r=mbrubeck
Implement element.innerText getter
<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19754)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script')
-rw-r--r-- | components/script/dom/element.rs | 2 | ||||
-rw-r--r-- | components/script/dom/htmlelement.rs | 24 | ||||
-rw-r--r-- | components/script/dom/node.rs | 4 | ||||
-rw-r--r-- | components/script/dom/webidls/HTMLElement.webidl | 2 | ||||
-rw-r--r-- | components/script/dom/window.rs | 1 |
5 files changed, 32 insertions, 1 deletions
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index ad050be3dda..9c88c1391fd 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -357,7 +357,7 @@ impl Element { } // https://drafts.csswg.org/cssom-view/#css-layout-box - fn has_css_layout_box(&self) -> bool { + pub fn has_css_layout_box(&self) -> bool { self.style() .map_or(false, |s| !s.get_box().clone_display().is_none()) } diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs index 89b0c0d9de2..ec9b3973ca1 100644 --- a/components/script/dom/htmlelement.rs +++ b/components/script/dom/htmlelement.rs @@ -8,6 +8,7 @@ use dom::bindings::codegen::Bindings::ElementBinding::ElementMethods; use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull; use dom::bindings::codegen::Bindings::HTMLElementBinding; use dom::bindings::codegen::Bindings::HTMLElementBinding::HTMLElementMethods; +use dom::bindings::codegen::Bindings::NodeBinding::NodeBinding::NodeMethods; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; use dom::bindings::error::{Error, ErrorResult}; use dom::bindings::inheritance::{ElementTypeId, HTMLElementTypeId, NodeTypeId}; @@ -28,8 +29,10 @@ use dom::node::{Node, NodeFlags}; use dom::node::{document_from_node, window_from_node}; use dom::nodelist::NodeList; use dom::virtualmethods::VirtualMethods; +use dom::window::ReflowReason; use dom_struct::dom_struct; use html5ever::{LocalName, Prefix}; +use script_layout_interface::message::ReflowGoal; use std::collections::HashSet; use std::default::Default; use std::rc::Rc; @@ -400,6 +403,27 @@ impl HTMLElementMethods for HTMLElement { rect.size.height.to_nearest_px() } + + // https://html.spec.whatwg.org/multipage/#the-innertext-idl-attribute + fn InnerText(&self) -> DOMString { + let node = self.upcast::<Node>(); + let window = window_from_node(node); + let element = self.upcast::<Element>(); + + // Step 1. + let element_not_rendered = !node.is_in_doc() || !element.has_css_layout_box(); + if element_not_rendered { + return node.GetTextContent().unwrap(); + } + + window.reflow(ReflowGoal::ElementInnerTextQuery(node.to_trusted_node_address()), ReflowReason::Query); + DOMString::from(window.layout().element_inner_text()) + } + + // https://html.spec.whatwg.org/multipage/#the-innertext-idl-attribute + fn SetInnerText(&self, _: DOMString) { + // XXX (ferjm) implement this. + } } // https://html.spec.whatwg.org/multipage/#attr-data-* diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index ce97cb1ee4b..64b808c3859 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -2741,6 +2741,8 @@ impl Into<LayoutElementType> for ElementTypeId { #[inline(always)] fn into(self) -> LayoutElementType { match self { + ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLBRElement) => + LayoutElementType::HTMLBRElement, ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLCanvasElement) => LayoutElementType::HTMLCanvasElement, ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLIFrameElement) => @@ -2751,6 +2753,8 @@ impl Into<LayoutElementType> for ElementTypeId { LayoutElementType::HTMLInputElement, ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLObjectElement) => LayoutElementType::HTMLObjectElement, + ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLParagraphElement) => + LayoutElementType::HTMLParagraphElement, ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTableCellElement(_)) => LayoutElementType::HTMLTableCellElement, ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTableColElement) => diff --git a/components/script/dom/webidls/HTMLElement.webidl b/components/script/dom/webidls/HTMLElement.webidl index 7c1b0d62c21..a007a93e6b3 100644 --- a/components/script/dom/webidls/HTMLElement.webidl +++ b/components/script/dom/webidls/HTMLElement.webidl @@ -46,6 +46,8 @@ interface HTMLElement : Element { // attribute boolean spellcheck; // void forceSpellCheck(); + [TreatNullAs=EmptyString] attribute DOMString innerText; + // command API // readonly attribute DOMString? commandType; // readonly attribute DOMString? commandLabel; diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index c92a04c7cd4..c9765b18253 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -1898,6 +1898,7 @@ fn debug_reflow_events(id: PipelineId, reflow_goal: &ReflowGoal, reason: &Reflow ReflowGoal::StyleQuery(_n) => "\tStyleQuery", ReflowGoal::TextIndexQuery(..) => "\tTextIndexQuery", ReflowGoal::TickAnimations => "\tTickAnimations", + ReflowGoal::ElementInnerTextQuery(_) => "\tElementInnerTextQuery", }); debug_msg.push_str(match *reason { |