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