Java Code Examples for org.chromium.content.browser.ContentViewCore#getContainerView()

The following examples show how to use org.chromium.content.browser.ContentViewCore#getContainerView() . 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: ContextMenuHelper.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Starts showing a context menu for {@code view} based on {@code params}.
 * @param contentViewCore The {@link ContentViewCore} to show the menu to.
 * @param params          The {@link ContextMenuParams} that indicate what menu items to show.
 */
@CalledByNative
private boolean showContextMenu(ContentViewCore contentViewCore, ContextMenuParams params) {
    final View view = contentViewCore.getContainerView();

    if (view == null
            || view.getVisibility() != View.VISIBLE
            || view.getParent() == null) {
        return false;
    }

    mCurrentContextMenuParams = params;

    view.setOnCreateContextMenuListener(this);
    if (view.showContextMenu()) {
        WebContents webContents = contentViewCore.getWebContents();
        RecordHistogram.recordBooleanHistogram(
                "ContextMenu.Shown", webContents != null);
        if (webContents != null) webContents.onContextMenuOpened();
        return true;
    }
    return false;
}
 
Example 2
Source File: ChromeFullscreenManager.java    From delion with Apache License 2.0 6 votes vote down vote up
private boolean shouldShowAndroidControls() {
    if (mTopControlsAndroidViewHidden) return false;

    boolean showControls = getControlOffset() == 0;
    ContentViewCore contentViewCore = getActiveContentViewCore();
    if (contentViewCore == null) return showControls;
    ViewGroup contentView = contentViewCore.getContainerView();

    for (int i = 0; i < contentView.getChildCount(); i++) {
        View child = contentView.getChildAt(i);
        if (!(child.getLayoutParams() instanceof FrameLayout.LayoutParams)) continue;

        FrameLayout.LayoutParams layoutParams =
                (FrameLayout.LayoutParams) child.getLayoutParams();
        if (Gravity.TOP == (layoutParams.gravity & Gravity.FILL_VERTICAL)) {
            showControls = true;
            break;
        }
    }

    showControls |= !mPersistentControlTokens.isEmpty();

    return showControls;
}
 
Example 3
Source File: ContextMenuHelper.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Starts showing a context menu for {@code view} based on {@code params}.
 * @param contentViewCore The {@link ContentViewCore} to show the menu to.
 * @param params          The {@link ContextMenuParams} that indicate what menu items to show.
 */
@CalledByNative
private void showContextMenu(ContentViewCore contentViewCore, ContextMenuParams params) {
    final View view = contentViewCore.getContainerView();

    if (view == null
            || view.getVisibility() != View.VISIBLE
            || view.getParent() == null) {
        return;
    }

    mCurrentContextMenuParams = params;

    view.setOnCreateContextMenuListener(this);
    if (view.showContextMenu()) {
        WebContents webContents = contentViewCore.getWebContents();
        RecordHistogram.recordBooleanHistogram(
                "ContextMenu.Shown", webContents != null);
    }
}
 
Example 4
Source File: ChromeFullscreenManager.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private boolean shouldShowAndroidControls() {
    if (mBrowserControlsAndroidViewHidden) return false;

    boolean showControls = !drawControlsAsTexture();
    ContentViewCore contentViewCore = getActiveContentViewCore();
    if (contentViewCore == null) return showControls;
    ViewGroup contentView = contentViewCore.getContainerView();

    for (int i = 0; i < contentView.getChildCount(); i++) {
        View child = contentView.getChildAt(i);
        if (!(child.getLayoutParams() instanceof FrameLayout.LayoutParams)) continue;

        FrameLayout.LayoutParams layoutParams =
                (FrameLayout.LayoutParams) child.getLayoutParams();
        if (Gravity.TOP == (layoutParams.gravity & Gravity.FILL_VERTICAL)) {
            showControls = true;
            break;
        }
    }

    return showControls;
}
 
