OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 package org.chromium.chrome.browser.tabmodel; | 5 package org.chromium.chrome.browser.tabmodel; |
6 | 6 |
7 import org.chromium.base.ObserverList; | 7 import org.chromium.base.ObserverList; |
8 import org.chromium.base.TraceEvent; | 8 import org.chromium.base.TraceEvent; |
9 import org.chromium.chrome.browser.tab.Tab; | 9 import org.chromium.chrome.browser.tab.Tab; |
10 import org.chromium.chrome.browser.util.MathUtils; | 10 import org.chromium.chrome.browser.util.MathUtils; |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 | 391 |
392 // TODO(aurimas): Move this method to TabModelSelector when notifications mo
ve there. | 392 // TODO(aurimas): Move this method to TabModelSelector when notifications mo
ve there. |
393 private int getLastId(TabSelectionType type) { | 393 private int getLastId(TabSelectionType type) { |
394 if (type == TabSelectionType.FROM_CLOSE) return Tab.INVALID_TAB_ID; | 394 if (type == TabSelectionType.FROM_CLOSE) return Tab.INVALID_TAB_ID; |
395 | 395 |
396 // Get the current tab in the current tab model. | 396 // Get the current tab in the current tab model. |
397 Tab currentTab = TabModelUtils.getCurrentTab(mModelDelegate.getCurrentMo
del()); | 397 Tab currentTab = TabModelUtils.getCurrentTab(mModelDelegate.getCurrentMo
del()); |
398 return currentTab != null ? currentTab.getId() : Tab.INVALID_TAB_ID; | 398 return currentTab != null ? currentTab.getId() : Tab.INVALID_TAB_ID; |
399 } | 399 } |
400 | 400 |
401 private boolean hasVaildTab() { | 401 private boolean hasValidTab() { |
402 if (mTabs.size() <= 0) return false; | 402 if (mTabs.size() <= 0) return false; |
403 for (int i = 0; i < mTabs.size(); i++) { | 403 for (int i = 0; i < mTabs.size(); i++) { |
404 if (!mTabs.get(i).isClosing()) return true; | 404 if (!mTabs.get(i).isClosing()) return true; |
405 } | 405 } |
406 return false; | 406 return false; |
407 } | 407 } |
408 | 408 |
409 // This function is complex and its behavior depends on persisted state, inc
luding mIndex. | 409 // This function is complex and its behavior depends on persisted state, inc
luding mIndex. |
410 @Override | 410 @Override |
411 public void setIndex(int i, final TabSelectionType type) { | 411 public void setIndex(int i, final TabSelectionType type) { |
412 try { | 412 try { |
413 TraceEvent.begin("TabModelBase.setIndex"); | 413 TraceEvent.begin("TabModelBase.setIndex"); |
414 int lastId = getLastId(type); | 414 int lastId = getLastId(type); |
415 | 415 |
416 if (!isCurrentModel()) { | 416 if (!isCurrentModel()) { |
417 mModelDelegate.selectModel(isIncognito()); | 417 mModelDelegate.selectModel(isIncognito()); |
418 } | 418 } |
419 | 419 |
420 if (!hasVaildTab()) { | 420 if (!hasValidTab()) { |
421 mIndex = INVALID_TAB_INDEX; | 421 mIndex = INVALID_TAB_INDEX; |
422 } else { | 422 } else { |
423 mIndex = MathUtils.clamp(i, 0, mTabs.size() - 1); | 423 mIndex = MathUtils.clamp(i, 0, mTabs.size() - 1); |
424 } | 424 } |
425 | 425 |
426 Tab tab = TabModelUtils.getCurrentTab(this); | 426 Tab tab = TabModelUtils.getCurrentTab(this); |
427 | 427 |
428 mModelDelegate.requestToShowTab(tab, type); | 428 mModelDelegate.requestToShowTab(tab, type); |
429 | 429 |
430 if (tab != null) { | 430 if (tab != null) { |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 @Override | 633 @Override |
634 public int index() { | 634 public int index() { |
635 return mIndex; | 635 return mIndex; |
636 } | 636 } |
637 | 637 |
638 @Override | 638 @Override |
639 protected boolean isSessionRestoreInProgress() { | 639 protected boolean isSessionRestoreInProgress() { |
640 return mModelDelegate.isSessionRestoreInProgress(); | 640 return mModelDelegate.isSessionRestoreInProgress(); |
641 } | 641 } |
642 } | 642 } |
OLD | NEW |