Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / chrome / browser / resources / print_preview / common / overlay.js
blob4585dd64ae13a19e50a4addfae28fbac4cc04a78
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
3 // found in the LICENSE file.
5 cr.define('print_preview', function() {
6 'use strict';
8 /**
9 * Modal dialog base component.
10 * @param {!print_preview.MetricsContext} metricsContext Metrics
11 * context to record usage statistics.
12 * @constructor
13 * @extends {print_preview.Component}
15 function Overlay(metricsContext) {
16 print_preview.Component.call(this);
18 /** @private {!print_preview.MetricsContext} */
19 this.metricsContext_ = metricsContext;
22 Overlay.prototype = {
23 __proto__: print_preview.Component.prototype,
25 /** @return {!print_preview.MetricsContext} */
26 get metricsContext() {
27 return this.metricsContext_;
30 /** @override */
31 enterDocument: function() {
32 print_preview.Component.prototype.enterDocument.call(this);
34 this.getElement().addEventListener('webkitTransitionEnd', function f(e) {
35 if (e.target == e.currentTarget && e.propertyName == 'opacity' &&
36 e.target.classList.contains('transparent')) {
37 setIsVisible(e.target, false);
39 });
41 this.getElement().addEventListener('keydown', function f(e) {
42 // Escape pressed -> cancel the dialog.
43 if (!e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey) {
44 if (e.keyCode == 27) {
45 e.stopPropagation();
46 e.preventDefault();
47 this.cancel();
48 } else if (e.keyCode == 13) {
49 var activeElementTag = document.activeElement ?
50 document.activeElement.tagName.toUpperCase() : '';
51 if (activeElementTag != 'BUTTON' && activeElementTag != 'SELECT') {
52 if (this.onEnterPressedInternal()) {
53 e.stopPropagation();
54 e.preventDefault();
59 }.bind(this));
61 this.tracker.add(
62 this.getChildElement('.page > .close-button'),
63 'click',
64 this.cancel.bind(this));
66 this.tracker.add(
67 this.getElement(), 'click', this.onOverlayClick_.bind(this));
68 this.tracker.add(
69 this.getChildElement('.page'),
70 'webkitAnimationEnd',
71 this.onAnimationEnd_.bind(this));
74 /** @return {boolean} Whether the component is visible. */
75 getIsVisible: function() {
76 return !this.getElement().classList.contains('transparent');
79 /** @param {boolean} isVisible Whether the component is visible. */
80 setIsVisible: function(isVisible) {
81 if (this.getIsVisible() == isVisible)
82 return;
83 if (isVisible) {
84 setIsVisible(this.getElement(), true);
85 setTimeout(function(element) {
86 element.classList.remove('transparent');
87 }.bind(this, this.getElement()), 0);
88 } else {
89 this.getElement().classList.add('transparent');
91 this.onSetVisibleInternal(isVisible);
94 /** Closes the dialog. */
95 cancel: function() {
96 this.setIsVisible(false);
97 this.onCancelInternal();
101 * @param {boolean} isVisible Whether the component is visible.
102 * @protected
104 onSetVisibleInternal: function(isVisible) {},
106 /** @protected */
107 onCancelInternal: function() {},
110 * @return {boolean} Whether the event was handled.
111 * @protected
113 onEnterPressedInternal: function() {
114 return false;
118 * Called when the overlay is clicked. Pulses the page.
119 * @param {Event} e Contains the element that was clicked.
120 * @private
122 onOverlayClick_: function(e) {
123 if (e.target && e.target.classList.contains('overlay'))
124 e.target.querySelector('.page').classList.add('pulse');
128 * Called when an animation ends on the page.
129 * @param {Event} e Contains the target done animating.
130 * @private
132 onAnimationEnd_: function(e) {
133 if (e.target && e.animationName == 'pulse')
134 e.target.classList.remove('pulse');
138 // Export
139 return {
140 Overlay: Overlay