Search in sources :

Example 66 with Tab

use of org.chromium.chrome.browser.tab.Tab in project AndroidChromium by JackyAndroid.

the class KeyboardShortcuts method onKeyDown.

/**
     * This should be called from the Activity's onKeyDown() to handle keyboard shortcuts.
     *
     * Note: onKeyDown() is called after the active view or web page has had a chance to handle
     * the key event. So the keys handled here *can* be overridden by any view or web page.
     *
     * @param event The KeyEvent to handle.
     * @param activity The ChromeActivity in which the key was pressed.
     * @param isCurrentTabVisible Whether page-related actions are valid, e.g. reload, zoom in.
     *                            This should be false when in the tab switcher.
     * @param tabSwitchingEnabled Whether shortcuts that switch between tabs are enabled (e.g.
     *                            Ctrl+Tab, Ctrl+3).
     * @return Whether the key event was handled.
     */
public static boolean onKeyDown(KeyEvent event, ChromeActivity activity, boolean isCurrentTabVisible, boolean tabSwitchingEnabled) {
    int keyCode = event.getKeyCode();
    if (event.getRepeatCount() != 0 || KeyEvent.isModifierKey(keyCode))
        return false;
    if (KeyEvent.isGamepadButton(keyCode)) {
        if (isGamepadAPIActive(activity))
            return false;
    } else if (!event.isCtrlPressed() && !event.isAltPressed() && keyCode != KeyEvent.KEYCODE_F3 && keyCode != KeyEvent.KEYCODE_F5 && keyCode != KeyEvent.KEYCODE_F10 && keyCode != KeyEvent.KEYCODE_FORWARD) {
        return false;
    }
    TabModel curModel = activity.getCurrentTabModel();
    int count = curModel.getCount();
    int metaState = getMetaState(event);
    int keyCodeAndMeta = keyCode | metaState;
    switch(keyCodeAndMeta) {
        case CTRL | SHIFT | KeyEvent.KEYCODE_T:
            activity.onMenuOrKeyboardAction(R.id.open_recently_closed_tab, false);
            return true;
        case CTRL | KeyEvent.KEYCODE_T:
            activity.onMenuOrKeyboardAction(curModel.isIncognito() ? R.id.new_incognito_tab_menu_id : R.id.new_tab_menu_id, false);
            return true;
        case CTRL | KeyEvent.KEYCODE_N:
            activity.onMenuOrKeyboardAction(R.id.new_tab_menu_id, false);
            return true;
        case CTRL | SHIFT | KeyEvent.KEYCODE_N:
            activity.onMenuOrKeyboardAction(R.id.new_incognito_tab_menu_id, false);
            return true;
        // the default dispatchKeyEvent and cannot open the menu.
        case ALT | KeyEvent.KEYCODE_E:
        case ALT | KeyEvent.KEYCODE_F:
        case KeyEvent.KEYCODE_F10:
        case KeyEvent.KEYCODE_BUTTON_Y:
            activity.onMenuOrKeyboardAction(R.id.show_menu, false);
            return true;
    }
    if (isCurrentTabVisible) {
        if (tabSwitchingEnabled && (metaState == CTRL || metaState == ALT)) {
            int numCode = keyCode - KeyEvent.KEYCODE_0;
            if (numCode > 0 && numCode <= Math.min(count, 8)) {
                // Ctrl+1 to Ctrl+8: select tab by index
                TabModelUtils.setIndex(curModel, numCode - 1);
                return true;
            } else if (numCode == 9 && count != 0) {
                // Ctrl+9: select last tab
                TabModelUtils.setIndex(curModel, count - 1);
                return true;
            }
        }
        switch(keyCodeAndMeta) {
            case CTRL | KeyEvent.KEYCODE_TAB:
            case CTRL | KeyEvent.KEYCODE_PAGE_DOWN:
            case KeyEvent.KEYCODE_BUTTON_R1:
                if (tabSwitchingEnabled && count > 1) {
                    TabModelUtils.setIndex(curModel, (curModel.index() + 1) % count);
                }
                return true;
            case CTRL | SHIFT | KeyEvent.KEYCODE_TAB:
            case CTRL | KeyEvent.KEYCODE_PAGE_UP:
            case KeyEvent.KEYCODE_BUTTON_L1:
                if (tabSwitchingEnabled && count > 1) {
                    TabModelUtils.setIndex(curModel, (curModel.index() + count - 1) % count);
                }
                return true;
            case CTRL | KeyEvent.KEYCODE_W:
            case CTRL | KeyEvent.KEYCODE_F4:
            case KeyEvent.KEYCODE_BUTTON_B:
                TabModelUtils.closeCurrentTab(curModel);
                return true;
            case CTRL | KeyEvent.KEYCODE_F:
            case CTRL | KeyEvent.KEYCODE_G:
            case CTRL | SHIFT | KeyEvent.KEYCODE_G:
            case KeyEvent.KEYCODE_F3:
            case SHIFT | KeyEvent.KEYCODE_F3:
                activity.onMenuOrKeyboardAction(R.id.find_in_page_id, false);
                return true;
            case CTRL | KeyEvent.KEYCODE_L:
            case ALT | KeyEvent.KEYCODE_D:
            case KeyEvent.KEYCODE_BUTTON_X:
                activity.onMenuOrKeyboardAction(R.id.focus_url_bar, false);
                return true;
            case CTRL | SHIFT | KeyEvent.KEYCODE_B:
                activity.onMenuOrKeyboardAction(R.id.all_bookmarks_menu_id, false);
                return true;
            case KeyEvent.KEYCODE_BOOKMARK:
            case CTRL | KeyEvent.KEYCODE_D:
                activity.onMenuOrKeyboardAction(R.id.bookmark_this_page_id, false);
                return true;
            case CTRL | KeyEvent.KEYCODE_H:
                activity.onMenuOrKeyboardAction(R.id.open_history_menu_id, false);
                return true;
            case CTRL | KeyEvent.KEYCODE_P:
                activity.onMenuOrKeyboardAction(R.id.print_id, false);
                return true;
            case CTRL | KeyEvent.KEYCODE_PLUS:
            case CTRL | KeyEvent.KEYCODE_EQUALS:
            case CTRL | SHIFT | KeyEvent.KEYCODE_PLUS:
            case CTRL | SHIFT | KeyEvent.KEYCODE_EQUALS:
            case KeyEvent.KEYCODE_ZOOM_IN:
                ContentViewCore cvc = activity.getCurrentContentViewCore();
                if (cvc != null)
                    cvc.zoomIn();
                return true;
            case CTRL | KeyEvent.KEYCODE_MINUS:
            case KeyEvent.KEYCODE_ZOOM_OUT:
                cvc = activity.getCurrentContentViewCore();
                if (cvc != null)
                    cvc.zoomOut();
                return true;
            case CTRL | KeyEvent.KEYCODE_0:
                cvc = activity.getCurrentContentViewCore();
                if (cvc != null)
                    cvc.zoomReset();
                return true;
            case SHIFT | CTRL | KeyEvent.KEYCODE_R:
            case CTRL | KeyEvent.KEYCODE_R:
            case SHIFT | KeyEvent.KEYCODE_F5:
            case KeyEvent.KEYCODE_F5:
                Tab tab = activity.getActivityTab();
                if (tab != null) {
                    if ((keyCodeAndMeta & SHIFT) == SHIFT) {
                        tab.reloadIgnoringCache();
                    } else {
                        tab.reload();
                    }
                    if (activity.getToolbarManager() != null && tab.getWebContents() != null && tab.getWebContents().focusLocationBarByDefault()) {
                        activity.getToolbarManager().revertLocationBarChanges();
                    } else {
                        tab.requestFocus();
                    }
                }
                return true;
            case ALT | KeyEvent.KEYCODE_DPAD_LEFT:
                tab = activity.getActivityTab();
                if (tab != null && tab.canGoBack())
                    tab.goBack();
                return true;
            case ALT | KeyEvent.KEYCODE_DPAD_RIGHT:
            case KeyEvent.KEYCODE_FORWARD:
            case KeyEvent.KEYCODE_BUTTON_START:
                tab = activity.getActivityTab();
                if (tab != null && tab.canGoForward())
                    tab.goForward();
                return true;
            case // i.e. Ctrl+?
            CTRL | SHIFT | KeyEvent.KEYCODE_SLASH:
                activity.onMenuOrKeyboardAction(R.id.help_id, false);
                return true;
        }
    }
    return false;
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab) ContentViewCore(org.chromium.content.browser.ContentViewCore) TabModel(org.chromium.chrome.browser.tabmodel.TabModel)

