aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script/html/cssparse.rs
diff options
context:
space:
mode:
authorSeo Sanghyeon <sanxiyn@gmail.com>2013-10-21 22:56:44 +0900
committerSeo Sanghyeon <sanxiyn@gmail.com>2013-10-23 16:49:35 +0900
commitb2431912d36dd84c2c0a5c6dabaa870435dcd621 (patch)
treec065d50f7aaf55c25a093d5773e27637fa8e8ad7 /src/components/script/html/cssparse.rs
parentf3f6e62f7fda50d77742f9527f8dc7171d7b8624 (diff)
downloadservo-b2431912d36dd84c2c0a5c6dabaa870435dcd621.tar.gz
servo-b2431912d36dd84c2c0a5c6dabaa870435dcd621.zip
Use the new style system
Credits to: Deokjin Kim Ilyong Cho Jaeman Park Junyoung Cho Ryan Choi Sangeun Kim Yongjin Kim Youngmin Yoo Youngsoo Son
Diffstat (limited to 'src/components/script/html/cssparse.rs')
-rw-r--r--src/components/script/html/cssparse.rs80
1 files changed, 24 insertions, 56 deletions
diff --git a/src/components/script/html/cssparse.rs b/src/components/script/html/cssparse.rs
index e6383599d39..bfe1d984171 100644
--- a/src/components/script/html/cssparse.rs
+++ b/src/components/script/html/cssparse.rs
@@ -8,9 +8,8 @@ use std::cell::Cell;
use std::comm;
use std::comm::Port;
use std::task;
-use newcss::stylesheet::Stylesheet;
-use newcss::util::DataStream;
-use servo_net::resource_task::{Load, LoadResponse, Payload, Done, ResourceTask, ProgressMsg};
+use style::Stylesheet;
+use servo_net::resource_task::{Load, ProgressMsg, Payload, Done, ResourceTask};
use extra::url::Url;
/// Where a style sheet comes from.
@@ -26,73 +25,42 @@ pub fn spawn_css_parser(provenance: StylesheetProvenance,
let provenance_cell = Cell::new(provenance);
do task::spawn {
- let url = do provenance_cell.with_ref |p| {
+ // TODO: CSS parsing should take a base URL.
+ let _url = do provenance_cell.with_ref |p| {
match *p {
UrlProvenance(ref the_url) => (*the_url).clone(),
InlineProvenance(ref the_url, _) => (*the_url).clone()
}
};
- let sheet = Stylesheet::new(url, data_stream(provenance_cell.take(),
- resource_task.clone()));
+ let sheet = match provenance_cell.take() {
+ UrlProvenance(url) => {
+ debug!("cssparse: loading style sheet at %s", url.to_str());
+ let (input_port, input_chan) = comm::stream();
+ resource_task.send(Load(url, input_chan));
+ Stylesheet::from_iter(ProgressMsgPortIterator {
+ progress_port: input_port.recv().progress_port
+ })
+ }
+ InlineProvenance(_, data) => {
+ Stylesheet::from_str(data)
+ }
+ };
result_chan.send(sheet);
}
return result_port;
}
-fn data_stream(provenance: StylesheetProvenance, resource_task: ResourceTask) -> @mut DataStream {
- match provenance {
- UrlProvenance(url) => {
- debug!("cssparse: loading style sheet at %s", url.to_str());
- let (input_port, input_chan) = comm::stream();
- resource_task.send(Load(url, input_chan));
- resource_port_to_data_stream(input_port)
- }
- InlineProvenance(_, data) => {
- data_to_data_stream(data)
- }
- }
+struct ProgressMsgPortIterator {
+ progress_port: Port<ProgressMsg>
}
-fn resource_port_to_data_stream(input_port: Port<LoadResponse>) -> @mut DataStream {
- let progress_port = input_port.recv().progress_port;
- struct ResourcePortDataStream {
- progress_port: Port<ProgressMsg>,
- };
- impl DataStream for ResourcePortDataStream {
- fn read(&mut self) -> Option<~[u8]> {
- match self.progress_port.recv() {
- Payload(data) => Some(data),
- Done(*) => None
- }
+impl Iterator<~[u8]> for ProgressMsgPortIterator {
+ fn next(&mut self) -> Option<~[u8]> {
+ match self.progress_port.recv() {
+ Payload(data) => Some(data),
+ Done(*) => None
}
}
- let stream = @mut ResourcePortDataStream {
- progress_port: progress_port,
- };
- stream as @mut DataStream
}
-
-fn data_to_data_stream(data: ~str) -> @mut DataStream {
- let data_cell = Cell::new(data);
- struct DataDataStream {
- data_cell: Cell<~str>,
- };
- impl DataStream for DataDataStream {
- fn read(&mut self) -> Option<~[u8]> {
- if self.data_cell.is_empty() {
- None
- } else {
- // FIXME: Blech, a copy.
- let data = self.data_cell.take();
- Some(data.as_bytes().to_owned())
- }
- }
- }
- let stream = @mut DataDataStream {
- data_cell: data_cell,
- };
- stream as @mut DataStream
-}
-