Skip to content

Commit

Permalink
Defined new trait ParseErrorReporter and added error_reporter member …
Browse files Browse the repository at this point in the history
…to ParserContext
  • Loading branch information
GauriGNaik committed Nov 25, 2015
1 parent 7a87312 commit 47bceb8
Show file tree
Hide file tree
Showing 23 changed files with 299 additions and 101 deletions.
3 changes: 3 additions & 0 deletions components/layout/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ path = "../script_traits"
[dependencies.style]
path = "../style"

[dependencies.style_traits]
path = "../style_traits"

[dependencies.plugins]
path = "../plugins"

Expand Down
5 changes: 5 additions & 0 deletions components/layout/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ use std::rc::Rc;
use std::sync::mpsc::{Sender, channel};
use std::sync::{Arc, Mutex};
use style::selector_matching::Stylist;
use style_traits::ParseErrorReporter;
use url::Url;
use util::mem::HeapSizeOf;
use util::opts;


struct LocalLayoutContext {
font_context: RefCell<FontContext>,
applicable_declarations_cache: RefCell<ApplicableDeclarationsCache>,
Expand Down Expand Up @@ -124,6 +126,9 @@ pub struct SharedLayoutContext {

/// Why is this reflow occurring
pub goal: ReflowGoal,

///The CSS error reporter for all CSS loaded in this layout thread
pub error_reporter: Box<ParseErrorReporter + Send>
}

pub struct LayoutContext<'a> {
Expand Down
9 changes: 6 additions & 3 deletions components/layout/css/matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use string_cache::{Atom, Namespace};
use style::node::TElementAttributes;
use style::properties::{ComputedValues, PropertyDeclaration, cascade};
use style::selector_matching::{DeclarationBlock, Stylist};
use style_traits::ParseErrorReporter;
use util::arc_ptr_eq;
use util::cache::{LRUCache, SimpleHashCache};
use util::opts;
Expand Down Expand Up @@ -467,16 +468,18 @@ impl<'ln> PrivateMatchMethods for LayoutNode<'ln> {
applicable_declarations,
shareable,
Some(&***parent_style),
cached_computed_values);
cached_computed_values,
layout_context.error_reporter.clone());
cacheable = is_cacheable;
this_style = the_style
}
None => {
let (the_style, is_cacheable) = cascade(layout_context.viewport_size,
let (the_style, is_cacheable) = cascade(layout_context.screen_size,
applicable_declarations,
shareable,
None,
None);
None,
layout_context.error_reporter.clone());
cacheable = is_cacheable;
this_style = the_style
}
Expand Down
87 changes: 70 additions & 17 deletions components/layout/layout_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ use script::layout_interface::Animation;
use script::layout_interface::{LayoutRPC, OffsetParentResponse};
use script::layout_interface::{Msg, NewLayoutTaskInfo, Reflow, ReflowGoal, ReflowQueryType};
use script::layout_interface::{ScriptLayoutChan, ScriptReflow, TrustedNodeAddress};
use script::reporter::CSSErrorReporter;
use script_traits::StylesheetLoadResponder;
use script_traits::{ConstellationControlMsg, LayoutControlMsg, OpaqueScriptLayoutChannel};
use selectors::parser::PseudoElement;
use sequential;
Expand All @@ -73,6 +75,8 @@ use style::properties::style_structs;
use style::selector_matching::{Stylist, USER_OR_USER_AGENT_STYLESHEETS};
use style::stylesheets::{CSSRuleIteratorExt, Stylesheet};
use style::values::AuExtensionMethods;
use style::viewport::ViewportRule;
use style_traits::ParseErrorReporter;
use url::Url;
use util::geometry::{MAX_RECT, ZERO_POINT};
use util::ipc::OptionalIpcSender;
Expand Down Expand Up @@ -215,7 +219,12 @@ pub struct LayoutTask {
/// structures, while still letting the LayoutTask modify them.
///
/// All the other elements of this struct are read-only.
rw_data: Arc<Mutex<LayoutTaskData>>,

pub rw_data: Arc<Mutex<LayoutTaskData>>,

/// The CSS error reporter for all CSS loaded in this layout thread
pub error_reporter: CSSErrorReporter,

}