Example 67 with Tab

use of org.chromium.chrome.browser.tab.Tab in project AndroidChromium by JackyAndroid.

the class ActivityTabTaskDescriptionHelper method refreshSelectedTab.

private void refreshSelectedTab() {
    Tab tab = mTabModelSelector.getCurrentTab();
    if (mCurrentTab == tab)
        return;
    if (mCurrentTab != null)
        mCurrentTab.removeObserver(mTabObserver);
    mCurrentTab = tab;
    if (mCurrentTab != null) {
        mCurrentTab.addObserver(mTabObserver);
        final String currentUrl = mCurrentTab.getUrl();
        mFaviconHelper.getLocalFaviconImageForURL(mCurrentTab.getProfile(), mCurrentTab.getUrl(), 0, new FaviconHelper.FaviconImageCallback() {

            @Override
            public void onFaviconAvailable(Bitmap image, String iconUrl) {
                if (mCurrentTab == null || !TextUtils.equals(currentUrl, mCurrentTab.getUrl())) {
                    return;
                }
                updateFavicon(image);
            }
        });
    }
    updateTaskDescription();
}
Also used : FaviconHelper(org.chromium.chrome.browser.favicon.FaviconHelper) Bitmap(android.graphics.Bitmap) Tab(org.chromium.chrome.browser.tab.Tab)