Example 5
Source File: ChromeFullscreenManager.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private boolean shouldShowAndroidControls() {
    if (mBrowserControlsAndroidViewHidden) return false;

    boolean showControls = !drawControlsAsTexture();
    ContentViewCore contentViewCore = getActiveContentViewCore();
    if (contentViewCore == null) return showControls;
    ViewGroup contentView = contentViewCore.getContainerView();

    for (int i = 0; i < contentView.getChildCount(); i++) {
        View child = contentView.getChildAt(i);
        if (!(child.getLayoutParams() instanceof FrameLayout.LayoutParams)) continue;

        FrameLayout.LayoutParams layoutParams =
                (FrameLayout.LayoutParams) child.getLayoutParams();
        if (Gravity.TOP == (layoutParams.gravity & Gravity.FILL_VERTICAL)) {
            showControls = true;
            break;
        }
    }

    return showControls;
}
 
Example 6
Source File: ChromeFullscreenManager.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public void updateContentViewChildrenState() {
    ContentViewCore contentViewCore = getActiveContentViewCore();
    if (contentViewCore == null) return;
    ViewGroup view = contentViewCore.getContainerView();

    float topViewsTranslation = (getControlOffset() + mControlContainerHeight);
    applyTranslationToTopChildViews(view, topViewsTranslation);
    applyMarginToFullChildViews(view, topViewsTranslation);
    updateContentViewViewportSize(contentViewCore);
}
 
Example 7
Source File: ChromeFullscreenManager.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void updateContentViewChildrenState() {
    ContentViewCore contentViewCore = getActiveContentViewCore();
    if (contentViewCore == null) return;
    ViewGroup view = contentViewCore.getContainerView();

    float topViewsTranslation = getTopVisibleContentOffset();
    applyTranslationToTopChildViews(view, topViewsTranslation);
    applyMarginToFullChildViews(view, topViewsTranslation);
    updateContentViewViewportSize(contentViewCore);
}
 
Example 8
Source File: CompositorViewHolder.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Adjusts the physical backing size of a given ContentViewCore. This method checks
 * the associated container view to see if the size needs to be overriden, such as when used for
 * {@link OverlayPanel}.
 * @param contentViewCore The {@link ContentViewCore} to resize.
 * @param width The default width.
 * @param height The default height.
 */
private void adjustPhysicalBackingSize(ContentViewCore contentViewCore, int width, int height) {
    ContentView contentView = (ContentView) contentViewCore.getContainerView();
    if (contentView == mOverlayContentView) {
        width = MeasureSpec.getSize(mOverlayContentWidthMeasureSpec);
        height = MeasureSpec.getSize(mOverlayContentHeightMeasureSpec);
    }
    mCompositorView.onPhysicalBackingSizeChanged(
            contentViewCore.getWebContents(), width, height);
}
 
Example 9
Source File: ChromeFullscreenManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void updateContentViewChildrenState() {
    ContentViewCore contentViewCore = getActiveContentViewCore();
    if (contentViewCore == null) return;
    ViewGroup view = contentViewCore.getContainerView();

    float topViewsTranslation = getTopVisibleContentOffset();
    applyTranslationToTopChildViews(view, topViewsTranslation);
    applyMarginToFullChildViews(view, topViewsTranslation);
    updateContentViewViewportSize(contentViewCore);
}
 
Example 10
Source File: OverlayPanelEventFilter.java    From delion with Apache License 2.0 4 votes vote down vote up
/**
 * Propagates the given {@link MotionEvent} to the {@link ContentViewCore}.
 * @param e The {@link MotionEvent} to be propagated.
 */
