org.chromium.chrome.browser.tabmodel.TabModel Java Examples

The following examples show how to use org.chromium.chrome.browser.tabmodel.TabModel. 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: LayoutManagerChrome.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void destroy() {
    super.destroy();
    if (mTabModelSelectorObserver != null) {
        getTabModelSelector().removeObserver(mTabModelSelectorObserver);
    }
    if (mTabModelObserver != null) {
        for (TabModel model : getTabModelSelector().getModels()) {
            model.removeObserver(mTabModelObserver);
        }
    }
    if (mTabSelectorTabObserver != null) mTabSelectorTabObserver.destroy();
    mOverviewModeObservers.clear();

    if (mOverviewLayout != null) {
        mOverviewLayout.destroy();
        mOverviewLayout = null;
    }
    mOverviewListLayout.destroy();
    mToolbarSwipeLayout.destroy();
}
 
Example #2
Source File: UmaSessionStats.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private void recordPageLoadStats(Tab tab) {
    WebContents webContents = tab.getWebContents();
    boolean isDesktopUserAgent = webContents != null
            && webContents.getNavigationController().getUseDesktopUserAgent();
    nativeRecordPageLoaded(isDesktopUserAgent);
    if (mKeyboardConnected) {
        nativeRecordPageLoadedWithKeyboard();
    }

    // If the session has ended (i.e. chrome is in the background), escape early. Ideally we
    // could track this number as part of either the previous or next session but this isn't
    // possible since the TabSelector is needed to figure out the current number of open tabs.
    if (mTabModelSelector == null) return;

    TabModel regularModel = mTabModelSelector.getModel(false);
    nativeRecordTabCountPerLoad(getTabCountFromModel(regularModel));
}
 
Example #3
Source File: SeparateTaskManagedCustomTabActivity.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
protected IntentHandlerDelegate createIntentHandlerDelegate() {
    return new IntentHandlerDelegate() {
        @Override
        public void processWebSearchIntent(String query) {
        }

        @Override
        public void processUrlViewIntent(String url, String referer, String headers,
                TabOpenType tabOpenType, String externalAppId, int tabIdToBringToFront,
                boolean hasUserGesture, Intent intent) {
            Tab currentTab = getTabCreator(false).launchUrlFromExternalApp(
                    url, referer, headers, externalAppId, true, intent, mIntentHandlingTimeMs);

            // Close all existing tabs from the previous session.
            TabModel tabModel = getTabModelSelector().getModel(false);
            for (int i = tabModel.getCount() - 1; i >= 0; i--) {
                if (tabModel.getTabAt(i).equals(currentTab)) continue;
                tabModel.closeTab(tabModel.getTabAt(i), false, false, false);
            }
        }
    };
}
 
Example #4
Source File: StaticLayout.java    From delion with Apache License 2.0 6 votes vote down vote up
private void setStaticTab(final int id) {
    if (mLayoutTabs != null && mLayoutTabs.length > 0 && mLayoutTabs[0].getId() == id) {
        if (!mLayoutTabs[0].shouldStall()) setPostHideState();
        return;
    }
    TabModel model = mTabModelSelector.getModelForTabId(id);
    if (model == null) return;
    updateCacheVisibleIds(new LinkedList<Integer>(Arrays.asList(id)));
    if (mLayoutTabs == null || mLayoutTabs.length != 1) mLayoutTabs = new LayoutTab[1];
    mLayoutTabs[0] = createLayoutTab(id, model.isIncognito(), NO_CLOSE_BUTTON, NO_TITLE);
    mLayoutTabs[0].setDrawDecoration(false);
    if (mLayoutTabs[0].shouldStall()) {
        setPreHideState();
        mHandler.postDelayed(mUnstallRunnable, HIDE_TIMEOUT_MS);
    } else {
        setPostHideState();
    }
    requestRender();
}
 
Example #5
Source File: TileGroupDelegateImpl.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@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 #6
Source File: SimpleAnimationLayout.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Set up for the tab closing animation
 */