impl LayoutTaskFactory for LayoutTask {
Expand Down Expand Up @@ -385,8 +394,8 @@ impl LayoutTask {
ROUTER.route_ipc_receiver_to_new_mpsc_receiver(ipc_image_cache_receiver);

let (font_cache_sender, font_cache_receiver) = channel();

let stylist = box Stylist::new(device);
let error_reporter = CSSErrorReporter;
let stylist = box Stylist::new(device, error_reporter.clone());
let outstanding_web_fonts_counter = Arc::new(AtomicUsize::new(0));
for stylesheet in &*USER_OR_USER_AGENT_STYLESHEETS {
add_font_face_rules(stylesheet,
Expand Down Expand Up @@ -437,6 +446,7 @@ impl LayoutTask {
resolved_style_response: None,
offset_parent_response: OffsetParentResponse::empty(),
})),
error_reporter: CSSErrorReporter,
}
}

Expand Down Expand Up @@ -473,7 +483,8 @@ impl LayoutTask {
generation: self.generation,
new_animations_sender: Mutex::new(self.new_animations_sender.clone()),
goal: goal,
running_animations: self.running_animations.clone(),
running_animations: rw_data.running_animations.clone(),
error_reporter: self.error_reporter.clone(),
}
}

Expand Down Expand Up @@ -555,7 +566,6 @@ impl LayoutTask {
goal: ReflowGoal::ForDisplay,
page_clip_rect: MAX_RECT,
};

