diff options
| author | mrmr1993 | 2015-05-13 00:16:20 +0100 | 
|---|---|---|
| committer | mrmr1993 | 2015-05-13 00:50:36 +0100 | 
| commit | 0e6692932d11e2c82514d65d0cd45e1325e2647c (patch) | |
| tree | fd44712763fa15077b7e8d7b0467204649eddda6 /content_scripts | |
| parent | bf03ebf7b806a2c3a3a3c529191adcc7309b4a53 (diff) | |
| download | vimium-0e6692932d11e2c82514d65d0cd45e1325e2647c.tar.bz2 | |
Move the HUD to an iframe, managed by UIComponent
Diffstat (limited to 'content_scripts')
| -rw-r--r-- | content_scripts/hud.coffee | 29 | ||||
| -rw-r--r-- | content_scripts/ui_component.coffee | 7 | ||||
| -rw-r--r-- | content_scripts/vimium.css | 21 | 
3 files changed, 32 insertions, 25 deletions
diff --git a/content_scripts/hud.coffee b/content_scripts/hud.coffee index 05fa998d..55c302d6 100644 --- a/content_scripts/hud.coffee +++ b/content_scripts/hud.coffee @@ -4,6 +4,7 @@  #  HUD =    tween: null +  hudUI: null    _displayElement: null    # This HUD is styled to precisely mimick the chrome HUD on Mac. Use the "has_popup_and_link_hud.html" @@ -11,7 +12,9 @@ HUD =    # it doesn't sit on top of horizontal scrollbars like Chrome's HUD does.    init: -> -    @tween = new Tween ".vimiumHUD.vimiumUIComponentVisible" +    @hudUI = new UIComponent "pages/hud.html", "vimiumHUDFrame", ({data}) => +      this[data.name]? data +    @tween = new Tween "iframe.vimiumHUDFrame.vimiumUIComponentVisible", @hudUI.shadowDOM    showForDuration: (text, duration) ->      @show(text) @@ -20,21 +23,8 @@ HUD =    show: (text) ->      return unless @enabled()      clearTimeout(@_showForDurationTimerId) -    @displayElement().innerText = text +    @hudUI.show {name: "show", text}      @tween.fade 1.0, 150 -    @displayElement().classList.add "vimiumUIComponentVisible" -    @displayElement().classList.remove "vimiumUIComponentHidden" - -  # -  # Retrieves the HUD HTML element. -  # -  displayElement: -> @_displayElement ?= @createHudElement() - -  createHudElement: -> -    element = document.createElement("div") -    element.className = "vimiumReset vimiumHUD vimiumUIComponentHidden" -    document.body.appendChild(element) -    element    # Hide the HUD.    # If :immediate is falsy, then the HUD is faded out smoothly (otherwise it is hidden immediately). @@ -42,11 +32,12 @@ HUD =    # mode indicator, is when hide() is called for the mode indicator itself.    hide: (immediate = false, updateIndicator = true) ->      return unless @tween? +    clearTimeout(@_showForDurationTimerId)      @tween.stop()      if immediate        unless updateIndicator -        @displayElement().classList.remove "vimiumUIComponentVisible" -        @displayElement().classList.add "vimiumUIComponentHidden" +        @hudUI.hide() +        @hudUI.postMessage {handler: "hide"}        Mode.setIndicator() if updateIndicator      else        @tween.fade 0, 150, => @hide true, updateIndicator @@ -64,11 +55,11 @@ class Tween    intervalId: -1    styleElement: null -  constructor: (@cssSelector) -> +  constructor: (@cssSelector, insertionPoint = document.documentElement) ->      @styleElement = document.createElement "style"      @styleElement.type = "text/css"      @styleElement.innerHTML = "" -    document.documentElement.appendChild @styleElement +    insertionPoint.appendChild @styleElement    fade: (toAlpha, duration, onComplete) ->      clearInterval @intervalId diff --git a/content_scripts/ui_component.coffee b/content_scripts/ui_component.coffee index 5e0bd5d5..938a8411 100644 --- a/content_scripts/ui_component.coffee +++ b/content_scripts/ui_component.coffee @@ -3,6 +3,7 @@ class UIComponent    iframePort: null    showing: null    options: null +  shadowDOM: null    constructor: (iframeUrl, className, @handleMessage) ->      styleSheet = document.createElement "style" @@ -18,9 +19,9 @@ class UIComponent      @iframeElement.addEventListener "load", => @openPort()      shadowWrapper = document.createElement "div"      # PhantomJS doesn't support createShadowRoot, so guard against its non-existance. -    shadowDOM = shadowWrapper.createShadowRoot?() ? shadowWrapper -    shadowDOM.appendChild styleSheet -    shadowDOM.appendChild @iframeElement +    @shadowDOM = shadowWrapper.createShadowRoot?() ? shadowWrapper +    @shadowDOM.appendChild styleSheet +    @shadowDOM.appendChild @iframeElement      document.documentElement.appendChild shadowWrapper      @showing = true # The iframe is visible now. diff --git a/content_scripts/vimium.css b/content_scripts/vimium.css index a3ea5a70..f36fe0c3 100644 --- a/content_scripts/vimium.css +++ b/content_scripts/vimium.css @@ -238,7 +238,7 @@ div.vimiumHUD {    position: fixed;    bottom: 0px;    /* Keep this far enough to the right so that it doesn't collide with the "popups blocked" chrome HUD. */ -  right: 150px; +  right: 0px;    color: black;    height: auto;    min-height: 13px; @@ -253,10 +253,25 @@ div.vimiumHUD {    border-radius: 4px 4px 0 0;    font-family: "Lucida Grande", "Arial", "Sans";    font-size: 12px; -  /* One less than vimium's hint markers, so link hints can be shown e.g. for the HUD panel's close button. */ -  z-index: 2147483646;    text-shadow: 0px 1px 2px #FFF;    line-height: 1.0; +} + +iframe.vimiumHUDFrame { +  display: block; +  background: none; +  position: fixed; +  bottom: 0px; +  right: 150px; +  height: 20px; +  min-height: 20px; +  width: 450px; +  min-width: 150px; +  padding: 0px; +  margin: 0; +  border: none; +  /* One less than vimium's hint markers, so link hints can be shown e.g. for the HUD panel's close button. */ +  z-index: 2147483646;    opacity: 0;  }  /* Hide the span between search box letters */  | 
