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

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

Issue 1612873002: Fix types in display_options.js (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@issue_576375_display2
Patch Set: Created 4 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 display layout. These values must match the C++ values in
9 * ash::DisplayController.
10 * @enum {number}
11 */
12 options.DisplayLayoutType = {
13 TOP: 0,
14 RIGHT: 1,
15 BOTTOM: 2,
16 LEFT: 3
17 };
18
19 /**
20 * Enumeration of multi display mode. These values must match the C++ values in
21 * ash::DisplayManager.
22 * @enum {number}
23 */
24 options.MultiDisplayMode = {
25 EXTENDED: 0,
26 MIRRORING: 1,
27 UNIFIED: 2,
28 };
29
30 /**
8 * @typedef {{ 31 * @typedef {{
9 * left: number, 32 * left: number,
10 * top: number, 33 * top: number,
11 * width: number, 34 * width: number,
12 * height: number 35 * height: number
13 * }} 36 * }}
14 */ 37 */
15 options.DisplayBounds; 38 options.DisplayBounds;
16 39
17 /** 40 /**
18 * @typedef {{ 41 * @typedef {{
42 * x: number,
43 * y: number
44 * }}
45 */
46 options.DisplayPosition;
47
48 /**
49 * @typedef {{
19 * width: number, 50 * width: number,
20 * height: number, 51 * height: number,
21 * originalWidth: number, 52 * originalWidth: number,
22 * originalHeight: number, 53 * originalHeight: number,
23 * deviceScaleFactor: number, 54 * deviceScaleFactor: number,
24 * scale: number, 55 * scale: number,
25 * refreshRate: number, 56 * refreshRate: number,
26 * isBest: boolean, 57 * isBest: boolean,
27 * selected: boolean 58 * selected: boolean
28 * }} 59 * }}
29 */ 60 */
30 options.DisplayMode; 61 options.DisplayMode;
31 62
32 /** 63 /**
33 * @typedef {{ 64 * @typedef {{
34 * profileId: number, 65 * profileId: number,
35 * name: string 66 * name: string
36 * }} 67 * }}
37 */ 68 */
38 options.ColorProfile; 69 options.ColorProfile;
39 70
40 /** 71 /**
41 * @typedef {{ 72 * @typedef {{
42 * availableColorProfiles: !Array<!options.ColorProfile>, 73 * availableColorProfiles: !Array<!options.ColorProfile>,
43 * bounds: options.DisplayBounds, 74 * bounds: !options.DisplayBounds,
44 * colorProfileId: number, 75 * colorProfileId: number,
45 * div: ?Element, 76 * div: ?Element,
46 * id: string, 77 * id: string,
47 * isInternal: boolean, 78 * isInternal: boolean,
48 * isPrimary: boolean, 79 * isPrimary: boolean,
49 * resolutions: !Array<!options.DisplayMode>, 80 * resolutions: !Array<!options.DisplayMode>,
50 * name: string, 81 * name: string,
51 * rotation: number, 82 * rotation: number,
52 * originalPosition: ?{x: number, y: number} 83 * originalPosition: ?options.DisplayPosition
53 * }} 84 * }}
54 */ 85 */
55 options.DisplayInfo; 86 options.DisplayInfo;
56 87
57 /**
58 * Enumeration of secondary display layout. The value has to be same as the
59 * values in ash/display/display_controller.cc.
60 * @enum {number}
61 */
62 options.SecondaryDisplayLayout = {
63 TOP: 0,
64 RIGHT: 1,
65 BOTTOM: 2,
66 LEFT: 3
67 };
68
69 /**
70 * Enumeration of multi display mode. The value has to be same as the
71 * values in ash/display/display_manager..
72 * @enum {number}
73 */
74 options.MultiDisplayMode = {
75 EXTENDED: 0,
76 MIRRORING: 1,
77 UNIFIED: 2,
78 };
79
80 cr.define('options', function() { 88 cr.define('options', function() {
81 var Page = cr.ui.pageManager.Page; 89 var Page = cr.ui.pageManager.Page;
82 var PageManager = cr.ui.pageManager.PageManager; 90 var PageManager = cr.ui.pageManager.PageManager;
83 91
84 // The scale ratio of the display rectangle to its original size. 92 // The scale ratio of the display rectangle to its original size.
85 /** @const */ var VISUAL_SCALE = 1 / 10; 93 /** @const */ var VISUAL_SCALE = 1 / 10;
86 94
87 // The number of pixels to share the edges between displays. 95 // The number of pixels to share the edges between displays.
88 /** @const */ var MIN_OFFSET_OVERLAP = 5; 96 /** @const */ var MIN_OFFSET_OVERLAP = 5;
89 97
90 /** 98 /**
91 * Calculates the bounds of |element| relative to the page.
92 * @param {HTMLElement} element The element to be known.
93 * @return {Object} The object for the bounds, with x, y, width, and height.
94 */
95 function getBoundsInPage(element) {
96 var bounds = {
97 x: element.offsetLeft,
98 y: element.offsetTop,
99 width: element.offsetWidth,
100 height: element.offsetHeight
101 };
102 var parent = element.offsetParent;
103 while (parent && parent != document.body) {
104 bounds.x += parent.offsetLeft;
105 bounds.y += parent.offsetTop;
106 parent = parent.offsetParent;
107 }
108 return bounds;
109 }
stevenjb 2016/01/21 03:56:17 Unused
110
111 /**
112 * Gets the position of |point| to |rect|, left, right, top, or bottom. 99 * Gets the position of |point| to |rect|, left, right, top, or bottom.
113 * @param {Object} rect The base rectangle with x, y, width, and height. 100 * @param {!options.DisplayBounds} rect The base rectangle.
114 * @param {Object} point The point to check the position. 101 * @param {!options.DisplayPosition} point The point to check the position.
115 * @return {options.SecondaryDisplayLayout} The position of the calculated 102 * @return {options.DisplayLayoutType} The position of the calculated point.
116 * point.
117 */ 103 */
118 function getPositionToRectangle(rect, point) { 104 function getPositionToRectangle(rect, point) {
119 // Separates the area into four (LEFT/RIGHT/TOP/BOTTOM) by the diagonals of 105 // Separates the area into four (LEFT/RIGHT/TOP/BOTTOM) by the diagonals of
120 // the rect, and decides which area the display should reside. 106 // the rect, and decides which area the display should reside.
121 var diagonalSlope = rect.height / rect.width; 107 var diagonalSlope = rect.height / rect.width;
122 var topDownIntercept = rect.y - rect.x * diagonalSlope; 108 var topDownIntercept = rect.top - rect.left * diagonalSlope;
123 var bottomUpIntercept = rect.y + rect.height + rect.x * diagonalSlope; 109 var bottomUpIntercept = rect.top + rect.height + rect.left * diagonalSlope;
124 110
125 if (point.y > topDownIntercept + point.x * diagonalSlope) { 111 if (point.y > topDownIntercept + point.x * diagonalSlope) {
126 if (point.y > bottomUpIntercept - point.x * diagonalSlope) 112 if (point.y > bottomUpIntercept - point.x * diagonalSlope)
127 return options.SecondaryDisplayLayout.BOTTOM; 113 return options.DisplayLayoutType.BOTTOM;
128 else 114 else
129 return options.SecondaryDisplayLayout.LEFT; 115 return options.DisplayLayoutType.LEFT;
130 } else { 116 } else {
131 if (point.y > bottomUpIntercept - point.x * diagonalSlope) 117 if (point.y > bottomUpIntercept - point.x * diagonalSlope)
132 return options.SecondaryDisplayLayout.RIGHT; 118 return options.DisplayLayoutType.RIGHT;
133 else 119 else
134 return options.SecondaryDisplayLayout.TOP; 120 return options.DisplayLayoutType.TOP;
135 } 121 }
136 } 122 }
137 123
138 /** 124 /**
139 * Encapsulated handling of the 'Display' page. 125 * Encapsulated handling of the 'Display' page.
140 * @constructor 126 * @constructor
141 * @extends {cr.ui.pageManager.Page} 127 * @extends {cr.ui.pageManager.Page}
142 */ 128 */
143 function DisplayOptions() { 129 function DisplayOptions() {
144 Page.call(this, 'display', 130 Page.call(this, 'display',
145 loadTimeData.getString('displayOptionsPageTabTitle'), 131 loadTimeData.getString('displayOptionsPageTabTitle'),
146 'display-options-page'); 132 'display-options-page');
147 } 133 }
148 134
149 cr.addSingletonGetter(DisplayOptions); 135 cr.addSingletonGetter(DisplayOptions);
150 136
151 DisplayOptions.prototype = { 137 DisplayOptions.prototype = {
152 __proto__: Page.prototype, 138 __proto__: Page.prototype,
153 139
154 /** 140 /**
155 * Whether the current output status is mirroring displays or not. 141 * Whether the current output status is mirroring displays or not.
142 * @type {boolean}
156 * @private 143 * @private
157 */ 144 */
158 mirroring_: false, 145 mirroring_: false,
159 146
160 /** 147 /**
161 * Whether the unified desktop is enable or not. 148 * Whether the unified desktop is enable or not.
149 * @type {boolean}
162 * @private 150 * @private
163 */ 151 */
164 unifiedDesktopEnabled_: false, 152 unifiedDesktopEnabled_: false,
165 153
166 /** 154 /**
167 * Whether the unified desktop option should be present. 155 * Whether the unified desktop option should be present.
156 * @type {boolean}
168 * @private 157 * @private
169 */ 158 */
170 showUnifiedDesktopOption_: false, 159 showUnifiedDesktopOption_: false,
171 160
172 /** 161 /**
173 * The current secondary display layout. 162 * The current secondary display layout.
163 * @type {options.DisplayLayoutType}
174 * @private 164 * @private
175 */ 165 */
176 layout_: options.SecondaryDisplayLayout.RIGHT, 166 layout_: options.DisplayLayoutType.RIGHT,
177 167
178 /** 168 /**
179 * The array of current output displays. It also contains the display 169 * The array of current output displays. It also contains the display
180 * rectangles currently rendered on screen. 170 * rectangles currently rendered on screen.
181 * @type {!Array<!options.DisplayInfo>} 171 * @type {!Array<!options.DisplayInfo>}
182 * @private 172 * @private
183 */ 173 */
184 displays_: [], 174 displays_: [],
185 175
186 /** 176 /**
187 * The index for the currently focused display in the options UI. null if 177 * The index of the currently focused display, or -1 for none.
188 * no one has focus. 178 * @type {number}
189 * @private 179 * @private
190 */ 180 */
191 focusedIndex_: null, 181 focusedIndex_: -1,
192 182
193 /** 183 /**
194 * The primary display edit info. 184 * The primary display edit info.
195 * @type {?options.DisplayInfo} 185 * @type {?options.DisplayInfo}
196 * @private 186 * @private
197 */ 187 */
198 primaryDisplay_: null, 188 primaryDisplay_: null,
199 189
200 /** 190 /**
201 * The secondary display edit info. 191 * The secondary display edit info.
202 * @type {?options.DisplayInfo} 192 * @type {?options.DisplayInfo}
203 * @private 193 * @private
204 */ 194 */
205 secondaryDisplay_: null, 195 secondaryDisplay_: null,
206 196
207 /** 197 /**
198 * Drag info.
199 * @type {?{display: !options.DisplayInfo,
200 * originalLocation: !options.DisplayPosition,
201 * eventLocation: !options.DisplayPosition}}
202 * @private
203 */
204 dragging_: null,
205
206 /**
208 * The container div element which contains all of the display rectangles. 207 * The container div element which contains all of the display rectangles.
208 * @type {?Element}
209 * @private 209 * @private
210 */ 210 */
211 displaysView_: null, 211 displaysView_: null,
212 212
213 /** 213 /**
214 * The scale factor of the actual display size to the drawn display 214 * The scale factor of the actual display size to the drawn display
215 * rectangle size. 215 * rectangle size.
216 * @type {number}
216 * @private 217 * @private
217 */ 218 */
218 visualScale_: VISUAL_SCALE, 219 visualScale_: VISUAL_SCALE,
219 220
220 /** 221 /**
221 * The location where the last touch event happened. This is used to 222 * The location where the last touch event happened. This is used to
222 * prevent unnecessary dragging events happen. Set to null unless it's 223 * prevent unnecessary dragging events happen. Set to null unless it's
223 * during touch events. 224 * during touch events.
225 * @type {?options.DisplayPosition}
224 * @private 226 * @private
225 */ 227 */
226 lastTouchLocation_: null, 228 lastTouchLocation_: null,
227 229
228 /** 230 /**
229 * Whether the display settings can be shown. 231 * Whether the display settings can be shown.
232 * @type {boolean}
230 * @private 233 * @private
231 */ 234 */
232 enabled_: true, 235 enabled_: true,
233 236
234 /** @override */ 237 /** @override */
235 initializePage: function() { 238 initializePage: function() {
236 Page.prototype.initializePage.call(this); 239 Page.prototype.initializePage.call(this);
237 240
238 $('display-options-select-mirroring').onchange = (function() { 241 $('display-options-select-mirroring').onchange = (function() {
239 this.mirroring_ = 242 this.mirroring_ =
(...skipping 10 matching lines...) Expand all
250 $('display-options-set-primary').onclick = (function() { 253 $('display-options-set-primary').onclick = (function() {
251 chrome.send('setPrimary', [this.displays_[this.focusedIndex_].id]); 254 chrome.send('setPrimary', [this.displays_[this.focusedIndex_].id]);
252 }).bind(this); 255 }).bind(this);
253 $('display-options-resolution-selection').onchange = (function(ev) { 256 $('display-options-resolution-selection').onchange = (function(ev) {
254 var display = this.displays_[this.focusedIndex_]; 257 var display = this.displays_[this.focusedIndex_];
255 var resolution = display.resolutions[ev.target.value]; 258 var resolution = display.resolutions[ev.target.value];
256 chrome.send('setDisplayMode', [display.id, resolution]); 259 chrome.send('setDisplayMode', [display.id, resolution]);
257 }).bind(this); 260 }).bind(this);
258 $('display-options-orientation-selection').onchange = (function(ev) { 261 $('display-options-orientation-selection').onchange = (function(ev) {
259 var displayIndex = 262 var displayIndex =
260 (this.focusedIndex_ === null) ? 0 : this.focusedIndex_; 263 (this.focusedIndex_ == -1) ? 0 : this.focusedIndex_;
261 var rotation = parseInt(ev.target.value, 10); 264 var rotation = parseInt(ev.target.value, 10);
262 chrome.send('setRotation', [this.displays_[displayIndex].id, rotation]); 265 chrome.send('setRotation', [this.displays_[displayIndex].id, rotation]);
263 }).bind(this); 266 }).bind(this);
264 $('display-options-color-profile-selection').onchange = (function(ev) { 267 $('display-options-color-profile-selection').onchange = (function(ev) {
265 chrome.send('setColorProfile', [this.displays_[this.focusedIndex_].id, 268 chrome.send('setColorProfile', [this.displays_[this.focusedIndex_].id,
266 ev.target.value]); 269 ev.target.value]);
267 }).bind(this); 270 }).bind(this);
268 $('selected-display-start-calibrating-overscan').onclick = (function() { 271 $('selected-display-start-calibrating-overscan').onclick = (function() {
269 // Passes the target display ID. Do not specify it through URL hash, 272 // Passes the target display ID. Do not specify it through URL hash,
270 // we do not care back/forward. 273 // we do not care back/forward.
(...skipping 21 matching lines...) Expand all
292 'selected-display-option-title'); 295 'selected-display-option-title');
293 var maxSize = 0; 296 var maxSize = 0;
294 for (var i = 0; i < optionTitles.length; i++) 297 for (var i = 0; i < optionTitles.length; i++)
295 maxSize = Math.max(maxSize, optionTitles[i].clientWidth); 298 maxSize = Math.max(maxSize, optionTitles[i].clientWidth);
296 for (var i = 0; i < optionTitles.length; i++) 299 for (var i = 0; i < optionTitles.length; i++)
297 optionTitles[i].style.width = maxSize + 'px'; 300 optionTitles[i].style.width = maxSize + 'px';
298 chrome.send('getDisplayInfo'); 301 chrome.send('getDisplayInfo');
299 }, 302 },
300 303
301 /** @override */ 304 /** @override */
302 canShowPage: function() { 305 canShowPage: function() { return this.enabled_; },
303 return this.enabled_;
304 },
305 306
306 /** 307 /**
307 * Enables or disables the page. When disabled, the page will not be able to 308 * Enables or disables the page. When disabled, the page will not be able to
308 * open, and will close if currently opened. 309 * open, and will close if currently opened.
309 * @param {boolean} enabled Whether the page should be enabled. 310 * @param {boolean} enabled Whether the page should be enabled.
310 * @param {boolean} showUnifiedDesktop Whether the unified desktop option 311 * @param {boolean} showUnifiedDesktop Whether the unified desktop option
311 * should be present. 312 * should be present.
312 */ 313 */
313 setEnabled: function(enabled, showUnifiedDesktop) { 314 setEnabled: function(enabled, showUnifiedDesktop) {
314 if (this.enabled_ == enabled && 315 if (this.enabled_ == enabled &&
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 395
395 /** 396 /**
396 * Collects the current data and sends it to Chrome. 397 * Collects the current data and sends it to Chrome.
397 * @private 398 * @private
398 */ 399 */
399 applyResult_: function() { 400 applyResult_: function() {
400 // Offset is calculated from top or left edge. 401 // Offset is calculated from top or left edge.
401 var primary = this.primaryDisplay_; 402 var primary = this.primaryDisplay_;
402 var secondary = this.secondaryDisplay_; 403 var secondary = this.secondaryDisplay_;
403 var offset; 404 var offset;
404 if (this.layout_ == options.SecondaryDisplayLayout.LEFT || 405 if (this.layout_ == options.DisplayLayoutType.LEFT ||
405 this.layout_ == options.SecondaryDisplayLayout.RIGHT) { 406 this.layout_ == options.DisplayLayoutType.RIGHT) {
406 offset = secondary.div.offsetTop - primary.div.offsetTop; 407 offset = secondary.div.offsetTop - primary.div.offsetTop;
407 } else { 408 } else {
408 offset = secondary.div.offsetLeft - primary.div.offsetLeft; 409 offset = secondary.div.offsetLeft - primary.div.offsetLeft;
409 } 410 }
410 offset = Math.floor(offset / this.visualScale_); 411 offset = Math.floor(offset / this.visualScale_);
411 chrome.send('setDisplayLayout', [secondary.id, this.layout_, offset]); 412 chrome.send('setDisplayLayout', [secondary.id, this.layout_, offset]);
412 }, 413 },
413 414
414 /** 415 /**
415 * Snaps the region [point, width] to [basePoint, baseWidth] if 416 * Snaps the region [point, width] to [basePoint, baseWidth] if
(...skipping 18 matching lines...) Expand all
434 return basePoint; 435 return basePoint;
435 else if (endDiff < SNAP_DISTANCE_PX) 436 else if (endDiff < SNAP_DISTANCE_PX)
436 return basePoint + baseWidth - width; 437 return basePoint + baseWidth - width;
437 438
438 return point; 439 return point;
439 }, 440 },
440 441
441 /** 442 /**
442 * Processes the actual dragging of display rectangle. 443 * Processes the actual dragging of display rectangle.
443 * @param {Event} e The event which triggers this drag. 444 * @param {Event} e The event which triggers this drag.
444 * @param {Object} eventLocation The location where the event happens. 445 * @param {options.DisplayPosition} eventLocation The location where the
446 * event happens.
445 * @private 447 * @private
446 */ 448 */
447 processDragging_: function(e, eventLocation) { 449 processDragging_: function(e, eventLocation) {
448 if (!this.dragging_) 450 if (!this.dragging_)
449 return true; 451 return true;
450 452
451 var index = -1; 453 var index = -1;
452 for (var i = 0; i < this.displays_.length; i++) { 454 for (var i = 0; i < this.displays_.length; i++) {
453 if (this.displays_[i] == this.dragging_.display) { 455 if (this.displays_[i] == this.dragging_.display) {
454 index = i; 456 index = i;
(...skipping 17 matching lines...) Expand all
472 474
473 var baseDiv = this.dragging_.display.isPrimary ? 475 var baseDiv = this.dragging_.display.isPrimary ?
474 this.secondaryDisplay_.div : this.primaryDisplay_.div; 476 this.secondaryDisplay_.div : this.primaryDisplay_.div;
475 var draggingDiv = this.dragging_.display.div; 477 var draggingDiv = this.dragging_.display.div;
476 478
477 newPosition.x = this.snapToEdge_(newPosition.x, draggingDiv.offsetWidth, 479 newPosition.x = this.snapToEdge_(newPosition.x, draggingDiv.offsetWidth,
478 baseDiv.offsetLeft, baseDiv.offsetWidth); 480 baseDiv.offsetLeft, baseDiv.offsetWidth);
479 newPosition.y = this.snapToEdge_(newPosition.y, draggingDiv.offsetHeight, 481 newPosition.y = this.snapToEdge_(newPosition.y, draggingDiv.offsetHeight,
480 baseDiv.offsetTop, baseDiv.offsetHeight); 482 baseDiv.offsetTop, baseDiv.offsetHeight);
481 483
482 var newCenter = { 484 var newCenter = /** {!options.DisplayPosition} */({
483 x: newPosition.x + draggingDiv.offsetWidth / 2, 485 x: newPosition.x + draggingDiv.offsetWidth / 2,
484 y: newPosition.y + draggingDiv.offsetHeight / 2 486 y: newPosition.y + draggingDiv.offsetHeight / 2
485 }; 487 });
486 488
487 var baseBounds = { 489 var baseBounds = /** {!options.DisplayBounds} */({
488 x: baseDiv.offsetLeft, 490 left: baseDiv.offsetLeft,
489 y: baseDiv.offsetTop, 491 top: baseDiv.offsetTop,
490 width: baseDiv.offsetWidth, 492 width: baseDiv.offsetWidth,
491 height: baseDiv.offsetHeight 493 height: baseDiv.offsetHeight
492 }; 494 });
493 switch (getPositionToRectangle(baseBounds, newCenter)) { 495 switch (getPositionToRectangle(baseBounds, newCenter)) {
494 case options.SecondaryDisplayLayout.RIGHT: 496 case options.DisplayLayoutType.RIGHT:
495 this.layout_ = this.dragging_.display.isPrimary ? 497 this.layout_ = this.dragging_.display.isPrimary ?
496 options.SecondaryDisplayLayout.LEFT : 498 options.DisplayLayoutType.LEFT :
497 options.SecondaryDisplayLayout.RIGHT; 499 options.DisplayLayoutType.RIGHT;
498 break; 500 break;
499 case options.SecondaryDisplayLayout.LEFT: 501 case options.DisplayLayoutType.LEFT:
500 this.layout_ = this.dragging_.display.isPrimary ? 502 this.layout_ = this.dragging_.display.isPrimary ?
501 options.SecondaryDisplayLayout.RIGHT : 503 options.DisplayLayoutType.RIGHT :
502 options.SecondaryDisplayLayout.LEFT; 504 options.DisplayLayoutType.LEFT;
503 break; 505 break;
504 case options.SecondaryDisplayLayout.TOP: 506 case options.DisplayLayoutType.TOP:
505 this.layout_ = this.dragging_.display.isPrimary ? 507 this.layout_ = this.dragging_.display.isPrimary ?
506 options.SecondaryDisplayLayout.BOTTOM : 508 options.DisplayLayoutType.BOTTOM :
507 options.SecondaryDisplayLayout.TOP; 509 options.DisplayLayoutType.TOP;
508 break; 510 break;
509 case options.SecondaryDisplayLayout.BOTTOM: 511 case options.DisplayLayoutType.BOTTOM:
510 this.layout_ = this.dragging_.display.isPrimary ? 512 this.layout_ = this.dragging_.display.isPrimary ?
511 options.SecondaryDisplayLayout.TOP : 513 options.DisplayLayoutType.TOP :
512 options.SecondaryDisplayLayout.BOTTOM; 514 options.DisplayLayoutType.BOTTOM;
513 break; 515 break;
514 } 516 }
515 517
516 if (this.layout_ == options.SecondaryDisplayLayout.LEFT || 518 if (this.layout_ == options.DisplayLayoutType.LEFT ||
517 this.layout_ == options.SecondaryDisplayLayout.RIGHT) { 519 this.layout_ == options.DisplayLayoutType.RIGHT) {
518 if (newPosition.y > baseDiv.offsetTop + baseDiv.offsetHeight) 520 if (newPosition.y > baseDiv.offsetTop + baseDiv.offsetHeight)
519 this.layout_ = this.dragging_.display.isPrimary ? 521 this.layout_ = this.dragging_.display.isPrimary ?
520 options.SecondaryDisplayLayout.TOP : 522 options.DisplayLayoutType.TOP :
521 options.SecondaryDisplayLayout.BOTTOM; 523 options.DisplayLayoutType.BOTTOM;
522 else if (newPosition.y + draggingDiv.offsetHeight < 524 else if (newPosition.y + draggingDiv.offsetHeight < baseDiv.offsetTop)
523 baseDiv.offsetTop)
524 this.layout_ = this.dragging_.display.isPrimary ? 525 this.layout_ = this.dragging_.display.isPrimary ?
525 options.SecondaryDisplayLayout.BOTTOM : 526 options.DisplayLayoutType.BOTTOM :
526 options.SecondaryDisplayLayout.TOP; 527 options.DisplayLayoutType.TOP;
527 } else { 528 } else {
528 if (newPosition.x > baseDiv.offsetLeft + baseDiv.offsetWidth) 529 if (newPosition.x > baseDiv.offsetLeft + baseDiv.offsetWidth)
529 this.layout_ = this.dragging_.display.isPrimary ? 530 this.layout_ = this.dragging_.display.isPrimary ?
530 options.SecondaryDisplayLayout.LEFT : 531 options.DisplayLayoutType.LEFT :
531 options.SecondaryDisplayLayout.RIGHT; 532 options.DisplayLayoutType.RIGHT;
532 else if (newPosition.x + draggingDiv.offsetWidth < 533 else if (newPosition.x + draggingDiv.offsetWidth < baseDiv.offsetLeft)
533 baseDiv.offsetLeft)
534 this.layout_ = this.dragging_.display.isPrimary ? 534 this.layout_ = this.dragging_.display.isPrimary ?
535 options.SecondaryDisplayLayout.RIGHT : 535 options.DisplayLayoutType.RIGHT :
536 options.SecondaryDisplayLayout.LEFT; 536 options.DisplayLayoutType.LEFT;
537 } 537 }
538 538
539 var layoutToBase; 539 var layoutToBase;
540 if (!this.dragging_.display.isPrimary) { 540 if (!this.dragging_.display.isPrimary) {
541 layoutToBase = this.layout_; 541 layoutToBase = this.layout_;
542 } else { 542 } else {
543 switch (this.layout_) { 543 switch (this.layout_) {
544 case options.SecondaryDisplayLayout.RIGHT: 544 case options.DisplayLayoutType.RIGHT:
545 layoutToBase = options.SecondaryDisplayLayout.LEFT; 545 layoutToBase = options.DisplayLayoutType.LEFT;
546 break; 546 break;
547 case options.SecondaryDisplayLayout.LEFT: 547 case options.DisplayLayoutType.LEFT:
548 layoutToBase = options.SecondaryDisplayLayout.RIGHT; 548 layoutToBase = options.DisplayLayoutType.RIGHT;
549 break; 549 break;
550 case options.SecondaryDisplayLayout.TOP: 550 case options.DisplayLayoutType.TOP:
551 layoutToBase = options.SecondaryDisplayLayout.BOTTOM; 551 layoutToBase = options.DisplayLayoutType.BOTTOM;
552 break; 552 break;
553 case options.SecondaryDisplayLayout.BOTTOM: 553 case options.DisplayLayoutType.BOTTOM:
554 layoutToBase = options.SecondaryDisplayLayout.TOP; 554 layoutToBase = options.DisplayLayoutType.TOP;
555 break; 555 break;
556 } 556 }
557 } 557 }
558 558
559 switch (layoutToBase) { 559 switch (layoutToBase) {
560 case options.SecondaryDisplayLayout.RIGHT: 560 case options.DisplayLayoutType.RIGHT:
561 draggingDiv.style.left = 561 draggingDiv.style.left =
562 baseDiv.offsetLeft + baseDiv.offsetWidth + 'px'; 562 baseDiv.offsetLeft + baseDiv.offsetWidth + 'px';
563 draggingDiv.style.top = newPosition.y + 'px'; 563 draggingDiv.style.top = newPosition.y + 'px';
564 break; 564 break;
565 case options.SecondaryDisplayLayout.LEFT: 565 case options.DisplayLayoutType.LEFT:
566 draggingDiv.style.left = 566 draggingDiv.style.left =
567 baseDiv.offsetLeft - draggingDiv.offsetWidth + 'px'; 567 baseDiv.offsetLeft - draggingDiv.offsetWidth + 'px';
568 draggingDiv.style.top = newPosition.y + 'px'; 568 draggingDiv.style.top = newPosition.y + 'px';
569 break; 569 break;
570 case options.SecondaryDisplayLayout.TOP: 570 case options.DisplayLayoutType.TOP:
571 draggingDiv.style.top = 571 draggingDiv.style.top =
572 baseDiv.offsetTop - draggingDiv.offsetHeight + 'px'; 572 baseDiv.offsetTop - draggingDiv.offsetHeight + 'px';
573 draggingDiv.style.left = newPosition.x + 'px'; 573 draggingDiv.style.left = newPosition.x + 'px';
574 break; 574 break;
575 case options.SecondaryDisplayLayout.BOTTOM: 575 case options.DisplayLayoutType.BOTTOM:
576 draggingDiv.style.top = 576 draggingDiv.style.top =
577 baseDiv.offsetTop + baseDiv.offsetHeight + 'px'; 577 baseDiv.offsetTop + baseDiv.offsetHeight + 'px';
578 draggingDiv.style.left = newPosition.x + 'px'; 578 draggingDiv.style.left = newPosition.x + 'px';
579 break; 579 break;
580 } 580 }
581 581
582 return false; 582 return false;
583 }, 583 },
584 584
585 /** 585 /**
586 * start dragging of a display rectangle. 586 * Start dragging of a display rectangle.
587 * @param {HTMLElement} target The event target. 587 * @param {!HTMLElement} target The event target.
588 * @param {Object} eventLocation The object to hold the location where 588 * @param {!options.DisplayPosition} eventLocation The event location.
589 * this event happens.
590 * @private 589 * @private
591 */ 590 */
592 startDragging_: function(target, eventLocation) { 591 startDragging_: function(target, eventLocation) {
593 var oldFocusedIndex = this.focusedIndex_; 592 var oldFocusedIndex = this.focusedIndex_;
594 var willUpdateDisplayDescription = false; 593 var willUpdateDisplayDescription = false;
595 this.focusedIndex_ = null; 594 this.focusedIndex_ = -1;
596 for (var i = 0; i < this.displays_.length; i++) { 595 for (var i = 0; i < this.displays_.length; i++) {
597 var display = this.displays_[i]; 596 var display = this.displays_[i];
598 if (display.div == target || 597 if (display.div == target ||
599 (target.offsetParent && target.offsetParent == display.div)) { 598 (target.offsetParent && target.offsetParent == display.div)) {
600 this.focusedIndex_ = i; 599 this.focusedIndex_ = i;
601 if (oldFocusedIndex !== null && oldFocusedIndex != i) 600 if (oldFocusedIndex !== null && oldFocusedIndex != i)
602 willUpdateDisplayDescription = true; 601 willUpdateDisplayDescription = true;
603 break; 602 break;
604 } 603 }
605 } 604 }
(...skipping 24 matching lines...) Expand all
630 /** 629 /**
631 * finish the current dragging of displays. 630 * finish the current dragging of displays.
632 * @param {Event} e The event which triggers this. 631 * @param {Event} e The event which triggers this.
633 * @private 632 * @private
634 */ 633 */
635 endDragging_: function(e) { 634 endDragging_: function(e) {
636 this.lastTouchLocation_ = null; 635 this.lastTouchLocation_ = null;
637 if (this.dragging_) { 636 if (this.dragging_) {
638 // Make sure the dragging location is connected. 637 // Make sure the dragging location is connected.
639 var baseDiv = this.dragging_.display.isPrimary ? 638 var baseDiv = this.dragging_.display.isPrimary ?
640 this.secondaryDisplay_.div : this.primaryDisplay_.div; 639 this.secondaryDisplay_.div :
640 this.primaryDisplay_.div;
641 var draggingDiv = this.dragging_.display.div; 641 var draggingDiv = this.dragging_.display.div;
642 if (this.layout_ == options.SecondaryDisplayLayout.LEFT || 642 if (this.layout_ == options.DisplayLayoutType.LEFT ||
643 this.layout_ == options.SecondaryDisplayLayout.RIGHT) { 643 this.layout_ == options.DisplayLayoutType.RIGHT) {
644 var top = Math.max(draggingDiv.offsetTop, 644 var top = Math.max(
645 baseDiv.offsetTop - draggingDiv.offsetHeight + 645 draggingDiv.offsetTop, baseDiv.offsetTop -
646 MIN_OFFSET_OVERLAP); 646 draggingDiv.offsetHeight + MIN_OFFSET_OVERLAP);
647 top = Math.min(top, 647 top = Math.min(
648 baseDiv.offsetTop + baseDiv.offsetHeight - 648 top,
649 MIN_OFFSET_OVERLAP); 649 baseDiv.offsetTop + baseDiv.offsetHeight - MIN_OFFSET_OVERLAP);
650 draggingDiv.style.top = top + 'px'; 650 draggingDiv.style.top = top + 'px';
651 } else { 651 } else {
652 var left = Math.max(draggingDiv.offsetLeft, 652 var left = Math.max(
653 baseDiv.offsetLeft - draggingDiv.offsetWidth + 653 draggingDiv.offsetLeft, baseDiv.offsetLeft -
654 MIN_OFFSET_OVERLAP); 654 draggingDiv.offsetWidth + MIN_OFFSET_OVERLAP);
655 left = Math.min(left, 655 left = Math.min(
656 baseDiv.offsetLeft + baseDiv.offsetWidth - 656 left,
657 MIN_OFFSET_OVERLAP); 657 baseDiv.offsetLeft + baseDiv.offsetWidth - MIN_OFFSET_OVERLAP);
658 draggingDiv.style.left = left + 'px'; 658 draggingDiv.style.left = left + 'px';
659 } 659 }
660 var originalPosition = this.dragging_.display.originalPosition; 660 var originalPosition = this.dragging_.display.originalPosition;
661 if (originalPosition.x != draggingDiv.offsetLeft || 661 if (originalPosition.x != draggingDiv.offsetLeft ||
662 originalPosition.y != draggingDiv.offsetTop) 662 originalPosition.y != draggingDiv.offsetTop)
663 this.applyResult_(); 663 this.applyResult_();
664 this.dragging_ = null; 664 this.dragging_ = null;
665 } 665 }
666 return false; 666 return false;
667 }, 667 },
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 $('display-options-orientation-selection').disabled = true; 704 $('display-options-orientation-selection').disabled = true;
705 $('selected-display-name').textContent = ''; 705 $('selected-display-name').textContent = '';
706 var resolution = $('display-options-resolution-selection'); 706 var resolution = $('display-options-resolution-selection');
707 resolution.appendChild(document.createElement('option')); 707 resolution.appendChild(document.createElement('option'));
708 resolution.disabled = true; 708 resolution.disabled = true;
709 }, 709 },
710 710
711 /** 711 /**
712 * Updates the description of selected display section for the selected 712 * Updates the description of selected display section for the selected
713 * display. 713 * display.
714 * @param {Object} display The selected display object. 714 * @param {options.DisplayInfo} display The selected display object.
715 * @private 715 * @private
716 */ 716 */
717 updateSelectedDisplaySectionForDisplay_: function(display) { 717 updateSelectedDisplaySectionForDisplay_: function(display) {
718 var arrow = $('display-configuration-arrow'); 718 var arrow = $('display-configuration-arrow');
719 arrow.hidden = false; 719 arrow.hidden = false;
720 // Adding 1 px to the position to fit the border line and the border in 720 // Adding 1 px to the position to fit the border line and the border in
721 // arrow precisely. 721 // arrow precisely.
722 arrow.style.top = $('display-configurations').offsetTop - 722 arrow.style.top = $('display-configurations').offsetTop -
723 arrow.offsetHeight / 2 + 'px'; 723 arrow.offsetHeight / 2 + 'px';
724 arrow.style.left = display.div.offsetLeft + 724 arrow.style.left = display.div.offsetLeft +
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 updateSelectedDisplayDescription_: function() { 797 updateSelectedDisplayDescription_: function() {
798 var resolution = $('display-options-resolution-selection'); 798 var resolution = $('display-options-resolution-selection');
799 resolution.textContent = ''; 799 resolution.textContent = '';
800 var orientation = $('display-options-orientation-selection'); 800 var orientation = $('display-options-orientation-selection');
801 var orientationOptions = orientation.getElementsByTagName('option'); 801 var orientationOptions = orientation.getElementsByTagName('option');
802 for (var i = 0; i < orientationOptions.length; i++) 802 for (var i = 0; i < orientationOptions.length; i++)
803 orientationOptions[i].selected = false; 803 orientationOptions[i].selected = false;
804 804
805 if (this.mirroring_) { 805 if (this.mirroring_) {
806 this.updateSelectedDisplaySectionMirroring_(); 806 this.updateSelectedDisplaySectionMirroring_();
807 } else if (this.focusedIndex_ == null || 807 } else if (this.focusedIndex_ == -1 ||
808 this.displays_[this.focusedIndex_] == null) { 808 this.displays_[this.focusedIndex_] == null) {
809 this.updateSelectedDisplaySectionNoSelected_(); 809 this.updateSelectedDisplaySectionNoSelected_();
810 } else { 810 } else {
811 this.updateSelectedDisplaySectionForDisplay_( 811 this.updateSelectedDisplaySectionForDisplay_(
812 this.displays_[this.focusedIndex_]); 812 this.displays_[this.focusedIndex_]);
813 } 813 }
814 }, 814 },
815 815
816 /** 816 /**
817 * Clears the drawing area for display rectangles. 817 * Clears the drawing area for display rectangles.
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 }; 974 };
975 975
976 if (this.secondaryDisplay_) { 976 if (this.secondaryDisplay_) {
977 var secondaryDiv = this.createDisplayRectangle_( 977 var secondaryDiv = this.createDisplayRectangle_(
978 this.secondaryDisplay_, this.secondaryDisplay_ == focusedDisplay); 978 this.secondaryDisplay_, this.secondaryDisplay_ == focusedDisplay);
979 // Don't trust the secondary display's x or y, because it may cause a 979 // Don't trust the secondary display's x or y, because it may cause a
980 // 1px gap due to rounding, which will create a fake update on end 980 // 1px gap due to rounding, which will create a fake update on end
981 // dragging. See crbug.com/386401 981 // dragging. See crbug.com/386401
982 var bounds = this.secondaryDisplay_.bounds; 982 var bounds = this.secondaryDisplay_.bounds;
983 switch (this.layout_) { 983 switch (this.layout_) {
984 case options.SecondaryDisplayLayout.TOP: 984 case options.DisplayLayoutType.TOP:
985 secondaryDiv.style.left = 985 secondaryDiv.style.left =
986 Math.floor(bounds.left * this.visualScale_) + offset.x + 'px'; 986 Math.floor(bounds.left * this.visualScale_) + offset.x + 'px';
987 secondaryDiv.style.top = 987 secondaryDiv.style.top =
988 primaryDiv.offsetTop - secondaryDiv.offsetHeight + 'px'; 988 primaryDiv.offsetTop - secondaryDiv.offsetHeight + 'px';
989 break; 989 break;
990 case options.SecondaryDisplayLayout.RIGHT: 990 case options.DisplayLayoutType.RIGHT:
991 secondaryDiv.style.left = 991 secondaryDiv.style.left =
992 primaryDiv.offsetLeft + primaryDiv.offsetWidth + 'px'; 992 primaryDiv.offsetLeft + primaryDiv.offsetWidth + 'px';
993 secondaryDiv.style.top = 993 secondaryDiv.style.top =
994 Math.floor(bounds.top * this.visualScale_) + offset.y + 'px'; 994 Math.floor(bounds.top * this.visualScale_) + offset.y + 'px';
995 break; 995 break;
996 case options.SecondaryDisplayLayout.BOTTOM: 996 case options.DisplayLayoutType.BOTTOM:
997 secondaryDiv.style.left = 997 secondaryDiv.style.left =
998 Math.floor(bounds.left * this.visualScale_) + offset.x + 'px'; 998 Math.floor(bounds.left * this.visualScale_) + offset.x + 'px';
999 secondaryDiv.style.top = 999 secondaryDiv.style.top =
1000 primaryDiv.offsetTop + primaryDiv.offsetHeight + 'px'; 1000 primaryDiv.offsetTop + primaryDiv.offsetHeight + 'px';
1001 break; 1001 break;
1002 case options.SecondaryDisplayLayout.LEFT: 1002 case options.DisplayLayoutType.LEFT:
1003 secondaryDiv.style.left = 1003 secondaryDiv.style.left =
1004 primaryDiv.offsetLeft - secondaryDiv.offsetWidth + 'px'; 1004 primaryDiv.offsetLeft - secondaryDiv.offsetWidth + 'px';
1005 secondaryDiv.style.top = 1005 secondaryDiv.style.top =
1006 Math.floor(bounds.top * this.visualScale_) + offset.y + 'px'; 1006 Math.floor(bounds.top * this.visualScale_) + offset.y + 'px';
1007 break; 1007 break;
1008 } 1008 }
1009 this.secondaryDisplay_.originalPosition = { 1009 this.secondaryDisplay_.originalPosition = {
1010 x: secondaryDiv.offsetLeft, 1010 x: secondaryDiv.offsetLeft,
1011 y: secondaryDiv.offsetTop 1011 y: secondaryDiv.offsetTop
1012 }; 1012 };
1013 } 1013 }
1014 }, 1014 },
1015 1015
1016 /** 1016 /**
1017 * Called when the display arrangement has changed. 1017 * Called when the display arrangement has changed.
1018 * @param {options.MultiDisplayMode} mode multi display mode. 1018 * @param {options.MultiDisplayMode} mode multi display mode.
1019 * @param {Array<options.DisplayInfo>} displays The list of the display 1019 * @param {Array<options.DisplayInfo>} displays The list of the display
1020 * information. 1020 * information.
1021 * @param {options.SecondaryDisplayLayout} layout The layout strategy. 1021 * @param {options.DisplayLayoutType} layout The layout strategy.
1022 * @param {number} offset The offset of the secondary display. 1022 * @param {number} offset The offset of the secondary display.
1023 * @private 1023 * @private
1024 */ 1024 */
1025 onDisplayChanged_: function(mode, displays, layout, offset) { 1025 onDisplayChanged_: function(mode, displays, layout, offset) {
1026 if (!this.visible) 1026 if (!this.visible)
1027 return; 1027 return;
1028 1028
1029 var hasExternal = false; 1029 var hasExternal = false;
1030 for (var i = 0; i < displays.length; i++) { 1030 for (var i = 0; i < displays.length; i++) {
1031 if (!displays[i].isInternal) { 1031 if (!displays[i].isInternal) {
1032 hasExternal = true; 1032 hasExternal = true;
1033 break; 1033 break;
1034 } 1034 }
1035 } 1035 }
1036 1036
1037 this.layout_ = layout; 1037 this.layout_ = layout;
1038 1038
1039 var mirroring = mode == options.MultiDisplayMode.MIRRORING; 1039 var mirroring = mode == options.MultiDisplayMode.MIRRORING;
1040 var unifiedDesktopEnabled = mode == options.MultiDisplayMode.UNIFIED; 1040 var unifiedDesktopEnabled = mode == options.MultiDisplayMode.UNIFIED;
1041 1041
1042 // Focus to the first display next to the primary one when |displays| list 1042 // Focus to the first display next to the primary one when |displays| list
1043 // is updated. 1043 // is updated.
1044 if (mirroring) { 1044 if (mirroring) {
1045 this.focusedIndex_ = null; 1045 this.focusedIndex_ = -1;
1046 } else if (this.mirroring_ != mirroring || 1046 } else if (this.mirroring_ != mirroring ||
1047 this.unifiedDesktopEnabled_ != unifiedDesktopEnabled || 1047 this.unifiedDesktopEnabled_ != unifiedDesktopEnabled ||
1048 this.displays_.length != displays.length) { 1048 this.displays_.length != displays.length) {
1049 this.focusedIndex_ = 0; 1049 this.focusedIndex_ = 0;
1050 } 1050 }
1051 1051
1052 this.mirroring_ = mirroring; 1052 this.mirroring_ = mirroring;
1053 this.unifiedDesktopEnabled_ = unifiedDesktopEnabled; 1053 this.unifiedDesktopEnabled_ = unifiedDesktopEnabled;
1054 this.displays_ = displays; 1054 this.displays_ = displays;
1055 1055
(...skipping 28 matching lines...) Expand all
1084 mode, displays, layout, offset) { 1084 mode, displays, layout, offset) {
1085 DisplayOptions.getInstance().onDisplayChanged_( 1085 DisplayOptions.getInstance().onDisplayChanged_(
1086 mode, displays, layout, offset); 1086 mode, displays, layout, offset);
1087 }; 1087 };
1088 1088
1089 // Export 1089 // Export
1090 return { 1090 return {
1091 DisplayOptions: DisplayOptions 1091 DisplayOptions: DisplayOptions
1092 }; 1092 };
1093 }); 1093 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698