From f60de52aae628a114935ec5e7272596fd798fa1a Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Mon, 25 Apr 2016 20:05:55 -0400 Subject: [PATCH] Fire 'select' event in SetSelectionRange --- components/script/dom/htmlinputelement.rs | 9 +++++-- components/script/dom/htmltextareaelement.rs | 9 +++++-- .../textfieldselection-setSelectionRange.html | 26 +++++++++++++++++++ 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index ed9f4826fb6..a226a2e224c 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -545,6 +545,12 @@ impl HTMLInputElementMethods for HTMLInputElement { let direction = direction.map_or(SelectionDirection::None, |d| SelectionDirection::from(d)); self.textinput.borrow_mut().selection_direction = direction; self.textinput.borrow_mut().set_selection_range(start, end); + let window = window_from_node(self); + let _ = window.user_interaction_task_source().queue_event( + &self.upcast(), + atom!("select"), + EventBubbles::Bubbles, + EventCancelable::NotCancelable); self.upcast::().dirty(NodeDamage::OtherNodeDamage); } } @@ -916,8 +922,7 @@ impl VirtualMethods for HTMLInputElement { if event.IsTrusted() { let window = window_from_node(self); - let task_source = window.user_interaction_task_source(); - let _ = task_source.queue_event( + let _ = window.user_interaction_task_source().queue_event( &self.upcast(), atom!("input"), EventBubbles::Bubbles, diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs index 44e331f4a9d..122d73e8553 100644 --- a/components/script/dom/htmltextareaelement.rs +++ b/components/script/dom/htmltextareaelement.rs @@ -256,6 +256,12 @@ impl HTMLTextAreaElementMethods for HTMLTextAreaElement { let direction = direction.map_or(SelectionDirection::None, |d| SelectionDirection::from(d)); self.textinput.borrow_mut().selection_direction = direction; self.textinput.borrow_mut().set_selection_range(start, end); + let window = window_from_node(self); + let _ = window.user_interaction_task_source().queue_event( + &self.upcast(), + atom!("select"), + EventBubbles::Bubbles, + EventCancelable::NotCancelable); self.upcast::().dirty(NodeDamage::OtherNodeDamage); } } @@ -374,8 +380,7 @@ impl VirtualMethods for HTMLTextAreaElement { if event.IsTrusted() { let window = window_from_node(self); - let task_source = window.user_interaction_task_source(); - let _ = task_source.queue_event( + let _ = window.user_interaction_task_source().queue_event( &self.upcast(), atom!("input"), EventBubbles::Bubbles, diff --git a/tests/wpt/web-platform-tests/html/semantics/forms/textfieldselection/textfieldselection-setSelectionRange.html b/tests/wpt/web-platform-tests/html/semantics/forms/textfieldselection/textfieldselection-setSelectionRange.html index 06915a81a8b..5f525736201 100644 --- a/tests/wpt/web-platform-tests/html/semantics/forms/textfieldselection/textfieldselection-setSelectionRange.html +++ b/tests/wpt/web-platform-tests/html/semantics/forms/textfieldselection/textfieldselection-setSelectionRange.html @@ -116,6 +116,19 @@ test(function() { },'input setSelectionRange(undefined,1)'); },"test of input.setSelectionRange"); +async_test(function() { + var q = false; + var input = document.getElementById("a"); + input.addEventListener("select", this.step_func_done(function(e) { + assert_true(q, "event should be queued"); + assert_true(e.isTrusted, "event is trusted"); + assert_true(e.bubbles, "event bubbles"); + assert_false(e.cancelable, "event is not cancelable"); + })); + input.setSelectionRange(0, 1); + q = true; +}, "input setSelectionRange fires a select event"); + test(function() { var textarea = document.getElementById("b"); test(function() { @@ -221,4 +234,17 @@ test(function() { assert_equals(textarea.selectionEnd, 1, "element.selectionStart should be 1"); },'textarea setSelectionRange(undefined,1)'); },"test of textarea.setSelectionRange"); + +async_test(function() { + var q = false; + var textarea = document.getElementById("b"); + textarea.addEventListener("select", this.step_func_done(function(e) { + assert_true(q, "event should be queued"); + assert_true(e.isTrusted, "event is trusted"); + assert_true(e.bubbles, "event bubbles"); + assert_false(e.cancelable, "event is not cancelable"); + })); + textarea.setSelectionRange(0, 1); + q = true; +}, "textarea setSelectionRange fires a select event");