use of org.chromium.chrome.browser.tabmodel.TabModel in project AndroidChromium by JackyAndroid.
the class ToolbarManager method initializeWithNative.
/**
* Initialize the manager with the components that had native initialization dependencies.
* <p>
* Calling this must occur after the native library have completely loaded.
*
* @param tabModelSelector The selector that handles tab management.
* @param controlsVisibilityDelegate The delegate to handle visibility of browser controls.
* @param findToolbarManager The manager for find in page.
* @param overviewModeBehavior The overview mode manager.
* @param layoutDriver A {@link LayoutManager} instance used to watch for scene
* changes.
*/
public void initializeWithNative(TabModelSelector tabModelSelector, BrowserStateBrowserControlsVisibilityDelegate controlsVisibilityDelegate, final FindToolbarManager findToolbarManager, final OverviewModeBehavior overviewModeBehavior, final LayoutManager layoutDriver, OnClickListener tabSwitcherClickHandler, OnClickListener newTabClickHandler, OnClickListener bookmarkClickHandler, OnClickListener customTabsBackClickHandler) {
assert !mInitializedWithNative;
mTabModelSelector = tabModelSelector;
mToolbar.getLocationBar().updateVisualsForState();
mToolbar.getLocationBar().setUrlToPageUrl();
mToolbar.setBrowserControlsVisibilityDelegate(controlsVisibilityDelegate);
mToolbar.setOnTabSwitcherClickHandler(tabSwitcherClickHandler);
mToolbar.setOnNewTabClickHandler(newTabClickHandler);
mToolbar.setBookmarkClickHandler(bookmarkClickHandler);
mToolbar.setCustomTabCloseClickHandler(customTabsBackClickHandler);
mToolbar.setLayoutUpdateHost(layoutDriver);
mToolbarModel.initializeWithNative();
mToolbar.addOnAttachStateChangeListener(new OnAttachStateChangeListener() {
@Override
public void onViewDetachedFromWindow(View v) {
Context context = mToolbar.getContext();
HomepageManager.getInstance(context).removeListener(mHomepageStateListener);
mTabModelSelector.removeObserver(mTabModelSelectorObserver);
for (TabModel model : mTabModelSelector.getModels()) {
model.removeObserver(mTabModelObserver);
}
if (mBookmarkBridge != null) {
mBookmarkBridge.destroy();
mBookmarkBridge = null;
}
if (mTemplateUrlObserver != null) {
TemplateUrlService.getInstance().removeObserver(mTemplateUrlObserver);
mTemplateUrlObserver = null;
}
// Remove all previously attached observers from the FindToolbarManager.
if (mFindToolbarManager != null) {
for (FindToolbarObserver observer : mFindToolbarObservers) {
mFindToolbarManager.removeObserver(observer);
}
}
if (overviewModeBehavior != null) {
overviewModeBehavior.removeOverviewModeObserver(mOverviewModeObserver);
}
if (layoutDriver != null) {
layoutDriver.removeSceneChangeObserver(mSceneChangeObserver);
}
}
@Override
public void onViewAttachedToWindow(View v) {
// As we have only just registered for notifications, any that were sent prior to
// this may have been missed.
// Calling refreshSelectedTab in case we missed the initial selection notification.
refreshSelectedTab();
}
});
mFindToolbarManager = findToolbarManager;
assert controlsVisibilityDelegate != null;
mControlsVisibilityDelegate = controlsVisibilityDelegate;
mNativeLibraryReady = false;
// Add observers to the FindToolbarManager.
if (mFindToolbarManager != null) {
for (FindToolbarObserver observer : mFindToolbarObservers) {
mFindToolbarManager.addObserver(observer);
}
}
if (overviewModeBehavior != null) {
overviewModeBehavior.addOverviewModeObserver(mOverviewModeObserver);
}
if (layoutDriver != null)
layoutDriver.addSceneChangeObserver(mSceneChangeObserver);
onNativeLibraryReady();
mInitializedWithNative = true;
}
use of org.chromium.chrome.browser.tabmodel.TabModel 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;
}
use of org.chromium.chrome.browser.tabmodel.TabModel in project AndroidChromium by JackyAndroid.
the class SimpleAnimationLayout method onTabClosing.
/**
* 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);
}
use of org.chromium.chrome.browser.tabmodel.TabModel in project AndroidChromium by JackyAndroid.
the class CustomTabTabPersistencePolicy method getAllTabIdsForActivity.
/**
* Get all current Tab IDs used by the specified activity.
*
* @param activity The activity whose tab IDs are to be collected from.
* @param tabIds Where the tab IDs should be added to.
*/
private static void getAllTabIdsForActivity(CustomTabActivity activity, Set<Integer> tabIds) {
if (activity == null)
return;
TabModelSelector selector = activity.getTabModelSelector();
if (selector == null)
return;
List<TabModel> models = selector.getModels();
for (int i = 0; i < models.size(); i++) {
TabModel model = models.get(i);
for (int j = 0; j < model.getCount(); j++) {
tabIds.add(model.getTabAt(j).getId());
}
}
}
Aggregations