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