1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 * @fileoverview This implements a splitter element which can be used to resize
9 * Each splitter is associated with certain column and resizes it when dragged.
10 * It is column model responsibility to resize other columns accordingly.
13 cr.define('cr.ui', function() {
14 /** @const */ var Splitter = cr.ui.Splitter;
17 * Creates a new table splitter element.
18 * @param {Object=} opt_propertyBag Optional properties.
20 * @extends {cr.ui.Splitter}
22 var TableSplitter = cr.ui.define('div');
24 TableSplitter.prototype = {
25 __proto__: Splitter.prototype,
32 * Initializes the element.
34 decorate: function() {
35 Splitter.prototype.decorate.call(this);
37 this.classList.add('table-header-splitter');
41 * Handles start of the splitter dragging.
42 * Saves starting width of the column and changes the cursor.
45 handleSplitterDragStart: function() {
46 var cm = this.table_.columnModel;
47 this.ownerDocument.documentElement.classList.add('col-resize');
49 this.columnWidth_ = cm.getWidth(this.columnIndex);
50 this.nextColumnWidth_ = cm.getWidth(this.columnIndex + 1);
54 * Handles spliter moves. Sets new width of the column.
57 handleSplitterDragMove: function(deltaX) {
58 this.table_.columnModel.setWidth(this.columnIndex,
59 this.columnWidth_ + deltaX);
63 * Handles end of the splitter dragging. Restores cursor.
66 handleSplitterDragEnd: function() {
67 this.ownerDocument.documentElement.classList.remove('col-resize');
68 cr.dispatchSimpleEvent(this, 'column-resize-end', true);
76 cr.defineProperty(TableSplitter, 'columnIndex');
79 * The table associated with the splitter.
82 cr.defineProperty(TableSplitter, 'table');
85 TableSplitter: TableSplitter