From 57face35d18e841b3894e3c2c258e7dabca76153 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Mon, 7 Mar 2016 09:14:28 +0100 Subject: [PATCH] Improve click simulation - Don't leak 'command' events to web pages. They're only needed for XUL. - Don't generate 'mousedown' and 'mouseup' when simlating clicks for browser UI elements. They seem to sometimes trigger some buttons' actions twice. It also caused background tabs to be selected before closed when clicking on their close button, which caused the selected tab to change. However, an exception had to be made for tabs. 'mousedown' seems to be the only relevant event there. --- extension/lib/commands-frame.coffee | 3 ++- extension/lib/commands.coffee | 7 ++++++- extension/lib/utils.coffee | 15 ++++++++++----- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/extension/lib/commands-frame.coffee b/extension/lib/commands-frame.coffee index 700ab34..d9c2ee8 100644 --- a/extension/lib/commands-frame.coffee +++ b/extension/lib/commands-frame.coffee @@ -297,7 +297,8 @@ commands.click_marker_element = (args) -> if type == 'clickable-special' element.click() else - utils.simulateMouseEvents(element, 'click') + isXUL = (element.ownerDocument instanceof XULDocument) + utils.simulateMouseEvents(element, if isXUL then 'click-xul' else 'click') element.target = targetReset if targetReset commands.copy_marker_element = ({vim, elementIndex, property}) -> diff --git a/extension/lib/commands.coffee b/extension/lib/commands.coffee index 985583b..ed1a0bc 100644 --- a/extension/lib/commands.coffee +++ b/extension/lib/commands.coffee @@ -519,8 +519,13 @@ commands.click_browser_element = ({vim}) -> when 'scrollable' utils.focusElement(element, {flag: 'FLAG_BYKEY'}) when 'clickable' + sequence = + if element.classList?.contains('tabbrowser-tab') + ['mousedown'] + else + 'click-xul' utils.focusElement(element) - utils.simulateMouseEvents(element, 'click') + utils.simulateMouseEvents(element, sequence) {wrappers, viewport} = hints.getMarkableElementsAndViewport(vim.window, filter) diff --git a/extension/lib/utils.coffee b/extension/lib/utils.coffee index ba2e8f8..9044c97 100644 --- a/extension/lib/utils.coffee +++ b/extension/lib/utils.coffee @@ -44,9 +44,10 @@ XULControlElement = Ci.nsIDOMXULControlElement XULMenuListElement = Ci.nsIDOMXULMenuListElement XULTextBoxElement = Ci.nsIDOMXULTextBoxElement -# Full chains of events for different mouse actions. ('command' is for XUL -# elements.) -EVENTS_CLICK = ['mousedown', 'mouseup', 'click', 'command'] +# Full chains of events for different mouse actions. Note: 'mouseup' is actually +# fired before 'click'! +EVENTS_CLICK = ['mousedown', 'mouseup', 'click'] +EVENTS_CLICK_XUL = ['click', 'command'] EVENTS_HOVER_START = ['mouseover', 'mouseenter', 'mousemove'] EVENTS_HOVER_END = ['mouseout', 'mouseleave'] @@ -259,17 +260,21 @@ suppressEvent = (event) -> event.preventDefault() event.stopPropagation() -simulateMouseEvents = (element, sequenceType) -> +simulateMouseEvents = (element, sequence) -> window = element.ownerGlobal rect = element.getBoundingClientRect() - eventSequence = switch sequenceType + eventSequence = switch sequence when 'click' EVENTS_CLICK + when 'click-xul' + EVENTS_CLICK_XUL when 'hover-start' EVENTS_HOVER_START when 'hover-end' EVENTS_HOVER_END + else + sequence for type in eventSequence buttonNum = if type in EVENTS_CLICK then 1 else 0 -- 2.39.3