michael@0: #ifdef 0 michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: #endif michael@0: michael@0: /** michael@0: * This class manages a cell's DOM node (not the actually cell content, a site). michael@0: * It's mostly read-only, i.e. all manipulation of both position and content michael@0: * aren't handled here. michael@0: */ michael@0: function Cell(aGrid, aNode) { michael@0: this._grid = aGrid; michael@0: this._node = aNode; michael@0: this._node._newtabCell = this; michael@0: michael@0: // Register drag-and-drop event handlers. michael@0: ["dragenter", "dragover", "dragexit", "drop"].forEach(function (aType) { michael@0: this._node.addEventListener(aType, this, false); michael@0: }, this); michael@0: } michael@0: michael@0: Cell.prototype = { michael@0: /** michael@0: * The grid. michael@0: */ michael@0: _grid: null, michael@0: michael@0: /** michael@0: * The cell's DOM node. michael@0: */ michael@0: get node() this._node, michael@0: michael@0: /** michael@0: * The cell's offset in the grid. michael@0: */ michael@0: get index() { michael@0: let index = this._grid.cells.indexOf(this); michael@0: michael@0: // Cache this value, overwrite the getter. michael@0: Object.defineProperty(this, "index", {value: index, enumerable: true}); michael@0: michael@0: return index; michael@0: }, michael@0: michael@0: /** michael@0: * The previous cell in the grid. michael@0: */ michael@0: get previousSibling() { michael@0: let prev = this.node.previousElementSibling; michael@0: prev = prev && prev._newtabCell; michael@0: michael@0: // Cache this value, overwrite the getter. michael@0: Object.defineProperty(this, "previousSibling", {value: prev, enumerable: true}); michael@0: michael@0: return prev; michael@0: }, michael@0: michael@0: /** michael@0: * The next cell in the grid. michael@0: */ michael@0: get nextSibling() { michael@0: let next = this.node.nextElementSibling; michael@0: next = next && next._newtabCell; michael@0: michael@0: // Cache this value, overwrite the getter. michael@0: Object.defineProperty(this, "nextSibling", {value: next, enumerable: true}); michael@0: michael@0: return next; michael@0: }, michael@0: michael@0: /** michael@0: * The site contained in the cell, if any. michael@0: */ michael@0: get site() { michael@0: let firstChild = this.node.firstElementChild; michael@0: return firstChild && firstChild._newtabSite; michael@0: }, michael@0: michael@0: /** michael@0: * Checks whether the cell contains a pinned site. michael@0: * @return Whether the cell contains a pinned site. michael@0: */ michael@0: containsPinnedSite: function Cell_containsPinnedSite() { michael@0: let site = this.site; michael@0: return site && site.isPinned(); michael@0: }, michael@0: michael@0: /** michael@0: * Checks whether the cell contains a site (is empty). michael@0: * @return Whether the cell is empty. michael@0: */ michael@0: isEmpty: function Cell_isEmpty() { michael@0: return !this.site; michael@0: }, michael@0: michael@0: /** michael@0: * Handles all cell events. michael@0: */ michael@0: handleEvent: function Cell_handleEvent(aEvent) { michael@0: // We're not responding to external drag/drop events michael@0: // when our parent window is in private browsing mode. michael@0: if (inPrivateBrowsingMode() && !gDrag.draggedSite) michael@0: return; michael@0: michael@0: if (aEvent.type != "dragexit" && !gDrag.isValid(aEvent)) michael@0: return; michael@0: michael@0: switch (aEvent.type) { michael@0: case "dragenter": michael@0: aEvent.preventDefault(); michael@0: gDrop.enter(this, aEvent); michael@0: break; michael@0: case "dragover": michael@0: aEvent.preventDefault(); michael@0: break; michael@0: case "dragexit": michael@0: gDrop.exit(this, aEvent); michael@0: break; michael@0: case "drop": michael@0: aEvent.preventDefault(); michael@0: gDrop.drop(this, aEvent); michael@0: break; michael@0: } michael@0: } michael@0: };