1 # This file contains lots of different helper functions.
3 {PlacesUIUtils} = ChromeUtils
4 .importESModule('resource:///modules/PlacesUIUtils.sys.mjs')
5 {PrivateBrowsingUtils} = ChromeUtils
6 .importESModule('resource://gre/modules/PrivateBrowsingUtils.sys.mjs')
7 {WebNavigationFrames} = ChromeUtils
8 .importESModule('resource://gre/modules/WebNavigationFrames.sys.mjs')
10 nsIClipboardHelper = Cc['@mozilla.org/widget/clipboardhelper;1']
11 .getService(Ci.nsIClipboardHelper)
12 nsIEventListenerService = Cc['@mozilla.org/eventlistenerservice;1']
13 .getService(Ci.nsIEventListenerService)
14 nsIFocusManager = Cc['@mozilla.org/focus-manager;1']
15 .getService(Ci.nsIFocusManager)
16 nsIStyleSheetService = Cc['@mozilla.org/content/style-sheet-service;1']
17 .getService(Ci.nsIStyleSheetService)
18 nsIWindowMediator = Cc['@mozilla.org/appshell/window-mediator;1']
19 .getService(Ci.nsIWindowMediator)
21 # For XUL, `instanceof` checks are often better than `.localName` checks,
22 # because some of the below interfaces are extended by many elements.
23 XULButtonElement = Ci.nsIDOMXULButtonElement
24 XULControlElement = Ci.nsIDOMXULControlElement
25 XULMenuListElement = Ci.nsIDOMXULMenuListElement
27 # Traverse the DOM upwards until we hit its containing document or the
29 getDocument = (e) -> if e.parentNode? then arguments.callee(e.parentNode) else e
31 isInShadowRoot = (element) ->
32 getDocument(element) instanceof element.ownerGlobal.ShadowRoot
34 isXULElement = (element) ->
35 XUL_NS = 'http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul'
36 element.namespaceURI == XUL_NS
38 # Full chains of events for different mouse actions. Note: 'click' is fired
39 # by Firefox automatically after 'mousedown' and 'mouseup'. Similarly,
40 # 'command' is fired automatically after 'click' on xul pages.
41 EVENTS_CLICK = ['mousedown', 'mouseup']
42 EVENTS_CLICK_XUL = ['click']
43 EVENTS_CONTEXT = ['contextmenu']
44 EVENTS_HOVER_START = ['mouseover', 'mouseenter', 'mousemove']
45 EVENTS_HOVER_END = ['mouseout', 'mouseleave']
49 # Element classification helpers
51 hasMarkableTextNode = (element) ->
52 return Array.prototype.some.call(element.childNodes, (node) ->
53 # Ignore whitespace-only text nodes, and single-letter ones (which are
54 # common in many syntax highlighters).
55 return node.nodeType == 3 and node.data.trim().length > 1
58 isActivatable = (element) ->
59 return element.localName in ['a', 'button'] or
60 (element.localName == 'input' and element.type in [
61 'button', 'submit', 'reset', 'image'
63 element instanceof XULButtonElement
65 isAdjustable = (element) ->
66 return element.localName == 'input' and element.type in [
67 'checkbox', 'radio', 'file', 'color'
68 'date', 'time', 'datetime', 'datetime-local', 'month', 'week'
70 element.localName in ['video', 'audio', 'embed', 'object'] or
71 element instanceof XULControlElement or
72 # Custom video players.
73 includes(element.className, 'video') or
74 includes(element.className, 'player') or
75 # Youtube special case.
76 element.classList?.contains('ytp-button') or
77 # Allow navigating object inspection trees in th devtools with the
78 # arrow keys, even if the arrow keys are used as VimFx shortcuts.
79 isDevtoolsElement(element)
81 isContentEditable = (element) ->
82 return element.isContentEditable or
83 isIframeEditor(element) or
85 element.getAttribute?('g_editable') == 'true' or
86 element.ownerDocument?.body?.getAttribute?('g_editable') == 'true' or
87 # Codeacademy terminals.
88 element.classList?.contains('real-terminal')
90 isDevtoolsElement = (element) ->
91 return false unless element.ownerGlobal
92 return Array.prototype.some.call(
93 element.ownerGlobal.top.frames, isDevtoolsWindow
96 isDevtoolsWindow = (window) ->
97 # Note: this function is called for each frame by isDevtoolsElement. When
98 # called on an out-of-process iframe, accessing .href will fail with
99 # SecurityError; the `try` around it makes it `undefined` in such a case.
100 return (try window.location?.href) in [
101 'about:devtools-toolbox'
102 'chrome://devtools/content/framework/toolbox.xhtml'
105 # Note: this is possibly a bit overzealous, but Works For Now™.
106 isDockedDevtoolsElement = (element) ->
107 return element.ownerDocument.URL.startsWith('chrome://devtools/content/')
109 isFocusable = (element) ->
110 # Focusable elements have `.tabIndex > 1` (but not necessarily a
111 # `tabindex="…"` attribute) …
112 return (element.tabIndex > -1 or
113 # … or an explicit `tabindex="-1"` attribute (which means that it is
114 # focusable, but not reachable with `<tab>`).
115 element.getAttribute?('tabindex') == '-1') and
116 not (element.localName?.endsWith?('box') and
117 element.localName != 'checkbox') and
118 not (element.localName == 'toolbarbutton' and
119 element.parentNode?.localName == 'toolbarbutton') and
120 element.localName not in ['tabs', 'menuitem', 'menuseparator']
122 isIframeEditor = (element) ->
123 return false unless element.localName == 'body'
126 element.id == 'innerdocbody' or
128 (element.classList?.contains('xe_content') and
129 element.classList?.contains('editable')) or
131 element.classList?.contains('wysiwyg') or
133 element.classList?.contains('htmlarea-content-body') or
134 # The wasavi extension.
135 element.hasAttribute?('data-wasavi-state')
137 isIgnoreModeFocusType = (element) ->
139 # The wasavi extension.
140 element.hasAttribute?('data-wasavi-state') or
141 element.closest?('#wasavi_container') or
142 # CodeMirror in Vim mode.
143 (element.localName == 'textarea' and
144 element.closest?('.CodeMirror') and _hasVimEventListener(element))
146 # CodeMirror’s Vim mode is really sucky to detect. The only way seems to be to
147 # check if the there are any event listener functions with Vim-y words in them.
148 _hasVimEventListener = (element) ->
149 for listener in nsIEventListenerService.getListenerInfoFor(element)
150 if listener.listenerObject and
151 /\bvim\b|insertmode/i.test(String(listener.listenerObject))
155 isProperLink = (element) ->
156 # `.getAttribute` is used below instead of `.hasAttribute` to exclude `<a
157 # href="">`s used as buttons on some sites.
158 return element.getAttribute?('href') and
159 (element.localName == 'a' or
160 (isXULElement(element) and
161 element.localName == 'label' and
162 element.getAttribute('is') == 'text-link')) and
163 not element.href?.endsWith?('#') and
164 not element.href?.endsWith?('#?') and
165 not element.href?.startsWith?('javascript:')
167 isTextInputElement = (element) ->
168 return (element.localName == 'input' and element.type in [
169 'text', 'search', 'tel', 'url', 'email', 'password', 'number'
171 element.localName in [ 'textarea', 'textbox' ] or
172 isContentEditable(element)
174 isTypingElement = (element) ->
175 return isTextInputElement(element) or
176 # `<select>` elements can also receive text input: You may type the
177 # text of an item to select it.
178 element.localName == 'select' or
179 element instanceof XULMenuListElement
183 # Active/focused element helpers
185 blurActiveBrowserElement = (vim) ->
186 # - Blurring in the next tick allows to pass `<escape>` to the location bar to
187 # reset it, for example.
188 # - Focusing the current browser afterwards allows to pass `<escape>` as well
189 # as unbound keys to the page. However, focusing the browser also triggers
190 # focus events on `document` and `window` in the current page. Many pages
191 # re-focus some text input on those events, making it impossible to blur
192 # those! Therefore we tell the frame script to suppress those events.
194 activeElement = getActiveElement(window)
195 activeElement.closest('tabmodalprompt')?.abortPrompt()
196 vim._send('browserRefocus')
199 window.gBrowser.selectedBrowser.focus()
202 blurActiveElement = (window) ->
203 # Blurring a frame element also blurs any active elements inside it. Recursing
204 # into the frames and blurring the “real” active element directly would give
205 # focus to the `<body>` of its containing frame, while blurring the top-most
206 # frame gives focus to the top-most `<body>`. This allows to blur fancy text
207 # editors which use an `<iframe>` as their text area.
208 # Note that this trick does not work with Web Components; for them, recursing
210 if window.document.activeElement?.shadowRoot?
211 return getActiveElement(window)?.blur()
212 window.document.activeElement?.blur()
214 # Focus an element and tell Firefox that the focus happened because of a user
215 # action (not just because some random programmatic focus). `.FLAG_BYKEY` might
216 # look more appropriate, but it unconditionally selects all text, which
217 # `.FLAG_BYMOUSE` does not.
218 focusElement = (element, options = {}) ->
219 nsIFocusManager.setFocus(element, options.flag ? 'FLAG_BYMOUSE')
220 element.select?() if options.select
222 # NOTE: In frame scripts, `document.activeElement` may be `null` when the page
223 # is loading. Therefore always check if anything was returned, such as:
225 # return unless activeElement = utils.getActiveElement(window)
226 getActiveElement = (window) ->
227 {activeElement} = window.shadowRoot or window.document
228 return null unless activeElement
229 # If the active element is a frame, recurse into it. The easiest way to detect
230 # a frame that works both in browser UI and in web page content is to check
231 # for the presence of `.contentWindow`. However, in non-multi-process,
232 # `<browser>` (sometimes `<xul:browser>`) elements have a `.contentWindow`
233 # pointing to the web page content `window`, which we don’t want to recurse
234 # into. The problem is that there are _some_ `<browser>`s which we _want_ to
235 # recurse into, such as the sidebar (for instance the history sidebar), and
236 # dialogs in `about:preferences`. Checking the `contextmenu` attribute seems
237 # to be a reliable test, catching both the main tab `<browser>`s and bookmarks
238 # opened in the sidebar.
239 # We also want to recurse into the (open) shadow DOM of custom elements.
240 if activeElement.shadowRoot?
241 return getActiveElement(activeElement)
242 else if activeElement.contentWindow and
243 not (activeElement.localName == 'browser' and
244 activeElement.getAttribute?('contextmenu') == 'contentAreaContextMenu')
245 # with Fission enabled, the iframe might be located in a different process
246 # (oop). Then, recursing into it isn't possible (throws SecurityError).
247 return activeElement unless (try activeElement.contentWindow.document)
249 return getActiveElement(activeElement.contentWindow)
253 getFocusType = (element) -> switch
254 when element.tagName in ['FRAME', 'IFRAME'] and
255 not (try element.contentWindow.document)
256 # Encountered an out-of-process iframe, which we can't inspect. We fall
257 # back to insert mode, so any text inputs it may contain are still usable.
259 when isIgnoreModeFocusType(element)
261 when isTypingElement(element)
262 if element.closest?('findbar') then 'findbar' else 'editable'
263 when isActivatable(element)
265 when isAdjustable(element)
274 listen = (element, eventName, listener, useCapture = true) ->
275 element.addEventListener(eventName, listener, useCapture)
277 element.removeEventListener(eventName, listener, useCapture)
280 listenOnce = (element, eventName, listener, useCapture = true) ->
283 element.removeEventListener(eventName, fn, useCapture)
284 listen(element, eventName, fn, useCapture)
286 onRemoved = (element, fn) ->
287 window = element.ownerGlobal
291 return if disconnected
293 mutationObserver.disconnect() unless Cu.isDeadWrapper(mutationObserver)
295 mutationObserver = new window.MutationObserver((changes) ->
296 for change in changes then for removedElement in change.removedNodes
297 if removedElement.contains?(element)
302 mutationObserver.observe(window.document.documentElement, {
306 module.onShutdown(disconnect)
310 contentAreaClick = (data, browser) ->
311 # This function is adapted from the same-named one currently in
312 # mozilla-central/browser/actors/ClickHandlerParent.sys.mjs. Keep in sync!
313 # Note: Our version is shortened substantially and unlike Mozilla, we pass in
314 # the browser object instead of extracting it from the browsingContext. Also,
315 # our version is only invoked from the parent process, so we can pass
316 # data.csp and data.referrerInfo without calling the E10SUtils helpers.
317 window = browser.ownerGlobal
318 wgp = window.browsingContext.currentWindowGlobal
321 charset: browser.characterSet,
322 referrerInfo: data.referrerInfo # passed unserialized
323 isContentWindowPrivate: wgp.browsingContext.usePrivateBrowsing,
324 originPrincipal: wgp.documentPrincipal,
325 originStoragePrincipal: wgp.documentStoragePrincipal,
326 triggeringPrincipal: data.triggeringPrincipal,
327 csp: data.csp # passed unserialized
328 frameID: WebNavigationFrames.getFrameId(wgp.browsingContext),
329 allowInheritPrincipal: true,
330 openerBrowser: browser,
331 hasValidUserGestureActivation: true,
332 triggeringRemoteType: browser.browsingContext.currentWindowGlobal
333 .domProcess?.remoteType,
336 if data.originAttributes.userContextId
337 params.userContextId = data.originAttributes.userContextId
339 try if not PrivateBrowsingUtils.isWindowPrivate(window)
340 PlacesUIUtils.markPageAsFollowedLink(data.href)
343 window.BrowserUtils.whereToOpenLink(data) # >=fx127
345 window.whereToOpenLink(data) # <=fx126
346 window.openLinkIn(data.href, where, params)
348 simulateMouseEvents = (element, sequence, browserOffset) ->
349 window = element.ownerGlobal
350 rect = element.getBoundingClientRect()
351 topOffset = getTopOffset(element)
353 eventSequence = switch sequence
367 for type in eventSequence
369 when type in EVENTS_CONTEXT
371 when type in EVENTS_CLICK
376 mouseEvent = new window.MouseEvent(type, {
377 # Let the event bubble in order to trigger delegated event listeners.
378 bubbles: type not in ['mouseenter', 'mouseleave']
379 # Make the event cancelable so that `<a href="#">` can be used as a
380 # JavaScript-powered button without scrolling to the top of the page.
381 cancelable: type not in ['mouseenter', 'mouseleave']
382 # These properties are just here for mimicing a real click as much as
387 # `page{X,Y}` are set automatically to the correct values when setting
388 # `client{X,Y}`. `{offset,layer,movement}{X,Y}` are not worth the trouble
391 clientY: rect.top + rect.height / 2
392 screenX: browserOffset.x + topOffset.x
393 screenY: browserOffset.y + topOffset.y + rect.height / 2
396 if type == 'mousemove'
397 # If the below technique is used for this event, the “URL popup” (shown
398 # when hovering or focusing links) does not appear.
399 element.dispatchEvent(mouseEvent)
400 else if isInShadowRoot(element)
401 # click events for links and other clickables inside the shadow DOM are
402 # caught by the callee (.click_marker_element()).
403 element.focus() if type == 'contextmenu' # for <input type=text>
404 element.dispatchEvent(mouseEvent)
408 .dispatchDOMEventViaPresShellForTesting(element, mouseEvent)
410 if error.result != Cr.NS_ERROR_UNEXPECTED
415 suppressEvent = (event) ->
416 event.preventDefault()
417 event.stopPropagation()
424 return element.clientWidth * element.clientHeight
426 checkElementOrAncestor = (element, fn) ->
427 window = element.ownerGlobal
428 while element.parentElement
429 return true if fn(element)
430 element = element.parentElement
433 clearSelectionDeep = (window, {blur = true} = {}) ->
434 # The selection might be `null` in hidden frames.
435 selection = window.getSelection()
436 selection?.removeAllRanges()
437 # Note: accessing frameElement fails on oop iframes (fission); skip those.
438 for frame in window.frames when (try frame.frameElement)
439 clearSelectionDeep(frame, {blur})
440 # Allow parents to re-gain control of text selection.
441 frame.frameElement.blur() if blur
444 containsDeep = (parent, element) ->
445 parentWindow = parent.ownerGlobal
446 elementWindow = element.ownerGlobal
448 # Owner windows might be missing when opening the devtools.
449 while elementWindow and parentWindow and
450 elementWindow != parentWindow and elementWindow.top != elementWindow
451 element = elementWindow.frameElement
452 elementWindow = element.ownerGlobal
454 return parent.contains(element)
456 createBox = (document, className = '', parent = null, text = null) ->
457 box = document.createElement('box')
458 box.className = "#{className} vimfx-box"
459 box.textContent = text if text?
460 parent.appendChild(box) if parent?
463 # In quirks mode (when the page lacks a doctype), such as on Hackernews,
464 # `<body>` is considered the root element rather than `<html>`.
465 getRootElement = (document) ->
466 if document.compatMode == 'BackCompat' and document.body?
469 return document.documentElement
471 getText = (element) ->
472 text = element.textContent or element.value or element.placeholder or ''
473 return text.trim().replace(/\s+/, ' ')
475 getTopOffset = (element) ->
476 window = element.ownerGlobal
478 {left: x, top: y} = element.getBoundingClientRect()
479 while window.frameElement
480 frame = window.frameElement
481 frameRect = frame.getBoundingClientRect()
485 computedStyle = frame.ownerGlobal.getComputedStyle(frame)
488 parseFloat(computedStyle.getPropertyValue('border-left-width')) +
489 parseFloat(computedStyle.getPropertyValue('padding-left'))
491 parseFloat(computedStyle.getPropertyValue('border-top-width')) +
492 parseFloat(computedStyle.getPropertyValue('padding-top'))
494 window = window.parent
497 injectTemporaryPopup = (document, contents) ->
498 popup = document.createXULElement('menupopup')
499 popup.appendChild(contents)
500 document.getElementById('mainPopupSet').appendChild(popup)
501 listenOnce(popup, 'popuphidden', popup.remove.bind(popup))
504 insertText = (input, value) ->
505 {selectionStart, selectionEnd} = input
507 input.value[0...selectionStart] + value + input.value[selectionEnd..]
508 input.selectionStart = input.selectionEnd = selectionStart + value.length
510 isDetached = (element) ->
511 return not element.ownerDocument?.documentElement?.contains?(element)
513 isNonEmptyTextNode = (node) ->
514 return node.nodeType == 3 and node.data.trim() != ''
516 querySelectorAllDeep = (window, selector) ->
517 elements = Array.from(window.document.querySelectorAll(selector))
518 for frame in window.frames
519 elements.push(querySelectorAllDeep(frame, selector)...)
522 selectAllSubstringMatches = (element, substring, {caseSensitive = true} = {}) ->
523 window = element.ownerGlobal
524 selection = window.getSelection()
525 {textContent} = element
527 format = (string) -> if caseSensitive then string else string.toLowerCase()
529 getAllNonOverlappingRangeOffsets(format(textContent), format(substring))
530 offsetsLength = offsets.length
531 return if offsetsLength == 0
535 [currentOffset] = offsets
536 searchIndex = currentOffset.start
539 walkTextNodes(element, (textNode) ->
540 {length} = textNode.data
541 return false if length == 0
543 while textIndex + length > searchIndex
545 range = window.document.createRange()
546 range.setStart(start.textNode, start.offset)
547 range.setEnd(textNode, currentOffset.end - textIndex)
548 selection.addRange(range)
551 return true if offsetsIndex >= offsetsLength
552 currentOffset = offsets[offsetsIndex]
555 searchIndex = currentOffset.start
558 start = {textNode, offset: currentOffset.start - textIndex}
559 searchIndex = currentOffset.end - 1
565 selectElement = (element) ->
566 window = element.ownerGlobal
567 selection = window.getSelection()
568 range = window.document.createRange()
569 range.selectNodeContents(element)
570 selection.addRange(range)
572 setAttributes = (element, attributes) ->
573 for attribute, value of attributes
574 element.setAttribute(attribute, value)
577 walkTextNodes = (element, fn) ->
578 for node in element.childNodes then switch node.nodeType
583 stop = walkTextNodes(node, fn)
592 constructor: ({start: @value = 0, @step = 1}) ->
593 tick: -> @value += @step
599 on: (event, listener) ->
600 (@listeners[event] ?= new Set()).add(listener)
602 off: (event, listener) ->
603 @listeners[event]?.delete(listener)
605 emit: (event, data) ->
606 @listeners[event]?.forEach((listener) ->
610 # Returns `[nonMatch, adjacentMatchAfter]`, where `adjacentMatchAfter - nonMatch
611 # == 1`. `fn(n)` is supposed to return `false` for `n <= nonMatch` and `true`
612 # for `n >= adjacentMatchAfter`. Both `nonMatch` and `adjacentMatchAfter` may be
613 # `null` if they cannot be found. Otherwise they’re in the range `min <= n <=
614 # max`. `[null, null]` is returned in non-sensical cases. This function is
615 # intended to be used as a faster alternative to something like this:
617 # adjacentMatchAfter = null
618 # for n in [min..max]
620 # adjacentMatchAfter = n
622 bisect = (min, max, fn) ->
623 return [null, null] unless max - min >= 0 and min % 1 == 0 and max % 1 == 0
626 mid = min + (max - min) // 2
637 when matchMin and matchMax
639 when not matchMin and not matchMax
641 when not matchMin and matchMax
646 getAllNonOverlappingRangeOffsets = (string, substring) ->
648 return [] if length == 0
651 lastOffset = {start: -Infinity, end: -Infinity}
655 index = string.indexOf(substring, index + 1)
657 if index > lastOffset.end
658 lastOffset = {start: index, end: index + length}
659 offsets.push(lastOffset)
661 lastOffset.end = index + length
665 has = (obj, prop) -> Object::hasOwnProperty.call(obj, prop)
667 # Check if `search` exists in `string` (case insensitively). Returns `false` if
668 # `string` doesn’t exist or isn’t a string, such as `<SVG element>.className`.
669 includes = (string, search) ->
670 return false unless typeof string == 'string'
671 return string.toLowerCase().includes(search)
673 # Calls `fn` repeatedly, with at least `interval` ms between each call.
674 interval = (window, interval, fn) ->
676 currentIntervalId = null
679 currentIntervalId = window.setTimeout((-> fn(next)), interval)
682 window.clearTimeout(currentIntervalId)
686 nextTick = (window, fn) -> window.setTimeout((-> fn()) , 0)
688 overlaps = (rectA, rectB) ->
690 Math.round(rectA.right) >= Math.round(rectB.left) and
691 Math.round(rectA.left) <= Math.round(rectB.right) and
692 Math.round(rectA.bottom) >= Math.round(rectB.top) and
693 Math.round(rectA.top) <= Math.round(rectB.bottom)
695 partition = (array, fn) ->
698 for item, index in array
699 if fn(item, index, array)
702 nonMatching.push(item)
703 return [matching, nonMatching]
705 regexEscape = (s) -> s.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&')
707 removeDuplicateChars = (string) -> removeDuplicates(string.split('')).join('')
709 removeDuplicates = (array) -> Array.from(new Set(array))
711 sum = (numbers) -> numbers.reduce(((sum, number) -> sum + number), 0)
717 expandPath = (path) ->
718 if path.startsWith('~/') or path.startsWith('~\\')
719 return Services.dirsvc.get('Home', Ci.nsIFile).path + path[1..]
723 getCurrentLocation = ->
724 return unless window = getCurrentWindow()
725 return new window.URL(window.gBrowser.selectedBrowser.currentURI.spec)
727 # This function might return `null` on startup.
728 getCurrentWindow = -> nsIWindowMediator.getMostRecentWindow('navigator:browser')
730 # gBrowser getFindBar() used to return the findBar directly, but in recent
731 # versions it returns a promise. This function should be removed once these old
732 # versions are no longer supported.
733 getFindBar = (gBrowser) ->
734 promiseOrFindBar = gBrowser.getFindBar()
735 if promiseOrFindBar instanceof Promise
738 Promise.resolve(promiseOrFindBar)
740 hasEventListeners = (element, type) ->
741 for listener in nsIEventListenerService.getListenerInfoFor(element)
742 if listener.listenerObject and listener.type == type
746 loadCss = (uriString) ->
747 uri = Services.io.newURI(uriString, null, null)
748 method = nsIStyleSheetService.AUTHOR_SHEET
749 unless nsIStyleSheetService.sheetRegistered(uri, method)
750 nsIStyleSheetService.loadAndRegisterSheet(uri, method)
752 nsIStyleSheetService.unregisterSheet(uri, method)
755 observe = (topic, observer) ->
756 observer = {observe: observer} if typeof observer == 'function'
757 Services.obs.addObserver(observer, topic, false)
759 Services.obs.removeObserver(observer, topic, false)
762 # Try to open a button’s dropdown menu, if any.
763 openDropdown = (element) ->
764 if isXULElement(element) and
765 element.getAttribute?('type') == 'menu' and
766 element.open == false # Only change `.open` if it is already a boolean.
769 openPopup = (popup) ->
770 window = popup.ownerGlobal
771 # Show the popup so it gets a height and width.
772 popup.openPopupAtScreen(0, 0)
773 # Center the popup inside the window.
775 window.screenX + window.outerWidth / 2 - popup.clientWidth / 2,
776 window.screenY + window.outerHeight / 2 - popup.clientHeight / 2
779 writeToClipboard = (text) -> nsIClipboardHelper.copyString(text)
790 isDockedDevtoolsElement
793 isIgnoreModeFocusType
800 blurActiveBrowserElement
814 checkElementOrAncestor
826 selectAllSubstringMatches
834 getAllNonOverlappingRangeOffsets