let mut layout_context = self.build_shared_layout_context(&*rw_data,
false,
&self.url,
Expand Down Expand Up @@ -725,9 +735,40 @@ impl LayoutTask {
response_port.recv().unwrap()
}

fn handle_add_stylesheet<'a, 'b>(&self,
stylesheet: Arc<Stylesheet>,
possibly_locked_rw_data: &mut RwData<'a, 'b>) {
fn handle_load_stylesheet<'a>(&'a self,
url: Url,
mq: MediaQueryList,
pending: PendingAsyncLoad,
responder: Box<StylesheetLoadResponder + Send>,
possibly_locked_rw_data:
&mut Option<MutexGuard<'a, LayoutTaskData>>) {
// TODO: Get the actual value. http://dev.w3.org/csswg/css-syntax/#environment-encoding
let environment_encoding = UTF_8 as EncodingRef;

// TODO we don't really even need to load this if mq does not match
let (metadata, iter) = load_bytes_iter(pending);
let protocol_encoding_label = metadata.charset.as_ref().map(|s| &**s);
let final_url = metadata.final_url;

let sheet = Stylesheet::from_bytes_iter(iter,
final_url,
protocol_encoding_label,
Some(environment_encoding),
Origin::Author, self.error_reporter.clone());

//TODO: mark critical subresources as blocking load as well (#5974)
self.script_chan.send(ConstellationControlMsg::StylesheetLoadComplete(self.id,
url,
responder)).unwrap();

self.handle_add_stylesheet(sheet, mq, possibly_locked_rw_data);
}

fn handle_add_stylesheet<'a>(&'a self,
sheet: Stylesheet,
mq: MediaQueryList,
possibly_locked_rw_data:
&mut Option<MutexGuard<'a, LayoutTaskData>>) {
// Find all font-face rules and notify the font cache of them.
// GWTODO: Need to handle unloading web fonts.

Expand All @@ -743,11 +784,27 @@ impl LayoutTask {
possibly_locked_rw_data.block(rw_data);
}

/// Sets quirks mode for the document, causing the quirks mode stylesheet to be used.
fn handle_set_quirks_mode<'a, 'b>(&self, possibly_locked_rw_data: &mut RwData<'a, 'b>) {
let mut rw_data = possibly_locked_rw_data.lock();
rw_data.stylist.set_quirks_mode(true);
possibly_locked_rw_data.block(rw_data);
fn handle_add_meta_viewport<'a>(&'a self,
translated_rule: ViewportRule,
possibly_locked_rw_data:
&mut Option<MutexGuard<'a, LayoutTaskData>>)
{
let mut rw_data = self.lock_rw_data(possibly_locked_rw_data);
rw_data.stylist.add_stylesheet(Stylesheet {
rules: vec![CSSRule::Viewport(translated_rule)],
origin: Origin::Author
});
LayoutTask::return_rw_data(possibly_locked_rw_data, rw_data);
}

/// Sets quirks mode for the document, causing the quirks mode stylesheet to be loaded.
fn handle_set_quirks_mode<'a>(&'a self,
possibly_locked_rw_data:
&mut Option<MutexGuard<'a, LayoutTaskData>>) {
let mut rw_data = self.lock_rw_data(possibly_locked_rw_data);
rw_data.stylist.add_quirks_mode_stylesheet(self.error_reporter.clone());
LayoutTask::return_rw_data(possibly_locked_rw_data, rw_data);

}

fn try_get_layout_root(&self, node: LayoutNode) -> Option<FlowRef> {
Expand Down Expand Up @@ -1157,7 +1214,6 @@ impl LayoutTask {
el.note_restyle_hint(hint);
}
}

// Create a layout context for use throughout the following passes.
let mut shared_layout_context = self.build_shared_layout_context(&*rw_data,
viewport_size_changed,
Expand Down Expand Up @@ -1265,7 +1321,6 @@ impl LayoutTask {
goal: ReflowGoal::ForDisplay,
page_clip_rect: MAX_RECT,
};

let mut layout_context = self.build_shared_layout_context(&*rw_data,
false,
&self.url,
Expand All @@ -1289,7 +1344,6 @@ impl LayoutTask {
goal: ReflowGoal::ForDisplay,
page_clip_rect: MAX_RECT,
};

let mut layout_context = self.build_shared_layout_context(&*rw_data,
false,
&self.url,
Expand Down Expand Up @@ -1320,7 +1374,6 @@ impl LayoutTask {
goal: ReflowGoal::ForDisplay,
page_clip_rect: MAX_RECT,
};

let mut layout_context = self.build_shared_layout_context(&*rw_data,
false,
&self.url,
Expand Down
1 change: 1 addition & 0 deletions components/layout/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ extern crate serde_json;
extern crate smallvec;
extern crate string_cache;
extern crate style;
extern crate style_traits;
extern crate unicode_bidi;
extern crate unicode_script;
extern crate url;
Expand Down
3 changes: 3 additions & 0 deletions components/script/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ path = "../devtools_traits"
[dependencies.style]
path = "../style"

[dependencies.style_traits]
path = "../style_traits"

[dependencies.canvas]
path = "../canvas"

Expand Down
7 changes: 4 additions & 3 deletions components/script/dom/cssstyledeclaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ use std::ascii::AsciiExt;
use std::borrow::ToOwned;
use std::cell::Ref;
use string_cache::Atom;
use style::properties::{PropertyDeclaration, Shorthand};
use style::properties::{is_supported_property, parse_one_declaration};
use style::properties::PropertyDeclaration;
use style::properties::{is_supported_property, longhands_from_shorthand, parse_one_declaration};
use style_traits::ParseErrorReporter;
use util::str::{DOMString, str_join};

// http://dev.w3.org/csswg/cssom/#the-cssstyledeclaration-interface
Expand Down Expand Up @@ -240,7 +241,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {

// Step 6
let window = window_from_node(&*self.owner);
let declarations = parse_one_declaration(&property, &value, &window.get_url());
let declarations = parse_one_declaration(&property, &value, &window.r().get_url(), window.css_error_reporter());

// Step 7
let declarations = if let Ok(declarations) = declarations {
Expand Down
8 changes: 5 additions & 3 deletions components/script/dom/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ use style::properties::DeclaredValue;
use style::properties::longhands::{self, background_image, border_spacing, font_family, font_size};
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock, parse_style_attribute};
use style::values::CSSFloat;
use style::values::specified::{self, CSSColor, CSSRGBA, LengthOrPercentage};
use style::values::specified::{self, CSSColor, CSSRGBA};
use style_traits::ParseErrorReporter;
use url::UrlParser;
use util::mem::HeapSizeOf;
use util::str::{DOMString, LengthOrPercentageOrAuto};
Expand Down Expand Up @@ -1507,12 +1508,13 @@ impl VirtualMethods for Element {
self.super_type().unwrap().attribute_mutated(attr, mutation);
let node = self.upcast::<Node>();
let doc = node.owner_doc();
match attr.local_name() {
let damage = match attr.local_name() {
&atom!(style) => {
// Modifying the `style` attribute might change style.
*self.style_attribute.borrow_mut() =
mutation.new_value(attr).map(|value| {
parse_style_attribute(&value, &doc.base_url())
let win = window_from_node(self);
parse_style_attribute(&value, &doc.base_url(), win.css_error_reporter())
});
if node.is_in_doc() {
doc.content_changed(node, NodeDamage::NodeStyleDamaged);
Expand Down
3 changes: 2 additions & 1 deletion components/script/dom/htmlstyleelement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ impl HTMLStyleElement {

let win = window_from_node(node);
let url = win.get_url();

let mq_attribute = element.get_attribute(&ns!(""), &atom!("media"));
let mq_str = match mq_attribute {
Some(a) => String::from(&**a.value()),
Expand All @@ -64,6 +63,8 @@ impl HTMLStyleElement {
sheet.set_media(Some(media));
let sheet = Arc::new(sheet);

let data = node.GetTextContent().expect("Element.textContent must be a string");
let sheet = Stylesheet::from_str(&data, url, Origin::Author, win.css_error_reporter());
let LayoutChan(ref layout_chan) = win.layout_chan();
layout_chan.send(Msg::AddStylesheet(sheet.clone())).unwrap();
*self.stylesheet.borrow_mut() = Some(sheet);
Expand Down
17 changes: 13 additions & 4 deletions components/script/dom/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ use net_traits::storage_task::{StorageTask, StorageType};
use num::traits::ToPrimitive;
use page::Page;
use profile_traits::mem;
use reporter::CSSErrorReporter;
use rustc_serialize::base64::{FromBase64, STANDARD, ToBase64};
use script_task::{ScriptChan, ScriptPort, MainThreadScriptMsg, RunnableWrapper};
use script_task::{SendableMainThreadScriptChan, MainThreadScriptChan};
Expand All @@ -69,6 +70,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::TryRecvError::{Disconnected, Empty};
use std::sync::mpsc::{Sender, channel};
use string_cache::Atom;
use style_traits::ParseErrorReporter;
use time;
use timers::{ActiveTimers, IsInterval, ScheduledCallback, TimerCallback, TimerHandle};
use url::Url;
Expand Down Expand Up @@ -211,10 +213,14 @@ pub struct Window {
current_state: Cell<WindowState>,

current_viewport: Cell<Rect<Au>>,
<<<<<<< HEAD

/// A flag to prevent async events from attempting to interact with this window.
#[ignore_heap_size_of = "defined in std"]
ignore_further_async_events: Arc<AtomicBool>,
=======
error_reporter: CSSErrorReporter,
>>>>>>> ddc0843... Code changes based on review
}

impl Window {
Expand Down Expand Up @@ -288,6 +294,10 @@ impl Window {
pub fn storage_task(&self) -> StorageTask {
self.storage_task.clone()
}

pub fn css_error_reporter(&self) -> Box<ParseErrorReporter + Send> {
return self.error_reporter.clone();
}
}

// https://html.spec.whatwg.org/multipage/#atob
Expand Down Expand Up @@ -1238,7 +1248,7 @@ impl Window {
lchan.send(Msg::GetRPC(rpc_send)).unwrap();
rpc_recv.recv().unwrap()
};

let error_reporter = CSSErrorReporter;
let win = box Window {
eventtarget: EventTarget::new_inherited(),
script_chan: script_chan,
Expand Down Expand Up @@ -1282,9 +1292,8 @@ impl Window {
devtools_marker_sender: DOMRefCell::new(None),
devtools_markers: DOMRefCell::new(HashSet::new()),
devtools_wants_updates: Cell::new(false),
webdriver_script_chan: DOMRefCell::new(None),

ignore_further_async_events: Arc::new(AtomicBool::new(false)),
webdriver_script_chan: RefCell::new(None),
error_reporter: error_reporter
};

WindowBinding::Wrap(runtime.cx(), win)
Expand Down

0 comments on commit 47bceb8

Please sign in to comment.