protected void propagateEventToContentViewCore(MotionEvent e) {
    MotionEvent event = e;
    int action = event.getActionMasked();
    boolean isSyntheticEvent = false;
    if (mGestureOrientation == GestureOrientation.HORIZONTAL && !mPanel.isMaximized()) {
        // Ignores multitouch events to prevent the Content View from scrolling.
        if (action == MotionEvent.ACTION_POINTER_UP
                || action == MotionEvent.ACTION_POINTER_DOWN) {
            return;
        }

        // NOTE(pedrosimonetti): Lock horizontal motion, ignoring all vertical changes,
        // when the Panel is not maximized. This is to prevent the Content View
        // from scrolling when side swiping on the expanded Panel. Also, note that the
        // method {@link OverlayPanelEventFilter#lockEventHorizontallty} will always
        // return an event with a single pointer, which is necessary to prevent
        // the app from crashing when the motion involves multiple pointers.
        // See: crbug.com/486901
        event = MotionEvent.obtain(
                e.getDownTime(),
                e.getEventTime(),
                // NOTE(pedrosimonetti): Use getActionMasked() to make sure we're not
                // send any pointer information to the event, given that getAction()
                // may have the pointer Id associated to it.
                e.getActionMasked(),
                e.getX(),
                mInitialEventY,
                e.getMetaState());

        isSyntheticEvent = true;
    }

    final float contentViewOffsetXPx = mPanel.getContentX() / mPxToDp;
    final float contentViewOffsetYPx = mPanel.getContentY() / mPxToDp;

    // Adjust the offset to be relative to the Content View.
    event.offsetLocation(-contentViewOffsetXPx, -contentViewOffsetYPx);

    // Get the container view to propagate the event to.
    ContentViewCore cvc = mPanel.getContentViewCore();
    ViewGroup containerView = cvc == null ? null : cvc.getContainerView();

    boolean wasEventCanceled = false;
    if (mWasActionDownEventSynthetic && action == MotionEvent.ACTION_UP) {
        float deltaX = event.getX() - mSyntheticActionDownX;
        float deltaY = event.getY() - mSyntheticActionDownY;
        // NOTE(pedrosimonetti): If the ACTION_DOWN event was synthetic and the distance
        // between it and the ACTION_UP event was short, then we should synthesize an
        // ACTION_CANCEL event to prevent a Tap gesture from being triggered on the
        // Content View. See crbug.com/408654
        if (!isDistanceGreaterThanTouchSlop(deltaX, deltaY)) {
            event.setAction(MotionEvent.ACTION_CANCEL);
            if (containerView != null) containerView.dispatchTouchEvent(event);
            wasEventCanceled = true;
        }
    } else if (action == MotionEvent.ACTION_DOWN) {
        mPanel.onTouchSearchContentViewAck();
    }

    if (!wasEventCanceled && containerView != null) containerView.dispatchTouchEvent(event);

    // Synthetic events should be recycled.
    if (isSyntheticEvent) event.recycle();
}
 
Example 11
Source File: OverlayPanelEventFilter.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Propagates the given {@link MotionEvent} to the {@link ContentViewCore}.
 * @param e The {@link MotionEvent} to be propagated.
 */
protected void propagateEventToContentViewCore(MotionEvent e) {
    MotionEvent event = e;
    int action = event.getActionMasked();
    boolean isSyntheticEvent = false;
    if (mGestureOrientation == GestureOrientation.HORIZONTAL && !mPanel.isMaximized()) {
        // Ignores multitouch events to prevent the Content View from scrolling.
        if (action == MotionEvent.ACTION_POINTER_UP
                || action == MotionEvent.ACTION_POINTER_DOWN) {
            return;
        }

        // NOTE(pedrosimonetti): Lock horizontal motion, ignoring all vertical changes,
        // when the Panel is not maximized. This is to prevent the Content View
        // from scrolling when side swiping on the expanded Panel. Also, note that the
        // method {@link OverlayPanelEventFilter#lockEventHorizontallty} will always
        // return an event with a single pointer, which is necessary to prevent
        // the app from crashing when the motion involves multiple pointers.
        // See: crbug.com/486901
        event = MotionEvent.obtain(
                e.getDownTime(),
                e.getEventTime(),
                // NOTE(pedrosimonetti): Use getActionMasked() to make sure we're not
                // send any pointer information to the event, given that getAction()
                // may have the pointer Id associated to it.
                e.getActionMasked(),
                e.getX(),
                mInitialEventY,
                e.getMetaState());

        isSyntheticEvent = true;
    }

    final float contentViewOffsetXPx = mPanel.getContentX() / mPxToDp;
    final float contentViewOffsetYPx = mPanel.getContentY() / mPxToDp;

    // Adjust the offset to be relative to the Content View.
    event.offsetLocation(-contentViewOffsetXPx, -contentViewOffsetYPx);

    // Get the container view to propagate the event to.
    ContentViewCore cvc = mPanel.getContentViewCore();
    ViewGroup containerView = cvc == null ? null : cvc.getContainerView();

    boolean wasEventCanceled = false;
    if (mWasActionDownEventSynthetic && action == MotionEvent.ACTION_UP) {
        float deltaX = event.getX() - mSyntheticActionDownX;
        float deltaY = event.getY() - mSyntheticActionDownY;
        // NOTE(pedrosimonetti): If the ACTION_DOWN event was synthetic and the distance
        // between it and the ACTION_UP event was short, then we should synthesize an
        // ACTION_CANCEL event to prevent a Tap gesture from being triggered on the
        // Content View. See crbug.com/408654
        if (!isDistanceGreaterThanTouchSlop(deltaX, deltaY)) {
            event.setAction(MotionEvent.ACTION_CANCEL);
            if (containerView != null) containerView.dispatchTouchEvent(event);
            wasEventCanceled = true;
        }
    } else if (action == MotionEvent.ACTION_DOWN) {
        mPanel.onTouchSearchContentViewAck();
    }

    if (!wasEventCanceled && containerView != null) containerView.dispatchTouchEvent(event);

    // Synthetic events should be recycled.
    if (isSyntheticEvent) event.recycle();
}
 
