mirror of
https://github.com/servo/servo.git
synced 2025-06-18 21:34:30 +00:00
Auto merge of #12196 - izgzhen:emit-change-file-select, r=Manishearth
Emit change event when files are selected <!-- Please describe your changes on the following line: --> r? @Manishearth As specified in step 6 of [activation behaviour](https://html.spec.whatwg.org/multipage/forms.html#file-upload-state-(type=file)). --- <!-- 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: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12196) <!-- Reviewable:end -->
This commit is contained in:
commit
110fd68610
1 changed files with 19 additions and 1 deletions
|
@ -1150,6 +1150,7 @@ impl Activatable for HTMLInputElement {
|
|||
EventCancelable::NotCancelable);
|
||||
},
|
||||
InputType::InputFile => {
|
||||
// https://html.spec.whatwg.org/multipage/#file-upload-state-(type=file)
|
||||
let window = window_from_node(self);
|
||||
let filemanager = window.resource_threads().sender();
|
||||
|
||||
|
@ -1157,6 +1158,7 @@ impl Activatable for HTMLInputElement {
|
|||
let mut error = None;
|
||||
|
||||
let filter = filter_from_accept(&self.Accept());
|
||||
let target = self.upcast::<EventTarget>();
|
||||
|
||||
if self.Multiple() {
|
||||
let (chan, recv) = ipc::channel().expect("Error initializing channel");
|
||||
|
@ -1168,6 +1170,13 @@ impl Activatable for HTMLInputElement {
|
|||
for selected in selected_files {
|
||||
files.push(File::new_from_selected(window.r(), selected));
|
||||
}
|
||||
|
||||
target.fire_event("input",
|
||||
EventBubbles::Bubbles,
|
||||
EventCancelable::NotCancelable);
|
||||
target.fire_event("change",
|
||||
EventBubbles::Bubbles,
|
||||
EventCancelable::NotCancelable);
|
||||
},
|
||||
Err(err) => error = Some(err),
|
||||
};
|
||||
|
@ -1177,7 +1186,16 @@ impl Activatable for HTMLInputElement {
|
|||
let _ = filemanager.send(msg).unwrap();
|
||||
|
||||
match recv.recv().expect("IpcSender side error") {
|
||||
Ok(selected) => files.push(File::new_from_selected(window.r(), selected)),
|
||||
Ok(selected) => {
|
||||
files.push(File::new_from_selected(window.r(), selected));
|
||||
|
||||
target.fire_event("input",
|
||||
EventBubbles::Bubbles,
|
||||
EventCancelable::NotCancelable);
|
||||
target.fire_event("change",
|
||||
EventBubbles::Bubbles,
|
||||
EventCancelable::NotCancelable);
|
||||
},
|
||||
Err(err) => error = Some(err),
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue