| 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 26 matching lines...) Expand all Loading... |
| 37 * @constructor | 37 * @constructor |
| 38 */ | 38 */ |
| 39 function ResizableVerticalSplitView(leftView, rightView, sizerView) { | 39 function ResizableVerticalSplitView(leftView, rightView, sizerView) { |
| 40 // Call superclass's constructor. | 40 // Call superclass's constructor. |
| 41 superClass.call(this); | 41 superClass.call(this); |
| 42 | 42 |
| 43 this.leftView_ = leftView; | 43 this.leftView_ = leftView; |
| 44 this.rightView_ = rightView; | 44 this.rightView_ = rightView; |
| 45 this.sizerView_ = sizerView; | 45 this.sizerView_ = sizerView; |
| 46 | 46 |
| 47 this.mouseDragging_ = false; |
| 48 this.touchDragging_ = false; |
| 49 |
| 47 // Setup the "sizer" so it can be dragged left/right to reposition the | 50 // Setup the "sizer" so it can be dragged left/right to reposition the |
| 48 // vertical split. | 51 // vertical split. The start event must occur within the sizer's node, |
| 49 sizerView.getNode().addEventListener( | 52 // but subsequent events may occur anywhere. |
| 50 'mousedown', this.onDragSizerStart_.bind(this), true); | 53 var node = sizerView.getNode(); |
| 54 node.addEventListener('mousedown', this.onMouseDragSizerStart_.bind(this)); |
| 55 window.addEventListener('mousemove', this.onMouseDragSizer_.bind(this)); |
| 56 window.addEventListener('mouseup', this.onMouseDragSizerEnd_.bind(this)); |
| 57 |
| 58 node.addEventListener('touchstart', this.onTouchDragSizerStart_.bind(this)); |
| 59 window.addEventListener('touchmove', this.onTouchDragSizer_.bind(this)); |
| 60 window.addEventListener('touchend', this.onTouchDragSizerEnd_.bind(this)); |
| 61 window.addEventListener('touchcancel', |
| 62 this.onTouchDragSizerEnd_.bind(this)); |
| 51 } | 63 } |
| 52 | 64 |
| 53 ResizableVerticalSplitView.prototype = { | 65 ResizableVerticalSplitView.prototype = { |
| 54 // Inherit the superclass's methods. | 66 // Inherit the superclass's methods. |
| 55 __proto__: superClass.prototype, | 67 __proto__: superClass.prototype, |
| 56 | 68 |
| 57 /** | 69 /** |
| 58 * Sets the width of the left view. | 70 * Sets the width of the left view. |
| 59 * @param {Integer} px The number of pixels | 71 * @param {Integer} px The number of pixels |
| 60 */ | 72 */ |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 }, | 104 }, |
| 93 | 105 |
| 94 show: function(isVisible) { | 106 show: function(isVisible) { |
| 95 superClass.prototype.show.call(this, isVisible); | 107 superClass.prototype.show.call(this, isVisible); |
| 96 this.leftView_.show(isVisible); | 108 this.leftView_.show(isVisible); |
| 97 this.sizerView_.show(isVisible); | 109 this.sizerView_.show(isVisible); |
| 98 this.rightView_.show(isVisible); | 110 this.rightView_.show(isVisible); |
| 99 }, | 111 }, |
| 100 | 112 |
| 101 /** | 113 /** |
| 102 * Called once we have clicked into the sizer. Starts capturing the mouse | 114 * Called once the sizer is clicked on. Starts moving the sizer in response |
| 103 * position to implement dragging. | 115 * to future mouse movement. |
| 104 */ | 116 */ |
| 105 onDragSizerStart_: function(event) { | 117 onMouseDragSizerStart_: function(event) { |
| 106 this.sizerMouseMoveListener_ = this.onDragSizer_.bind(this); | 118 this.mouseDragging_ = true; |
| 107 this.sizerMouseUpListener_ = this.onDragSizerEnd_.bind(this); | 119 event.preventDefault(); |
| 120 }, |
| 108 | 121 |
| 109 window.addEventListener('mousemove', this.sizerMouseMoveListener_, true); | 122 /** |
| 110 window.addEventListener('mouseup', this.sizerMouseUpListener_, true); | 123 * Called when the mouse has moved. |
| 124 */ |
| 125 onMouseDragSizer_: function(event) { |
| 126 if (!this.mouseDragging_) |
| 127 return; |
| 128 // If dragging has started, move the sizer. |
| 129 this.onDragSizer_(event.pageX); |
| 130 event.preventDefault(); |
| 131 }, |
| 111 | 132 |
| 133 /** |
| 134 * Called once the mouse has been released. |
| 135 */ |
| 136 onMouseDragSizerEnd_: function(event) { |
| 137 if (!this.mouseDragging_) |
| 138 return; |
| 139 // Dragging is over. |
| 140 this.mouseDragging_ = false; |
| 141 event.preventDefault(); |
| 142 }, |
| 143 |
| 144 /** |
| 145 * Called when the user touches the sizer. Starts moving the sizer in |
| 146 * response to future touch events. |
| 147 */ |
| 148 onTouchDragSizerStart_: function(event) { |
| 149 this.touchDragging_ = true; |
| 112 event.preventDefault(); | 150 event.preventDefault(); |
| 113 }, | 151 }, |
| 114 | 152 |
| 115 /** | 153 /** |
| 116 * Called when the mouse has moved after dragging started. | 154 * Called when the mouse has moved after dragging started. |
| 117 */ | 155 */ |
| 118 onDragSizer_: function(event) { | 156 onTouchDragSizer_: function(event) { |
| 157 if (!this.touchDragging_) |
| 158 return; |
| 159 // If dragging has started, move the sizer. |
| 160 this.onDragSizer_(event.touches[0].pageX); |
| 161 event.preventDefault(); |
| 162 }, |
| 163 |
| 164 /** |
| 165 * Called once the user stops touching the screen. |
| 166 */ |
| 167 onTouchDragSizerEnd_: function(event) { |
| 168 if (!this.touchDragging_) |
| 169 return; |
| 170 // Dragging is over. |
| 171 this.touchDragging_ = false; |
| 172 event.preventDefault(); |
| 173 }, |
| 174 |
| 175 /** |
| 176 * Common code used for both mouse and touch dragging. |
| 177 */ |
| 178 onDragSizer_: function(pageX) { |
| 119 // Convert from page coordinates, to view coordinates. | 179 // Convert from page coordinates, to view coordinates. |
| 120 this.leftSplit_ = (event.pageX - this.getLeft()); | 180 this.leftSplit_ = (pageX - this.getLeft()); |
| 121 | 181 |
| 122 // Avoid shrinking the left box too much. | 182 // Avoid shrinking the left box too much. |
| 123 this.leftSplit_ = Math.max(this.leftSplit_, MIN_PANEL_WIDTH); | 183 this.leftSplit_ = Math.max(this.leftSplit_, MIN_PANEL_WIDTH); |
| 124 // Avoid shrinking the right box too much. | 184 // Avoid shrinking the right box too much. |
| 125 this.leftSplit_ = Math.min( | 185 this.leftSplit_ = Math.min( |
| 126 this.leftSplit_, this.getWidth() - MIN_PANEL_WIDTH); | 186 this.leftSplit_, this.getWidth() - MIN_PANEL_WIDTH); |
| 127 | 187 |
| 128 // Force a layout with the new |leftSplit_|. | 188 // Force a layout with the new |leftSplit_|. |
| 129 this.setGeometry( | 189 this.setGeometry( |
| 130 this.getLeft(), this.getTop(), this.getWidth(), this.getHeight()); | 190 this.getLeft(), this.getTop(), this.getWidth(), this.getHeight()); |
| 131 }, | 191 }, |
| 132 | |
| 133 /** | |
| 134 * Called once the mouse has been released, and the dragging is over. | |
| 135 */ | |
| 136 onDragSizerEnd_: function(event) { | |
| 137 window.removeEventListener( | |
| 138 'mousemove', this.sizerMouseMoveListener_, true); | |
| 139 window.removeEventListener('mouseup', this.sizerMouseUpListener_, true); | |
| 140 | |
| 141 this.sizerMouseMoveListener_ = null; | |
| 142 this.sizerMouseUpListener_ = null; | |
| 143 | |
| 144 event.preventDefault(); | |
| 145 } | |
| 146 }; | 192 }; |
| 147 | 193 |
| 148 return ResizableVerticalSplitView; | 194 return ResizableVerticalSplitView; |
| 149 })(); | 195 })(); |
| OLD | NEW |