Example 12
Source File: ContextMenuHelper.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Starts showing a context menu for {@code view} based on {@code params}.
 * @param contentViewCore The {@link ContentViewCore} to show the menu to.
 * @param params          The {@link ContextMenuParams} that indicate what menu items to show.
 */
@CalledByNative
private void showContextMenu(final ContentViewCore contentViewCore, ContextMenuParams params) {
    if (params.isFile()) return;
    View view = contentViewCore.getContainerView();
    final WindowAndroid windowAndroid = contentViewCore.getWindowAndroid();

    if (view == null || view.getVisibility() != View.VISIBLE || view.getParent() == null
            || windowAndroid == null || windowAndroid.getActivity().get() == null
            || mPopulator == null) {
        return;
    }

    mCurrentContextMenuParams = params;
    mActivity = windowAndroid.getActivity().get();
    mCallback = new Callback<Integer>() {
        @Override
        public void onResult(Integer result) {
            mPopulator.onItemSelected(
                    ContextMenuHelper.this, mCurrentContextMenuParams, result);
        }
    };
    mOnMenuShown = new Runnable() {
        @Override
        public void run() {
            WebContents webContents = contentViewCore.getWebContents();
            RecordHistogram.recordBooleanHistogram("ContextMenu.Shown", webContents != null);
        }
    };
    mOnMenuClosed = new Runnable() {
        @Override
        public void run() {
            if (mNativeContextMenuHelper == 0) return;
            nativeOnContextMenuClosed(mNativeContextMenuHelper);
        }
    };

    if (ChromeFeatureList.isEnabled(ChromeFeatureList.CUSTOM_CONTEXT_MENU)) {
        List<Pair<Integer, List<ContextMenuItem>>> items =
                mPopulator.buildContextMenu(null, mActivity, mCurrentContextMenuParams);
        if (items.isEmpty()) {
            ThreadUtils.postOnUiThread(mOnMenuClosed);
            return;
        }

        final ContextMenuUi menuUi = new TabularContextMenuUi(new Runnable() {
            @Override
            public void run() {
                shareImageDirectly(ShareHelper.getLastShareComponentName());
            }
        });
        menuUi.displayMenu(mActivity, mCurrentContextMenuParams, items, mCallback, mOnMenuShown,
                mOnMenuClosed);
        if (mCurrentContextMenuParams.isImage()) {
            getThumbnail(new Callback<Bitmap>() {
                @Override
                public void onResult(Bitmap result) {
                    ((TabularContextMenuUi) menuUi).onImageThumbnailRetrieved(result);
                }
            });
        }
        return;
    }

    // The Platform Context Menu requires the listener within this hepler since this helper and
    // provides context menu for us to show.
    view.setOnCreateContextMenuListener(this);
    if (view.showContextMenu()) {
        mOnMenuShown.run();
        windowAndroid.addContextMenuCloseListener(new OnCloseContextMenuListener() {
            @Override
            public void onContextMenuClosed() {
                mOnMenuClosed.run();
                windowAndroid.removeContextMenuCloseListener(this);
            }
        });
    }
}
 
