org.chromium.chrome.browser.tabmodel.TabModelUtils Java Examples
The following examples show how to use
org.chromium.chrome.browser.tabmodel.TabModelUtils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TabWebContentsDelegateAndroid.java From delion with Apache License 2.0 | 6 votes |
@Override public void activateContents() { boolean activityIsDestroyed = false; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { activityIsDestroyed = mTab.getActivity().isDestroyed(); } if (activityIsDestroyed || !mTab.isInitialized()) { Log.e(TAG, "Activity destroyed before calling activateContents(). Bailing out."); return; } TabModel model = getTabModel(); int index = model.indexOf(mTab); if (index == TabModel.INVALID_TAB_INDEX) return; TabModelUtils.setIndex(model, index); bringActivityToForeground(); }
Example #2
Source File: StripLayoutHelper.java From delion with Apache License 2.0 | 6 votes |
/** * Displays the tab menu below the anchor tab. * @param anchorTab The tab the menu will be anchored to */ private void showTabMenu(StripLayoutTab anchorTab) { // 1. Bring the anchor tab to the foreground. int tabIndex = TabModelUtils.getTabIndexById(mModel, anchorTab.getId()); TabModelUtils.setIndex(mModel, tabIndex); // 2. Anchor the popupMenu to the view associated with the tab View tabView = TabModelUtils.getCurrentTab(mModel).getView(); mTabMenu.setAnchorView(tabView); // 3. Set the vertical offset to align the tab menu with bottom of the tab strip int verticalOffset = -(tabView.getHeight() - (int) mContext.getResources().getDimension(R.dimen.tab_strip_height)) - ((MarginLayoutParams) tabView.getLayoutParams()).topMargin; mTabMenu.setVerticalOffset(verticalOffset); // 4. Set the horizontal offset to align the tab menu with the right side of the tab int horizontalOffset = Math.round((anchorTab.getDrawX() + anchorTab.getWidth()) * mContext.getResources().getDisplayMetrics().density) - mTabMenu.getWidth() - ((MarginLayoutParams) tabView.getLayoutParams()).leftMargin; mTabMenu.setHorizontalOffset(horizontalOffset); mTabMenu.show(); }
Example #3
Source File: TileGroupDelegateImpl.java From 365browser with Apache License 2.0 | 6 votes |
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private boolean switchToExistingTab(String url) { String matchPattern = CommandLine.getInstance().getSwitchValue(ChromeSwitches.NTP_SWITCH_TO_EXISTING_TAB); boolean matchByHost; if ("url".equals(matchPattern)) { matchByHost = false; } else if ("host".equals(matchPattern)) { matchByHost = true; } else { return false; } TabModel tabModel = mTabModelSelector.getModel(false); for (int i = tabModel.getCount() - 1; i >= 0; --i) { if (matchURLs(tabModel.getTabAt(i).getUrl(), url, matchByHost)) { TabModelUtils.setIndex(tabModel, i); return true; } } return false; }
Example #4
Source File: LayoutManagerDocument.java From delion with Apache License 2.0 | 6 votes |
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void changeTabs() { DocumentTabModelSelector selector = ChromeApplication.getDocumentTabModelSelector(); TabModel tabModel = selector.getCurrentModel(); int currentIndex = tabModel.index(); if (mLastScroll == ScrollDirection.LEFT) { if (currentIndex < tabModel.getCount() - 1) { TabModelUtils.setIndex(tabModel, currentIndex + 1); } } else { if (currentIndex > 0) { TabModelUtils.setIndex(tabModel, currentIndex - 1); } } }
Example #5
Source File: StripLayoutHelper.java From delion with Apache License 2.0 | 6 votes |
/** * Called when a tab get selected. * @param time The current time of the app in ms. * @param id The id of the selected tab. * @param prevId The id of the previously selected tab. */ public void tabSelected(long time, int id, int prevId) { StripLayoutTab stripTab = findTabById(id); if (stripTab == null) { tabCreated(time, id, prevId, true); } else { updateVisualTabOrdering(); // If the tab was selected through a method other than the user tapping on the strip, it // may not be currently visible. Scroll if necessary. bringSelectedTabToVisibleArea(time, true); mUpdateHost.requestUpdate(); setAccessibilityDescription(stripTab, TabModelUtils.getTabById(mModel, id)); setAccessibilityDescription(findTabById(prevId), TabModelUtils.getTabById(mModel, prevId)); } }
Example #6
Source File: NewTabPage.java From 365browser with Apache License 2.0 | 6 votes |
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private boolean switchToExistingTab(String url) { String matchPattern = CommandLine.getInstance().getSwitchValue( ChromeSwitches.NTP_SWITCH_TO_EXISTING_TAB); boolean matchByHost; if ("url".equals(matchPattern)) { matchByHost = false; } else if ("host".equals(matchPattern)) { matchByHost = true; } else { return false; } TabModel tabModel = mTabModelSelector.getModel(false); for (int i = tabModel.getCount() - 1; i >= 0; --i) { if (matchURLs(tabModel.getTabAt(i).getUrl(), url, matchByHost)) { TabModelUtils.setIndex(tabModel, i); return true; } } return false; }
Example #7
Source File: Stack.java From delion with Apache License 2.0 | 6 votes |
/** * Creates a {@link StackTab}. * This function should ONLY be called from {@link #tabCreated(long, int)} and nowhere else. * * @param id The id of the tab. * @return Whether the tab has successfully been created and added. */ private boolean createTabHelper(int id) { if (TabModelUtils.getTabById(mTabModel, id) == null) return false; // Check to see if the tab already exists in our model. This is // just to cover the case where stackEntered and then tabCreated() // called in a row. if (mStackTabs != null) { final int count = mStackTabs.length; for (int i = 0; i < count; ++i) { if (mStackTabs[i].getId() == id) { return false; } } } createStackTabs(true); return true; }
Example #8
Source File: Stack.java From 365browser with Apache License 2.0 | 6 votes |
/** * Creates a {@link StackTab}. * This function should ONLY be called from {@link #tabCreated(long, int)} and nowhere else. * * @param id The id of the tab. * @return Whether the tab has successfully been created and added. */ private boolean createTabHelper(int id) { if (TabModelUtils.getTabById(mTabModel, id) == null) return false; // Check to see if the tab already exists in our model. This is // just to cover the case where stackEntered and then tabCreated() // called in a row. if (mStackTabs != null) { final int count = mStackTabs.length; for (int i = 0; i < count; ++i) { if (mStackTabs[i].getId() == id) { return false; } } } createStackTabs(true); return true; }
Example #9
Source File: LayoutManagerDocument.java From 365browser with Apache License 2.0 | 6 votes |
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void changeTabs() { DocumentTabModelSelector selector = ChromeApplication.getDocumentTabModelSelector(); TabModel tabModel = selector.getCurrentModel(); int currentIndex = tabModel.index(); if (mLastScroll == ScrollDirection.LEFT) { if (currentIndex < tabModel.getCount() - 1) { TabModelUtils.setIndex(tabModel, currentIndex + 1); } } else { if (currentIndex > 0) { TabModelUtils.setIndex(tabModel, currentIndex - 1); } } }
Example #10
Source File: StripLayoutHelper.java From AndroidChromium with Apache License 2.0 | 6 votes |
/** * Called when a tab get selected. * @param time The current time of the app in ms. * @param id The id of the selected tab. * @param prevId The id of the previously selected tab. */ public void tabSelected(long time, int id, int prevId) { StripLayoutTab stripTab = findTabById(id); if (stripTab == null) { tabCreated(time, id, prevId, true); } else { updateVisualTabOrdering(); // If the tab was selected through a method other than the user tapping on the strip, it // may not be currently visible. Scroll if necessary. bringSelectedTabToVisibleArea(time, true); mUpdateHost.requestUpdate(); setAccessibilityDescription(stripTab, TabModelUtils.getTabById(mModel, id)); setAccessibilityDescription(findTabById(prevId), TabModelUtils.getTabById(mModel, prevId)); } }
Example #11
Source File: StripLayoutHelper.java From 365browser with Apache License 2.0 | 6 votes |
/** * Called when a tab get selected. * @param time The current time of the app in ms. * @param id The id of the selected tab. * @param prevId The id of the previously selected tab. */ public void tabSelected(long time, int id, int prevId) { StripLayoutTab stripTab = findTabById(id); if (stripTab == null) { tabCreated(time, id, prevId, true); } else { updateVisualTabOrdering(); // If the tab was selected through a method other than the user tapping on the strip, it // may not be currently visible. Scroll if necessary. bringSelectedTabToVisibleArea(time, true); mUpdateHost.requestUpdate(); setAccessibilityDescription(stripTab, TabModelUtils.getTabById(mModel, id)); setAccessibilityDescription(findTabById(prevId), TabModelUtils.getTabById(mModel, prevId)); } }
Example #12
Source File: TabWebContentsDelegateAndroid.java From AndroidChromium with Apache License 2.0 | 6 votes |
@Override public void activateContents() { boolean activityIsDestroyed = false; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { activityIsDestroyed = mTab.getActivity().isDestroyed(); } if (activityIsDestroyed || !mTab.isInitialized()) { Log.e(TAG, "Activity destroyed before calling activateContents(). Bailing out."); return; } TabModel model = getTabModel(); int index = model.indexOf(mTab); if (index == TabModel.INVALID_TAB_INDEX) return; TabModelUtils.setIndex(model, index); bringActivityToForeground(); }
Example #13
Source File: LayoutManagerDocument.java From AndroidChromium with Apache License 2.0 | 6 votes |
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void changeTabs() { DocumentTabModelSelector selector = ChromeApplication.getDocumentTabModelSelector(); TabModel tabModel = selector.getCurrentModel(); int currentIndex = tabModel.index(); if (mLastScroll == ScrollDirection.LEFT) { if (currentIndex < tabModel.getCount() - 1) { TabModelUtils.setIndex(tabModel, currentIndex + 1); } } else { if (currentIndex > 0) { TabModelUtils.setIndex(tabModel, currentIndex - 1); } } }
Example #14
Source File: Stack.java From AndroidChromium with Apache License 2.0 | 6 votes |
/** * Creates a {@link StackTab}. * This function should ONLY be called from {@link #tabCreated(long, int)} and nowhere else. * * @param id The id of the tab. * @return Whether the tab has successfully been created and added. */ private boolean createTabHelper(int id) { if (TabModelUtils.getTabById(mTabModel, id) == null) return false; // Check to see if the tab already exists in our model. This is // just to cover the case where stackEntered and then tabCreated() // called in a row. if (mStackTabs != null) { final int count = mStackTabs.length; for (int i = 0; i < count; ++i) { if (mStackTabs[i].getId() == id) { return false; } } } createStackTabs(true); return true; }
Example #15
Source File: Stack.java From 365browser with Apache License 2.0 | 5 votes |
/** * Called when the user has cancelled a swipe; most likely if they have dragged their finger * back to the starting position. Some handlers will throw swipeFinished() instead. * @param time The current time of the app in ms. */ public void swipeCancelled(long time) { if (!mInSwipe) return; mDiscardingTab = null; mInSwipe = false; setWarpState(true, true); mEvenOutProgress = 0.f; // Select the current tab so we exit the switcher. Tab tab = TabModelUtils.getCurrentTab(mTabModel); mLayout.uiSelectingTab(time, tab != null ? tab.getId() : Tab.INVALID_TAB_ID); }
Example #16
Source File: TabWebContentsDelegateAndroid.java From 365browser with Apache License 2.0 | 5 votes |
@Override public void activateContents() { ChromeActivity activity = mTab.getActivity(); if (activity == null) { Log.e(TAG, "Activity not set activateContents(). Bailing out."); return; } if (activity.isActivityDestroyed()) { Log.e(TAG, "Activity destroyed before calling activateContents(). Bailing out."); return; } if (!mTab.isInitialized()) { Log.e(TAG, "Tab not initialized before calling activateContents(). Bailing out."); return; } // Do nothing if the tab can currently be interacted with by the user. if (mTab.isUserInteractable()) return; TabModel model = getTabModel(); int index = model.indexOf(mTab); if (index == TabModel.INVALID_TAB_INDEX) return; TabModelUtils.setIndex(model, index); // Do nothing if the activity is visible (STOPPED is the only valid invisible state as we // explicitly check isActivityDestroyed above). if (ApplicationStatus.getStateForActivity(activity) == ActivityState.STOPPED) { bringActivityToForeground(); } }
Example #17
Source File: StackLayout.java From 365browser with Apache License 2.0 | 5 votes |
/** * Get the tab stack state for the specified tab id. * * @param tabId The id of the tab to lookup. * @return The tab stack index for the given tab id. * @VisibleForTesting */ protected int getTabStackIndex(int tabId) { if (tabId == Tab.INVALID_TAB_ID) { boolean incognito = mTemporarySelectedStack != null ? mTemporarySelectedStack : mTabModelSelector.isIncognitoSelected(); return incognito ? 1 : 0; } else { return TabModelUtils.getTabById(mTabModelSelector.getModel(true), tabId) != null ? 1 : 0; } }
Example #18
Source File: StackLayout.java From 365browser with Apache License 2.0 | 5 votes |
/** * Called when a UI element is done animating the close tab effect started by * {@link #uiRequestingCloseTab(long, int)}. This actually pushes the close event to the model. * @param time The current time of the app in ms. * @param id The id of the tab to close. * @param canUndo Whether or not this close can be undone. * @param incognito Whether or not this was for the incognito stack or not. */ public void uiDoneClosingTab(long time, int id, boolean canUndo, boolean incognito) { // If homepage is enabled and there is a maximum of 1 tab in both models // (this is the last tab), the tab closure cannot be undone. canUndo &= !(HomepageManager.isHomepageEnabled(getContext()) && (mTabModelSelector.getModel(true).getCount() + mTabModelSelector.getModel(false).getCount() < 2)); // Propagate the tab closure to the model. TabModelUtils.closeTabById(mTabModelSelector.getModel(incognito), id, canUndo); }
Example #19
Source File: StripLayoutHelper.java From 365browser with Apache License 2.0 | 5 votes |
/** * Called on onDown event. * @param time The time stamp in millisecond of the event. * @param x The x position of the event. * @param y The y position of the event. * @param fromMouse Whether the event originates from a mouse. * @param buttons State of all buttons that are pressed. */ public void onDown(long time, float x, float y, boolean fromMouse, int buttons) { resetResizeTimeout(false); if (mNewTabButton.onDown(x, y)) { mRenderHost.requestRender(); return; } final StripLayoutTab clickedTab = getTabAtPosition(x); final int index = clickedTab != null ? TabModelUtils.getTabIndexById(mModel, clickedTab.getId()) : TabModel.INVALID_TAB_INDEX; // http://crbug.com/472186 : Needs to handle a case that index is invalid. // The case could happen when the current tab is touched while we're inflating the rest of // the tabs from disk. mInteractingTab = index != TabModel.INVALID_TAB_INDEX && index < mStripTabs.length ? mStripTabs[index] : null; boolean clickedClose = clickedTab != null && clickedTab.checkCloseHitTest(x, y); if (clickedClose) { clickedTab.setClosePressed(true); mLastPressedCloseButton = clickedTab.getCloseButton(); mRenderHost.requestRender(); } if (!mScroller.isFinished()) { mScroller.forceFinished(true); mInteractingTab = null; } if (fromMouse && !clickedClose && clickedTab != null && clickedTab.getVisiblePercentage() >= 1.f && (buttons & MotionEvent.BUTTON_TERTIARY) == 0) { startReorderMode(time, x, x); } }
Example #20
Source File: SuggestionsNavigationDelegateImpl.java From 365browser with Apache License 2.0 | 5 votes |
private boolean openRecentTabSnippet(SnippetArticle article) { TabModel tabModel = mTabModelSelector.getModel(false); int tabId = article.getRecentTabId(); int tabIndex = TabModelUtils.getTabIndexById(tabModel, tabId); if (tabIndex == TabModel.INVALID_TAB_INDEX) return false; TabModelUtils.setIndex(tabModel, tabIndex); return true; }
Example #21
Source File: OverviewListLayout.java From 365browser with Apache License 2.0 | 5 votes |
@Override public void onTabsAllClosing(long time, boolean incognito) { super.onTabsAllClosing(time, incognito); TabModel model = mTabModelSelector.getModel(incognito); while (model.getCount() > 0) TabModelUtils.closeTabByIndex(model, 0); if (incognito) { mTabModelSelector.selectModel(!incognito); } if (mTabModelWrapper == null) return; mTabModelWrapper.setStateBasedOnModel(); }
Example #22
Source File: AccessibilityTabModelAdapter.java From AndroidChromium with Apache License 2.0 | 5 votes |
@Override public void tabClosed(int tab) { if (mActualTabModel.isClosurePending(tab)) { mActualTabModel.commitTabClosure(tab); } else { TabModelUtils.closeTabById(mActualTabModel, tab); } notifyDataSetChanged(); }
Example #23
Source File: AccessibilityTabModelAdapter.java From AndroidChromium with Apache License 2.0 | 5 votes |
@Override public void tabSelected(int tab) { if (mListener != null) mListener.showTab(tab); TabModelUtils.setIndex(mActualTabModel, TabModelUtils.getTabIndexById(mActualTabModel, tab)); notifyDataSetChanged(); }
Example #24
Source File: OverviewListLayout.java From AndroidChromium with Apache License 2.0 | 5 votes |
@Override public void onTabsAllClosing(long time, boolean incognito) { super.onTabsAllClosing(time, incognito); TabModel model = mTabModelSelector.getModel(incognito); while (model.getCount() > 0) TabModelUtils.closeTabByIndex(model, 0); if (incognito) { mTabModelSelector.selectModel(!incognito); } if (mTabModelWrapper == null) return; mTabModelWrapper.setStateBasedOnModel(); }
Example #25
Source File: AccessibilityTabModelAdapter.java From 365browser with Apache License 2.0 | 5 votes |
@Override public void tabSelected(int tab) { if (mListener != null) mListener.showTab(tab); TabModelUtils.setIndex(mActualTabModel, TabModelUtils.getTabIndexById(mActualTabModel, tab)); notifyDataSetChanged(); }
Example #26
Source File: CustomTabLayoutManager.java From AndroidChromium with Apache License 2.0 | 5 votes |
@Override public void didAddTab(Tab tab, TabLaunchType type) { if (type == TabLaunchType.FROM_RESTORE) { getActiveLayout().onTabRestored(time(), tab.getId()); } else { int newIndex = TabModelUtils.getTabIndexById(getTabModelSelector().getModel(false), tab.getId()); getActiveLayout().onTabCreated(time(), tab.getId(), newIndex, getTabModelSelector().getCurrentTabId(), false, false, 0f, 0f); } }
Example #27
Source File: StackLayout.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * Called when a UI element is done animating the close tab effect started by * {@link #uiRequestingCloseTab(long, int)}. This actually pushes the close event to the model. * @param time The current time of the app in ms. * @param id The id of the tab to close. * @param canUndo Whether or not this close can be undone. * @param incognito Whether or not this was for the incognito stack or not. */ public void uiDoneClosingTab(long time, int id, boolean canUndo, boolean incognito) { // If homepage is enabled and there is a maximum of 1 tab in both models // (this is the last tab), the tab closure cannot be undone. canUndo &= !(HomepageManager.isHomepageEnabled(getContext()) && (mTabModelSelector.getModel(true).getCount() + mTabModelSelector.getModel(false).getCount() < 2)); // Propagate the tab closure to the model. TabModelUtils.closeTabById(mTabModelSelector.getModel(incognito), id, canUndo); }
Example #28
Source File: AccessibilityTabModelAdapter.java From 365browser with Apache License 2.0 | 5 votes |
@Override public void tabClosed(int tab) { if (mActualTabModel.isClosurePending(tab)) { mActualTabModel.commitTabClosure(tab); } else { TabModelUtils.closeTabById(mActualTabModel, tab); } notifyDataSetChanged(); }
Example #29
Source File: StackLayout.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * Get the tab stack state for the specified tab id. * * @param tabId The id of the tab to lookup. * @return The tab stack index for the given tab id. * @VisibleForTesting */ protected int getTabStackIndex(int tabId) { if (tabId == Tab.INVALID_TAB_ID) { boolean incognito = mTemporarySelectedStack != null ? mTemporarySelectedStack : mTabModelSelector.isIncognitoSelected(); return incognito ? 1 : 0; } else { return TabModelUtils.getTabById(mTabModelSelector.getModel(true), tabId) != null ? 1 : 0; } }
Example #30
Source File: StripLayoutHelper.java From 365browser with Apache License 2.0 | 5 votes |
private void startReorderMode(long time, float currentX, float startX) { if (mInReorderMode) return; // 1. Reset the last pressed close button state. if (mLastPressedCloseButton != null && mLastPressedCloseButton.isPressed()) { mLastPressedCloseButton.setPressed(false); } mLastPressedCloseButton = null; // 2. Check to see if we have a valid tab to start dragging. mInteractingTab = getTabAtPosition(startX); if (mInteractingTab == null) return; // 3. Set initial state parameters. mLastReorderScrollTime = 0; mReorderState = REORDER_SCROLL_NONE; mLastReorderX = startX; mInReorderMode = true; // 4. Select this tab so that it is always in the foreground. TabModelUtils.setIndex( mModel, TabModelUtils.getTabIndexById(mModel, mInteractingTab.getId())); // 5. Fast expand to make sure this tab is visible. If tabs are not cascaded, the selected // tab will already be visible, so there's no need to fast expand to make it visible. if (mShouldCascadeTabs) { float fastExpandDelta = calculateOffsetToMakeTabVisible(mInteractingTab, true, true, true); mScroller.startScroll(mScrollOffset, 0, (int) fastExpandDelta, 0, time, EXPAND_DURATION_MS); } // 6. Request an update. mUpdateHost.requestUpdate(); }