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

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

Issue 1648493002: Rely less on DisplayInfo in display_options.js (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Feedback Created 4 years, 10 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 | « chrome/browser/resources/options/chromeos/display_layout_manager.js ('k') | 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 multi display mode. These values must match the C++ values in 8 * Enumeration of multi display mode. These values must match the C++ values in
9 * ash::DisplayManager. 9 * ash::DisplayManager.
10 * @enum {number} 10 * @enum {number}
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 var container = $('display-options-displays-view-host'); 199 var container = $('display-options-displays-view-host');
200 container.onmousemove = this.onMouseMove_.bind(this); 200 container.onmousemove = this.onMouseMove_.bind(this);
201 window.addEventListener('mouseup', this.endDragging_.bind(this), true); 201 window.addEventListener('mouseup', this.endDragging_.bind(this), true);
202 container.ontouchmove = this.onTouchMove_.bind(this); 202 container.ontouchmove = this.onTouchMove_.bind(this);
203 container.ontouchend = this.endDragging_.bind(this); 203 container.ontouchend = this.endDragging_.bind(this);
204 204
205 $('display-options-set-primary').onclick = (function() { 205 $('display-options-set-primary').onclick = (function() {
206 chrome.send('setPrimary', [this.focusedId_]); 206 chrome.send('setPrimary', [this.focusedId_]);
207 }).bind(this); 207 }).bind(this);
208 $('display-options-resolution-selection').onchange = (function(ev) { 208 $('display-options-resolution-selection').onchange = (function(ev) {
209 var display = this.getDisplayInfoFromId(this.focusedId_); 209 var display = this.getDisplayInfoFromId_(this.focusedId_);
210 if (!display)
211 return;
210 var resolution = display.resolutions[ev.target.value]; 212 var resolution = display.resolutions[ev.target.value];
211 chrome.send('setDisplayMode', [this.focusedId_, resolution]); 213 chrome.send('setDisplayMode', [this.focusedId_, resolution]);
212 }).bind(this); 214 }).bind(this);
213 $('display-options-orientation-selection').onchange = (function(ev) { 215 $('display-options-orientation-selection').onchange = (function(ev) {
214 var rotation = parseInt(ev.target.value, 10); 216 var rotation = parseInt(ev.target.value, 10);
215 chrome.send('setRotation', [this.focusedId_, rotation]); 217 chrome.send('setRotation', [this.focusedId_, rotation]);
216 }).bind(this); 218 }).bind(this);
217 $('display-options-color-profile-selection').onchange = (function(ev) { 219 $('display-options-color-profile-selection').onchange = (function(ev) {
218 chrome.send('setColorProfile', [this.focusedId_, ev.target.value]); 220 chrome.send('setColorProfile', [this.focusedId_, ev.target.value]);
219 }).bind(this); 221 }).bind(this);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 var touch = e.touches[0]; 341 var touch = e.touches[0];
340 this.lastTouchLocation_ = {x: touch.pageX, y: touch.pageY}; 342 this.lastTouchLocation_ = {x: touch.pageX, y: touch.pageY};
341 var target = assertInstanceof(e.target, HTMLElement); 343 var target = assertInstanceof(e.target, HTMLElement);
342 return this.startDragging_(target, this.lastTouchLocation_); 344 return this.startDragging_(target, this.lastTouchLocation_);
343 }, 345 },
344 346
345 /** 347 /**
346 * @param {string} id 348 * @param {string} id
347 * @return {options.DisplayInfo} 349 * @return {options.DisplayInfo}
348 */ 350 */
349 getDisplayInfoFromId(id) { 351 getDisplayInfoFromId_(id) {
350 return this.displays_.find(function(display) { 352 return this.displays_.find(function(display) {
351 return display.id == id; 353 return display.id == id;
352 }); 354 });
353 }, 355 },
354 356
355 /** 357 /**
356 * Sends the display layout for the secondary display to Chrome. 358 * Sends the display layout for the secondary display to Chrome.
357 * @private 359 * @private
358 */ 360 */
359 sendDragResult_: function() { 361 sendDragResult_: function() {
(...skipping 29 matching lines...) Expand all
389 var dragInfo = this.dragInfo_; 391 var dragInfo = this.dragInfo_;
390 392
391 /** @type {options.DisplayPosition} */ var newPosition = { 393 /** @type {options.DisplayPosition} */ var newPosition = {
392 x: dragInfo.originalLocation.x + 394 x: dragInfo.originalLocation.x +
393 (eventLocation.x - dragInfo.eventLocation.x), 395 (eventLocation.x - dragInfo.eventLocation.x),
394 y: dragInfo.originalLocation.y + 396 y: dragInfo.originalLocation.y +
395 (eventLocation.y - dragInfo.eventLocation.y) 397 (eventLocation.y - dragInfo.eventLocation.y)
396 }; 398 };
397 399
398 this.displayLayoutManager_.updatePosition( 400 this.displayLayoutManager_.updatePosition(
399 this.dragInfo_.displayId, newPosition); 401 dragInfo.displayId, newPosition);
400 402
401 return false; 403 return false;
402 }, 404 },
403 405
404 /** 406 /**
405 * Start dragging of a display rectangle. 407 * Start dragging of a display rectangle.
406 * @param {!HTMLElement} target The event target. 408 * @param {!HTMLElement} target The event target.
407 * @param {!options.DisplayPosition} eventLocation The event location. 409 * @param {!options.DisplayPosition} eventLocation The event location.
408 * @private 410 * @private
409 */ 411 */
410 startDragging_: function(target, eventLocation) { 412 startDragging_: function(target, eventLocation) {
411 var oldFocusedId = this.focusedId_; 413 var focused = this.displayLayoutManager_.getFocusedLayoutForDiv(target);
412 var newFocusedId; 414 if (!focused)
413 var willUpdateDisplayDescription = false;
414 for (var i = 0; i < this.displays_.length; i++) {
415 var displayLayout =
416 this.displayLayoutManager_.getDisplayLayout(this.displays_[i].id);
417 if (displayLayout.div == target ||
418 (target.offsetParent && target.offsetParent == displayLayout.div)) {
419 newFocusedId = displayLayout.id;
420 break;
421 }
422 }
423 if (!newFocusedId)
424 return false; 415 return false;
425 416
426 this.focusedId_ = newFocusedId; 417 var updateDisplayDescription = focused.id != this.focusedId_;
427 willUpdateDisplayDescription = newFocusedId != oldFocusedId; 418 this.focusedId_ = focused.id;
419 this.displayLayoutManager_.setFocusedId(focused.id);
428 420
429 for (var i = 0; i < this.displays_.length; i++) { 421 if (this.displayLayoutManager_.getDisplayLayoutCount() > 1) {
430 var displayLayout = 422 this.dragInfo_ = {
431 this.displayLayoutManager_.getDisplayLayout(this.displays_[i].id); 423 displayId: focused.id,
432 displayLayout.div.className = 'displays-display'; 424 originalLocation: {
433 if (displayLayout.id != this.focusedId_) 425 x: focused.div.offsetLeft,
434 continue; 426 y: focused.div.offsetTop
435 427 },
436 displayLayout.div.classList.add('displays-focused'); 428 eventLocation: {x: eventLocation.x, y: eventLocation.y}
437 if (this.displays_.length > 1) { 429 };
438 this.dragInfo_ = {
439 displayId: displayLayout.id,
440 originalLocation: {
441 x: displayLayout.div.offsetLeft,
442 y: displayLayout.div.offsetTop
443 },
444 eventLocation: {x: eventLocation.x, y: eventLocation.y}
445 };
446 }
447 } 430 }
448 431
449 if (willUpdateDisplayDescription) 432 if (updateDisplayDescription)
450 this.updateSelectedDisplayDescription_(); 433 this.updateSelectedDisplayDescription_();
434
451 return false; 435 return false;
452 }, 436 },
453 437
454 /** 438 /**
455 * finish the current dragging of displays. 439 * finish the current dragging of displays.
456 * @param {Event} e The event which triggers this. 440 * @param {Event} e The event which triggers this.
457 * @private 441 * @private
458 */ 442 */
459 endDragging_: function(e) { 443 endDragging_: function(e) {
460 this.lastTouchLocation_ = null; 444 this.lastTouchLocation_ = null;
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 var orientation = $('display-options-orientation-selection'); 589 var orientation = $('display-options-orientation-selection');
606 var orientationOptions = orientation.getElementsByTagName('option'); 590 var orientationOptions = orientation.getElementsByTagName('option');
607 for (var i = 0; i < orientationOptions.length; i++) 591 for (var i = 0; i < orientationOptions.length; i++)
608 orientationOptions[i].selected = false; 592 orientationOptions[i].selected = false;
609 593
610 if (this.mirroring_) { 594 if (this.mirroring_) {
611 this.updateSelectedDisplaySectionMirroring_(); 595 this.updateSelectedDisplaySectionMirroring_();
612 } else if (this.focusedId_ == '') { 596 } else if (this.focusedId_ == '') {
613 this.updateSelectedDisplaySectionNoSelected_(); 597 this.updateSelectedDisplaySectionNoSelected_();
614 } else { 598 } else {
615 this.updateSelectedDisplaySectionForDisplay_( 599 var focusedDisplay = this.getDisplayInfoFromId_(this.focusedId_);
616 this.getDisplayInfoFromId(this.focusedId_)); 600 if (focusedDisplay)
601 this.updateSelectedDisplaySectionForDisplay_(focusedDisplay);
617 } 602 }
618 }, 603 },
619 604
620 /** 605 /**
621 * Clears the drawing area for display rectangles. 606 * Clears the drawing area for display rectangles.
622 * @private 607 * @private
623 */ 608 */
624 resetDisplaysView_: function() { 609 resetDisplaysView_: function() {
625 var displaysViewHost = $('display-options-displays-view-host'); 610 var displaysViewHost = $('display-options-displays-view-host');
626 displaysViewHost.removeChild(displaysViewHost.firstChild); 611 displaysViewHost.removeChild(displaysViewHost.firstChild);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 parentId: parentId 679 parentId: parentId
695 }; 680 };
696 }, 681 },
697 682
698 /** 683 /**
699 * Layouts the display rectangles according to the current layout_. 684 * Layouts the display rectangles according to the current layout_.
700 * @param {options.DisplayLayoutType} layoutType 685 * @param {options.DisplayLayoutType} layoutType
701 * @private 686 * @private
702 */ 687 */
703 layoutDisplays_: function(layoutType) { 688 layoutDisplays_: function(layoutType) {
704 var maxWidth = 0; 689 // Create the layout manager.
705 var maxHeight = 0; 690 this.displayLayoutManager_ = new options.DisplayLayoutManager();
706 var boundingBox = {left: 0, right: 0, top: 0, bottom: 0}; 691
692 // Create the display layouts. Child displays are parented to the primary.
693 // TODO(stevenjb): DisplayInfo should provide the parent id for displays.
707 var primaryDisplayId = ''; 694 var primaryDisplayId = '';
708 for (var i = 0; i < this.displays_.length; i++) { 695 for (var i = 0; i < this.displays_.length; i++) {
709 var display = this.displays_[i]; 696 var display = this.displays_[i];
710 if (display.isPrimary && primaryDisplayId == '') 697 if (display.isPrimary) {
711 primaryDisplayId = display.id; 698 primaryDisplayId = display.id;
712 699 break;
713 var bounds = display.bounds; 700 }
714 boundingBox.left = Math.min(boundingBox.left, bounds.left);
715 boundingBox.right =
716 Math.max(boundingBox.right, bounds.left + bounds.width);
717 boundingBox.top = Math.min(boundingBox.top, bounds.top);
718 boundingBox.bottom =
719 Math.max(boundingBox.bottom, bounds.top + bounds.height);
720 maxWidth = Math.max(maxWidth, bounds.width);
721 maxHeight = Math.max(maxHeight, bounds.height);
722 } 701 }
723 if (primaryDisplayId == '')
724 return;
725
726 // Make the margin around the bounding box.
727 var areaWidth = boundingBox.right - boundingBox.left + maxWidth;
728 var areaHeight = boundingBox.bottom - boundingBox.top + maxHeight;
729
730 // Calculates the scale by the width since horizontal size is more strict.
731 // TODO(mukai): Adds the check of vertical size in case.
732 this.visualScale_ = Math.min(
733 VISUAL_SCALE, this.displaysView_.offsetWidth / areaWidth);
734
735 // Prepare enough area for thisplays_view by adding the maximum height.
736 this.displaysView_.style.height =
737 Math.ceil(areaHeight * this.visualScale_) + 'px';
738
739 // Centering the bounding box of the display rectangles.
740 var offset = {
741 x: Math.floor(
742 this.displaysView_.offsetWidth / 2 -
743 (boundingBox.right + boundingBox.left) * this.visualScale_ / 2),
744 y: Math.floor(
745 this.displaysView_.offsetHeight / 2 -
746 (boundingBox.bottom + boundingBox.top) * this.visualScale_ / 2)
747 };
748
749 // Create the layout manager.
750 this.displayLayoutManager_ =
751 new options.DisplayLayoutManager(this.visualScale_);
752
753 // Create the display layouts.
754 for (var i = 0; i < this.displays_.length; i++) { 702 for (var i = 0; i < this.displays_.length; i++) {
755 var display = this.displays_[i]; 703 var display = this.displays_[i];
756 var parentId = display.isPrimary ? '' : primaryDisplayId; 704 var parentId = display.isPrimary ? '' : primaryDisplayId;
757 var layout = this.createDisplayLayout_(display, layoutType, parentId); 705 var layout = this.createDisplayLayout_(display, layoutType, parentId);
758 this.displayLayoutManager_.addDisplayLayout(layout); 706 this.displayLayoutManager_.addDisplayLayout(layout);
759 } 707 }
760 708
761 // Create the display divs. 709 // Calculate the display area bounds and create the divs for each display.
762 this.displayLayoutManager_.createDisplayLayoutDivs( 710 this.visualScale_ = this.displayLayoutManager_.createDisplayArea(
763 this.displaysView_, offset); 711 /** @type {!Element} */(this.displaysView_), VISUAL_SCALE);
764 712
765 // Set the div callbacks and highlight the focused div. 713 this.displayLayoutManager_.setFocusedId(this.focusedId_);
766 for (var i = 0; i < this.displays_.length; i++) { 714 this.displayLayoutManager_.setDivCallbacks(
767 var id = this.displays_[i].id; 715 this.onMouseDown_.bind(this), this.onTouchStart_.bind(this));
768 var div = this.displayLayoutManager_.getDisplayLayout(id).div;
769 div.onmousedown = this.onMouseDown_.bind(this);
770 div.ontouchstart = this.onTouchStart_.bind(this);
771 div.classList.toggle('displays-focused', id == this.focusedId_);
772 }
773 }, 716 },
774 717
775 /** 718 /**
776 * Called when the display arrangement has changed. 719 * Called when the display arrangement has changed.
777 * @param {options.MultiDisplayMode} mode multi display mode. 720 * @param {options.MultiDisplayMode} mode multi display mode.
778 * @param {!Array<!options.DisplayInfo>} displays The list of the display 721 * @param {!Array<!options.DisplayInfo>} displays The list of the display
779 * information. 722 * information.
780 * @param {options.DisplayLayoutType} layoutType The layout type for the 723 * @param {options.DisplayLayoutType} layoutType The layout type for the
781 * secondary display. 724 * secondary display.
782 * @param {number} offset The offset of the secondary display. 725 * @param {number} offset The offset of the secondary display.
783 * @private 726 * @private
784 */ 727 */
785 onDisplayChanged_: function(mode, displays, layoutType, offset) { 728 onDisplayChanged_: function(mode, displays, layoutType, offset) {
786 if (!this.visible) 729 if (!this.visible)
787 return; 730 return;
788 731
789 this.displays_ = displays;
790
791 var mirroring = mode == options.MultiDisplayMode.MIRRORING; 732 var mirroring = mode == options.MultiDisplayMode.MIRRORING;
792 var unifiedDesktopEnabled = mode == options.MultiDisplayMode.UNIFIED; 733 var unifiedDesktopEnabled = mode == options.MultiDisplayMode.UNIFIED;
793 734
794 // Focus to the first display next to the primary one when |displays_| 735 // Focus to the first display next to the primary one when |displays_|
795 // is updated. 736 // is updated.
796 if (mirroring) { 737 if (mirroring) {
797 this.focusedId_ = ''; 738 this.focusedId_ = '';
798 } else if ( 739 } else if (
799 this.focusedId_ == '' || this.mirroring_ != mirroring || 740 this.focusedId_ == '' || this.mirroring_ != mirroring ||
800 this.unifiedDesktopEnabled_ != unifiedDesktopEnabled || 741 this.unifiedDesktopEnabled_ != unifiedDesktopEnabled ||
801 this.displays_.length != displays.length) { 742 this.displays_.length != displays.length) {
802 this.focusedId_ = displays.length > 0 ? displays[0].id : ''; 743 this.focusedId_ = displays.length > 0 ? displays[0].id : '';
803 } 744 }
804 745
746 this.displays_ = displays;
805 this.mirroring_ = mirroring; 747 this.mirroring_ = mirroring;
806 this.unifiedDesktopEnabled_ = unifiedDesktopEnabled; 748 this.unifiedDesktopEnabled_ = unifiedDesktopEnabled;
807 749
808 this.resetDisplaysView_(); 750 this.resetDisplaysView_();
809 if (this.mirroring_) 751 if (this.mirroring_)
810 this.layoutMirroringDisplays_(); 752 this.layoutMirroringDisplays_();
811 else 753 else
812 this.layoutDisplays_(layoutType); 754 this.layoutDisplays_(layoutType);
813 755
814 $('display-options-select-mirroring').value = 756 $('display-options-select-mirroring').value =
815 mirroring ? 'mirroring' : 'extended'; 757 mirroring ? 'mirroring' : 'extended';
816 758
817 $('display-options-unified-desktop').hidden = 759 $('display-options-unified-desktop').hidden =
818 !this.showUnifiedDesktopOption_; 760 !this.showUnifiedDesktopOption_;
819 761
820 $('display-options-toggle-unified-desktop').checked = 762 $('display-options-toggle-unified-desktop').checked =
821 this.unifiedDesktopEnabled_; 763 this.unifiedDesktopEnabled_;
822 764
823 var disableUnifiedDesktopOption = 765 var disableUnifiedDesktopOption =
824 (this.mirroring_ || 766 (this.mirroring_ ||
825 (!this.unifiedDesktopEnabled_ && 767 (!this.unifiedDesktopEnabled_ && this.displays_.length == 1));
826 this.displays_.length == 1));
827 768
828 $('display-options-toggle-unified-desktop').disabled = 769 $('display-options-toggle-unified-desktop').disabled =
829 disableUnifiedDesktopOption; 770 disableUnifiedDesktopOption;
830 771
831 this.updateSelectedDisplayDescription_(); 772 this.updateSelectedDisplayDescription_();
832 } 773 }
833 }; 774 };
834 775
835 DisplayOptions.setDisplayInfo = function( 776 DisplayOptions.setDisplayInfo = function(
836 mode, displays, layoutType, offset) { 777 mode, displays, layoutType, offset) {
837 DisplayOptions.getInstance().onDisplayChanged_( 778 DisplayOptions.getInstance().onDisplayChanged_(
838 mode, displays, layoutType, offset); 779 mode, displays, layoutType, offset);
839 }; 780 };
840 781
841 // Export 782 // Export
842 return { 783 return {
843 DisplayOptions: DisplayOptions 784 DisplayOptions: DisplayOptions
844 }; 785 };
845 }); 786 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/options/chromeos/display_layout_manager.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698