Example 13
Source File: OverlayPanelEventFilter.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Propagates the given {@link MotionEvent} to the {@link ContentViewCore}.
 * @param e The {@link MotionEvent} to be propagated.
 */
protected void propagateEventToContentViewCore(MotionEvent e) {
    MotionEvent event = e;
    int action = event.getActionMasked();
    boolean isSyntheticEvent = false;
    if (mGestureOrientation == GestureOrientation.HORIZONTAL && !mPanel.isMaximized()) {
        // Ignores multitouch events to prevent the Content View from scrolling.
        if (action == MotionEvent.ACTION_POINTER_UP
                || action == MotionEvent.ACTION_POINTER_DOWN) {
            return;
        }

        // NOTE(pedrosimonetti): Lock horizontal motion, ignoring all vertical changes,
        // when the Panel is not maximized. This is to prevent the Content View
        // from scrolling when side swiping on the expanded Panel. Also, note that the
        // method {@link OverlayPanelEventFilter#lockEventHorizontallty} will always
        // return an event with a single pointer, which is necessary to prevent
        // the app from crashing when the motion involves multiple pointers.
        // See: crbug.com/486901
        event = MotionEvent.obtain(
                e.getDownTime(),
                e.getEventTime(),
                // NOTE(pedrosimonetti): Use getActionMasked() to make sure we're not
                // send any pointer information to the event, given that getAction()
                // may have the pointer Id associated to it.
                e.getActionMasked(),
                e.getX(),
                mInitialEventY,
                e.getMetaState());

        isSyntheticEvent = true;
    }

    final float contentViewOffsetXPx = mPanel.getContentX() / mPxToDp;
    final float contentViewOffsetYPx = mPanel.getContentY() / mPxToDp;

    // Adjust the offset to be relative to the Content View.
    event.offsetLocation(-contentViewOffsetXPx, -contentViewOffsetYPx);

    // Get the container view to propagate the event to.
    ContentViewCore cvc = mPanel.getContentViewCore();
    ViewGroup containerView = cvc == null ? null : cvc.getContainerView();

    boolean wasEventCanceled = false;
    if (mWasActionDownEventSynthetic && action == MotionEvent.ACTION_UP) {
        float deltaX = event.getX() - mSyntheticActionDownX;
        float deltaY = event.getY() - mSyntheticActionDownY;
        // NOTE(pedrosimonetti): If the ACTION_DOWN event was synthetic and the distance
        // between it and the ACTION_UP event was short, then we should synthesize an
        // ACTION_CANCEL event to prevent a Tap gesture from being triggered on the
        // Content View. See crbug.com/408654
        if (!isDistanceGreaterThanTouchSlop(deltaX, deltaY)) {
            event.setAction(MotionEvent.ACTION_CANCEL);
            if (containerView != null) containerView.dispatchTouchEvent(event);
            wasEventCanceled = true;
        }
    } else if (action == MotionEvent.ACTION_DOWN) {
        mPanel.onTouchSearchContentViewAck();
    }

    if (!wasEventCanceled && containerView != null) containerView.dispatchTouchEvent(event);

    // Synthetic events should be recycled.
    if (isSyntheticEvent) event.recycle();
}
 
Example 14
Source File: ValidationMessageBubble.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private static boolean canShowBubble(ContentViewCore contentViewCore) {
    return contentViewCore.getContainerView() != null
            && contentViewCore.getContainerView().getWindowToken() != null;
}
 
Example 15
Source File: AwAutofillManagerDelegate.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void init(ContentViewCore contentViewCore) {
    mContentViewCore = contentViewCore;
    mContainerView = contentViewCore.getContainerView();
}
 
Example 16
Source File: AwAutofillManagerDelegate.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void init(ContentViewCore contentViewCore) {
    mContentViewCore = contentViewCore;
    mContainerView = contentViewCore.getContainerView();
}