Commit 7a676cfc authored by bauerb's avatar bauerb Committed by Commit bot

Use only toolbar to transition from fakebox to real omnibox.

Previously, we would fade out the fakebox and fade in the real omnibox during
the scroll transition, which created discrepancies. With this change, the
toolbar omnibox does the full transition. The search box on the NTP is still
kept, both to get the starting point of the transition, and for the tablet
toolbar, where the omnibox stays at the top, so there are two boxes.

Because the two boxes now have to match, their dimensions and padding are
slightly updated. The height is 56dp, and the padding on the sides is 12dp.

Also, in the focused state the omnibox now has 1dp bleed at the sides,
which moves the rounded corners out of view.

The remaining changes are not user-visible:
* Opacity of the fakebox is now driven by the toolbar. This lets us centralize
  the logic (the toolbar can decide its own opacity and the opacity of the
  fakebox) and use different behavior on tablets, where the fakebox will simply
  fade out as before.
* Rename variables to (hopefully) make them more consistent / self-explanatory.
* |mLocationBarBackgroundBounds| (formerly |mUrlViewportBounds|) more accurately
  reflects the visible omnibox bounds in the absence of the NTP / when the NTP
  is scrolled so that the omnibox is at the top. To do that, we no longer
  include the Y translation we apply to position it where the fakebox is (it's
  instead applied to the |mLocationBarBackgroundNtpOffset|), and we always use
  an expansion value of 1 if the current tab is an NTP.
* Remove the |inset_textbox| drawable -- it was the same as |textbox|, but with
  a margin added at the top and bottom (but *not* left or right). Since we
  calculate the omnibox bounds manually anyway, this allows us to account for
  the omnibox padding in the same way in either dimension.
* Remove the |isInTabSwitcherMode| parameter from some methods in favor of using
  the member variable.

BUG=605054,625108,618955,616728,612520

