script: Stop destroying all flows on every mouse-over event.

This commit is contained in:
Patrick Walton 2015-03-27 19:00:31 -07:00
parent afbc51a746
commit 1fe55a27b1
2 changed files with 17 additions and 13 deletions

View file

@ -219,9 +219,13 @@ pub trait DocumentHelpers<'a> {
fn handle_click_event(self, js_runtime: *mut JSRuntime, _button: uint, point: Point2D<f32>); fn handle_click_event(self, js_runtime: *mut JSRuntime, _button: uint, point: Point2D<f32>);
fn dispatch_key_event(self, key: Key, state: KeyState, fn dispatch_key_event(self, key: Key, state: KeyState,
modifiers: KeyModifiers, compositor: &mut Box<ScriptListener+'static>); modifiers: KeyModifiers, compositor: &mut Box<ScriptListener+'static>);
/// Return need force reflow or not
fn handle_mouse_move_event(self, js_runtime: *mut JSRuntime, point: Point2D<f32>, /// Handles a mouse-move event coming from the compositor.
prev_mouse_over_targets: &mut Vec<JS<Node>>) -> bool; fn handle_mouse_move_event(self,
js_runtime: *mut JSRuntime,
point: Point2D<f32>,
prev_mouse_over_targets: &mut Vec<JS<Node>>);
fn set_current_script(self, script: Option<JSRef<HTMLScriptElement>>); fn set_current_script(self, script: Option<JSRef<HTMLScriptElement>>);
fn trigger_mozbrowser_event(self, event: MozBrowserEvent); fn trigger_mozbrowser_event(self, event: MozBrowserEvent);
} }
@ -538,10 +542,10 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> {
window.r().reflow(ReflowGoal::ForDisplay, ReflowQueryType::NoQuery, ReflowReason::MouseEvent); window.r().reflow(ReflowGoal::ForDisplay, ReflowQueryType::NoQuery, ReflowReason::MouseEvent);
} }
/// Return need force reflow or not fn handle_mouse_move_event(self,
fn handle_mouse_move_event(self, js_runtime: *mut JSRuntime, point: Point2D<f32>, js_runtime: *mut JSRuntime,
prev_mouse_over_targets: &mut Vec<JS<Node>>) -> bool { point: Point2D<f32>,
let mut needs_reflow = false; prev_mouse_over_targets: &mut Vec<JS<Node>>) {
// Build a list of elements that are currently under the mouse. // Build a list of elements that are currently under the mouse.
let mouse_over_addresses = self.get_nodes_under_mouse(&point); let mouse_over_addresses = self.get_nodes_under_mouse(&point);
let mouse_over_targets: Vec<JS<Node>> = mouse_over_addresses.iter() let mouse_over_targets: Vec<JS<Node>> = mouse_over_addresses.iter()
@ -555,7 +559,6 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> {
for target in prev_mouse_over_targets.iter() { for target in prev_mouse_over_targets.iter() {
if !mouse_over_targets.contains(target) { if !mouse_over_targets.contains(target) {
target.root().r().set_hover_state(false); target.root().r().set_hover_state(false);
needs_reflow = true;
} }
} }
@ -567,7 +570,6 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> {
let target_ref = target.r(); let target_ref = target.r();
if !target_ref.get_hover_state() { if !target_ref.get_hover_state() {
target_ref.set_hover_state(true); target_ref.set_hover_state(true);
needs_reflow = true;
} }
} }
@ -598,7 +600,11 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> {
// Store the current mouse over targets for next frame // Store the current mouse over targets for next frame
*prev_mouse_over_targets = mouse_over_targets; *prev_mouse_over_targets = mouse_over_targets;
needs_reflow
let window = self.window.root();
window.r().reflow(ReflowGoal::ForDisplay,
ReflowQueryType::NoQuery,
ReflowReason::MouseEvent);
} }
/// The entry point for all key processing for web content /// The entry point for all key processing for web content

View file

@ -1218,9 +1218,7 @@ impl ScriptTask {
let document = page.document().root(); let document = page.document().root();
let mouse_over_targets = &mut *self.mouse_over_targets.borrow_mut(); let mouse_over_targets = &mut *self.mouse_over_targets.borrow_mut();
if document.r().handle_mouse_move_event(self.js_runtime.ptr, point, mouse_over_targets) { document.r().handle_mouse_move_event(self.js_runtime.ptr, point, mouse_over_targets);
self.force_reflow(&page, ReflowReason::MouseEvent)
}
} }
KeyEvent(key, state, modifiers) => { KeyEvent(key, state, modifiers) => {