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

Side by Side Diff: chrome/browser/resources/net_internals/tab_switcher_view.js

Issue 2121763002: [net-internals] Fix JS exception on stopping capturing while in Capture view (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 | « no previous file | 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 /** 5 /**
6 * Controller and View for switching between tabs. 6 * Controller and View for switching between tabs.
7 * 7 *
8 * The View part of TabSwitcherView displays the contents of the currently 8 * The View part of TabSwitcherView displays the contents of the currently
9 * selected tab (only one tab can be active at a time). 9 * selected tab (only one tab can be active at a time).
10 * 10 *
(...skipping 13 matching lines...) Expand all
24 * 24 *
25 * @param {?Function} opt_onTabSwitched Optional callback to run when the 25 * @param {?Function} opt_onTabSwitched Optional callback to run when the
26 * active tab changes. Called as 26 * active tab changes. Called as
27 * opt_onTabSwitched(oldTabId, newTabId). 27 * opt_onTabSwitched(oldTabId, newTabId).
28 */ 28 */
29 function TabSwitcherView(opt_onTabSwitched) { 29 function TabSwitcherView(opt_onTabSwitched) {
30 assertFirstConstructorCall(TabSwitcherView); 30 assertFirstConstructorCall(TabSwitcherView);
31 31
32 this.tabIdToView_ = {}; 32 this.tabIdToView_ = {};
33 this.tabIdToLink_ = {}; 33 this.tabIdToLink_ = {};
34 // Ordered list of views. 34 // Map from tab id to the views link visiblity.
35 this.viewList_ = []; 35 this.tabIdsLinkVisibility_ = new Map();
36 this.activeTabId_ = null; 36 this.activeTabId_ = null;
37 37
38 this.onTabSwitched_ = opt_onTabSwitched; 38 this.onTabSwitched_ = opt_onTabSwitched;
39 39
40 // The ideal width of the tab list. If width is reduced below this, the 40 // The ideal width of the tab list. If width is reduced below this, the
41 // tab list will be shrunk, but it will be returned to this width once it 41 // tab list will be shrunk, but it will be returned to this width once it
42 // can be. 42 // can be.
43 this.tabListWidth_ = $(TAB_LIST_ID).offsetWidth; 43 this.tabListWidth_ = $(TAB_LIST_ID).offsetWidth;
44 44
45 superClass.call(this); 45 superClass.call(this);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 * @param {string} tabId The ID to refer to the tab by. 91 * @param {string} tabId The ID to refer to the tab by.
92 * @param {!View} view The tab's actual contents. 92 * @param {!View} view The tab's actual contents.
93 * @param {string} name The name for the menu item that selects the tab. 93 * @param {string} name The name for the menu item that selects the tab.
94 */ 94 */
95 addTab: function(tabId, view, name, hash) { 95 addTab: function(tabId, view, name, hash) {
96 if (!tabId) { 96 if (!tabId) {
97 throw Error('Must specify a non-false tabId'); 97 throw Error('Must specify a non-false tabId');
98 } 98 }
99 99
100 this.tabIdToView_[tabId] = view; 100 this.tabIdToView_[tabId] = view;
101 this.viewList_.push(view); 101 this.tabIdsLinkVisibility_.set(tabId, true);
102 102
103 var node = addNodeWithText($(TAB_LIST_ID), 'a', name); 103 var node = addNodeWithText($(TAB_LIST_ID), 'a', name);
104 node.href = hash; 104 node.href = hash;
105 this.tabIdToLink_[tabId] = node; 105 this.tabIdToLink_[tabId] = node;
106 addNode($(TAB_LIST_ID), 'br'); 106 addNode($(TAB_LIST_ID), 'br');
107 107
108 // Tab content views start off hidden. 108 // Tab content views start off hidden.
109 view.show(false); 109 view.show(false);
110 110
111 this.tabListWidth_ = $(TAB_LIST_ID).offsetWidth; 111 this.tabListWidth_ = $(TAB_LIST_ID).offsetWidth;
112 }, 112 },
113 113
114 showTabLink: function(tabId, isVisible) { 114 showTabLink: function(tabId, isVisible) {
115 var wasActive = this.activeTabId_ == tabId; 115 var wasActive = this.activeTabId_ == tabId;
116 116
117 setNodeDisplay(this.tabIdToLink_[tabId], isVisible); 117 setNodeDisplay(this.tabIdToLink_[tabId], isVisible);
118 this.tabIdsLinkVisibility_.set(tabId, isVisible);
118 119
119 if (wasActive && !isVisible) { 120 if (wasActive && !isVisible) {
120 // If the link for active tab is being hidden, then switch to the first 121 // If the link for active tab is being hidden, then switch to the first
121 // tab which is still visible. 122 // tab which is still visible.
122 for (var view in this.viewList_) { 123 for (var [localTabId, enabled] of this.tabIdsLinkVisibility_) {
eroman 2016/07/06 20:06:29 I agree that the current code is quite wrong. The
123 if (view.isVisible()) 124 if (enabled) {
124 this.switchToTab(option.value); 125 this.switchToTab(localTabId);
126 break;
127 }
125 } 128 }
126 } 129 }
127 }, 130 },
128 131
129 getAllTabViews: function() { 132 getAllTabViews: function() {
130 return this.tabIdToView_; 133 return this.tabIdToView_;
131 }, 134 },
132 135
133 getTabView: function(tabId) { 136 getTabView: function(tabId) {
134 return this.tabIdToView_[tabId]; 137 return this.tabIdToView_[tabId];
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 171
169 newView.show(this.isVisible()); 172 newView.show(this.isVisible());
170 173
171 if (this.onTabSwitched_) 174 if (this.onTabSwitched_)
172 this.onTabSwitched_(oldTabId, tabId); 175 this.onTabSwitched_(oldTabId, tabId);
173 }, 176 },
174 }; 177 };
175 178
176 return TabSwitcherView; 179 return TabSwitcherView;
177 })(); 180 })();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698