Skip to content

Commit f60de52

Browse files
committed
Fire 'select' event in SetSelectionRange
1 parent cc04951 commit f60de52

3 files changed

Lines changed: 40 additions & 4 deletions

File tree

‎components/script/dom/htmlinputelement.rs‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,12 @@ impl HTMLInputElementMethods for HTMLInputElement {
545545
let direction = direction.map_or(SelectionDirection::None, |d| SelectionDirection::from(d));
546546
self.textinput.borrow_mut().selection_direction = direction;
547547
self.textinput.borrow_mut().set_selection_range(start, end);
548+
let window = window_from_node(self);
549+
let _ = window.user_interaction_task_source().queue_event(
550+
&self.upcast(),
551+
atom!("select"),
552+
EventBubbles::Bubbles,
553+
EventCancelable::NotCancelable);
548554
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
549555
}
550556
}
@@ -916,8 +922,7 @@ impl VirtualMethods for HTMLInputElement {
916922

917923
if event.IsTrusted() {
918924
let window = window_from_node(self);
919-
let task_source = window.user_interaction_task_source();
920-
let _ = task_source.queue_event(
925+
let _ = window.user_interaction_task_source().queue_event(
921926
&self.upcast(),
922927
atom!("input"),
923928
EventBubbles::Bubbles,

‎components/script/dom/htmltextareaelement.rs‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,12 @@ impl HTMLTextAreaElementMethods for HTMLTextAreaElement {
256256
let direction = direction.map_or(SelectionDirection::None, |d| SelectionDirection::from(d));
257257
self.textinput.borrow_mut().selection_direction = direction;
258258
self.textinput.borrow_mut().set_selection_range(start, end);
259+
let window = window_from_node(self);
260+
let _ = window.user_interaction_task_source().queue_event(
261+
&self.upcast(),
262+
atom!("select"),
263+
EventBubbles::Bubbles,
264+
EventCancelable::NotCancelable);
259265
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
260266
}
261267
}
@@ -374,8 +380,7 @@ impl VirtualMethods for HTMLTextAreaElement {
374380

375381
if event.IsTrusted() {
376382
let window = window_from_node(self);
377-
let task_source = window.user_interaction_task_source();
378-
let _ = task_source.queue_event(
383+
let _ = window.user_interaction_task_source().queue_event(
379384
&self.upcast(),
380385
atom!("input"),
381386
EventBubbles::Bubbles,

‎tests/wpt/web-platform-tests/html/semantics/forms/textfieldselection/textfieldselection-setSelectionRange.html‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,19 @@
116116
},'input setSelectionRange(undefined,1)');
117117
},"test of input.setSelectionRange");
118118

119+
async_test(function() {
120+
var q = false;
121+
var input = document.getElementById("a");
122+
input.addEventListener("select", this.step_func_done(function(e) {
123+
assert_true(q, "event should be queued");
124+
assert_true(e.isTrusted, "event is trusted");
125+
assert_true(e.bubbles, "event bubbles");
126+
assert_false(e.cancelable, "event is not cancelable");
127+
}));
128+
input.setSelectionRange(0, 1);
129+
q = true;
130+
}, "input setSelectionRange fires a select event");
131+
119132
test(function() {
120133
var textarea = document.getElementById("b");
121134
test(function() {
@@ -221,4 +234,17 @@
221234
assert_equals(textarea.selectionEnd, 1, "element.selectionStart should be 1");
222235
},'textarea setSelectionRange(undefined,1)');
223236
},"test of textarea.setSelectionRange");
237+
238+
async_test(function() {
239+
var q = false;
240+
var textarea = document.getElementById("b");
241+
textarea.addEventListener("select", this.step_func_done(function(e) {
242+
assert_true(q, "event should be queued");
243+
assert_true(e.isTrusted, "event is trusted");
244+
assert_true(e.bubbles, "event bubbles");
245+
assert_false(e.cancelable, "event is not cancelable");
246+
}));
247+
textarea.setSelectionRange(0, 1);
248+
q = true;
249+
}, "textarea setSelectionRange fires a select event");
224250
</script>

0 commit comments

Comments
 (0)