OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.bottombar; | 5 package org.chromium.chrome.browser.compositor.bottombar; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.graphics.Color; | 8 import android.graphics.Color; |
9 import android.view.ViewGroup; | 9 import android.view.ViewGroup; |
10 | 10 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 */ | 152 */ |
153 protected abstract void closePanel(StateChangeReason reason, boolean animate
); | 153 protected abstract void closePanel(StateChangeReason reason, boolean animate
); |
154 | 154 |
155 /** | 155 /** |
156 * Event notification that the Panel did get closed. | 156 * Event notification that the Panel did get closed. |
157 * @param reason The reason the panel is closing. | 157 * @param reason The reason the panel is closing. |
158 */ | 158 */ |
159 protected abstract void onClosed(StateChangeReason reason); | 159 protected abstract void onClosed(StateChangeReason reason); |
160 | 160 |
161 /** | 161 /** |
162 * @return The absolute amount in DP that the top controls have shifted off
screen. | |
163 */ | |
164 protected abstract float getTopControlsOffsetDp(); | |
165 | |
166 /** | |
167 * TODO(mdjones): This method should be removed from this class. | 162 * TODO(mdjones): This method should be removed from this class. |
168 * @return The resource id that contains how large the top controls are. | 163 * @return The resource id that contains how large the top controls are. |
169 */ | 164 */ |
170 protected abstract int getControlContainerHeightResource(); | 165 protected abstract int getControlContainerHeightResource(); |
171 | 166 |
172 /** | 167 /** |
173 * Handles when the Panel's container view size changes. | 168 * Handles when the Panel's container view size changes. |
174 * @param width The new width of the Panel's container view. | 169 * @param width The new width of the Panel's container view. |
175 * @param height The new height of the Panel's container view. | 170 * @param height The new height of the Panel's container view. |
176 * @param previousWidth The previous width of the Panel's container view. | 171 * @param previousWidth The previous width of the Panel's container view. |
177 */ | 172 */ |
178 protected abstract void handleSizeChanged(float width, float height, float p
reviousWidth); | 173 protected abstract void handleSizeChanged(float width, float height, float p
reviousWidth); |
179 | 174 |
180 // =========================================================================
=================== | 175 // =========================================================================
=================== |
181 // Layout Integration | 176 // Layout Integration |
182 // =========================================================================
=================== | 177 // =========================================================================
=================== |
183 | 178 |
184 private float mLayoutWidth; | 179 private float mLayoutWidth; |
185 private float mLayoutHeight; | 180 private float mLayoutHeight; |
| 181 private float mLayoutYOffset; |
186 | 182 |
187 private float mMaximumWidth; | 183 private float mMaximumWidth; |
188 private float mMaximumHeight; | 184 private float mMaximumHeight; |
189 | 185 |
190 private boolean mIsFullWidthSizePanelForTesting; | 186 private boolean mIsFullWidthSizePanelForTesting; |
191 private boolean mOverrideIsFullWidthSizePanelForTesting; | 187 private boolean mOverrideIsFullWidthSizePanelForTesting; |
192 | 188 |
193 /** | 189 /** |
194 * Called when the size of the view has changed. | 190 * Called when the layout has changed. |
195 * | 191 * |
196 * @param width The new width in dp. | 192 * @param width The new width in dp. |
197 * @param height The new width in dp. | 193 * @param height The new height in dp. |
| 194 * @param visibleViewportOffsetY The Y offset of the content in dp. |
198 */ | 195 */ |
199 public void onSizeChanged(float width, float height) { | 196 public void onLayoutChanged(float width, float height, float visibleViewport
OffsetY) { |
200 if (width == mLayoutWidth && height == mLayoutHeight) return; | 197 if (width == mLayoutWidth && height == mLayoutHeight |
| 198 && visibleViewportOffsetY == mLayoutYOffset) { |
| 199 return; |
| 200 } |
201 | 201 |
202 float previousLayoutWidth = mLayoutWidth; | 202 float previousLayoutWidth = mLayoutWidth; |
203 | 203 |
204 mLayoutWidth = width; | 204 mLayoutWidth = width; |
205 mLayoutHeight = height; | 205 mLayoutHeight = height; |
| 206 mLayoutYOffset = visibleViewportOffsetY; |
206 | 207 |
207 mMaximumWidth = calculateOverlayPanelWidth(); | 208 mMaximumWidth = calculateOverlayPanelWidth(); |
208 mMaximumHeight = getPanelHeightFromState(PanelState.MAXIMIZED); | 209 mMaximumHeight = getPanelHeightFromState(PanelState.MAXIMIZED); |
209 | 210 |
210 handleSizeChanged(width, height, previousLayoutWidth); | 211 handleSizeChanged(width, height, previousLayoutWidth); |
211 } | 212 } |
212 | 213 |
213 /** | 214 /** |
214 * @return Whether the Panel is in full width size. | 215 * @return Whether the Panel is in full width size. |
215 */ | 216 */ |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 } | 252 } |
252 | 253 |
253 /** | 254 /** |
254 * @return The height of the Chrome toolbar in dp. | 255 * @return The height of the Chrome toolbar in dp. |
255 */ | 256 */ |
256 public float getToolbarHeight() { | 257 public float getToolbarHeight() { |
257 return mToolbarHeight; | 258 return mToolbarHeight; |
258 } | 259 } |
259 | 260 |
260 /** | 261 /** |
261 * @param y The y coordinate. | |
262 * @return The Y coordinate relative the fullscreen height. | |
263 */ | |
264 public float getFullscreenY(float y) { | |
265 return y + (mToolbarHeight - getTopControlsOffsetDp()) / mPxToDp; | |
266 } | |
267 | |
268 /** | |
269 * @return Whether the Panel is showing. | 262 * @return Whether the Panel is showing. |
270 */ | 263 */ |
271 public boolean isShowing() { | 264 public boolean isShowing() { |
272 return mHeight > 0; | 265 return mHeight > 0; |
273 } | 266 } |
274 | 267 |
275 /** | 268 /** |
276 * @return Whether the Overlay Panel is opened. That is, whether the current
height is greater | 269 * @return Whether the Overlay Panel is opened. That is, whether the current
height is greater |
277 * than the peeking height. | 270 * than the peeking height. |
278 */ | 271 */ |
279 public boolean isPanelOpened() { | 272 public boolean isPanelOpened() { |
280 return mHeight > getBarContainerHeight(); | 273 return mHeight > getBarContainerHeight(); |
281 } | 274 } |
282 | 275 |
283 /** | 276 /** |
284 * @return The fullscreen width. | 277 * @return The fullscreen width. |
285 */ | 278 */ |
286 private float getFullscreenWidth() { | 279 private float getFullscreenWidth() { |
287 return mLayoutWidth; | 280 return mLayoutWidth; |
288 } | 281 } |
289 | 282 |
290 /** | 283 /** |
291 * @return The height of the tab the panel is displayed on top of. | 284 * @return The height of the tab the panel is displayed on top of. |
292 */ | 285 */ |
293 public float getTabHeight() { | 286 public float getTabHeight() { |
294 // NOTE(mdjones): This value will always be the same for a particular or
ientation; it is | 287 return mLayoutHeight; |
295 // the content height + visible toolbar height. | |
296 return mLayoutHeight + (getToolbarHeight() - getTopControlsOffsetDp()); | |
297 } | 288 } |
298 | 289 |
299 /** | 290 /** |
300 * @return The maximum width of the Overlay Panel in pixels. | 291 * @return The maximum width of the Overlay Panel in pixels. |
301 */ | 292 */ |
302 public int getMaximumWidthPx() { | 293 public int getMaximumWidthPx() { |
303 return Math.round(mMaximumWidth / mPxToDp); | 294 return Math.round(mMaximumWidth / mPxToDp); |
304 } | 295 } |
305 | 296 |
306 /** | 297 /** |
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1092 * consideration the Toolbar height, and adjust the offset accordingly, in o
rder to | 1083 * consideration the Toolbar height, and adjust the offset accordingly, in o
rder to |
1093 * move the Toolbar out of the view as the Panel expands. | 1084 * move the Toolbar out of the view as the Panel expands. |
1094 * | 1085 * |
1095 * @return The target offset Y. | 1086 * @return The target offset Y. |
1096 */ | 1087 */ |
1097 private float calculateBasePageTargetY() { | 1088 private float calculateBasePageTargetY() { |
1098 // Only a fullscreen wide Panel should offset the base page. A small pan
el should | 1089 // Only a fullscreen wide Panel should offset the base page. A small pan
el should |
1099 // always return zero to ensure the Base Page remains in the same positi
on. | 1090 // always return zero to ensure the Base Page remains in the same positi
on. |
1100 if (!isFullWidthSizePanel()) return 0.f; | 1091 if (!isFullWidthSizePanel()) return 0.f; |
1101 | 1092 |
1102 // Start with the desired offset. | 1093 // Start with the desired offset taking viewport offset into considerati
on and make sure |
1103 float offset = calculateBasePageDesiredOffset(); | 1094 // the result is <= 0 so the page moves up and not down. |
| 1095 float offset = Math.min(calculateBasePageDesiredOffset() - mLayoutYOffse
t, 0.0f); |
1104 | 1096 |
1105 // Make sure offset is negative to prevent Base Page from moving down, | |
1106 // because there's nothing to render above the Page. | |
1107 offset = Math.min(offset, 0.f); | |
1108 // If visible, the Toolbar will be hidden. Therefore, we need to adjust | |
1109 // the offset to account for this difference. | |
1110 offset -= (mToolbarHeight - getTopControlsOffsetDp()); | |
1111 // Make sure the offset is not greater than the expanded height, because | 1097 // Make sure the offset is not greater than the expanded height, because |
1112 // there's nothing to render below the Page. | 1098 // there's nothing to render below the Page. |
1113 offset = Math.max(offset, -getExpandedHeight()); | 1099 offset = Math.max(offset, -getExpandedHeight()); |
1114 | 1100 |
1115 return offset; | 1101 return offset; |
1116 } | 1102 } |
1117 | 1103 |
1118 /** | 1104 /** |
1119 * @return The Y coordinate to apply to the Base Page in order to keep the s
election | 1105 * @return The Y coordinate to apply to the Base Page in order to keep the s
election |
1120 * in view when the Overlay Panel is in EXPANDED state. | 1106 * in view when the Overlay Panel is in EXPANDED state. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1188 * Overrides the FullWidthSizePanel state for testing. | 1174 * Overrides the FullWidthSizePanel state for testing. |
1189 * | 1175 * |
1190 * @param isFullWidthSizePanel Whether the Panel has a full width size. | 1176 * @param isFullWidthSizePanel Whether the Panel has a full width size. |
1191 */ | 1177 */ |
1192 @VisibleForTesting | 1178 @VisibleForTesting |
1193 public void setIsFullWidthSizePanelForTesting(boolean isFullWidthSizePanel)
{ | 1179 public void setIsFullWidthSizePanelForTesting(boolean isFullWidthSizePanel)
{ |
1194 mOverrideIsFullWidthSizePanelForTesting = true; | 1180 mOverrideIsFullWidthSizePanelForTesting = true; |
1195 mIsFullWidthSizePanelForTesting = isFullWidthSizePanel; | 1181 mIsFullWidthSizePanelForTesting = isFullWidthSizePanel; |
1196 } | 1182 } |
1197 } | 1183 } |
OLD | NEW |