Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement element.innerText getter #19754

Merged
merged 1 commit into from Feb 13, 2018
Merged

Implement element.innerText getter #19754

merged 1 commit into from Feb 13, 2018

Conversation

@ferjm
Copy link
Member

ferjm commented Jan 12, 2018

This change is Reviewable

@highfive
Copy link

highfive commented Jan 12, 2018

Heads up! This PR modifies the following files:

  • @asajeffrey: components/script/dom/webidls/HTMLElement.webidl, components/script/dom/node.rs, components/script/dom/htmlelement.rs, components/script/dom/window.rs
  • @KiChjang: components/script/dom/webidls/HTMLElement.webidl, components/script/dom/node.rs, components/script/dom/htmlelement.rs, components/script/dom/window.rs
  • @fitzgen: components/script/dom/webidls/HTMLElement.webidl, components/script/dom/node.rs, components/script/dom/htmlelement.rs, components/script/dom/window.rs
  • @emilio: components/layout/query.rs
@highfive
Copy link

highfive commented Jan 12, 2018

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!
  • These commits modify layout and script code, but no tests are modified. Please consider adding a test!
@ferjm
Copy link
Member Author

ferjm 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!

@mbrubeck
Copy link
Contributor

mbrubeck commented Jan 12, 2018

There are two types of text fragments: UnscannedText and ScannedText, which are created at different points during flow construction. The ScannedText fragments are transformed based
are transformed based on the white-space and text-transform styles, so I think they are what you want to access here. Unfortunately the ConstructionResult will only contain the initial unscanned text fragments, so we'll need to find a different way to access the scanned text. I'm still investigating how to do this...

@bors-servo
Copy link
Contributor

bors-servo commented Jan 28, 2018

The latest upstream changes (presumably #19881) made this pull request unmergeable. Please resolve the merge conflicts.

@ferjm ferjm force-pushed the ferjm:innertext branch from bcbb647 to ed9ce2c Feb 8, 2018
@ferjm
Copy link
Member Author

ferjm commented Feb 8, 2018

I made some progress here. Instead of trying to get the text from the node's LayoutData I got it from the display list. The result is still not the expected one, but at least I am able to show some text now.

Servo:
screen shot 2018-02-08 at 18 46 45

Firefox (showing expected output):
screen shot 2018-02-08 at 18 46 55

@ferjm ferjm force-pushed the ferjm:innertext branch from ed9ce2c to 0ec7438 Feb 9, 2018
@ferjm
Copy link
Member Author

ferjm commented Feb 9, 2018

Looking better now:

81e32e99476a2149e4b83d9f08b06a00

@jdm jdm removed the S-needs-rebase label Feb 9, 2018
@ferjm ferjm force-pushed the ferjm:innertext branch 2 times, most recently from 6143e93 to 4bee985 Feb 12, 2018
@ferjm
Copy link
Member Author

ferjm commented Feb 12, 2018

r? @mbrubeck

There are still a bunch of tests failing and the tables stuff pending, but I think this is a start.

@highfive highfive assigned mbrubeck and unassigned emilio Feb 12, 2018
@ferjm ferjm changed the title WIP - Implement element.innerText getter Implement element.innerText getter Feb 12, 2018
// 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.

Copy link
@emilio

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.

Copy link
@emilio

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.

Copy link
@emilio

emilio Feb 12, 2018

Member

nit: if let.

}

fn is_block_level_or_table_caption(display: &Display) -> bool {
#[cfg(feature = "gecko")]

This comment has been minimized.

Copy link
@emilio

emilio Feb 12, 2018

Member

nit: No need for feature = "gecko" stuff on layout.

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.

Copy link
@emilio

emilio Feb 12, 2018

Member

nit: Please avoid using GetComputedStyle, use has_css_layout_box instead. This is completely bogus otherwise.

@ferjm ferjm force-pushed the ferjm:innertext branch from 4bee985 to d988c3d Feb 12, 2018
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.

Copy link
@mbrubeck

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...

@mbrubeck
Copy link
Contributor

mbrubeck commented Feb 12, 2018

@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.

@bors-servo
Copy link
Contributor

bors-servo commented Feb 12, 2018

📌 Commit d988c3d has been approved by mbrubeck

@bors-servo
Copy link
Contributor

bors-servo commented Feb 12, 2018

Testing commit d988c3d with merge 08a4ea4...

bors-servo added a commit that referenced this pull request Feb 12, 2018
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
Copy link
Contributor

bors-servo commented Feb 12, 2018

💔 Test failed - mac-rel-wpt3

@ferjm
Copy link
Member Author

ferjm commented Feb 12, 2018

@bors-servo retry

@bors-servo
Copy link
Contributor

bors-servo commented Feb 12, 2018

Testing commit d279bac with merge 1aaa309...

bors-servo added a commit that referenced this pull request Feb 12, 2018
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
Copy link
Contributor

bors-servo commented Feb 12, 2018

💔 Test failed - linux-rel-wpt

@mbrubeck
Copy link
Contributor

mbrubeck commented Feb 13, 2018

There are two newly-passing subtests in /html/dom/interfaces.html:

{"status": "PASS", "group": "default", "message": null, "stack": null, "subtest": "HTMLElement interface: attribute innerText", "test": "/html/dom/interfaces.html", "line": 27384, "action": "test_result", "expected": "FAIL"}
{"status": "PASS", "group": "default", "message": null, "stack": null, "subtest": "HTMLElement interface: document.createElement(\"noscript\") must inherit property \"innerText\" with the proper type", "test": "/html/dom/interfaces.html", "line": 27470, "action": "test_result", "expected": "FAIL"}
@ferjm ferjm force-pushed the ferjm:innertext branch from d279bac to 2a4535f Feb 13, 2018
@emilio
Copy link
Member

emilio commented Feb 13, 2018

@bors-servo delegate+

@bors-servo
Copy link
Contributor

bors-servo commented Feb 13, 2018

✌️ @ferjm can now approve this pull request

@ferjm
Copy link
Member Author

ferjm commented Feb 13, 2018

@bors-servo r=mbrubeck

@bors-servo
Copy link
Contributor

bors-servo commented Feb 13, 2018

📌 Commit 2a4535f has been approved by mbrubeck

@bors-servo
Copy link
Contributor

bors-servo commented Feb 13, 2018

Testing commit 2a4535f with merge 9e64008...

bors-servo added a commit that referenced this pull request Feb 13, 2018
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
Copy link
Contributor

bors-servo commented Feb 13, 2018

@bors-servo bors-servo merged commit 2a4535f into servo:master Feb 13, 2018
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@ferjm ferjm deleted the ferjm:innertext branch Feb 13, 2018
jdm added a commit to web-platform-tests/wpt that referenced this pull request Feb 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants
You can’t perform that action at this time.