Search in sources :

Example 1 with ContentViewClient

use of org.chromium.content.browser.ContentViewClient in project AndroidChromium by JackyAndroid.

the class OverlayPanelContent method createNewContentView.

/**
     * Create a new ContentViewCore that will be managed by this panel.
     */
private void createNewContentView() {
    if (mContentViewCore != null) {
        // then there's no need to create a new one.
        if (!mDidStartLoadingUrl)
            return;
        destroyContentView();
    }
    mContentViewCore = createContentViewCore(mActivity);
    if (mContentViewClient == null) {
        mContentViewClient = new ContentViewClient();
    }
    mContentViewCore.setContentViewClient(mContentViewClient);
    ContentView cv = ContentView.createContentView(mActivity, mContentViewCore);
    // Creates an initially hidden WebContents which gets shown when the panel is opened.
    WebContents panelWebContents = WebContentsFactory.createWebContents(false, true);
    // Dummny ViewAndroidDelegate since the container view for overlay panel is
    // never added to the view hierarchy.
    ViewAndroidDelegate delegate = new ViewAndroidDelegate() {

        private ViewGroup mContainerView;

        private ViewAndroidDelegate init(ViewGroup containerView) {
            mContainerView = containerView;
            return this;
        }

        @Override
        public View acquireView() {
            assert false : "Shold not reach here";
            return null;
        }

        @Override
        public void setViewPosition(View anchorView, float x, float y, float width, float height, float scale, int leftMargin, int topMargin) {
        }

        @Override
        public void removeView(View anchorView) {
        }

        @Override
        public ViewGroup getContainerView() {
            return mContainerView;
        }
    }.init(cv);
    mContentViewCore.initialize(delegate, cv, panelWebContents, mActivity.getWindowAndroid());
    // Transfers the ownership of the WebContents to the native OverlayPanelContent.
    nativeSetWebContents(mNativeOverlayPanelContentPtr, panelWebContents, mWebContentsDelegate);
    mWebContentsObserver = new WebContentsObserver(panelWebContents) {

        @Override
        public void didStartLoading(String url) {
            mContentDelegate.onContentLoadStarted(url);
        }

        @Override
        public void navigationEntryCommitted() {
            mContentDelegate.onNavigationEntryCommitted();
        }

        @Override
        public void didStartProvisionalLoadForFrame(long frameId, long parentFrameId, boolean isMainFrame, String validatedUrl, boolean isErrorPage, boolean isIframeSrcdoc) {
            if (isMainFrame) {
                mContentDelegate.onMainFrameLoadStarted(validatedUrl, !TextUtils.equals(validatedUrl, mLoadedUrl));
            }
        }

        @Override
        public void didNavigateMainFrame(String url, String baseUrl, boolean isNavigationToDifferentPage, boolean isNavigationInPage, int httpResultCode) {
            mIsProcessingPendingNavigation = false;
            mContentDelegate.onMainFrameNavigation(url, !TextUtils.equals(url, mLoadedUrl), isHttpFailureCode(httpResultCode));
        }

        @Override
        public void didFinishLoad(long frameId, String validatedUrl, boolean isMainFrame) {
            mContentDelegate.onContentLoadFinished();
        }
    };
    mInterceptNavigationDelegate = new InterceptNavigationDelegateImpl();
    nativeSetInterceptNavigationDelegate(mNativeOverlayPanelContentPtr, mInterceptNavigationDelegate, panelWebContents);
    mContentDelegate.onContentViewCreated(mContentViewCore);
}
Also used : WebContents(org.chromium.content_public.browser.WebContents) ContentView(org.chromium.content.browser.ContentView) ViewGroup(android.view.ViewGroup) ViewAndroidDelegate(org.chromium.ui.base.ViewAndroidDelegate) View(android.view.View) ContentView(org.chromium.content.browser.ContentView) ContentViewClient(org.chromium.content.browser.ContentViewClient) WebContentsObserver(org.chromium.content_public.browser.WebContentsObserver)

Example 2 with ContentViewClient

