Search in sources :

Example 11 with LayoutTab

use of org.chromium.chrome.browser.compositor.layouts.components.LayoutTab in project AndroidChromium by JackyAndroid.

the class SimpleAnimationLayout method onTabClosed.

/**
     * Animate the closing of a tab
     */
@Override
public void onTabClosed(long time, int id, int nextId, boolean incognito) {
    super.onTabClosed(time, id, nextId, incognito);
    if (mClosedTab != null) {
        TabModel nextModel = mTabModelSelector.getModelForTabId(nextId);
        if (nextModel != null) {
            LayoutTab nextLayoutTab = createLayoutTab(nextId, nextModel.isIncognito(), NO_CLOSE_BUTTON, NO_TITLE);
            nextLayoutTab.setDrawDecoration(false);
            mLayoutTabs = new LayoutTab[] { nextLayoutTab, mClosedTab };
            updateCacheVisibleIds(new LinkedList<Integer>(Arrays.asList(nextId, mClosedTab.getId())));
        } else {
            mLayoutTabs = new LayoutTab[] { mClosedTab };
        }
        forceAnimationToFinish();
        mAnimatedTab = mClosedTab;
        addToAnimation(this, Property.DISCARD_AMOUNT, 0, getDiscardRange(), TAB_CLOSED_ANIMATION_DURATION, 0, false, BakedBezierInterpolator.FADE_OUT_CURVE);
        mClosedTab = null;
        if (nextModel != null) {
            mTabModelSelector.selectModel(nextModel.isIncognito());
        }
    }
    startHiding(nextId, false);
}
Also used : LayoutTab(org.chromium.chrome.browser.compositor.layouts.components.LayoutTab) TabModel(org.chromium.chrome.browser.tabmodel.TabModel)

Example 12 with LayoutTab

use of org.chromium.chrome.browser.compositor.layouts.components.LayoutTab in project AndroidChromium by JackyAndroid.

the class SimpleAnimationLayout method tabCreatedInBackground.

/**
     * Animate opening a tab in the background.
     *
     * @param id             The id of the new tab to animate.
     * @param sourceId       The id of the tab that spawned this new tab.
     * @param newIsIncognito true if the new tab is an incognito tab.
     * @param originX        The X screen coordinate in dp of the last touch down event that spawned
     *                       this tab.
     * @param originY        The Y screen coordinate in dp of the last touch down event that spawned
     *                       this tab.
     */
