aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJez Ng2012-09-02 22:51:29 -0400
committerJez Ng2012-09-02 22:51:29 -0400
commitf0f3a385bec153c931f8dcf651241b06c0dc6b2d (patch)
tree4ab89ced9c09bdbe98dda75e96c16f449ccc3458
parent54255af086135da4cccc7aad56effd0dacb0a425 (diff)
parent3cbe7758d7ca4cfac70c931c4c3fa58c50841d90 (diff)
downloadvimium-f0f3a385bec153c931f8dcf651241b06c0dc6b2d.tar.bz2
Merge branch 'focus-input'
-rw-r--r--content_scripts/vimium_frontend.coffee60
-rw-r--r--vimium.css18
2 files changed, 65 insertions, 13 deletions
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index 9c86e808..577aa0c5 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -301,19 +301,53 @@ extend window,
HUD.showForDuration("Yanked URL", 1000)
focusInput: (count) ->
- results = DomUtils.evaluateXPath(textInputXPath, XPathResult.ORDERED_NODE_ITERATOR_TYPE)
-
- lastInputBox
- i = 0
-
- while (i < count)
- currentInputBox = results.iterateNext()
- break unless currentInputBox
- continue if (DomUtils.getVisibleClientRect(currentInputBox) == null)
- lastInputBox = currentInputBox
- i += 1
-
- lastInputBox.focus() if lastInputBox
+ resultSet = DomUtils.evaluateXPath(textInputXPath, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE)
+ visibleInputs =
+ for i in [0...resultSet.snapshotLength] by 1
+ element = resultSet.snapshotItem(i)
+ rect = DomUtils.getVisibleClientRect(element)
+ continue if rect == null
+ { element: element, rect: rect }
+
+ return if visibleInputs.length == 0
+
+ selectedInputIndex = Math.min(count - 1, visibleInputs.length - 1)
+
+ visibleInputs[selectedInputIndex].element.focus()
+
+ return if visibleInputs.length == 1
+
+ hints = for tuple in visibleInputs
+ hint = document.createElement("div")
+ hint.className = "vimiumReset internalVimiumInputHint vimiumInputHint"
+
+ # minus 1 for the border
+ hint.style.left = (tuple.rect.left - 1) + window.scrollX + "px"
+ hint.style.top = (tuple.rect.top - 1) + window.scrollY + "px"
+ hint.style.width = tuple.rect.width + "px"
+ hint.style.height = tuple.rect.height + "px"
+
+ hint
+
+ hints[0].classList.add 'internalVimiumSelectedInputHint'
+
+ hintContainingDiv = DomUtils.addElementList(hints,
+ { id: "vimiumInputMarkerContainer", className: "vimiumReset" })
+
+ handlerStack.push keydown: (event) ->
+ if event.keyCode == KeyboardUtils.keyCodes.tab
+ hints[selectedInputIndex].classList.remove 'internalVimiumSelectedInputHint'
+ if event.shiftKey
+ if --selectedInputIndex == -1
+ selectedInputIndex = hints.length - 1
+ else
+ if ++selectedInputIndex == hints.length
+ selectedInputIndex = 0
+ hints[selectedInputIndex].classList.add 'internalVimiumSelectedInputHint'
+ visibleInputs[selectedInputIndex].element.focus()
+ else unless event.keyCode == KeyboardUtils.keyCodes.shiftKey
+ DomUtils.removeElement hintContainingDiv
+ handlerStack.pop()
#
# Sends everything except i & ESC to the handler in background_page. i & ESC are special because they control
diff --git a/vimium.css b/vimium.css
index c774b604..cf626efe 100644
--- a/vimium.css
+++ b/vimium.css
@@ -86,6 +86,24 @@ div.internalVimiumHintMarker > .matchingCharacter {
color: #D4AC3A;
}
+/* Input hints CSS */
+
+div.internalVimiumInputHint {
+ position: absolute;
+ display: block;
+ background-color: rgba(255, 247, 133, 0.3);
+ border: solid 1px #C38A22;
+}
+
+div.internalVimiumSelectedInputHint {
+ background-color: rgba(255, 102, 102, 0.3);
+ border: solid 1px #993333 !important;
+}
+
+div.internalVimiumSelectedInputHint span {
+ color: white !important;
+}
+
/* Help Dialog CSS */
div#vimiumHelpDialog {