blob: 75c88e63927e4d9e843134b5e9fb168b174ef10b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// <window-controls> shadow element implementation.
//
var chrome = requireNative('chrome').GetChrome();
var forEach = require('utils').forEach;
var addTagWatcher = require('tagWatcher').addTagWatcher;
var appWindow = require('app.window');
var getHtmlTemplate =
requireNative('app_window_natives').GetWindowControlsHtmlTemplate;
/**
* @constructor
*/
function WindowControls(node) {
this.node_ = node;
this.shadowRoot_ = this.createShadowRoot_(node);
this.setupWindowControls_();
}
/**
* @private
*/
WindowControls.prototype.template_element = null;
/**
* @private
*/
WindowControls.prototype.createShadowRoot_ = function(node) {
// Initialize |template| from HTML template resource and cache result.
var template = WindowControls.prototype.template_element;
if (!template) {
var element = document.createElement('div');
element.innerHTML = getHtmlTemplate();
WindowControls.prototype.template_element = element.firstChild;
template = WindowControls.prototype.template_element;
}
// Create shadow root element with template clone as first child.
var shadowRoot = node.createShadowRoot();
shadowRoot.appendChild(template.content.cloneNode(true));
return shadowRoot;
}
/**
* @private
*/
WindowControls.prototype.setupWindowControls_ = function() {
var self = this;
this.shadowRoot_.querySelector("#close-control").addEventListener('click',
function(e) {
chrome.app.window.current().close();
});
this.shadowRoot_.querySelector("#maximize-control").addEventListener('click',
function(e) {
self.maxRestore_();
});
}
/**
* @private
* Restore or maximize depending on current state
*/
WindowControls.prototype.maxRestore_ = function() {
if (chrome.app.window.current().isMaximized()) {
chrome.app.window.current().restore();
} else {
chrome.app.window.current().maximize();
}
}
addTagWatcher('WINDOW-CONTROLS', function(addedNode) {
new WindowControls(addedNode);
});
|