Search in sources :

Example 21 with LayoutTab

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

the class Stack method createStackTabs.

/**
     * Creates the {@link StackTab}s needed for display and populates {@link #mStackTabs}.
     * It is called from show() at the beginning of every new draw phase. It tries to reuse old
     * {@link StackTab} instead of creating new ones every time.
     * @param restoreState Whether or not to restore the {@link LayoutTab} state when we rebuild the
     *                     {@link StackTab}s.  There are some properties like maximum content size
     *                     or whether or not to show the toolbar that might have to be restored if
     *                     we're calling this while the switcher is already visible.
     */
private void createStackTabs(boolean restoreState) {
    final int count = mTabModel.getCount();
    if (count == 0) {
        cleanupTabs();
    } else {
        StackTab[] oldTabs = mStackTabs;
        mStackTabs = new StackTab[count];
        final boolean isIncognito = mTabModel.isIncognito();
        final boolean needTitle = !mLayout.isHiding();
        for (int i = 0; i < count; ++i) {
            Tab tab = mTabModel.getTabAt(i);
            int tabId = tab != null ? tab.getId() : Tab.INVALID_TAB_ID;
            mStackTabs[i] = findTabById(oldTabs, tabId);
            float maxContentWidth = -1.f;
            float maxContentHeight = -1.f;
            if (mStackTabs[i] != null && mStackTabs[i].getLayoutTab() != null && restoreState) {
                maxContentWidth = mStackTabs[i].getLayoutTab().getMaxContentWidth();
                maxContentHeight = mStackTabs[i].getLayoutTab().getMaxContentHeight();
            }
            LayoutTab layoutTab = mLayout.createLayoutTab(tabId, isIncognito, Layout.SHOW_CLOSE_BUTTON, needTitle, maxContentWidth, maxContentHeight);
            layoutTab.setInsetBorderVertical(true);
            layoutTab.setShowToolbar(true);
            layoutTab.setToolbarAlpha(0.f);
            layoutTab.setAnonymizeToolbar(!mIsStackForCurrentTabModel || mTabModel.index() != i);
            if (mStackTabs[i] == null) {
                mStackTabs[i] = new StackTab(layoutTab);
            } else {
                mStackTabs[i].setLayoutTab(layoutTab);
            }
            mStackTabs[i].setNewIndex(i);
        // The initial enterStack animation will take care of
        // positioning, scaling, etc.
        }
    }
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab) LayoutTab(org.chromium.chrome.browser.compositor.layouts.components.LayoutTab) LayoutTab(org.chromium.chrome.browser.compositor.layouts.components.LayoutTab)

Example 22 with LayoutTab

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

the class Stack method computeTabClippingVisibilityHelper.

/**
     * ComputeTabPosition pass 5:
     * Computes the clipping, visibility and adjust overall alpha if needed.
     */
private void computeTabClippingVisibilityHelper() {
    // alpha override, clipping and culling.
    final boolean portrait = mCurrentMode == Orientation.PORTRAIT;
    // Iterate through each tab starting at the top of the stack and working
    // backwards. Set the clip on each tab such that it does not extend past
    // the beginning of the tab above it. clipOffset is used to keep track
    // of where the previous tab started.
    float clipOffset;
    if (portrait) {
        // portrait LTR & RTL
        clipOffset = mLayout.getHeight() + StackTab.sStackedTabVisibleSize;
    } else if (!LocalizationUtils.isLayoutRtl()) {
        // landscape LTR
        clipOffset = mLayout.getWidth() + StackTab.sStackedTabVisibleSize;
    } else {
        // landscape RTL
        clipOffset = -StackTab.sStackedTabVisibleSize;
    }
    for (int i = mStackTabs.length - 1; i >= 0; i--) {
        LayoutTab layoutTab = mStackTabs[i].getLayoutTab();
        layoutTab.setVisible(true);
        // non-opaque.
        if (mStackTabs[i].isDying() || mStackTabs[i].getXInStackOffset() != 0.0f || layoutTab.getAlpha() < 1.0f) {
            layoutTab.setClipOffset(0.0f, 0.0f);
            layoutTab.setClipSize(Float.MAX_VALUE, Float.MAX_VALUE);
            continue;
        }
        // The beginning, size, and clipped size of the current tab.
        float tabOffset, tabSize, tabClippedSize, borderAdjustmentSize, insetBorderPadding;
        if (portrait) {
            // portrait LTR & RTL
            tabOffset = layoutTab.getY();
            tabSize = layoutTab.getScaledContentHeight();
            tabClippedSize = Math.min(tabSize, clipOffset - tabOffset);
            borderAdjustmentSize = mBorderTransparentTop;
            insetBorderPadding = mBorderTopPadding;
        } else if (!LocalizationUtils.isLayoutRtl()) {
            // landscape LTR
            tabOffset = layoutTab.getX();
            tabSize = layoutTab.getScaledContentWidth();
            tabClippedSize = Math.min(tabSize, clipOffset - tabOffset);
            borderAdjustmentSize = mBorderTransparentSide;
            insetBorderPadding = 0;
        } else {
            // landscape RTL
            tabOffset = layoutTab.getX() + layoutTab.getScaledContentWidth();
            tabSize = layoutTab.getScaledContentWidth();
            tabClippedSize = Math.min(tabSize, tabOffset - clipOffset);
            borderAdjustmentSize = -mBorderTransparentSide;
            insetBorderPadding = 0;
        }
        float absBorderAdjustmentSize = Math.abs(borderAdjustmentSize);
        if (tabClippedSize <= absBorderAdjustmentSize) {
            // If the tab is completed covered, don't bother drawing it at all.
            layoutTab.setVisible(false);
            layoutTab.setDrawDecoration(true);
        } else {
            // Fade the tab as it gets too close to the next one. This helps
            // prevent overlapping shadows from becoming too dark.
            float fade = MathUtils.clamp(((tabClippedSize - absBorderAdjustmentSize) / StackTab.sStackedTabVisibleSize), 0, 1);
            layoutTab.setDecorationAlpha(fade);
            // When tabs tilt forward, it will expose more of the tab
            // underneath. To compensate, make the clipping size larger.
            // Note, this calculation is only an estimate that seems to
            // work.
            float clipScale = 1.0f;
            if (layoutTab.getTiltX() > 0 || ((!portrait && LocalizationUtils.isLayoutRtl()) ? layoutTab.getTiltY() < 0 : layoutTab.getTiltY() > 0)) {
                final float tilt = Math.max(layoutTab.getTiltX(), Math.abs(layoutTab.getTiltY()));
                clipScale += (tilt / mMaxOverScrollAngle) * 0.60f;
            }
            float scaledTabClippedSize = Math.min(tabClippedSize * clipScale, tabSize);
            // Set the clip
            layoutTab.setClipOffset((!portrait && LocalizationUtils.isLayoutRtl()) ? (tabSize - scaledTabClippedSize) : 0, 0);
            layoutTab.setClipSize(portrait ? Float.MAX_VALUE : scaledTabClippedSize, portrait ? scaledTabClippedSize : Float.MAX_VALUE);
        }
        // Clip the next tab where this tab begins.
        if (i > 0) {
            LayoutTab nextLayoutTab = mStackTabs[i - 1].getLayoutTab();
            if (nextLayoutTab.getScale() <= layoutTab.getScale()) {
                clipOffset = tabOffset;
            } else {
                clipOffset = tabOffset + tabClippedSize * layoutTab.getScale();
            }
            // Extend the border just a little bit. Otherwise, the
            // rounded borders will intersect and make it look like the
            // content is actually smaller.
            clipOffset += borderAdjustmentSize;
            if (layoutTab.getBorderAlpha() < 1.f && layoutTab.getToolbarAlpha() < 1.f) {
                clipOffset += insetBorderPadding;
            }
        }
    }
}
Also used : LayoutTab(org.chromium.chrome.browser.compositor.layouts.components.LayoutTab)

