OLD | NEW |
---|---|
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.define('options', function() { | 5 cr.define('options', function() { |
6 var OptionsPage = options.OptionsPage; | 6 var OptionsPage = options.OptionsPage; |
7 | 7 |
8 // The scale ratio of the display rectangle to its original size. | 8 // The scale ratio of the display rectangle to its original size. |
9 /** @const */ var VISUAL_SCALE = 1 / 10; | 9 /** @const */ var VISUAL_SCALE = 1 / 10; |
10 | 10 |
(...skipping 26 matching lines...) Expand all Loading... | |
37 | 37 |
38 DisplayOptions.prototype = { | 38 DisplayOptions.prototype = { |
39 __proto__: OptionsPage.prototype, | 39 __proto__: OptionsPage.prototype, |
40 | 40 |
41 /** | 41 /** |
42 * Initialize the page. | 42 * Initialize the page. |
43 */ | 43 */ |
44 initializePage: function() { | 44 initializePage: function() { |
45 OptionsPage.prototype.initializePage.call(this); | 45 OptionsPage.prototype.initializePage.call(this); |
46 | 46 |
47 $('display-options-confirm').onclick = function() { | |
48 OptionsPage.closeOverlay(); | |
49 }; | |
50 | |
51 $('display-options-toggle-mirroring').onclick = (function() { | 47 $('display-options-toggle-mirroring').onclick = (function() { |
52 this.mirroring_ = !this.mirroring_; | 48 this.mirroring_ = !this.mirroring_; |
53 chrome.send('setMirroring', [this.mirroring_]); | 49 chrome.send('setMirroring', [this.mirroring_]); |
54 }).bind(this); | 50 }).bind(this); |
55 | 51 |
52 $('display-options-apply').onclick = (function() { | |
53 chrome.send('setDisplayLayout', [this.layout_]); | |
54 }).bind(this); | |
56 chrome.send('getDisplayInfo'); | 55 chrome.send('getDisplayInfo'); |
57 }, | 56 }, |
58 | 57 |
59 /** | 58 /** |
60 * Mouse move handler for dragging display rectangle. | 59 * Mouse move handler for dragging display rectangle. |
61 * @private | 60 * @private |
62 * @param {Event} e The mouse move event. | 61 * @param {Event} e The mouse move event. |
63 */ | 62 */ |
64 onMouseMove_: function(e) { | 63 onMouseMove_: function(e) { |
65 if (!this.dragging_) | 64 if (!this.dragging_) |
66 return true; | 65 return true; |
67 | 66 |
68 var index = -1; | 67 var index = -1; |
69 for (var i = 0; i < this.displays_.length; i++) { | 68 for (var i = 0; i < this.displays_.length; i++) { |
70 if (this.displays_[i] == this.dragging_.display) { | 69 if (this.displays_[i] == this.dragging_.display) { |
71 index = i; | 70 index = i; |
72 break; | 71 break; |
73 } | 72 } |
74 } | 73 } |
75 if (index < 0) | 74 if (index < 0) |
76 return true; | 75 return true; |
77 | 76 |
78 // Note that current code of moving display-rectangles doesn't work | 77 // Note that current code of moving display-rectangles doesn't work |
79 // if there are >=3 displays. This is our assumption for M21. | 78 // if there are >=3 displays. This is our assumption for M21. |
80 // TODO(mukai): Fix the code to allow >=3 displays. | 79 // TODO(mukai): Fix the code to allow >=3 displays. |
81 var mouse_position = { | 80 var mousePosition = { |
82 x: e.pageX - this.dragging_.offset.x, | 81 x: e.pageX - this.dragging_.offset.x, |
83 y: e.pageY - this.dragging_.offset.y | 82 y: e.pageY - this.dragging_.offset.y |
84 }; | 83 }; |
85 var new_position = { | 84 var newPosition = { |
86 x: mouse_position.x - this.dragging_.click_location.x, | 85 x: mousePosition.x - this.dragging_.clickLocation.x, |
87 y: mouse_position.y - this.dragging_.click_location.y | 86 y: mousePosition.y - this.dragging_.clickLocation.y |
88 }; | 87 }; |
89 | 88 |
90 var primary_div = this.displays_[0].div; | 89 var primaryDiv = this.displays_[0].div; |
91 var display = this.dragging_.display; | 90 var display = this.dragging_.display; |
92 | 91 |
93 // Separate the area into four (LEFT/RIGHT/TOP/BOTTOM) by the diagonals of | 92 // Separate the area into four (LEFT/RIGHT/TOP/BOTTOM) by the diagonals of |
94 // the primary display, and decide which area the display should reside. | 93 // the primary display, and decide which area the display should reside. |
95 var diagonal_slope = primary_div.offsetHeight / primary_div.offsetWidth; | 94 var diagonalSlope = primaryDiv.offsetHeight / primaryDiv.offsetWidth; |
96 var top_down_intercept = | 95 var topDownIntercept = |
97 primary_div.offsetTop - primary_div.offsetLeft * diagonal_slope; | 96 primaryDiv.offsetTop - primaryDiv.offsetLeft * diagonalSlope; |
98 var bottom_up_intercept = primary_div.offsetTop + | 97 var bottomUpIntercept = primaryDiv.offsetTop + |
99 primary_div.offsetHeight + primary_div.offsetLeft * diagonal_slope; | 98 primaryDiv.offsetHeight + primaryDiv.offsetLeft * diagonalSlope; |
100 | 99 |
101 if (mouse_position.y > | 100 if (mousePosition.y > |
102 top_down_intercept + mouse_position.x * diagonal_slope) { | 101 topDownIntercept + mousePosition.x * diagonalSlope) { |
103 if (mouse_position.y > | 102 if (mousePosition.y > |
104 bottom_up_intercept - mouse_position.x * diagonal_slope) | 103 bottomUpIntercept - mousePosition.x * diagonalSlope) |
105 this.layout_ = SecondaryDisplayLayout.BOTTOM; | 104 this.layout_ = SecondaryDisplayLayout.BOTTOM; |
106 else | 105 else |
107 this.layout_ = SecondaryDisplayLayout.LEFT; | 106 this.layout_ = SecondaryDisplayLayout.LEFT; |
108 } else { | 107 } else { |
109 if (mouse_position.y > | 108 if (mousePosition.y > |
110 bottom_up_intercept - mouse_position.x * diagonal_slope) | 109 bottomUpIntercept - mousePosition.x * diagonalSlope) |
111 this.layout_ = SecondaryDisplayLayout.RIGHT; | 110 this.layout_ = SecondaryDisplayLayout.RIGHT; |
112 else | 111 else |
113 this.layout_ = SecondaryDisplayLayout.TOP; | 112 this.layout_ = SecondaryDisplayLayout.TOP; |
114 } | 113 } |
115 | 114 |
116 if (this.layout_ == SecondaryDisplayLayout.LEFT || | 115 if (this.layout_ == SecondaryDisplayLayout.LEFT || |
117 this.layout_ == SecondaryDisplayLayout.RIGHT) { | 116 this.layout_ == SecondaryDisplayLayout.RIGHT) { |
118 if (new_position.y > primary_div.offsetTop + primary_div.offsetHeight) | 117 if (newPosition.y > primaryDiv.offsetTop + primaryDiv.offsetHeight) |
119 this.layout_ = SecondaryDisplayLayout.BOTTOM; | 118 this.layout_ = SecondaryDisplayLayout.BOTTOM; |
120 else if (new_position.y + display.div.offsetHeight < | 119 else if (newPosition.y + display.div.offsetHeight < |
121 primary_div.offsetTop) | 120 primaryDiv.offsetTop) |
122 this.layout_ = SecondaryDisplayLayout.TOP; | 121 this.layout_ = SecondaryDisplayLayout.TOP; |
123 } else { | 122 } else { |
124 if (new_position.y > primary_div.offsetLeft + primary_div.offsetWidth) | 123 if (newPosition.y > primaryDiv.offsetLeft + primaryDiv.offsetWidth) |
125 this.layout_ = SecondaryDisplayLayout.RIGHT; | 124 this.layout_ = SecondaryDisplayLayout.RIGHT; |
126 else if (new_position.y + display.div.offsetWidth < | 125 else if (newPosition.y + display.div.offsetWidth < |
127 primary_div.offstLeft) | 126 primaryDiv.offstLeft) |
128 this.layout_ = SecondaryDisplayLayout.LEFT; | 127 this.layout_ = SecondaryDisplayLayout.LEFT; |
129 } | 128 } |
130 | 129 |
131 switch (this.layout_) { | 130 switch (this.layout_) { |
132 case SecondaryDisplayLayout.RIGHT: | 131 case SecondaryDisplayLayout.RIGHT: |
133 display.div.style.left = | 132 display.div.style.left = |
134 primary_div.offsetLeft + primary_div.offsetWidth + 'px'; | 133 primaryDiv.offsetLeft + primaryDiv.offsetWidth + 'px'; |
135 display.div.style.top = new_position.y + 'px'; | 134 display.div.style.top = newPosition.y + 'px'; |
136 break; | 135 break; |
137 case SecondaryDisplayLayout.LEFT: | 136 case SecondaryDisplayLayout.LEFT: |
138 display.div.style.left = | 137 display.div.style.left = |
139 primary_div.offsetLeft - display.div.offsetWidth + 'px'; | 138 primaryDiv.offsetLeft - display.div.offsetWidth + 'px'; |
140 display.div.style.top = new_position.y + 'px'; | 139 display.div.style.top = newPosition.y + 'px'; |
141 break; | 140 break; |
142 case SecondaryDisplayLayout.TOP: | 141 case SecondaryDisplayLayout.TOP: |
143 display.div.style.top = | 142 display.div.style.top = |
144 primary_div.offsetTop - display.div.offsetHeight + 'px'; | 143 primaryDiv.offsetTop - display.div.offsetHeight + 'px'; |
145 display.div.style.left = new_position.x + 'px'; | 144 display.div.style.left = newPosition.x + 'px'; |
146 break; | 145 break; |
147 case SecondaryDisplayLayout.BOTTOM: | 146 case SecondaryDisplayLayout.BOTTOM: |
148 display.div.style.top = | 147 display.div.style.top = |
149 primary_div.offsetTop + primary_div.offsetHeight + 'px'; | 148 primaryDiv.offsetTop + primaryDiv.offsetHeight + 'px'; |
150 display.div.style.left = new_position.x + 'px'; | 149 display.div.style.left = newPosition.x + 'px'; |
151 break; | 150 break; |
152 } | 151 } |
153 | 152 |
154 return false; | 153 return false; |
155 }, | 154 }, |
156 | 155 |
157 /** | 156 /** |
158 * Mouse down handler for dragging display rectangle. | 157 * Mouse down handler for dragging display rectangle. |
159 * @private | 158 * @private |
160 * @param {Event} e The mouse down event. | 159 * @param {Event} e The mouse down event. |
161 */ | 160 */ |
162 onMouseDown_: function(e) { | 161 onMouseDown_: function(e) { |
163 if (this.mirroring_) | 162 if (this.mirroring_) |
164 return true; | 163 return true; |
165 | 164 |
166 if (e.button != 0) | 165 if (e.button != 0) |
167 return true; | 166 return true; |
168 | 167 |
169 if (e.target == this.displays_view_) | 168 this.focusedIndex_ = null; |
170 return true; | 169 for (var i = 0; i < this.displays_.length; i++) { |
170 var display = this.displays_[i]; | |
171 if (this.displays_[i].div == e.target || | |
172 (i == 0 && $('display-launcher') == e.target)) { | |
173 this.focusedIndex_ = i; | |
174 break; | |
175 } | |
176 } | |
171 | 177 |
172 for (var i = 0; i < this.displays_.length; i++) { | 178 for (var i = 0; i < this.displays_.length; i++) { |
173 var display = this.displays_[i]; | 179 var display = this.displays_[i]; |
174 if (display.div == e.target) { | 180 display.div.className = 'displays-display'; |
175 // Do not drag the primary monitor. | 181 if (i != this.focusedIndex_) |
176 if (i == 0) | 182 continue; |
177 return true; | |
178 | 183 |
179 this.focused_index_ = i; | 184 display.div.className += ' displays-focused'; |
James Hawkins
2012/08/06 16:44:43
classList.add
Jun Mukai
2012/08/07 00:31:31
Done.
| |
180 this.dragging_ = { | 185 // Do not drag the primary monitor. |
186 if (i == 0) | |
187 continue; | |
188 | |
189 this.dragging_ = { | |
181 display: display, | 190 display: display, |
182 click_location: {x: e.offsetX, y: e.offsetY}, | 191 clickLocation: {x: e.offsetX, y: e.offsetY}, |
183 offset: {x: e.pageX - e.offsetX - display.div.offsetLeft, | 192 offset: {x: e.pageX - e.offsetX - display.div.offsetLeft, |
184 y: e.pageY - e.offsetY - display.div.offsetTop} | 193 y: e.pageY - e.offsetY - display.div.offsetTop} |
185 }; | 194 }; |
186 if (display.div.className.indexOf('displays-focused') == -1) | |
187 display.div.className += ' displays-focused'; | |
188 } else if (display.div.className.indexOf('displays-focused') >= 0) { | |
189 // We can assume that '-primary' monitor doesn't have '-focused'. | |
190 this.displays_[i].div.className = 'displays-display'; | |
191 } | |
192 } | 195 } |
196 this.updateSelectedDisplayDescription_(); | |
193 return false; | 197 return false; |
194 }, | 198 }, |
195 | 199 |
196 /** | 200 /** |
197 * Mouse up handler for dragging display rectangle. | 201 * Mouse up handler for dragging display rectangle. |
198 * @private | 202 * @private |
199 * @param {Event} e The mouse up event. | 203 * @param {Event} e The mouse up event. |
200 */ | 204 */ |
201 onMouseUp_: function(e) { | 205 onMouseUp_: function(e) { |
202 if (this.dragging_) { | 206 if (this.dragging_) |
203 this.dragging_ = null; | 207 this.dragging_ = null; |
204 chrome.send('setDisplayLayout', [this.layout_]); | 208 this.updateSelectedDisplayDescription_(); |
209 return false; | |
210 }, | |
211 | |
212 /** | |
213 * Updates the description of the selected display section. | |
214 * @private | |
215 */ | |
216 updateSelectedDisplayDescription_: function() { | |
217 if (this.focusedIndex_ == null || | |
218 this.displays_[this.focusedIndex_] == null) { | |
219 $('selected-display-data-container').hidden = true; | |
220 $('display-configuration-arrow').hidden = true; | |
221 return; | |
205 } | 222 } |
206 return false; | 223 |
224 $('selected-display-data-container').hidden = false; | |
225 var display = this.displays_[this.focusedIndex_]; | |
226 var nameElement = $('selected-display-name'); | |
227 while (nameElement.childNodes.length > 0) | |
228 nameElement.removeChild(nameElement.firstChild); | |
229 nameElement.appendChild(document.createTextNode(display.name)); | |
230 | |
231 var resolutionData = display.width + 'x' + display.height; | |
232 var resolutionElement = $('selected-display-resolution'); | |
233 while (resolutionElement.childNodes.length > 0) | |
234 resolutionElement.removeChild(resolutionElement.firstChild); | |
235 resolutionElement.appendChild(document.createTextNode(resolutionData)); | |
236 | |
237 var arrow = $('display-configuration-arrow'); | |
238 arrow.hidden = false; | |
239 arrow.style.top = | |
240 $('display-configurations').offsetTop - arrow.offsetHeight / 2 + 'px'; | |
241 arrow.style.left = display.div.offsetLeft + display.div.offsetWidth / 2 - | |
242 arrow.offsetWidth / 2 + 'px'; | |
207 }, | 243 }, |
208 | 244 |
209 /** | 245 /** |
210 * Clears the drawing area for display rectangles. | 246 * Clears the drawing area for display rectangles. |
211 * @private | 247 * @private |
212 */ | 248 */ |
213 resetDisplaysView_: function() { | 249 resetDisplaysView_: function() { |
214 var displays_view_host = $('display-options-displays-view-host'); | 250 var displaysViewHost = $('display-options-displays-view-host'); |
215 displays_view_host.removeChild(displays_view_host.firstChild); | 251 displaysViewHost.removeChild(displaysViewHost.firstChild); |
216 this.displays_view_ = document.createElement('div'); | 252 this.displaysView_ = document.createElement('div'); |
217 this.displays_view_.id = 'display-options-displays-view'; | 253 this.displaysView_.id = 'display-options-displays-view'; |
218 this.displays_view_.onmousemove = this.onMouseMove_.bind(this); | 254 this.displaysView_.onmousemove = this.onMouseMove_.bind(this); |
219 this.displays_view_.onmousedown = this.onMouseDown_.bind(this); | 255 this.displaysView_.onmousedown = this.onMouseDown_.bind(this); |
220 this.displays_view_.onmouseup = this.onMouseUp_.bind(this); | 256 this.displaysView_.onmouseup = this.onMouseUp_.bind(this); |
221 displays_view_host.appendChild(this.displays_view_); | 257 displaysViewHost.appendChild(this.displaysView_); |
222 }, | 258 }, |
223 | 259 |
224 /** | 260 /** |
225 * Lays out the display rectangles for mirroring. | 261 * Lays out the display rectangles for mirroring. |
226 * @private | 262 * @private |
227 */ | 263 */ |
228 layoutMirroringDisplays_: function() { | 264 layoutMirroringDisplays_: function() { |
229 // Offset pixels for secondary display rectangles. | 265 // Offset pixels for secondary display rectangles. |
230 /** @const */ var MIRRORING_OFFSET_PIXELS = 2; | 266 /** @const */ var MIRRORING_OFFSET_PIXELS = 2; |
231 // Always show two displays because there must be two displays when | 267 // Always show two displays because there must be two displays when |
232 // the display_options is enabled. Don't rely on displays_.length because | 268 // the display_options is enabled. Don't rely on displays_.length because |
233 // there is only one display from chrome's perspective in mirror mode. | 269 // there is only one display from chrome's perspective in mirror mode. |
234 /** @const */ var MIN_NUM_DISPLAYS = 2; | 270 /** @const */ var MIN_NUM_DISPLAYS = 2; |
271 /** @const */ var MIRRORING_VERTICAL_MARGIN = 20; | |
235 | 272 |
236 // The width/height should be same as the primary display: | 273 // The width/height should be same as the primary display: |
237 var width = this.displays_[0].width * VISUAL_SCALE; | 274 var width = this.displays_[0].width * VISUAL_SCALE; |
238 var height = this.displays_[0].height * VISUAL_SCALE; | 275 var height = this.displays_[0].height * VISUAL_SCALE; |
239 | 276 |
240 var num_displays = Math.max(MIN_NUM_DISPLAYS, this.displays_.length); | 277 var numDisplays = Math.max(MIN_NUM_DISPLAYS, this.displays_.length); |
241 | 278 |
242 this.displays_view_.style.height = | 279 var totalWidth = width + numDisplays * MIRRORING_OFFSET_PIXELS; |
243 height + num_displays * MIRRORING_OFFSET_PIXELS + 'px'; | 280 var totalHeight = height + numDisplays * MIRRORING_OFFSET_PIXELS; |
244 | 281 |
245 for (var i = 0; i < num_displays; i++) { | 282 this.displaysView_.style.height = totalHeight + 'px'; |
283 this.displaysView_.style.width = '100%'; | |
284 this.displaysView_.style.marginTop = MIRRORING_VERTICAL_MARGIN + 'px'; | |
285 this.displaysView_.style.marginBottom = MIRRORING_VERTICAL_MARGIN + 'px'; | |
286 | |
287 // The displays should be centered. | |
288 var offsetX = | |
289 $('display-options-displays-view').offsetWidth / 2 - totalWidth / 2; | |
290 | |
291 for (var i = 0; i < numDisplays; i++) { | |
246 var div = document.createElement('div'); | 292 var div = document.createElement('div'); |
247 div.className = 'displays-display'; | 293 div.className = 'displays-display'; |
248 div.style.top = i * MIRRORING_OFFSET_PIXELS + 'px'; | 294 div.style.top = i * MIRRORING_OFFSET_PIXELS + 'px'; |
249 div.style.left = i * MIRRORING_OFFSET_PIXELS + 'px'; | 295 div.style.left = i * MIRRORING_OFFSET_PIXELS + offsetX + 'px'; |
250 div.style.width = width + 'px'; | 296 div.style.width = width + 'px'; |
251 div.style.height = height + 'px'; | 297 div.style.height = height + 'px'; |
252 div.style.zIndex = i; | 298 div.style.zIndex = i; |
253 if (i == num_displays - 1) | 299 // set 'display-mirrored' class for the background display rectangles. |
254 div.className += ' displays-primary'; | 300 if (i != numDisplays - 1) |
255 this.displays_view_.appendChild(div); | 301 div.className += ' display-mirrored'; |
302 this.displaysView_.appendChild(div); | |
256 } | 303 } |
257 }, | 304 }, |
258 | 305 |
259 /** | 306 /** |
260 * Layouts the display rectangles according to the current layout_. | 307 * Layouts the display rectangles according to the current layout_. |
261 * @private | 308 * @private |
262 */ | 309 */ |
263 layoutDisplays_: function() { | 310 layoutDisplays_: function() { |
264 var total_size = {width: 0, height: 0}; | 311 var totalHeight = 0; |
265 for (var i = 0; i < this.displays_.length; i++) { | 312 for (var i = 0; i < this.displays_.length; i++) { |
266 total_size.width += this.displays_[i].width * VISUAL_SCALE; | 313 totalHeight += this.displays_[i].height * VISUAL_SCALE; |
267 total_size.height += this.displays_[i].height * VISUAL_SCALE; | |
268 } | 314 } |
269 | 315 |
270 this.displays_view_.style.width = total_size.width + 'px'; | 316 // Prepare enough area for thisplays_view by adding the maximum height. |
271 this.displays_view_.style.height = total_size.height + 'px'; | 317 this.displaysView_.style.width = '100%'; |
James Hawkins
2012/08/06 16:44:43
Use a new CSS class with these properties instead.
Jun Mukai
2012/08/07 00:31:31
Done.
| |
318 this.displaysView_.style.height = totalHeight + 'px'; | |
272 | 319 |
273 var base_point = {x: 0, y: 0}; | 320 var basePoint = {x: 0, y: 0}; |
274 if (this.layout_ == SecondaryDisplayLayout.LEFT) | 321 var boundingSize = {width: 0, height: 0}; |
275 base_point.x = total_size.width; | |
276 else if (this.layout_ == SecondaryDisplayLayout.TOP) | |
277 base_point.y = total_size.height; | |
278 | |
279 for (var i = 0; i < this.displays_.length; i++) { | 322 for (var i = 0; i < this.displays_.length; i++) { |
280 var display = this.displays_[i]; | 323 var display = this.displays_[i]; |
281 var div = document.createElement('div'); | 324 var div = document.createElement('div'); |
282 display.div = div; | 325 display.div = div; |
283 | 326 |
284 div.className = 'displays-display'; | 327 div.className = 'displays-display'; |
285 if (i == 0) | 328 if (i == this.focusedIndex_) |
286 div.className += ' displays-primary'; | |
287 else if (i == this.focused_index_) | |
288 div.className += ' displays-focused'; | 329 div.className += ' displays-focused'; |
289 div.style.width = display.width * VISUAL_SCALE + 'px'; | 330 div.style.width = display.width * VISUAL_SCALE + 'px'; |
290 div.style.height = display.height * VISUAL_SCALE + 'px'; | 331 div.style.height = display.height * VISUAL_SCALE + 'px'; |
291 div.style.lineHeight = div.style.height; | 332 div.style.lineHeight = div.style.height; |
333 if (i == 0) { | |
334 // Assumes that first display is primary and put a grey rectangle to | |
335 // denote launcher below. | |
336 var launcher = document.createElement('div'); | |
337 launcher.id = 'display-launcher'; | |
338 launcher.style.width = display.div.style.width; | |
339 div.appendChild(launcher); | |
340 } | |
292 switch (this.layout_) { | 341 switch (this.layout_) { |
293 case SecondaryDisplayLayout.RIGHT: | 342 case SecondaryDisplayLayout.RIGHT: |
294 display.div.style.top = '0'; | 343 display.div.style.top = '0'; |
295 display.div.style.left = base_point.x + 'px'; | 344 display.div.style.left = basePoint.x + 'px'; |
296 base_point.x += display.width * VISUAL_SCALE; | 345 basePoint.x += display.width * VISUAL_SCALE; |
346 boundingSize.width += display.width * VISUAL_SCALE; | |
347 boundingSize.height = Math.max(boundingSize.height, | |
348 display.height * VISUAL_SCALE); | |
297 break; | 349 break; |
298 case SecondaryDisplayLayout.LEFT: | 350 case SecondaryDisplayLayout.LEFT: |
299 display.div.style.top = '0'; | 351 display.div.style.top = '0'; |
300 base_point.x -= display.width * VISUAL_SCALE; | 352 basePoint.x -= display.width * VISUAL_SCALE; |
301 display.div.style.left = base_point.x + 'px'; | 353 display.div.style.left = basePoint.x + 'px'; |
354 boundingSize.width += display.width * VISUAL_SCALE; | |
355 boundingSize.height = Math.max(boundingSize.height, | |
356 display.height * VISUAL_SCALE); | |
302 break; | 357 break; |
303 case SecondaryDisplayLayout.TOP: | 358 case SecondaryDisplayLayout.TOP: |
304 display.div.style.left = '0'; | 359 display.div.style.left = '0'; |
305 base_point.y -= display.height * VISUAL_SCALE; | 360 basePoint.y -= display.height * VISUAL_SCALE; |
306 display.div.style.top = base_point.y + 'px'; | 361 display.div.style.top = basePoint.y + 'px'; |
362 boundingSize.width = Math.max(boundingSize.width, | |
363 display.width * VISUAL_SCALE); | |
364 boundingSize.height += display.height * VISUAL_SCALE; | |
307 break; | 365 break; |
308 case SecondaryDisplayLayout.BOTTOM: | 366 case SecondaryDisplayLayout.BOTTOM: |
309 display.div.style.left = '0'; | 367 display.div.style.left = '0'; |
310 display.div.style.top = base_point.y + 'px'; | 368 display.div.style.top = basePoint.y + 'px'; |
311 base_point.y += display.height * VISUAL_SCALE; | 369 basePoint.y += display.height * VISUAL_SCALE; |
370 boundingSize.width = Math.max(boundingSize.width, | |
371 display.width * VISUAL_SCALE); | |
372 boundingSize.height += display.height * VISUAL_SCALE; | |
312 break; | 373 break; |
313 } | 374 } |
314 | 375 |
315 this.displays_view_.appendChild(div); | 376 div.appendChild(document.createTextNode(display.name)); |
377 | |
378 this.displaysView_.appendChild(div); | |
379 } | |
380 | |
381 // Centering the display rectangles. | |
382 var offset = {x: $('display-options-displays-view').offsetWidth / 2 - | |
383 boundingSize.width / 2, | |
384 y: totalHeight / 2 - boundingSize.height / 2}; | |
385 if (basePoint.x < 0) | |
386 offset.x -= basePoint.x; | |
387 if (basePoint.y < 0) | |
388 offset.y -= basePoint.y; | |
389 for (var i = 0; i < this.displays_.length; i++) { | |
390 var div = this.displays_[i].div; | |
391 div.style.left = div.offsetLeft + offset.x + 'px'; | |
392 div.style.top = div.offsetTop + offset.y + 'px'; | |
316 } | 393 } |
317 }, | 394 }, |
318 | 395 |
319 /** | 396 /** |
320 * Called when the display arrangement has changed. | 397 * Called when the display arrangement has changed. |
321 * @private | 398 * @private |
322 * @param {boolean} mirroring Whether current mode is mirroring or not. | 399 * @param {boolean} mirroring Whether current mode is mirroring or not. |
323 * @param {Array} displays The list of the display information. | 400 * @param {Array} displays The list of the display information. |
324 * @param {SecondaryDisplayLayout} layout The layout strategy. | 401 * @param {SecondaryDisplayLayout} layout The layout strategy. |
325 */ | 402 */ |
326 onDisplayChanged_: function(mirroring, displays, layout) { | 403 onDisplayChanged_: function(mirroring, displays, layout) { |
327 this.mirroring_ = mirroring; | 404 this.mirroring_ = mirroring; |
328 this.layout_ = layout; | 405 this.layout_ = layout; |
329 | 406 |
330 $('display-options-toggle-mirroring').textContent = | 407 $('display-options-toggle-mirroring').textContent = |
331 loadTimeData.getString( | 408 loadTimeData.getString( |
332 this.mirroring_ ? 'stopMirroring' : 'startMirroring'); | 409 this.mirroring_ ? 'stopMirroring' : 'startMirroring'); |
333 | 410 |
334 // Focus to the first display next to the primary one when |displays| list | 411 // Focus to the first display next to the primary one when |displays| list |
335 // is updated. | 412 // is updated. |
336 if (this.displays_.length != displays.length) | 413 if (this.mirroring_) |
337 this.focused_index_ = 1; | 414 this.focusedIndex_ = null; |
415 else if (this.displays_.length != displays.length) | |
416 this.focusedIndex_ = 1; | |
338 | 417 |
339 this.displays_ = displays; | 418 this.displays_ = displays; |
340 | 419 |
341 this.resetDisplaysView_(); | 420 this.resetDisplaysView_(); |
342 if (this.mirroring_) | 421 if (this.mirroring_) |
343 this.layoutMirroringDisplays_(); | 422 this.layoutMirroringDisplays_(); |
344 else | 423 else |
345 this.layoutDisplays_(); | 424 this.layoutDisplays_(); |
425 this.updateSelectedDisplayDescription_(); | |
346 }, | 426 }, |
347 }; | 427 }; |
348 | 428 |
349 DisplayOptions.setDisplayInfo = function(mirroring, displays, layout) { | 429 DisplayOptions.setDisplayInfo = function(mirroring, displays, layout) { |
350 DisplayOptions.getInstance().onDisplayChanged_(mirroring, displays, layout); | 430 DisplayOptions.getInstance().onDisplayChanged_(mirroring, displays, layout); |
351 }; | 431 }; |
352 | 432 |
353 // Export | 433 // Export |
354 return { | 434 return { |
355 DisplayOptions: DisplayOptions | 435 DisplayOptions: DisplayOptions |
356 }; | 436 }; |
357 }); | 437 }); |
OLD | NEW |