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

HTML input value #9514

Merged
merged 1 commit into from Feb 27, 2016
Merged

HTML input value #9514

merged 1 commit into from Feb 27, 2016

Conversation

@g-k
Copy link
Contributor

g-k commented Feb 3, 2016

Ready for review.

Fixes #9455.

Review on Reviewable

fn default() -> InputValueMode { InputValueMode::Default }
}

impl InputValueMode {

This comment has been minimized.

Copy link
@KiChjang

KiChjang Feb 3, 2016

Member

nit: Move these impl up to where the enum is.

@frewsxcv
Copy link
Member

frewsxcv commented Feb 3, 2016

./components/script/dom/htmlinputelement.rs:396: link to WHATWG may break in the future, use this format instead: https://html.spec.whatwg.org/multipage/#input-type-attr-summary
./components/script/dom/htmlinputelement.rs:411: missing space before {
@g-k
Copy link
Contributor Author

g-k commented Feb 3, 2016

Thanks for the feedback!

I broke a bunch of tests in: tests/wpt/web-platform-tests/html/semantics/forms/the-input-element/ so I'm going to work on getting those passing next.

@g-k g-k force-pushed the g-k:html-input-value branch from 7f13744 to 9a4b26f Feb 4, 2016
@g-k
Copy link
Contributor Author

g-k commented Feb 5, 2016

OK, I'm stuck.

9a4b26f passes the radionodelist test and the tests/wpt/web-platform-tests/html/semantics/forms/the-input-element/ tests except for the one below.

I tried to get it test passing by setting the value to the textinput value when the type attribute changes (in VirtualMethods attribute_mutated for type AttributeMutation::Set), but that crashes.

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/type-change-state.html:
  │ FAIL [expected PASS] change state from hidden to checkbox
  │   → assert_equals: input.value should be '  foo\rbar  ' after change of state expected "  foo\rbar  " but got "on"
  │ FAIL [expected PASS] change state from hidden to radio
  │   → assert_equals: input.value should be '  foo\rbar  ' after change of state expected "  foo\rbar  " but got "on"
...
  │ FAIL [expected PASS] change state from image to reset
  │   → assert_equals: input.value should be '  foo\rbar  ' after change of state expected "  foo\rbar  " but got ""
  │ FAIL [expected PASS] change state from image to button
  │   → assert_equals: input.value should be '  foo\rbar  ' after change of state expected "  foo\rbar  " but got ""
  │ 
  │ @http://web-platform.test:8000/html/semantics/forms/the-input-element/type-change-state.html:42:15
  │ Test.prototype.step@http://web-platform.test:8000/resources/testharness.js:1381:20
  │ test@http://web-platform.test:8000/resources/testharness.js:495:9
  └ @http://web-platform.test:8000/html/semantics/forms/the-input-element/type-change-state.html:28:1
} else {
input.upcast::<Element>()
.get_attribute(&ns!(), &atom!("value"))
.map_or_else(|| default,

This comment has been minimized.

Copy link
@KiChjang

KiChjang Feb 5, 2016

Member

This looks like a .map_or() is enough, no need for .map_or_else()

@KiChjang
Copy link
Member

KiChjang commented Feb 5, 2016

Could you also provide step annotations for the functions that you've wrote? It's hard to follow which part of the spec you're implementing.

@@ -292,14 +352,12 @@ impl HTMLInputElementMethods for HTMLInputElement {

// https://html.spec.whatwg.org/multipage/#dom-input-value
fn Value(&self) -> DOMString {
self.textinput.borrow().get_content()
InputValueMode::from_input_element(&self).get_value(self)

This comment has been minimized.

Copy link
@KiChjang

KiChjang Feb 5, 2016

Member

I'm not sure how I missed this, but this style is kind of weird. I'd expect InputValueMode to be a field in HTMLInputElement, and this method would just be a call to self.get_value(). Here you're constructing a new InputValueMode every time you get or set the value of an HTMLInputElement, and then calling a method on the InputValueMode, supplying it with an instance of HTMLInputElement.

}

fn set_value(&self, input: &HTMLInputElement, value: DOMString) {
let element = input.upcast::<Element>();

This comment has been minimized.

Copy link
@KiChjang

KiChjang Feb 5, 2016

Member

I see no value in putting the let-binding here, since element is only used in the else-body.

@KiChjang
Copy link
Member

KiChjang commented Feb 5, 2016

I suspect that the test failures are because of the changes between InputModeValues - some of them make changes to the attributes on the upcasted Element struct, and some don't. Filed whatwg/html#628 for some clairifications.

@g-k g-k force-pushed the g-k:html-input-value branch from 9a4b26f to a9994e1 Feb 8, 2016
@g-k
Copy link
Contributor Author

g-k commented Feb 8, 2016

Ah! I thought only content attributes were called attributes.

I made the suggested changes and the input and raidonodelist tests pass, but the implementation is wrong since SetValue for default/on updates the content attribute.

I need to find out if the simple list iterator does a tree order traversal (pre-order, depth-first traversal of DOM nodes) and whether remove attribute on an Element should call attribute_mutated when it's an HTMLInputElement.

// assert_equals(document.getElementById("r1").value, -39); // but got string "1"

rdoList.value = "on";
// expected "1" but got "2"

This comment has been minimized.

Copy link
@KiChjang

KiChjang Feb 12, 2016

Member

Revert changes to this file, please.

This comment has been minimized.

Copy link
@g-k

g-k Feb 17, 2016

Author Contributor

I will. This is a WIP branch.

I just thought it was interesting, because it seems like IDL attribute has the right value before it is set to "on".


// On setting, if the new value is the empty string, it
// must empty the list of selected files; otherwise, it
// must throw an InvalidStateError exception.

This comment has been minimized.

Copy link
@KiChjang

KiChjang Feb 16, 2016

Member

All of these annotations are unnecessary; we only need step numbers.

This comment has been minimized.

Copy link
@g-k

g-k Feb 17, 2016

Author Contributor

I might be misreading the spec or looking in the wrong place, but I don't see any step numbers on: https://html.spec.whatwg.org/multipage/forms.html#dom-input-value

// must return that attribute's value; otherwise, it must
// return the string "on" (for default/on mode)
ValueMode::DefaultOn => {
let content = self.textinput.borrow().get_content();

This comment has been minimized.

Copy link
@KiChjang

KiChjang Feb 16, 2016

Member

This should instead upcast itself to an Element and grab the content attribute value from it.

Same for ValueMode::Default.

This comment has been minimized.

Copy link
@g-k

g-k Feb 17, 2016

Author Contributor

My bad, I didn't realize the red text in the spec are links and I thought they were talking about the IDL attribute.

Confusingly the bold red text is talking about an IDL attribute.

@g-k g-k force-pushed the g-k:html-input-value branch from a9994e1 to a2efef6 Feb 17, 2016
@g-k g-k force-pushed the g-k:html-input-value branch 2 times, most recently from 8fc5c64 to 7b21d8e Feb 17, 2016
|a| DOMString::from(a.summarize().value)),
ValueMode::DefaultOn =>
self.upcast::<Element>()
.get_attribute(&ns!(), &atom!("value"))

This comment has been minimized.

Copy link
@KiChjang

KiChjang Feb 17, 2016

Member

nit: Indentation

ValueMode::Filename | ValueMode::Value => self.textinput.borrow().get_content(),
ValueMode::Default =>
self.upcast::<Element>()
.get_attribute(&ns!(), &atom!("value"))

This comment has been minimized.

Copy link
@KiChjang

KiChjang Feb 17, 2016

Member

nit: Indentation

@@ -292,12 +320,32 @@ impl HTMLInputElementMethods for HTMLInputElement {

// https://html.spec.whatwg.org/multipage/#dom-input-value
fn Value(&self) -> DOMString {
self.textinput.borrow().get_content()
match self.get_value_mode() {
ValueMode::Filename | ValueMode::Value => self.textinput.borrow().get_content(),

This comment has been minimized.

Copy link
@KiChjang

KiChjang Feb 17, 2016

Member

This is actually much more involved than just returning the textinput.The spec says the following for value:

On getting, it must return the current value of the element. On setting, it must set the element's value to the new value, set the element's dirty value flag to true, invoke the value sanitization algorithm, if the element's type attribute's current state defines one, and then, if the element has a text entry cursor position, should move the text entry cursor position to the end of the text field, unselecting any selected text and resetting the selection direction to none.

And the following for filename:

On getting, it must return the string "C:\fakepath" followed by the name of the first file in the list of selected files, if any, or the empty string if the list is empty. On setting, if the new value is the empty string, it must empty the list of selected files; otherwise, it must throw an InvalidStateError exception.

}

// https://html.spec.whatwg.org/multipage/#input-type-attr-summary
fn get_value_mode_for_input_type(input_type: InputType) -> ValueMode {

This comment has been minimized.

Copy link
@KiChjang

KiChjang Feb 17, 2016

Member

Why is this written in a functional style? The HTMLInputElement has all the necessary information about its own input type.

This comment has been minimized.

Copy link
@g-k

g-k Feb 18, 2016

Author Contributor

I was using it in the type mutation handler.

self.SetValue(DOMString::from(""));
}

if new_type == InputType::InputRadio {

This comment has been minimized.

Copy link
@KiChjang

KiChjang Feb 17, 2016

Member

This is step 5.

} else if old_value_mode != ValueMode::Value && new_value_mode == ValueMode::Value {
// Step 2
self.SetValue(self.upcast::<Element>()
.get_attribute(&ns!(), &atom!("value"))

This comment has been minimized.

Copy link
@KiChjang

KiChjang Feb 17, 2016

Member

nit: Indentation

@bors-servo
Copy link
Contributor

bors-servo commented Feb 26, 2016

Testing commit e6c31e3 with merge b9698bf...

bors-servo added a commit that referenced this pull request Feb 26, 2016
HTML input value

Ready for review.

Fixes #9455.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9514)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Feb 26, 2016

💔 Test failed - linux-rel

@nox
Copy link
Member

nox commented Feb 26, 2016

@nox nox added S-awaiting-merge and removed S-tests-failed labels Feb 26, 2016
@bors-servo
Copy link
Contributor

bors-servo commented Feb 26, 2016

Previous build results for android, gonk, linux-dev, mac-dev-unit, mac-rel-css, mac-rel-wpt are reusable. Rebuilding only linux-rel...

@bors-servo
Copy link
Contributor

bors-servo commented Feb 26, 2016

💔 Test failed - linux-rel

@KiChjang
Copy link
Member

KiChjang commented Feb 26, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Feb 26, 2016

Testing commit e6c31e3 with merge f30fb64...

bors-servo added a commit that referenced this pull request Feb 26, 2016
HTML input value

Ready for review.

Fixes #9455.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9514)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Feb 26, 2016

💔 Test failed - linux-rel

@KiChjang
Copy link
Member

KiChjang commented Feb 26, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Feb 26, 2016

Testing commit e6c31e3 with merge 0d7a2ee...

bors-servo added a commit that referenced this pull request Feb 26, 2016
HTML input value

Ready for review.

Fixes #9455.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9514)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Feb 27, 2016

@bors-servo bors-servo merged commit e6c31e3 into servo:master Feb 27, 2016
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@g-k g-k deleted the g-k:html-input-value branch Feb 27, 2016
ivanzr added a commit to ivanzr/web-platform-tests that referenced this pull request Jun 29, 2016
According to step 3 of
https://html.spec.whatwg.org/multipage/forms.html#input-type-change a
value mode transition from non-filename to filename should update the
input internal value state to the empty string.

According to
https://html.spec.whatwg.org/multipage/forms.html#dom-input-value a
subsequent read of the value IDL attribute should return the empty
string (assuming no selected files).

Refs: servo/servo#9514
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

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