Example 23 with LayoutTab

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

the class Stack method updateCurrentMode.

private void updateCurrentMode(int orientation) {
    mCurrentMode = orientation;
    mDiscardDirection = getDefaultDiscardDirection();
    setWarpState(true, false);
    final float opaqueTopPadding = mBorderTopPadding - mBorderTransparentTop;
    mAnimationFactory = StackAnimation.createAnimationFactory(mLayout.getWidth(), mLayout.getHeight(), mLayout.getHeightMinusTopControls(), mBorderTopPadding, opaqueTopPadding, mBorderLeftPadding, mCurrentMode);
    float dpToPx = mLayout.getContext().getResources().getDisplayMetrics().density;
    mViewAnimationFactory = new StackViewAnimation(dpToPx, mLayout.getWidth());
    if (mStackTabs == null)
        return;
    float width = mLayout.getWidth();
    float height = mLayout.getHeightMinusTopControls();
    for (int i = 0; i < mStackTabs.length; i++) {
        LayoutTab tab = mStackTabs[i].getLayoutTab();
        if (tab == null)
            continue;
        tab.setMaxContentWidth(width);
        tab.setMaxContentHeight(height);
    }
}
Also used : LayoutTab(org.chromium.chrome.browser.compositor.layouts.components.LayoutTab)

Example 24 with LayoutTab

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

the class LayoutManagerDocument method emptyCachesExcept.

/**
     * Clears all content associated with {@code tabId} from the internal caches.
     * @param tabId The id of the tab to clear.
     */
protected void emptyCachesExcept(int tabId) {
    LayoutTab tab = mTabCache.get(tabId);
    mTabCache.clear();
    if (tab != null)
        mTabCache.put(tabId, tab);
}
Also used : LayoutTab(org.chromium.chrome.browser.compositor.layouts.components.LayoutTab)

Example 25 with LayoutTab

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

the class StaticLayout method setStaticTab.

private void setStaticTab(final int id) {
    if (mLayoutTabs != null && mLayoutTabs.length > 0 && mLayoutTabs[0].getId() == id) {
        if (!mLayoutTabs[0].shouldStall())
            setPostHideState();
        return;
    }
    TabModel model = mTabModelSelector.getModelForTabId(id);
    if (model == null)
        return;
    updateCacheVisibleIds(new LinkedList<Integer>(Arrays.asList(id)));
    if (mLayoutTabs == null || mLayoutTabs.length != 1)
        mLayoutTabs = new LayoutTab[1];
    mLayoutTabs[0] = createLayoutTab(id, model.isIncognito(), NO_CLOSE_BUTTON, NO_TITLE);
    mLayoutTabs[0].setDrawDecoration(false);
    if (mLayoutTabs[0].shouldStall()) {
        setPreHideState();
        mHandler.postDelayed(mUnstallRunnable, HIDE_TIMEOUT_MS);
    } else {
        setPostHideState();
    }
    requestRender();
}
Also used : LayoutTab(org.chromium.chrome.browser.compositor.layouts.components.LayoutTab) TabModel(org.chromium.chrome.browser.tabmodel.TabModel)

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