| 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.classList.add('displays-focused'); |
| 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_.classList.add( |
| 284 'display-options-displays-view-mirroring'); |
| 285 |
| 286 // The displays should be centered. |
| 287 var offsetX = |
| 288 $('display-options-displays-view').offsetWidth / 2 - totalWidth / 2; |
| 289 |
| 290 for (var i = 0; i < numDisplays; i++) { |
| 246 var div = document.createElement('div'); | 291 var div = document.createElement('div'); |
| 247 div.className = 'displays-display'; | 292 div.className = 'displays-display'; |
| 248 div.style.top = i * MIRRORING_OFFSET_PIXELS + 'px'; | 293 div.style.top = i * MIRRORING_OFFSET_PIXELS + 'px'; |
| 249 div.style.left = i * MIRRORING_OFFSET_PIXELS + 'px'; | 294 div.style.left = i * MIRRORING_OFFSET_PIXELS + offsetX + 'px'; |
| 250 div.style.width = width + 'px'; | 295 div.style.width = width + 'px'; |
| 251 div.style.height = height + 'px'; | 296 div.style.height = height + 'px'; |
| 252 div.style.zIndex = i; | 297 div.style.zIndex = i; |
| 253 if (i == num_displays - 1) | 298 // set 'display-mirrored' class for the background display rectangles. |
| 254 div.className += ' displays-primary'; | 299 if (i != numDisplays - 1) |
| 255 this.displays_view_.appendChild(div); | 300 div.classList.add('display-mirrored'); |
| 301 this.displaysView_.appendChild(div); |
| 256 } | 302 } |
| 257 }, | 303 }, |
| 258 | 304 |
| 259 /** | 305 /** |
| 260 * Layouts the display rectangles according to the current layout_. | 306 * Layouts the display rectangles according to the current layout_. |
| 261 * @private | 307 * @private |
| 262 */ | 308 */ |
| 263 layoutDisplays_: function() { | 309 layoutDisplays_: function() { |
| 264 var total_size = {width: 0, height: 0}; | 310 var totalHeight = 0; |
| 265 for (var i = 0; i < this.displays_.length; i++) { | 311 for (var i = 0; i < this.displays_.length; i++) { |
| 266 total_size.width += this.displays_[i].width * VISUAL_SCALE; | 312 totalHeight += this.displays_[i].height * VISUAL_SCALE; |
| 267 total_size.height += this.displays_[i].height * VISUAL_SCALE; | |
| 268 } | 313 } |
| 269 | 314 |
| 270 this.displays_view_.style.width = total_size.width + 'px'; | 315 // Prepare enough area for thisplays_view by adding the maximum height. |
| 271 this.displays_view_.style.height = total_size.height + 'px'; | 316 this.displaysView_.style.height = totalHeight + 'px'; |
| 272 | 317 |
| 273 var base_point = {x: 0, y: 0}; | 318 var basePoint = {x: 0, y: 0}; |
| 274 if (this.layout_ == SecondaryDisplayLayout.LEFT) | 319 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++) { | 320 for (var i = 0; i < this.displays_.length; i++) { |
| 280 var display = this.displays_[i]; | 321 var display = this.displays_[i]; |
| 281 var div = document.createElement('div'); | 322 var div = document.createElement('div'); |
| 282 display.div = div; | 323 display.div = div; |
| 283 | 324 |
| 284 div.className = 'displays-display'; | 325 div.className = 'displays-display'; |
| 285 if (i == 0) | 326 if (i == this.focusedIndex_) |
| 286 div.className += ' displays-primary'; | 327 div.classList.add('displays-focused'); |
| 287 else if (i == this.focused_index_) | |
| 288 div.className += ' displays-focused'; | |
| 289 div.style.width = display.width * VISUAL_SCALE + 'px'; | 328 div.style.width = display.width * VISUAL_SCALE + 'px'; |
| 290 div.style.height = display.height * VISUAL_SCALE + 'px'; | 329 div.style.height = display.height * VISUAL_SCALE + 'px'; |
| 291 div.style.lineHeight = div.style.height; | 330 div.style.lineHeight = div.style.height; |
| 331 if (i == 0) { |
| 332 // Assumes that first display is primary and put a grey rectangle to |
| 333 // denote launcher below. |
| 334 var launcher = document.createElement('div'); |
| 335 launcher.id = 'display-launcher'; |
| 336 launcher.style.width = display.div.style.width; |
| 337 div.appendChild(launcher); |
| 338 } |
| 292 switch (this.layout_) { | 339 switch (this.layout_) { |
| 293 case SecondaryDisplayLayout.RIGHT: | 340 case SecondaryDisplayLayout.RIGHT: |
| 294 display.div.style.top = '0'; | 341 display.div.style.top = '0'; |
| 295 display.div.style.left = base_point.x + 'px'; | 342 display.div.style.left = basePoint.x + 'px'; |
| 296 base_point.x += display.width * VISUAL_SCALE; | 343 basePoint.x += display.width * VISUAL_SCALE; |
| 344 boundingSize.width += display.width * VISUAL_SCALE; |
| 345 boundingSize.height = Math.max(boundingSize.height, |
| 346 display.height * VISUAL_SCALE); |
| 297 break; | 347 break; |
| 298 case SecondaryDisplayLayout.LEFT: | 348 case SecondaryDisplayLayout.LEFT: |
| 299 display.div.style.top = '0'; | 349 display.div.style.top = '0'; |
| 300 base_point.x -= display.width * VISUAL_SCALE; | 350 basePoint.x -= display.width * VISUAL_SCALE; |
| 301 display.div.style.left = base_point.x + 'px'; | 351 display.div.style.left = basePoint.x + 'px'; |
| 352 boundingSize.width += display.width * VISUAL_SCALE; |
| 353 boundingSize.height = Math.max(boundingSize.height, |
| 354 display.height * VISUAL_SCALE); |
| 302 break; | 355 break; |
| 303 case SecondaryDisplayLayout.TOP: | 356 case SecondaryDisplayLayout.TOP: |
| 304 display.div.style.left = '0'; | 357 display.div.style.left = '0'; |
| 305 base_point.y -= display.height * VISUAL_SCALE; | 358 basePoint.y -= display.height * VISUAL_SCALE; |
| 306 display.div.style.top = base_point.y + 'px'; | 359 display.div.style.top = basePoint.y + 'px'; |
| 360 boundingSize.width = Math.max(boundingSize.width, |
| 361 display.width * VISUAL_SCALE); |
| 362 boundingSize.height += display.height * VISUAL_SCALE; |
| 307 break; | 363 break; |
| 308 case SecondaryDisplayLayout.BOTTOM: | 364 case SecondaryDisplayLayout.BOTTOM: |
| 309 display.div.style.left = '0'; | 365 display.div.style.left = '0'; |
| 310 display.div.style.top = base_point.y + 'px'; | 366 display.div.style.top = basePoint.y + 'px'; |
| 311 base_point.y += display.height * VISUAL_SCALE; | 367 basePoint.y += display.height * VISUAL_SCALE; |
| 368 boundingSize.width = Math.max(boundingSize.width, |
| 369 display.width * VISUAL_SCALE); |
| 370 boundingSize.height += display.height * VISUAL_SCALE; |
| 312 break; | 371 break; |
| 313 } | 372 } |
| 314 | 373 |
| 315 this.displays_view_.appendChild(div); | 374 div.appendChild(document.createTextNode(display.name)); |
| 375 |
| 376 this.displaysView_.appendChild(div); |
| 377 } |
| 378 |
| 379 // Centering the display rectangles. |
| 380 var offset = {x: $('display-options-displays-view').offsetWidth / 2 - |
| 381 boundingSize.width / 2, |
| 382 y: totalHeight / 2 - boundingSize.height / 2}; |
| 383 if (basePoint.x < 0) |
| 384 offset.x -= basePoint.x; |
| 385 if (basePoint.y < 0) |
| 386 offset.y -= basePoint.y; |
| 387 for (var i = 0; i < this.displays_.length; i++) { |
| 388 var div = this.displays_[i].div; |
| 389 div.style.left = div.offsetLeft + offset.x + 'px'; |
| 390 div.style.top = div.offsetTop + offset.y + 'px'; |
| 316 } | 391 } |
| 317 }, | 392 }, |
| 318 | 393 |
| 319 /** | 394 /** |
| 320 * Called when the display arrangement has changed. | 395 * Called when the display arrangement has changed. |
| 321 * @private | 396 * @private |
| 322 * @param {boolean} mirroring Whether current mode is mirroring or not. | 397 * @param {boolean} mirroring Whether current mode is mirroring or not. |
| 323 * @param {Array} displays The list of the display information. | 398 * @param {Array} displays The list of the display information. |
| 324 * @param {SecondaryDisplayLayout} layout The layout strategy. | 399 * @param {SecondaryDisplayLayout} layout The layout strategy. |
| 325 */ | 400 */ |
| 326 onDisplayChanged_: function(mirroring, displays, layout) { | 401 onDisplayChanged_: function(mirroring, displays, layout) { |
| 327 this.mirroring_ = mirroring; | 402 this.mirroring_ = mirroring; |
| 328 this.layout_ = layout; | 403 this.layout_ = layout; |
| 329 | 404 |
| 330 $('display-options-toggle-mirroring').textContent = | 405 $('display-options-toggle-mirroring').textContent = |
| 331 loadTimeData.getString( | 406 loadTimeData.getString( |
| 332 this.mirroring_ ? 'stopMirroring' : 'startMirroring'); | 407 this.mirroring_ ? 'stopMirroring' : 'startMirroring'); |
| 333 | 408 |
| 334 // Focus to the first display next to the primary one when |displays| list | 409 // Focus to the first display next to the primary one when |displays| list |
| 335 // is updated. | 410 // is updated. |
| 336 if (this.displays_.length != displays.length) | 411 if (this.mirroring_) |
| 337 this.focused_index_ = 1; | 412 this.focusedIndex_ = null; |
| 413 else if (this.displays_.length != displays.length) |
| 414 this.focusedIndex_ = 1; |
| 338 | 415 |
| 339 this.displays_ = displays; | 416 this.displays_ = displays; |
| 340 | 417 |
| 341 this.resetDisplaysView_(); | 418 this.resetDisplaysView_(); |
| 342 if (this.mirroring_) | 419 if (this.mirroring_) |
| 343 this.layoutMirroringDisplays_(); | 420 this.layoutMirroringDisplays_(); |
| 344 else | 421 else |
| 345 this.layoutDisplays_(); | 422 this.layoutDisplays_(); |
| 423 this.updateSelectedDisplayDescription_(); |
| 346 }, | 424 }, |
| 347 }; | 425 }; |
| 348 | 426 |
| 349 DisplayOptions.setDisplayInfo = function(mirroring, displays, layout) { | 427 DisplayOptions.setDisplayInfo = function(mirroring, displays, layout) { |
| 350 DisplayOptions.getInstance().onDisplayChanged_(mirroring, displays, layout); | 428 DisplayOptions.getInstance().onDisplayChanged_(mirroring, displays, layout); |
| 351 }; | 429 }; |
| 352 | 430 |
| 353 // Export | 431 // Export |
| 354 return { | 432 return { |
| 355 DisplayOptions: DisplayOptions | 433 DisplayOptions: DisplayOptions |
| 356 }; | 434 }; |
| 357 }); | 435 }); |
| OLD | NEW |