Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upImplement element.innerText getter #19754
Conversation
highfive
commented
Jan 12, 2018
|
Heads up! This PR modifies the following files:
|
highfive
commented
Jan 12, 2018
|
Since I'd like to start learning about how layout works, I figured that I could get back to this implementation. I made some progress wrt my previous attempt, but I still couldn't figure out how to get the text fragments from each node's LayoutData. @mbrubeck , I would really appreciate if you could give me some pointers about how to get this data. Thank you in advance for your help! |
|
There are two types of text fragments: |
|
|
6143e93
to
4bee985
|
r? @mbrubeck There are still a bunch of tests failing and the tables stuff pending, but I think this is a start. |
| // https://html.spec.whatwg.org/multipage/#inner-text-collection-steps | ||
| #[allow(unsafe_code)] | ||
| fn inner_text_collection_steps<N: LayoutNode>(node: N, | ||
| display_list: &Option<Arc<DisplayList>>, |
This comment has been minimized.
This comment has been minimized.
emilio
Feb 12, 2018
Member
nit: Given you bail out here, you may as well bail out on the parent and get a &DisplayList here, right?
| // Step 4. | ||
| let opaque_child = child.opaque(); | ||
| for item in &display_list.as_ref().unwrap().list { | ||
| if item.base().metadata.node != opaque_child { |
This comment has been minimized.
This comment has been minimized.
emilio
Feb 12, 2018
Member
This looks... not great, this traverses the whole display list for the page for each text-node, right?
| continue; | ||
| } | ||
| match item { | ||
| &DisplayItem::Text(ref text) => { |
This comment has been minimized.
This comment has been minimized.
| } | ||
|
|
||
| fn is_block_level_or_table_caption(display: &Display) -> bool { | ||
| #[cfg(feature = "gecko")] |
This comment has been minimized.
This comment has been minimized.
| let style = window.GetComputedStyle(element, None); | ||
|
|
||
| // Step 1. | ||
| let element_not_rendered = !node.is_in_doc() || style.GetPropertyValue(DOMString::from("display")) == "none"; |
This comment has been minimized.
This comment has been minimized.
emilio
Feb 12, 2018
Member
nit: Please avoid using GetComputedStyle, use has_css_layout_box instead. This is completely bogus otherwise.
| let mut text = HashMap::new(); | ||
| for item in &display_list.as_ref().list { | ||
| if let &DisplayItem::Text(ref text_content) = item { | ||
| let entries = text.entry(&item.base().metadata.node).or_insert(Vec::new()); |
This comment has been minimized.
This comment has been minimized.
mbrubeck
Feb 12, 2018
Contributor
The bad news is that #20031 conflicts with this, because it moves the text out of the display list. The good news is that it should actually make it easier to query for the text of a node, because the text will already be in a HashMap, so you won't need to build one here...
|
@bors-servo r+ Approving this because it looks ready to land now. If it lands before #20031, then #20031 can resolve the conflict by making some fairly straightforward changes to the code that fetches text from the display list. If this doesn't manage to land right away and #20031 ends up landing first, then that conflict resolution will need to be done in this PR instead. |
|
|
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 -->
|
|
|
@bors-servo retry |
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 -->
|
|
|
There are two newly-passing subtests in /html/dom/interfaces.html:
|
|
@bors-servo delegate+ |
|
|
|
@bors-servo 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 -->
|
|
Upstreamed from servo/servo#19754 [ci skip]



ferjm commentedJan 12, 2018
•
edited by SimonSapin
This change is