Skip to content

Further changes in relation to #19171 - #19272

Merged
bors-servo merged 2 commits into
servo:masterfrom
jonleighton:issue-19171-2
Nov 21, 2017
Merged

bors-servo merged 2 commits into
servo:masterfrom
jonleighton:issue-19171-2

Conversation

@jonleighton

@jonleighton jonleighton commented Nov 17, 2017 •

Copy link
Copy Markdown
Contributor

This change is Reviewable

@highfive

Copy link
Copy Markdown

Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @asajeffrey (or someone else) soon.

@highfive

Copy link
Copy Markdown

Heads up! This PR modifies the following files:

  • @fitzgen: components/script/dom/htmltextareaelement.rs, components/script/dom/textcontrol.rs, components/script/dom/mod.rs, components/script/dom/htmlinputelement.rs
  • @KiChjang: components/script/dom/htmltextareaelement.rs, components/script/dom/textcontrol.rs, components/script/dom/mod.rs, components/script/dom/htmlinputelement.rs

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Nov 17, 2017
@jonleighton

Copy link
Copy Markdown
Contributor Author

r? @KiChjang

@highfive highfive assigned KiChjang and unassigned asajeffrey Nov 17, 2017
@jonleighton

Copy link
Copy Markdown
Contributor Author

I don't know if this TextControl trait is the right abstraction, so feedback on that front is very welcome. It kind of annoys me that now there's lots of boilerplate code to call in to the methods defined by TextControl.

@KiChjang

Copy link
Copy Markdown
Contributor

This is a larger change than I expected, and I'm not comfortable reviewing this. r? @jdm

@highfive highfive assigned jdm and unassigned KiChjang Nov 17, 2017
@jdm jdm added the S-fails-tidy `./mach test-tidy` reported errors. label Nov 17, 2017

@jdm jdm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a sensible solution. The only other abstraction I came up with is free functions that accept the textinput as an argument, rather than putting them all in a trait, but I don't see a compelling reason to use that design instead.

}, "Sanity check for testValue length; if this fails, variou absolute offsets in the test below need to be adjusted to be less than testValue.length");

for (let prop of ["selectionStart", "selectionEnd"]) {
test(function() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This outer test is not necessary.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I thought that maybe it was a bad idea to call createTestElements outside of a test, but perhaps it doesn't actually matter.

@jdm jdm added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Nov 17, 2017
@jdm

jdm commented Nov 17, 2017

Copy link
Copy Markdown
Member

Also ./mach test-tidy fails with these changes.


// https://html.spec.whatwg.org/multipage/#dom-textarea/input-selectionstart
fn dom_selection_start(&self) -> u32 {
self.textinput().borrow().get_selection_start()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I mentioned that whether the selection{Start, End, Range} functions matches the spec, I meant whether they are following the steps as defined in the spec. This function in particular does not seem to have included step 1 and 2.

@KiChjang

Copy link
Copy Markdown
Contributor

Also, may I ask why this abstraction is necessary? It seems to me that the intent is to generalize the textinput stuff across HTMLInputElement and HTMLTextAreaElement, but I may be wrong on that.

@jonleighton

Copy link
Copy Markdown
Contributor Author

The only other abstraction I came up with is free functions that accept the textinput as an argument

Out of curiosity, can you point me to anything which describes what is meant by a "free function"? (I'm not very familiar with Rust yet...)

Also ./mach test-tidy fails with these changes.

I'll look into that.

When I mentioned that whether the selection{Start, End, Range} functions matches the spec, I meant whether they are following the steps as defined in the spec. This function in particular does not seem to have included step 1 and 2.

Yeah, I'm not done yet but I thought it was worth submitting this PR to get feedback before I make further changes. For now, the implementation of TextControl is simply moved from elsewhere in the code base. I'd then intend to work through the spec to make sure it conforms to everything. (I can continue working on the subsequent changes if desired, but I just wanted to get some feedback so I don't go too far down an undesirable path.)

Also, may I ask why this abstraction is necessary? It seems to me that the intent is to generalize the textinput stuff across HTMLInputElement and HTMLTextAreaElement, but I may be wrong on that.

Yes, that's the intent. The spec of the selection API is identical for both input and textarea, but until this change they both had separate implementations in the Servo codebase. However, the separate implementations were very similar and had clearly been copy/pasted. When I fixed the firing of the select event on assignment to selection{Start,End} for input, my fix didn't apply to textarea. To fix it for textarea would require me to make an identical change to HTMLTextAreaElement. It seemed more sensible to extract the common code so that the two elements behave the same way and there is no duplication. (This extraction implicitly fixes the implementation for textarea hence some more tests now pass.)

@KiChjang

Copy link
Copy Markdown
Contributor

A free function is a function that isn't inside an impl block, i.e. it exists at the top level of a module.

@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Nov 18, 2017
Move assertions about the initial value of selection{Start,End} to their
own tests. This ensures that when one of these assertions fails, it
doesn't prevent other tests from being defined. Thus we have a clearer
view of which tests are passing or failing, since all tests get defined
regardless of which assertions fail.
The API for text control selection is the same for both <input> and
<textarea>:

https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#textFieldSelection

Before this change, they had similar but not identical implementations
with duplicate code. Now there is a common TextControl trait which
contains the implementation used by both. As a result, some previously
failing tests now pass.
@jonleighton

Copy link
Copy Markdown
Contributor Author

Also ran ./mach update-manifest (what is the MANIFEST.json file for?)

@KiChjang

KiChjang commented Nov 20, 2017 •

Copy link
Copy Markdown
Contributor

So I thought a bit about this, and was wondering whether the trait abstraction is necessary. It's true that HTMLInputElement and HTMLTextAreaElement don't share the selection code, but they both do have a textinput field in their structs. I'm wondering if the trait methods you define should better be located in textinput.rs.

@jonleighton

Copy link
Copy Markdown
Contributor Author

Yeah, I thought about that too. The reason I didn't go down that path is that TextInput wouldn't be able to handle anything DOM-related, i.e. firing events, marking the node dirty, etc. As the selection spec is further implemented, I expect there to be more common DOM-related code than there currently is, so it seems like a good idea to have an abstraction which can cover that stuff.

@KiChjang

Copy link
Copy Markdown
Contributor

I think it's actually doable to include DOM-related stuff as parameters to functions defined in textinput.rs, e.g. for set_selection_range, you can pass in a Window and Node parameter in order for it to performs its job.

@jdm

jdm commented Nov 20, 2017

Copy link
Copy Markdown
Member

@bors-servo: r+
I am fine with the current abstraction. We can revisit the design as further changes are made.

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit 6beda3c has been approved by jdm

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Nov 20, 2017
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 6beda3c with merge 9797935...

bors-servo pushed a commit that referenced this pull request Nov 21, 2017
@bors-servo

Copy link
Copy Markdown
Contributor

☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt1, mac-rel-wpt2, mac-rel-wpt3, mac-rel-wpt4, windows-msvc-dev
Approved by: jdm
Pushing 9797935 to master...

@bors-servo
bors-servo merged commit 6beda3c into servo:master Nov 21, 2017
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Nov 21, 2017
jdm pushed a commit to web-platform-tests/wpt that referenced this pull request Jan 4, 2018
Move assertions about the initial value of selection{Start,End} to their
own tests. This ensures that when one of these assertions fails, it
doesn't prevent other tests from being defined. Thus we have a clearer
view of which tests are passing or failing, since all tests get defined
regardless of which assertions fail.

Upstreamed from servo/servo#19272 [ci skip]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-fails-tidy `./mach test-tidy` reported errors.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants