From 267f562f2ed087419a6484aa9f2ecac020fc9fbd Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Mon, 13 Jun 2016 18:35:04 +0200 Subject: [PATCH] Improve click simulation of XUL elements - Use `.click()` when possible for the `zF` command as it seems to work with more buttons than simulating events the regular VimFx way. - Add extra code for activating XUL dropdown menus. - Make it possible to use `zF` to activate VimFx's own button. - Finally make it possible to click the gear icon in the Add-ons Manager using `f`. Fixes #759. --- extension/lib/commands-frame.coffee | 1 + extension/lib/commands.coffee | 26 +++++++++++++++++++------- extension/lib/utils.coffee | 8 ++++++++ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/extension/lib/commands-frame.coffee b/extension/lib/commands-frame.coffee index 3bfa986..edddc33 100644 --- a/extension/lib/commands-frame.coffee +++ b/extension/lib/commands-frame.coffee @@ -358,6 +358,7 @@ commands.click_marker_element = ( else 'click' utils.simulateMouseEvents(element, sequence) + utils.openDropdown(element) 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 c2912a5..a3cb164 100644 --- a/extension/lib/commands.coffee +++ b/extension/lib/commands.coffee @@ -601,13 +601,25 @@ commands.click_browser_element = ({vim}) -> when 'scrollable' utils.focusElement(element, {flag: 'FLAG_BYKEY'}) when 'clickable', 'complementary' - sequence = - if element.localName == 'tab' - ['mousedown'] - else - 'click-xul' - utils.focusElement(element) - utils.simulateMouseEvents(element, sequence) + # VimFx’s own button won’t trigger unless the click is simulated in the + # next tick. This might be true for other buttons as well. + utils.nextTick(window, -> + utils.focusElement(element) + switch + when element.localName == 'tab' + # Only 'mousedown' seems to be able to activate tabs. + utils.simulateMouseEvents(element, ['mousedown']) + when element.closest('tab') + # If `.click()` is used on a tab close button, its tab will be + # selected first, which might cause the selected tab to change. + utils.simulateMouseEvents(element, 'click-xul') + else + # `.click()` seems to trigger more buttons (such as NoScript’s + # button and Firefox’s “hamburger” menu button) than simulating + # 'click-xul'. + element.click() + utils.openDropdown(element) + ) return false wrappers = markableElements.find( diff --git a/extension/lib/utils.coffee b/extension/lib/utils.coffee index 94bcfd7..ee8f939 100644 --- a/extension/lib/utils.coffee +++ b/extension/lib/utils.coffee @@ -560,6 +560,13 @@ observe = (topic, observer) -> Services.obs.removeObserver(observer, topic, false) ) +# Try to open a button’s dropdown menu, if any. +openDropdown = (element) -> + if element.ownerDocument instanceof XULDocument and + element.getAttribute?('type') == 'menu' and + element.open == false # Only change `.open` if it is already a boolean. + element.open = true + openPopup = (popup) -> window = popup.ownerGlobal # Show the popup so it gets a height and width. @@ -632,6 +639,7 @@ module.exports = { hasEventListeners loadCss observe + openDropdown openPopup writeToClipboard } -- 2.39.3