From 8c477c0e33c2472f4fd8a13ec271fe276356f6ae Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E4=BE=9D=E4=BA=91?= Date: Thu, 29 Mar 2018 02:35:58 +0800 Subject: [PATCH] Replace removed nsIDOMXULDocument (#913) --- extension/lib/commands-frame.coffee | 8 +++----- extension/lib/events-frame.coffee | 4 +--- extension/lib/markable-elements.coffee | 3 +-- extension/lib/utils.coffee | 8 +++++--- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/extension/lib/commands-frame.coffee b/extension/lib/commands-frame.coffee index 24656a1..0b0595a 100644 --- a/extension/lib/commands-frame.coffee +++ b/extension/lib/commands-frame.coffee @@ -13,8 +13,6 @@ viewportUtils = require('./viewport') {FORWARD, BACKWARD} = SelectionManager {isProperLink, isTextInputElement, isTypingElement, isContentEditable} = utils -XULDocument = Ci.nsIDOMXULDocument - # CLICKABLE_ARIA_ROLES = [ 'link', 'button', 'tab' @@ -141,7 +139,7 @@ commands.scroll_to_position = (args) -> helper_follow = (options, matcher, {vim, pass}) -> {id, combine = true, selectors = FOLLOW_DEFAULT_SELECTORS} = options - if vim.content.document instanceof XULDocument + if utils.isXULDocument(vim.content.document) selectors = ['*'] if pass == 'auto' @@ -242,7 +240,7 @@ commands.follow = helper_follow.bind( null, {id: 'normal'}, ({vim, element, getElementShape}) -> document = element.ownerDocument - isXUL = (document instanceof XULDocument) + isXUL = utils.isXULDocument(document) type = null switch # Bootstrap. Match these before regular links, because especially slider @@ -405,7 +403,7 @@ commands.click_marker_element = ( if type == 'clickable-special' element.click() else - isXUL = (element.ownerDocument instanceof XULDocument) + isXUL = utils.isXULDocument(element.ownerDocument) sequence = switch when isXUL if element.localName == 'tab' then ['mousedown'] else 'click-xul' diff --git a/extension/lib/events-frame.coffee b/extension/lib/events-frame.coffee index 4f2bcb5..6d4228c 100644 --- a/extension/lib/events-frame.coffee +++ b/extension/lib/events-frame.coffee @@ -9,8 +9,6 @@ utils = require('./utils') nsIFocusManager = Cc['@mozilla.org/focus-manager;1'] .getService(Ci.nsIFocusManager) -XULDocument = Ci.nsIDOMXULDocument - class FrameEventManager constructor: (@vim) -> @numFocusToSuppress = 0 @@ -247,7 +245,7 @@ class FrameEventManager # …and the target may steal most keystrokes… utils.isTypingElement(target) and # …and the page isn’t a Firefox internal page (like `about:config`). - @vim.content.document not instanceof XULDocument + not utils.isXULDocument(@vim.content.document) # Some sites (such as icloud.com) re-focuses inputs if they are blurred, # causing an infinite loop of autofocus prevention and re-focusing. # Therefore, blur events that happen just after an autofocus prevention diff --git a/extension/lib/markable-elements.coffee b/extension/lib/markable-elements.coffee index bb478c5..325e617 100644 --- a/extension/lib/markable-elements.coffee +++ b/extension/lib/markable-elements.coffee @@ -6,7 +6,6 @@ viewportUtils = require('./viewport') {devtools} = Cu.import('resource://devtools/shared/Loader.jsm', {}) Element = Ci.nsIDOMElement -XULDocument = Ci.nsIDOMXULDocument MIN_TEXTNODE_SIZE = 4 @@ -57,7 +56,7 @@ getMarkableElements = ( return getAllElements = (document, selector) -> - unless document instanceof XULDocument + unless utils.isXULDocument(document) return document.querySelectorAll(selector) # Use a `Set` since this algorithm may find the same element more than once. diff --git a/extension/lib/utils.coffee b/extension/lib/utils.coffee index 823ba1a..d805af9 100644 --- a/extension/lib/utils.coffee +++ b/extension/lib/utils.coffee @@ -25,12 +25,14 @@ nsIDomUtils = # For XUL, `instanceof` checks are often better than `.localName` checks, # because some of the below interfaces are extended by many elements. -XULDocument = Ci.nsIDOMXULDocument XULButtonElement = Ci.nsIDOMXULButtonElement XULControlElement = Ci.nsIDOMXULControlElement XULMenuListElement = Ci.nsIDOMXULMenuListElement XULTextBoxElement = Ci.nsIDOMXULTextBoxElement +isXULDocument = (doc) -> + doc.toString() == '[object XULDocument]' + # Full chains of events for different mouse actions. Note: 'click' is fired # by Firefox automatically after 'mousedown' and 'mouseup'. Similarly, # 'command' is fired automatically after 'click' on xul pages. @@ -144,7 +146,7 @@ isProperLink = (element) -> # href="">`s used as buttons on some sites. return element.getAttribute?('href') and (element.localName == 'a' or - element.ownerDocument instanceof XULDocument) and + isXULDocument(element.ownerDocument)) and not element.href?.endsWith?('#') and not element.href?.endsWith?('#?') and not element.href?.startsWith?('javascript:') @@ -687,7 +689,7 @@ observe = (topic, observer) -> # Try to open a button’s dropdown menu, if any. openDropdown = (element) -> - if element.ownerDocument instanceof XULDocument and + if isXULDocument(element.ownerDocument) and element.getAttribute?('type') == 'menu' and element.open == false # Only change `.open` if it is already a boolean. element.open = true -- 2.39.3