Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(239)

Side by Side Diff: ios/chrome/browser/ui/toolbar/web_toolbar_controller.mm

Issue 2934463002: [iOS] Add experimental new keyboard accessory view. (Closed)
Patch Set: Rebased. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/chrome/browser/ui/toolbar/toolbar_tools_menu_button.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 #import "ios/chrome/browser/ui/toolbar/web_toolbar_controller.h" 5 #import "ios/chrome/browser/ui/toolbar/web_toolbar_controller.h"
6 6
7 #import <CoreLocation/CoreLocation.h> 7 #import <CoreLocation/CoreLocation.h>
8 #include <QuartzCore/QuartzCore.h> 8 #include <QuartzCore/QuartzCore.h>
9 9
10 #include <stdint.h> 10 #include <stdint.h>
(...skipping 11 matching lines...) Expand all
22 #include "base/metrics/user_metrics_action.h" 22 #include "base/metrics/user_metrics_action.h"
23 #include "base/strings/sys_string_conversions.h" 23 #include "base/strings/sys_string_conversions.h"
24 #include "components/google/core/browser/google_util.h" 24 #include "components/google/core/browser/google_util.h"
25 #include "components/omnibox/browser/omnibox_edit_model.h" 25 #include "components/omnibox/browser/omnibox_edit_model.h"
26 #include "components/search_engines/util.h" 26 #include "components/search_engines/util.h"
27 #include "components/strings/grit/components_strings.h" 27 #include "components/strings/grit/components_strings.h"
28 #include "components/toolbar/toolbar_model.h" 28 #include "components/toolbar/toolbar_model.h"
29 #include "ios/chrome/browser/autocomplete/autocomplete_scheme_classifier_impl.h" 29 #include "ios/chrome/browser/autocomplete/autocomplete_scheme_classifier_impl.h"
30 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" 30 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
31 #include "ios/chrome/browser/chrome_url_constants.h" 31 #include "ios/chrome/browser/chrome_url_constants.h"
32 #include "ios/chrome/browser/experimental_flags.h"
32 #include "ios/chrome/browser/reading_list/reading_list_model_factory.h" 33 #include "ios/chrome/browser/reading_list/reading_list_model_factory.h"
33 #include "ios/chrome/browser/search_engines/template_url_service_factory.h" 34 #include "ios/chrome/browser/search_engines/template_url_service_factory.h"
34 #import "ios/chrome/browser/tabs/tab.h" 35 #import "ios/chrome/browser/tabs/tab.h"
35 #import "ios/chrome/browser/tabs/tab_model.h" 36 #import "ios/chrome/browser/tabs/tab_model.h"
36 #import "ios/chrome/browser/ui/animation_util.h" 37 #import "ios/chrome/browser/ui/animation_util.h"
37 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" 38 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
38 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" 39 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h"
39 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" 40 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h"
40 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" 41 #include "ios/chrome/browser/ui/commands/ios_command_ids.h"
41 #import "ios/chrome/browser/ui/history/tab_history_popup_controller.h" 42 #import "ios/chrome/browser/ui/history/tab_history_popup_controller.h"
42 #import "ios/chrome/browser/ui/image_util.h" 43 #import "ios/chrome/browser/ui/image_util.h"
43 #import "ios/chrome/browser/ui/keyboard/hardware_keyboard_watcher.h" 44 #import "ios/chrome/browser/ui/keyboard/hardware_keyboard_watcher.h"
44 #include "ios/chrome/browser/ui/omnibox/location_bar_controller_impl.h" 45 #include "ios/chrome/browser/ui/omnibox/location_bar_controller_impl.h"
45 #include "ios/chrome/browser/ui/omnibox/omnibox_view_ios.h" 46 #include "ios/chrome/browser/ui/omnibox/omnibox_view_ios.h"
46 #import "ios/chrome/browser/ui/popup_menu/popup_menu_view.h" 47 #import "ios/chrome/browser/ui/popup_menu/popup_menu_view.h"
47 #import "ios/chrome/browser/ui/reversed_animation.h" 48 #import "ios/chrome/browser/ui/reversed_animation.h"
48 #include "ios/chrome/browser/ui/rtl_geometry.h" 49 #include "ios/chrome/browser/ui/rtl_geometry.h"
49 #import "ios/chrome/browser/ui/toolbar/keyboard_accessory_view.h" 50 #import "ios/chrome/browser/ui/toolbar/keyboard_accessory_view.h"
51 #import "ios/chrome/browser/ui/toolbar/keyboard_accessory_view_protocol.h"
52 #import "ios/chrome/browser/ui/toolbar/new_keyboard_accessory_view.h"
50 #import "ios/chrome/browser/ui/toolbar/toolbar_controller+protected.h" 53 #import "ios/chrome/browser/ui/toolbar/toolbar_controller+protected.h"
51 #import "ios/chrome/browser/ui/toolbar/toolbar_controller.h" 54 #import "ios/chrome/browser/ui/toolbar/toolbar_controller.h"
52 #import "ios/chrome/browser/ui/toolbar/toolbar_model_ios.h" 55 #import "ios/chrome/browser/ui/toolbar/toolbar_model_ios.h"
53 #include "ios/chrome/browser/ui/toolbar/toolbar_resource_macros.h" 56 #include "ios/chrome/browser/ui/toolbar/toolbar_resource_macros.h"
54 #include "ios/chrome/browser/ui/ui_util.h" 57 #include "ios/chrome/browser/ui/ui_util.h"
55 #import "ios/chrome/browser/ui/uikit_ui_util.h" 58 #import "ios/chrome/browser/ui/uikit_ui_util.h"
56 #import "ios/chrome/browser/ui/url_loader.h" 59 #import "ios/chrome/browser/ui/url_loader.h"
57 #import "ios/chrome/browser/ui/voice/text_to_speech_player.h" 60 #import "ios/chrome/browser/ui/voice/text_to_speech_player.h"
58 #import "ios/chrome/browser/ui/voice/voice_search_notification_names.h" 61 #import "ios/chrome/browser/ui/voice/voice_search_notification_names.h"
59 #import "ios/chrome/common/material_timing.h" 62 #import "ios/chrome/common/material_timing.h"
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 // Top-level view for web content. 238 // Top-level view for web content.
236 UIView* _webToolbar; 239 UIView* _webToolbar;
237 UIButton* _backButton; 240 UIButton* _backButton;
238 UIButton* _forwardButton; 241 UIButton* _forwardButton;
239 UIButton* _reloadButton; 242 UIButton* _reloadButton;
240 UIButton* _stopButton; 243 UIButton* _stopButton;
241 UIButton* _starButton; 244 UIButton* _starButton;
242 UIButton* _voiceSearchButton; 245 UIButton* _voiceSearchButton;
243 OmniboxTextFieldIOS* _omniBox; 246 OmniboxTextFieldIOS* _omniBox;
244 UIButton* _cancelButton; 247 UIButton* _cancelButton;
245 KeyboardAccessoryView* _keyBoardAccessoryView; 248 UIView<KeyboardAccessoryViewProtocol>* _keyboardAccessoryView;
246 // Progress bar used to show what fraction of the page has loaded. 249 // Progress bar used to show what fraction of the page has loaded.
247 MDCProgressView* _determinateProgressView; 250 MDCProgressView* _determinateProgressView;
248 UIImageView* _omniboxBackground; 251 UIImageView* _omniboxBackground;
249 BOOL _prerenderAnimating; 252 BOOL _prerenderAnimating;
250 UIImageView* _incognitoIcon; 253 UIImageView* _incognitoIcon;
251 UIView* _clippingView; 254 UIView* _clippingView;
252 255
253 std::unique_ptr<LocationBarController> _locationBar; 256 std::unique_ptr<LocationBarController> _locationBar;
254 BOOL _initialLayoutComplete; 257 BOOL _initialLayoutComplete;
255 // If |YES|, toolbar is incognito. 258 // If |YES|, toolbar is incognito.
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 if (IsIPadIdiom()) { 871 if (IsIPadIdiom()) {
869 // Update toolbar accessory views. 872 // Update toolbar accessory views.
870 BOOL isCompactTabletView = IsCompactTablet(self.view); 873 BOOL isCompactTabletView = IsCompactTablet(self.view);
871 [_voiceSearchButton setHidden:isCompactTabletView]; 874 [_voiceSearchButton setHidden:isCompactTabletView];
872 [_starButton setHidden:isCompactTabletView]; 875 [_starButton setHidden:isCompactTabletView];
873 [_reloadButton setHidden:isCompactTabletView]; 876 [_reloadButton setHidden:isCompactTabletView];
874 [_stopButton setHidden:isCompactTabletView]; 877 [_stopButton setHidden:isCompactTabletView];
875 [self updateToolbarState]; 878 [self updateToolbarState];
876 879
877 // Update keyboard accessory views. 880 // Update keyboard accessory views.
878 auto mode = _keyBoardAccessoryView.mode; 881 auto mode = _keyboardAccessoryView.mode;
879 _keyBoardAccessoryView = nil; 882 _keyboardAccessoryView = nil;
880 [_omniBox setInputAccessoryView:[self keyboardAccessoryView]]; 883 [_omniBox setInputAccessoryView:[self keyboardAccessoryView]];
881 _keyBoardAccessoryView.mode = mode; 884 _keyboardAccessoryView.mode = mode;
882 if ([_omniBox isFirstResponder]) { 885 if ([_omniBox isFirstResponder]) {
883 [_omniBox reloadInputViews]; 886 [_omniBox reloadInputViews];
884 } 887 }
885 888
886 // Re-layout toolbar and omnibox. 889 // Re-layout toolbar and omnibox.
887 [_webToolbar setFrame:[self specificControlsArea]]; 890 [_webToolbar setFrame:[self specificControlsArea]];
888 [self layoutOmnibox]; 891 [self layoutOmnibox];
889 } 892 }
890 } 893 }
891 894
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
1254 kLocationAuthorizationStatusCount); 1257 kLocationAuthorizationStatusCount);
1255 } 1258 }
1256 } 1259 }
1257 [self cancelOmniboxEdit]; 1260 [self cancelOmniboxEdit];
1258 } 1261 }
1259 1262
1260 - (void)locationBarHasBecomeFirstResponder { 1263 - (void)locationBarHasBecomeFirstResponder {
1261 [self.delegate locationBarDidBecomeFirstResponder:self]; 1264 [self.delegate locationBarDidBecomeFirstResponder:self];
1262 [self animateMaterialOmnibox]; 1265 [self animateMaterialOmnibox];
1263 1266
1264 _keyBoardAccessoryView.mode = VOICE_SEARCH; 1267 _keyboardAccessoryView.mode = VOICE_SEARCH;
1265 1268
1266 // Record the appropriate user action for focusing the omnibox. 1269 // Record the appropriate user action for focusing the omnibox.
1267 web::WebState* webState = [self.delegate currentWebState]; 1270 web::WebState* webState = [self.delegate currentWebState];
1268 if (webState) { 1271 if (webState) {
1269 if (webState->GetVisibleURL() == GURL(kChromeUINewTabURL)) { 1272 if (webState->GetVisibleURL() == GURL(kChromeUINewTabURL)) {
1270 OmniboxEditModel* model = _locationBar->GetLocationEntry()->model(); 1273 OmniboxEditModel* model = _locationBar->GetLocationEntry()->model();
1271 if (model->is_caret_visible()) { 1274 if (model->is_caret_visible()) {
1272 base::RecordAction( 1275 base::RecordAction(
1273 base::UserMetricsAction("MobileFocusedOmniboxOnNtp")); 1276 base::UserMetricsAction("MobileFocusedOmniboxOnNtp"));
1274 } else { 1277 } else {
(...skipping 17 matching lines...) Expand all
1292 } 1295 }
1293 1296
1294 - (void)locationBarChanged { 1297 - (void)locationBarChanged {
1295 // Hide the voice search button once the user starts editing the omnibox but 1298 // Hide the voice search button once the user starts editing the omnibox but
1296 // show it if the omnibox is empty. 1299 // show it if the omnibox is empty.
1297 bool isEditingOrEmpty = _locationBar->GetLocationEntry()->IsEditingOrEmpty(); 1300 bool isEditingOrEmpty = _locationBar->GetLocationEntry()->IsEditingOrEmpty();
1298 BOOL editingAndNotEmpty = isEditingOrEmpty && _omniBox.text.length != 0; 1301 BOOL editingAndNotEmpty = isEditingOrEmpty && _omniBox.text.length != 0;
1299 // If the voice search button is visible but about to be hidden (i.e. 1302 // If the voice search button is visible but about to be hidden (i.e.
1300 // the omnibox is no longer empty) then this is the first omnibox text so 1303 // the omnibox is no longer empty) then this is the first omnibox text so
1301 // record a user action. 1304 // record a user action.
1302 if (_keyBoardAccessoryView.mode == VOICE_SEARCH && editingAndNotEmpty) { 1305 if (_keyboardAccessoryView.mode == VOICE_SEARCH && editingAndNotEmpty) {
1303 base::RecordAction(UserMetricsAction("MobileFirstTextInOmnibox")); 1306 base::RecordAction(UserMetricsAction("MobileFirstTextInOmnibox"));
1304 } 1307 }
1305 if (editingAndNotEmpty) { 1308 if (editingAndNotEmpty) {
1306 _keyBoardAccessoryView.mode = KEY_SHORTCUTS; 1309 _keyboardAccessoryView.mode = KEY_SHORTCUTS;
1307 } else { 1310 } else {
1308 _keyBoardAccessoryView.mode = VOICE_SEARCH; 1311 _keyboardAccessoryView.mode = VOICE_SEARCH;
1309 } 1312 }
1310 } 1313 }
1311 1314
1312 - (web::WebState*)getWebState { 1315 - (web::WebState*)getWebState {
1313 return [self.delegate currentWebState]; 1316 return [self.delegate currentWebState];
1314 } 1317 }
1315 1318
1316 - (ToolbarModel*)toolbarModel { 1319 - (ToolbarModel*)toolbarModel {
1317 ToolbarModelIOS* toolbarModelIOS = [self.delegate toolbarModelIOS]; 1320 ToolbarModelIOS* toolbarModelIOS = [self.delegate toolbarModelIOS];
1318 return toolbarModelIOS ? toolbarModelIOS->GetToolbarModel() : nullptr; 1321 return toolbarModelIOS ? toolbarModelIOS->GetToolbarModel() : nullptr;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1457 } 1460 }
1458 } 1461 }
1459 1462
1460 #pragma mark - 1463 #pragma mark -
1461 #pragma mark KeyboardAccessoryViewDelegate 1464 #pragma mark KeyboardAccessoryViewDelegate
1462 1465
1463 - (void)keyboardAccessoryVoiceSearchTouchDown { 1466 - (void)keyboardAccessoryVoiceSearchTouchDown {
1464 if (ios::GetChromeBrowserProvider() 1467 if (ios::GetChromeBrowserProvider()
1465 ->GetVoiceSearchProvider() 1468 ->GetVoiceSearchProvider()
1466 ->IsVoiceSearchEnabled()) { 1469 ->IsVoiceSearchEnabled()) {
1467 [self preloadVoiceSearch:_keyBoardAccessoryView]; 1470 [self preloadVoiceSearch:_keyboardAccessoryView];
1468 } 1471 }
1469 } 1472 }
1470 1473
1471 - (void)keyboardAccessoryVoiceSearchTouchUpInside { 1474 - (void)keyboardAccessoryVoiceSearchTouchUpInside {
1472 if (ios::GetChromeBrowserProvider() 1475 if (ios::GetChromeBrowserProvider()
1473 ->GetVoiceSearchProvider() 1476 ->GetVoiceSearchProvider()
1474 ->IsVoiceSearchEnabled()) { 1477 ->IsVoiceSearchEnabled()) {
1475 base::RecordAction(UserMetricsAction("MobileCustomRowVoiceSearch")); 1478 base::RecordAction(UserMetricsAction("MobileCustomRowVoiceSearch"));
1476 GenericChromeCommand* command = 1479 GenericChromeCommand* command =
1477 [[GenericChromeCommand alloc] initWithTag:IDC_VOICE_SEARCH]; 1480 [[GenericChromeCommand alloc] initWithTag:IDC_VOICE_SEARCH];
1478 [_keyBoardAccessoryView chromeExecuteCommand:command]; 1481 [_keyboardAccessoryView chromeExecuteCommand:command];
1479 } else { 1482 } else {
1480 _keyBoardAccessoryView.mode = KEY_SHORTCUTS; 1483 _keyboardAccessoryView.mode = KEY_SHORTCUTS;
1481 } 1484 }
1482 } 1485 }
1483 1486
1487 - (void)keyboardAccessoryCameraSearchTouchUpInside {
1488 GenericChromeCommand* command =
1489 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_QR_SCANNER];
1490 [_keyboardAccessoryView chromeExecuteCommand:command];
1491 }
1492
1484 - (void)keyPressed:(NSString*)title { 1493 - (void)keyPressed:(NSString*)title {
1485 NSString* text = [self updateTextForDotCom:title]; 1494 NSString* text = [self updateTextForDotCom:title];
1486 [_omniBox insertTextWhileEditing:text]; 1495 [_omniBox insertTextWhileEditing:text];
1487 } 1496 }
1488 1497
1489 #pragma mark - 1498 #pragma mark -
1490 #pragma mark Private methods. 1499 #pragma mark Private methods.
1491 1500
1492 - (UIButton*)cancelButton { 1501 - (UIButton*)cancelButton {
1493 if (_cancelButton) 1502 if (_cancelButton)
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
1835 ui::PageTransition transition = ui::PageTransitionFromInt( 1844 ui::PageTransition transition = ui::PageTransitionFromInt(
1836 ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR); 1845 ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR);
1837 [self.urlLoader loadURL:GURL(searchURL) 1846 [self.urlLoader loadURL:GURL(searchURL)
1838 referrer:web::Referrer() 1847 referrer:web::Referrer()
1839 transition:transition 1848 transition:transition
1840 rendererInitiated:NO]; 1849 rendererInitiated:NO];
1841 } 1850 }
1842 } 1851 }
1843 1852
1844 - (UIView*)keyboardAccessoryView { 1853 - (UIView*)keyboardAccessoryView {
1845 if (!_keyBoardAccessoryView) { 1854 if (!_keyboardAccessoryView) {
1846 NSArray<NSString*>* buttonTitles = 1855 if (experimental_flags::IsKeyboardAccessoryViewWithCameraSearchEnabled()) {
1847 [NSArray arrayWithObjects:@":", @".", @"-", @"/", kDotComTLD, nil]; 1856 // The '.' shortcut is left out because the new keyboard accessory view
1848 _keyBoardAccessoryView = 1857 // has less free space for the shortcut buttons, and the '.' is already
1849 [[KeyboardAccessoryView alloc] initWithButtons:buttonTitles 1858 // present in the standard iOS keyboard.
1850 delegate:self]; 1859 NSArray<NSString*>* buttonTitles = @[ @":", @"-", @"/", kDotComTLD ];
1851 [_keyBoardAccessoryView 1860 _keyboardAccessoryView =
1861 [[NewKeyboardAccessoryView alloc] initWithButtons:buttonTitles
1862 delegate:self];
1863 } else {
1864 NSArray<NSString*>* buttonTitles =
1865 @[ @":", @".", @"-", @"/", kDotComTLD ];
1866 _keyboardAccessoryView =
1867 [[KeyboardAccessoryView alloc] initWithButtons:buttonTitles
1868 delegate:self];
1869 }
1870 [_keyboardAccessoryView
1852 setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; 1871 setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
1853 _hardwareKeyboardWatcher = [[HardwareKeyboardWatcher alloc] 1872 _hardwareKeyboardWatcher = [[HardwareKeyboardWatcher alloc]
1854 initWithAccessoryView:_keyBoardAccessoryView]; 1873 initWithAccessoryView:_keyboardAccessoryView];
1855 } 1874 }
1856 return _keyBoardAccessoryView; 1875 return _keyboardAccessoryView;
1857 } 1876 }
1858 1877
1859 - (void)preloadVoiceSearch:(id)sender { 1878 - (void)preloadVoiceSearch:(id)sender {
1860 DCHECK(ios::GetChromeBrowserProvider() 1879 DCHECK(ios::GetChromeBrowserProvider()
1861 ->GetVoiceSearchProvider() 1880 ->GetVoiceSearchProvider()
1862 ->IsVoiceSearchEnabled()); 1881 ->IsVoiceSearchEnabled());
1863 // Use a GenericChromeCommand because |sender| already has a tag set for a 1882 // Use a GenericChromeCommand because |sender| already has a tag set for a
1864 // different command. 1883 // different command.
1865 GenericChromeCommand* command = 1884 GenericChromeCommand* command =
1866 [[GenericChromeCommand alloc] initWithTag:IDC_PRELOAD_VOICE_SEARCH]; 1885 [[GenericChromeCommand alloc] initWithTag:IDC_PRELOAD_VOICE_SEARCH];
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after
2450 2469
2451 - (BOOL)isPrerenderAnimationRunning { 2470 - (BOOL)isPrerenderAnimationRunning {
2452 return _prerenderAnimating; 2471 return _prerenderAnimating;
2453 } 2472 }
2454 2473
2455 - (OmniboxTextFieldIOS*)omnibox { 2474 - (OmniboxTextFieldIOS*)omnibox {
2456 return _omniBox; 2475 return _omniBox;
2457 } 2476 }
2458 2477
2459 @end 2478 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/toolbar/toolbar_tools_menu_button.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698