use of org.chromium.content.browser.ContentViewCore 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.content.browser.ContentViewCore 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);
}
}
}
}
use of org.chromium.content.browser.ContentViewCore in project AndroidChromium by JackyAndroid.
the class CompositorViewHolder method setContentViewMotionEventOffsets.
private void setContentViewMotionEventOffsets(MotionEvent e, boolean canClear) {
// TODO(dtrainor): Factor this out to LayoutDriver.
if (e == null || mTabVisible == null)
return;
ContentViewCore contentViewCore = mTabVisible.getContentViewCore();
if (contentViewCore == null)
return;
int actionMasked = e.getActionMasked();
if (SPenSupport.isSPenSupported(getContext())) {
actionMasked = SPenSupport.convertSPenEventAction(actionMasked);
}
if (actionMasked == MotionEvent.ACTION_DOWN || actionMasked == MotionEvent.ACTION_HOVER_ENTER) {
if (mLayoutManager != null)
mLayoutManager.getViewportPixel(mCacheViewport);
contentViewCore.setCurrentTouchEventOffsets(-mCacheViewport.left, -mCacheViewport.top);
} else if (canClear && (actionMasked == MotionEvent.ACTION_UP || actionMasked == MotionEvent.ACTION_CANCEL || actionMasked == MotionEvent.ACTION_HOVER_EXIT)) {
contentViewCore.setCurrentTouchEventOffsets(0.f, 0.f);
}
}
use of org.chromium.content.browser.ContentViewCore in project AndroidChromium by JackyAndroid.
the class OverlayPanel method resizePanelContentViewCore.
/**
* Resize the panel's ContentViewCore manually since it is not attached to the view hierarchy.
* TODO(mdjones): Remove the need for this method by supporting multiple ContentViewCores
* existing simultaneously in the view hierarchy.
* @param width The new width in dp.
* @param height The new height in dp.
*/
protected void resizePanelContentViewCore(float width, float height) {
if (!isShowing())
return;
ContentViewCore panelContent = getContentViewCore();
if (panelContent != null) {
panelContent.onSizeChanged((int) (width / mPxToDp), (int) (height / mPxToDp), panelContent.getViewportWidthPix(), panelContent.getViewportHeightPix());
panelContent.onPhysicalBackingSizeChanged((int) (width / mPxToDp), (int) (height / mPxToDp));
}
}
use of org.chromium.content.browser.ContentViewCore in project AndroidChromium by JackyAndroid.
the class CompositorViewHolder method updateContentOverlayVisibility.
private void updateContentOverlayVisibility(boolean show) {
if (mView == null)
return;
ContentViewCore content = getActiveContent();
if (show) {
if (mView.getParent() != this) {
// During tab creation, we temporarily add the new tab's view to a FrameLayout to
// measure and lay it out. This way we could show the animation in the stack view.
// Therefore we should remove the view from that temporary FrameLayout here.
UiUtils.removeViewFromParent(mView);
if (content != null) {
assert content.isAlive();
content.getContainerView().setVisibility(View.VISIBLE);
if (mFullscreenManager != null) {
mFullscreenManager.updateContentViewViewportSize(content);
}
}
CoordinatorLayout.LayoutParams layoutParams;
if (mView.getLayoutParams() instanceof CoordinatorLayout.LayoutParams) {
layoutParams = (CoordinatorLayout.LayoutParams) mView.getLayoutParams();
} else {
layoutParams = new CoordinatorLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
}
layoutParams.setBehavior(mView.getBehavior());
// CompositorView has index of 0; TabContentViewParent has index of 1; omnibox
// result container (the scrim) has index of 2, Snackbar (if any) has index of 3.
// Setting index here explicitly to avoid TabContentViewParent hiding the scrim.
// TODO(ianwen): Use more advanced technologies to ensure z-order of the children of
// this class, instead of hard-coding.
addView(mView, 1, layoutParams);
setFocusable(false);
setFocusableInTouchMode(false);
// Claim focus for the new view unless the user is currently using the URL bar.
if (mUrlBar == null || !mUrlBar.hasFocus())
mView.requestFocus();
}
} else {
if (mView.getParent() == this) {
setFocusable(true);
setFocusableInTouchMode(true);
if (content != null) {
if (content.isAlive())
content.getContainerView().setVisibility(View.INVISIBLE);
}
removeView(mView);
}
}
}
Aggregations