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 cr.define('print_preview', function() { | 5 cr.define('print_preview', function() { |
6 'strict'; | 6 'strict'; |
7 | 7 |
8 /** | 8 /** |
9 * @constructor | 9 * @constructor |
10 * This class represents a margin line and a textbox corresponding to that | 10 * This class represents a margin line and a textbox corresponding to that |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 | 158 |
159 /** | 159 /** |
160 * Adds event listeners for events related to dragging. | 160 * Adds event listeners for events related to dragging. |
161 */ | 161 */ |
162 addEventListeners_: function() { | 162 addEventListeners_: function() { |
163 this.onmousedown = this.onMouseDown_.bind(this); | 163 this.onmousedown = this.onMouseDown_.bind(this); |
164 }, | 164 }, |
165 | 165 |
166 /** | 166 /** |
167 * Executes whenever a mousedown event occurs on |this| or its child nodes. | 167 * Executes whenever a mousedown event occurs on |this| or its child nodes. |
168 * @parameter {MouseEvent} e The event that occured. | 168 * @param {MouseEvent} e The event that occured. |
169 */ | 169 */ |
170 onMouseDown_: function(e) { | 170 onMouseDown_: function(e) { |
171 if (e.button != 0) | 171 if (e.button != 0) |
172 return; | 172 return; |
173 if (e.target != this) | 173 if (e.target != this) |
174 return; | 174 return; |
175 var point = print_preview.MarginsUI.convert({x: e.x, y: e.y}); | 175 var point = print_preview.MarginsUI.convert({x: e.x, y: e.y}); |
176 this.originBeforeDragging = { x: this.offsetLeft, y: this.offsetTop }; | 176 this.originBeforeDragging = { x: this.offsetLeft, y: this.offsetTop }; |
177 this.mousePointerOffset = | 177 this.mousePointerOffset = |
178 { x: point.x - this.offsetLeft, y: point.y - this.offsetTop }; | 178 { x: point.x - this.offsetLeft, y: point.y - this.offsetTop }; |
179 cr.dispatchSimpleEvent(this, customEvents.MARGIN_LINE_MOUSE_DOWN); | 179 cr.dispatchSimpleEvent(this, customEvents.MARGIN_LINE_MOUSE_DOWN); |
180 }, | 180 }, |
181 | 181 |
182 /** | 182 /** |
183 * Executes whenever a mouseup event occurs while |this| is dragged. | 183 * Executes whenever a mouseup event occurs while |this| is dragged. |
184 */ | 184 */ |
185 onMouseUp: function() { | 185 onMouseUp: function() { |
186 this.box_.onTextValueMayHaveChanged(); | 186 this.box_.onTextValueMayHaveChanged(); |
187 }, | 187 }, |
188 | 188 |
189 /** | 189 /** |
190 * Moves |this| including all its children to |point|. | 190 * Moves |this| including all its children to |point|. |
191 * @param {{x: number, y: number}} point The point where |this| should be | 191 * @param {{x: number, y: number}} point The point where |this| should be |
192 * moved. | 192 * moved. |
193 */ | 193 */ |
194 moveTo: function(point) { | 194 moveTo: function(point) { |
195 if (this.isTop_() || this.isBottom_()) | 195 if (this.isTop_() || this.isBottom_()) |
196 this.style.top = point.y - this.mousePointerOffset.y + 'px'; | 196 this.style.top = point.y - this.mousePointerOffset.y + 'px'; |
197 else | 197 else |
198 this.style.left = point.x - this.mousePointerOffset.x + 'px'; | 198 this.style.left = point.x - this.mousePointerOffset.x + 'px'; |
199 }, | 199 }, |
200 | 200 |
201 /** | 201 /** |
202 * @param {{x: number, y: number}} rhs The point to compare with. | 202 * @param {{x: number, y: number}} rhs The point to compare with. |
203 * @return {number} The horizontal or vertical displacement in pixels | 203 * @return {number} The horizontal or vertical displacement in pixels |
204 * between |this.originBeforeDragging| and |rhs|. Note: Bottom margin | 204 * between |this.originBeforeDragging| and |rhs|. Note: Bottom margin |
205 * grows upwards, right margin grows when going to the left. | 205 * grows upwards, right margin grows when going to the left. |
206 */ | 206 */ |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 | 287 |
288 this.rectangle = this.getCoordinates_(newMarginsRectangle); | 288 this.rectangle = this.getCoordinates_(newMarginsRectangle); |
289 this.drawDraggableArea_(); | 289 this.drawDraggableArea_(); |
290 }, | 290 }, |
291 }; | 291 }; |
292 | 292 |
293 return { | 293 return { |
294 MarginsUIPair: MarginsUIPair | 294 MarginsUIPair: MarginsUIPair |
295 }; | 295 }; |
296 }); | 296 }); |
OLD | NEW |