private void tabCreatedInBackground(int id, int sourceId, boolean newIsIncognito, float originX, float originY) {
    LayoutTab newLayoutTab = createLayoutTab(id, newIsIncognito, NO_CLOSE_BUTTON, NEED_TITLE);
    // mLayoutTabs should already have the source tab from tabCreating().
    assert mLayoutTabs.length == 1;
    LayoutTab sourceLayoutTab = mLayoutTabs[0];
    mLayoutTabs = new LayoutTab[] { sourceLayoutTab, newLayoutTab };
    updateCacheVisibleIds(new LinkedList<Integer>(Arrays.asList(id, sourceId)));
    forceAnimationToFinish();
    newLayoutTab.setBorderAlpha(0.0f);
    final float scale = StackAnimation.SCALE_AMOUNT;
    final float margin = Math.min(getWidth(), getHeight()) * (1.0f - scale) / 2.0f;
    // Step 1: zoom out the source tab and bring in the new tab
    addToAnimation(sourceLayoutTab, LayoutTab.Property.SCALE, 1.0f, scale, BACKGROUND_STEP1_DURATION, 0, false, BakedBezierInterpolator.TRANSFORM_CURVE);
    addToAnimation(sourceLayoutTab, LayoutTab.Property.X, 0.0f, margin, BACKGROUND_STEP1_DURATION, 0, false, BakedBezierInterpolator.TRANSFORM_CURVE);
    addToAnimation(sourceLayoutTab, LayoutTab.Property.Y, 0.0f, margin, BACKGROUND_STEP1_DURATION, 0, false, BakedBezierInterpolator.TRANSFORM_CURVE);
    addToAnimation(sourceLayoutTab, LayoutTab.Property.BORDER_SCALE, 1.0f / scale, 1.0f, BACKGROUND_STEP1_DURATION, 0, false, BakedBezierInterpolator.TRANSFORM_CURVE);
    addToAnimation(sourceLayoutTab, LayoutTab.Property.BORDER_ALPHA, 0.0f, 1.0f, BACKGROUND_STEP1_DURATION, 0, false, BakedBezierInterpolator.TRANSFORM_CURVE);
    float pauseX = margin;
    float pauseY = margin;
    if (getOrientation() == Orientation.PORTRAIT) {
        pauseY = BACKGROUND_COVER_PCTG * getHeight();
    } else {
        pauseX = BACKGROUND_COVER_PCTG * getWidth();
    }
    addToAnimation(newLayoutTab, LayoutTab.Property.ALPHA, 0.0f, 1.0f, BACKGROUND_STEP1_DURATION / 2, 0, false, BakedBezierInterpolator.FADE_IN_CURVE);
    addToAnimation(newLayoutTab, LayoutTab.Property.SCALE, 0.f, scale, BACKGROUND_STEP1_DURATION, 0, false, BakedBezierInterpolator.FADE_IN_CURVE);
    addToAnimation(newLayoutTab, LayoutTab.Property.X, originX, pauseX, BACKGROUND_STEP1_DURATION, 0, false, BakedBezierInterpolator.FADE_IN_CURVE);
    addToAnimation(newLayoutTab, LayoutTab.Property.Y, originY, pauseY, BACKGROUND_STEP1_DURATION, 0, false, BakedBezierInterpolator.FADE_IN_CURVE);
    // step 2: pause and admire the nice tabs
    // step 3: zoom in the source tab and slide down the new tab
    addToAnimation(sourceLayoutTab, LayoutTab.Property.SCALE, scale, 1.0f, BACKGROUND_STEP3_DURATION, BACKGROUND_STEP3_START, true, BakedBezierInterpolator.TRANSFORM_CURVE);
    addToAnimation(sourceLayoutTab, LayoutTab.Property.X, margin, 0.0f, BACKGROUND_STEP3_DURATION, BACKGROUND_STEP3_START, true, BakedBezierInterpolator.TRANSFORM_CURVE);
    addToAnimation(sourceLayoutTab, LayoutTab.Property.Y, margin, 0.0f, BACKGROUND_STEP3_DURATION, BACKGROUND_STEP3_START, true, BakedBezierInterpolator.TRANSFORM_CURVE);
    addToAnimation(sourceLayoutTab, LayoutTab.Property.BORDER_SCALE, 1.0f, 1.0f / scale, BACKGROUND_STEP3_DURATION, BACKGROUND_STEP3_START, true, BakedBezierInterpolator.TRANSFORM_CURVE);
    addToAnimation(sourceLayoutTab, LayoutTab.Property.BORDER_ALPHA, 1.0f, 0.0f, BACKGROUND_STEP3_DURATION, BACKGROUND_STEP3_START, true, BakedBezierInterpolator.TRANSFORM_CURVE);
    addToAnimation(newLayoutTab, LayoutTab.Property.ALPHA, 1.f, 0.f, BACKGROUND_STEP3_DURATION, BACKGROUND_STEP3_START, true, BakedBezierInterpolator.FADE_OUT_CURVE);
    if (getOrientation() == Orientation.PORTRAIT) {
        addToAnimation(newLayoutTab, LayoutTab.Property.Y, pauseY, getHeight(), BACKGROUND_STEP3_DURATION, BACKGROUND_STEP3_START, true, BakedBezierInterpolator.FADE_OUT_CURVE);
    } else {
        addToAnimation(newLayoutTab, LayoutTab.Property.X, pauseX, getWidth(), BACKGROUND_STEP3_DURATION, BACKGROUND_STEP3_START, true, BakedBezierInterpolator.FADE_OUT_CURVE);
    }
    mTabModelSelector.selectModel(newIsIncognito);
    startHiding(sourceId, false);
}
Also used : LayoutTab(org.chromium.chrome.browser.compositor.layouts.components.LayoutTab)

Example 13 with LayoutTab

use of org.chromium.chrome.browser.compositor.layouts.components.LayoutTab in project AndroidChromium by JackyAndroid.

the class StaticLayout method updateSceneLayer.

