browser/base/content/newtab/cells.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 #ifdef 0
     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 file,
     4  * You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #endif
     7 /**
     8  * This class manages a cell's DOM node (not the actually cell content, a site).
     9  * It's mostly read-only, i.e. all manipulation of both position and content
    10  * aren't handled here.
    11  */
    12 function Cell(aGrid, aNode) {
    13   this._grid = aGrid;
    14   this._node = aNode;
    15   this._node._newtabCell = this;
    17   // Register drag-and-drop event handlers.
    18   ["dragenter", "dragover", "dragexit", "drop"].forEach(function (aType) {
    19     this._node.addEventListener(aType, this, false);
    20   }, this);
    21 }
    23 Cell.prototype = {
    24   /**
    25    * The grid.
    26    */
    27   _grid: null,
    29   /**
    30    * The cell's DOM node.
    31    */
    32   get node() this._node,
    34   /**
    35    * The cell's offset in the grid.
    36    */
    37   get index() {
    38     let index = this._grid.cells.indexOf(this);
    40     // Cache this value, overwrite the getter.
    41     Object.defineProperty(this, "index", {value: index, enumerable: true});
    43     return index;
    44   },
    46   /**
    47    * The previous cell in the grid.
    48    */
    49   get previousSibling() {
    50     let prev = this.node.previousElementSibling;
    51     prev = prev && prev._newtabCell;
    53     // Cache this value, overwrite the getter.
    54     Object.defineProperty(this, "previousSibling", {value: prev, enumerable: true});
    56     return prev;
    57   },
    59   /**
    60    * The next cell in the grid.
    61    */
    62   get nextSibling() {
    63     let next = this.node.nextElementSibling;
    64     next = next && next._newtabCell;
    66     // Cache this value, overwrite the getter.
    67     Object.defineProperty(this, "nextSibling", {value: next, enumerable: true});
    69     return next;
    70   },
    72   /**
    73    * The site contained in the cell, if any.
    74    */
    75   get site() {
    76     let firstChild = this.node.firstElementChild;
    77     return firstChild && firstChild._newtabSite;
    78   },
    80   /**
    81    * Checks whether the cell contains a pinned site.
    82    * @return Whether the cell contains a pinned site.
    83    */
    84   containsPinnedSite: function Cell_containsPinnedSite() {
    85     let site = this.site;
    86     return site && site.isPinned();
    87   },
    89   /**
    90    * Checks whether the cell contains a site (is empty).
    91    * @return Whether the cell is empty.
    92    */
    93   isEmpty: function Cell_isEmpty() {
    94     return !this.site;
    95   },
    97   /**
    98    * Handles all cell events.
    99    */
   100   handleEvent: function Cell_handleEvent(aEvent) {
   101     // We're not responding to external drag/drop events
   102     // when our parent window is in private browsing mode.
   103     if (inPrivateBrowsingMode() && !gDrag.draggedSite)
   104       return;
   106     if (aEvent.type != "dragexit" && !gDrag.isValid(aEvent))
   107       return;
   109     switch (aEvent.type) {
   110       case "dragenter":
   111         aEvent.preventDefault();
   112         gDrop.enter(this, aEvent);
   113         break;
   114       case "dragover":
   115         aEvent.preventDefault();
   116         break;
   117       case "dragexit":
   118         gDrop.exit(this, aEvent);
   119         break;
   120       case "drop":
   121         aEvent.preventDefault();
   122         gDrop.drop(this, aEvent);
   123         break;
   124     }
   125   }
   126 };

mercurial