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. 4 5 cr.define('options', function() { 6 var OptionsPage = options.OptionsPage; 7 8 /** 9 * Encapsulated handling of the 'DisplayOverscan' page. 10 * @constructor 11 */ 12 function DisplayOverscan() { 13 OptionsPage.call(this, 'displayOverscan', 14 loadTimeData.getString('displayOverscanPageTabTitle'), 15 'display-overscan-page'); 16 } 17 18 cr.addSingletonGetter(DisplayOverscan); 19 20 DisplayOverscan.prototype = { 21 __proto__: OptionsPage.prototype, 22 23 /** 24 * The ID of the target display. 25 * @private 26 */ 27 id_: null, 28 29 /** 30 * The keyboard event handler function. 31 * @private 32 */ 33 keyHandler_: null, 34 35 /** 36 * Initialize the page. 37 */ 38 initializePage: function() { 39 OptionsPage.prototype.initializePage.call(this); 40 41 this.keyHandler_ = this.handleKeyevent_.bind(this); 42 $('display-overscan-operation-reset').onclick = function() { 43 chrome.send('reset'); 44 }; 45 $('display-overscan-operation-ok').onclick = function() { 46 chrome.send('commit'); 47 OptionsPage.closeOverlay(); 48 }; 49 $('display-overscan-operation-cancel').onclick = function() { 50 OptionsPage.cancelOverlay(); 51 }; 52 }, 53 54 /** @override */ 55 handleCancel: function() { 56 // signals the cancel event. 57 chrome.send('cancel'); 58 OptionsPage.closeOverlay(); 59 }, 60 61 /** @override */ 62 didShowPage: function() { 63 if (this.id_ == null) { 64 OptionsPage.cancelOverlay(); 65 return; 66 } 67 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'; 77 78 // Moves the table to describe operation at the middle of the contents 79 // vertically. 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'; 84 85 $('display-overscan-operation-cancel').focus(); 86 chrome.send('start', [this.id_]); 87 }, 88 89 /** @override */ 90 didClosePage: function() { 91 window.removeEventListener('keydown', this.keyHandler_); 92 }, 93 94 /** 95 * Called when the overscan calibration is canceled at the system level, 96 * such like the display is disconnected. 97 * @private 98 */ 99 onOverscanCanceled_: function() { 100 OptionsPage.cancelOverlay(); 101 }, 102 103 /** 104 * Sets the target display id. This method has to be called before 105 * navigating to this page. 106 * @param {string} id The target display id. 107 */ 108 setDisplayId: function(id) { 109 this.id_ = id; 110 }, 111 112 /** 113 * Key event handler to make the effect of display rectangle. 114 * @param {Event} event The keyboard event. 115 * @private 116 */ 117 handleKeyevent_: function(event) { 118 switch (event.keyCode) { 119 case 37: // left arrow 120 if (event.shiftKey) 121 chrome.send('move', ['horizontal', -1]); 122 else 123 chrome.send('resize', ['horizontal', -1]); 124 event.preventDefault(); 125 break; 126 case 38: // up arrow 127 if (event.shiftKey) 128 chrome.send('move', ['vertical', -1]); 129 else 130 chrome.send('resize', ['vertical', -1]); 131 event.preventDefault(); 132 break; 133 case 39: // right arrow 134 if (event.shiftKey) 135 chrome.send('move', ['horizontal', 1]); 136 else 137 chrome.send('resize', ['horizontal', 1]); 138 event.preventDefault(); 139 break; 140 case 40: // bottom arrow 141 if (event.shiftKey) 142 chrome.send('move', ['vertical', 1]); 143 else 144 chrome.send('resize', ['vertical', 1]); 145 event.preventDefault(); 146 break; 147 } 148 } 149 }; 150 151 DisplayOverscan.onOverscanCanceled = function() { 152 DisplayOverscan.getInstance().onOverscanCanceled_(); 153 }; 154 155 // Export 156 return { 157 DisplayOverscan: DisplayOverscan 158 }; 159 }); 160