зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1350718 - Post: Name the special value -1 used to indicate a new tab should be appended. r=maliu
MozReview-Commit-ID: 7r8cHItW4wG --HG-- extra : rebase_source : b7ea5736f706a126f553d6c2eddc314ee4f5f011
This commit is contained in:
Родитель
69608d9657
Коммит
89477640e6
|
@ -81,6 +81,8 @@ public class Tabs implements BundleEventListener {
|
|||
private static final long PERSIST_TABS_AFTER_MILLISECONDS = 1000 * 2;
|
||||
|
||||
public static final int INVALID_TAB_ID = -1;
|
||||
// Used to indicate a new tab should be appended to the current tabs.
|
||||
public static final int NEW_LAST_INDEX = -1;
|
||||
|
||||
private static final AtomicInteger sTabId = new AtomicInteger(0);
|
||||
private volatile boolean mInitialTabsAdded;
|
||||
|
@ -260,10 +262,17 @@ public class Tabs implements BundleEventListener {
|
|||
return tab;
|
||||
}
|
||||
|
||||
// Return the index, among those tabs of the chosen type whose privacy setting matches
|
||||
// isPrivate, of the tab at position index in mOrder. Returns -1, for "new last tab",
|
||||
// when index is -1.
|
||||
/**
|
||||
* Return the index, among those tabs of the chosen {@code type} whose privacy setting matches
|
||||
* {@code isPrivate}, of the tab at position {@code index} in {@code mOrder}. Returns
|
||||
* {@code NEW_LAST_INDEX} when {@code index} is {@code NEW_LAST_INDEX} or no matches were
|
||||
* found.
|
||||
*/
|
||||
private int getPrivacySpecificTabIndex(int index, boolean isPrivate, TabType type) {
|
||||
if (index == NEW_LAST_INDEX) {
|
||||
return NEW_LAST_INDEX;
|
||||
}
|
||||
|
||||
int privacySpecificIndex = -1;
|
||||
for (int i = 0; i <= index; i++) {
|
||||
final Tab tab = mOrder.get(i);
|
||||
|
@ -271,7 +280,7 @@ public class Tabs implements BundleEventListener {
|
|||
privacySpecificIndex++;
|
||||
}
|
||||
}
|
||||
return privacySpecificIndex;
|
||||
return privacySpecificIndex > -1 ? privacySpecificIndex : NEW_LAST_INDEX;
|
||||
}
|
||||
|
||||
public synchronized void removeTab(int id) {
|
||||
|
@ -1022,7 +1031,7 @@ public class Tabs implements BundleEventListener {
|
|||
String tabUrl = (url != null && Uri.parse(url).getScheme() != null) ? url : null;
|
||||
|
||||
// Add the new tab to the end of the tab order.
|
||||
final int tabIndex = -1;
|
||||
final int tabIndex = NEW_LAST_INDEX;
|
||||
|
||||
tabToSelect = addTab(tabId, tabUrl, external, parentId, url, isPrivate, tabIndex, type);
|
||||
tabToSelect.setDesktopMode(desktopMode);
|
||||
|
|
|
@ -106,8 +106,7 @@ public abstract class TabsLayout extends RecyclerView
|
|||
switch (msg) {
|
||||
case ADDED:
|
||||
int tabIndex = Integer.parseInt(data);
|
||||
// A tabIndex of -1 means "add a new last tab".
|
||||
tabIndex = tabIndex == -1 ? tabsAdapter.getItemCount() : tabIndex;
|
||||
tabIndex = tabIndex == Tabs.NEW_LAST_INDEX ? tabsAdapter.getItemCount() : tabIndex;
|
||||
tabsAdapter.notifyTabInserted(tab, tabIndex);
|
||||
if (addAtIndexRequiresScroll(tabIndex)) {
|
||||
// (The SELECTED tab is updated *after* this call to ADDED, so don't just call
|
||||
|
|
Загрузка…
Ссылка в новой задаче