| Index: chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/phone/StackLayout.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/phone/StackLayout.java b/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/phone/StackLayout.java
|
| index 5c336f2187576ce9f1ef7cd6ae1be7079d758ad7..cea303618ba9dd3d025423d6c11edf2b981ad32a 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/phone/StackLayout.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/phone/StackLayout.java
|
| @@ -17,14 +17,11 @@
|
| import org.chromium.chrome.browser.compositor.LayerTitleCache;
|
| import org.chromium.chrome.browser.compositor.layouts.ChromeAnimation.Animatable;
|
| import org.chromium.chrome.browser.compositor.layouts.Layout;
|
| -import org.chromium.chrome.browser.compositor.layouts.LayoutManager;
|
| import org.chromium.chrome.browser.compositor.layouts.LayoutRenderHost;
|
| import org.chromium.chrome.browser.compositor.layouts.LayoutUpdateHost;
|
| import org.chromium.chrome.browser.compositor.layouts.components.LayoutTab;
|
| import org.chromium.chrome.browser.compositor.layouts.content.TabContentManager;
|
| import org.chromium.chrome.browser.compositor.layouts.eventfilter.EventFilter;
|
| -import org.chromium.chrome.browser.compositor.layouts.eventfilter.GestureEventFilter;
|
| -import org.chromium.chrome.browser.compositor.layouts.eventfilter.GestureHandler;
|
| import org.chromium.chrome.browser.compositor.layouts.eventfilter.ScrollDirection;
|
| import org.chromium.chrome.browser.compositor.layouts.phone.stack.Stack;
|
| import org.chromium.chrome.browser.compositor.layouts.phone.stack.StackTab;
|
| @@ -135,116 +132,7 @@
|
|
|
| private final ViewGroup mViewContainer;
|
|
|
| - private final GestureEventFilter mGestureEventFilter;
|
| private final TabListSceneLayer mSceneLayer;
|
| -
|
| - private StackLayoutGestureHandler mGestureHandler;
|
| -
|
| - private class StackLayoutGestureHandler implements GestureHandler {
|
| - @Override
|
| - public void onDown(float x, float y, boolean fromMouse, int buttons) {
|
| - long time = time();
|
| - mLastOnDownX = x;
|
| - mLastOnDownY = y;
|
| - mLastOnDownTimeStamp = time;
|
| - mInputMode = computeInputMode(time, x, y, 0, 0);
|
| - mStacks[getTabStackIndex()].onDown(time);
|
| - }
|
| -
|
| - @Override
|
| - public void onUpOrCancel() {
|
| - onUpOrCancel(time());
|
| - }
|
| -
|
| - @Override
|
| - public void drag(float x, float y, float dx, float dy, float tx, float ty) {
|
| - SwipeMode oldInputMode = mInputMode;
|
| - long time = time();
|
| - float amountX = dx;
|
| - float amountY = dy;
|
| - mInputMode = computeInputMode(time, x, y, amountX, amountY);
|
| -
|
| - if (oldInputMode == SwipeMode.SEND_TO_STACK && mInputMode == SwipeMode.SWITCH_STACK) {
|
| - mStacks[getTabStackIndex()].onUpOrCancel(time);
|
| - } else if (oldInputMode == SwipeMode.SWITCH_STACK
|
| - && mInputMode == SwipeMode.SEND_TO_STACK) {
|
| - onUpOrCancel(time);
|
| - }
|
| -
|
| - if (mInputMode == SwipeMode.SEND_TO_STACK) {
|
| - mStacks[getTabStackIndex()].drag(time, x, y, amountX, amountY);
|
| - } else if (mInputMode == SwipeMode.SWITCH_STACK) {
|
| - scrollStacks(getOrientation() == Orientation.PORTRAIT ? amountX : amountY);
|
| - }
|
| - }
|
| -
|
| - @Override
|
| - public void click(float x, float y, boolean fromMouse, int buttons) {
|
| - // Click event happens before the up event. mClicked is set to mute the up event.
|
| - mClicked = true;
|
| - PortraitViewport viewportParams = getViewportParameters();
|
| - int stackIndexAt = viewportParams.getStackIndexAt(x, y);
|
| - if (stackIndexAt == getTabStackIndex()) {
|
| - mStacks[getTabStackIndex()].click(time(), x, y);
|
| - } else {
|
| - flingStacks(getTabStackIndex() == 0);
|
| - }
|
| - requestStackUpdate();
|
| - }
|
| -
|
| - @Override
|
| - public void fling(float x, float y, float velocityX, float velocityY) {
|
| - long time = time();
|
| - float vx = velocityX;
|
| - float vy = velocityY;
|
| -
|
| - if (mInputMode == SwipeMode.NONE) {
|
| - mInputMode = computeInputMode(
|
| - time, x, y, vx * SWITCH_STACK_FLING_DT, vy * SWITCH_STACK_FLING_DT);
|
| - }
|
| -
|
| - if (mInputMode == SwipeMode.SEND_TO_STACK) {
|
| - mStacks[getTabStackIndex()].fling(time, x, y, vx, vy);
|
| - } else if (mInputMode == SwipeMode.SWITCH_STACK) {
|
| - final float velocity = getOrientation() == Orientation.PORTRAIT ? vx : vy;
|
| - final float origin = getOrientation() == Orientation.PORTRAIT ? x : y;
|
| - final float max =
|
| - getOrientation() == Orientation.PORTRAIT ? getWidth() : getHeight();
|
| - final float predicted = origin + velocity * SWITCH_STACK_FLING_DT;
|
| - final float delta = MathUtils.clamp(predicted, 0, max) - origin;
|
| - scrollStacks(delta);
|
| - }
|
| - requestStackUpdate();
|
| - }
|
| -
|
| - @Override
|
| - public void onLongPress(float x, float y) {
|
| - mStacks[getTabStackIndex()].onLongPress(time(), x, y);
|
| - }
|
| -
|
| - @Override
|
| - public void onPinch(float x0, float y0, float x1, float y1, boolean firstEvent) {
|
| - mStacks[getTabStackIndex()].onPinch(time(), x0, y0, x1, y1, firstEvent);
|
| - }
|
| -
|
| - private void onUpOrCancel(long time) {
|
| - int currentIndex = getTabStackIndex();
|
| - int nextIndex = 1 - currentIndex;
|
| - if (!mClicked
|
| - && Math.abs(currentIndex + mRenderedScrollOffset) > THRESHOLD_TO_SWITCH_STACK
|
| - && mStacks[nextIndex].isDisplayable()) {
|
| - setActiveStackState(nextIndex == 1);
|
| - }
|
| - mClicked = false;
|
| - finishScrollStacks();
|
| - mStacks[getTabStackIndex()].onUpOrCancel(time);
|
| - mInputMode = SwipeMode.NONE;
|
| - }
|
| -
|
| - private long time() {
|
| - return LayoutManager.time();
|
| - }
|
| - }
|
|
|
| /**
|
| * @param context The current Android's context.
|
| @@ -252,11 +140,10 @@
|
| * @param renderHost The {@link LayoutRenderHost} view for this layout.
|
| * @param eventFilter The {@link EventFilter} that is needed for this view.
|
| */
|
| - public StackLayout(Context context, LayoutUpdateHost updateHost, LayoutRenderHost renderHost) {
|
| - super(context, updateHost, renderHost);
|
| -
|
| - mGestureHandler = new StackLayoutGestureHandler();
|
| - mGestureEventFilter = new GestureEventFilter(context, mGestureHandler);
|
| + public StackLayout(Context context, LayoutUpdateHost updateHost, LayoutRenderHost renderHost,
|
| + EventFilter eventFilter) {
|
| + super(context, updateHost, renderHost, eventFilter);
|
| +
|
| final ViewConfiguration configuration = ViewConfiguration.get(context);
|
| mMinDirectionThreshold = configuration.getScaledTouchSlop();
|
| mMinShortPressThresholdSqr =
|
| @@ -278,32 +165,6 @@
|
| @Override
|
| public boolean forceShowBrowserControlsAndroidView() {
|
| return true;
|
| - }
|
| -
|
| - /**
|
| - * Simulates a click on the view at the specified pixel offset
|
| - * from the top left of the view.
|
| - * This is used by UI tests.
|
| - * @param x Coordinate of the click in dp.
|
| - * @param y Coordinate of the click in dp.
|
| - */
|
| - @VisibleForTesting
|
| - public void simulateClick(float x, float y) {
|
| - mGestureHandler.click(x, y, false, -1);
|
| - }
|
| -
|
| - /**
|
| - * Simulates a drag and issues Up-event to commit the drag.
|
| - * @param x Coordinate to start the Drag from in dp.
|
| - * @param y Coordinate to start the Drag from in dp.
|
| - * @param dX Amount of drag in X direction in dp.
|
| - * @param dY Amount of drag in Y direction in dp.
|
| - */
|
| - @VisibleForTesting
|
| - public void simulateDrag(float x, float y, float dX, float dY) {
|
| - mGestureHandler.onDown(x, y, false, -1);
|
| - mGestureHandler.drag(x, y, dX, dY, -1, -1);
|
| - mGestureHandler.onUpOrCancel();
|
| }
|
|
|
| @Override
|
| @@ -737,6 +598,25 @@
|
| requestStackUpdate();
|
| }
|
|
|
| + @Override
|
| + public void drag(long time, float x, float y, float amountX, float amountY) {
|
| + SwipeMode oldInputMode = mInputMode;
|
| + mInputMode = computeInputMode(time, x, y, amountX, amountY);
|
| +
|
| + if (oldInputMode == SwipeMode.SEND_TO_STACK && mInputMode == SwipeMode.SWITCH_STACK) {
|
| + mStacks[getTabStackIndex()].onUpOrCancel(time);
|
| + } else if (oldInputMode == SwipeMode.SWITCH_STACK
|
| + && mInputMode == SwipeMode.SEND_TO_STACK) {
|
| + onUpOrCancel(time);
|
| + }
|
| +
|
| + if (mInputMode == SwipeMode.SEND_TO_STACK) {
|
| + mStacks[getTabStackIndex()].drag(time, x, y, amountX, amountY);
|
| + } else if (mInputMode == SwipeMode.SWITCH_STACK) {
|
| + scrollStacks(getOrientation() == Orientation.PORTRAIT ? amountX : amountY);
|
| + }
|
| + }
|
| +
|
| /**
|
| * Computes the input mode for drag and fling based on the first event position.
|
| * @param time The current time of the app in ms.
|
| @@ -784,6 +664,26 @@
|
| return SwipeMode.SWITCH_STACK;
|
| }
|
| return SwipeMode.NONE;
|
| + }
|
| +
|
| + @Override
|
| + public void fling(long time, float x, float y, float vx, float vy) {
|
| + if (mInputMode == SwipeMode.NONE) {
|
| + mInputMode = computeInputMode(
|
| + time, x, y, vx * SWITCH_STACK_FLING_DT, vy * SWITCH_STACK_FLING_DT);
|
| + }
|
| +
|
| + if (mInputMode == SwipeMode.SEND_TO_STACK) {
|
| + mStacks[getTabStackIndex()].fling(time, x, y, vx, vy);
|
| + } else if (mInputMode == SwipeMode.SWITCH_STACK) {
|
| + final float velocity = getOrientation() == Orientation.PORTRAIT ? vx : vy;
|
| + final float origin = getOrientation() == Orientation.PORTRAIT ? x : y;
|
| + final float max = getOrientation() == Orientation.PORTRAIT ? getWidth() : getHeight();
|
| + final float predicted = origin + velocity * SWITCH_STACK_FLING_DT;
|
| + final float delta = MathUtils.clamp(predicted, 0, max) - origin;
|
| + scrollStacks(delta);
|
| + }
|
| + requestStackUpdate();
|
| }
|
|
|
| class PortraitViewport {
|
| @@ -916,6 +816,20 @@
|
| }
|
| return mCachedLandscapeViewport;
|
| }
|
| + }
|
| +
|
| + @Override
|
| + public void click(long time, float x, float y) {
|
| + // Click event happens before the up event. mClicked is set to mute the up event.
|
| + mClicked = true;
|
| + PortraitViewport viewportParams = getViewportParameters();
|
| + int stackIndexAt = viewportParams.getStackIndexAt(x, y);
|
| + if (stackIndexAt == getTabStackIndex()) {
|
| + mStacks[getTabStackIndex()].click(time, x, y);
|
| + } else {
|
| + flingStacks(getTabStackIndex() == 0);
|
| + }
|
| + requestStackUpdate();
|
| }
|
|
|
| /**
|
| @@ -990,6 +904,34 @@
|
| }
|
| }
|
|
|
| + @Override
|
| + public void onDown(long time, float x, float y) {
|
| + mLastOnDownX = x;
|
| + mLastOnDownY = y;
|
| + mLastOnDownTimeStamp = time;
|
| + mInputMode = computeInputMode(time, x, y, 0, 0);
|
| + mStacks[getTabStackIndex()].onDown(time);
|
| + }
|
| +
|
| + @Override
|
| + public void onLongPress(long time, float x, float y) {
|
| + mStacks[getTabStackIndex()].onLongPress(time, x, y);
|
| + }
|
| +
|
| + @Override
|
| + public void onUpOrCancel(long time) {
|
| + int currentIndex = getTabStackIndex();
|
| + int nextIndex = 1 - currentIndex;
|
| + if (!mClicked && Math.abs(currentIndex + mRenderedScrollOffset) > THRESHOLD_TO_SWITCH_STACK
|
| + && mStacks[nextIndex].isDisplayable()) {
|
| + setActiveStackState(nextIndex == 1);
|
| + }
|
| + mClicked = false;
|
| + finishScrollStacks();
|
| + mStacks[getTabStackIndex()].onUpOrCancel(time);
|
| + mInputMode = SwipeMode.NONE;
|
| + }
|
| +
|
| /**
|
| * Pushes a rectangle to be drawn on the screen on top of everything.
|
| *
|
| @@ -1008,6 +950,11 @@
|
| rect.top = tmp;
|
| }
|
| mRenderHost.pushDebugRect(rect, color);
|
| + }
|
| +
|
| + @Override
|
| + public void onPinch(long time, float x0, float y0, float x1, float y1, boolean firstEvent) {
|
| + mStacks[getTabStackIndex()].onPinch(time, x0, y0, x1, y1, firstEvent);
|
| }
|
|
|
| @Override
|
| @@ -1280,11 +1227,6 @@
|
| }
|
|
|
| @Override
|
| - protected EventFilter getEventFilter() {
|
| - return mGestureEventFilter;
|
| - }
|
| -
|
| - @Override
|
| protected SceneLayer getSceneLayer() {
|
| return mSceneLayer;
|
| }
|
|
|