Example 68 with Tab

use of org.chromium.chrome.browser.tab.Tab in project AndroidChromium by JackyAndroid.

the class ChromeActivity method createContextualSearchTab.

@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());
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab) LoadUrlParams(org.chromium.content_public.browser.LoadUrlParams)

Example 69 with Tab

use of org.chromium.chrome.browser.tab.Tab in project AndroidChromium by JackyAndroid.

the class ChromeTabbedActivity method toggleOverview.

private void toggleOverview() {
    Tab currentTab = getActivityTab();
    ContentViewCore contentViewCore = currentTab != null ? currentTab.getContentViewCore() : null;
    if (!mLayoutManager.overviewVisible()) {
        getCompositorViewHolder().hideKeyboard(new Runnable() {

            @Override
            public void run() {
                mLayoutManager.showOverview(true);
            }
        });
        if (contentViewCore != null) {
            contentViewCore.setAccessibilityState(false);
        }
    } else {
        Layout activeLayout = mLayoutManager.getActiveLayout();
        if (activeLayout instanceof StackLayout) {
            ((StackLayout) activeLayout).commitOutstandingModelState(LayoutManager.time());
        }
        if (getCurrentTabModel().getCount() != 0) {
            // Don't hide overview if current tab stack is empty()
            mLayoutManager.hideOverview(true);
            // hideOverview could change the current tab.  Update the local variables.
            currentTab = getActivityTab();
            contentViewCore = currentTab != null ? currentTab.getContentViewCore() : null;
            if (contentViewCore != null) {
                contentViewCore.setAccessibilityState(true);
            }
        }
    }
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab) ContentViewCore(org.chromium.content.browser.ContentViewCore) FrameLayout(android.widget.FrameLayout) StackLayout(org.chromium.chrome.browser.compositor.layouts.phone.StackLayout) Layout(org.chromium.chrome.browser.compositor.layouts.Layout) StackLayout(org.chromium.chrome.browser.compositor.layouts.phone.StackLayout)

Example 70 with Tab

use of org.chromium.chrome.browser.tab.Tab in project AndroidChromium by JackyAndroid.

the class ChromeWindow method showCallbackNonExistentError.

/**
     * Shows an infobar error message overriding the WindowAndroid implementation.
     */
@Override
protected void showCallbackNonExistentError(String error) {
    Activity activity = getActivity().get();
    // We can assume that activity is a ChromeActivity because we require one to be passed in
    // in the constructor.
    Tab tab = activity != null ? ((ChromeActivity) activity).getActivityTab() : null;
    if (tab != null) {
        SimpleConfirmInfoBarBuilder.create(tab, InfoBarIdentifier.CHROME_WINDOW_ERROR, error, false);
    } else {
        super.showCallbackNonExistentError(error);
    }
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab) Activity(android.app.Activity)

Aggregations

Tab (org.chromium.chrome.browser.tab.Tab)116 LayoutTab (org.chromium.chrome.browser.compositor.layouts.components.LayoutTab)13 TabModel (org.chromium.chrome.browser.tabmodel.TabModel)10 LoadUrlParams (org.chromium.content_public.browser.LoadUrlParams)9 SuppressLint (android.annotation.SuppressLint)8 TabModelSelectorTabObserver (org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver)8 Intent (android.content.Intent)5 FrameLayout (android.widget.FrameLayout)4 ContentViewCore (org.chromium.content.browser.ContentViewCore)4 WebContents (org.chromium.content_public.browser.WebContents)4 Activity (android.app.Activity)3 Bitmap (android.graphics.Bitmap)3 TabLaunchType (org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType)3 PendingIntent (android.app.PendingIntent)2 Context (android.content.Context)2 Bundle (android.os.Bundle)2 StrictMode (android.os.StrictMode)2 CustomTabsIntent (android.support.customtabs.CustomTabsIntent)2 MenuItem (android.view.MenuItem)2 View (android.view.View)2