summaryrefslogtreecommitdiffstats
path: root/application/palemoon/components/places/content/menu.xml
blob: d4041ec6bdf5578cb11b6fea10125609c5316bb2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
<?xml version="1.0"?>

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

<bindings id="placesMenuBindings"
          xmlns="http://www.mozilla.org/xbl"
          xmlns:xbl="http://www.mozilla.org/xbl"
          xmlns:html="http://www.w3.org/1999/xhtml"
          xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

  <binding id="places-popup-base"
           extends="chrome://global/content/bindings/popup.xml#popup">
    <content>
      <xul:hbox flex="1">
        <xul:vbox class="menupopup-drop-indicator-bar" hidden="true">
          <xul:image class="menupopup-drop-indicator" mousethrough="always"/>
        </xul:vbox>
        <xul:arrowscrollbox class="popup-internal-box" flex="1" orient="vertical"
                            smoothscroll="false">
          <children/>
        </xul:arrowscrollbox>
      </xul:hbox>
    </content>

    <implementation>

      <field name="_indicatorBar">
        document.getAnonymousElementByAttribute(this, "class",
                                                "menupopup-drop-indicator-bar");
      </field>

      <field name="_scrollBox">
        document.getAnonymousElementByAttribute(this, "class",
                                                "popup-internal-box");
      </field>

      <!-- This is the view that manage the popup -->
      <field name="_rootView">PlacesUIUtils.getViewForNode(this);</field>

      <!-- Check if we should hide the drop indicator for the target -->
      <method name="_hideDropIndicator">
        <parameter name="aEvent"/>
        <body><![CDATA[
          let target = aEvent.target;

          // Don't draw the drop indicator outside of markers.
          // The markers are hidden, since otherwise sometimes popups acquire
          // scrollboxes on OS X, so we can't use them directly.
          let firstChildTop = this._startMarker.nextSibling.boxObject.y;
          let lastChildBottom = this._endMarker.previousSibling.boxObject.y +
                                this._endMarker.previousSibling.boxObject.height;
          let betweenMarkers = target.boxObject.y >= firstChildTop ||
                               target.boxObject.y <= lastChildBottom;

          // Hide the dropmarker if current node is not a Places node.
          return !(target && target._placesNode && betweenMarkers);
        ]]></body>
      </method>

      <!-- This function returns information about where to drop when
           dragging over this popup insertion point -->
      <method name="_getDropPoint">
        <parameter name="aEvent"/>
          <body><![CDATA[
            // Can't drop if the menu isn't a folder
            let resultNode = this._placesNode;

            if (!PlacesUtils.nodeIsFolder(resultNode) ||
                PlacesControllerDragHelper.disallowInsertion(resultNode)) {
              return null;
            }

            var dropPoint = { ip: null, folderElt: null };

            // The element we are dragging over
            let elt = aEvent.target;
            if (elt.localName == "menupopup")
              elt = elt.parentNode;

            // Calculate positions taking care of arrowscrollbox
            let eventY = aEvent.layerY;
            let scrollbox = this._scrollBox;
            let scrollboxOffset = scrollbox.scrollBoxObject.y -
                                  (scrollbox.boxObject.y - this.boxObject.y);
            let eltY = elt.boxObject.y - scrollboxOffset;
            let eltHeight = elt.boxObject.height;

            if (!elt._placesNode) {
              // If we are dragging over a non places node drop at the end.
              dropPoint.ip = new InsertionPoint(
                                  PlacesUtils.getConcreteItemId(resultNode),
                                  -1,
                                  Ci.nsITreeView.DROP_ON);
              // We can set folderElt if we are dropping over a static menu that
              // has an internal placespopup.
              let isMenu = elt.localName == "menu" ||
                 (elt.localName == "toolbarbutton" &&
                  elt.getAttribute("type") == "menu");
              if (isMenu && elt.lastChild &&
                  elt.lastChild.hasAttribute("placespopup"))
                dropPoint.folderElt = elt;
              return dropPoint;
            }
            if ((PlacesUtils.nodeIsFolder(elt._placesNode) &&
                 !PlacesUIUtils.isContentsReadOnly(elt._placesNode)) ||
                PlacesUtils.nodeIsTagQuery(elt._placesNode)) {
              // This is a folder or a tag container.
              if (eventY - eltY < eltHeight * 0.20) {
                // If mouse is in the top part of the element, drop above folder.
                dropPoint.ip = new InsertionPoint(
                                    PlacesUtils.getConcreteItemId(resultNode),
                                    -1,
                                    Ci.nsITreeView.DROP_BEFORE,
                                    PlacesUtils.nodeIsTagQuery(elt._placesNode),
                                    elt._placesNode.itemId);
                return dropPoint;
              }
              else if (eventY - eltY < eltHeight * 0.80) {
                // If mouse is in the middle of the element, drop inside folder.
                dropPoint.ip = new InsertionPoint(
                                    PlacesUtils.getConcreteItemId(elt._placesNode),
                                    -1,
                                    Ci.nsITreeView.DROP_ON,
                                    PlacesUtils.nodeIsTagQuery(elt._placesNode));
                dropPoint.folderElt = elt;
                return dropPoint;
              }
            }
            else if (eventY - eltY <= eltHeight / 2) {
              // This is a non-folder node or a readonly folder.
              // If the mouse is above the middle, drop above this item.
              dropPoint.ip = new InsertionPoint(
                                  PlacesUtils.getConcreteItemId(resultNode),
                                  -1,
                                  Ci.nsITreeView.DROP_BEFORE,
                                  PlacesUtils.nodeIsTagQuery(elt._placesNode),
                                  elt._placesNode.itemId);
              return dropPoint;
            }

            // Drop below the item.
            dropPoint.ip = new InsertionPoint(
                                PlacesUtils.getConcreteItemId(resultNode),
                                -1,
                                Ci.nsITreeView.DROP_AFTER,
                                PlacesUtils.nodeIsTagQuery(elt._placesNode),
                                elt._placesNode.itemId);
            return dropPoint;
        ]]></body>
      </method>

      <!-- Sub-menus should be opened when the mouse drags over them, and closed
           when the mouse drags off.  The overFolder object manages opening and
           closing of folders when the mouse hovers. -->
      <field name="_overFolder"><![CDATA[({
        _self: this,
        _folder: {elt: null,
                  openTimer: null,
                  hoverTime: 350,
                  closeTimer: null},
        _closeMenuTimer: null,

        get elt() {
          return this._folder.elt;
        },
        set elt(val) {
          return this._folder.elt = val;
        },

        get openTimer() {
          return this._folder.openTimer;
        },
        set openTimer(val) {
          return this._folder.openTimer = val;
        },

        get hoverTime() {
          return this._folder.hoverTime;
        },
        set hoverTime(val) {
          return this._folder.hoverTime = val;
        },

        get closeTimer() {
          return this._folder.closeTimer;
        },
        set closeTimer(val) {
          return this._folder.closeTimer = val;
        },

        get closeMenuTimer() {
          return this._closeMenuTimer;
        },
        set closeMenuTimer(val) {
          return this._closeMenuTimer = val;
        },

        setTimer: function OF__setTimer(aTime) {
          var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
          timer.initWithCallback(this, aTime, timer.TYPE_ONE_SHOT);
          return timer;
        },

        notify: function OF__notify(aTimer) {
          // Function to process all timer notifications.

          if (aTimer == this._folder.openTimer) {
            // Timer to open a submenu that's being dragged over.
            this._folder.elt.lastChild.setAttribute("autoopened", "true");
            this._folder.elt.lastChild.showPopup(this._folder.elt);
            this._folder.openTimer = null;
          }

          else if (aTimer == this._folder.closeTimer) {
            // Timer to close a submenu that's been dragged off of.
            // Only close the submenu if the mouse isn't being dragged over any
            // of its child menus.
            var draggingOverChild = PlacesControllerDragHelper
                                    .draggingOverChildNode(this._folder.elt);
            if (draggingOverChild)
              this._folder.elt = null;
            this.clear();

            // Close any parent folders which aren't being dragged over.
            // (This is necessary because of the above code that keeps a folder
            // open while its children are being dragged over.)
            if (!draggingOverChild)
              this.closeParentMenus();
          }

          else if (aTimer == this.closeMenuTimer) {
            // Timer to close this menu after the drag exit.
            var popup = this._self;
            // if we are no more dragging we can leave the menu open to allow
            // for better D&D bookmark organization
            if (PlacesControllerDragHelper.getSession() &&
                !PlacesControllerDragHelper.draggingOverChildNode(popup.parentNode)) {
              popup.hidePopup();
              // Close any parent menus that aren't being dragged over;
              // otherwise they'll stay open because they couldn't close
              // while this menu was being dragged over.
              this.closeParentMenus();
            }
            this._closeMenuTimer = null;
          }
        },

        //  Helper function to close all parent menus of this menu,
        //  as long as none of the parent's children are currently being
        //  dragged over.
        closeParentMenus: function OF__closeParentMenus() {
          var popup = this._self;
          var parent = popup.parentNode;
          while (parent) {
            if (parent.localName == "menupopup" && parent._placesNode) {
              if (PlacesControllerDragHelper.draggingOverChildNode(parent.parentNode))
                break;
              parent.hidePopup();
            }
            parent = parent.parentNode;
          }
        },

        //  The mouse is no longer dragging over the stored menubutton.
        //  Close the menubutton, clear out drag styles, and clear all
        //  timers for opening/closing it.
        clear: function OF__clear() {
          if (this._folder.elt && this._folder.elt.lastChild) {
            if (!this._folder.elt.lastChild.hasAttribute("dragover"))
              this._folder.elt.lastChild.hidePopup();
            // remove menuactive style
            this._folder.elt.removeAttribute("_moz-menuactive");
            this._folder.elt = null;
          }
          if (this._folder.openTimer) {
            this._folder.openTimer.cancel();
            this._folder.openTimer = null;
          }
          if (this._folder.closeTimer) {
            this._folder.closeTimer.cancel();
            this._folder.closeTimer = null;
          }
        }
      })]]></field>

      <method name="_cleanupDragDetails">
        <body><![CDATA[
          // Called on dragend and drop.
          PlacesControllerDragHelper.currentDropTarget = null;
          this._rootView._draggedElt = null;
          this.removeAttribute("dragover");
          this.removeAttribute("dragstart");
          this._indicatorBar.hidden = true;
        ]]></body>
      </method>

    </implementation>

    <handlers>
      <handler event="DOMMenuItemActive"><![CDATA[
        let elt = event.target;
        if (elt.parentNode != this)
          return;

#ifdef XP_MACOSX
        // XXX: The following check is a temporary hack until bug 420033 is
        // resolved.
        let parentElt = elt.parent;
        while (parentElt) {
          if (parentElt.id == "bookmarksMenuPopup" ||
              parentElt.id == "goPopup")
            return;

          parentElt = parentElt.parentNode;
        }
#endif

        if (window.XULBrowserWindow) {
          let elt = event.target;
          let placesNode = elt._placesNode;

          var linkURI;
          if (placesNode && PlacesUtils.nodeIsURI(placesNode))
            linkURI = placesNode.uri;
          else if (elt.hasAttribute("targetURI"))
            linkURI = elt.getAttribute("targetURI");

          if (linkURI)
            window.XULBrowserWindow.setOverLink(linkURI, null);
        }
      ]]></handler>

      <handler event="DOMMenuItemInactive"><![CDATA[
        let elt = event.target;
        if (elt.parentNode != this)
          return;

        if (window.XULBrowserWindow)
          window.XULBrowserWindow.setOverLink("", null);
      ]]></handler>

      <handler event="dragstart"><![CDATA[
        if (!event.target._placesNode)
          return;

        let draggedElt = event.target._placesNode;

        // Force a copy action if parent node is a query or we are dragging a
        // not-removable node.
        if (!PlacesControllerDragHelper.canMoveNode(draggedElt))
          event.dataTransfer.effectAllowed = "copyLink";

        // Activate the view and cache the dragged element.
        this._rootView._draggedElt = draggedElt;
        this._rootView.controller.setDataTransfer(event);
        this.setAttribute("dragstart", "true");
        event.stopPropagation();
      ]]></handler>

      <handler event="drop"><![CDATA[
        PlacesControllerDragHelper.currentDropTarget = event.target;

        let dropPoint = this._getDropPoint(event);
        if (dropPoint && dropPoint.ip) {
          PlacesControllerDragHelper.onDrop(dropPoint.ip, event.dataTransfer);
          event.preventDefault();
        }

        this._cleanupDragDetails();
        event.stopPropagation();
      ]]></handler>

      <handler event="dragover"><![CDATA[
        PlacesControllerDragHelper.currentDropTarget = event.target;
        let dt = event.dataTransfer;

        let dropPoint = this._getDropPoint(event);
        if (!dropPoint || !dropPoint.ip ||
            !PlacesControllerDragHelper.canDrop(dropPoint.ip, dt)) {
          this._indicatorBar.hidden = true;
          event.stopPropagation();
          return;
        }

        // Mark this popup as being dragged over.
        this.setAttribute("dragover", "true");

        if (dropPoint.folderElt) {
          // We are dragging over a folder.
          // _overFolder should take the care of opening it on a timer.
          if (this._overFolder.elt &&
              this._overFolder.elt != dropPoint.folderElt) {
            // We are dragging over a new folder, let's clear old values
            this._overFolder.clear();
          }
          if (!this._overFolder.elt) {
            this._overFolder.elt = dropPoint.folderElt;
            // Create the timer to open this folder.
            this._overFolder.openTimer = this._overFolder
                                             .setTimer(this._overFolder.hoverTime);
          }
          // Since we are dropping into a folder set the corresponding style.
          dropPoint.folderElt.setAttribute("_moz-menuactive", true);
        }
        else {
          // We are not dragging over a folder.
          // Clear out old _overFolder information.
          this._overFolder.clear();
        }

        // Autoscroll the popup strip if we drag over the scroll buttons.
        let anonid = event.originalTarget.getAttribute('anonid');
        let scrollDir = anonid == "scrollbutton-up" ? -1 :
                        anonid == "scrollbutton-down" ? 1 : 0;
        if (scrollDir != 0) {
          this._scrollBox.scrollByIndex(scrollDir, false);
        }

        // Check if we should hide the drop indicator for this target.
        if (dropPoint.folderElt || this._hideDropIndicator(event)) {
          this._indicatorBar.hidden = true;
          event.preventDefault();
          event.stopPropagation();
          return;
        }

        // We should display the drop indicator relative to the arrowscrollbox.
        let sbo = this._scrollBox.scrollBoxObject;
        let newMarginTop = 0;
        if (scrollDir == 0) {
          let elt = this.firstChild;
          while (elt && event.screenY > elt.boxObject.screenY +
                                        elt.boxObject.height / 2)
            elt = elt.nextSibling;
          newMarginTop = elt ? elt.boxObject.screenY - sbo.screenY :
                               sbo.height;
        }
        else if (scrollDir == 1)
          newMarginTop = sbo.height;

        // Set the new marginTop based on arrowscrollbox.
        newMarginTop += sbo.y - this._scrollBox.boxObject.y;
        this._indicatorBar.firstChild.style.marginTop = newMarginTop + "px";
        this._indicatorBar.hidden = false;

        event.preventDefault();
        event.stopPropagation();
      ]]></handler>

      <handler event="dragexit"><![CDATA[
        PlacesControllerDragHelper.currentDropTarget = null;
        this.removeAttribute("dragover");

        // If we have not moved to a valid new target clear the drop indicator
        // this happens when moving out of the popup.
        let target = event.relatedTarget;
        if (!target)
          this._indicatorBar.hidden = true;

        // Close any folder being hovered over
        if (this._overFolder.elt) {
          this._overFolder.closeTimer = this._overFolder
                                            .setTimer(this._overFolder.hoverTime);
        }

        // The autoopened attribute is set when this folder was automatically
        // opened after the user dragged over it.  If this attribute is set,
        // auto-close the folder on drag exit.
        // We should also try to close this popup if the drag has started
        // from here, the timer will check if we are dragging over a child.
        if (this.hasAttribute("autoopened") ||
            this.hasAttribute("dragstart")) {
          this._overFolder.closeMenuTimer = this._overFolder
                                                .setTimer(this._overFolder.hoverTime);
        }

        event.stopPropagation();
      ]]></handler>

      <handler event="dragend"><![CDATA[
        this._cleanupDragDetails();
      ]]></handler>

    </handlers>
  </binding>
</bindings>