Commit d2ea3853 authored by dgn's avatar dgn Committed by Commit bot

[NTP] Delay the URL focus effects if they happen before NTP is loaded.

When the URL bar is focused before the NTP is loaded, the UI misses
the events and renders in the incorrect state. This change just runs
the effects of the event later.

BUG=617582

Review-Url: https://codereview.chromium.org/2133753002
Cr-Commit-Position: refs/heads/master@{#404634}
parent e2ffc8ba
...@@ -165,6 +165,11 @@ public class NewTabPage ...@@ -165,6 +165,11 @@ public class NewTabPage
*/ */
boolean isVoiceSearchEnabled(); boolean isVoiceSearchEnabled();
/**
* @return Whether the URL bar is currently focused.
*/
boolean isUrlBarFocused();
/** /**
* Focuses the URL bar when the user taps the fakebox, types in the fakebox, or pastes text * Focuses the URL bar when the user taps the fakebox, types in the fakebox, or pastes text
* into the fakebox. * into the fakebox.
...@@ -679,6 +684,13 @@ public class NewTabPage ...@@ -679,6 +684,13 @@ public class NewTabPage
mFakeboxDelegate = fakeboxDelegate; mFakeboxDelegate = fakeboxDelegate;
if (mFakeboxDelegate != null) { if (mFakeboxDelegate != null) {
mNewTabPageView.updateVoiceSearchButtonVisibility(); mNewTabPageView.updateVoiceSearchButtonVisibility();
// The toolbar can't get the reference to the native page until its initialization is
// finished, so we can't cache it here and transfer it to the view later. We pull that
// state from the location bar when we get a reference to it as a workaround.
if (fakeboxDelegate.isUrlBarFocused()) {
mNewTabPageView.setUrlFocusChangeAnimationPercent(1f);
}
} }
} }
......
...@@ -113,6 +113,8 @@ public class NewTabPageView extends FrameLayout ...@@ -113,6 +113,8 @@ public class NewTabPageView extends FrameLayout
private float mUrlFocusChangePercent; private float mUrlFocusChangePercent;
private boolean mDisableUrlFocusChangeAnimations; private boolean mDisableUrlFocusChangeAnimations;
/** Flag used to request some layout changes after the next layout pass is completed. */
private boolean mTileCountChanged;
private boolean mSnapshotMostVisitedChanged; private boolean mSnapshotMostVisitedChanged;
private int mSnapshotWidth; private int mSnapshotWidth;
private int mSnapshotHeight; private int mSnapshotHeight;
...@@ -351,7 +353,7 @@ public class NewTabPageView extends FrameLayout ...@@ -351,7 +353,7 @@ public class NewTabPageView extends FrameLayout
params.bottomMargin = 0; params.bottomMargin = 0;
} }
addOnLayoutChangeListener(this); mNewTabPageLayout.addOnLayoutChangeListener(this);
setSearchProviderHasLogo(searchProviderHasLogo); setSearchProviderHasLogo(searchProviderHasLogo);
mPendingLoadTasks++; mPendingLoadTasks++;
...@@ -790,9 +792,11 @@ public class NewTabPageView extends FrameLayout ...@@ -790,9 +792,11 @@ public class NewTabPageView extends FrameLayout
@Override @Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, public void onLayoutChange(View v, int left, int top, int right, int bottom,
int oldLeft, int oldTop, int oldRight, int oldBottom) { int oldLeft, int oldTop, int oldRight, int oldBottom) {
int oldWidth = oldRight - oldLeft; int oldHeight = oldBottom - oldTop;
int newWidth = right - left; int newHeight = bottom - top;
if (oldWidth == newWidth) return;
if (oldHeight == newHeight && !mTileCountChanged) return;
mTileCountChanged = false;
// Re-apply the url focus change amount after a rotation to ensure the views are correctly // Re-apply the url focus change amount after a rotation to ensure the views are correctly
// placed with their new layout configurations. // placed with their new layout configurations.
...@@ -875,6 +879,12 @@ public class NewTabPageView extends FrameLayout ...@@ -875,6 +879,12 @@ public class NewTabPageView extends FrameLayout
mHasReceivedMostVisitedSites = true; mHasReceivedMostVisitedSites = true;
updateMostVisitedPlaceholderVisibility(); updateMostVisitedPlaceholderVisibility();
if (mUrlFocusChangePercent == 1f && oldItemCount != mMostVisitedItems.length) {
// If the number of NTP Tile rows change while the URL bar is focused, the icons'
// position will be wrong. Schedule the translation to be updated.
mTileCountChanged = true;
}
if (isInitialLoad) { if (isInitialLoad) {
loadTaskCompleted(); loadTaskCompleted();
// The page contents are initially hidden; otherwise they'll be drawn centered on the // The page contents are initially hidden; otherwise they'll be drawn centered on the
......
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