use of org.chromium.chrome.browser.compositor.layouts.components.LayoutTab in project AndroidChromium by JackyAndroid.
the class Stack method computeTabScaleAlphaDepthHelper.
/**
* ComputeTabPosition pass 1:
* Combine the overall stack scale with the animated tab scale.
*
* @param stackRect The frame of the stack.
*/
private void computeTabScaleAlphaDepthHelper(RectF stackRect) {
final float stackScale = getStackScale(stackRect);
final float discardRange = getDiscardRange();
for (int i = 0; i < mStackTabs.length; ++i) {
assert mStackTabs[i] != null;
StackTab stackTab = mStackTabs[i];
LayoutTab layoutTab = stackTab.getLayoutTab();
final float discard = stackTab.getDiscardAmount();
// Scale
float discardScale = computeDiscardScale(discard, discardRange, stackTab.getDiscardFromClick());
layoutTab.setScale(stackTab.getScale() * discardScale * stackScale);
layoutTab.setBorderScale(discardScale);
// Alpha
float discardAlpha = computeDiscardAlpha(discard, discardRange);
layoutTab.setAlpha(stackTab.getAlpha() * discardAlpha);
}
}
use of org.chromium.chrome.browser.compositor.layouts.components.LayoutTab in project AndroidChromium by JackyAndroid.
the class Stack method computeTabOffsetHelper.
/**
* ComputeTabPosition pass 3:
* Compute the position of the tabs. Adjust for top and bottom stacking.
*
* @param stackRect The frame of the stack.
*/
private void computeTabOffsetHelper(RectF stackRect) {
final boolean portrait = mCurrentMode == Orientation.PORTRAIT;
// Precompute the position using scroll offset and top stacking.
final float parentWidth = stackRect.width();
final float parentHeight = stackRect.height();
final float overscrollPercent = computeOverscrollPercent();
final float scrollOffset = MathUtils.clamp(mScrollOffset, getMinScroll(false), getMaxScroll(false));
final float stackScale = getStackScale(stackRect);
int stackedCount = 0;
float minStackedPosition = 0.0f;
for (int i = 0; i < mStackTabs.length; ++i) {
assert mStackTabs[i] != null;
StackTab stackTab = mStackTabs[i];
LayoutTab layoutTab = stackTab.getLayoutTab();
// Position
final float stackScrollOffset = stackTab.isDying() ? mScrollOffsetForDyingTabs : scrollOffset;
float screenScrollOffset = approxScreen(stackTab, stackScrollOffset);
// Resolve top stacking
screenScrollOffset = Math.max(minStackedPosition, screenScrollOffset);
if (stackedCount < MAX_NUMBER_OF_STACKED_TABS_TOP) {
// This make sure all the tab get stacked up as one when all the tabs do a
// full roll animation.
final float tiltXcos = (float) Math.cos(Math.toRadians(layoutTab.getTiltX()));
final float tiltYcos = (float) Math.cos(Math.toRadians(layoutTab.getTiltY()));
float collapse = Math.min(Math.abs(tiltXcos), Math.abs(tiltYcos));
collapse *= layoutTab.getAlpha();
minStackedPosition += StackTab.sStackedTabVisibleSize * collapse;
}
stackedCount += stackTab.isDying() ? 0 : 1;
if (overscrollPercent < 0) {
// Oversroll at the top of the screen. For the first
// OVERSCROLL_TOP_SLIDE_PCTG of the overscroll, slide the tabs
// together so they completely overlap. After that, stop scrolling the tabs.
screenScrollOffset += (overscrollPercent / OVERSCROLL_TOP_SLIDE_PCTG) * screenScrollOffset;
screenScrollOffset = Math.max(0, screenScrollOffset);
}
// Note: All the Offsets except for centering shouldn't depend on the tab's scaling
// because it interferes the scaling center.
// Centers the tab in its parent.
float xIn = (parentWidth - layoutTab.getScaledContentWidth()) / 2.0f;
float yIn = (parentHeight - layoutTab.getScaledContentHeight()) / 2.0f;
// We want slight offset from the center so that multiple tab browsing
// have more space to its expanding direction. e.g., On portrait mode,
// there will be more space on the bottom than top.
final float horizontalPadding = (parentWidth - layoutTab.getOriginalContentWidth() * StackAnimation.SCALE_AMOUNT * stackScale) / 2.0f;
final float verticalPadding = (parentHeight - layoutTab.getOriginalContentHeight() * StackAnimation.SCALE_AMOUNT * stackScale) / 2.0f;
if (portrait) {
yIn += STACK_PORTRAIT_Y_OFFSET_PROPORTION * verticalPadding;
yIn += screenScrollOffset;
} else {
if (LocalizationUtils.isLayoutRtl()) {
xIn -= STACK_LANDSCAPE_START_OFFSET_PROPORTION * horizontalPadding;
xIn -= screenScrollOffset;
} else {
xIn += STACK_LANDSCAPE_START_OFFSET_PROPORTION * horizontalPadding;
xIn += screenScrollOffset;
}
yIn += STACK_LANDSCAPE_Y_OFFSET_PROPORTION * verticalPadding;
}
layoutTab.setX(xIn);
layoutTab.setY(yIn);
}
// Resolve bottom stacking
stackedCount = 0;
float maxStackedPosition = portrait ? mLayout.getHeightMinusTopControls() : mLayout.getWidth();
for (int i = mStackTabs.length - 1; i >= 0; i--) {
assert mStackTabs[i] != null;
StackTab stackTab = mStackTabs[i];
LayoutTab layoutTab = stackTab.getLayoutTab();
if (stackTab.isDying())
continue;
float pos;
if (portrait) {
pos = layoutTab.getY();
layoutTab.setY(Math.min(pos, maxStackedPosition));
} else if (LocalizationUtils.isLayoutRtl()) {
// On RTL landscape, pos is a distance between tab's right and mLayout's right.
float posOffset = mLayout.getWidth() - layoutTab.getOriginalContentWidth() * StackAnimation.SCALE_AMOUNT * stackScale;
pos = -layoutTab.getX() + posOffset;
layoutTab.setX(-Math.min(pos, maxStackedPosition) + posOffset);
} else {
pos = layoutTab.getX();
layoutTab.setX(Math.min(pos, maxStackedPosition));
}
if (pos >= maxStackedPosition && stackedCount < MAX_NUMBER_OF_STACKED_TABS_BOTTOM) {
maxStackedPosition -= StackTab.sStackedTabVisibleSize;
stackedCount++;
}
}
// final position blend
final float discardRange = getDiscardRange();
for (int i = 0; i < mStackTabs.length; ++i) {
assert mStackTabs[i] != null;
StackTab stackTab = mStackTabs[i];
LayoutTab layoutTab = stackTab.getLayoutTab();
final float xIn = layoutTab.getX() + stackTab.getXInStackOffset();
final float yIn = layoutTab.getY() + stackTab.getYInStackOffset();
final float xOut = stackTab.getXOutOfStack();
final float yOut = stackTab.getYOutOfStack();
float x = MathUtils.interpolate(xOut, xIn, stackTab.getXInStackInfluence());
float y = MathUtils.interpolate(yOut, yIn, stackTab.getYInStackInfluence());
// Discard offsets
if (stackTab.getDiscardAmount() != 0) {
float discard = stackTab.getDiscardAmount();
boolean fromClick = stackTab.getDiscardFromClick();
float scale = computeDiscardScale(discard, discardRange, fromClick);
float deltaX = stackTab.getDiscardOriginX() - stackTab.getLayoutTab().getOriginalContentWidth() / 2.f;
float deltaY = stackTab.getDiscardOriginY() - stackTab.getLayoutTab().getOriginalContentHeight() / 2.f;
float discardOffset = fromClick ? 0.f : discard;
if (portrait) {
x += discardOffset + deltaX * (1.f - scale);
y += deltaY * (1.f - scale);
} else {
x += deltaX * (1.f - scale);
y += discardOffset + deltaY * (1.f - scale);
}
}
// Finally apply the stack translation
layoutTab.setX(stackRect.left + x);
layoutTab.setY(stackRect.top + y);
}
}
use of org.chromium.chrome.browser.compositor.layouts.components.LayoutTab in project AndroidChromium by JackyAndroid.
the class Stack method computeTabTiltHelper.
/**
* ComputeTabPosition pass 4:
* Update the tilt of each tab.
*
* @param time The current time of the app in ms.
* @param stackRect The frame of the stack.
*/
private void computeTabTiltHelper(long time, RectF stackRect) {
final boolean portrait = mCurrentMode == Orientation.PORTRAIT;
final float parentWidth = stackRect.width();
final float parentHeight = stackRect.height();
final float overscrollPercent = computeOverscrollPercent();
// All the animations that sets the tilt value must be listed here.
if (mOverviewAnimationType == OverviewAnimationType.START_PINCH || mOverviewAnimationType == OverviewAnimationType.DISCARD || mOverviewAnimationType == OverviewAnimationType.FULL_ROLL || mOverviewAnimationType == OverviewAnimationType.TAB_FOCUSED || mOverviewAnimationType == OverviewAnimationType.UNDISCARD || mOverviewAnimationType == OverviewAnimationType.DISCARD_ALL) {
// Let the animation handle setting tilt values
} else if (mPinch0TabIndex >= 0 || overscrollPercent == 0.0f || mOverviewAnimationType == OverviewAnimationType.REACH_TOP) {
// Keep tabs flat during pinch
for (int i = 0; i < mStackTabs.length; ++i) {
StackTab stackTab = mStackTabs[i];
LayoutTab layoutTab = stackTab.getLayoutTab();
layoutTab.setTiltX(0, 0);
layoutTab.setTiltY(0, 0);
}
} else if (overscrollPercent < 0) {
if (mOverScrollCounter >= OVERSCROLL_FULL_ROLL_TRIGGER) {
startAnimation(time, OverviewAnimationType.FULL_ROLL);
mOverScrollCounter = 0;
// Remove overscroll so when the animation finishes the overscroll won't
// be bothering.
setScrollTarget(MathUtils.clamp(mScrollOffset, getMinScroll(false), getMaxScroll(false)), false);
} else {
// Handle tilting tabs backwards (top or left of the tab goes away
// from the camera). Each tab pivots the same amount around the
// same point on the screen. The pivot point is the middle of the
// top tab.
float tilt = 0;
if (overscrollPercent < -OVERSCROLL_TOP_SLIDE_PCTG) {
// Start tilting tabs after they're done sliding together.
float scaledOverscroll = (overscrollPercent + OVERSCROLL_TOP_SLIDE_PCTG) / (1 - OVERSCROLL_TOP_SLIDE_PCTG);
tilt = mUnderScrollAngleInterpolator.getInterpolation(-scaledOverscroll) * -mMaxOverScrollAngle * BACKWARDS_TILT_SCALE;
}
float pivotOffset = 0;
LayoutTab topTab = mStackTabs[mStackTabs.length - 1].getLayoutTab();
pivotOffset = portrait ? topTab.getScaledContentHeight() / 2 + topTab.getY() : topTab.getScaledContentWidth() / 2 + topTab.getX();
for (int i = 0; i < mStackTabs.length; ++i) {
StackTab stackTab = mStackTabs[i];
LayoutTab layoutTab = stackTab.getLayoutTab();
if (portrait) {
layoutTab.setTiltX(tilt, pivotOffset - layoutTab.getY());
} else {
layoutTab.setTiltY(LocalizationUtils.isLayoutRtl() ? -tilt : tilt, pivotOffset - layoutTab.getX());
}
}
}
} else {
// Handle tilting tabs forwards (top or left of the tab comes
// towards the camera). Each tab pivots around a point 1/3 of the
// way down from the top/left of itself. The angle angle is scaled
// based on its distance away from the top/left.
float tilt = mOverScrollAngleInterpolator.getInterpolation(overscrollPercent) * mMaxOverScrollAngle;
float offset = mOverscrollSlideInterpolator.getInterpolation(overscrollPercent) * mMaxOverScrollSlide;
for (int i = 0; i < mStackTabs.length; ++i) {
StackTab stackTab = mStackTabs[i];
LayoutTab layoutTab = stackTab.getLayoutTab();
if (portrait) {
// portrait LTR & RTL
float adjust = MathUtils.clamp((layoutTab.getY() / parentHeight) + 0.50f, 0, 1);
layoutTab.setTiltX(tilt * adjust, layoutTab.getScaledContentHeight() / 3);
layoutTab.setY(layoutTab.getY() + offset);
} else if (LocalizationUtils.isLayoutRtl()) {
// landscape RTL
float adjust = MathUtils.clamp(-(layoutTab.getX() / parentWidth) + 0.50f, 0, 1);
layoutTab.setTiltY(-tilt * adjust, layoutTab.getScaledContentWidth() * 2 / 3);
layoutTab.setX(layoutTab.getX() - offset);
} else {
// landscape LTR
float adjust = MathUtils.clamp((layoutTab.getX() / parentWidth) + 0.50f, 0, 1);
layoutTab.setTiltY(tilt * adjust, layoutTab.getScaledContentWidth() / 3);
layoutTab.setX(layoutTab.getX() + offset);
}
}
}
}
use of org.chromium.chrome.browser.compositor.layouts.components.LayoutTab in project AndroidChromium by JackyAndroid.
the class Layout method createLayoutTab.
/**
* Creates a {@link LayoutTab}.
* @param id The id of the reference {@link Tab} in the {@link TabModel}.
* @param isIncognito Whether the new tab is incognito.
* @param showCloseButton True to show and activate a close button on the border.
* @param isTitleNeeded Whether a title will be shown.
* @param maxContentWidth The max content width of the tab. Negative numbers will use the
* original content width.
* @param maxContentHeight The max content height of the tab. Negative numbers will use the
* original content height.
* @return The newly created {@link LayoutTab}.
*/
public LayoutTab createLayoutTab(int id, boolean isIncognito, boolean showCloseButton, boolean isTitleNeeded, float maxContentWidth, float maxContentHeight) {
LayoutTab layoutTab = mUpdateHost.createLayoutTab(id, isIncognito, showCloseButton, isTitleNeeded, maxContentWidth, maxContentHeight);
initLayoutTabFromHost(layoutTab);
return layoutTab;
}
use of org.chromium.chrome.browser.compositor.layouts.components.LayoutTab in project AndroidChromium by JackyAndroid.
the class LayoutManagerChrome method startHiding.
@Override
public void startHiding(int nextTabId, boolean hintAtTabSelection) {
super.startHiding(nextTabId, hintAtTabSelection);
Layout layoutBeingHidden = getActiveLayout();
if (isOverviewLayout(layoutBeingHidden)) {
boolean showToolbar = true;
if (mEnableAnimations && layoutBeingHidden == mOverviewLayout) {
final LayoutTab tab = layoutBeingHidden.getLayoutTab(nextTabId);
showToolbar = tab != null ? !tab.showToolbar() : true;
}
boolean creatingNtp = layoutBeingHidden == mOverviewLayout && mCreatingNtp;
for (OverviewModeObserver observer : mOverviewModeObservers) {
observer.onOverviewModeStartedHiding(showToolbar, creatingNtp);
}
}
}
Aggregations