@Override
public void onTabClosing(long time, int id) {
    reset();

    // Make sure any currently running animations can't influence tab if we are reusing it.
    forceAnimationToFinish();

    // Create the {@link LayoutTab} for the tab before it is destroyed.
    TabModel model = mTabModelSelector.getModelForTabId(id);
    if (model != null) {
        mClosedTab = createLayoutTab(id, model.isIncognito(), NO_CLOSE_BUTTON, NO_TITLE);
        mClosedTab.setBorderAlpha(0.0f);
        mLayoutTabs = new LayoutTab[] {mClosedTab};
        updateCacheVisibleIds(new LinkedList<Integer>(Arrays.asList(id)));
    } else {
        mLayoutTabs = null;
        mClosedTab = null;
    }
    // Only close the id at the end when we are done querying the model.
    super.onTabClosing(time, id);
}
 
Example #7
Source File: SeparateTaskManagedCustomTabActivity.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
protected IntentHandlerDelegate createIntentHandlerDelegate() {
    return new IntentHandlerDelegate() {
        @Override
        public void processWebSearchIntent(String query) {
        }

        @Override
        public void processUrlViewIntent(String url, String referer, String headers,
                TabOpenType tabOpenType, String externalAppId, int tabIdToBringToFront,
                boolean hasUserGesture, Intent intent) {
            Tab currentTab = getTabCreator(false).launchUrlFromExternalApp(
                    url, referer, headers, externalAppId, true, intent, mIntentHandlingTimeMs);

            // Close all existing tabs from the previous session.
            TabModel tabModel = getTabModelSelector().getModel(false);
            for (int i = tabModel.getCount() - 1; i >= 0; i--) {
                if (tabModel.getTabAt(i).equals(currentTab)) continue;
                tabModel.closeTab(tabModel.getTabAt(i), false, false, false);
            }
        }
    };
}
 
Example #8
Source File: StackViewAnimation.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * The wrapper method responsible for delegating animation requests to the appropriate helper
 * method.
 * @param type       The type of animation to be created.  This is what determines which helper
 *                   method is called.
 * @param tabs       The tabs that make up the current stack.
 * @param container  The {@link ViewGroup} that {@link View}s can be added to/removed from.
 * @param model      The {@link TabModel} that this animation will influence.
 * @param focusIndex The index of the tab that is the focus of this animation.
 * @return           The resulting {@link Animator} that will animate the Android views.
 */
public Animator createAnimatorForType(OverviewAnimationType type, StackTab[] tabs,
        ViewGroup container, TabModel model, int focusIndex) {
    Animator animator = null;

    if (model != null) {
        switch (type) {
            case NEW_TAB_OPENED:
                animator = createNewTabOpenedAnimator(tabs, container, model, focusIndex);
                break;
            default:
                break;
        }
    }

    return animator;
}
 
Example #9
Source File: StackViewAnimation.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * The wrapper method responsible for delegating animation requests to the appropriate helper
 * method.
 * @param type       The type of animation to be created.  This is what determines which helper
 *                   method is called.
 * @param tabs       The tabs that make up the current stack.
 * @param container  The {@link ViewGroup} that {@link View}s can be added to/removed from.
 * @param model      The {@link TabModel} that this animation will influence.
 * @param focusIndex The index of the tab that is the focus of this animation.
 * @return           The resulting {@link Animator} that will animate the Android views.
 */
public Animator createAnimatorForType(OverviewAnimationType type, StackTab[] tabs,
        ViewGroup container, TabModel model, int focusIndex) {
    Animator animator = null;

    if (model != null) {
        switch (type) {
            case NEW_TAB_OPENED:
                animator = createNewTabOpenedAnimator(tabs, container, model, focusIndex);
                break;
            default:
                break;
        }
    }

    return animator;
}
 
Example #10
Source File: UmaSessionStats.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private void recordPageLoadStats(Tab tab) {
    WebContents webContents = tab.getWebContents();
    boolean isDesktopUserAgent = webContents != null
            && webContents.getNavigationController().getUseDesktopUserAgent();
    nativeRecordPageLoaded(isDesktopUserAgent);
    if (mKeyboardConnected) {
        nativeRecordPageLoadedWithKeyboard();
    }

    // If the session has ended (i.e. chrome is in the background), escape early. Ideally we
    // could track this number as part of either the previous or next session but this isn't
    // possible since the TabSelector is needed to figure out the current number of open tabs.
    if (mTabModelSelector == null) return;

    TabModel regularModel = mTabModelSelector.getModel(false);
    nativeRecordTabCountPerLoad(getTabCountFromModel(regularModel));
}
 
