1 // Copyright 2020 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.omnibox;
6 
7 import android.animation.Animator;
8 import android.view.View;
9 import android.widget.FrameLayout;
10 
11 import java.util.List;
12 
13 /**
14  * A supplement to {@link LocationBarCoordinator} with methods specific to smaller devices.
15  */
16 public class LocationBarCoordinatorPhone implements LocationBarCoordinator.SubCoordinator {
17     private LocationBarPhone mLocationBarPhone;
18 
LocationBarCoordinatorPhone(LocationBarPhone phoneLayout)19     public LocationBarCoordinatorPhone(LocationBarPhone phoneLayout) {
20         mLocationBarPhone = phoneLayout;
21     }
22 
23     @Override
destroy()24     public void destroy() {
25         mLocationBarPhone = null;
26     }
27 
28     /**
29      * Returns width of child views before the first view that would be visible when location
30      * bar is focused. The first visible, focused view should be either url bar or status icon.
31      */
getOffsetOfFirstVisibleFocusedView()32     public int getOffsetOfFirstVisibleFocusedView() {
33         return mLocationBarPhone.getOffsetOfFirstVisibleFocusedView();
34     }
35 
36     /**
37      * Populates fade animators of status icon for location bar focus change animation.
38      *
39      * @param animators The target list to add animators to.
40      * @param startDelayMs Start delay of fade animation in milliseconds.
41      * @param durationMs Duration of fade animation in milliseconds.
42      * @param targetAlpha Target alpha value.
43      */
populateFadeAnimations( List<Animator> animators, long startDelayMs, long durationMs, float targetAlpha)44     public void populateFadeAnimations(
45             List<Animator> animators, long startDelayMs, long durationMs, float targetAlpha) {
46         mLocationBarPhone.populateFadeAnimations(animators, startDelayMs, durationMs, targetAlpha);
47     }
48 
49     /**
50      * Calculates the offset required for the focused LocationBar to appear as it's still
51      * unfocused so it can animate to a focused state.
52      *
53      * @param hasFocus True if the LocationBar has focus, this will be true between the focus
54      *         animation starting and the unfocus animation starting.
55      * @return The offset for the location bar when showing the DSE/loupe icon.
56      */
getLocationBarOffsetForFocusAnimation(boolean hasFocus)57     public int getLocationBarOffsetForFocusAnimation(boolean hasFocus) {
58         return mLocationBarPhone.getLocationBarOffsetForFocusAnimation(hasFocus);
59     }
60 
61     /**
62      * Function used to position the URL bar inside the location bar during omnibox animation.
63      *
64      * @param urlExpansionFraction The current expansion progress, 1 is fully focused and 0 is
65      *         completely unfocused.
66      * @param hasFocus True if the LocationBar has focus, this will be true between the focus
67      *         animation starting and the unfocus animation starting.
68      * @return The number of pixels of horizontal translation for the URL bar, used in the
69      *         toolbar animation.
70      */
getUrlBarTranslationXForToolbarAnimation( float urlExpansionFraction, boolean hasFocus)71     public float getUrlBarTranslationXForToolbarAnimation(
72             float urlExpansionFraction, boolean hasFocus) {
73         return mLocationBarPhone.getUrlBarTranslationXForToolbarAnimation(
74                 urlExpansionFraction, hasFocus);
75     }
76 
77     /**
78      * Handles any actions to be performed after all other actions triggered by the URL focus
79      * change. This will be called after any animations are performed to transition from one
80      * focus state to the other.
81      *
82      * @param hasFocus Whether the URL field has gained focus.
83      * @param shouldShowKeyboard Whether the keyboard should be shown. This value should be the same
84      *         as hasFocus by default.
85      */
finishUrlFocusChange(boolean hasFocus, boolean shouldShowKeyboard)86     public void finishUrlFocusChange(boolean hasFocus, boolean shouldShowKeyboard) {
87         mLocationBarPhone.finishUrlFocusChange(hasFocus, shouldShowKeyboard);
88     }
89 
90     /** Sets whether the url bar should be focusable. */
setUrlBarFocusable(boolean focusable)91     public void setUrlBarFocusable(boolean focusable) {
92         mLocationBarPhone.setUrlBarFocusable(focusable);
93     }
94 
95     /**
96      * Returns {@link FrameLayout.LayoutParams} of the LocationBar view.
97      *
98      * <p>TODO(1133482): Hide this View interaction if possible.
99      *
100      * @see View#getLayoutParams()
101      */
getFrameLayoutParams()102     public FrameLayout.LayoutParams getFrameLayoutParams() {
103         return mLocationBarPhone.getFrameLayoutParams();
104     }
105 
106     /**
107      * The opacity of the view.
108      *
109      * <p>TODO(1133482): Hide this View interaction if possible.
110      *
111      * @see View#getAlpha()
112      */
getAlpha()113     public float getAlpha() {
114         return mLocationBarPhone.getAlpha();
115     }
116 
117     /**
118      * Bottom position of this view relative to its parent.
119      *
120      * <p>TODO(1133482): Hide this View interaction if possible.
121      *
122      * @see View#getBottom()
123      * @return The bottom of this view, in pixels.
124      */
getBottom()125     public int getBottom() {
126         return mLocationBarPhone.getBottom();
127     }
128 
129     /**
130      * Returns the resolved layout direction for this view.
131      *
132      * <p>TODO(1133482): Hide this View interaction if possible.
133      *
134      * @see View#getLayoutDirection()
135      * @return {@link View#LAYOUT_DIRECTION_LTR}, or {@link View#LAYOUT_DIRECTION_RTL}.
136      */
getLayoutDirection()137     public int getLayoutDirection() {
138         return mLocationBarPhone.getLayoutDirection();
139     }
140 
141     /**
142      * Returns the end padding of this view.
143      *
144      * <p>TODO(1133482): Hide this View interaction if possible.
145      *
146      * @see View#getPaddingEnd()
147      * @return The end padding in pixels.
148      */
getPaddingEnd()149     public int getPaddingEnd() {
150         return mLocationBarPhone.getPaddingEnd();
151     }
152 
153     /**
154      * Returns the start padding of this view.
155      *
156      * <p>TODO(1133482): Hide this View interaction if possible.
157      *
158      * @see View#getPaddingStart()
159      * @return The start padding in pixels.
160      */
getPaddingStart()161     public int getPaddingStart() {
162         return mLocationBarPhone.getPaddingStart();
163     }
164 
165     /**
166      * Top position of this view relative to its parent.
167      *
168      * <p>TODO(1133482): Hide this View interaction if possible.
169      *
170      * @see View#getTop()
171      * @return The top of this view, in pixels.
172      */
getTop()173     public int getTop() {
174         return mLocationBarPhone.getTop();
175     }
176 
177     /**
178      * The vertical location of this view relative to its top position, in pixels.
179      *
180      * <p>TODO(1133482): Hide this View interaction if possible.
181      *
182      * @see View#getTranslationY()
183      */
getTranslationY()184     public float getTranslationY() {
185         return mLocationBarPhone.getTranslationY();
186     }
187 
188     /**
189      * Returns the visibility status for this view.
190      *
191      * <p>TODO(1133482): Hide this View interaction if possible.
192      *
193      * @see View#getVisibility()
194      */
getVisibility()195     public int getVisibility() {
196         return mLocationBarPhone.getVisibility();
197     }
198 
199     /**
200      * Returns true if this view has focus itself, or is the ancestor of the view that has
201      * focus.
202      *
203      * <p>TODO(1133482): Hide this View interaction if possible.
204      *
205      * @see View#hasFocus()
206      */
hasFocus()207     public boolean hasFocus() {
208         return mLocationBarPhone.hasFocus();
209     }
210 
211     /**
212      * Invalidate the whole view.
213      *
214      * <p>TODO(1133482): Hide this View interaction if possible.
215      *
216      * @see View#invalidate()
217      */
invalidate()218     public void invalidate() {
219         mLocationBarPhone.invalidate();
220     }
221 
222     /**
223      * Sets the opacity of the view.
224      *
225      * <p>TODO(1133482): Hide this View interaction if possible.
226      *
227      * @see View#setAlpha(float)
228      */
setAlpha(float alpha)229     public void setAlpha(float alpha) {
230         mLocationBarPhone.setAlpha(alpha);
231     }
232 
233     /**
234      * Sets the padding.
235      *
236      * <p>TODO(1133482): Hide this View interaction if possible.
237      *
238      * @see View#setPadding(int, int, int, int)
239      */
setPadding(int left, int top, int right, int bottom)240     public void setPadding(int left, int top, int right, int bottom) {
241         mLocationBarPhone.setPadding(left, top, right, bottom);
242     }
243 
244     /**
245      * Sets the horizontal location of this view relative to its left position.
246      *
247      * <p>TODO(1133482): Hide this View interaction if possible.
248      *
249      * @see View#setTranslationX(float)
250      */
setTranslationX(float translationX)251     public void setTranslationX(float translationX) {
252         mLocationBarPhone.setTranslationX(translationX);
253     }
254 
255     /**
256      * Sets the vertical location of this view relative to its top position.
257      *
258      * <p>TODO(1133482): Hide this View interaction if possible.
259      *
260      * @see View#setTranslationY(float)
261      */
setTranslationY(float translationY)262     public void setTranslationY(float translationY) {
263         mLocationBarPhone.setTranslationY(translationY);
264     }
265 
266     /**
267      * Returns the LocationBar view for use in drawing.
268      *
269      * <p>TODO(1133482): Hide this View interaction if possible.
270      *
271      * @see ViewGroup#drawChild(Canvas, View, long)
272      */
getViewForDrawing()273     public View getViewForDrawing() {
274         return mLocationBarPhone;
275     }
276 }
277