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

Side by Side Diff: Source/devtools/front_end/SplitView.js

Issue 214663005: [DevTools] Add preferred size to WebInspector.View. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: saved main size Created 6 years, 9 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 10 *
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 this._showMode = showMode; 379 this._showMode = showMode;
380 this._saveShowModeToSettings(); 380 this._saveShowModeToSettings();
381 this._updateShowHideSidebarButton(); 381 this._updateShowHideSidebarButton();
382 this.dispatchEventToListeners(WebInspector.SplitView.Events.ShowModeChan ged, showMode); 382 this.dispatchEventToListeners(WebInspector.SplitView.Events.ShowModeChan ged, showMode);
383 this.invalidateMinimumSize(); 383 this.invalidateMinimumSize();
384 }, 384 },
385 385
386 /** 386 /**
387 * @param {number} size 387 * @param {number} size
388 * @param {boolean} animate 388 * @param {boolean} animate
389 * @param {boolean=} userAction
389 */ 390 */
390 _innerSetSidebarSize: function(size, animate) 391 _innerSetSidebarSize: function(size, animate, userAction)
391 { 392 {
392 if (this._showMode !== WebInspector.SplitView.ShowMode.Both || !this.isS howing()) 393 if (this._showMode !== WebInspector.SplitView.ShowMode.Both || !this.isS howing())
393 return; 394 return;
394 395
395 size = this._applyConstraints(size); 396 size = this._applyConstraints(size, userAction);
396 if (this._sidebarSize === size) 397 if (this._sidebarSize === size)
397 return; 398 return;
398 399
399 this._removeAllLayoutProperties(); 400 this._removeAllLayoutProperties();
400 401
401 var sizeValue = (size / WebInspector.zoomManager.zoomFactor()) + "px"; 402 var sizeValue = (size / WebInspector.zoomManager.zoomFactor()) + "px";
402 this.sidebarElement().style.flexBasis = sizeValue; 403 this.sidebarElement().style.flexBasis = sizeValue;
403 404
404 if (!this._resizerElementSize) 405 if (!this._resizerElementSize)
405 this._resizerElementSize = this._isVertical ? this._resizerElement.o ffsetWidth : this._resizerElement.offsetHeight; 406 this._resizerElementSize = this._isVertical ? this._resizerElement.o ffsetWidth : this._resizerElement.offsetHeight;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 delete this._animationFrameHandle; 511 delete this._animationFrameHandle;
511 } 512 }
512 if (this._animationCallback) { 513 if (this._animationCallback) {
513 this._animationCallback(); 514 this._animationCallback();
514 delete this._animationCallback; 515 delete this._animationCallback;
515 } 516 }
516 }, 517 },
517 518
518 /** 519 /**
519 * @param {number} sidebarSize 520 * @param {number} sidebarSize
521 * @param {boolean=} userAction
520 * @return {number} 522 * @return {number}
521 */ 523 */
522 _applyConstraints: function(sidebarSize) 524 _applyConstraints: function(sidebarSize, userAction)
523 { 525 {
524 var totalSize = this.totalSize(); 526 var totalSize = this.totalSize();
525 527
526 var size = this._sidebarView.minimumSize(); 528 var size = this._sidebarView.minimumSize();
527 var from = this.isVertical() ? size.width : size.height; 529 var minSidebarSize = this.isVertical() ? size.width : size.height;
528 if (!from) 530 if (!minSidebarSize)
529 from = WebInspector.SplitView.MinPadding; 531 minSidebarSize = WebInspector.SplitView.MinPadding;
532
533 var preferredSidebarSize = this.isVertical() ? size.preferredWidth : siz e.preferredHeight;
534 if (!preferredSidebarSize)
535 preferredSidebarSize = WebInspector.SplitView.MinPadding;
536 // Allow sidebar to be less than preferred by explicit user action.
537 if (sidebarSize < preferredSidebarSize)
538 preferredSidebarSize = Math.max(sidebarSize, minSidebarSize);
530 539
531 size = this._mainView.minimumSize(); 540 size = this._mainView.minimumSize();
532 var minMainSize = this.isVertical() ? size.width : size.height; 541 var minMainSize = this.isVertical() ? size.width : size.height;
533 if (!minMainSize) 542 if (!minMainSize)
534 minMainSize = WebInspector.SplitView.MinPadding; 543 minMainSize = WebInspector.SplitView.MinPadding;
535 544
536 var to = totalSize - minMainSize; 545 var preferredMainSize = this.isVertical() ? size.preferredWidth : size.p referredHeight;
537 if (from <= to) 546 if (!preferredMainSize)
538 return Number.constrain(sidebarSize, from, to); 547 preferredMainSize = WebInspector.SplitView.MinPadding;
548 var savedMainSize = this.isVertical() ? this._savedVerticalMainSize : th is._savedHorizontalMainSize;
549 if (typeof savedMainSize !== "undefined")
550 preferredMainSize = Math.min(preferredMainSize, savedMainSize);
551 if (userAction)
552 preferredMainSize = minMainSize;
539 553
540 // If we don't have enough space (which is a very rare case), prioritize main view. 554 // Enough space for preferred.
541 return Math.max(0, to); 555 var totalPreferred = preferredMainSize + preferredSidebarSize;
556 if (totalPreferred <= totalSize)
557 return Number.constrain(sidebarSize, preferredSidebarSize, totalSize - preferredMainSize);
558
559 // Enough space for minimum.
560 if (totalPreferred > 0 && minMainSize + minSidebarSize <= totalSize) {
vsevik 2014/03/28 16:13:26 How can totalPreferred > 0 be wrong?
dgozman 2014/03/28 18:05:02 Done.
561 var delta = totalPreferred - totalSize;
562 var sidebarDelta = delta * preferredSidebarSize / totalPreferred;
563 sidebarSize = preferredSidebarSize - sidebarDelta;
564 return Number.constrain(sidebarSize, minSidebarSize, totalSize - min MainSize);
565 }
566
567 // Not enough space even for minimum sizes.
568 return Math.max(0, totalSize - minMainSize);
542 }, 569 },
543 570
544 wasShown: function() 571 wasShown: function()
545 { 572 {
546 this._forceUpdateLayout(); 573 this._forceUpdateLayout();
547 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Event s.ZoomChanged, this._onZoomChanged, this); 574 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Event s.ZoomChanged, this._onZoomChanged, this);
548 }, 575 },
549 576
550 willHide: function() 577 willHide: function()
551 { 578 {
(...skipping 16 matching lines...) Expand all
568 calculateMinimumSize: function() 595 calculateMinimumSize: function()
569 { 596 {
570 if (this._showMode === WebInspector.SplitView.ShowMode.OnlyMain) 597 if (this._showMode === WebInspector.SplitView.ShowMode.OnlyMain)
571 return this._mainView.minimumSize(); 598 return this._mainView.minimumSize();
572 if (this._showMode === WebInspector.SplitView.ShowMode.OnlySidebar) 599 if (this._showMode === WebInspector.SplitView.ShowMode.OnlySidebar)
573 return this._sidebarView.minimumSize(); 600 return this._sidebarView.minimumSize();
574 601
575 var mainSize = this._mainView.minimumSize(); 602 var mainSize = this._mainView.minimumSize();
576 var sidebarSize = this._sidebarView.minimumSize(); 603 var sidebarSize = this._sidebarView.minimumSize();
577 var min = WebInspector.SplitView.MinPadding; 604 var min = WebInspector.SplitView.MinPadding;
578 if (this._isVertical) 605 if (this._isVertical) {
579 return new Size((mainSize.width || min) + (sidebarSize.width || min) , Math.max(mainSize.height, sidebarSize.height)); 606 mainSize = mainSize.widthToMax(new Size(min, 0));
580 else 607 sidebarSize = sidebarSize.widthToMax(new Size(min, 0));
581 return new Size(Math.max(mainSize.width, sidebarSize.width), (mainSi ze.height || min) + (sidebarSize.height || min)); 608 return mainSize.addWidth(sidebarSize).heightToMax(sidebarSize);
609 } else {
610 mainSize = mainSize.heightToMax(new Size(0, min));
611 sidebarSize = sidebarSize.heightToMax(new Size(0, min));
612 return mainSize.widthToMax(sidebarSize).addHeight(sidebarSize);
613 }
582 }, 614 },
583 615
584 /** 616 /**
585 * @param {!MouseEvent} event 617 * @param {!MouseEvent} event
586 * @return {boolean} 618 * @return {boolean}
587 */ 619 */
588 _startResizerDragging: function(event) 620 _startResizerDragging: function(event)
589 { 621 {
590 if (!this._resizable) 622 if (!this._resizable)
591 return false; 623 return false;
592 624
593 var dipEventPosition = (this._isVertical ? event.pageX : event.pageY) * WebInspector.zoomManager.zoomFactor(); 625 var dipEventPosition = (this._isVertical ? event.pageX : event.pageY) * WebInspector.zoomManager.zoomFactor();
594 this._dragOffset = (this._secondIsSidebar ? this.totalSize() - this._sid ebarSize : this._sidebarSize) - dipEventPosition; 626 this._dragOffset = (this._secondIsSidebar ? this.totalSize() - this._sid ebarSize : this._sidebarSize) - dipEventPosition;
595 return true; 627 return true;
596 }, 628 },
597 629
598 /** 630 /**
599 * @param {!MouseEvent} event 631 * @param {!MouseEvent} event
600 */ 632 */
601 _resizerDragging: function(event) 633 _resizerDragging: function(event)
602 { 634 {
603 var dipEventPosition = (this._isVertical ? event.pageX : event.pageY) * WebInspector.zoomManager.zoomFactor(); 635 var dipEventPosition = (this._isVertical ? event.pageX : event.pageY) * WebInspector.zoomManager.zoomFactor();
604 var newOffset = dipEventPosition + this._dragOffset; 636 var newOffset = dipEventPosition + this._dragOffset;
605 var newSize = (this._secondIsSidebar ? this.totalSize() - newOffset : ne wOffset); 637 var newSize = (this._secondIsSidebar ? this.totalSize() - newOffset : ne wOffset);
606 var constrainedSize = this._applyConstraints(newSize); 638 var constrainedSize = this._applyConstraints(newSize, true);
607 this._savedSidebarSize = constrainedSize; 639 this._savedSidebarSize = constrainedSize;
608 this._saveSetting(); 640 this._saveSetting();
609 this._innerSetSidebarSize(constrainedSize, false); 641 this._innerSetSidebarSize(constrainedSize, false, true);
642 if (this.isVertical())
643 this._savedVerticalMainSize = this.totalSize() - this._sidebarSize;
644 else
645 this._savedHorizontalMainSize = this.totalSize() - this._sidebarSize ;
610 event.preventDefault(); 646 event.preventDefault();
611 }, 647 },
612 648
613 /** 649 /**
614 * @param {!MouseEvent} event 650 * @param {!MouseEvent} event
615 */ 651 */
616 _endResizerDragging: function(event) 652 _endResizerDragging: function(event)
617 { 653 {
618 delete this._dragOffset; 654 delete this._dragOffset;
619 }, 655 },
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 this._showHideSidebarButton.state = sidebarHidden ? "show" : "hide"; 861 this._showHideSidebarButton.state = sidebarHidden ? "show" : "hide";
826 this._showHideSidebarButton.element.classList.toggle("top-sidebar-show-h ide-button", !this.isVertical() && !this.isSidebarSecond()); 862 this._showHideSidebarButton.element.classList.toggle("top-sidebar-show-h ide-button", !this.isVertical() && !this.isSidebarSecond());
827 this._showHideSidebarButton.element.classList.toggle("right-sidebar-show -hide-button", this.isVertical() && this.isSidebarSecond()); 863 this._showHideSidebarButton.element.classList.toggle("right-sidebar-show -hide-button", this.isVertical() && this.isSidebarSecond());
828 this._showHideSidebarButton.element.classList.toggle("bottom-sidebar-sho w-hide-button", !this.isVertical() && this.isSidebarSecond()); 864 this._showHideSidebarButton.element.classList.toggle("bottom-sidebar-sho w-hide-button", !this.isVertical() && this.isSidebarSecond());
829 this._showHideSidebarButton.element.classList.toggle("left-sidebar-show- hide-button", this.isVertical() && !this.isSidebarSecond()); 865 this._showHideSidebarButton.element.classList.toggle("left-sidebar-show- hide-button", this.isVertical() && !this.isSidebarSecond());
830 this._showHideSidebarButton.title = sidebarHidden ? WebInspector.UIStrin g("Show %s", this._showHideSidebarButtonTitle) : WebInspector.UIString("Hide %s" , this._showHideSidebarButtonTitle); 866 this._showHideSidebarButton.title = sidebarHidden ? WebInspector.UIStrin g("Show %s", this._showHideSidebarButtonTitle) : WebInspector.UIString("Hide %s" , this._showHideSidebarButtonTitle);
831 }, 867 },
832 868
833 __proto__: WebInspector.View.prototype 869 __proto__: WebInspector.View.prototype
834 } 870 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698