| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.compositor.layouts; | 5 package org.chromium.chrome.browser.compositor.layouts; |
| 6 | 6 |
| 7 import static org.chromium.chrome.browser.compositor.layouts.ChromeAnimation.Ani
matableAnimation.createAnimation; | 7 import static org.chromium.chrome.browser.compositor.layouts.ChromeAnimation.Ani
matableAnimation.createAnimation; |
| 8 | 8 |
| 9 import android.content.Context; | 9 import android.content.Context; |
| 10 import android.graphics.PointF; | 10 import android.graphics.PointF; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 protected TabContentManager mTabContentManager; | 92 protected TabContentManager mTabContentManager; |
| 93 | 93 |
| 94 private ChromeAnimation<Animatable<?>> mLayoutAnimations; | 94 private ChromeAnimation<Animatable<?>> mLayoutAnimations; |
| 95 | 95 |
| 96 // Tablet tab strip managers. | 96 // Tablet tab strip managers. |
| 97 private final List<SceneOverlay> mSceneOverlays = new ArrayList<SceneOverlay
>(); | 97 private final List<SceneOverlay> mSceneOverlays = new ArrayList<SceneOverlay
>(); |
| 98 | 98 |
| 99 // Helpers | 99 // Helpers |
| 100 private final LayoutUpdateHost mUpdateHost; | 100 private final LayoutUpdateHost mUpdateHost; |
| 101 protected final LayoutRenderHost mRenderHost; | 101 protected final LayoutRenderHost mRenderHost; |
| 102 private EventFilter mEventFilter; |
| 102 | 103 |
| 103 /** The tabs currently being rendered as part of this layout. The tabs are | 104 /** The tabs currently being rendered as part of this layout. The tabs are |
| 104 * drawn using the same ordering as this array. */ | 105 * drawn using the same ordering as this array. */ |
| 105 protected LayoutTab[] mLayoutTabs; | 106 protected LayoutTab[] mLayoutTabs; |
| 106 | 107 |
| 107 // True means that the layout is going to hide as soon as the animation fini
shes. | 108 // True means that the layout is going to hide as soon as the animation fini
shes. |
| 108 private boolean mIsHiding; | 109 private boolean mIsHiding; |
| 109 | 110 |
| 110 // The next id to show when the layout is hidden, or TabBase#INVALID_TAB_ID
if no change. | 111 // The next id to show when the layout is hidden, or TabBase#INVALID_TAB_ID
if no change. |
| 111 private int mNextTabId = Tab.INVALID_TAB_ID; | 112 private int mNextTabId = Tab.INVALID_TAB_ID; |
| 112 | 113 |
| 113 // The ratio of dp to px. | 114 // The ratio of dp to px. |
| 114 private final float mDpToPx; | 115 private final float mDpToPx; |
| 115 | 116 |
| 116 /** | 117 /** |
| 117 * The {@link Layout} is not usable until sizeChanged is called. | 118 * The {@link Layout} is not usable until sizeChanged is called. |
| 118 * This is convenient this way so we can pre-create the layout before the ho
st is fully defined. | 119 * This is convenient this way so we can pre-create the layout before the ho
st is fully defined. |
| 119 * @param context The current Android's context. | 120 * @param context The current Android's context. |
| 120 * @param updateHost The parent {@link LayoutUpdateHost}. | 121 * @param updateHost The parent {@link LayoutUpdateHost}. |
| 121 * @param renderHost The parent {@link LayoutRenderHost}. | 122 * @param renderHost The parent {@link LayoutRenderHost}. |
| 123 * @param eventFilter The {@link EventFilter} this {@link Layout} is listen
ing to. |
| 122 */ | 124 */ |
| 123 public Layout(Context context, LayoutUpdateHost updateHost, LayoutRenderHost
renderHost) { | 125 public Layout(Context context, LayoutUpdateHost updateHost, LayoutRenderHost
renderHost, |
| 126 EventFilter eventFilter) { |
| 124 mContext = context; | 127 mContext = context; |
| 125 mUpdateHost = updateHost; | 128 mUpdateHost = updateHost; |
| 126 mRenderHost = renderHost; | 129 mRenderHost = renderHost; |
| 130 mEventFilter = eventFilter; |
| 127 | 131 |
| 128 // Invalid sizes | 132 // Invalid sizes |
| 129 mWidthDp = -1; | 133 mWidthDp = -1; |
| 130 mHeightDp = -1; | 134 mHeightDp = -1; |
| 131 mHeightMinusBrowserControlsDp = -1; | 135 mHeightMinusBrowserControlsDp = -1; |
| 132 | 136 |
| 133 mCurrentOrientation = Orientation.UNSET; | 137 mCurrentOrientation = Orientation.UNSET; |
| 134 mDpToPx = context.getResources().getDisplayMetrics().density; | 138 mDpToPx = context.getResources().getDisplayMetrics().density; |
| 135 } | 139 } |
| 136 | 140 |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 */ | 565 */ |
| 562 protected boolean initLayoutTabFromHost(LayoutTab layoutTab) { | 566 protected boolean initLayoutTabFromHost(LayoutTab layoutTab) { |
| 563 if (layoutTab.isInitFromHostNeeded()) { | 567 if (layoutTab.isInitFromHostNeeded()) { |
| 564 mUpdateHost.initLayoutTabFromHost(layoutTab.getId()); | 568 mUpdateHost.initLayoutTabFromHost(layoutTab.getId()); |
| 565 return true; | 569 return true; |
| 566 } | 570 } |
| 567 return false; | 571 return false; |
| 568 } | 572 } |
| 569 | 573 |
| 570 /** | 574 /** |
| 575 * Called on touch drag event. |
| 576 * @param time The current time of the app in ms. |
| 577 * @param x The y coordinate of the end of the drag event. |
| 578 * @param y The y coordinate of the end of the drag event. |
| 579 * @param deltaX The number of pixels dragged in the x direction. |
| 580 * @param deltaY The number of pixels dragged in the y direction. |
| 581 */ |
| 582 public void drag(long time, float x, float y, float deltaX, float deltaY) {
} |
| 583 |
| 584 /** |
| 585 * Called on touch fling event. This is called before the onUpOrCancel event
. |
| 586 * |
| 587 * @param time The current time of the app in ms. |
| 588 * @param x The y coordinate of the start of the fling event. |
| 589 * @param y The y coordinate of the start of the fling event. |
| 590 * @param velocityX The amount of velocity in the x direction. |
| 591 * @param velocityY The amount of velocity in the y direction. |
| 592 */ |
| 593 public void fling(long time, float x, float y, float velocityX, float veloci
tyY) { } |
| 594 |
| 595 /** |
| 596 * Called on onDown event. |
| 597 * |
| 598 * @param time The time stamp in millisecond of the event. |
| 599 * @param x The x position of the event. |
| 600 * @param y The y position of the event. |
| 601 */ |
| 602 public void onDown(long time, float x, float y) { } |
| 603 |
| 604 /** |
| 605 * Called on long press touch event. |
| 606 * @param time The current time of the app in ms. |
| 607 * @param x The x coordinate of the position of the press event. |
| 608 * @param y The y coordinate of the position of the press event. |
| 609 */ |
| 610 public void onLongPress(long time, float x, float y) { } |
| 611 |
| 612 /** |
| 613 * Called on click. This is called before the onUpOrCancel event. |
| 614 * @param time The current time of the app in ms. |
| 615 * @param x The x coordinate of the position of the click. |
| 616 * @param y The y coordinate of the position of the click. |
| 617 */ |
| 618 public void click(long time, float x, float y) { } |
| 619 |
| 620 /** |
| 621 * Called on up or cancel touch events. This is called after the click and f
ling event if any. |
| 622 * @param time The current time of the app in ms. |
| 623 */ |
| 624 public void onUpOrCancel(long time) { } |
| 625 |
| 626 /** |
| 627 * Called when at least 2 touch events are detected. |
| 628 * @param time The current time of the app in ms. |
| 629 * @param x0 The x coordinate of the first touch event. |
| 630 * @param y0 The y coordinate of the first touch event. |
| 631 * @param x1 The x coordinate of the second touch event. |
| 632 * @param y1 The y coordinate of the second touch event. |
| 633 * @param firstEvent The pinch is the first of a sequence of pinch events. |
| 634 */ |
| 635 public void onPinch(long time, float x0, float y0, float x1, float y1, boole
an firstEvent) { } |
| 636 |
| 637 /** |
| 571 * Called by the LayoutManager when an animation should be killed. | 638 * Called by the LayoutManager when an animation should be killed. |
| 572 */ | 639 */ |
| 573 public void unstallImmediately() { } | 640 public void unstallImmediately() { } |
| 574 | 641 |
| 575 /** | 642 /** |
| 576 * Called by the LayoutManager when an animation should be killed. | 643 * Called by the LayoutManager when an animation should be killed. |
| 577 * @param tabId The tab that the kill signal is associated with | 644 * @param tabId The tab that the kill signal is associated with |
| 578 */ | 645 */ |
| 579 public void unstallImmediately(int tabId) { } | 646 public void unstallImmediately(int tabId) { } |
| 580 | 647 |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 964 } | 1031 } |
| 965 | 1032 |
| 966 /** | 1033 /** |
| 967 * @return True if the currently active content view is shown in the normal
interactive mode. | 1034 * @return True if the currently active content view is shown in the normal
interactive mode. |
| 968 */ | 1035 */ |
| 969 public boolean isTabInteractive() { | 1036 public boolean isTabInteractive() { |
| 970 return false; | 1037 return false; |
| 971 } | 1038 } |
| 972 | 1039 |
| 973 /** | 1040 /** |
| 1041 * Setting this will only take effect the next time this layout is shown. I
f it is currently |
| 1042 * showing the original filter will still be used. |
| 1043 * @param filter |
| 1044 */ |
| 1045 public void setEventFilter(EventFilter filter) { |
| 1046 mEventFilter = filter; |
| 1047 } |
| 1048 |
| 1049 /** |
| 974 * @param e The {@link MotionEvent} to consider. | 1050 * @param e The {@link MotionEvent} to consider. |
| 975 * @param offsets The current touch offsets that should be applied
to the | 1051 * @param offsets The current touch offsets that should be applied
to the |
| 976 * {@link EventFilter}s. | 1052 * {@link EventFilter}s. |
| 977 * @param isKeyboardShowing Whether or not the keyboard is showing. | 1053 * @param isKeyboardShowing Whether or not the keyboard is showing. |
| 978 * @return The {@link EventFilter} the {@link Layout} is listening to. | 1054 * @return The {@link EventFilter} the {@link Layout} is listening to. |
| 979 */ | 1055 */ |
| 980 public EventFilter findInterceptingEventFilter( | 1056 public EventFilter findInterceptingEventFilter( |
| 981 MotionEvent e, PointF offsets, boolean isKeyboardShowing) { | 1057 MotionEvent e, PointF offsets, boolean isKeyboardShowing) { |
| 982 // The last added overlay will be drawn on top of everything else, there
fore the last | 1058 // The last added overlay will be drawn on top of everything else, there
fore the last |
| 983 // filter added should have the first chance to intercept any touch even
ts. | 1059 // filter added should have the first chance to intercept any touch even
ts. |
| 984 for (int i = mSceneOverlays.size() - 1; i >= 0; i--) { | 1060 for (int i = mSceneOverlays.size() - 1; i >= 0; i--) { |
| 985 EventFilter eventFilter = mSceneOverlays.get(i).getEventFilter(); | 1061 EventFilter eventFilter = mSceneOverlays.get(i).getEventFilter(); |
| 986 if (eventFilter == null) continue; | 1062 if (eventFilter == null) continue; |
| 987 if (offsets != null) eventFilter.setCurrentMotionEventOffsets(offset
s.x, offsets.y); | 1063 if (offsets != null) eventFilter.setCurrentMotionEventOffsets(offset
s.x, offsets.y); |
| 988 if (eventFilter.onInterceptTouchEvent(e, isKeyboardShowing)) return
eventFilter; | 1064 if (eventFilter.onInterceptTouchEvent(e, isKeyboardShowing)) return
eventFilter; |
| 989 } | 1065 } |
| 990 | 1066 |
| 991 EventFilter layoutEventFilter = getEventFilter(); | 1067 if (mEventFilter != null) { |
| 992 if (layoutEventFilter != null) { | 1068 if (offsets != null) mEventFilter.setCurrentMotionEventOffsets(offse
ts.x, offsets.y); |
| 993 if (offsets != null) { | 1069 if (mEventFilter.onInterceptTouchEvent(e, isKeyboardShowing)) return
mEventFilter; |
| 994 layoutEventFilter.setCurrentMotionEventOffsets(offsets.x, offset
s.y); | |
| 995 } | |
| 996 if (layoutEventFilter.onInterceptTouchEvent(e, isKeyboardShowing)) { | |
| 997 return layoutEventFilter; | |
| 998 } | |
| 999 } | 1070 } |
| 1000 return null; | 1071 return null; |
| 1001 } | 1072 } |
| 1002 | 1073 |
| 1003 /** | 1074 /** |
| 1004 * Build a {@link SceneLayer} if it hasn't already been built, and update it
and return it. | 1075 * Build a {@link SceneLayer} if it hasn't already been built, and update it
and return it. |
| 1005 * | 1076 * |
| 1006 * @param viewport A viewport in which to display content in px. | 1077 * @param viewport A viewport in which to display content in px. |
| 1007 * @param visibleViewport The visible section of the viewport in px. | 1078 * @param visibleViewport The visible section of the viewport in px. |
| 1008 * @param layerTitleCache A layer title cache. | 1079 * @param layerTitleCache A layer title cache. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1049 } | 1120 } |
| 1050 | 1121 |
| 1051 /** | 1122 /** |
| 1052 * @return Whether or not the layout should permenantly show the browser con
trols. | 1123 * @return Whether or not the layout should permenantly show the browser con
trols. |
| 1053 */ | 1124 */ |
| 1054 public boolean forceShowBrowserControlsAndroidView() { | 1125 public boolean forceShowBrowserControlsAndroidView() { |
| 1055 return false; | 1126 return false; |
| 1056 } | 1127 } |
| 1057 | 1128 |
| 1058 /** | 1129 /** |
| 1059 * @return The EventFilter to use for processing events for this Layout. | 1130 * @return Whether the tabstrip's event filter is enabled. |
| 1060 */ | 1131 */ |
| 1061 protected abstract EventFilter getEventFilter(); | 1132 public boolean isTabStripEventFilterEnabled() { |
| 1133 return true; |
| 1134 } |
| 1062 | 1135 |
| 1063 /** | 1136 /** |
| 1064 * Get an instance of {@link SceneLayer}. Any class inheriting {@link Layout
} | 1137 * Get an instance of {@link SceneLayer}. Any class inheriting {@link Layout
} |
| 1065 * should override this function in order for other functions to work. | 1138 * should override this function in order for other functions to work. |
| 1066 * | 1139 * |
| 1067 * @return The scene layer for this {@link Layout}. | 1140 * @return The scene layer for this {@link Layout}. |
| 1068 */ | 1141 */ |
| 1069 protected abstract SceneLayer getSceneLayer(); | 1142 protected abstract SceneLayer getSceneLayer(); |
| 1070 | 1143 |
| 1071 /** | 1144 /** |
| 1072 * Update {@link SceneLayer} instance this layout holds. Any class inheritin
g {@link Layout} | 1145 * Update {@link SceneLayer} instance this layout holds. Any class inheritin
g {@link Layout} |
| 1073 * should override this function in order for other functions to work. | 1146 * should override this function in order for other functions to work. |
| 1074 */ | 1147 */ |
| 1075 protected void updateSceneLayer(RectF viewport, RectF contentViewport, | 1148 protected void updateSceneLayer(RectF viewport, RectF contentViewport, |
| 1076 LayerTitleCache layerTitleCache, TabContentManager tabContentManager
, | 1149 LayerTitleCache layerTitleCache, TabContentManager tabContentManager
, |
| 1077 ResourceManager resourceManager, ChromeFullscreenManager fullscreenM
anager) { | 1150 ResourceManager resourceManager, ChromeFullscreenManager fullscreenM
anager) { |
| 1078 } | 1151 } |
| 1079 } | 1152 } |
| OLD | NEW |