| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 * @fileoverview | 6 * @fileoverview |
| 7 * A module that contains basic utility components and methods for the | 7 * A module that contains basic utility components and methods for the |
| 8 * chromoting project | 8 * chromoting project |
| 9 * | 9 * |
| 10 */ | 10 */ |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 * ); | 500 * ); |
| 501 * } | 501 * } |
| 502 * | 502 * |
| 503 * MyConstructor.prototype.dispose = function() { | 503 * MyConstructor.prototype.dispose = function() { |
| 504 * this.eventHooks_.dispose(); | 504 * this.eventHooks_.dispose(); |
| 505 * this.eventHooks_ = null; | 505 * this.eventHooks_ = null; |
| 506 * } | 506 * } |
| 507 * | 507 * |
| 508 * @param {base.EventSource} src | 508 * @param {base.EventSource} src |
| 509 * @param {string} eventName | 509 * @param {string} eventName |
| 510 * @param {function(...?)} listener | 510 * @param {Function} listener |
| 511 * | 511 * |
| 512 * @constructor | 512 * @constructor |
| 513 * @implements {base.Disposable} | 513 * @implements {base.Disposable} |
| 514 */ | 514 */ |
| 515 base.EventHook = function(src, eventName, listener) { | 515 base.EventHook = function(src, eventName, listener) { |
| 516 this.src_ = src; | 516 this.src_ = src; |
| 517 this.eventName_ = eventName; | 517 this.eventName_ = eventName; |
| 518 this.listener_ = listener; | 518 this.listener_ = listener; |
| 519 src.addEventListener(eventName, listener); | 519 src.addEventListener(eventName, listener); |
| 520 }; | 520 }; |
| 521 | 521 |
| 522 base.EventHook.prototype.dispose = function() { | 522 base.EventHook.prototype.dispose = function() { |
| 523 this.src_.removeEventListener(this.eventName_, this.listener_); | 523 this.src_.removeEventListener(this.eventName_, this.listener_); |
| 524 }; | 524 }; |
| 525 | 525 |
| 526 /** | 526 /** |
| 527 * An event hook implementation for DOM Events. | 527 * An event hook implementation for DOM Events. |
| 528 * | 528 * |
| 529 * @param {HTMLElement|Element} src | 529 * @param {HTMLElement|Element|Window|HTMLDocument} src |
| 530 * @param {string} eventName | 530 * @param {string} eventName |
| 531 * @param {function(...?)} listener | 531 * @param {Function} listener |
| 532 * @param {boolean} capture | 532 * @param {boolean} capture |
| 533 * | 533 * |
| 534 * @constructor | 534 * @constructor |
| 535 * @implements {base.Disposable} | 535 * @implements {base.Disposable} |
| 536 */ | 536 */ |
| 537 base.DomEventHook = function(src, eventName, listener, capture) { | 537 base.DomEventHook = function(src, eventName, listener, capture) { |
| 538 this.src_ = src; | 538 this.src_ = src; |
| 539 this.eventName_ = eventName; | 539 this.eventName_ = eventName; |
| 540 this.listener_ = listener; | 540 this.listener_ = listener; |
| 541 this.capture_ = capture; | 541 this.capture_ = capture; |
| 542 src.addEventListener(eventName, listener, capture); | 542 src.addEventListener(eventName, listener, capture); |
| 543 }; | 543 }; |
| 544 | 544 |
| 545 base.DomEventHook.prototype.dispose = function() { | 545 base.DomEventHook.prototype.dispose = function() { |
| 546 this.src_.removeEventListener(this.eventName_, this.listener_, this.capture_); | 546 this.src_.removeEventListener(this.eventName_, this.listener_, this.capture_); |
| 547 }; | 547 }; |
| 548 | 548 |
| 549 | 549 |
| 550 /** | 550 /** |
| 551 * An event hook implementation for Chrome Events. | 551 * An event hook implementation for Chrome Events. |
| 552 * | 552 * |
| 553 * @param {chrome.Event} src | 553 * @param {chrome.Event} src |
| 554 * @param {function(...?)} listener | 554 * @param {Function} listener |
| 555 * | 555 * |
| 556 * @constructor | 556 * @constructor |
| 557 * @implements {base.Disposable} | 557 * @implements {base.Disposable} |
| 558 */ | 558 */ |
| 559 base.ChromeEventHook = function(src, listener) { | 559 base.ChromeEventHook = function(src, listener) { |
| 560 this.src_ = src; | 560 this.src_ = src; |
| 561 this.listener_ = listener; | 561 this.listener_ = listener; |
| 562 src.addListener(listener); | 562 src.addListener(listener); |
| 563 }; | 563 }; |
| 564 | 564 |
| 565 base.ChromeEventHook.prototype.dispose = function() { | 565 base.ChromeEventHook.prototype.dispose = function() { |
| 566 this.src_.removeListener(this.listener_); | 566 this.src_.removeListener(this.listener_); |
| 567 }; | 567 }; |
| 568 | 568 |
| 569 /** |
| 570 * A disposable repeating timer. |
| 571 * |
| 572 * @constructor |
| 573 * @implements {base.Disposable} |
| 574 */ |
| 575 base.RepeatingTimer = function(/** Function */callback, /** number */interval) { |
| 576 this.intervalId_ = window.setInterval(callback, interval); |
| 577 }; |
| 578 |
| 579 base.RepeatingTimer.prototype.dispose = function() { |
| 580 window.clearInterval(this.intervalId_); |
| 581 this.intervalId_ = null; |
| 582 }; |
| 569 | 583 |
| 570 /** | 584 /** |
| 571 * Converts UTF-8 string to ArrayBuffer. | 585 * Converts UTF-8 string to ArrayBuffer. |
| 572 * | 586 * |
| 573 * @param {string} string | 587 * @param {string} string |
| 574 * @return {ArrayBuffer} | 588 * @return {ArrayBuffer} |
| 575 */ | 589 */ |
| 576 base.encodeUtf8 = function(string) { | 590 base.encodeUtf8 = function(string) { |
| 577 var utf8String = unescape(encodeURIComponent(string)); | 591 var utf8String = unescape(encodeURIComponent(string)); |
| 578 var result = new Uint8Array(utf8String.length); | 592 var result = new Uint8Array(utf8String.length); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 */ | 635 */ |
| 622 base.resizeWindowToContent = function() { | 636 base.resizeWindowToContent = function() { |
| 623 var appWindow = chrome.app.window.current(); | 637 var appWindow = chrome.app.window.current(); |
| 624 var outerBounds = appWindow.outerBounds; | 638 var outerBounds = appWindow.outerBounds; |
| 625 var borderY = outerBounds.height - appWindow.innerBounds.height; | 639 var borderY = outerBounds.height - appWindow.innerBounds.height; |
| 626 appWindow.resizeTo(outerBounds.width, document.body.clientHeight + borderY); | 640 appWindow.resizeTo(outerBounds.width, document.body.clientHeight + borderY); |
| 627 // Sometimes, resizing the window causes its position to be reset to (0, 0), | 641 // Sometimes, resizing the window causes its position to be reset to (0, 0), |
| 628 // so restore it explicitly. | 642 // so restore it explicitly. |
| 629 appWindow.moveTo(outerBounds.left, outerBounds.top); | 643 appWindow.moveTo(outerBounds.left, outerBounds.top); |
| 630 }; | 644 }; |
| OLD | NEW |