Example #11
Source File: StaticLayout.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private void setStaticTab(final int id) {
    if (mLayoutTabs != null && mLayoutTabs.length > 0 && mLayoutTabs[0].getId() == id) {
        if (!mLayoutTabs[0].shouldStall()) setPostHideState();
        return;
    }
    TabModel model = mTabModelSelector.getModelForTabId(id);
    if (model == null) return;
    updateCacheVisibleIds(new LinkedList<Integer>(Arrays.asList(id)));
    if (mLayoutTabs == null || mLayoutTabs.length != 1) mLayoutTabs = new LayoutTab[1];
    mLayoutTabs[0] = createLayoutTab(id, model.isIncognito(), NO_CLOSE_BUTTON, NO_TITLE);
    mLayoutTabs[0].setDrawDecoration(false);
    if (mLayoutTabs[0].shouldStall()) {
        setPreHideState();
        mHandler.postDelayed(mUnstallRunnable, HIDE_TIMEOUT_MS);
    } else {
        setPostHideState();
    }
    requestRender();
}
 
Example #12
Source File: LayoutManagerDocument.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@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 #13
Source File: SimpleAnimationLayout.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Set up for the tab closing animation
 */
@Override
public void onTabClosing(long time, int id) {
    reset();

    // Make sure any currently running animations can't influence tab if we are reusing it.
    forceAnimationToFinish();

    // Create the {@link LayoutTab} for the tab before it is destroyed.
    TabModel model = mTabModelSelector.getModelForTabId(id);
    if (model != null) {
        mClosedTab = createLayoutTab(id, model.isIncognito(), NO_CLOSE_BUTTON, NO_TITLE);
        mClosedTab.setBorderAlpha(0.0f);
        mLayoutTabs = new LayoutTab[] {mClosedTab};
        updateCacheVisibleIds(new LinkedList<Integer>(Arrays.asList(id)));
    } else {
        mLayoutTabs = null;
        mClosedTab = null;
    }
    // Only close the id at the end when we are done querying the model.
    super.onTabClosing(time, id);
}
 
Example #14
Source File: ChromeTabbedActivity.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void onDestroyInternal() {
    if (mLayoutManager != null) mLayoutManager.removeOverviewModeObserver(this);

    if (mTabModelSelectorTabObserver != null) {
        mTabModelSelectorTabObserver.destroy();
        mTabModelSelectorTabObserver = null;
    }

    if (mTabModelObserver != null) {
        for (TabModel model : mTabModelSelectorImpl.getModels()) {
            model.removeObserver(mTabModelObserver);
        }
    }

    if (mUndoBarPopupController != null) {
        mUndoBarPopupController.destroy();
        mUndoBarPopupController = null;
    }

    super.onDestroyInternal();
}
 
Example #15
Source File: LayoutManagerChrome.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void destroy() {
    super.destroy();
    if (mTabModelSelectorObserver != null) {
        getTabModelSelector().removeObserver(mTabModelSelectorObserver);
    }
    if (mTabModelObserver != null) {
        for (TabModel model : getTabModelSelector().getModels()) {
            model.removeObserver(mTabModelObserver);
        }
    }
    if (mTabSelectorTabObserver != null) mTabSelectorTabObserver.destroy();
    mOverviewModeObservers.clear();

    if (mOverviewLayout != null) {
        mOverviewLayout.destroy();
        mOverviewLayout = null;
    }
    mOverviewListLayout.destroy();
    mToolbarSwipeLayout.destroy();
}
 
Example #16
Source File: StaticLayout.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private void setStaticTab(final int id) {
    if (mLayoutTabs != null && mLayoutTabs.length > 0 && mLayoutTabs[0].getId() == id) {
        if (!mLayoutTabs[0].shouldStall()) setPostHideState();
        return;
    }
    TabModel model = mTabModelSelector.getModelForTabId(id);
    if (model == null) return;

    updateCacheVisibleIdsAndPrimary(new LinkedList<Integer>(Arrays.asList(id)), id);

    if (mLayoutTabs == null || mLayoutTabs.length != 1) mLayoutTabs = new LayoutTab[1];
    mLayoutTabs[0] = createLayoutTab(id, model.isIncognito(), NO_CLOSE_BUTTON, NO_TITLE);
    mLayoutTabs[0].setDrawDecoration(false);
    if (mLayoutTabs[0].shouldStall()) {
        setPreHideState();
        mHandler.postDelayed(mUnstallRunnable, HIDE_TIMEOUT_MS);
    } else {
        setPostHideState();
    }
    requestRender();
}
 
