Auto merge of #11225 - izgzhen:patch-input-element-file, r=Manishearth

Implement file related functionalities in htmlinputelement and related

- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy --faster` does not report any errors
- [x] These changes is related to #11131
- [x] These changes do not require tests because it is a partial implementation

1. Improve the `filemanager_thread` by adding type string and create `SelectedFile`
2. Fill several gaps in `htmlinputelement` implementation related to file type
3. Improve the `File` interface to accommodate the above changes
4. Integrate changes introduced by PR #11189

<!-- 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/11225)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-05-23 01:10:46 -07:00
commit 7cea4eb01c
10 changed files with 155 additions and 30 deletions

View file

@ -28,6 +28,7 @@ extern crate util;
extern crate uuid;
extern crate websocket;
use filemanager_thread::FileManagerThreadMsg;
use heapsize::HeapSizeOf;
use hyper::header::{ContentType, Headers};
use hyper::http::RawStatus;
@ -217,8 +218,13 @@ pub type CoreResourceThread = IpcSender<CoreResourceMsg>;
pub type IpcSendResult = Result<(), IOError>;
/// Abstraction of the ability to send a particular type of message,
/// used by net_traits::ResourceThreads to ease the use its IpcSender sub-fields
/// XXX: If this trait will be used more in future, some auto derive might be appealing
pub trait IpcSend<T> where T: serde::Serialize + serde::Deserialize {
/// send message T
fn send(&self, T) -> IpcSendResult;
/// get underlying sender
fn sender(&self) -> IpcSender<T>;
}
@ -231,13 +237,17 @@ pub trait IpcSend<T> where T: serde::Serialize + serde::Deserialize {
pub struct ResourceThreads {
core_thread: CoreResourceThread,
storage_thread: IpcSender<StorageThreadMsg>,
filemanager_thread: IpcSender<FileManagerThreadMsg>,
}
impl ResourceThreads {
pub fn new(c: CoreResourceThread, s: IpcSender<StorageThreadMsg>) -> ResourceThreads {
pub fn new(c: CoreResourceThread,
s: IpcSender<StorageThreadMsg>,
f: IpcSender<FileManagerThreadMsg>) -> ResourceThreads {
ResourceThreads {
core_thread: c,
storage_thread: s,
filemanager_thread: f,
}
}
}
@ -262,6 +272,16 @@ impl IpcSend<StorageThreadMsg> for ResourceThreads {
}
}
impl IpcSend<FileManagerThreadMsg> for ResourceThreads {
fn send(&self, msg: FileManagerThreadMsg) -> IpcSendResult {
self.filemanager_thread.send(msg)
}
fn sender(&self) -> IpcSender<FileManagerThreadMsg> {
self.filemanager_thread.clone()
}
}
// Ignore the sub-fields
impl HeapSizeOf for ResourceThreads {
fn heap_size_of_children(&self) -> usize { 0 }