From dd590d088b036e06dd5775237e04ac45de3b1488 Mon Sep 17 00:00:00 2001 From: Zhen Zhang Date: Tue, 17 May 2016 18:10:07 +0800 Subject: Implement file-type functionalities in htmlinputelement and related Changes include: - Implement file selection and other DOM behaviours in htmlinputelement - Integrate IpcSender into ResourceThreads - Improve filemanager_thread, including adding type_string field to SelectedFile - Improve interfaces in FileList/File/Blob to accommodate the above changes --- components/script/dom/file.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'components/script/dom/file.rs') diff --git a/components/script/dom/file.rs b/components/script/dom/file.rs index 9667182671a..4ece71a5ce3 100644 --- a/components/script/dom/file.rs +++ b/components/script/dom/file.rs @@ -10,6 +10,8 @@ use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; use dom::bindings::reflector::reflect_dom_object; use dom::blob::{Blob, DataSlice, blob_parts_to_bytes}; +use dom::window::Window; +use net_traits::filemanager_thread::SelectedFile; use std::sync::Arc; use time; use util::str::DOMString; @@ -45,6 +47,19 @@ impl File { FileBinding::Wrap) } + // Construct from selected file message from file manager thread + pub fn new_from_selected(window: &Window, selected: SelectedFile) -> Root { + let name = DOMString::from(selected.filename.to_str().expect("File name encoding error")); + + // FIXME: fix this after PR #11221 is landed + let id = selected.id; + let slice = DataSlice::empty(); + + let global = GlobalRef::Window(window); + + File::new(global, slice, name, Some(selected.modified as i64), "") + } + // https://w3c.github.io/FileAPI/#file-constructor pub fn Constructor(global: GlobalRef, fileBits: Vec, @@ -64,7 +79,6 @@ impl File { pub fn name(&self) -> &DOMString { &self.name } - } impl FileMethods for File { -- cgit v1.2.3