Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | # -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | # This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | # License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
michael@0 | 5 | |
michael@0 | 6 | var SidebarUtils = { |
michael@0 | 7 | handleTreeClick: function SU_handleTreeClick(aTree, aEvent, aGutterSelect) { |
michael@0 | 8 | // right-clicks are not handled here |
michael@0 | 9 | if (aEvent.button == 2) |
michael@0 | 10 | return; |
michael@0 | 11 | |
michael@0 | 12 | var tbo = aTree.treeBoxObject; |
michael@0 | 13 | var row = { }, col = { }, obj = { }; |
michael@0 | 14 | tbo.getCellAt(aEvent.clientX, aEvent.clientY, row, col, obj); |
michael@0 | 15 | |
michael@0 | 16 | if (row.value == -1 || obj.value == "twisty") |
michael@0 | 17 | return; |
michael@0 | 18 | |
michael@0 | 19 | var mouseInGutter = false; |
michael@0 | 20 | if (aGutterSelect) { |
michael@0 | 21 | var x = { }, y = { }, w = { }, h = { }; |
michael@0 | 22 | tbo.getCoordsForCellItem(row.value, col.value, "image", |
michael@0 | 23 | x, y, w, h); |
michael@0 | 24 | // getCoordsForCellItem returns the x coordinate in logical coordinates |
michael@0 | 25 | // (i.e., starting from the left and right sides in LTR and RTL modes, |
michael@0 | 26 | // respectively.) Therefore, we make sure to exclude the blank area |
michael@0 | 27 | // before the tree item icon (that is, to the left or right of it in |
michael@0 | 28 | // LTR and RTL modes, respectively) from the click target area. |
michael@0 | 29 | var isRTL = window.getComputedStyle(aTree, null).direction == "rtl"; |
michael@0 | 30 | if (isRTL) |
michael@0 | 31 | mouseInGutter = aEvent.clientX > x.value; |
michael@0 | 32 | else |
michael@0 | 33 | mouseInGutter = aEvent.clientX < x.value; |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | #ifdef XP_MACOSX |
michael@0 | 37 | var modifKey = aEvent.metaKey || aEvent.shiftKey; |
michael@0 | 38 | #else |
michael@0 | 39 | var modifKey = aEvent.ctrlKey || aEvent.shiftKey; |
michael@0 | 40 | #endif |
michael@0 | 41 | |
michael@0 | 42 | var isContainer = tbo.view.isContainer(row.value); |
michael@0 | 43 | var openInTabs = isContainer && |
michael@0 | 44 | (aEvent.button == 1 || |
michael@0 | 45 | (aEvent.button == 0 && modifKey)) && |
michael@0 | 46 | PlacesUtils.hasChildURIs(tbo.view.nodeForTreeIndex(row.value)); |
michael@0 | 47 | |
michael@0 | 48 | if (aEvent.button == 0 && isContainer && !openInTabs) { |
michael@0 | 49 | tbo.view.toggleOpenState(row.value); |
michael@0 | 50 | return; |
michael@0 | 51 | } |
michael@0 | 52 | else if (!mouseInGutter && openInTabs && |
michael@0 | 53 | aEvent.originalTarget.localName == "treechildren") { |
michael@0 | 54 | tbo.view.selection.select(row.value); |
michael@0 | 55 | PlacesUIUtils.openContainerNodeInTabs(aTree.selectedNode, aEvent, aTree); |
michael@0 | 56 | } |
michael@0 | 57 | else if (!mouseInGutter && !isContainer && |
michael@0 | 58 | aEvent.originalTarget.localName == "treechildren") { |
michael@0 | 59 | // Clear all other selection since we're loading a link now. We must |
michael@0 | 60 | // do this *before* attempting to load the link since openURL uses |
michael@0 | 61 | // selection as an indication of which link to load. |
michael@0 | 62 | tbo.view.selection.select(row.value); |
michael@0 | 63 | PlacesUIUtils.openNodeWithEvent(aTree.selectedNode, aEvent, aTree); |
michael@0 | 64 | } |
michael@0 | 65 | }, |
michael@0 | 66 | |
michael@0 | 67 | handleTreeKeyPress: function SU_handleTreeKeyPress(aEvent) { |
michael@0 | 68 | // XXX Bug 627901: Post Fx4, this method should take a tree parameter. |
michael@0 | 69 | let tree = aEvent.target; |
michael@0 | 70 | let node = tree.selectedNode; |
michael@0 | 71 | if (node) { |
michael@0 | 72 | if (aEvent.keyCode == KeyEvent.DOM_VK_RETURN) |
michael@0 | 73 | PlacesUIUtils.openNodeWithEvent(node, aEvent, tree); |
michael@0 | 74 | } |
michael@0 | 75 | }, |
michael@0 | 76 | |
michael@0 | 77 | /** |
michael@0 | 78 | * The following function displays the URL of a node that is being |
michael@0 | 79 | * hovered over. |
michael@0 | 80 | */ |
michael@0 | 81 | handleTreeMouseMove: function SU_handleTreeMouseMove(aEvent) { |
michael@0 | 82 | if (aEvent.target.localName != "treechildren") |
michael@0 | 83 | return; |
michael@0 | 84 | |
michael@0 | 85 | var tree = aEvent.target.parentNode; |
michael@0 | 86 | var tbo = tree.treeBoxObject; |
michael@0 | 87 | var row = { }, col = { }, obj = { }; |
michael@0 | 88 | tbo.getCellAt(aEvent.clientX, aEvent.clientY, row, col, obj); |
michael@0 | 89 | |
michael@0 | 90 | // row.value is -1 when the mouse is hovering an empty area within the tree. |
michael@0 | 91 | // To avoid showing a URL from a previously hovered node for a currently |
michael@0 | 92 | // hovered non-url node, we must clear the moused-over URL in these cases. |
michael@0 | 93 | if (row.value != -1) { |
michael@0 | 94 | var node = tree.view.nodeForTreeIndex(row.value); |
michael@0 | 95 | if (PlacesUtils.nodeIsURI(node)) |
michael@0 | 96 | this.setMouseoverURL(node.uri); |
michael@0 | 97 | else |
michael@0 | 98 | this.setMouseoverURL(""); |
michael@0 | 99 | } |
michael@0 | 100 | else |
michael@0 | 101 | this.setMouseoverURL(""); |
michael@0 | 102 | }, |
michael@0 | 103 | |
michael@0 | 104 | setMouseoverURL: function SU_setMouseoverURL(aURL) { |
michael@0 | 105 | // When the browser window is closed with an open sidebar, the sidebar |
michael@0 | 106 | // unload event happens after the browser's one. In this case |
michael@0 | 107 | // top.XULBrowserWindow has been nullified already. |
michael@0 | 108 | if (top.XULBrowserWindow) { |
michael@0 | 109 | top.XULBrowserWindow.setOverLink(aURL, null); |
michael@0 | 110 | } |
michael@0 | 111 | } |
michael@0 | 112 | }; |