Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(319)

Side by Side Diff: chrome/browser/resources/options/chromeos/display_options.js

Issue 2939273002: DO NOT SUBMIT: what chrome/browser/resources/ could eventually look like with clang-format (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 cr.exportPath('options'); 5 cr.exportPath('options');
6 6
7 /** 7 /**
8 * Enumeration of multi display mode. These values must match the C++ values in 8 * Enumeration of multi display mode. These values must match the C++ values in
9 * ash::DisplayManager. 9 * ash::DisplayManager.
10 * @enum {number} 10 * @enum {number}
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 62
63 // The scale ratio of the display rectangle to its original size. 63 // The scale ratio of the display rectangle to its original size.
64 /** @const */ var VISUAL_SCALE = 1 / 10; 64 /** @const */ var VISUAL_SCALE = 1 / 10;
65 65
66 /** 66 /**
67 * Encapsulated handling of the 'Display' page. 67 * Encapsulated handling of the 'Display' page.
68 * @constructor 68 * @constructor
69 * @extends {cr.ui.pageManager.Page} 69 * @extends {cr.ui.pageManager.Page}
70 */ 70 */
71 function DisplayOptions() { 71 function DisplayOptions() {
72 Page.call(this, 'display', 72 Page.call(
73 loadTimeData.getString('displayOptionsPageTabTitle'), 73 this, 'display', loadTimeData.getString('displayOptionsPageTabTitle'),
74 'display-options-page'); 74 'display-options-page');
75 } 75 }
76 76
77 cr.addSingletonGetter(DisplayOptions); 77 cr.addSingletonGetter(DisplayOptions);
78 78
79 DisplayOptions.prototype = { 79 DisplayOptions.prototype = {
80 __proto__: Page.prototype, 80 __proto__: Page.prototype,
81 81
82 /** 82 /**
83 * Whether the current output status is mirroring displays or not. 83 * Whether the current output status is mirroring displays or not.
84 * @type {boolean} 84 * @type {boolean}
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 * Whether the display settings can be shown. 166 * Whether the display settings can be shown.
167 * @type {boolean} 167 * @type {boolean}
168 * @private 168 * @private
169 */ 169 */
170 enabled_: true, 170 enabled_: true,
171 171
172 /** @override */ 172 /** @override */
173 initializePage: function() { 173 initializePage: function() {
174 Page.prototype.initializePage.call(this); 174 Page.prototype.initializePage.call(this);
175 175
176 $('display-options-select-mirroring').onchange = (function() { 176 $('display-options-select-mirroring').onchange =
177 this.mirroring_ = 177 (function() {
178 $('display-options-select-mirroring').value == 'mirroring'; 178 this.mirroring_ =
179 chrome.send('setMirroring', [this.mirroring_]); 179 $('display-options-select-mirroring').value == 'mirroring';
180 }).bind(this); 180 chrome.send('setMirroring', [this.mirroring_]);
181 }).bind(this);
181 182
182 var container = $('display-options-displays-view-host'); 183 var container = $('display-options-displays-view-host');
183 container.onmousemove = this.onMouseMove_.bind(this); 184 container.onmousemove = this.onMouseMove_.bind(this);
184 window.addEventListener('mouseup', this.endDragging_.bind(this), true); 185 window.addEventListener('mouseup', this.endDragging_.bind(this), true);
185 container.ontouchmove = this.onTouchMove_.bind(this); 186 container.ontouchmove = this.onTouchMove_.bind(this);
186 container.ontouchend = this.endDragging_.bind(this); 187 container.ontouchend = this.endDragging_.bind(this);
187 188
188 $('display-options-set-primary').onclick = (function() { 189 $('display-options-set-primary').onclick =
189 chrome.send('setPrimary', [this.focusedId_]); 190 (function() {
190 }).bind(this); 191 chrome.send('setPrimary', [this.focusedId_]);
191 $('display-options-resolution-selection').onchange = (function(ev) { 192 }).bind(this);
192 var display = this.getDisplayInfoFromId_(this.focusedId_); 193 $('display-options-resolution-selection').onchange =
193 if (!display) 194 (function(ev) {
194 return; 195 var display = this.getDisplayInfoFromId_(this.focusedId_);
195 var resolution = display.resolutions[ev.target.value]; 196 if (!display)
196 chrome.send('setDisplayMode', [this.focusedId_, resolution]); 197 return;
197 }).bind(this); 198 var resolution = display.resolutions[ev.target.value];
198 $('display-options-orientation-selection').onchange = (function(ev) { 199 chrome.send('setDisplayMode', [this.focusedId_, resolution]);
199 var rotation = parseInt(ev.target.value, 10); 200 }).bind(this);
200 chrome.send('setRotation', [this.focusedId_, rotation]); 201 $('display-options-orientation-selection').onchange =
201 }).bind(this); 202 (function(ev) {
202 $('display-options-color-profile-selection').onchange = (function(ev) { 203 var rotation = parseInt(ev.target.value, 10);
203 chrome.send('setColorProfile', [this.focusedId_, ev.target.value]); 204 chrome.send('setRotation', [this.focusedId_, rotation]);
204 }).bind(this); 205 }).bind(this);
205 $('selected-display-start-calibrating-overscan').onclick = (function() { 206 $('display-options-color-profile-selection').onchange =
206 // Passes the target display ID. Do not specify it through URL hash, 207 (function(ev) {
207 // we do not care back/forward. 208 chrome.send('setColorProfile', [this.focusedId_, ev.target.value]);
208 var displayOverscan = options.DisplayOverscan.getInstance(); 209 }).bind(this);
209 displayOverscan.setDisplayId(this.focusedId_); 210 $('selected-display-start-calibrating-overscan').onclick =
210 PageManager.showPageByName('displayOverscan'); 211 (function() {
211 chrome.send('coreOptionsUserMetricsAction', 212 // Passes the target display ID. Do not specify it through URL hash,
212 ['Options_DisplaySetOverscan']); 213 // we do not care back/forward.
213 }).bind(this); 214 var displayOverscan = options.DisplayOverscan.getInstance();
215 displayOverscan.setDisplayId(this.focusedId_);
216 PageManager.showPageByName('displayOverscan');
217 chrome.send(
218 'coreOptionsUserMetricsAction', ['Options_DisplaySetOverscan']);
219 }).bind(this);
214 220
215 $('display-options-done').onclick = function() { 221 $('display-options-done').onclick = function() {
216 PageManager.closeOverlay(); 222 PageManager.closeOverlay();
217 }; 223 };
218 224
219 $('display-options-toggle-unified-desktop').onclick = (function() { 225 $('display-options-toggle-unified-desktop').onclick =
220 this.unifiedDesktopEnabled_ = !this.unifiedDesktopEnabled_; 226 (function() {
221 chrome.send('setUnifiedDesktopEnabled', 227 this.unifiedDesktopEnabled_ = !this.unifiedDesktopEnabled_;
222 [this.unifiedDesktopEnabled_]); 228 chrome.send(
223 }).bind(this); 229 'setUnifiedDesktopEnabled', [this.unifiedDesktopEnabled_]);
230 }).bind(this);
224 }, 231 },
225 232
226 /** @override */ 233 /** @override */
227 didShowPage: function() { 234 didShowPage: function() {
228 var optionTitles = document.getElementsByClassName( 235 var optionTitles =
229 'selected-display-option-title'); 236 document.getElementsByClassName('selected-display-option-title');
230 var maxSize = 0; 237 var maxSize = 0;
231 for (var i = 0; i < optionTitles.length; i++) 238 for (var i = 0; i < optionTitles.length; i++)
232 maxSize = Math.max(maxSize, optionTitles[i].clientWidth); 239 maxSize = Math.max(maxSize, optionTitles[i].clientWidth);
233 for (var i = 0; i < optionTitles.length; i++) 240 for (var i = 0; i < optionTitles.length; i++)
234 optionTitles[i].style.width = maxSize + 'px'; 241 optionTitles[i].style.width = maxSize + 'px';
235 chrome.send('getDisplayInfo'); 242 chrome.send('getDisplayInfo');
236 }, 243 },
237 244
238 /** @override */ 245 /** @override */
239 canShowPage: function() { return this.enabled_; }, 246 canShowPage: function() {
247 return this.enabled_;
248 },
240 249
241 /** 250 /**
242 * Enables or disables the page. When disabled, the page will not be able to 251 * Enables or disables the page. When disabled, the page will not be able to
243 * open, and will close if currently opened. Also sets the enabled states of 252 * open, and will close if currently opened. Also sets the enabled states of
244 * mirrored and unifed desktop. 253 * mirrored and unifed desktop.
245 * @param {boolean} uiEnabled 254 * @param {boolean} uiEnabled
246 * @param {boolean} unifiedEnabled 255 * @param {boolean} unifiedEnabled
247 * @param {boolean} mirroredEnabled 256 * @param {boolean} mirroredEnabled
248 */ 257 */
249 setEnabled: function(uiEnabled, unifiedEnabled, mirroredEnabled) { 258 setEnabled: function(uiEnabled, unifiedEnabled, mirroredEnabled) {
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 return false; 399 return false;
391 400
392 var updateDisplayDescription = focused.id != this.focusedId_; 401 var updateDisplayDescription = focused.id != this.focusedId_;
393 this.focusedId_ = focused.id; 402 this.focusedId_ = focused.id;
394 this.displayLayoutManager_.setFocusedId( 403 this.displayLayoutManager_.setFocusedId(
395 focused.id, true /* user action */); 404 focused.id, true /* user action */);
396 405
397 if (this.displayLayoutManager_.getDisplayLayoutCount() > 1) { 406 if (this.displayLayoutManager_.getDisplayLayoutCount() > 1) {
398 this.dragInfo_ = { 407 this.dragInfo_ = {
399 displayId: focused.id, 408 displayId: focused.id,
400 originalLocation: { 409 originalLocation:
401 x: focused.div.offsetLeft, 410 {x: focused.div.offsetLeft, y: focused.div.offsetTop},
402 y: focused.div.offsetTop
403 },
404 eventLocation: {x: eventLocation.x, y: eventLocation.y} 411 eventLocation: {x: eventLocation.x, y: eventLocation.y}
405 }; 412 };
406 } 413 }
407 414
408 if (updateDisplayDescription) 415 if (updateDisplayDescription)
409 this.updateSelectedDisplayDescription_(); 416 this.updateSelectedDisplayDescription_();
410 417
411 return false; 418 return false;
412 }, 419 },
413 420
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 * @param {options.DisplayInfo} display The selected display object. 484 * @param {options.DisplayInfo} display The selected display object.
478 * @private 485 * @private
479 */ 486 */
480 updateSelectedDisplaySectionForDisplay_: function(display) { 487 updateSelectedDisplaySectionForDisplay_: function(display) {
481 var displayLayout = 488 var displayLayout =
482 this.displayLayoutManager_.getDisplayLayout(display.id); 489 this.displayLayoutManager_.getDisplayLayout(display.id);
483 var arrow = $('display-configuration-arrow'); 490 var arrow = $('display-configuration-arrow');
484 arrow.hidden = false; 491 arrow.hidden = false;
485 // Adding 1 px to the position to fit the border line and the border in 492 // Adding 1 px to the position to fit the border line and the border in
486 // arrow precisely. 493 // arrow precisely.
487 arrow.style.top = $('display-configurations').offsetTop - 494 arrow.style.top =
488 arrow.offsetHeight / 2 + 'px'; 495 $('display-configurations').offsetTop - arrow.offsetHeight / 2 + 'px';
489 arrow.style.left = displayLayout.div.offsetLeft + 496 arrow.style.left = displayLayout.div.offsetLeft +
490 displayLayout.div.offsetWidth / 2 - arrow.offsetWidth / 2 + 'px'; 497 displayLayout.div.offsetWidth / 2 - arrow.offsetWidth / 2 + 'px';
491 498
492 $('display-options-set-primary').disabled = display.isPrimary; 499 $('display-options-set-primary').disabled = display.isPrimary;
493 $('display-options-select-mirroring').disabled = !this.mirroredEnabled_; 500 $('display-options-select-mirroring').disabled = !this.mirroredEnabled_;
494 $('selected-display-start-calibrating-overscan').disabled = 501 $('selected-display-start-calibrating-overscan').disabled =
495 display.isInternal; 502 display.isInternal;
496 503
497 var orientation = $('display-options-orientation-selection'); 504 var orientation = $('display-options-orientation-selection');
498 orientation.disabled = this.unifiedDesktopEnabled_; 505 orientation.disabled = this.unifiedDesktopEnabled_;
(...skipping 13 matching lines...) Expand all
512 resolution.appendChild(option); 519 resolution.appendChild(option);
513 resolution.disabled = true; 520 resolution.disabled = true;
514 } else { 521 } else {
515 var previousOption; 522 var previousOption;
516 for (var i = 0; i < display.resolutions.length; i++) { 523 for (var i = 0; i < display.resolutions.length; i++) {
517 var option = document.createElement('option'); 524 var option = document.createElement('option');
518 option.value = i; 525 option.value = i;
519 option.textContent = display.resolutions[i].width + 'x' + 526 option.textContent = display.resolutions[i].width + 'x' +
520 display.resolutions[i].height; 527 display.resolutions[i].height;
521 if (display.resolutions[i].isBest) { 528 if (display.resolutions[i].isBest) {
522 option.textContent += ' ' + 529 option.textContent += ' ' + loadTimeData.getString('annotateBest');
523 loadTimeData.getString('annotateBest');
524 } else if (display.resolutions[i].isNative) { 530 } else if (display.resolutions[i].isNative) {
525 option.textContent += ' ' + 531 option.textContent +=
526 loadTimeData.getString('annotateNative'); 532 ' ' + loadTimeData.getString('annotateNative');
527 } 533 }
528 if (display.resolutions[i].deviceScaleFactor && previousOption && 534 if (display.resolutions[i].deviceScaleFactor && previousOption &&
529 previousOption.textContent == option.textContent) { 535 previousOption.textContent == option.textContent) {
530 option.textContent += 536 option.textContent +=
531 ' (' + display.resolutions[i].deviceScaleFactor + 'x)'; 537 ' (' + display.resolutions[i].deviceScaleFactor + 'x)';
532 } 538 }
533 option.selected = display.resolutions[i].selected; 539 option.selected = display.resolutions[i].selected;
534 resolution.appendChild(option); 540 resolution.appendChild(option);
535 previousOption = option; 541 previousOption = option;
536 } 542 }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 for (var i = 0; i < this.displays_.length; i++) { 656 for (var i = 0; i < this.displays_.length; i++) {
651 var display = this.displays_[i]; 657 var display = this.displays_[i];
652 var layout = new options.DisplayLayout( 658 var layout = new options.DisplayLayout(
653 display.id, display.name, display.bounds, display.layoutType, 659 display.id, display.name, display.bounds, display.layoutType,
654 display.offset, display.parentId); 660 display.offset, display.parentId);
655 this.displayLayoutManager_.addDisplayLayout(layout); 661 this.displayLayoutManager_.addDisplayLayout(layout);
656 } 662 }
657 663
658 // Calculate the display area bounds and create the divs for each display. 664 // Calculate the display area bounds and create the divs for each display.
659 this.visualScale_ = this.displayLayoutManager_.createDisplayArea( 665 this.visualScale_ = this.displayLayoutManager_.createDisplayArea(
660 /** @type {!Element} */(this.displaysView_), VISUAL_SCALE); 666 /** @type {!Element} */ (this.displaysView_), VISUAL_SCALE);
661 667
662 this.displayLayoutManager_.setFocusedId(this.focusedId_); 668 this.displayLayoutManager_.setFocusedId(this.focusedId_);
663 this.displayLayoutManager_.setDivCallbacks( 669 this.displayLayoutManager_.setDivCallbacks(
664 this.onMouseDown_.bind(this), this.onTouchStart_.bind(this)); 670 this.onMouseDown_.bind(this), this.onTouchStart_.bind(this));
665 }, 671 },
666 672
667 /** 673 /**
668 * Called when the display arrangement has changed. 674 * Called when the display arrangement has changed.
669 * @param {options.MultiDisplayMode} mode multi display mode. 675 * @param {options.MultiDisplayMode} mode multi display mode.
670 * @param {!Array<!options.DisplayInfo>} displays The list of the display 676 * @param {!Array<!options.DisplayInfo>} displays The list of the display
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 722
717 this.updateSelectedDisplayDescription_(); 723 this.updateSelectedDisplayDescription_();
718 } 724 }
719 }; 725 };
720 726
721 DisplayOptions.setDisplayInfo = function(mode, displays) { 727 DisplayOptions.setDisplayInfo = function(mode, displays) {
722 DisplayOptions.getInstance().onDisplayChanged_(mode, displays); 728 DisplayOptions.getInstance().onDisplayChanged_(mode, displays);
723 }; 729 };
724 730
725 // Export 731 // Export
726 return { 732 return {DisplayOptions: DisplayOptions};
727 DisplayOptions: DisplayOptions
728 };
729 }); 733 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698