1 // Copyright 2013 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.
6 // <window-controls> shadow element implementation.
9 var chrome
= requireNative('chrome').GetChrome();
10 var forEach
= require('utils').forEach
;
11 var addTagWatcher
= require('tagWatcher').addTagWatcher
;
12 var appWindow
= require('app.window');
14 requireNative('app_window_natives').GetWindowControlsHtmlTemplate
;
19 function WindowControls(node
) {
21 this.shadowRoot_
= this.createShadowRoot_(node
);
22 this.setupWindowControls_();
28 WindowControls
.prototype.template_element
= null;
33 WindowControls
.prototype.createShadowRoot_ = function(node
) {
34 // Initialize |template| from HTML template resource and cache result.
35 var template
= WindowControls
.prototype.template_element
;
37 var element
= document
.createElement('div');
38 element
.innerHTML
= getHtmlTemplate();
39 WindowControls
.prototype.template_element
= element
.firstChild
;
40 template
= WindowControls
.prototype.template_element
;
42 // Create shadow root element with template clone as first child.
43 var shadowRoot
= node
.createShadowRoot();
44 shadowRoot
.appendChild(template
.content
.cloneNode(true));
51 WindowControls
.prototype.setupWindowControls_ = function() {
53 this.shadowRoot_
.querySelector("#close-control").addEventListener('click',
55 chrome
.app
.window
.current().close();
58 this.shadowRoot_
.querySelector("#maximize-control").addEventListener('click',
66 * Restore or maximize depending on current state
68 WindowControls
.prototype.maxRestore_ = function() {
69 if (chrome
.app
.window
.current().isMaximized()) {
70 chrome
.app
.window
.current().restore();
72 chrome
.app
.window
.current().maximize();
76 addTagWatcher('WINDOW-CONTROLS', function(addedNode
) {
77 new WindowControls(addedNode
);