use of org.chromium.content.browser.ContentViewClient in project AndroidChromium by JackyAndroid.

the class OverlayPanel method createNewOverlayPanelContentInternal.

/**
     * Add any other objects that depend on the OverlayPanelContent having already been created.
     */
private OverlayPanelContent createNewOverlayPanelContentInternal() {
    OverlayPanelContent content = mContentFactory.createNewOverlayPanelContent();
    content.setContentViewClient(new ContentViewClient() {

        @Override
        public int getDesiredWidthMeasureSpec() {
            if (isFullWidthSizePanel()) {
                return super.getDesiredWidthMeasureSpec();
            } else {
                return MeasureSpec.makeMeasureSpec(getContentViewWidthPx(), MeasureSpec.EXACTLY);
            }
        }

        @Override
        public int getDesiredHeightMeasureSpec() {
            if (isFullWidthSizePanel()) {
                return super.getDesiredHeightMeasureSpec();
            } else {
                return MeasureSpec.makeMeasureSpec(getContentViewHeightPx(), MeasureSpec.EXACTLY);
            }
        }
    });
    return content;
}
Also used : ContentViewClient(org.chromium.content.browser.ContentViewClient)

Example 3 with ContentViewClient

use of org.chromium.content.browser.ContentViewClient in project AndroidChromium by JackyAndroid.

the class CompositorViewHolder method adjustPhysicalBackingSize.

/**
     * Adjusts the physical backing size of a given ContentViewCore. This method will first check
     * if the ContentViewCore's client wants to override the size and, if so, it will use the
     * values provided by the {@link ContentViewClient#getDesiredWidthMeasureSpec()} and
     * {@link ContentViewClient#getDesiredHeightMeasureSpec()} methods. If no value is provided
     * in one of these methods, the values from the |width| and |height| arguments will be
     * used instead.
     *
     * @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) {
    ContentViewClient client = contentViewCore.getContentViewClient();
    int desiredWidthMeasureSpec = client.getDesiredWidthMeasureSpec();
    if (MeasureSpec.getMode(desiredWidthMeasureSpec) != MeasureSpec.UNSPECIFIED) {
        width = MeasureSpec.getSize(desiredWidthMeasureSpec);
    }
    int desiredHeightMeasureSpec = client.getDesiredHeightMeasureSpec();
    if (MeasureSpec.getMode(desiredHeightMeasureSpec) != MeasureSpec.UNSPECIFIED) {
        height = MeasureSpec.getSize(desiredHeightMeasureSpec);
    }
    contentViewCore.onPhysicalBackingSizeChanged(width, height);
}
Also used : ContentViewClient(org.chromium.content.browser.ContentViewClient) Paint(android.graphics.Paint)

Example 4 with ContentViewClient

use of org.chromium.content.browser.ContentViewClient in project AndroidChromium by JackyAndroid.

the class Tab method setContentViewClient.

/**
     * @param client The {@link ContentViewClient} to be bound to any current or new
     *               {@link ContentViewCore}s associated with this {@link Tab}.
     */
private void setContentViewClient(ContentViewClient client) {
    if (mContentViewClient == client)
        return;
    ContentViewClient oldClient = mContentViewClient;
    mContentViewClient = client;
    if (mContentViewCore == null)
        return;
    if (mContentViewClient != null) {
        mContentViewCore.setContentViewClient(mContentViewClient);
    } else if (oldClient != null) {
        // We can't set a null client, but we should clear references to the last one.
        mContentViewCore.setContentViewClient(new ContentViewClient());
    }
}
Also used : ContentViewClient(org.chromium.content.browser.ContentViewClient)

Aggregations

ContentViewClient (org.chromium.content.browser.ContentViewClient)4 Paint (android.graphics.Paint)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 ContentView (org.chromium.content.browser.ContentView)1 WebContents (org.chromium.content_public.browser.WebContents)1 WebContentsObserver (org.chromium.content_public.browser.WebContentsObserver)1 ViewAndroidDelegate (org.chromium.ui.base.ViewAndroidDelegate)1