aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/htmlinputelement.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-01-04 10:52:06 -0800
committerGitHub <noreply@github.com>2017-01-04 10:52:06 -0800
commit6f9ff7b8bf66cbeb7d539c6728db05f05aa8f85c (patch)
tree3b69d3f845bcdda83e27b7174370e8ff54b446d1 /components/script/dom/htmlinputelement.rs
parent96fd0837d3de70b1f0d8f2bff0253b0220e7e5ce (diff)
parent5f0b3bd53c25c158117c91e9da36aaec0342244f (diff)
downloadservo-6f9ff7b8bf66cbeb7d539c6728db05f05aa8f85c.tar.gz
servo-6f9ff7b8bf66cbeb7d539c6728db05f05aa8f85c.zip
Auto merge of #14738 - Wafflespeanut:keypress, r=jdm
Properly dispatch keypress event <!-- Please describe your changes on the following line: --> This was an attempt to fix #14659. It turned out that the problem wasn't what I thought it was. So, I didn't fix that. On the brighter side, this fixes two related issues. - Previously, we were unable to launch `keypress` events from `input` and `textarea` elements, because [we'd been cancelling](https://github.com/servo/servo/blob/1327ebd52f53f5f6637a12fab6cf0cad0aa0be6f/components/script/dom/htmlinputelement.rs#L1120-L1124) the key events, so that they don't trigger window navigation - #8400). I've introduced an enum to represent an additional state to an event's cancellation. - [According to the spec](https://w3c.github.io/uievents/#keypress-event-order), `keypress` (if available) should be dispatched immediately after `keydown`, and it should be followed by `input`. Canceling `keypress` should also cancel `input`. But, we'd been dispatching `input` before `keypress`. We now dispatch `input` once the `keypress` event is on the respective elements. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors <!-- Either: --> - [x] These changes do not require tests because it's a refactor? <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> r? @jdm or anyone interested <!-- 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/14738) <!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/htmlinputelement.rs')
-rwxr-xr-xcomponents/script/dom/htmlinputelement.rs29
1 files changed, 15 insertions, 14 deletions
diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs
index eb344ef0a79..d133efd5e14 100755
--- a/components/script/dom/htmlinputelement.rs
+++ b/components/script/dom/htmlinputelement.rs
@@ -1105,28 +1105,29 @@ impl VirtualMethods for HTMLInputElement {
DispatchInput => {
self.value_changed.set(true);
self.update_placeholder_shown_state();
-
- if event.IsTrusted() {
- let window = window_from_node(self);
- let _ = window.user_interaction_task_source().queue_event(
- &self.upcast(),
- atom!("input"),
- EventBubbles::Bubbles,
- EventCancelable::NotCancelable,
- &window);
- }
-
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
- event.PreventDefault();
+ event.mark_as_handled();
}
RedrawSelection => {
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
- event.PreventDefault();
+ event.mark_as_handled();
}
Nothing => (),
}
}
- }
+ } else if event.type_() == atom!("keypress") && !event.DefaultPrevented() &&
+ (self.input_type.get() == InputType::InputText ||
+ self.input_type.get() == InputType::InputPassword) {
+ if event.IsTrusted() {
+ let window = window_from_node(self);
+ let _ = window.user_interaction_task_source()
+ .queue_event(&self.upcast(),
+ atom!("input"),
+ EventBubbles::Bubbles,
+ EventCancelable::NotCancelable,
+ &window);
+ }
+ }
}
}