1 // Copyright (c) 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.
5 cr.define('options', function() {
6 var Page = cr.ui.pageManager.Page;
7 var PageManager = cr.ui.pageManager.PageManager;
10 * Encapsulated handling of the 'DisplayOverscan' page.
12 * @extends {cr.ui.pageManager.Page}
14 function DisplayOverscan() {
15 Page.call(this, 'displayOverscan',
16 loadTimeData.getString('displayOverscanPageTabTitle'),
17 'display-overscan-page');
20 cr.addSingletonGetter(DisplayOverscan);
22 DisplayOverscan.prototype = {
23 __proto__: Page.prototype,
26 * The ID of the target display.
32 * The keyboard event handler function.
38 initializePage: function() {
39 Page.prototype.initializePage.call(this);
41 this.keyHandler_ = this.handleKeyevent_.bind(this);
42 $('display-overscan-operation-reset').onclick = function() {
45 $('display-overscan-operation-ok').onclick = function() {
46 chrome.send('commit');
47 PageManager.closeOverlay();
49 $('display-overscan-operation-cancel').onclick = function() {
50 PageManager.cancelOverlay();
55 handleCancel: function() {
56 // signals the cancel event.
57 chrome.send('cancel');
58 PageManager.closeOverlay();
62 didShowPage: function() {
63 if (this.id_ == null) {
64 PageManager.cancelOverlay();
68 window.addEventListener('keydown', this.keyHandler_);
69 // Sets up the size of the overscan dialog based on DisplayOptions dialog.
70 var displayOptionsPage = $('display-options-page');
71 var displayOverscanPage = $('display-overscan-page');
72 displayOverscanPage.style.width =
73 displayOptionsPage.offsetWidth - 20 + 'px';
74 displayOverscanPage.style.minWidth = displayOverscanPage.style.width;
75 displayOverscanPage.style.height =
76 displayOptionsPage.offsetHeight - 50 + 'px';
78 // Moves the table to describe operation at the middle of the contents
80 var operationsTable = $('display-overscan-operations-table');
81 var buttonsContainer = $('display-overscan-button-strip');
82 operationsTable.style.top = buttonsContainer.offsetTop / 2 -
83 operationsTable.offsetHeight / 2 + 'px';
85 $('display-overscan-operation-cancel').focus();
86 chrome.send('start', [this.id_]);
90 didClosePage: function() {
91 window.removeEventListener('keydown', this.keyHandler_);
95 * Called when the overscan calibration is canceled at the system level,
96 * such like the display is disconnected.
99 onOverscanCanceled_: function() {
100 if (PageManager.getTopmostVisiblePage() == this)
101 PageManager.cancelOverlay();
105 * Sets the target display id. This method has to be called before
106 * navigating to this page.
107 * @param {string} id The target display id.
109 setDisplayId: function(id) {
114 * Key event handler to make the effect of display rectangle.
115 * @param {Event} event The keyboard event.
118 handleKeyevent_: function(event) {
119 switch (event.keyCode) {
120 case 37: // left arrow
122 chrome.send('move', ['horizontal', -1]);
124 chrome.send('resize', ['horizontal', -1]);
125 event.preventDefault();
129 chrome.send('move', ['vertical', -1]);
131 chrome.send('resize', ['vertical', -1]);
132 event.preventDefault();
134 case 39: // right arrow
136 chrome.send('move', ['horizontal', 1]);
138 chrome.send('resize', ['horizontal', 1]);
139 event.preventDefault();
141 case 40: // bottom arrow
143 chrome.send('move', ['vertical', 1]);
145 chrome.send('resize', ['vertical', 1]);
146 event.preventDefault();
152 DisplayOverscan.onOverscanCanceled = function() {
153 DisplayOverscan.getInstance().onOverscanCanceled_();
158 DisplayOverscan: DisplayOverscan