OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * This view implements a vertically split display with a draggable divider. | 6 * This view implements a vertically split display with a draggable divider. |
7 * | 7 * |
8 * <<-- sizer -->> | 8 * <<-- sizer -->> |
9 * | 9 * |
10 * +----------------------++----------------+ | 10 * +----------------------++----------------+ |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 // vertical split. The start event must occur within the sizer's node, | 51 // vertical split. The start event must occur within the sizer's node, |
52 // but subsequent events may occur anywhere. | 52 // but subsequent events may occur anywhere. |
53 var node = sizerView.getNode(); | 53 var node = sizerView.getNode(); |
54 node.addEventListener('mousedown', this.onMouseDragSizerStart_.bind(this)); | 54 node.addEventListener('mousedown', this.onMouseDragSizerStart_.bind(this)); |
55 window.addEventListener('mousemove', this.onMouseDragSizer_.bind(this)); | 55 window.addEventListener('mousemove', this.onMouseDragSizer_.bind(this)); |
56 window.addEventListener('mouseup', this.onMouseDragSizerEnd_.bind(this)); | 56 window.addEventListener('mouseup', this.onMouseDragSizerEnd_.bind(this)); |
57 | 57 |
58 node.addEventListener('touchstart', this.onTouchDragSizerStart_.bind(this)); | 58 node.addEventListener('touchstart', this.onTouchDragSizerStart_.bind(this)); |
59 window.addEventListener('touchmove', this.onTouchDragSizer_.bind(this)); | 59 window.addEventListener('touchmove', this.onTouchDragSizer_.bind(this)); |
60 window.addEventListener('touchend', this.onTouchDragSizerEnd_.bind(this)); | 60 window.addEventListener('touchend', this.onTouchDragSizerEnd_.bind(this)); |
61 window.addEventListener('touchcancel', | 61 window.addEventListener( |
62 this.onTouchDragSizerEnd_.bind(this)); | 62 'touchcancel', this.onTouchDragSizerEnd_.bind(this)); |
63 } | 63 } |
64 | 64 |
65 ResizableVerticalSplitView.prototype = { | 65 ResizableVerticalSplitView.prototype = { |
66 // Inherit the superclass's methods. | 66 // Inherit the superclass's methods. |
67 __proto__: superClass.prototype, | 67 __proto__: superClass.prototype, |
68 | 68 |
69 /** | 69 /** |
70 * Sets the width of the left view. | 70 * Sets the width of the left view. |
71 * @param {Integer} px The number of pixels | 71 * @param {Integer} px The number of pixels |
72 */ | 72 */ |
(...skipping 17 matching lines...) Expand all Loading... |
90 var rightboxWidth = width - (leftboxWidth + sizerWidth); | 90 var rightboxWidth = width - (leftboxWidth + sizerWidth); |
91 | 91 |
92 // Don't let the right pane get too small. | 92 // Don't let the right pane get too small. |
93 if (rightboxWidth < MIN_PANEL_WIDTH) { | 93 if (rightboxWidth < MIN_PANEL_WIDTH) { |
94 rightboxWidth = MIN_PANEL_WIDTH; | 94 rightboxWidth = MIN_PANEL_WIDTH; |
95 leftboxWidth = width - (sizerWidth + rightboxWidth); | 95 leftboxWidth = width - (sizerWidth + rightboxWidth); |
96 } | 96 } |
97 | 97 |
98 // Position the boxes using calculated split points. | 98 // Position the boxes using calculated split points. |
99 this.leftView_.setGeometry(left, top, leftboxWidth, height); | 99 this.leftView_.setGeometry(left, top, leftboxWidth, height); |
100 this.sizerView_.setGeometry(this.leftView_.getRight(), top, | 100 this.sizerView_.setGeometry( |
101 sizerWidth, height); | 101 this.leftView_.getRight(), top, sizerWidth, height); |
102 this.rightView_.setGeometry(this.sizerView_.getRight(), top, | 102 this.rightView_.setGeometry( |
103 rightboxWidth, height); | 103 this.sizerView_.getRight(), top, rightboxWidth, height); |
104 }, | 104 }, |
105 | 105 |
106 show: function(isVisible) { | 106 show: function(isVisible) { |
107 superClass.prototype.show.call(this, isVisible); | 107 superClass.prototype.show.call(this, isVisible); |
108 this.leftView_.show(isVisible); | 108 this.leftView_.show(isVisible); |
109 this.sizerView_.show(isVisible); | 109 this.sizerView_.show(isVisible); |
110 this.rightView_.show(isVisible); | 110 this.rightView_.show(isVisible); |
111 }, | 111 }, |
112 | 112 |
113 /** | 113 /** |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 /** | 175 /** |
176 * Common code used for both mouse and touch dragging. | 176 * Common code used for both mouse and touch dragging. |
177 */ | 177 */ |
178 onDragSizer_: function(pageX) { | 178 onDragSizer_: function(pageX) { |
179 // Convert from page coordinates, to view coordinates. | 179 // Convert from page coordinates, to view coordinates. |
180 this.leftSplit_ = (pageX - this.getLeft()); | 180 this.leftSplit_ = (pageX - this.getLeft()); |
181 | 181 |
182 // Avoid shrinking the left box too much. | 182 // Avoid shrinking the left box too much. |
183 this.leftSplit_ = Math.max(this.leftSplit_, MIN_PANEL_WIDTH); | 183 this.leftSplit_ = Math.max(this.leftSplit_, MIN_PANEL_WIDTH); |
184 // Avoid shrinking the right box too much. | 184 // Avoid shrinking the right box too much. |
185 this.leftSplit_ = Math.min( | 185 this.leftSplit_ = |
186 this.leftSplit_, this.getWidth() - MIN_PANEL_WIDTH); | 186 Math.min(this.leftSplit_, this.getWidth() - MIN_PANEL_WIDTH); |
187 | 187 |
188 // Force a layout with the new |leftSplit_|. | 188 // Force a layout with the new |leftSplit_|. |
189 this.setGeometry( | 189 this.setGeometry( |
190 this.getLeft(), this.getTop(), this.getWidth(), this.getHeight()); | 190 this.getLeft(), this.getTop(), this.getWidth(), this.getHeight()); |
191 }, | 191 }, |
192 }; | 192 }; |
193 | 193 |
194 return ResizableVerticalSplitView; | 194 return ResizableVerticalSplitView; |
195 })(); | 195 })(); |
OLD | NEW |