| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Draggable control for setting a page margin. | 9 * Draggable control for setting a page margin. |
| 10 * @param {!print_preview.ticket_items.CustomMargins.Orientation} orientation | 10 * @param {!print_preview.ticket_items.CustomMargins.Orientation} orientation |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 translateMouseToPositionInPixels: function(mousePosition) { | 300 translateMouseToPositionInPixels: function(mousePosition) { |
| 301 return new print_preview.Coordinate2d( | 301 return new print_preview.Coordinate2d( |
| 302 mousePosition.x - this.mouseStartPositionInPixels_.x + | 302 mousePosition.x - this.mouseStartPositionInPixels_.x + |
| 303 this.marginStartPositionInPixels_.x, | 303 this.marginStartPositionInPixels_.x, |
| 304 mousePosition.y - this.mouseStartPositionInPixels_.y + | 304 mousePosition.y - this.mouseStartPositionInPixels_.y + |
| 305 this.marginStartPositionInPixels_.y); | 305 this.marginStartPositionInPixels_.y); |
| 306 }, | 306 }, |
| 307 | 307 |
| 308 /** @override */ | 308 /** @override */ |
| 309 createDom: function() { | 309 createDom: function() { |
| 310 this.setElementInternal(this.cloneTemplateInternal( | 310 this.setElementInternal( |
| 311 'margin-control-template')); | 311 this.cloneTemplateInternal('margin-control-template')); |
| 312 this.getElement().classList.add('margin-control-' + this.orientation_); | 312 this.getElement().classList.add('margin-control-' + this.orientation_); |
| 313 this.textbox_ = this.getElement().getElementsByClassName( | 313 this.textbox_ = this.getElement().getElementsByClassName( |
| 314 MarginControl.Classes_.TEXTBOX)[0]; | 314 MarginControl.Classes_.TEXTBOX)[0]; |
| 315 this.textbox_.setAttribute( | 315 this.textbox_.setAttribute( |
| 316 'aria-label', loadTimeData.getString(this.orientation_)); | 316 'aria-label', loadTimeData.getString(this.orientation_)); |
| 317 this.marginLineEl_ = this.getElement().getElementsByClassName( | 317 this.marginLineEl_ = this.getElement().getElementsByClassName( |
| 318 MarginControl.Classes_.LINE)[0]; | 318 MarginControl.Classes_.LINE)[0]; |
| 319 }, | 319 }, |
| 320 | 320 |
| 321 /** @override */ | 321 /** @override */ |
| 322 enterDocument: function() { | 322 enterDocument: function() { |
| 323 print_preview.Component.prototype.enterDocument.call(this); | 323 print_preview.Component.prototype.enterDocument.call(this); |
| 324 this.tracker.add( | 324 this.tracker.add( |
| 325 this.getElement(), 'mousedown', this.onMouseDown_.bind(this)); | 325 this.getElement(), 'mousedown', this.onMouseDown_.bind(this)); |
| 326 this.tracker.add( | 326 this.tracker.add( |
| 327 this.getElement(), | 327 this.getElement(), 'webkitTransitionEnd', |
| 328 'webkitTransitionEnd', | |
| 329 this.onWebkitTransitionEnd_.bind(this)); | 328 this.onWebkitTransitionEnd_.bind(this)); |
| 330 this.tracker.add( | 329 this.tracker.add(this.textbox_, 'input', this.onTextboxInput_.bind(this)); |
| 331 this.textbox_, 'input', this.onTextboxInput_.bind(this)); | |
| 332 this.tracker.add( | 330 this.tracker.add( |
| 333 this.textbox_, 'keydown', this.onTextboxKeyDown_.bind(this)); | 331 this.textbox_, 'keydown', this.onTextboxKeyDown_.bind(this)); |
| 334 this.tracker.add( | 332 this.tracker.add( |
| 335 this.textbox_, 'focus', this.setIsFocused_.bind(this, true)); | 333 this.textbox_, 'focus', this.setIsFocused_.bind(this, true)); |
| 336 this.tracker.add(this.textbox_, 'blur', this.onTexboxBlur_.bind(this)); | 334 this.tracker.add(this.textbox_, 'blur', this.onTexboxBlur_.bind(this)); |
| 337 }, | 335 }, |
| 338 | 336 |
| 339 /** @override */ | 337 /** @override */ |
| 340 exitDocument: function() { | 338 exitDocument: function() { |
| 341 print_preview.Component.prototype.exitDocument.call(this); | 339 print_preview.Component.prototype.exitDocument.call(this); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 361 previewArea.scrollLeft = 0; | 359 previewArea.scrollLeft = 0; |
| 362 } | 360 } |
| 363 }, | 361 }, |
| 364 | 362 |
| 365 /** | 363 /** |
| 366 * Called whenever a mousedown event occurs on the component. | 364 * Called whenever a mousedown event occurs on the component. |
| 367 * @param {MouseEvent} event The event that occured. | 365 * @param {MouseEvent} event The event that occured. |
| 368 * @private | 366 * @private |
| 369 */ | 367 */ |
| 370 onMouseDown_: function(event) { | 368 onMouseDown_: function(event) { |
| 371 if (!this.textbox_.disabled && | 369 if (!this.textbox_.disabled && event.button == 0 && |
| 372 event.button == 0 && | |
| 373 (event.target == this.getElement() || | 370 (event.target == this.getElement() || |
| 374 event.target == this.marginLineEl_)) { | 371 event.target == this.marginLineEl_)) { |
| 375 this.mouseStartPositionInPixels_ = | 372 this.mouseStartPositionInPixels_ = |
| 376 new print_preview.Coordinate2d(event.x, event.y); | 373 new print_preview.Coordinate2d(event.x, event.y); |
| 377 this.marginStartPositionInPixels_ = new print_preview.Coordinate2d( | 374 this.marginStartPositionInPixels_ = new print_preview.Coordinate2d( |
| 378 this.getElement().offsetLeft, this.getElement().offsetTop); | 375 this.getElement().offsetLeft, this.getElement().offsetTop); |
| 379 this.setIsInError(false); | 376 this.setIsInError(false); |
| 380 cr.dispatchSimpleEvent(this, MarginControl.EventType.DRAG_START); | 377 cr.dispatchSimpleEvent(this, MarginControl.EventType.DRAG_START); |
| 381 } | 378 } |
| 382 }, | 379 }, |
| 383 | 380 |
| 384 /** | 381 /** |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 if (this.textTimeout_) { | 437 if (this.textTimeout_) { |
| 441 clearTimeout(this.textTimeout_); | 438 clearTimeout(this.textTimeout_); |
| 442 this.textTimeout_ = null; | 439 this.textTimeout_ = null; |
| 443 } | 440 } |
| 444 this.setIsFocused_(false); | 441 this.setIsFocused_(false); |
| 445 cr.dispatchSimpleEvent(this, MarginControl.EventType.TEXT_CHANGE); | 442 cr.dispatchSimpleEvent(this, MarginControl.EventType.TEXT_CHANGE); |
| 446 } | 443 } |
| 447 }; | 444 }; |
| 448 | 445 |
| 449 // Export | 446 // Export |
| 450 return { | 447 return {MarginControl: MarginControl}; |
| 451 MarginControl: MarginControl | |
| 452 }; | |
| 453 }); | 448 }); |
| OLD | NEW |