Example #17
Source File: ContextReporter.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Stops reporting context. Called when the app goes to the background.
 */
public void disable() {
    reportUsageEndedIfNecessary();

    if (mSelectorTabObserver != null) {
        mSelectorTabObserver.destroy();
        mSelectorTabObserver = null;
    }
    if (mModelObserver != null) {
        for (TabModel model : mActivity.getTabModelSelector().getModels()) {
            model.removeObserver(mModelObserver);
        }
        mModelObserver = null;
    }
    if (mContextualSearchObserver != null && mActivity.getContextualSearchManager() != null) {
        mActivity.getContextualSearchManager().removeObserver(mContextualSearchObserver);
        mContextualSearchObserver = null;
    }
}
 
Example #18
Source File: SeparateTaskManagedCustomTabActivity.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
protected IntentHandlerDelegate createIntentHandlerDelegate() {
    return new IntentHandlerDelegate() {
        @Override
        public void processWebSearchIntent(String query) {
        }

        @Override
        public void processUrlViewIntent(String url, String referer, String headers,
                TabOpenType tabOpenType, String externalAppId, int tabIdToBringToFront,
                boolean hasUserGesture, Intent intent) {
            Tab currentTab = getTabCreator(false).launchUrlFromExternalApp(
                    url, referer, headers, externalAppId, true, intent, mIntentHandlingTimeMs);

            // Close all existing tabs from the previous session.
            TabModel tabModel = getTabModelSelector().getModel(false);
            for (int i = tabModel.getCount() - 1; i >= 0; i--) {
                if (tabModel.getTabAt(i).equals(currentTab)) continue;
                tabModel.closeTab(tabModel.getTabAt(i), false, false, false);
            }
        }
    };
}
 
Example #19
Source File: SimpleAnimationLayout.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Set up for the tab closing animation
 */
@Override
public void onTabClosing(long time, int id) {
    reset();

    // Make sure any currently running animations can't influence tab if we are reusing it.
    forceAnimationToFinish();

    // Create the {@link LayoutTab} for the tab before it is destroyed.
    TabModel model = mTabModelSelector.getModelForTabId(id);
    if (model != null) {
        mClosedTab = createLayoutTab(id, model.isIncognito(), NO_CLOSE_BUTTON, NO_TITLE);
        mClosedTab.setBorderAlpha(0.0f);
        mLayoutTabs = new LayoutTab[] {mClosedTab};
        updateCacheVisibleIds(new LinkedList<Integer>(Arrays.asList(id)));
    } else {
        mLayoutTabs = null;
        mClosedTab = null;
    }
    // Only close the id at the end when we are done querying the model.
    super.onTabClosing(time, id);
}
 
Example #20
Source File: NewTabPage.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@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 #21
Source File: Stack.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Animates a new tab opening.
 *
 * @param time The current time of the app in ms.
 * @param id The id of the new tab to animate.
 */
public void tabCreated(long time, int id) {
    if (!createTabHelper(id)) return;

    mIsDying = false;
    finishAnimation(time);
    startAnimation(time, OverviewAnimationType.NEW_TAB_OPENED,
            TabModelUtils.getTabIndexById(mTabModel, id), TabModel.INVALID_TAB_INDEX, false);
}
 
Example #22
Source File: DocumentTabModelSelector.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
public DocumentTabModelSelector(ActivityDelegate activityDelegate,
        StorageDelegate storageDelegate, TabDelegate regularTabDelegate,
        TabDelegate incognitoTabDelegate) {
    mActivityDelegate = activityDelegate;
    mStorageDelegate =
            sStorageDelegateForTests == null ? storageDelegate : sStorageDelegateForTests;
    mRegularTabDelegate = regularTabDelegate;
    mIncognitoTabDelegate = incognitoTabDelegate;

    final Context context = ContextUtils.getApplicationContext();
    mRegularTabModel = new DocumentTabModelImpl(
            mActivityDelegate, mStorageDelegate, this, false, sPrioritizedTabId, context);
    mIncognitoTabModel = new IncognitoDocumentTabModel(new IncognitoTabModelDelegate() {
        @Override
        public TabModel createTabModel() {
            DocumentTabModel incognitoModel = new DocumentTabModelImpl(mActivityDelegate,
                    mStorageDelegate, DocumentTabModelSelector.this, true, sPrioritizedTabId,
                    context);
            return incognitoModel;
        }

        @Override
        public boolean doIncognitoTabsExist() {
            // TODO(dfalcantara): Devices in document mode do not trigger the TabWindowManager.
            //                    Revisit this when we have a Samsung L multi-instance device.
            return mIncognitoTabModel.getCount() > 0;
        }
    }, mActivityDelegate);
    initializeTabIdCounter();

    // Re-select the previously selected TabModel.
    SharedPreferences prefs = context.getSharedPreferences(PREF_PACKAGE, Context.MODE_PRIVATE);
    boolean startIncognito = prefs.getBoolean(PREF_IS_INCOGNITO_SELECTED, false);
    initialize(startIncognito, mRegularTabModel, mIncognitoTabModel);
}
 
