Chromium Code Reviews

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/ui/TabbedPane.js

Issue 2157363006: DevTools: keep widgets in widget hierarchy upon hide, split attach/detach cycle from show/hide. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: lcean Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 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 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 190 matching lines...)
201 { 201 {
202 isCloseable = typeof isCloseable === "boolean" ? isCloseable : this._clo seableTabs; 202 isCloseable = typeof isCloseable === "boolean" ? isCloseable : this._clo seableTabs;
203 var tab = new WebInspector.TabbedPaneTab(this, id, tabTitle, isCloseable , view, tabTooltip); 203 var tab = new WebInspector.TabbedPaneTab(this, id, tabTitle, isCloseable , view, tabTooltip);
204 tab.setDelegate(this._delegate); 204 tab.setDelegate(this._delegate);
205 this._tabsById[id] = tab; 205 this._tabsById[id] = tab;
206 if (index !== undefined) 206 if (index !== undefined)
207 this._tabs.splice(index, 0, tab); 207 this._tabs.splice(index, 0, tab);
208 else 208 else
209 this._tabs.push(tab); 209 this._tabs.push(tab);
210 this._tabsHistory.push(tab); 210 this._tabsHistory.push(tab);
211 view.attach(this.element);
211 if (this._tabsHistory[0] === tab && this.isShowing()) 212 if (this._tabsHistory[0] === tab && this.isShowing())
212 this.selectTab(tab.id, userGesture); 213 this.selectTab(tab.id, userGesture);
213 this._updateTabElements(); 214 this._updateTabElements();
214 }, 215 },
215 216
216 /** 217 /**
217 * @param {string} id 218 * @param {string} id
218 * @param {boolean=} userGesture 219 * @param {boolean=} userGesture
219 */ 220 */
220 closeTab: function(id, userGesture) 221 closeTab: function(id, userGesture)
(...skipping 30 matching lines...)
251 if (this._currentTab && this._currentTab.id === id) 252 if (this._currentTab && this._currentTab.id === id)
252 this._hideCurrentTab(); 253 this._hideCurrentTab();
253 254
254 var tab = this._tabsById[id]; 255 var tab = this._tabsById[id];
255 delete this._tabsById[id]; 256 delete this._tabsById[id];
256 257
257 this._tabsHistory.splice(this._tabsHistory.indexOf(tab), 1); 258 this._tabsHistory.splice(this._tabsHistory.indexOf(tab), 1);
258 this._tabs.splice(this._tabs.indexOf(tab), 1); 259 this._tabs.splice(this._tabs.indexOf(tab), 1);
259 if (tab._shown) 260 if (tab._shown)
260 this._hideTabElement(tab); 261 this._hideTabElement(tab);
262 tab.view.detach();
261 263
262 var eventData = { tabId: id, view: tab.view, isUserGesture: userGesture }; 264 var eventData = { tabId: id, view: tab.view, isUserGesture: userGesture };
263 this.dispatchEventToListeners(WebInspector.TabbedPane.EventTypes.TabClos ed, eventData); 265 this.dispatchEventToListeners(WebInspector.TabbedPane.EventTypes.TabClos ed, eventData);
264 return true; 266 return true;
265 }, 267 },
266 268
267 /** 269 /**
268 * @param {string} tabId 270 * @param {string} tabId
269 * @return {boolean} 271 * @return {boolean}
270 */ 272 */
(...skipping 145 matching lines...)
416 this._updateTabElements(); 418 this._updateTabElements();
417 }, 419 },
418 420
419 /** 421 /**
420 * @param {string} id 422 * @param {string} id
421 * @param {!WebInspector.Widget} view 423 * @param {!WebInspector.Widget} view
422 */ 424 */
423 changeTabView: function(id, view) 425 changeTabView: function(id, view)
424 { 426 {
425 var tab = this._tabsById[id]; 427 var tab = this._tabsById[id];
426 if (this._currentTab && this._currentTab.id === tab.id) { 428 if (tab.view === view)
427 if (tab.view !== view) 429 return;
428 this._hideTab(tab); 430
429 tab.view = view; 431 var isSelected = this._currentTab && this._currentTab.id === id;
432 if (isSelected)
433 this._hideTab(tab);
434 tab.view.detach();
435 tab.view = view;
436 tab.view.attach(this.element);
437 if (isSelected)
430 this._showTab(tab); 438 this._showTab(tab);
431 } else
432 tab.view = view;
433 }, 439 },
434 440
435 onResize: function() 441 onResize: function()
436 { 442 {
437 this._updateTabElements(); 443 this._updateTabElements();
438 }, 444 },
439 445
440 headerResized: function() 446 headerResized: function()
441 { 447 {
442 this._updateTabElements(); 448 this._updateTabElements();
(...skipping 309 matching lines...)
752 this._hideTab(this._currentTab); 758 this._hideTab(this._currentTab);
753 delete this._currentTab; 759 delete this._currentTab;
754 }, 760 },
755 761
756 /** 762 /**
757 * @param {!WebInspector.TabbedPaneTab} tab 763 * @param {!WebInspector.TabbedPaneTab} tab
758 */ 764 */
759 _showTab: function(tab) 765 _showTab: function(tab)
760 { 766 {
761 tab.tabElement.classList.add("selected"); 767 tab.tabElement.classList.add("selected");
762 tab.view.show(this.element); 768 tab.view.showWidget();
763 this._updateTabSlider(); 769 this._updateTabSlider();
764 }, 770 },
765 771
766 _updateTabSlider: function() 772 _updateTabSlider: function()
767 { 773 {
768 if (!this._currentTab || !this._sliderEnabled) 774 if (!this._currentTab || !this._sliderEnabled)
769 return; 775 return;
770 var left = 0; 776 var left = 0;
771 for (var i = 0; i < this._tabs.length && this._currentTab !== this._tabs [i] && this._tabs[i]._shown; i++) 777 for (var i = 0; i < this._tabs.length && this._currentTab !== this._tabs [i] && this._tabs[i]._shown; i++)
772 left += this._tabs[i]._measuredWidth; 778 left += this._tabs[i]._measuredWidth;
773 var sliderWidth = this._currentTab._shown ? this._currentTab._measuredWi dth : this._dropDownButton.offsetWidth; 779 var sliderWidth = this._currentTab._shown ? this._currentTab._measuredWi dth : this._dropDownButton.offsetWidth;
774 var scaleFactor = window.devicePixelRatio >= 1.5 ? " scaleY(0.75)" : ""; 780 var scaleFactor = window.devicePixelRatio >= 1.5 ? " scaleY(0.75)" : "";
775 this._tabSlider.style.transform = "translateX(" + left + "px)" + scaleFa ctor; 781 this._tabSlider.style.transform = "translateX(" + left + "px)" + scaleFa ctor;
776 this._tabSlider.style.width = sliderWidth + "px"; 782 this._tabSlider.style.width = sliderWidth + "px";
777 783
778 if (this._tabSlider.parentElement !== this._headerContentsElement) 784 if (this._tabSlider.parentElement !== this._headerContentsElement)
779 this._headerContentsElement.appendChild(this._tabSlider); 785 this._headerContentsElement.appendChild(this._tabSlider);
780 }, 786 },
781 787
782 /** 788 /**
783 * @param {!WebInspector.TabbedPaneTab} tab 789 * @param {!WebInspector.TabbedPaneTab} tab
784 */ 790 */
785 _hideTab: function(tab) 791 _hideTab: function(tab)
786 { 792 {
787 tab.tabElement.classList.remove("selected"); 793 tab.tabElement.classList.remove("selected");
788 tab.view.detach(); 794 tab.view.hideWidget();
789 }, 795 },
790 796
791 /** 797 /**
792 * @override 798 * @override
793 * @return {!Array.<!Element>} 799 * @return {!Array.<!Element>}
794 */ 800 */
795 elementsToRestoreScrollPositionsFor: function() 801 elementsToRestoreScrollPositionsFor: function()
796 { 802 {
797 return [ this._contentElement ]; 803 return [ this._contentElement ];
798 }, 804 },
(...skipping 624 matching lines...)
1423 if (this._viewCallback && view) 1429 if (this._viewCallback && view)
1424 this._viewCallback(id, view); 1430 this._viewCallback(id, view);
1425 var shouldFocus = this._tabbedPane.visibleView.element.isSelfOrAnces tor(WebInspector.currentFocusElement()); 1431 var shouldFocus = this._tabbedPane.visibleView.element.isSelfOrAnces tor(WebInspector.currentFocusElement());
1426 this._tabbedPane.changeTabView(id, view); 1432 this._tabbedPane.changeTabView(id, view);
1427 if (shouldFocus) 1433 if (shouldFocus)
1428 view.focus(); 1434 view.focus();
1429 return view; 1435 return view;
1430 } 1436 }
1431 } 1437 }
1432 } 1438 }
OLDNEW

Powered by Google App Engine