Review-Url: https://codereview.chromium.org/2134663002
Cr-Commit-Position: refs/heads/master@{#408885}
parent 78c093f7
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2015 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<inset
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/textbox"
android:insetTop="@dimen/location_bar_margin_top"
android:insetBottom="@dimen/location_bar_margin_bottom"/>
\ No newline at end of file
......@@ -32,7 +32,7 @@
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="26dp"
android:layout_marginBottom="27dp" />
android:layout_marginBottom="23dp" />
<!-- Search box -->
<LinearLayout
......@@ -41,7 +41,7 @@
android:layout_height="48dp"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:layout_marginTop="3dp"
android:layout_marginTop="7dp"
android:layout_marginBottom="8dp"
android:gravity="center_vertical"
android:background="@drawable/bg_ntp_search_box"
......
......@@ -220,14 +220,13 @@
<dimen name="toolbar_progress_bar_height">2dp</dimen>
<dimen name="toolbar_button_width">48dp</dimen>
<dimen name="location_bar_margin_top">5dp</dimen>
<dimen name="location_bar_margin_bottom">5dp</dimen>
<dimen name="toolbar_edge_padding">8dp</dimen>
<dimen name="location_bar_vertical_margin">8dp</dimen>
<dimen name="location_bar_url_text_size">16sp</dimen>
<dimen name="location_bar_incognito_badge_padding">7dp</dimen>
<dimen name="location_bar_icon_width">32dp</dimen>
<dimen name="location_bar_corner_radius">1dp</dimen>
<dimen name="location_bar_icon_width">36dp</dimen>
<dimen name="tablet_toolbar_start_padding">4dp</dimen>
<dimen name="tablet_toolbar_start_padding_no_buttons">6dp</dimen>
<dimen name="tablet_toolbar_end_padding">6dp</dimen>
......@@ -269,8 +268,8 @@
<dimen name="ntp_search_box_material_margin_left">10dp</dimen>
<dimen name="ntp_search_box_material_margin_right">10dp</dimen>
<dimen name="ntp_search_box_material_margin_top">0dp</dimen>
<dimen name="ntp_search_box_material_margin_bottom">5dp</dimen>
<dimen name="ntp_search_box_material_height">54dp</dimen>
<dimen name="ntp_search_box_material_margin_bottom">1dp</dimen>
<dimen name="ntp_search_box_material_height">62dp</dimen>
<dimen name="ntp_search_box_material_extra_width">4dp</dimen>
<dimen name="ntp_search_box_material_padding_top">3dp</dimen>
<dimen name="ntp_search_box_material_padding_bottom">3dp</dimen>
......
......@@ -8,6 +8,7 @@ import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.Rect;
import android.net.Uri;
import android.os.Build;
......@@ -671,16 +672,30 @@ public class NewTabPage
/**
* Get the bounds of the search box in relation to the top level NewTabPage view.
*
* @param originalBounds The bounding region of the search box without external transforms
* applied. The delta between this and the transformed bounds determines
* the amount of scroll applied to this view.
* @param transformedBounds The bounding region of the search box including any transforms
* applied by the parent view hierarchy up to the NewTabPage view.
* This more accurately reflects the current drawing location of the
* search box.
* @param bounds The current drawing location of the search box.
* @param translation The translation applied to the search box by the parent view hierarchy up
* to the NewTabPage view.
*/
public void getSearchBoxBounds(Rect originalBounds, Rect transformedBounds) {
mNewTabPageView.getSearchBoxBounds(originalBounds, transformedBounds);
public void getSearchBoxBounds(Rect bounds, Point translation) {
mNewTabPageView.getSearchBoxBounds(bounds, translation);
}
/**
* Updates the opacity of the search box when scrolling.
*
* @param alpha opacity (alpha) value to use.
*/
public void setSearchBoxAlpha(float alpha) {
mNewTabPageView.setSearchBoxAlpha(alpha);
}
/**
* Updates the opacity of the search provider logo when scrolling.
*
* @param alpha opacity (alpha) value to use.
*/
public void setSearchProviderLogoAlpha(float alpha) {
mNewTabPageView.setSearchProviderLogoAlpha(alpha);
}
/**
......
......@@ -12,6 +12,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
......@@ -405,37 +406,49 @@ public class NewTabPageView extends FrameLayout
private void updateSearchBoxOnScroll() {
if (mDisableUrlFocusChangeAnimations) return;
float toolbarTransitionPercentage;
// During startup the view may not be fully initialized, so we only calculate the current
// percentage if some basic view properties are sane.
if (getWrapperView().getHeight() == 0 || mSearchBoxView.getTop() == 0) {
toolbarTransitionPercentage = 0f;
} else if (!mUseCardsUi) {
toolbarTransitionPercentage =
MathUtils.clamp(getVerticalScroll() / (float) mSearchBoxView.getTop(), 0f, 1f);
} else {
if (!mRecyclerView.isFirstItemVisible()) {
// getVerticalScroll is valid only for the RecyclerView if the first item is
// visible. Luckily, if the first item is not visible, we know the toolbar
// transition should be 100%.
toolbarTransitionPercentage = 1f;
} else {
final int scrollY = getVerticalScroll();
final int top = mSearchBoxView.getTop(); // Relative to mNewTabPageLayout.
final int transitionLength = getResources()
.getDimensionPixelSize(R.dimen.ntp_search_box_transition_length);
// |scrollY - top| gives the distance the search bar is from the top of the screen.
toolbarTransitionPercentage = MathUtils.clamp(
(scrollY - top + transitionLength) / (float) transitionLength, 0f, 1f);
}
if (mSearchBoxScrollListener != null) {
mSearchBoxScrollListener.onNtpScrollChanged(getToolbarTransitionPercentage());
}
}
updateVisualsForToolbarTransition(toolbarTransitionPercentage);
/**
* Calculates the percentage (between 0 and 1) of the transition from the search box to the
* omnibox at the top of the New Tab Page, which is determined by the amount of scrolling and
* the position of the search box.
*
* @return the transition percentage
*/
private float getToolbarTransitionPercentage() {
// During startup the view may not be fully initialized, so we only calculate the current
// percentage if some basic view properties (height of the containing view, position of the
// search box) are sane.
if (getWrapperView().getHeight() == 0) return 0f;
if (mSearchBoxScrollListener != null) {
mSearchBoxScrollListener.onNtpScrollChanged(toolbarTransitionPercentage);
int searchBoxTop = mSearchBoxView.getTop();
if (searchBoxTop == 0) return 0f;
// For all other calculations, add the search box padding, because it defines where the
// visible "border" of the search box is.
searchBoxTop += mSearchBoxView.getPaddingTop();
if (!mUseCardsUi) {
return MathUtils.clamp(getVerticalScroll() / (float) searchBoxTop, 0f, 1f);
}
if (!mRecyclerView.isFirstItemVisible()) {
// getVerticalScroll is valid only for the RecyclerView if the first item is
// visible. If the first item is not visible, we know the toolbar transition
// should be 100%.
return 1f;
}
final int scrollY = getVerticalScroll();
final float transitionLength =
getResources().getDimension(R.dimen.ntp_search_box_transition_length);
// |scrollY - searchBoxTop| gives the distance the search bar is from the top of the screen.
return MathUtils.clamp(
(scrollY - searchBoxTop + transitionLength) / transitionLength, 0f, 1f);
}
private ViewGroup getWrapperView() {
......@@ -673,55 +686,52 @@ public class NewTabPageView extends FrameLayout
int scrollOffset = mUseCardsUi ? 0 : mScrollView.getScrollY();
mNewTabPageLayout.setTranslationY(percent * (-mMostVisitedLayout.getTop() + scrollOffset
+ mNewTabPageLayout.getPaddingTop()));
updateVisualsForToolbarTransition(percent);
}
/**
* Updates the opacity of the fake omnibox and Google logo when scrolling.
* @param transitionPercentage
* Updates the opacity of the search box when scrolling.
*
* @param alpha opacity (alpha) value to use.
*/
private void updateVisualsForToolbarTransition(float transitionPercentage) {
// Complete the full alpha transition in the first 40% of the animation.
float searchUiAlpha =
transitionPercentage >= 0.4f ? 0f : (0.4f - transitionPercentage) * 2.5f;
// Ensure there are no rounding issues when the animation percent is 0.
if (transitionPercentage == 0f) searchUiAlpha = 1f;
public void setSearchBoxAlpha(float alpha) {
mSearchBoxView.setAlpha(alpha);
}
if (!mUseCardsUi) {
mSearchProviderLogoView.setAlpha(searchUiAlpha);
}
mSearchBoxView.setAlpha(searchUiAlpha);
/**
* Updates the opacity of the search provider logo when scrolling.
*
* @param alpha opacity (alpha) value to use.
*/
public void setSearchProviderLogoAlpha(float alpha) {
mSearchProviderLogoView.setAlpha(alpha);
}
/**
* Get the bounds of the search box in relation to the top level NewTabPage view.
*
* @param originalBounds The bounding region of the search box without external transforms
* applied. The delta between this and the transformed bounds determines
* the amount of scroll applied to this view.
* @param transformedBounds The bounding region of the search box including any transforms
* applied by the parent view hierarchy up to the NewTabPage view.
* This more accurately reflects the current drawing location of the
* search box.
* @param bounds The current drawing location of the search box.
* @param translation The translation applied to the search box by the parent view hierarchy up
* to the NewTabPage view.
*/
void getSearchBoxBounds(Rect originalBounds, Rect transformedBounds) {
void getSearchBoxBounds(Rect bounds, Point translation) {
int searchBoxX = (int) mSearchBoxView.getX();
int searchBoxY = (int) mSearchBoxView.getY();
originalBounds.set(
searchBoxX + mSearchBoxView.getPaddingLeft(),
bounds.set(searchBoxX + mSearchBoxView.getPaddingLeft(),
searchBoxY + mSearchBoxView.getPaddingTop(),
searchBoxX + mSearchBoxView.getWidth() - mSearchBoxView.getPaddingRight(),
searchBoxY + mSearchBoxView.getHeight() - mSearchBoxView.getPaddingBottom());
transformedBounds.set(originalBounds);
translation.set(0, 0);
View view = (View) mSearchBoxView.getParent();
while (view != null) {
transformedBounds.offset(-view.getScrollX(), -view.getScrollY());
translation.offset(-view.getScrollX(), -view.getScrollY());
if (view == this) break;
transformedBounds.offset((int) view.getX(), (int) view.getY());
translation.offset((int) view.getX(), (int) view.getY());
view = (View) view.getParent();
}
bounds.offset(translation.x, translation.y);
}
/**
......
......@@ -319,7 +319,8 @@ public class NewTabPageRecyclerView extends RecyclerView {
// Snap scroll to prevent resting in the middle of the omnibox transition.
final int searchBoxTransitionLength = getResources()
.getDimensionPixelSize(R.dimen.ntp_search_box_transition_length);
if (scrollOutOfRegion(fakeBox.getTop() - searchBoxTransitionLength, fakeBox.getTop())) {
int fakeBoxUpperBound = fakeBox.getTop() + fakeBox.getPaddingTop();
if (scrollOutOfRegion(fakeBoxUpperBound - searchBoxTransitionLength, fakeBoxUpperBound)) {
// The snap scrolling regions should never overlap.
return;
}
......
......@@ -172,8 +172,6 @@ public class LocationBarPhone extends LocationBarLayout {
mUrlActionsContainer.setVisibility(GONE);
}
mDeleteButton.setAlpha(percent);
mMicButton.setAlpha(percent);
if (showMenuButtonInOmnibox()) mMenuButtonWrapper.setAlpha(1f - percent);
updateButtonVisibility();
......
......@@ -21,6 +21,7 @@ import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.NavigationPopup;
import org.chromium.chrome.browser.device.DeviceClassManager;
import org.chromium.chrome.browser.ntp.NewTabPage;
import org.chromium.chrome.browser.omnibox.LocationBar;
import org.chromium.chrome.browser.omnibox.LocationBarTablet;
import org.chromium.chrome.browser.partnercustomizations.HomepageManager;
......@@ -69,6 +70,8 @@ public class ToolbarTablet extends ToolbarLayout implements OnClickListener {
private boolean mShouldAnimateButtonVisibilityChange;
private AnimatorSet mButtonVisibilityAnimators;
private NewTabPage mVisibleNtp;
/**
* Constructs a ToolbarTablet object.
* @param context The Context in which this View object is created.
......@@ -337,6 +340,38 @@ public class ToolbarTablet extends ToolbarLayout implements OnClickListener {
}
mUseLightColorAssets = incognito;
}
updateNtp();
}
/**
* Called when the currently visible New Tab Page changes.
*/
private void updateNtp() {
NewTabPage newVisibleNtp = getToolbarDataProvider().getNewTabPageForCurrentTab();
if (mVisibleNtp == newVisibleNtp) return;
if (mVisibleNtp != null) {
mVisibleNtp.setSearchBoxScrollListener(null);
}
mVisibleNtp = newVisibleNtp;
if (mVisibleNtp != null) {
mVisibleNtp.setSearchBoxScrollListener(new NewTabPage.OnSearchBoxScrollListener() {
@Override
public void onNtpScrollChanged(float scrollPercentage) {
// Fade the search box out in the first 40% of the scrolling transition.
float alpha = Math.max(1f - scrollPercentage * 2.5f, 0f);
mVisibleNtp.setSearchBoxAlpha(alpha);
mVisibleNtp.setSearchProviderLogoAlpha(alpha);
}
});
}
}
@Override
protected void onTabContentViewChanged() {
super.onTabContentViewChanged();
updateNtp();
}
@Override
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment