OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser.compositor.layouts.phone.stack; |
| 6 |
| 7 import static org.chromium.chrome.browser.compositor.layouts.ChromeAnimation.Ani
matableAnimation.addAnimation; |
| 8 import static org.chromium.chrome.browser.compositor.layouts.components.LayoutTa
b.Property.MAX_CONTENT_HEIGHT; |
| 9 import static org.chromium.chrome.browser.compositor.layouts.components.LayoutTa
b.Property.SATURATION; |
| 10 import static org.chromium.chrome.browser.compositor.layouts.components.LayoutTa
b.Property.SIDE_BORDER_SCALE; |
| 11 import static org.chromium.chrome.browser.compositor.layouts.components.LayoutTa
b.Property.TILTX; |
| 12 import static org.chromium.chrome.browser.compositor.layouts.components.LayoutTa
b.Property.TOOLBAR_ALPHA; |
| 13 import static org.chromium.chrome.browser.compositor.layouts.components.LayoutTa
b.Property.TOOLBAR_Y_OFFSET; |
| 14 import static org.chromium.chrome.browser.compositor.layouts.phone.stack.StackTa
b.Property.DISCARD_AMOUNT; |
| 15 import static org.chromium.chrome.browser.compositor.layouts.phone.stack.StackTa
b.Property.SCALE; |
| 16 import static org.chromium.chrome.browser.compositor.layouts.phone.stack.StackTa
b.Property.SCROLL_OFFSET; |
| 17 import static org.chromium.chrome.browser.compositor.layouts.phone.stack.StackTa
b.Property.Y_IN_STACK_INFLUENCE; |
| 18 import static org.chromium.chrome.browser.compositor.layouts.phone.stack.StackTa
b.Property.Y_IN_STACK_OFFSET; |
| 19 |
| 20 import org.chromium.chrome.browser.compositor.layouts.ChromeAnimation; |
| 21 import org.chromium.chrome.browser.compositor.layouts.ChromeAnimation.Animatable
; |
| 22 import org.chromium.chrome.browser.compositor.layouts.components.LayoutTab; |
| 23 import org.chromium.chrome.browser.util.MathUtils; |
| 24 import org.chromium.ui.base.LocalizationUtils; |
| 25 |
| 26 class StackAnimationPortrait extends StackAnimation { |
| 27 /** |
| 28 * Only Constructor. |
| 29 */ |
| 30 public StackAnimationPortrait(float width, float height, float heightMinusTo
pControls, |
| 31 float borderFramePaddingTop, float borderFramePaddingTopOpaque, |
| 32 float borderFramePaddingLeft) { |
| 33 super(width, height, heightMinusTopControls, borderFramePaddingTop, |
| 34 borderFramePaddingTopOpaque, borderFramePaddingLeft); |
| 35 } |
| 36 |
| 37 @Override |
| 38 protected ChromeAnimation<?> createEnterStackAnimatorSet( |
| 39 StackTab[] tabs, int focusIndex, int spacing, float warpSize) { |
| 40 ChromeAnimation<Animatable<?>> set = new ChromeAnimation<Animatable<?>>(
); |
| 41 final float initialScrollOffset = StackTab.screenToScroll(0, warpSize); |
| 42 |
| 43 float trailingScrollOffset = 0.f; |
| 44 if (focusIndex >= 0 && focusIndex < tabs.length - 1) { |
| 45 final float focusOffset = tabs[focusIndex].getScrollOffset(); |
| 46 final float nextOffset = tabs[focusIndex + 1].getScrollOffset(); |
| 47 final float topSpacing = focusIndex == 0 ? spacing : 0.f; |
| 48 final float extraSpace = tabs[focusIndex].getLayoutTab().getScaledCo
ntentHeight() |
| 49 * ENTER_STACK_SIZE_RATIO; |
| 50 trailingScrollOffset = Math.max(focusOffset - nextOffset + topSpacin
g + extraSpace, 0); |
| 51 } |
| 52 |
| 53 for (int i = 0; i < tabs.length; ++i) { |
| 54 StackTab tab = tabs[i]; |
| 55 |
| 56 tab.resetOffset(); |
| 57 tab.setScale(SCALE_AMOUNT); |
| 58 tab.setAlpha(1.f); |
| 59 tab.getLayoutTab().setToolbarAlpha(0.f); |
| 60 tab.getLayoutTab().setBorderScale(1.f); |
| 61 |
| 62 float scrollOffset = StackTab.screenToScroll(i * spacing, warpSize); |
| 63 |
| 64 if (i < focusIndex) { |
| 65 tab.getLayoutTab().setMaxContentHeight(mHeightMinusTopControls); |
| 66 addAnimation(set, tab, SCROLL_OFFSET, initialScrollOffset, scrol
lOffset, |
| 67 ENTER_STACK_ANIMATION_DURATION, 0); |
| 68 } else if (i > focusIndex) { |
| 69 tab.getLayoutTab().setMaxContentHeight(mHeightMinusTopControls); |
| 70 tab.setScrollOffset(scrollOffset + trailingScrollOffset); |
| 71 addAnimation( |
| 72 set, tab, Y_IN_STACK_OFFSET, mHeight, 0, ENTER_STACK_ANI
MATION_DURATION, 0); |
| 73 } else { |
| 74 tab.setScrollOffset(scrollOffset); |
| 75 |
| 76 addAnimation(set, tab.getLayoutTab(), MAX_CONTENT_HEIGHT, |
| 77 tab.getLayoutTab().getUnclampedOriginalContentHeight(), |
| 78 mHeightMinusTopControls, ENTER_STACK_ANIMATION_DURATION, |
| 79 ENTER_STACK_RESIZE_DELAY); |
| 80 addAnimation(set, tab, Y_IN_STACK_INFLUENCE, 0.0f, 1.0f, |
| 81 ENTER_STACK_BORDER_ALPHA_DURATION, 0); |
| 82 addAnimation( |
| 83 set, tab, SCALE, 1.0f, SCALE_AMOUNT, ENTER_STACK_BORDER_
ALPHA_DURATION, 0); |
| 84 addAnimation(set, tab.getLayoutTab(), TOOLBAR_ALPHA, 1.f, 0.f, |
| 85 ENTER_STACK_BORDER_ALPHA_DURATION, ENTER_STACK_TOOLBAR_A
LPHA_DELAY); |
| 86 addAnimation(set, tab.getLayoutTab(), TOOLBAR_Y_OFFSET, 0.f, |
| 87 getToolbarOffsetToLineUpWithBorder(), ENTER_STACK_BORDER
_ALPHA_DURATION, |
| 88 TAB_FOCUSED_TOOLBAR_ALPHA_DELAY); |
| 89 addAnimation(set, tab.getLayoutTab(), SIDE_BORDER_SCALE, 0.f, 1.
f, |
| 90 ENTER_STACK_BORDER_ALPHA_DURATION, TAB_FOCUSED_TOOLBAR_A
LPHA_DELAY); |
| 91 |
| 92 tab.setYOutOfStack(mHeight - mHeightMinusTopControls - mBorderTo
pHeight); |
| 93 } |
| 94 } |
| 95 |
| 96 return set; |
| 97 } |
| 98 |
| 99 @Override |
| 100 protected ChromeAnimation<?> createTabFocusedAnimatorSet( |
| 101 StackTab[] tabs, int focusIndex, int spacing, float warpSize) { |
| 102 ChromeAnimation<Animatable<?>> set = new ChromeAnimation<Animatable<?>>(
); |
| 103 for (int i = 0; i < tabs.length; ++i) { |
| 104 StackTab tab = tabs[i]; |
| 105 LayoutTab layoutTab = tab.getLayoutTab(); |
| 106 |
| 107 addTiltScrollAnimation(set, layoutTab, 0.0f, TAB_FOCUSED_ANIMATION_D
URATION, 0); |
| 108 addAnimation(set, tab, DISCARD_AMOUNT, tab.getDiscardAmount(), 0.0f, |
| 109 TAB_FOCUSED_ANIMATION_DURATION, 0); |
| 110 |
| 111 if (i < focusIndex) { |
| 112 // For tabs above the focused tab move them up to 0. |
| 113 addAnimation(set, tab, SCROLL_OFFSET, tab.getScrollOffset(), |
| 114 tab.getScrollOffset() - mHeight - spacing, TAB_FOCUSED_A
NIMATION_DURATION, |
| 115 0); |
| 116 } else if (i > focusIndex) { |
| 117 // We also need to animate the Y Translation to move them down |
| 118 // off the screen. |
| 119 float coveringTabPosition = layoutTab.getY(); |
| 120 float distanceToBorder = MathUtils.clamp(mHeight - coveringTabPo
sition, 0, mHeight); |
| 121 float delay = TAB_FOCUSED_MAX_DELAY * distanceToBorder / mHeight
; |
| 122 addAnimation(set, tab, Y_IN_STACK_OFFSET, tab.getYInStackOffset(
), |
| 123 tab.getYInStackOffset() + mHeight, |
| 124 (TAB_FOCUSED_ANIMATION_DURATION - (long) delay), (long)
delay); |
| 125 } else { |
| 126 // This is the focused tab. We need to scale it back to |
| 127 // 1.0f, move it to the top of the screen, and animate the |
| 128 // YTranslation so that it looks like it is zooming into the |
| 129 // full screen view. |
| 130 tab.setXOutOfStack(0.0f); |
| 131 tab.setYOutOfStack(0.0f); |
| 132 layoutTab.setBorderScale(1.f); |
| 133 |
| 134 addAnimation(set, tab, SCROLL_OFFSET, tab.getScrollOffset(), |
| 135 Math.max(0.0f, tab.getScrollOffset() - mWidth - spacing)
, |
| 136 TAB_FOCUSED_ANIMATION_DURATION, 0); |
| 137 addAnimation( |
| 138 set, tab, SCALE, tab.getScale(), 1.0f, TAB_FOCUSED_ANIMA
TION_DURATION, 0); |
| 139 addAnimation(set, tab, Y_IN_STACK_INFLUENCE, tab.getYInStackInfl
uence(), 0.0f, |
| 140 TAB_FOCUSED_Y_STACK_DURATION, 0); |
| 141 addAnimation(set, tab.getLayoutTab(), MAX_CONTENT_HEIGHT, |
| 142 tab.getLayoutTab().getMaxContentHeight(), |
| 143 tab.getLayoutTab().getUnclampedOriginalContentHeight(), |
| 144 TAB_FOCUSED_ANIMATION_DURATION, 0); |
| 145 tab.setYOutOfStack(mHeight - mHeightMinusTopControls - mBorderTo
pHeight); |
| 146 if (layoutTab.shouldStall()) { |
| 147 addAnimation(set, layoutTab, SATURATION, 1.0f, 0.0f, |
| 148 TAB_FOCUSED_BORDER_ALPHA_DURATION, TAB_FOCUSED_BORDE
R_ALPHA_DELAY); |
| 149 } |
| 150 addAnimation(set, tab.getLayoutTab(), TOOLBAR_ALPHA, layoutTab.g
etToolbarAlpha(), |
| 151 1.f, TAB_FOCUSED_TOOLBAR_ALPHA_DURATION, TAB_FOCUSED_TOO
LBAR_ALPHA_DELAY); |
| 152 addAnimation(set, tab.getLayoutTab(), TOOLBAR_Y_OFFSET, |
| 153 getToolbarOffsetToLineUpWithBorder(), 0.f, |
| 154 TAB_FOCUSED_TOOLBAR_ALPHA_DURATION, TAB_FOCUSED_TOOLBAR_
ALPHA_DELAY); |
| 155 addAnimation(set, tab.getLayoutTab(), SIDE_BORDER_SCALE, 1.f, 0.
f, |
| 156 TAB_FOCUSED_TOOLBAR_ALPHA_DURATION, TAB_FOCUSED_TOOLBAR_
ALPHA_DELAY); |
| 157 } |
| 158 } |
| 159 |
| 160 return set; |
| 161 } |
| 162 |
| 163 @Override |
| 164 protected ChromeAnimation<?> createViewMoreAnimatorSet(StackTab[] tabs, int
selectedIndex) { |
| 165 ChromeAnimation<Animatable<?>> set = new ChromeAnimation<Animatable<?>>(
); |
| 166 |
| 167 if (selectedIndex + 1 >= tabs.length) return set; |
| 168 |
| 169 float offset = tabs[selectedIndex].getScrollOffset() |
| 170 - tabs[selectedIndex + 1].getScrollOffset() |
| 171 + (tabs[selectedIndex].getLayoutTab().getScaledContentHeight() |
| 172 * VIEW_MORE_SIZE_RATIO); |
| 173 offset = Math.max(VIEW_MORE_MIN_SIZE, offset); |
| 174 for (int i = selectedIndex + 1; i < tabs.length; ++i) { |
| 175 addAnimation(set, tabs[i], SCROLL_OFFSET, tabs[i].getScrollOffset(), |
| 176 tabs[i].getScrollOffset() + offset, VIEW_MORE_ANIMATION_DURA
TION, 0); |
| 177 } |
| 178 |
| 179 return set; |
| 180 } |
| 181 |
| 182 @Override |
| 183 protected ChromeAnimation<?> createReachTopAnimatorSet(StackTab[] tabs, floa
t warpSize) { |
| 184 ChromeAnimation<Animatable<?>> set = new ChromeAnimation<Animatable<?>>(
); |
| 185 |
| 186 float screenTarget = 0.0f; |
| 187 for (int i = 0; i < tabs.length; ++i) { |
| 188 if (screenTarget >= tabs[i].getLayoutTab().getY()) { |
| 189 break; |
| 190 } |
| 191 addAnimation(set, tabs[i], SCROLL_OFFSET, tabs[i].getScrollOffset(), |
| 192 StackTab.screenToScroll(screenTarget, warpSize), REACH_TOP_A
NIMATION_DURATION, |
| 193 0); |
| 194 screenTarget += tabs[i].getLayoutTab().getScaledContentHeight(); |
| 195 } |
| 196 |
| 197 return set; |
| 198 } |
| 199 |
| 200 @Override |
| 201 protected ChromeAnimation<?> createNewTabOpenedAnimatorSet( |
| 202 StackTab[] tabs, int focusIndex, float discardRange) { |
| 203 return super.createNewTabOpenedAnimatorSet(tabs, focusIndex, -discardRan
ge); |
| 204 } |
| 205 |
| 206 @Override |
| 207 protected boolean isDefaultDiscardDirectionPositive() { |
| 208 // On clicking the close button, discard the tab to the right on LTR, to
the left on RTL. |
| 209 return !LocalizationUtils.isLayoutRtl(); |
| 210 } |
| 211 |
| 212 @Override |
| 213 protected float getScreenPositionInScrollDirection(StackTab tab) { |
| 214 return tab.getLayoutTab().getY(); |
| 215 } |
| 216 |
| 217 @Override |
| 218 protected void addTiltScrollAnimation(ChromeAnimation<Animatable<?>> set, La
youtTab tab, |
| 219 float end, int duration, int startTime) { |
| 220 addAnimation(set, tab, TILTX, tab.getTiltX(), end, duration, startTime); |
| 221 } |
| 222 |
| 223 @Override |
| 224 protected float getScreenSizeInScrollDirection() { |
| 225 return mHeight; |
| 226 } |
| 227 |
| 228 @Override |
| 229 protected int getTabCreationDirection() { |
| 230 return -1; |
| 231 } |
| 232 } |
OLD | NEW |