diff options
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/document.rs | 6 | ||||
-rw-r--r-- | components/script/dom/window.rs | 58 |
2 files changed, 55 insertions, 9 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 059f568f873..8bd32de323d 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -56,7 +56,7 @@ use dom::processinginstruction::ProcessingInstruction; use dom::range::Range; use dom::treewalker::TreeWalker; use dom::uievent::UIEvent; -use dom::window::{Window, WindowHelpers}; +use dom::window::{Window, WindowHelpers, ReflowReason}; use layout_interface::{HitTestResponse, MouseOverResponse}; use msg::compositor_msg::ScriptListener; @@ -523,7 +523,7 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> { el.authentic_click_activation(event); self.commit_focus_transaction(); - window.r().reflow(ReflowGoal::ForDisplay, ReflowQueryType::NoQuery); + window.r().reflow(ReflowGoal::ForDisplay, ReflowQueryType::NoQuery, ReflowReason::MouseEvent); } /// Return need force reflow or not @@ -664,7 +664,7 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> { _ => () } - window.r().reflow(ReflowGoal::ForDisplay, ReflowQueryType::NoQuery); + window.r().reflow(ReflowGoal::ForDisplay, ReflowQueryType::NoQuery, ReflowReason::KeyEvent); } fn set_current_script(self, script: Option<JSRef<HTMLScriptElement>>) { diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 29551114315..1babbfcb2cd 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -41,6 +41,7 @@ use net::image_cache_task::ImageCacheTask; use net::resource_task::ResourceTask; use net::storage_task::StorageTask; use util::geometry::{self, Au, MAX_RECT}; +use util::opts; use util::str::{DOMString,HTML_SPACE_CHARACTERS}; use geom::{Point2D, Rect, Size2D}; @@ -63,6 +64,19 @@ use std::sync::mpsc::{channel, Receiver}; use std::sync::mpsc::TryRecvError::{Empty, Disconnected}; use time; +/// Extra information concerning the reason for reflowing. +pub enum ReflowReason { + CachedPageNeededReflow, + FirstLoad, + KeyEvent, + MouseEvent, + Query, + ReceivedReflowEvent, + Timer, + Viewport, + WindowResize, +} + #[dom_struct] pub struct Window { eventtarget: EventTarget, @@ -397,7 +411,7 @@ pub trait WindowHelpers { fn init_browser_context(self, doc: JSRef<Document>, frame_element: Option<JSRef<Element>>); fn load_url(self, href: DOMString); fn handle_fire_timer(self, timer_id: TimerId); - fn reflow(self, goal: ReflowGoal, query_type: ReflowQueryType); + fn reflow(self, goal: ReflowGoal, query_type: ReflowQueryType, reason: ReflowReason); fn join_layout(self); fn layout(&self) -> &LayoutRPC; fn content_box_query(self, content_box_request: TrustedNodeAddress) -> Rect<Au>; @@ -480,7 +494,7 @@ impl<'a> WindowHelpers for JSRef<'a, Window> { /// yet, the page is presumed invisible and no reflow is performed. /// /// TODO(pcwalton): Only wait for style recalc, since we have off-main-thread layout. - fn reflow(self, goal: ReflowGoal, query_type: ReflowQueryType) { + fn reflow(self, goal: ReflowGoal, query_type: ReflowQueryType, reason: ReflowReason) { let document = self.Document().root(); let root = document.r().GetDocumentElement().root(); let root = match root.r() { @@ -511,6 +525,11 @@ impl<'a> WindowHelpers for JSRef<'a, Window> { let window_size = self.window_size.get(); + // On debug mode, print the reflow event information. + if opts::get().relayout_event { + debug_reflow_events(&goal, &query_type, &reason); + } + // Send new document and relevant styles to layout. let reflow = box Reflow { document_root: root.to_trusted_node_address(), @@ -562,14 +581,14 @@ impl<'a> WindowHelpers for JSRef<'a, Window> { } fn content_box_query(self, content_box_request: TrustedNodeAddress) -> Rect<Au> { - self.reflow(ReflowGoal::ForScriptQuery, ReflowQueryType::ContentBoxQuery(content_box_request)); + self.reflow(ReflowGoal::ForScriptQuery, ReflowQueryType::ContentBoxQuery(content_box_request), ReflowReason::Query); self.join_layout(); //FIXME: is this necessary, or is layout_rpc's mutex good enough? let ContentBoxResponse(rect) = self.layout_rpc.content_box(); rect } fn content_boxes_query(self, content_boxes_request: TrustedNodeAddress) -> Vec<Rect<Au>> { - self.reflow(ReflowGoal::ForScriptQuery, ReflowQueryType::ContentBoxesQuery(content_boxes_request)); + self.reflow(ReflowGoal::ForScriptQuery, ReflowQueryType::ContentBoxesQuery(content_boxes_request), ReflowReason::Query); self.join_layout(); //FIXME: is this necessary, or is layout_rpc's mutex good enough? let ContentBoxesResponse(rects) = self.layout_rpc.content_boxes(); rects @@ -609,7 +628,7 @@ impl<'a> WindowHelpers for JSRef<'a, Window> { fn handle_fire_timer(self, timer_id: TimerId) { self.timers.fire_timer(timer_id, self); - self.reflow(ReflowGoal::ForDisplay, ReflowQueryType::NoQuery); + self.reflow(ReflowGoal::ForDisplay, ReflowQueryType::NoQuery, ReflowReason::Timer); } fn set_fragment_name(self, fragment: Option<String>) { @@ -715,7 +734,6 @@ impl<'a> WindowHelpers for JSRef<'a, Window> { fn freeze(self) { self.timers.suspend(); } - } impl Window { @@ -798,3 +816,31 @@ fn should_move_clip_rect(clip_rect: Rect<Au>, new_viewport: Rect<f32>) -> bool{ (clip_rect.origin.y - new_viewport.origin.y).abs() <= viewport_scroll_margin.height || (clip_rect.max_y() - new_viewport.max_y()).abs() <= viewport_scroll_margin.height } + +fn debug_reflow_events(goal: &ReflowGoal, query_type: &ReflowQueryType, reason: &ReflowReason) { + let mut debug_msg = String::from_str("****"); + match *goal { + ReflowGoal::ForDisplay => debug_msg.push_str("\tForDisplay"), + ReflowGoal::ForScriptQuery => debug_msg.push_str("\tForScriptQuery"), + } + + match *query_type { + ReflowQueryType::NoQuery => debug_msg.push_str("\tNoQuery"), + ReflowQueryType::ContentBoxQuery(_n) => debug_msg.push_str("\tContentBoxQuery"), + ReflowQueryType::ContentBoxesQuery(_n) => debug_msg.push_str("\tContentBoxesQuery"), + } + + match *reason { + ReflowReason::CachedPageNeededReflow => debug_msg.push_str("\tCachedPageNeededReflow"), + ReflowReason::FirstLoad => debug_msg.push_str("\tFirstLoad"), + ReflowReason::KeyEvent => debug_msg.push_str("\tKeyEvent"), + ReflowReason::MouseEvent => debug_msg.push_str("\tMouseEvent"), + ReflowReason::Query => debug_msg.push_str("\tQuery"), + ReflowReason::ReceivedReflowEvent => debug_msg.push_str("\tReceivedReflowEvent"), + ReflowReason::Timer => debug_msg.push_str("\tTimer"), + ReflowReason::Viewport => debug_msg.push_str("\tViewport"), + ReflowReason::WindowResize => debug_msg.push_str("\tWindowResize"), + } + + println!("{}", debug_msg); +} |