Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 this._tabSlider = createElementWithClass('div', 'tabbed-pane-tab-slider'); | 44 this._tabSlider = createElementWithClass('div', 'tabbed-pane-tab-slider'); |
| 45 this._tabsElement = this._headerContentsElement.createChild('div', 'tabbed-p ane-header-tabs'); | 45 this._tabsElement = this._headerContentsElement.createChild('div', 'tabbed-p ane-header-tabs'); |
| 46 this._tabsElement.setAttribute('role', 'tablist'); | 46 this._tabsElement.setAttribute('role', 'tablist'); |
| 47 this._contentElement = this.contentElement.createChild('div', 'tabbed-pane-c ontent'); | 47 this._contentElement = this.contentElement.createChild('div', 'tabbed-pane-c ontent'); |
| 48 this._contentElement.setAttribute('role', 'tabpanel'); | 48 this._contentElement.setAttribute('role', 'tabpanel'); |
| 49 this._contentElement.createChild('content'); | 49 this._contentElement.createChild('content'); |
| 50 /** @type {!Array.<!UI.TabbedPaneTab>} */ | 50 /** @type {!Array.<!UI.TabbedPaneTab>} */ |
| 51 this._tabs = []; | 51 this._tabs = []; |
| 52 /** @type {!Array.<!UI.TabbedPaneTab>} */ | 52 /** @type {!Array.<!UI.TabbedPaneTab>} */ |
| 53 this._tabsHistory = []; | 53 this._tabsHistory = []; |
| 54 /** @type {!Object.<string, !UI.TabbedPaneTab>} */ | 54 /** @type {!Map<string, !UI.TabbedPaneTab>} */ |
| 55 this._tabsById = {}; | 55 this._tabsById = new Map(); |
|
einbinder
2016/12/09 00:28:56
The never ending quest to convert Objects to Maps.
| |
| 56 this._currentTabLocked = false; | 56 this._currentTabLocked = false; |
| 57 this._autoSelectFirstItemOnShow = true; | 57 this._autoSelectFirstItemOnShow = true; |
| 58 | 58 |
| 59 this._dropDownButton = this._createDropDownButton(); | 59 this._dropDownButton = this._createDropDownButton(); |
| 60 UI.zoomManager.addEventListener(UI.ZoomManager.Events.ZoomChanged, this._zoo mChanged, this); | 60 UI.zoomManager.addEventListener(UI.ZoomManager.Events.ZoomChanged, this._zoo mChanged, this); |
| 61 } | 61 } |
| 62 | 62 |
| 63 /** | 63 /** |
| 64 * @param {boolean} locked | 64 * @param {boolean} locked |
| 65 */ | 65 */ |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 */ | 102 */ |
| 103 tabViews() { | 103 tabViews() { |
| 104 return this._tabs.map(tab => tab.view); | 104 return this._tabs.map(tab => tab.view); |
| 105 } | 105 } |
| 106 | 106 |
| 107 /** | 107 /** |
| 108 * @param {string} tabId | 108 * @param {string} tabId |
| 109 * @return {?UI.Widget} | 109 * @return {?UI.Widget} |
| 110 */ | 110 */ |
| 111 tabView(tabId) { | 111 tabView(tabId) { |
| 112 return this._tabsById[tabId] ? this._tabsById[tabId].view : null; | 112 return this._tabsById.has(tabId) ? this._tabsById.get(tabId).view : null; |
| 113 } | 113 } |
| 114 | 114 |
| 115 /** | 115 /** |
| 116 * @return {?string} | 116 * @return {?string} |
| 117 */ | 117 */ |
| 118 get selectedTabId() { | 118 get selectedTabId() { |
| 119 return this._currentTab ? this._currentTab.id : null; | 119 return this._currentTab ? this._currentTab.id : null; |
| 120 } | 120 } |
| 121 | 121 |
| 122 /** | 122 /** |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 */ | 157 */ |
| 158 headerElement() { | 158 headerElement() { |
| 159 return this._headerElement; | 159 return this._headerElement; |
| 160 } | 160 } |
| 161 | 161 |
| 162 /** | 162 /** |
| 163 * @param {string} id | 163 * @param {string} id |
| 164 * @return {boolean} | 164 * @return {boolean} |
| 165 */ | 165 */ |
| 166 isTabCloseable(id) { | 166 isTabCloseable(id) { |
| 167 var tab = this._tabsById[id]; | 167 var tab = this._tabsById.get(id); |
| 168 return tab ? tab.isCloseable() : false; | 168 return tab ? tab.isCloseable() : false; |
| 169 } | 169 } |
| 170 | 170 |
| 171 /** | 171 /** |
| 172 * @param {!UI.TabbedPaneTabDelegate} delegate | 172 * @param {!UI.TabbedPaneTabDelegate} delegate |
| 173 */ | 173 */ |
| 174 setTabDelegate(delegate) { | 174 setTabDelegate(delegate) { |
| 175 var tabs = this._tabs.slice(); | 175 var tabs = this._tabs.slice(); |
| 176 for (var i = 0; i < tabs.length; ++i) | 176 for (var i = 0; i < tabs.length; ++i) |
| 177 tabs[i].setDelegate(delegate); | 177 tabs[i].setDelegate(delegate); |
| 178 this._delegate = delegate; | 178 this._delegate = delegate; |
| 179 } | 179 } |
| 180 | 180 |
| 181 /** | 181 /** |
| 182 * @param {string} id | 182 * @param {string} id |
| 183 * @param {string} tabTitle | 183 * @param {string} tabTitle |
| 184 * @param {!UI.Widget} view | 184 * @param {!UI.Widget} view |
| 185 * @param {string=} tabTooltip | 185 * @param {string=} tabTooltip |
| 186 * @param {boolean=} userGesture | 186 * @param {boolean=} userGesture |
| 187 * @param {boolean=} isCloseable | 187 * @param {boolean=} isCloseable |
| 188 * @param {number=} index | 188 * @param {number=} index |
| 189 */ | 189 */ |
| 190 appendTab(id, tabTitle, view, tabTooltip, userGesture, isCloseable, index) { | 190 appendTab(id, tabTitle, view, tabTooltip, userGesture, isCloseable, index) { |
| 191 isCloseable = typeof isCloseable === 'boolean' ? isCloseable : this._closeab leTabs; | 191 isCloseable = typeof isCloseable === 'boolean' ? isCloseable : this._closeab leTabs; |
| 192 var tab = new UI.TabbedPaneTab(this, id, tabTitle, isCloseable, view, tabToo ltip); | 192 var tab = new UI.TabbedPaneTab(this, id, tabTitle, isCloseable, view, tabToo ltip); |
| 193 tab.setDelegate(this._delegate); | 193 tab.setDelegate(this._delegate); |
| 194 this._tabsById[id] = tab; | 194 this._tabsById.set(id, tab); |
| 195 if (index !== undefined) | 195 if (index !== undefined) |
| 196 this._tabs.splice(index, 0, tab); | 196 this._tabs.splice(index, 0, tab); |
| 197 else | 197 else |
| 198 this._tabs.push(tab); | 198 this._tabs.push(tab); |
| 199 this._tabsHistory.push(tab); | 199 this._tabsHistory.push(tab); |
| 200 view.attach(this); | 200 view.attach(this); |
| 201 if (this._tabsHistory[0] === tab && this.isShowing()) | 201 if (this._tabsHistory[0] === tab && this.isShowing()) |
| 202 this.selectTab(tab.id, userGesture); | 202 this.selectTab(tab.id, userGesture); |
| 203 this._updateTabElements(); | 203 this._updateTabElements(); |
| 204 } | 204 } |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 224 this.selectTab(this._tabsHistory[0].id, false); | 224 this.selectTab(this._tabsHistory[0].id, false); |
| 225 if (focused) | 225 if (focused) |
| 226 this.focus(); | 226 this.focus(); |
| 227 } | 227 } |
| 228 | 228 |
| 229 /** | 229 /** |
| 230 * @param {string} id | 230 * @param {string} id |
| 231 * @param {boolean=} userGesture | 231 * @param {boolean=} userGesture |
| 232 */ | 232 */ |
| 233 _innerCloseTab(id, userGesture) { | 233 _innerCloseTab(id, userGesture) { |
| 234 if (!this._tabsById[id]) | 234 if (!this._tabsById.has(id)) |
| 235 return; | 235 return; |
| 236 if (userGesture && !this._tabsById[id]._closeable) | 236 if (userGesture && !this._tabsById.get(id)._closeable) |
| 237 return; | 237 return; |
| 238 if (this._currentTab && this._currentTab.id === id) | 238 if (this._currentTab && this._currentTab.id === id) |
| 239 this._hideCurrentTab(); | 239 this._hideCurrentTab(); |
| 240 | 240 |
| 241 var tab = this._tabsById[id]; | 241 var tab = this._tabsById.get(id); |
| 242 delete this._tabsById[id]; | 242 this._tabsById.delete(id); |
| 243 | 243 |
| 244 this._tabsHistory.splice(this._tabsHistory.indexOf(tab), 1); | 244 this._tabsHistory.splice(this._tabsHistory.indexOf(tab), 1); |
| 245 this._tabs.splice(this._tabs.indexOf(tab), 1); | 245 this._tabs.splice(this._tabs.indexOf(tab), 1); |
| 246 if (tab._shown) | 246 if (tab._shown) |
| 247 this._hideTabElement(tab); | 247 this._hideTabElement(tab); |
| 248 tab.view.detach(); | 248 tab.view.detach(); |
| 249 | 249 |
| 250 var eventData = {tabId: id, view: tab.view, isUserGesture: userGesture}; | 250 var eventData = {tabId: id, view: tab.view, isUserGesture: userGesture}; |
| 251 this.dispatchEventToListeners(UI.TabbedPane.Events.TabClosed, eventData); | 251 this.dispatchEventToListeners(UI.TabbedPane.Events.TabClosed, eventData); |
| 252 return true; | 252 return true; |
| 253 } | 253 } |
| 254 | 254 |
| 255 /** | 255 /** |
| 256 * @param {string} tabId | 256 * @param {string} tabId |
| 257 * @return {boolean} | 257 * @return {boolean} |
| 258 */ | 258 */ |
| 259 hasTab(tabId) { | 259 hasTab(tabId) { |
| 260 return !!this._tabsById[tabId]; | 260 return this._tabsById.has(tabId); |
| 261 } | 261 } |
| 262 | 262 |
| 263 /** | 263 /** |
| 264 * @return {!Array.<string>} | 264 * @return {!Array.<string>} |
| 265 */ | 265 */ |
| 266 allTabs() { | 266 allTabs() { |
| 267 return this._tabs.map(function(tab) { | 267 return this._tabs.map(function(tab) { |
| 268 return tab.id; | 268 return tab.id; |
| 269 }); | 269 }); |
| 270 } | 270 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 | 303 |
| 304 /** | 304 /** |
| 305 * @param {string} id | 305 * @param {string} id |
| 306 * @param {boolean=} userGesture | 306 * @param {boolean=} userGesture |
| 307 * @return {boolean} | 307 * @return {boolean} |
| 308 */ | 308 */ |
| 309 selectTab(id, userGesture) { | 309 selectTab(id, userGesture) { |
| 310 if (this._currentTabLocked) | 310 if (this._currentTabLocked) |
| 311 return false; | 311 return false; |
| 312 var focused = this.hasFocus(); | 312 var focused = this.hasFocus(); |
| 313 var tab = this._tabsById[id]; | 313 var tab = this._tabsById.get(id); |
| 314 if (!tab) | 314 if (!tab) |
| 315 return false; | 315 return false; |
| 316 if (this._currentTab && this._currentTab.id === id) | 316 if (this._currentTab && this._currentTab.id === id) |
| 317 return true; | 317 return true; |
| 318 | 318 |
| 319 this.suspendInvalidations(); | 319 this.suspendInvalidations(); |
| 320 this._hideCurrentTab(); | 320 this._hideCurrentTab(); |
| 321 this._showTab(tab); | 321 this._showTab(tab); |
| 322 this.resumeInvalidations(); | 322 this.resumeInvalidations(); |
| 323 this._currentTab = tab; | 323 this._currentTab = tab; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 345 | 345 |
| 346 return this._tabsHistory.slice(0, tabsCount).map(tabToTabId); | 346 return this._tabsHistory.slice(0, tabsCount).map(tabToTabId); |
| 347 } | 347 } |
| 348 | 348 |
| 349 /** | 349 /** |
| 350 * @param {string} id | 350 * @param {string} id |
| 351 * @param {string} iconType | 351 * @param {string} iconType |
| 352 * @param {string=} iconTooltip | 352 * @param {string=} iconTooltip |
| 353 */ | 353 */ |
| 354 setTabIcon(id, iconType, iconTooltip) { | 354 setTabIcon(id, iconType, iconTooltip) { |
| 355 var tab = this._tabsById[id]; | 355 var tab = this._tabsById.get(id); |
| 356 if (tab._setIconType(iconType, iconTooltip)) | 356 if (tab._setIconType(iconType, iconTooltip)) |
| 357 this._updateTabElements(); | 357 this._updateTabElements(); |
| 358 } | 358 } |
| 359 | 359 |
| 360 /** | 360 /** |
| 361 * @param {string} id | 361 * @param {string} id |
| 362 * @param {boolean} enabled | 362 * @param {boolean} enabled |
| 363 */ | 363 */ |
| 364 setTabEnabled(id, enabled) { | 364 setTabEnabled(id, enabled) { |
| 365 var tab = this._tabsById[id]; | 365 var tab = this._tabsById.get(id); |
| 366 tab.tabElement.classList.toggle('disabled', !enabled); | 366 tab.tabElement.classList.toggle('disabled', !enabled); |
| 367 } | 367 } |
| 368 | 368 |
| 369 /** | 369 /** |
| 370 * @param {string} id | 370 * @param {string} id |
| 371 * @param {string} className | 371 * @param {string} className |
| 372 * @param {boolean=} force | 372 * @param {boolean=} force |
| 373 */ | 373 */ |
| 374 toggleTabClass(id, className, force) { | 374 toggleTabClass(id, className, force) { |
| 375 var tab = this._tabsById[id]; | 375 var tab = this._tabsById.get(id); |
| 376 if (tab._toggleClass(className, force)) | 376 if (tab._toggleClass(className, force)) |
| 377 this._updateTabElements(); | 377 this._updateTabElements(); |
| 378 } | 378 } |
| 379 | 379 |
| 380 /** | 380 /** |
| 381 * @param {!Common.Event} event | 381 * @param {!Common.Event} event |
| 382 */ | 382 */ |
| 383 _zoomChanged(event) { | 383 _zoomChanged(event) { |
| 384 for (var i = 0; i < this._tabs.length; ++i) | 384 for (var i = 0; i < this._tabs.length; ++i) |
| 385 delete this._tabs[i]._measuredWidth; | 385 delete this._tabs[i]._measuredWidth; |
| 386 if (this.isShowing()) | 386 if (this.isShowing()) |
| 387 this._updateTabElements(); | 387 this._updateTabElements(); |
| 388 } | 388 } |
| 389 | 389 |
| 390 /** | 390 /** |
| 391 * @param {string} id | 391 * @param {string} id |
| 392 * @param {string} tabTitle | 392 * @param {string} tabTitle |
| 393 * @param {string=} tabTooltip | 393 * @param {string=} tabTooltip |
| 394 */ | 394 */ |
| 395 changeTabTitle(id, tabTitle, tabTooltip) { | 395 changeTabTitle(id, tabTitle, tabTooltip) { |
| 396 var tab = this._tabsById[id]; | 396 var tab = this._tabsById.get(id); |
| 397 if (tabTooltip !== undefined) | 397 if (tabTooltip !== undefined) |
| 398 tab.tooltip = tabTooltip; | 398 tab.tooltip = tabTooltip; |
| 399 if (tab.title !== tabTitle) { | 399 if (tab.title !== tabTitle) { |
| 400 tab.title = tabTitle; | 400 tab.title = tabTitle; |
| 401 this._updateTabElements(); | 401 this._updateTabElements(); |
| 402 } | 402 } |
| 403 } | 403 } |
| 404 | 404 |
| 405 /** | 405 /** |
| 406 * @param {string} id | 406 * @param {string} id |
| 407 * @param {!UI.Widget} view | 407 * @param {!UI.Widget} view |
| 408 */ | 408 */ |
| 409 changeTabView(id, view) { | 409 changeTabView(id, view) { |
| 410 var tab = this._tabsById[id]; | 410 var tab = this._tabsById.get(id); |
| 411 if (tab.view === view) | 411 if (tab.view === view) |
| 412 return; | 412 return; |
| 413 | 413 |
| 414 var shouldFocus = tab.view.hasFocus(); | 414 var shouldFocus = tab.view.hasFocus(); |
| 415 | 415 |
| 416 this.suspendInvalidations(); | 416 this.suspendInvalidations(); |
| 417 | 417 |
| 418 var isSelected = this._currentTab && this._currentTab.id === id; | 418 var isSelected = this._currentTab && this._currentTab.id === id; |
| 419 if (isSelected) | 419 if (isSelected) |
| 420 this._hideTab(tab); | 420 this._hideTab(tab); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 534 this._dropDownMenu.addEventListener(UI.DropDownMenu.Events.ItemSelected, thi s._dropDownMenuItemSelected, this); | 534 this._dropDownMenu.addEventListener(UI.DropDownMenu.Events.ItemSelected, thi s._dropDownMenuItemSelected, this); |
| 535 | 535 |
| 536 return dropDownContainer; | 536 return dropDownContainer; |
| 537 } | 537 } |
| 538 | 538 |
| 539 /** | 539 /** |
| 540 * @param {!Common.Event} event | 540 * @param {!Common.Event} event |
| 541 */ | 541 */ |
| 542 _dropDownMenuItemSelected(event) { | 542 _dropDownMenuItemSelected(event) { |
| 543 var tabId = /** @type {string} */ (event.data); | 543 var tabId = /** @type {string} */ (event.data); |
| 544 this._lastSelectedOverflowTab = this._tabsById[tabId]; | 544 this._lastSelectedOverflowTab = this._tabsById.get(tabId); |
| 545 this.selectTab(tabId, true); | 545 this.selectTab(tabId, true); |
| 546 } | 546 } |
| 547 | 547 |
| 548 _totalWidth() { | 548 _totalWidth() { |
| 549 return this._headerContentsElement.getBoundingClientRect().width; | 549 return this._headerContentsElement.getBoundingClientRect().width; |
| 550 } | 550 } |
| 551 | 551 |
| 552 /** | 552 /** |
| 553 * @return {number} | 553 * @return {number} |
| 554 */ | 554 */ |
| (...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1209 * @param {!Array.<string>} ids | 1209 * @param {!Array.<string>} ids |
| 1210 */ | 1210 */ |
| 1211 closeTabs(tabbedPane, ids) {}, | 1211 closeTabs(tabbedPane, ids) {}, |
| 1212 | 1212 |
| 1213 /** | 1213 /** |
| 1214 * @param {string} tabId | 1214 * @param {string} tabId |
| 1215 * @param {!UI.ContextMenu} contextMenu | 1215 * @param {!UI.ContextMenu} contextMenu |
| 1216 */ | 1216 */ |
| 1217 onContextMenu(tabId, contextMenu) {} | 1217 onContextMenu(tabId, contextMenu) {} |
| 1218 }; | 1218 }; |
| OLD | NEW |