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.ntp; | 5 package org.chromium.chrome.browser.ntp; |
6 | 6 |
7 import android.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
8 import android.content.Context; | 8 import android.content.Context; |
9 import android.graphics.Canvas; | 9 import android.graphics.Canvas; |
10 import android.graphics.Point; | 10 import android.graphics.Point; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 private final int mThemeColor; | 86 private final int mThemeColor; |
87 private final NewTabPageView mNewTabPageView; | 87 private final NewTabPageView mNewTabPageView; |
88 private final NewTabPageManagerImpl mNewTabPageManager; | 88 private final NewTabPageManagerImpl mNewTabPageManager; |
89 private final TileGroup.Delegate mTileGroupDelegate; | 89 private final TileGroup.Delegate mTileGroupDelegate; |
90 | 90 |
91 private TabObserver mTabObserver; | 91 private TabObserver mTabObserver; |
92 private boolean mSearchProviderHasLogo; | 92 private boolean mSearchProviderHasLogo; |
93 private FakeboxDelegate mFakeboxDelegate; | 93 private FakeboxDelegate mFakeboxDelegate; |
94 private SnippetsBridge mSnippetsBridge; | 94 private SnippetsBridge mSnippetsBridge; |
95 | 95 |
96 private boolean mVoiceInputEnabled = true; | |
97 | |
96 // The timestamp at which the constructor was called. | 98 // The timestamp at which the constructor was called. |
97 private final long mConstructedTimeNs; | 99 private final long mConstructedTimeNs; |
98 | 100 |
99 // The timestamp at which this NTP was last shown to the user. | 101 // The timestamp at which this NTP was last shown to the user. |
100 private long mLastShownTimeNs; | 102 private long mLastShownTimeNs; |
101 | 103 |
102 private boolean mIsLoaded; | 104 private boolean mIsLoaded; |
103 | 105 |
104 // Whether destroy() has been called. | 106 // Whether destroy() has been called. |
105 private boolean mIsDestroyed; | 107 private boolean mIsDestroyed; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 * | 147 * |
146 * @param pastedText The text that was pasted or typed into the fakebox, or null if the user | 148 * @param pastedText The text that was pasted or typed into the fakebox, or null if the user |
147 * just tapped the fakebox. | 149 * just tapped the fakebox. |
148 */ | 150 */ |
149 void requestUrlFocusFromFakebox(String pastedText); | 151 void requestUrlFocusFromFakebox(String pastedText); |
150 | 152 |
151 /** | 153 /** |
152 * @return whether the provided native page is the one currently display ed to the user. | 154 * @return whether the provided native page is the one currently display ed to the user. |
153 */ | 155 */ |
154 boolean isCurrentPage(NativePage nativePage); | 156 boolean isCurrentPage(NativePage nativePage); |
157 | |
158 /** | |
159 * See LocationBarLayout#setUrlBarFocusable. | |
160 */ | |
161 void setUrlBarFocusable(boolean focusable); | |
Ted C
2017/06/02 17:01:51
I feel there needs to be a path where this is isol
| |
155 } | 162 } |
156 | 163 |
157 /** | 164 /** |
158 * @param url The URL to check whether it is for the NTP. | 165 * @param url The URL to check whether it is for the NTP. |
159 * @return Whether the passed in URL is used to render the NTP. | 166 * @return Whether the passed in URL is used to render the NTP. |
160 */ | 167 */ |
161 public static boolean isNTPUrl(String url) { | 168 public static boolean isNTPUrl(String url) { |
162 // Also handle the legacy chrome://newtab URL since that will redirect t o | 169 // Also handle the legacy chrome://newtab URL since that will redirect t o |
163 // chrome-native://newtab natively. | 170 // chrome-native://newtab natively. |
164 return url != null | 171 return url != null |
(...skipping 22 matching lines...) Expand all Loading... | |
187 @Override | 194 @Override |
188 public boolean isLocationBarShownInNTP() { | 195 public boolean isLocationBarShownInNTP() { |
189 if (mIsDestroyed) return false; | 196 if (mIsDestroyed) return false; |
190 Context context = mNewTabPageView.getContext(); | 197 Context context = mNewTabPageView.getContext(); |
191 return isInSingleUrlBarMode(context) | 198 return isInSingleUrlBarMode(context) |
192 && !mNewTabPageView.urlFocusAnimationsDisabled(); | 199 && !mNewTabPageView.urlFocusAnimationsDisabled(); |
193 } | 200 } |
194 | 201 |
195 @Override | 202 @Override |
196 public boolean isVoiceSearchEnabled() { | 203 public boolean isVoiceSearchEnabled() { |
197 return mFakeboxDelegate != null && mFakeboxDelegate.isVoiceSearchEna bled(); | 204 return mVoiceInputEnabled && mFakeboxDelegate != null |
205 && mFakeboxDelegate.isVoiceSearchEnabled(); | |
198 } | 206 } |
199 | 207 |
200 @TargetApi(Build.VERSION_CODES.LOLLIPOP) | 208 @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
201 private boolean switchToExistingTab(String url) { | 209 private boolean switchToExistingTab(String url) { |
202 String matchPattern = CommandLine.getInstance().getSwitchValue( | 210 String matchPattern = CommandLine.getInstance().getSwitchValue( |
203 ChromeSwitches.NTP_SWITCH_TO_EXISTING_TAB); | 211 ChromeSwitches.NTP_SWITCH_TO_EXISTING_TAB); |
204 boolean matchByHost; | 212 boolean matchByHost; |
205 if ("url".equals(matchPattern)) { | 213 if ("url".equals(matchPattern)) { |
206 matchByHost = false; | 214 matchByHost = false; |
207 } else if ("host".equals(matchPattern)) { | 215 } else if ("host".equals(matchPattern)) { |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
398 } | 406 } |
399 | 407 |
400 /** | 408 /** |
401 * Updates whether the NewTabPage should animate on URL focus changes. | 409 * Updates whether the NewTabPage should animate on URL focus changes. |
402 * @param disable Whether to disable the animations. | 410 * @param disable Whether to disable the animations. |
403 */ | 411 */ |
404 public void setUrlFocusAnimationsDisabled(boolean disable) { | 412 public void setUrlFocusAnimationsDisabled(boolean disable) { |
405 mNewTabPageView.setUrlFocusAnimationsDisabled(disable); | 413 mNewTabPageView.setUrlFocusAnimationsDisabled(disable); |
406 } | 414 } |
407 | 415 |
416 /** | |
417 * Updates whether input to the URL bar should be enabled. | |
418 * @param enable Whether to enable URL Bar input. | |
419 */ | |
420 public void setUrlBarInputEnabled(boolean enable) { | |
421 mFakeboxDelegate.setUrlBarFocusable(enable); | |
422 mVoiceInputEnabled = enable; | |
423 mNewTabPageView.updateVoiceSearchButtonVisibility(); | |
424 } | |
425 | |
408 private boolean isInSingleUrlBarMode(Context context) { | 426 private boolean isInSingleUrlBarMode(Context context) { |
409 if (DeviceFormFactor.isTablet()) return false; | 427 if (DeviceFormFactor.isTablet()) return false; |
410 if (FeatureUtilities.isChromeHomeEnabled()) return false; | 428 if (FeatureUtilities.isChromeHomeEnabled()) return false; |
411 return mSearchProviderHasLogo; | 429 return mSearchProviderHasLogo; |
412 } | 430 } |
413 | 431 |
414 private void updateSearchProviderHasLogo() { | 432 private void updateSearchProviderHasLogo() { |
415 mSearchProviderHasLogo = TemplateUrlService.getInstance().isDefaultSearc hEngineGoogle(); | 433 mSearchProviderHasLogo = TemplateUrlService.getInstance().isDefaultSearc hEngineGoogle(); |
Ted C
2017/05/23 14:37:45
Is it better UI if VR would to fall into this path
mthiesse
2017/05/31 21:27:11
Hmm I don't personally think the UI is better when
| |
416 } | 434 } |
417 | 435 |
418 private void onSearchEngineUpdated() { | 436 private void onSearchEngineUpdated() { |
419 // TODO(newt): update this if other search providers provide logos. | 437 // TODO(newt): update this if other search providers provide logos. |
420 updateSearchProviderHasLogo(); | 438 updateSearchProviderHasLogo(); |
421 mNewTabPageView.setSearchProviderHasLogo(mSearchProviderHasLogo); | 439 mNewTabPageView.setSearchProviderHasLogo(mSearchProviderHasLogo); |
422 } | 440 } |
423 | 441 |
424 /** | 442 /** |
425 * Specifies the percentage the URL is focused during an animation. 1.0 spe cifies that the URL | 443 * Specifies the percentage the URL is focused during an animation. 1.0 spe cifies that the URL |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
617 @Override | 635 @Override |
618 public void captureThumbnail(Canvas canvas) { | 636 public void captureThumbnail(Canvas canvas) { |
619 mNewTabPageView.captureThumbnail(canvas); | 637 mNewTabPageView.captureThumbnail(canvas); |
620 } | 638 } |
621 | 639 |
622 @VisibleForTesting | 640 @VisibleForTesting |
623 public NewTabPageManager getManagerForTesting() { | 641 public NewTabPageManager getManagerForTesting() { |
624 return mNewTabPageManager; | 642 return mNewTabPageManager; |
625 } | 643 } |
626 } | 644 } |
OLD | NEW |