Changeset 258623 in webkit


Ignore:
Timestamp:
Mar 17, 2020 9:30:22 PM (4 years ago)
Author:
Devin Rousso
Message:

Web Inspector: the width of WI.TabBarItem can change if the detached window is resized
https://bugs.webkit.org/show_bug.cgi?id=209200

Reviewed by Timothy Hatcher.

  • UserInterface/Views/TabBar.js:

(WI.TabBar.prototype.layout):
(WI.TabBar.prototype.layout.measureWidth): Renamed from measureItemWidth.
When undocked, WI.TabBarItem grow to fill any available space. As a result, if a
WI.TabBarItem is added or removed, the width of all WI.TabBarItem will change.
Wait to measure widths until all WI.TabBarItem are un-hidden for the reason above.

Location:
trunk/Source/WebInspectorUI
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebInspectorUI/ChangeLog

    r258622 r258623  
     12020-03-17  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: the width of `WI.TabBarItem` can change if the detached window is resized
     4        https://bugs.webkit.org/show_bug.cgi?id=209200
     5
     6        Reviewed by Timothy Hatcher.
     7
     8        * UserInterface/Views/TabBar.js:
     9        (WI.TabBar.prototype.layout):
     10        (WI.TabBar.prototype.layout.measureWidth): Renamed from `measureItemWidth`.
     11        When undocked, `WI.TabBarItem` grow to fill any available space. As a result, if a
     12        `WI.TabBarItem` is added or removed, the width of all `WI.TabBarItem` will change.
     13        Wait to measure widths until all `WI.TabBarItem` are un-hidden for the reason above.
     14
    1152020-03-17  Devin Rousso  <drousso@apple.com>
    216
  • trunk/Source/WebInspectorUI/UserInterface/Views/TabBar.js

    r258550 r258623  
    436436        const tabBarItemHorizontalMargin = WI.TabBarItem.horizontalMargin;
    437437
    438         function measureItemWidth(item) {
    439             if (!item[WI.TabBar.CachedWidthSymbol])
    440                 item[WI.TabBar.CachedWidthSymbol] = item.element.realOffsetWidth + tabBarItemHorizontalMargin;
    441             return item[WI.TabBar.CachedWidthSymbol];
    442         }
    443 
    444         let availableSpace = this._tabContainer.realOffsetWidth - tabBarHorizontalPadding;
     438        let undocked = WI.dockConfiguration === WI.DockConfiguration.Undocked;
     439
     440        function measureWidth(tabBarItem) {
     441            if (!tabBarItem[WI.TabBar.CachedWidthSymbol])
     442                tabBarItem[WI.TabBar.CachedWidthSymbol] = tabBarItem.element.realOffsetWidth + tabBarItemHorizontalMargin;
     443            return tabBarItem[WI.TabBar.CachedWidthSymbol];
     444        }
     445
     446        // Add one to allow for possible sub-px widths.
     447        let availableSpace = this._tabContainer.realOffsetWidth - tabBarHorizontalPadding + 1;
    445448
    446449        this._tabContainer.classList.add("calculate-width");
     
    449452
    450453        let normalTabBarItems = [];
    451         let normalTabBarItemsWidth = 0;
    452454        for (let tabBarItem of this._tabBarItemsFromLeftToRight()) {
    453455            if (tabBarItem === this._tabPickerTabBarItem) {
     
    458460            tabBarItem.hidden = false;
    459461
    460             if (tabBarItem instanceof WI.PinnedTabBarItem)
    461                 availableSpace -= measureItemWidth(tabBarItem);
    462             else {
    463                 normalTabBarItems.push(tabBarItem);
    464                 normalTabBarItemsWidth += measureItemWidth(tabBarItem);
    465             }
    466         }
    467 
     462            if (tabBarItem instanceof WI.PinnedTabBarItem) {
     463                availableSpace -= measureWidth(tabBarItem);
     464                continue;
     465            }
     466
     467            normalTabBarItems.push(tabBarItem);
     468
     469            // When undocked, `WI.TabBarItem` grow to fill any available space. As a result, if a
     470            // `WI.TabBarItem` is added or removed, the width of all `WI.TabBarItem` will change.
     471            if (undocked)
     472                tabBarItem[WI.TabBar.CachedWidthSymbol] = 0;
     473        }
     474
     475        // Wait to measure widths until all `WI.TabBarItem` are un-hidden for the reason above.
     476        let normalTabBarItemsWidth = normalTabBarItems.reduce((accumulator, tabBarItem) => accumulator + measureWidth(tabBarItem), 0);
    468477        if (normalTabBarItemsWidth > availableSpace) {
    469478            this._tabPickerTabBarItem.hidden = false;
    470             availableSpace -= measureItemWidth(this._tabPickerTabBarItem);
     479            availableSpace -= measureWidth(this._tabPickerTabBarItem);
    471480
    472481            let index = normalTabBarItems.length - 1;
     
    476485                    continue;
    477486
    478                 normalTabBarItemsWidth -= measureItemWidth(tabBarItem);
     487                normalTabBarItemsWidth -= measureWidth(tabBarItem);
    479488
    480489                tabBarItem.hidden = true;
Note: See TracChangeset for help on using the changeset viewer.