DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (920bcf17a9e1)

VCS Links

Line Code
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 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078
<?xml version="1.0"?>

# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is the Places Menupopup View.
#
# The Initial Developer of the Original Code is Google Inc.
# Portions created by the Initial Developer are Copyright (C) 2005-2006
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#   Annie Sullivan <annie.sullivan@gmail.com>
#   Ben Goodger <beng@google.com>
#   Asaf Romano <mano@mozilla.com>
#   Simon B├╝nzli <zeniko@gmail.com>
#   Marco Bonardo <mak77@bonardo.net>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****

<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">
          <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>

      <!-- markers for start and end of valid places items -->
      <field name="_startMarker">-1</field>
      <field name="_endMarker">-1</field>

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

      <field name="_built">false</field>

      <method name="onDragOver">
        <parameter name="aEvent"/>
        <parameter name="aFlavour"/>
        <parameter name="aDragSession"/>
        <body><![CDATA[
          PlacesControllerDragHelper.currentDropTarget = aEvent.target;
          // check if we have a valid dropPoint
          var dropPoint = this._getDropPoint(aEvent);
          if (!dropPoint || !dropPoint.ip ||
              !PlacesControllerDragHelper.canDrop(dropPoint.ip)) {
            aEvent.dataTransfer.effectAllowed = "none";
            return;
          }

          // add a dragover attribute to this popup
          this.setAttribute("dragover", "true");

          if (dropPoint.folderNode) {
            // We are dragging over a folder
            // _overFolder should take the care of opening it on a timer
            if (this._overFolder.node &&
                this._overFolder.node != dropPoint.folderNode) {
              // we are dragging over a new folder, let's clear old values
              this._overFolder.clear();
            }
            if (!this._overFolder.node) {
              this._overFolder.node = dropPoint.folderNode;
              // 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.folderNode.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
          var anonid = aEvent.originalTarget.getAttribute('anonid');
          var scrollDir = anonid == "scrollbutton-up" ? -1 :
                          anonid == "scrollbutton-down" ? 1 : 0;
          if (scrollDir != 0) {
              this._scrollBox.scrollByIndex(scrollDir);
          }

          // Check if we should hide the drop indicator for this target
          if (!aDragSession.canDrop ||
              !dropPoint || dropPoint.folderNode ||
              this._hideDropIndicator(aEvent, dropPoint)) {
            this._indicatorBar.hidden = true;
            return;
          }

          // We should display the drop indicator relative to the arrowscrollbox
          var sbo = this._scrollBox.scrollBoxObject;
          var newMarginTop = 0;
          if (scrollDir == 0) {
            var node = this.firstChild;
            while (node && aEvent.screenY > node.boxObject.screenY +
                                            node.boxObject.height / 2)
              node = node.nextSibling;
            newMarginTop = node ? node.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;
          aEvent.stopPropagation();
        ]]></body>
      </method>

      <method name="onDragExit">
        <parameter name="aEvent"/>
        <parameter name="aDragSession"/>
        <body><![CDATA[
          PlacesControllerDragHelper.currentDropTarget = null;
          PlacesControllerDragHelper.currentDataTransfer = 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
          var target = aEvent.relatedTarget;
          if (!target)
            this._indicatorBar.hidden = true;

          // Close any folder being hovered over
          if (this._overFolder.node) {
            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);
          }

          this._rootView._draggedNode = null;
        ]]></body>
      </method>

      <method name="onDragStart">
        <parameter name="aEvent"/>
        <parameter name="aXferData"/>
        <parameter name="aDragAction"/>
        <body><![CDATA[
          var draggedNode = aEvent.target.node;

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

          // activate the view and cache the dragged node
          this._rootView._draggedNode = draggedNode;
          this._rootView.focus();

          // Fill the dataTransfer
          this._rootView._controller.setDataTransfer(aEvent);

          this.setAttribute("dragstart", "true");
          aEvent.stopPropagation();
        ]]></body>
      </method>

      <method name="onDrop">
        <parameter name="aEvent"/>
        <parameter name="aDropData"/>
        <parameter name="aSession"/>
        <body><![CDATA[
          // Cache the dataTransfer
          PlacesControllerDragHelper.currentDataTransfer = aEvent.dataTransfer;

          var dropPoint = this._getDropPoint(aEvent);
          if (!dropPoint)
            return;

          PlacesControllerDragHelper.onDrop(dropPoint.ip);
          aEvent.stopPropagation();
        ]]></body>
      </method>

      <!-- This returns the FavourSet accepted by this popup -->
      <method name="getSupportedFlavours">
        <body><![CDATA[
          return PlacesControllerDragHelper.flavourSet;
        ]]></body>
      </method>

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

          // in some view we have _startMarker and _endMarker, we should not
          // draw the drop indicator outside of them
          var betweenMarkers = true;
          if (this._startMarker != -1 &&
              target.boxObject.y <= this.childNodes[this._startMarker].boxObject.y)
            betweenMarkers = false;
          if (this._endMarker != -1 &&
              target.boxObject.y >= this.childNodes[this._endMarker].boxObject.y)
            betweenMarkers = false;

          // hide the dropmarker if current node is not a places bookmark item
          return !(target && target.node && betweenMarkers &&
                   this.canDrop(aEvent));
        ]]></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
            var resultNode = this._resultNode;

            if (!PlacesUtils.nodeIsFolder(resultNode) ||
                PlacesControllerDragHelper.disallowInsertion(resultNode)) {
              aEvent.dataTransfer.effectAllowed = "none";
              return null;
            }

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

            // The node we are dragging over
            var xulNode = aEvent.target;

            // Calculate positions taking care of arrowscrollbox
            var eventY = aEvent.layerY;
            var scrollbox = this._scrollBox;
            var scrollboxOffset = scrollbox.scrollBoxObject.y -
                                  (scrollbox.boxObject.y - this.boxObject.y);
            var nodeY = xulNode.boxObject.y - scrollboxOffset;
            var nodeHeight = xulNode.boxObject.height;

            if (!xulNode.node) {
              // 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);
              return dropPoint;
            }
            else if ((PlacesUtils.nodeIsFolder(xulNode.node) ||
                      PlacesUtils.nodeIsTagQuery(xulNode.node)) &&
                     !PlacesUtils.nodeIsReadOnly(xulNode.node)) {
              // This is a folder or a tag container.
              if (eventY - nodeY < nodeHeight * 0.20) {
                // If mouse is in the top part of the node, drop above folder.
                dropPoint.ip = new InsertionPoint(
                                    PlacesUtils.getConcreteItemId(resultNode),
                                    -1,
                                    Ci.nsITreeView.DROP_BEFORE,
                                    PlacesUtils.nodeIsTagQuery(xulNode.node),
                                    xulNode.node.itemId);
                return dropPoint;
              }
              else if (eventY - nodeY < nodeHeight * 0.80) {
                // If mouse is in the middle of the node, drop inside folder.
                dropPoint.ip = new InsertionPoint(
                                    PlacesUtils.getConcreteItemId(xulNode.node),
                                    -1,
                                    Ci.nsITreeView.DROP_ON,
                                    PlacesUtils.nodeIsTagQuery(xulNode.node));
                dropPoint.folderNode = xulNode;
                return dropPoint;
              }
            }
            else if (eventY - nodeY <= nodeHeight / 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(xulNode.node),
                                  xulNode.node.itemId);
              return dropPoint;
            }

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

      <method name="canDrop">
        <parameter name="aEvent"/>
        <body><![CDATA[
          // Cache the dataTransfer
          PlacesControllerDragHelper.currentDataTransfer = aEvent.dataTransfer;

          var ip = this._rootView.insertionPoint;
          return ip && PlacesControllerDragHelper.canDrop(ip);
        ]]></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: {node: null,
                  openTimer: null,
                  hoverTime: 350,
                  closeTimer: null},
        _closeMenuTimer: null,

        get node() {
          return this._folder.node;
        },
        set node(val) {
          return this._folder.node = 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.node.lastChild.setAttribute("autoopened", "true");
            this._folder.node.lastChild.showPopup(this._folder.node);
            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.node);
            if (draggingOverChild)
              this._folder.node = 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.nodeName == "menupopup" && parent._resultNode) {
              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.node && this._folder.node.lastChild) {
            if (!this._folder.node.lastChild.hasAttribute("dragover"))
              this._folder.node.lastChild.hidePopup();
            // remove menuactive style
            this._folder.node.removeAttribute("_moz-menuactive");
            this._folder.node = 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>

    </implementation>

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

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

          node = node.parentNode;
        }
