diff options
Diffstat (limited to 'content_scripts/vimium_frontend.coffee')
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 45 | 
1 files changed, 23 insertions, 22 deletions
| diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 8f4c7e82..781223b1 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -274,23 +274,22 @@ setScrollPosition = ({ scrollX, scrollY }) ->  #  # Called from the backend in order to change frame focus.  # -window.focusThisFrame = do -> +DomUtils.documentReady ->    # Create a shadow DOM wrapping the frame so the page's styles don't interfere with ours. -  highlightedFrameElement = document.createElement "div" +  highlightedFrameElement = DomUtils.createElement "div"    # PhantomJS doesn't support createShadowRoot, so guard against its non-existance.    _shadowDOM = highlightedFrameElement.createShadowRoot?() ? highlightedFrameElement    # Inject stylesheet. -  _styleSheet = document.createElement "style" -  if _styleSheet.style? -    _styleSheet.innerHTML = "@import url(\"#{chrome.runtime.getURL("content_scripts/vimium.css")}\");" -    _shadowDOM.appendChild _styleSheet +  _styleSheet = DomUtils.createElement "style" +  _styleSheet.innerHTML = "@import url(\"#{chrome.runtime.getURL("content_scripts/vimium.css")}\");" +  _shadowDOM.appendChild _styleSheet -  _frameEl = document.createElement "div" +  _frameEl = DomUtils.createElement "div"    _frameEl.className = "vimiumReset vimiumHighlightedFrame"    _shadowDOM.appendChild _frameEl -  (request) -> +  window.focusThisFrame = (request) ->      if window.innerWidth < 3 or window.innerHeight < 3        # This frame is too small to focus. Cancel and tell the background frame to focus the next one instead.        # This affects sites like Google Inbox, which have many tiny iframes. See #1317. @@ -304,6 +303,8 @@ window.focusThisFrame = do ->        document.documentElement.appendChild highlightedFrameElement        setTimeout (-> highlightedFrameElement.remove()), 200 +window.focusThisFrame = -> +  extend window,    scrollToBottom: ->      Marks.setPreviousPosition() @@ -405,7 +406,7 @@ extend window,            Math.min(count, visibleInputs.length) - 1        hints = for tuple in visibleInputs -        hint = document.createElement "div" +        hint = DomUtils.createElement "div"          hint.className = "vimiumReset internalVimiumInputHint vimiumInputHint"          # minus 1 for the border @@ -429,7 +430,7 @@ extend window,                  hints[selectedInputIndex].classList.add 'internalVimiumSelectedInputHint'                  # Deactivate any active modes on this element (PostFindMode, or a suspended edit mode).                  @deactivateSingleton visibleInputs[selectedInputIndex].element -                visibleInputs[selectedInputIndex].element.focus() +                DomUtils.simulateSelect visibleInputs[selectedInputIndex].element                  @suppressEvent                else unless event.keyCode == KeyboardUtils.keyCodes.shiftKey                  @exit() @@ -442,7 +443,7 @@ extend window,            # Deactivate any active modes on this element (PostFindMode, or a suspended edit mode).            @deactivateSingleton visibleInputs[selectedInputIndex].element -          visibleInputs[selectedInputIndex].element.focus() +          DomUtils.simulateSelect visibleInputs[selectedInputIndex].element            if visibleInputs.length == 1              @exit()              return @@ -463,25 +464,25 @@ extend window,  KeydownEvents =    handledEvents: {} -  stringify: (event) -> -    JSON.stringify -      metaKey: event.metaKey -      altKey: event.altKey -      ctrlKey: event.ctrlKey -      keyIdentifier: event.keyIdentifier -      keyCode: event.keyCode +  getEventCode: (event) -> event.keyCode    push: (event) -> -    @handledEvents[@stringify event] = true +    @handledEvents[@getEventCode event] = true    # Yields truthy or falsy depending upon whether a corresponding keydown event is present (and removes that    # event).    pop: (event) -> -    detailString = @stringify event +    detailString = @getEventCode event      value = @handledEvents[detailString]      delete @handledEvents[detailString]      value +  clear: -> @handledEvents = {} + +handlerStack.push +  _name: "KeydownEvents-cleanup" +  blur: (event) -> KeydownEvents.clear() if event.target == window; true +  #  # Sends everything except i & ESC to the handler in background_page. i & ESC are special because they control  # insert mode which is local state to the page. The key will be are either a single ascii letter or a @@ -775,7 +776,7 @@ window.enterFindMode = ->  window.showHelpDialog = (html, fid) ->    return if (isShowingHelpDialog || !document.body || fid != frameId)    isShowingHelpDialog = true -  container = document.createElement("div") +  container = DomUtils.createElement "div"    container.id = "vimiumHelpDialogContainer"    container.className = "vimiumReset" @@ -861,7 +862,7 @@ CursorHider =      # See #1345 and #1348.      return unless Utils.haveChromeVersion "39.0.2171.71" -    @cursorHideStyle = document.createElement("style") +    @cursorHideStyle = DomUtils.createElement "style"      @cursorHideStyle.innerHTML = """        body * {pointer-events: none !important; cursor: none !important;}        body, html {cursor: none !important;} | 