@Override
protected void updateSceneLayer(Rect viewport, Rect contentViewport, LayerTitleCache layerTitleCache, TabContentManager tabContentManager, ResourceManager resourceManager, ChromeFullscreenManager fullscreenManager) {
    super.updateSceneLayer(viewport, contentViewport, layerTitleCache, tabContentManager, resourceManager, fullscreenManager);
    assert mSceneLayer != null;
    final LayoutTab[] tabs = getLayoutTabsToRender();
    if (tabs == null || tabs.length != 1 || tabs[0].getId() == Tab.INVALID_TAB_ID) {
        return;
    }
    LayoutTab layoutTab = tabs[0];
    final float dpToPx = getContext().getResources().getDisplayMetrics().density;
    mSceneLayer.update(dpToPx, contentViewport, layerTitleCache, tabContentManager, fullscreenManager, layoutTab);
    // We should probably erase the thumbnail when we select a tab that we need to restore.
    if (tabContentManager != null && tabContentManager.hasFullCachedThumbnail(layoutTab.getId())) {
        TabModelImpl.logPerceivedTabSwitchLatencyMetric();
    }
}
Also used : LayoutTab(org.chromium.chrome.browser.compositor.layouts.components.LayoutTab)

Example 14 with LayoutTab

use of org.chromium.chrome.browser.compositor.layouts.components.LayoutTab in project AndroidChromium by JackyAndroid.

the class ToolbarSwipeLayout method swipeStarted.

@Override
public void swipeStarted(long time, ScrollDirection direction, float x, float y) {
    if (mTabModelSelector == null || mToTab != null || direction == ScrollDirection.DOWN) {
        return;
    }
    boolean dragFromLeftEdge = direction == ScrollDirection.RIGHT;
    // Finish off any other animations.
    forceAnimationToFinish();
    // Determine which tabs we're showing.
    TabModel model = mTabModelSelector.getCurrentModel();
    if (model == null)
        return;
    int fromIndex = model.index();
    if (fromIndex == TabModel.INVALID_TAB_INDEX)
        return;
    // On RTL, edge-dragging to the left is the next tab.
    int toIndex = (LocalizationUtils.isLayoutRtl() ^ dragFromLeftEdge) ? fromIndex - 1 : fromIndex + 1;
    int leftIndex = dragFromLeftEdge ? toIndex : fromIndex;
    int rightIndex = !dragFromLeftEdge ? toIndex : fromIndex;
    List<Integer> visibleTabs = new ArrayList<Integer>();
    if (0 <= leftIndex && leftIndex < model.getCount()) {
        int leftTabId = model.getTabAt(leftIndex).getId();
        mLeftTab = createLayoutTab(leftTabId, model.isIncognito(), NO_CLOSE_BUTTON, NEED_TITLE);
        prepareLayoutTabForSwipe(mLeftTab, leftIndex != fromIndex);
        visibleTabs.add(leftTabId);
    }
    if (0 <= rightIndex && rightIndex < model.getCount()) {
        int rightTabId = model.getTabAt(rightIndex).getId();
        mRightTab = createLayoutTab(rightTabId, model.isIncognito(), NO_CLOSE_BUTTON, NEED_TITLE);
        prepareLayoutTabForSwipe(mRightTab, rightIndex != fromIndex);
        visibleTabs.add(rightTabId);
    }
    updateCacheVisibleIds(visibleTabs);
    mToTab = null;
    // Reset the tab offsets.
    mOffsetStart = dragFromLeftEdge ? 0 : getWidth();
    mOffset = 0;
    mOffsetTarget = 0;
    if (mLeftTab != null && mRightTab != null) {
        mLayoutTabs = new LayoutTab[] { mLeftTab, mRightTab };
    } else if (mLeftTab != null) {
        mLayoutTabs = new LayoutTab[] { mLeftTab };
    } else if (mRightTab != null) {
        mLayoutTabs = new LayoutTab[] { mRightTab };
    } else {
        mLayoutTabs = null;
    }
    requestUpdate();
}
Also used : ArrayList(java.util.ArrayList) LayoutTab(org.chromium.chrome.browser.compositor.layouts.components.LayoutTab) TabModel(org.chromium.chrome.browser.tabmodel.TabModel)

Example 15 with LayoutTab