Example #23
Source File: IncognitoToggleButtonTablet.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
protected void onAttachedToWindow() {
    if (mTabModelSelector != null) {
        mTabModelSelector.addObserver(mTabModelSelectorObserver);
        for (TabModel model : mTabModelSelector.getModels()) {
            model.addObserver(mTabModelObserver);
        }
    }
    super.onAttachedToWindow();
}
 
Example #24
Source File: IncognitoToggleButtonTablet.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDetachedFromWindow() {
    if (mTabModelSelector != null) {
        mTabModelSelector.removeObserver(mTabModelSelectorObserver);
        for (TabModel model : mTabModelSelector.getModels()) {
            model.removeObserver(mTabModelObserver);
        }
    }
    super.onDetachedFromWindow();
}
 
Example #25
Source File: IncognitoToggleButtonTablet.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
protected void onAttachedToWindow() {
    if (mTabModelSelector != null) {
        mTabModelSelector.addObserver(mTabModelSelectorObserver);
        for (TabModel model : mTabModelSelector.getModels()) {
            model.addObserver(mTabModelObserver);
        }
    }
    super.onAttachedToWindow();
}
 
Example #26
Source File: FindToolbar.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Call this just before closing the find toolbar.
 * @param clearSelection Whether the selection on the page should be cleared.
 */
public void deactivate(boolean clearSelection) {
    if (!mActive) return;

    if (mObserver != null) mObserver.onFindToolbarHidden();

    setResultsBarVisibility(false);

    mTabModelSelector.removeObserver(mTabModelSelectorObserver);
    for (TabModel model : mTabModelSelector.getModels()) {
        model.removeObserver(mTabModelObserver);
    }

    mCurrentTab.getTabWebContentsDelegateAndroid().setFindResultListener(null);
    mCurrentTab.getTabWebContentsDelegateAndroid().setFindMatchRectsListener(null);
    mCurrentTab.removeObserver(mTabObserver);

    UiUtils.hideKeyboard(mFindQuery);
    if (mFindQuery.getText().length() > 0) {
        clearResults();
        mFindInPageBridge.stopFinding(clearSelection);
    }

    mFindInPageBridge.destroy();
    mFindInPageBridge = null;
    mCurrentTab = null;
    mActive = false;
}
 
Example #27
Source File: ContextualSearchManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/** Stops listening for notifications that should hide the Contextual Search bar. */
private void stopListeningForHideNotifications() {
    if (mTabModelSelectorTabObserver != null) mTabModelSelectorTabObserver.destroy();

    TabModelSelector selector = mActivity.getTabModelSelector();
    if (selector != null) {
        for (TabModel tabModel : selector.getModels()) {
            tabModel.removeObserver(mTabModelObserver);
        }
    }
}
 
Example #28
Source File: EmptyBackgroundViewWrapper.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Unregister all dependencies and listeners.
 */
public void uninitialize() {
    for (TabModel model : mTabModelSelector.getModels()) {
        model.removeObserver(mTabModelObserver);
    }
    mTabModelSelector.removeObserver(mTabModelSelectorObserver);
}
 
Example #29
Source File: ChromeActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void createContextualSearchTab(String searchUrl) {
    Tab currentTab = getActivityTab();
    if (currentTab == null) return;

    TabCreator tabCreator = getTabCreator(currentTab.isIncognito());
    if (tabCreator == null) return;

    tabCreator.createNewTab(
            new LoadUrlParams(searchUrl, PageTransition.LINK),
            TabModel.TabLaunchType.FROM_LINK, getActivityTab());
}
 
Example #30
Source File: StripLayoutHelper.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    }
}