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; | |
103 | 102 |
104 /** The tabs currently being rendered as part of this layout. The tabs are | 103 /** The tabs currently being rendered as part of this layout. The tabs are |
105 * drawn using the same ordering as this array. */ | 104 * drawn using the same ordering as this array. */ |
106 protected LayoutTab[] mLayoutTabs; | 105 protected LayoutTab[] mLayoutTabs; |
107 | 106 |
108 // True means that the layout is going to hide as soon as the animation fini
shes. | 107 // True means that the layout is going to hide as soon as the animation fini
shes. |
109 private boolean mIsHiding; | 108 private boolean mIsHiding; |
110 | 109 |
111 // The next id to show when the layout is hidden, or TabBase#INVALID_TAB_ID
if no change. | 110 // The next id to show when the layout is hidden, or TabBase#INVALID_TAB_ID
if no change. |
112 private int mNextTabId = Tab.INVALID_TAB_ID; | 111 private int mNextTabId = Tab.INVALID_TAB_ID; |
113 | 112 |
114 // The ratio of dp to px. | 113 // The ratio of dp to px. |
115 private final float mDpToPx; | 114 private final float mDpToPx; |
116 | 115 |
117 /** | 116 /** |
118 * The {@link Layout} is not usable until sizeChanged is called. | 117 * The {@link Layout} is not usable until sizeChanged is called. |
119 * This is convenient this way so we can pre-create the layout before the ho
st is fully defined. | 118 * This is convenient this way so we can pre-create the layout before the ho
st is fully defined. |
120 * @param context The current Android's context. | 119 * @param context The current Android's context. |
121 * @param updateHost The parent {@link LayoutUpdateHost}. | 120 * @param updateHost The parent {@link LayoutUpdateHost}. |
122 * @param renderHost The parent {@link LayoutRenderHost}. | 121 * @param renderHost The parent {@link LayoutRenderHost}. |
123 * @param eventFilter The {@link EventFilter} this {@link Layout} is listen
ing to. | |
124 */ | 122 */ |
125 public Layout(Context context, LayoutUpdateHost updateHost, LayoutRenderHost
renderHost, | 123 public Layout(Context context, LayoutUpdateHost updateHost, LayoutRenderHost
renderHost) { |
126 EventFilter eventFilter) { | |
127 mContext = context; | 124 mContext = context; |
128 mUpdateHost = updateHost; | 125 mUpdateHost = updateHost; |
129 mRenderHost = renderHost; | 126 mRenderHost = renderHost; |
130 mEventFilter = eventFilter; | |
131 | 127 |
132 // Invalid sizes | 128 // Invalid sizes |
133 mWidthDp = -1; | 129 mWidthDp = -1; |
134 mHeightDp = -1; | 130 mHeightDp = -1; |
135 mHeightMinusBrowserControlsDp = -1; | 131 mHeightMinusBrowserControlsDp = -1; |
136 | 132 |
137 mCurrentOrientation = Orientation.UNSET; | 133 mCurrentOrientation = Orientation.UNSET; |
138 mDpToPx = context.getResources().getDisplayMetrics().density; | 134 mDpToPx = context.getResources().getDisplayMetrics().density; |
139 } | 135 } |
140 | 136 |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 */ | 561 */ |
566 protected boolean initLayoutTabFromHost(LayoutTab layoutTab) { | 562 protected boolean initLayoutTabFromHost(LayoutTab layoutTab) { |
567 if (layoutTab.isInitFromHostNeeded()) { | 563 if (layoutTab.isInitFromHostNeeded()) { |
568 mUpdateHost.initLayoutTabFromHost(layoutTab.getId()); | 564 mUpdateHost.initLayoutTabFromHost(layoutTab.getId()); |
569 return true; | 565 return true; |
570 } | 566 } |
571 return false; | 567 return false; |
572 } | 568 } |
573 | 569 |
574 /** | 570 /** |
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 /** | |
638 * Called by the LayoutManager when an animation should be killed. | 571 * Called by the LayoutManager when an animation should be killed. |
639 */ | 572 */ |
640 public void unstallImmediately() { } | 573 public void unstallImmediately() { } |
641 | 574 |
642 /** | 575 /** |
643 * Called by the LayoutManager when an animation should be killed. | 576 * Called by the LayoutManager when an animation should be killed. |
644 * @param tabId The tab that the kill signal is associated with | 577 * @param tabId The tab that the kill signal is associated with |
645 */ | 578 */ |
646 public void unstallImmediately(int tabId) { } | 579 public void unstallImmediately(int tabId) { } |
647 | 580 |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1031 } | 964 } |
1032 | 965 |
1033 /** | 966 /** |
1034 * @return True if the currently active content view is shown in the normal
interactive mode. | 967 * @return True if the currently active content view is shown in the normal
interactive mode. |
1035 */ | 968 */ |
1036 public boolean isTabInteractive() { | 969 public boolean isTabInteractive() { |
1037 return false; | 970 return false; |
1038 } | 971 } |
1039 | 972 |
1040 /** | 973 /** |
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 /** | |
1050 * @param e The {@link MotionEvent} to consider. | 974 * @param e The {@link MotionEvent} to consider. |
1051 * @param offsets The current touch offsets that should be applied
to the | 975 * @param offsets The current touch offsets that should be applied
to the |
1052 * {@link EventFilter}s. | 976 * {@link EventFilter}s. |
1053 * @param isKeyboardShowing Whether or not the keyboard is showing. | 977 * @param isKeyboardShowing Whether or not the keyboard is showing. |
1054 * @return The {@link EventFilter} the {@link Layout} is listening to. | 978 * @return The {@link EventFilter} the {@link Layout} is listening to. |
1055 */ | 979 */ |
1056 public EventFilter findInterceptingEventFilter( | 980 public EventFilter findInterceptingEventFilter( |
1057 MotionEvent e, PointF offsets, boolean isKeyboardShowing) { | 981 MotionEvent e, PointF offsets, boolean isKeyboardShowing) { |
1058 // The last added overlay will be drawn on top of everything else, there
fore the last | 982 // The last added overlay will be drawn on top of everything else, there
fore the last |
1059 // filter added should have the first chance to intercept any touch even
ts. | 983 // filter added should have the first chance to intercept any touch even
ts. |
1060 for (int i = mSceneOverlays.size() - 1; i >= 0; i--) { | 984 for (int i = mSceneOverlays.size() - 1; i >= 0; i--) { |
1061 EventFilter eventFilter = mSceneOverlays.get(i).getEventFilter(); | 985 EventFilter eventFilter = mSceneOverlays.get(i).getEventFilter(); |
1062 if (eventFilter == null) continue; | 986 if (eventFilter == null) continue; |
1063 if (offsets != null) eventFilter.setCurrentMotionEventOffsets(offset
s.x, offsets.y); | 987 if (offsets != null) eventFilter.setCurrentMotionEventOffsets(offset
s.x, offsets.y); |
1064 if (eventFilter.onInterceptTouchEvent(e, isKeyboardShowing)) return
eventFilter; | 988 if (eventFilter.onInterceptTouchEvent(e, isKeyboardShowing)) return
eventFilter; |
1065 } | 989 } |
1066 | 990 |
1067 if (mEventFilter != null) { | 991 EventFilter layoutEventFilter = getEventFilter(); |
1068 if (offsets != null) mEventFilter.setCurrentMotionEventOffsets(offse
ts.x, offsets.y); | 992 if (layoutEventFilter != null) { |
1069 if (mEventFilter.onInterceptTouchEvent(e, isKeyboardShowing)) return
mEventFilter; | 993 if (offsets != null) { |
| 994 layoutEventFilter.setCurrentMotionEventOffsets(offsets.x, offset
s.y); |
| 995 } |
| 996 if (layoutEventFilter.onInterceptTouchEvent(e, isKeyboardShowing)) { |
| 997 return layoutEventFilter; |
| 998 } |
1070 } | 999 } |
1071 return null; | 1000 return null; |
1072 } | 1001 } |
1073 | 1002 |
1074 /** | 1003 /** |
1075 * Build a {@link SceneLayer} if it hasn't already been built, and update it
and return it. | 1004 * Build a {@link SceneLayer} if it hasn't already been built, and update it
and return it. |
1076 * | 1005 * |
1077 * @param viewport A viewport in which to display content in px. | 1006 * @param viewport A viewport in which to display content in px. |
1078 * @param visibleViewport The visible section of the viewport in px. | 1007 * @param visibleViewport The visible section of the viewport in px. |
1079 * @param layerTitleCache A layer title cache. | 1008 * @param layerTitleCache A layer title cache. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1120 } | 1049 } |
1121 | 1050 |
1122 /** | 1051 /** |
1123 * @return Whether or not the layout should permenantly show the browser con
trols. | 1052 * @return Whether or not the layout should permenantly show the browser con
trols. |
1124 */ | 1053 */ |
1125 public boolean forceShowBrowserControlsAndroidView() { | 1054 public boolean forceShowBrowserControlsAndroidView() { |
1126 return false; | 1055 return false; |
1127 } | 1056 } |
1128 | 1057 |
1129 /** | 1058 /** |
1130 * @return Whether the tabstrip's event filter is enabled. | 1059 * @return The EventFilter to use for processing events for this Layout. |
1131 */ | 1060 */ |
1132 public boolean isTabStripEventFilterEnabled() { | 1061 protected abstract EventFilter getEventFilter(); |
1133 return true; | |
1134 } | |
1135 | 1062 |
1136 /** | 1063 /** |
1137 * Get an instance of {@link SceneLayer}. Any class inheriting {@link Layout
} | 1064 * Get an instance of {@link SceneLayer}. Any class inheriting {@link Layout
} |
1138 * should override this function in order for other functions to work. | 1065 * should override this function in order for other functions to work. |
1139 * | 1066 * |
1140 * @return The scene layer for this {@link Layout}. | 1067 * @return The scene layer for this {@link Layout}. |
1141 */ | 1068 */ |
1142 protected abstract SceneLayer getSceneLayer(); | 1069 protected abstract SceneLayer getSceneLayer(); |
1143 | 1070 |
1144 /** | 1071 /** |
1145 * Update {@link SceneLayer} instance this layout holds. Any class inheritin
g {@link Layout} | 1072 * Update {@link SceneLayer} instance this layout holds. Any class inheritin
g {@link Layout} |
1146 * should override this function in order for other functions to work. | 1073 * should override this function in order for other functions to work. |
1147 */ | 1074 */ |
1148 protected void updateSceneLayer(RectF viewport, RectF contentViewport, | 1075 protected void updateSceneLayer(RectF viewport, RectF contentViewport, |
1149 LayerTitleCache layerTitleCache, TabContentManager tabContentManager
, | 1076 LayerTitleCache layerTitleCache, TabContentManager tabContentManager
, |
1150 ResourceManager resourceManager, ChromeFullscreenManager fullscreenM
anager) { | 1077 ResourceManager resourceManager, ChromeFullscreenManager fullscreenM
anager) { |
1151 } | 1078 } |
1152 } | 1079 } |
OLD | NEW |