use of org.chromium.chrome.browser.compositor.layouts.components.LayoutTab in project AndroidChromium by JackyAndroid.

the class CompositorView method finalizeLayers.

/**
     * Converts the layout into compositor layers. This is to be called on every frame the layout
     * is changing.
     * @param provider               Provides the layout to be rendered.
     * @param forRotation            Whether or not this is a special draw during a rotation.
     */
public void finalizeLayers(final LayoutProvider provider, boolean forRotation, final DrawingInfo progressBarDrawingInfo) {
    TraceEvent.begin("CompositorView:finalizeLayers");
    Layout layout = provider.getActiveLayout();
    if (layout == null || mNativeCompositorView == 0) {
        TraceEvent.end("CompositorView:finalizeLayers");
        return;
    }
    if (!mPreloadedResources) {
        // Attempt to prefetch any necessary resources
        mResourceManager.preloadResources(AndroidResourceType.STATIC, StaticResourcePreloads.getSynchronousResources(getContext()), StaticResourcePreloads.getAsynchronousResources(getContext()));
        mPreloadedResources = true;
    }
    // IMPORTANT: Do not do anything that impacts the compositor layer tree before this line.
    // If you do, you could inadvertently trigger follow up renders.  For further information
    // see dtrainor@, tedchoc@, or klobag@.
    // TODO(jscholler): change 1.0f to dpToPx once the native part is fully supporting dp.
    mRenderHost.getVisibleViewport(mCacheVisibleViewport);
    mCacheVisibleViewport.right = mCacheVisibleViewport.left + mSurfaceWidth;
    mCacheVisibleViewport.bottom = mCacheVisibleViewport.top + mSurfaceHeight;
    provider.getViewportPixel(mCacheViewport);
    nativeSetLayoutViewport(mNativeCompositorView, mCacheViewport.left, mCacheViewport.top, mCacheViewport.width(), mCacheViewport.height(), mCacheVisibleViewport.left, mCacheVisibleViewport.top, 1.0f);
    SceneLayer sceneLayer = provider.getUpdatedActiveSceneLayer(mCacheViewport, mCacheVisibleViewport, mLayerTitleCache, mTabContentManager, mResourceManager, provider.getFullscreenManager());
    nativeSetSceneLayer(mNativeCompositorView, sceneLayer);
    final LayoutTab[] tabs = layout.getLayoutTabsToRender();
    final int tabsCount = tabs != null ? tabs.length : 0;
    mLastLayerCount = tabsCount;
    TabModelImpl.flushActualTabSwitchLatencyMetric();
    nativeFinalizeLayers(mNativeCompositorView);
    TraceEvent.end("CompositorView:finalizeLayers");
}
Also used : SceneLayer(org.chromium.chrome.browser.compositor.scene_layer.SceneLayer) Layout(org.chromium.chrome.browser.compositor.layouts.Layout) LayoutTab(org.chromium.chrome.browser.compositor.layouts.components.LayoutTab)

Aggregations

LayoutTab (org.chromium.chrome.browser.compositor.layouts.components.LayoutTab)25 TabModel (org.chromium.chrome.browser.tabmodel.TabModel)4 ChromeAnimation (org.chromium.chrome.browser.compositor.layouts.ChromeAnimation)3 Animatable (org.chromium.chrome.browser.compositor.layouts.ChromeAnimation.Animatable)3 Tab (org.chromium.chrome.browser.tab.Tab)2 OverviewListLayout (org.chromium.chrome.browser.widget.OverviewListLayout)2 Resources (android.content.res.Resources)1 Interpolator (android.view.animation.Interpolator)1 ArrayList (java.util.ArrayList)1 Layout (org.chromium.chrome.browser.compositor.layouts.Layout)1 StackLayout (org.chromium.chrome.browser.compositor.layouts.phone.StackLayout)1 SceneLayer (org.chromium.chrome.browser.compositor.scene_layer.SceneLayer)1 TabModelSelector (org.chromium.chrome.browser.tabmodel.TabModelSelector)1 DocumentTabModelSelector (org.chromium.chrome.browser.tabmodel.document.DocumentTabModelSelector)1 BakedBezierInterpolator (org.chromium.ui.interpolators.BakedBezierInterpolator)1