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

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

Issue 10843066: Polish "Displays" Options UI for ChromeOS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: blue -> skyblue Created 8 years, 4 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 | Annotate | Revision Log
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.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 // The margin pixels to calculate the arrow position from left. This happens
James Hawkins 2012/08/03 18:08:23 You use the word 'left' here: does this work in RT
Jun Mukai 2012/08/06 08:07:32 Removed this constant. According to kuscher's com
11 // due to the 'padding' value of $('display-options-displays-view-host').
12 /** @const */ var ARROW_POSITION_MARGIN = 20;
10 13
11 /** 14 /**
12 * Enumeration of secondary display layout. The value has to be same as the 15 * Enumeration of secondary display layout. The value has to be same as the
13 * values in ash/monitor/monitor_controller.cc. 16 * values in ash/monitor/monitor_controller.cc.
14 * @enum {number} 17 * @enum {number}
15 */ 18 */
16 var SecondaryDisplayLayout = { 19 var SecondaryDisplayLayout = {
17 TOP: 0, 20 TOP: 0,
18 RIGHT: 1, 21 RIGHT: 1,
19 BOTTOM: 2, 22 BOTTOM: 2,
(...skipping 17 matching lines...) Expand all
37 40
38 DisplayOptions.prototype = { 41 DisplayOptions.prototype = {
39 __proto__: OptionsPage.prototype, 42 __proto__: OptionsPage.prototype,
40 43
41 /** 44 /**
42 * Initialize the page. 45 * Initialize the page.
43 */ 46 */
44 initializePage: function() { 47 initializePage: function() {
45 OptionsPage.prototype.initializePage.call(this); 48 OptionsPage.prototype.initializePage.call(this);
46 49
47 $('display-options-confirm').onclick = function() {
48 OptionsPage.closeOverlay();
49 };
50
51 $('display-options-toggle-mirroring').onclick = (function() { 50 $('display-options-toggle-mirroring').onclick = (function() {
52 this.mirroring_ = !this.mirroring_; 51 this.mirroring_ = !this.mirroring_;
53 chrome.send('setMirroring', [this.mirroring_]); 52 chrome.send('setMirroring', [this.mirroring_]);
54 }).bind(this); 53 }).bind(this);
55 54
55 $('display-options-apply-button').onclick = (function() {
56 chrome.send('setDisplayLayout', [this.layout_]);
57 }).bind(this);
56 chrome.send('getDisplayInfo'); 58 chrome.send('getDisplayInfo');
57 }, 59 },
58 60
59 /** 61 /**
60 * Mouse move handler for dragging display rectangle. 62 * Mouse move handler for dragging display rectangle.
61 * @private 63 * @private
62 * @param {Event} e The mouse move event. 64 * @param {Event} e The mouse move event.
63 */ 65 */
64 onMouseMove_: function(e) { 66 onMouseMove_: function(e) {
65 if (!this.dragging_) 67 if (!this.dragging_)
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 * @private 161 * @private
160 * @param {Event} e The mouse down event. 162 * @param {Event} e The mouse down event.
161 */ 163 */
162 onMouseDown_: function(e) { 164 onMouseDown_: function(e) {
163 if (this.mirroring_) 165 if (this.mirroring_)
164 return true; 166 return true;
165 167
166 if (e.button != 0) 168 if (e.button != 0)
167 return true; 169 return true;
168 170
169 if (e.target == this.displays_view_) 171 this.focused_index_ = null;
170 return true; 172 for (var i = 0; i < this.displays_.length; i++) {
173 var display = this.displays_[i];
174 if (this.displays_[i].div == e.target) {
175 this.focused_index_ = i;
176 break;
177 } else if (i == 0 && $('display-launcher') == e.target) {
178 this.focused_index_ = i;
James Hawkins 2012/08/03 18:08:23 This is the same functionality as the block above:
Jun Mukai 2012/08/06 08:07:32 Done.
179 break;
180 }
181 }
171 182
172 for (var i = 0; i < this.displays_.length; i++) { 183 for (var i = 0; i < this.displays_.length; i++) {
173 var display = this.displays_[i]; 184 var display = this.displays_[i];
174 if (display.div == e.target) { 185 display.div.className = 'displays-display';
175 // Do not drag the primary monitor. 186 if (i != this.focused_index_)
176 if (i == 0) 187 continue;
177 return true;
178 188
179 this.focused_index_ = i; 189 display.div.className += ' displays-focused';
180 this.dragging_ = { 190 // Do not drag the primary monitor.
191 if (i == 0)
192 continue;
193
194 this.dragging_ = {
181 display: display, 195 display: display,
182 click_location: {x: e.offsetX, y: e.offsetY}, 196 click_location: {x: e.offsetX, y: e.offsetY},
183 offset: {x: e.pageX - e.offsetX - display.div.offsetLeft, 197 offset: {x: e.pageX - e.offsetX - display.div.offsetLeft,
184 y: e.pageY - e.offsetY - display.div.offsetTop} 198 y: e.pageY - e.offsetY - display.div.offsetTop}
185 }; 199 };
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 } 200 }
201 this.updateSelectedDisplayDescription_();
193 return false; 202 return false;
194 }, 203 },
195 204
196 /** 205 /**
197 * Mouse up handler for dragging display rectangle. 206 * Mouse up handler for dragging display rectangle.
198 * @private 207 * @private
199 * @param {Event} e The mouse up event. 208 * @param {Event} e The mouse up event.
200 */ 209 */
201 onMouseUp_: function(e) { 210 onMouseUp_: function(e) {
202 if (this.dragging_) { 211 if (this.dragging_)
203 this.dragging_ = null; 212 this.dragging_ = null;
204 chrome.send('setDisplayLayout', [this.layout_]); 213 this.updateSelectedDisplayDescription_();
214 return false;
215 },
216
217 /**
218 * Update the description of the selected display section.
James Hawkins 2012/08/03 18:08:23 s/Update/Updates.
Jun Mukai 2012/08/06 08:07:32 Done.
219 * @private
220 */
221 updateSelectedDisplayDescription_: function() {
222 if (this.focused_index_ == null) {
223 $('selected-display-data-container').hidden = true;
224 $('display-configuration-arrow').hidden = true;
225 return;
205 } 226 }
206 return false; 227
228 $('selected-display-data-container').hidden = false;
229 var display = this.displays_[this.focused_index_];
230 var name_element = $('selected-display-name');
James Hawkins 2012/08/03 18:08:23 s/name_element/nameElement/ javaScript case here
Jun Mukai 2012/08/06 08:07:32 Sorry breaking such a basic rule. I reviewed the
231 while (name_element.childNodes.length > 0)
232 name_element.removeChild(name_element.firstChild);
233 name_element.appendChild(document.createTextNode(display.name));
234
235 var resolution_data = display.width + 'x' + display.height;
236 var resolution_element = $('selected-display-resolution');
237 while (resolution_element.childNodes.length > 0)
238 resolution_element.removeChild(resolution_element.firstChild);
239 resolution_element.appendChild(document.createTextNode(resolution_data));
240
241 var arrow = $('display-configuration-arrow');
242 arrow.hidden = false;
243 arrow.style.top =
244 $('display-configurations').offsetTop - arrow.offsetHeight / 2 + 'px';
245 arrow.style.left = display.div.offsetLeft + display.div.offsetWidth / 2 +
James Hawkins 2012/08/03 18:08:23 RTL
Jun Mukai 2012/08/06 08:07:32 Removed ARROW_POSITION_MARGIN and working fine now
246 ARROW_POSITION_MARGIN - arrow.offsetWidth / 2 + 'px';
207 }, 247 },
208 248
209 /** 249 /**
210 * Clears the drawing area for display rectangles. 250 * Clears the drawing area for display rectangles.
211 * @private 251 * @private
212 */ 252 */
213 resetDisplaysView_: function() { 253 resetDisplaysView_: function() {
214 var displays_view_host = $('display-options-displays-view-host'); 254 var displays_view_host = $('display-options-displays-view-host');
215 displays_view_host.removeChild(displays_view_host.firstChild); 255 displays_view_host.removeChild(displays_view_host.firstChild);
216 this.displays_view_ = document.createElement('div'); 256 this.displays_view_ = document.createElement('div');
(...skipping 26 matching lines...) Expand all
243 height + num_displays * MIRRORING_OFFSET_PIXELS + 'px'; 283 height + num_displays * MIRRORING_OFFSET_PIXELS + 'px';
244 284
245 for (var i = 0; i < num_displays; i++) { 285 for (var i = 0; i < num_displays; i++) {
246 var div = document.createElement('div'); 286 var div = document.createElement('div');
247 div.className = 'displays-display'; 287 div.className = 'displays-display';
248 div.style.top = i * MIRRORING_OFFSET_PIXELS + 'px'; 288 div.style.top = i * MIRRORING_OFFSET_PIXELS + 'px';
249 div.style.left = i * MIRRORING_OFFSET_PIXELS + 'px'; 289 div.style.left = i * MIRRORING_OFFSET_PIXELS + 'px';
250 div.style.width = width + 'px'; 290 div.style.width = width + 'px';
251 div.style.height = height + 'px'; 291 div.style.height = height + 'px';
252 div.style.zIndex = i; 292 div.style.zIndex = i;
253 if (i == num_displays - 1) 293 // set 'display-mirrored' class for the background display rectangles.
254 div.className += ' displays-primary'; 294 if (i != num_displays - 1)
295 div.className += ' display-mirrored';
255 this.displays_view_.appendChild(div); 296 this.displays_view_.appendChild(div);
256 } 297 }
257 }, 298 },
258 299
259 /** 300 /**
260 * Layouts the display rectangles according to the current layout_. 301 * Layouts the display rectangles according to the current layout_.
261 * @private 302 * @private
262 */ 303 */
263 layoutDisplays_: function() { 304 layoutDisplays_: function() {
264 var total_size = {width: 0, height: 0}; 305 var total_size = {width: 0, height: 0};
(...skipping 10 matching lines...) Expand all
275 base_point.x = total_size.width; 316 base_point.x = total_size.width;
276 else if (this.layout_ == SecondaryDisplayLayout.TOP) 317 else if (this.layout_ == SecondaryDisplayLayout.TOP)
277 base_point.y = total_size.height; 318 base_point.y = total_size.height;
278 319
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.focused_index_)
286 div.className += ' displays-primary';
287 else if (i == this.focused_index_)
288 div.className += ' displays-focused'; 327 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 // We assume that first display is primary and put a grey rectangle to
James Hawkins 2012/08/03 18:08:23 nit: Don't use pronouns (we) in comments; pronouns
Jun Mukai 2012/08/06 08:07:32 Done.
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 = base_point.x + 'px';
296 base_point.x += display.width * VISUAL_SCALE; 343 base_point.x += display.width * VISUAL_SCALE;
297 break; 344 break;
298 case SecondaryDisplayLayout.LEFT: 345 case SecondaryDisplayLayout.LEFT:
299 display.div.style.top = '0'; 346 display.div.style.top = '0';
300 base_point.x -= display.width * VISUAL_SCALE; 347 base_point.x -= display.width * VISUAL_SCALE;
301 display.div.style.left = base_point.x + 'px'; 348 display.div.style.left = base_point.x + 'px';
302 break; 349 break;
303 case SecondaryDisplayLayout.TOP: 350 case SecondaryDisplayLayout.TOP:
304 display.div.style.left = '0'; 351 display.div.style.left = '0';
305 base_point.y -= display.height * VISUAL_SCALE; 352 base_point.y -= display.height * VISUAL_SCALE;
306 display.div.style.top = base_point.y + 'px'; 353 display.div.style.top = base_point.y + 'px';
307 break; 354 break;
308 case SecondaryDisplayLayout.BOTTOM: 355 case SecondaryDisplayLayout.BOTTOM:
309 display.div.style.left = '0'; 356 display.div.style.left = '0';
310 display.div.style.top = base_point.y + 'px'; 357 display.div.style.top = base_point.y + 'px';
311 base_point.y += display.height * VISUAL_SCALE; 358 base_point.y += display.height * VISUAL_SCALE;
312 break; 359 break;
313 } 360 }
314 361
362 div.appendChild(document.createTextNode(display.name));
363
315 this.displays_view_.appendChild(div); 364 this.displays_view_.appendChild(div);
316 } 365 }
317 }, 366 },
318 367
319 /** 368 /**
320 * Called when the display arrangement has changed. 369 * Called when the display arrangement has changed.
321 * @private 370 * @private
322 * @param {boolean} mirroring Whether current mode is mirroring or not. 371 * @param {boolean} mirroring Whether current mode is mirroring or not.
323 * @param {Array} displays The list of the display information. 372 * @param {Array} displays The list of the display information.
324 * @param {SecondaryDisplayLayout} layout The layout strategy. 373 * @param {SecondaryDisplayLayout} layout The layout strategy.
325 */ 374 */
326 onDisplayChanged_: function(mirroring, displays, layout) { 375 onDisplayChanged_: function(mirroring, displays, layout) {
327 this.mirroring_ = mirroring; 376 this.mirroring_ = mirroring;
328 this.layout_ = layout; 377 this.layout_ = layout;
329 378
330 $('display-options-toggle-mirroring').textContent = 379 $('display-options-toggle-mirroring').textContent =
331 loadTimeData.getString( 380 loadTimeData.getString(
332 this.mirroring_ ? 'stopMirroring' : 'startMirroring'); 381 this.mirroring_ ? 'stopMirroring' : 'startMirroring');
333 382
334 // Focus to the first display next to the primary one when |displays| list 383 // Focus to the first display next to the primary one when |displays| list
335 // is updated. 384 // is updated.
336 if (this.displays_.length != displays.length) 385 if (this.mirroring_)
386 this.focused_index_ = null;
387 else if (this.displays_.length != displays.length)
337 this.focused_index_ = 1; 388 this.focused_index_ = 1;
338 389
339 this.displays_ = displays; 390 this.displays_ = displays;
340 391
341 this.resetDisplaysView_(); 392 this.resetDisplaysView_();
342 if (this.mirroring_) 393 if (this.mirroring_)
343 this.layoutMirroringDisplays_(); 394 this.layoutMirroringDisplays_();
344 else 395 else
345 this.layoutDisplays_(); 396 this.layoutDisplays_();
397 this.updateSelectedDisplayDescription_();
346 }, 398 },
347 }; 399 };
348 400
349 DisplayOptions.setDisplayInfo = function(mirroring, displays, layout) { 401 DisplayOptions.setDisplayInfo = function(mirroring, displays, layout) {
350 DisplayOptions.getInstance().onDisplayChanged_(mirroring, displays, layout); 402 DisplayOptions.getInstance().onDisplayChanged_(mirroring, displays, layout);
351 }; 403 };
352 404
353 // Export 405 // Export
354 return { 406 return {
355 DisplayOptions: DisplayOptions 407 DisplayOptions: DisplayOptions
356 }; 408 };
357 }); 409 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698