#endif

        if (window.XULBrowserWindow) {
          var nodeItem = event.target.node;
          if (nodeItem && PlacesUtils.nodeIsURI(nodeItem))
            window.XULBrowserWindow.setOverLink(nodeItem.uri, null);
        }
      ]]></handler>
      <handler event="DOMMenuItemInactive"><![CDATA[
        var node = event.target;
        if (node.parentNode != this)
          return;

        if (window.XULBrowserWindow)
          window.XULBrowserWindow.setOverLink("", null);
      ]]></handler>
      <handler event="draggesture" action="if (event.target.node) nsDragAndDrop.startDrag(event, this);"/>
      <handler event="drop" action="nsDragAndDrop.drop(event, this);"/>
      <handler event="dragover" action="nsDragAndDrop.dragOver(event, this);"/>
      <handler event="dragexit" action="nsDragAndDrop.dragExit(event, this);"/>
    </handlers>
  </binding>


  <binding id="places-menupopup"
           extends="chrome://browser/content/places/menu.xml#places-popup-base">
    <implementation>
      <destructor><![CDATA[
        this._resultNode = null;
        if (this._result) {
          this._result.viewer = null;
          this._result = null;
        }
      ]]></destructor>

      <field name="_initialized">false</field>
      <method name="_ensureInitialized">
        <body><![CDATA[
          if (this._initialized)
            return;

          this._controller = new PlacesController(this);
          this.controllers.appendController(this._controller);

          // This function should only be called for top-level menus like the bookmarks menu.
          // Submenus get their _result and _resultNode from their parents.
          if (this.hasAttribute("place")) {
            // Do the initial build.
            this.place = this.place;
          }
          this._initialized = true;
        ]]></body>
      </method>

      <property name="controller"
                readonly="true"
                onget="return this._controller;"/>

      <method name="onPopupShowing">
        <parameter name="aEvent"/>
        <body><![CDATA[
          var popup = aEvent.target;
          var resultNode = popup._resultNode;
          if (!resultNode.containerOpen)
            resultNode.containerOpen = true;
          if (!popup._built)
            this._rebuild(popup);
        ]]></body>
      </method>

      <!-- nsIPlacesView -->
      <method name="getResult">
        <body><![CDATA[
          return this._result;
        ]]></body>
      </method>

      <!-- nsIPlacesView -->
      <method name="getResultNode">
        <body><![CDATA[
          this._ensureInitialized();
          return this._resultNode;
        ]]></body>
      </method>

      <method name="removeItem">
        <parameter name="child"/>
        <body><![CDATA[
          if (PlacesUtils.nodeIsContainer(child.node)) {
            for (var i=0; i < this._containerNodesMap.length; i++) {
              if (this._containerNodesMap[i].resultNode == child.node) {
                this._containerNodesMap.splice(i, 1);
                break;
              }
            }
          }

          // if document.popupNode pointed to this child, null it out,
          // otherwise controller's command-updating may rely on the removed
          // item still being "selected".
          if (document.popupNode == child)
            document.popupNode = null;
          child.parentNode.removeChild(child);

          if (this._endMarker != -1)
            this._endMarker--;
        ]]></body>
      </method>

      <method name="insertNewItem">
        <parameter name="aChild"/>
        <parameter name="aParentPopup"/>
        <parameter name="aBefore"/>
        <body><![CDATA[
          var element =
            PlacesUIUtils.createMenuItemForNode(aChild, this._containerNodesMap);

          if (aBefore)
            aParentPopup.insertBefore(element, aBefore);
          else {
            // Add the new element to the menu.  If there is static content at
            // the end of the menu, add the element before that.  Otherwise,
            // just add to the end.
            if (aParentPopup._endMarker != -1) {
              aParentPopup.insertBefore(element,
                                        aParentPopup.childNodes[aParentPopup._endMarker]);
            }
            else
              aParentPopup.appendChild(element);
          }

          if (aParentPopup._endMarker != -1)
            aParentPopup._endMarker++;
        ]]></body>
      </method>

      <method name="_showEmptyMenuItem">
        <parameter name="aPopup"/>
        <body><![CDATA[
          if (aPopup._emptyMenuItem) {
            aPopup._emptyMenuItem.hidden = false;
            return;
          }

          var label = PlacesUIUtils.getString("bookmarksMenuEmptyFolder");
          aPopup._emptyMenuItem = document.createElement("menuitem");
          aPopup._emptyMenuItem.setAttribute("label", label);
          aPopup._emptyMenuItem.setAttribute("disabled", true);
          aPopup.appendChild(aPopup._emptyMenuItem);
        ]]></body>
      </method>

      <method name="_rebuild">
        <parameter name="aPopup"/>
        <body><![CDATA[
          PlacesUIUtils.cleanPlacesPopup(aPopup);

          // If this is a livemark container check if the status menuitem has
          // to be added or removed.
          if (PlacesUtils.nodeIsLivemarkContainer(aPopup._resultNode))
            PlacesUIUtils.ensureLivemarkStatusMenuItem(aPopup);

          var cc = aPopup._resultNode.childCount;
          if (cc > 0) {
            if (aPopup._emptyMenuItem)
              aPopup._emptyMenuItem.hidden = true;

            for (var i = 0; i < cc; ++i) {
              var child = aPopup._resultNode.getChild(i);
              this.insertNewItem(child, aPopup, null);
            }
          }
          else {
            // This menu is empty.  If there is no static content, add
            // an element to show it is empty.
            if (aPopup._startMarker == -1 && aPopup._endMarker == -1)
              this._showEmptyMenuItem(aPopup);
          }
          aPopup._built = true;
        ]]></body>
      </method>

      <!-- nsINavHistoryResultViewer -->
      <field name="_viewer"><![CDATA[({
        _self: this,

        _getPopupForContainer:
        function PMV__getPopupForContainer(aNode) {
          if (this._self._resultNode == aNode)
            return this._self;

          for (var i=0; i < this._self._containerNodesMap.length; i++) {
            if (this._self._containerNodesMap[i].resultNode == aNode)
              return this._self._containerNodesMap[i].domNode;
          }
          throw("Container view not found");
        },

        get result() {
          return this._self._result;
        },

        set result(val) {
          // some methods (e.g. getURLsFromContainer) temporarily null out the
          // viewer when they do temporary changes to the view, this does _not_
          // call setResult(null), but then, we're called again with the result
          // object which is already set for this viewer. At that point,
          // we should do nothing.
          if (this._self._result != val) {
            this._built = false;
            this._self._containerNodesMap = [];
            this._self._resultNode = val.root;
            this._self._result = val;
          }
          return val;
        },

        itemInserted: function PMV_itemInserted(aParentNode, aNode, aIndex) {
          var popup = this._getPopupForContainer(aParentNode);
          if (!popup._built)
            return;

          var index = popup._startMarker + 1 + aIndex;
          var before = popup.childNodes[index] || null;
          this._self.insertNewItem(aNode, popup, before);
          if (popup._emptyMenuItem)
            popup._emptyMenuItem.hidden = true;
        },

        itemRemoved: function PMV_itemRemoved(aParentNode, aNode, aIndex) {
          var popup = this._getPopupForContainer(aParentNode);
          if (!popup._built)
            return;

          var children = popup.childNodes;
          for (var i = 0; i < children.length; i++) {
            if (children[i].node == aNode) {
              this._self.removeItem(children[i]);
              if (!popup.hasChildNodes() ||
                  (popup.childNodes.length == 1 &&
                   popup.firstChild == popup._emptyMenuItem)) {
                this._self._showEmptyMenuItem(popup);
              }
              return;
            }
          }
        },

        itemMoved:
        function PMV_itemMoved(aItem, aOldParent, aOldIndex, aNewParent,
                               aNewIndex) {
          // This cannot actually happen yet (see IDL)
          if (aNewParent != aOldParent)
            return;

          var popup = this._getPopupForContainer(aNewParent);
          var index = popup._startMarker + 1 + aNewIndex;
          var children = popup.childNodes;
          for (var i = 0; i < children.length; i++) {
            var menuItem = children[i];
            if (menuItem.node == aItem) {
              popup.removeChild(menuItem);
              popup.insertBefore(menuItem, children[index]);
              return;
            }
          }
        },

        itemChanged: function PMV_itemChanged(aNode) {
          // this check can be removed once we fix bug #382397
          var parentNode = aNode.parent;
          if (!parentNode)
            return;

          var popup = this._getPopupForContainer(parentNode);
          if (!popup._built)
            return;

          var children = popup.childNodes;
          var menuitem;
          for (var i = 0; i < children.length; i++) {
            if (children[i].node == aNode) {
              menuitem = children[i];
              break;
            }
          }

          if (PlacesUtils.nodeIsSeparator(aNode)) {
            // nothing to do when a separator changes
            return;
          }

          var iconURI = aNode.icon;
          if (iconURI) {
            var spec = iconURI.spec;
            if (menuitem.getAttribute("image") != spec)
              menuitem.setAttribute("image", spec);
          }
          else
            menuitem.removeAttribute("image");

          var title = PlacesUIUtils.getBestTitle(aNode);
          if (menuitem.getAttribute("label") != title)
            menuitem.setAttribute("label", title);

          if (PlacesUtils.nodeIsLivemarkContainer(aNode)) {
            if (!menuitem.hasAttribute("livemark"))
              menuitem.setAttribute("livemark", "true");
            // If this is a livemark container check if the status menuitem has
            // to be added or removed.
            PlacesUIUtils.ensureLivemarkStatusMenuItem(menuitem.firstChild);
          }
          else if (PlacesUtils.nodeIsURI(aNode)) {
              menuitem.setAttribute("scheme", PlacesUIUtils.guessUrlSchemeForUI(aNode.uri));
          }
        },

        itemReplaced:
        function PMV_itemReplaced(aParentNode, aOldNode, aNewNode, aIndex) {
          var popup = this._getPopupForContainer(aParentNode);
          if (!popup._built)
            return;

          var children = popup.childNodes;
          for (var i = 0; i < children.length; i++) {
            if (children[i].node == aOldNode) {
              var next = children[i].nextSibling;
              this._self.removeItem(children[i]);
              this._self.insertNewItem(aNewNode, popup, next);
              return;
            }
          }
        },

        containerOpened: function PMV_containerOpened(aNode) {
          this.invalidateContainer(aNode);
        },

        containerClosed: function PMV_containerClosed(aNode) {
          this.invalidateContainer(aNode);
        },
 
        invalidateContainer: function PMV_invalidateContainer(aContainer) {
          if (!this._self._built)
            return;

          function isChildOf(node, container) {
            var parent = node.parent;
            while (parent) {
              if (parent == container)
                return true;
              parent = parent.parent;
            }
            return false;
          }

          var popupToRebuild = null;
          for (var i=0; i < this._self._containerNodesMap.length; i++) {
            var node = this._self._containerNodesMap[i].resultNode;

            if (node == aContainer)
              popupToRebuild = this._self._containerNodesMap[i].domNode;
            if (isChildOf(node, aContainer)) {
              this._self._containerNodesMap.splice(i,1);
              i--;
            }
          }

          if (!popupToRebuild)
            popupToRebuild = this._self;
          popupToRebuild._built = false;

          // if the menupopup is open we should live-update it
          if (popupToRebuild.parentNode.open)
            this._self._rebuild(popupToRebuild);
        },

        invalidateAll: function PMV_invalidateAll() {
          this._self._containerNodesMap.splice(0);
          this._self._built = false;
        },

        sortingChanged: function PMV_sortingChanged(aSortingMode) {
        }
      })]]></field>

      <!-- nsIPlacesView -->
      <property name="place">
        <getter><![CDATA[
          return this.getAttribute("place");
        ]]></getter>
        <setter><![CDATA[
          this.setAttribute("place", val);
          var queries = { }, options = { };
          PlacesUtils.history.queryStringToQueries(val, queries, { }, options);
          if (!queries.value.length)
            queries.value = [PlacesUtils.history.getNewQuery()];
          var result =
            PlacesUtils.history.executeQueries(queries.value,
                                               queries.value.length,
                                               options.value);
          result.viewer = this._viewer;
          return val;
        ]]></setter>
      </property>

      <!-- nsIPlacesView -->
      <property name="hasSelection">
        <getter><![CDATA[
          return this.selectedNode != null;
        ]]></getter>
      </property>

      <!-- nsIPlacesView -->
      <method name="getSelectionNodes">
        <body><![CDATA[
          var selectedNode = this.selectedNode;
          return selectedNode ? [selectedNode] : [];
        ]]></body>
      </method>

      <!-- nsIPlacesView -->
      <method name="getRemovableSelectionRanges">
        <body><![CDATA[
          // On static content the current selectedNode would be the selection's
          // parent node. We don't want to allow removing a node when the
          // selection is not explicit.
          if (document.popupNode &&
              (document.popupNode == "menupopup" || !document.popupNode.node))
            return [];

          return [this.getSelectionNodes()];
        ]]></body>
      </method>

      <!-- nsIPlacesView -->
      <method name="getDragableSelection">
        <body><![CDATA[
          return [this._draggedNode];
        ]]></body>
      </method>

      <!-- nsIPlacesView -->
      <property name="selectedNode">
        <getter><![CDATA[
          if (this._contextMenuShown) {
            var popupNode = document.popupNode;
            return popupNode.node || popupNode.parentNode._resultNode || null;
          }
          return null;
        ]]></getter>
      </property>

      <!-- nsIPlacesView -->
      <property name="insertionPoint">
        <getter><![CDATA[
          // there is no insertion point for history queries
          // so bail out now and save a lot of work when updating commands
          var resultNode = this._resultNode;
          if (PlacesUtils.nodeIsQuery(resultNode) &&
              asQuery(resultNode).queryOptions.queryType ==
                Ci.nsINavHistoryQueryOptions.QUERY_TYPE_HISTORY)
              return null;

          // By default, the insertion point is at the top level, at the end.
          var index = PlacesUtils.bookmarks.DEFAULT_INDEX;
          var container = null;
          var orientation = Ci.nsITreeView.DROP_BEFORE;
          var isTag = false;

          if (PlacesUtils.nodeIsFolder(resultNode)) {
            container = resultNode;
            isTag = PlacesUtils.nodeIsTagQuery(resultNode);
          }

          var selectedNode = this.selectedNode;
          if (selectedNode) {
            var popupNode = document.popupNode;
            if (!popupNode.node) {
              // If a static menuitem is selected the insertion point
              // is inside the folder, at the end.
              container = selectedNode;
              orientation = Ci.nsITreeView.DROP_ON;
            }
            else {
              // In all other cases the insertion point is before that node.
              container = selectedNode.parent;
              index = PlacesUtils.getIndexOfNode(selectedNode);
              isTag = PlacesUtils.nodeIsTagQuery(selectedNode.parent);
            }
          }

          if (PlacesControllerDragHelper.disallowInsertion(container))
            return null;

          return new InsertionPoint(PlacesUtils.getConcreteItemId(container),
                                    index, orientation, isTag);
        ]]></getter>
      </property>

      <!-- nsIPlacesView -->
      <method name="selectAll">
        <body/>
      </method>

      <method name="selectItems">
        <body/>
      </method>

      <property name="selType" readonly="true" onget="return 'single';"/>

      <method name="buildContextMenu">
        <parameter name="aPopup"/>
        <body><![CDATA[
          this._ensureInitialized();
          this._contextMenuShown = true;
          // Activate the controller
          this.focus();
          // The above call may not always fire a consumable event for
          // commandUpdater, so we force a command update.
          window.updateCommands("focus");
          return this.controller.buildContextMenu(aPopup);
        ]]></body>
      </method>

      <method name="destroyContextMenu">
        <parameter name="aPopup"/>
        <body>
          <![CDATA[
            this._contextMenuShown = false;
            if (window.content)
              window.content.focus();
          ]]>
        </body>
      </method>
    </implementation>
    <handlers>
      <handler event="popupshowing" phase="capturing"><![CDATA[
        this._ensureInitialized();
        var popup = event.target;
        // Avoid handling popupshowing of inner views
        if (!popup._resultNode || PlacesUIUtils.getViewForNode(popup) != this)
          return;

        this.onPopupShowing(event);
      ]]></handler>

      <handler event="popuphidden"><![CDATA[
        var popup = event.target;
        // We should avoid to handle events of inner views
        if (!popup._resultNode || PlacesUIUtils.getViewForNode(popup) != this)
          return;

        // UI performance: folder queries are cheap, keep the resultnode open
        // so we don't rebuild its contents whenever the popup is reopened.
        if (!PlacesUtils.nodeIsFolder(popup._resultNode))
          popup._resultNode.containerOpen = false;

        // The autoopened attribute is set for folders which have been
        // automatically opened when dragged over.  Turn off this attribute
        // when the folder closes because it is no longer applicable.
        popup.removeAttribute("autoopened");
        popup.removeAttribute("dragstart");
      ]]></handler>
    </handlers>
  </binding>

</bindings>