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

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

Issue 2965943002: [ios] Remove IDC_BACK and IDC_FORWARD
Patch Set: Rebase, self review. Created 3 years, 5 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
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 19 matching lines...) Expand all
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/experimental_flags.h"
33 #include "ios/chrome/browser/reading_list/reading_list_model_factory.h" 33 #include "ios/chrome/browser/reading_list/reading_list_model_factory.h"
34 #include "ios/chrome/browser/search_engines/template_url_service_factory.h" 34 #include "ios/chrome/browser/search_engines/template_url_service_factory.h"
35 #import "ios/chrome/browser/tabs/tab.h" 35 #import "ios/chrome/browser/tabs/tab.h"
36 #import "ios/chrome/browser/tabs/tab_model.h" 36 #import "ios/chrome/browser/tabs/tab_model.h"
37 #import "ios/chrome/browser/ui/animation_util.h" 37 #import "ios/chrome/browser/ui/animation_util.h"
38 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" 38 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
39 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" 39 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h"
40 #import "ios/chrome/browser/ui/commands/browser_commands.h"
40 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" 41 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h"
41 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" 42 #include "ios/chrome/browser/ui/commands/ios_command_ids.h"
42 #import "ios/chrome/browser/ui/history/tab_history_popup_controller.h" 43 #import "ios/chrome/browser/ui/history/tab_history_popup_controller.h"
43 #import "ios/chrome/browser/ui/image_util.h" 44 #import "ios/chrome/browser/ui/image_util.h"
44 #import "ios/chrome/browser/ui/keyboard/hardware_keyboard_watcher.h" 45 #import "ios/chrome/browser/ui/keyboard/hardware_keyboard_watcher.h"
45 #include "ios/chrome/browser/ui/omnibox/location_bar_controller_impl.h" 46 #include "ios/chrome/browser/ui/omnibox/location_bar_controller_impl.h"
46 #include "ios/chrome/browser/ui/omnibox/omnibox_view_ios.h" 47 #include "ios/chrome/browser/ui/omnibox/omnibox_view_ios.h"
47 #import "ios/chrome/browser/ui/popup_menu/popup_menu_view.h" 48 #import "ios/chrome/browser/ui/popup_menu/popup_menu_view.h"
48 #import "ios/chrome/browser/ui/reversed_animation.h" 49 #import "ios/chrome/browser/ui/reversed_animation.h"
49 #include "ios/chrome/browser/ui/rtl_geometry.h" 50 #include "ios/chrome/browser/ui/rtl_geometry.h"
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 @end 360 @end
360 361
361 @implementation WebToolbarController 362 @implementation WebToolbarController
362 363
363 @synthesize delegate = _delegate; 364 @synthesize delegate = _delegate;
364 @synthesize urlLoader = _urlLoader; 365 @synthesize urlLoader = _urlLoader;
365 366
366 - (instancetype)initWithDelegate:(id<WebToolbarDelegate>)delegate 367 - (instancetype)initWithDelegate:(id<WebToolbarDelegate>)delegate
367 urlLoader:(id<UrlLoader>)urlLoader 368 urlLoader:(id<UrlLoader>)urlLoader
368 browserState:(ios::ChromeBrowserState*)browserState 369 browserState:(ios::ChromeBrowserState*)browserState
369 preloadProvider:(id<PreloadProvider>)preloader { 370 preloadProvider:(id<PreloadProvider>)preloader
371 dispatcher:(id<BrowserCommands>)dispatcher {
370 DCHECK(delegate); 372 DCHECK(delegate);
371 DCHECK(urlLoader); 373 DCHECK(urlLoader);
372 DCHECK(browserState); 374 DCHECK(browserState);
373 _delegate = delegate; 375 _delegate = delegate;
374 _urlLoader = urlLoader; 376 _urlLoader = urlLoader;
375 _browserState = browserState; 377 _browserState = browserState;
376 _incognito = browserState->IsOffTheRecord(); 378 _incognito = browserState->IsOffTheRecord();
377 self = [super initWithStyle:(_incognito ? ToolbarControllerStyleIncognitoMode 379 self = [super initWithStyle:(_incognito ? ToolbarControllerStyleIncognitoMode
378 : ToolbarControllerStyleLightMode)]; 380 : ToolbarControllerStyleLightMode)];
379 if (!self) 381 if (!self)
380 return nil; 382 return nil;
381 383
384 self.dispatcher = dispatcher;
382 self.readingListModel = 385 self.readingListModel =
383 ReadingListModelFactory::GetForBrowserState(browserState); 386 ReadingListModelFactory::GetForBrowserState(browserState);
384 387
385 InterfaceIdiom idiom = IsIPadIdiom() ? IPAD_IDIOM : IPHONE_IDIOM; 388 InterfaceIdiom idiom = IsIPadIdiom() ? IPAD_IDIOM : IPHONE_IDIOM;
386 // Note that |_webToolbar| gets its frame set to -specificControlArea later in 389 // Note that |_webToolbar| gets its frame set to -specificControlArea later in
387 // this method. 390 // this method.
388 _webToolbar = 391 _webToolbar =
389 [[UIView alloc] initWithFrame:LayoutRectGetRect(kWebToolbarFrame[idiom])]; 392 [[UIView alloc] initWithFrame:LayoutRectGetRect(kWebToolbarFrame[idiom])];
390 UIColor* textColor = 393 UIColor* textColor =
391 _incognito 394 _incognito
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 [self layoutIncognitoIcon]; 472 [self layoutIncognitoIcon];
470 [_webToolbar addSubview:_incognitoIcon]; 473 [_webToolbar addSubview:_incognitoIcon];
471 } 474 }
472 } 475 }
473 476
474 [_webToolbar addSubview:_omniBox]; 477 [_webToolbar addSubview:_omniBox];
475 478
476 [_backButton setEnabled:NO]; 479 [_backButton setEnabled:NO];
477 [_forwardButton setEnabled:NO]; 480 [_forwardButton setEnabled:NO];
478 481
482 // Assign tags before calling -setUpButton, since only buttons with tags
483 // have -chromeExecuteCommand added as a target.
484 [_reloadButton setTag:IDC_RELOAD];
485 [_stopButton setTag:IDC_STOP];
486 [_starButton setTag:IDC_BOOKMARK_PAGE];
487 [_voiceSearchButton setTag:IDC_VOICE_SEARCH];
488
479 if (idiom == IPAD_IDIOM) { 489 if (idiom == IPAD_IDIOM) {
480 // Note that the reload button gets repositioned when -layoutOmnibox is 490 // Note that the reload button gets repositioned when -layoutOmnibox is
481 // called. 491 // called.
482 _reloadButton = [[UIButton alloc] 492 _reloadButton = [[UIButton alloc]
483 initWithFrame:LayoutRectGetRect(kStopReloadButtonFrame)]; 493 initWithFrame:LayoutRectGetRect(kStopReloadButtonFrame)];
484 [_reloadButton 494 [_reloadButton
485 setAutoresizingMask:UIViewAutoresizingFlexibleTrailingMargin() | 495 setAutoresizingMask:UIViewAutoresizingFlexibleTrailingMargin() |
486 UIViewAutoresizingFlexibleBottomMargin]; 496 UIViewAutoresizingFlexibleBottomMargin];
487 _stopButton = [[UIButton alloc] 497 _stopButton = [[UIButton alloc]
488 initWithFrame:LayoutRectGetRect(kStopReloadButtonFrame)]; 498 initWithFrame:LayoutRectGetRect(kStopReloadButtonFrame)];
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 withImageEnum:WebToolbarButtonNameBack 542 withImageEnum:WebToolbarButtonNameBack
533 forInitialState:UIControlStateDisabled 543 forInitialState:UIControlStateDisabled
534 hasDisabledImage:YES 544 hasDisabledImage:YES
535 synchronously:NO]; 545 synchronously:NO];
536 [self setUpButton:_forwardButton 546 [self setUpButton:_forwardButton
537 withImageEnum:WebToolbarButtonNameForward 547 withImageEnum:WebToolbarButtonNameForward
538 forInitialState:UIControlStateDisabled 548 forInitialState:UIControlStateDisabled
539 hasDisabledImage:YES 549 hasDisabledImage:YES
540 synchronously:NO]; 550 synchronously:NO];
541 551
552 // Assign targets for buttons using the dispatcher.
553 [_backButton addTarget:self.dispatcher
554 action:@selector(goBack)
555 forControlEvents:UIControlEventTouchUpInside];
556 [_forwardButton addTarget:self.dispatcher
557 action:@selector(goForward)
558 forControlEvents:UIControlEventTouchUpInside];
559
542 _backButtonMode = ToolbarButtonModeNormal; 560 _backButtonMode = ToolbarButtonModeNormal;
543 _forwardButtonMode = ToolbarButtonModeNormal; 561 _forwardButtonMode = ToolbarButtonModeNormal;
544 UILongPressGestureRecognizer* backLongPress = 562 UILongPressGestureRecognizer* backLongPress =
545 [[UILongPressGestureRecognizer alloc] 563 [[UILongPressGestureRecognizer alloc]
546 initWithTarget:self 564 initWithTarget:self
547 action:@selector(handleLongPress:)]; 565 action:@selector(handleLongPress:)];
548 [_backButton addGestureRecognizer:backLongPress]; 566 [_backButton addGestureRecognizer:backLongPress];
549 UILongPressGestureRecognizer* forwardLongPress = 567 UILongPressGestureRecognizer* forwardLongPress =
550 [[UILongPressGestureRecognizer alloc] 568 [[UILongPressGestureRecognizer alloc]
551 initWithTarget:self 569 initWithTarget:self
552 action:@selector(handleLongPress:)]; 570 action:@selector(handleLongPress:)];
553 [_forwardButton addGestureRecognizer:forwardLongPress]; 571 [_forwardButton addGestureRecognizer:forwardLongPress];
554 572
555 // TODO(leng): Consider moving this to a pak file as well. For now, 573 // TODO(leng): Consider moving this to a pak file as well. For now,
556 // because it is also used by find_bar_controller_ios, leave it as is. 574 // because it is also used by find_bar_controller_ios, leave it as is.
557 NSString* imageName = 575 NSString* imageName =
558 _incognito ? @"omnibox_transparent_background" : @"omnibox_background"; 576 _incognito ? @"omnibox_transparent_background" : @"omnibox_background";
559 [_omniboxBackground setImage:StretchableImageNamed(imageName, 12, 12)]; 577 [_omniboxBackground setImage:StretchableImageNamed(imageName, 12, 12)];
560 [_omniBox setAutoresizingMask:UIViewAutoresizingFlexibleWidth | 578 [_omniBox setAutoresizingMask:UIViewAutoresizingFlexibleWidth |
561 UIViewAutoresizingFlexibleBottomMargin]; 579 UIViewAutoresizingFlexibleBottomMargin];
562 [_reloadButton addTarget:self 580 [_reloadButton addTarget:self
563 action:@selector(cancelOmniboxEdit) 581 action:@selector(cancelOmniboxEdit)
564 forControlEvents:UIControlEventTouchUpInside]; 582 forControlEvents:UIControlEventTouchUpInside];
565 [_stopButton addTarget:self 583 [_stopButton addTarget:self
566 action:@selector(cancelOmniboxEdit) 584 action:@selector(cancelOmniboxEdit)
567 forControlEvents:UIControlEventTouchUpInside]; 585 forControlEvents:UIControlEventTouchUpInside];
568 586
569 [_backButton setTag:IDC_BACK];
570 [_forwardButton setTag:IDC_FORWARD];
571 [_reloadButton setTag:IDC_RELOAD];
572 [_stopButton setTag:IDC_STOP];
573 [_starButton setTag:IDC_BOOKMARK_PAGE];
574 [_voiceSearchButton setTag:IDC_VOICE_SEARCH];
575
576 SetA11yLabelAndUiAutomationName(_backButton, IDS_ACCNAME_BACK, @"Back"); 587 SetA11yLabelAndUiAutomationName(_backButton, IDS_ACCNAME_BACK, @"Back");
577 SetA11yLabelAndUiAutomationName(_forwardButton, IDS_ACCNAME_FORWARD, 588 SetA11yLabelAndUiAutomationName(_forwardButton, IDS_ACCNAME_FORWARD,
578 @"Forward"); 589 @"Forward");
579 SetA11yLabelAndUiAutomationName(_reloadButton, IDS_IOS_ACCNAME_RELOAD, 590 SetA11yLabelAndUiAutomationName(_reloadButton, IDS_IOS_ACCNAME_RELOAD,
580 @"Reload"); 591 @"Reload");
581 SetA11yLabelAndUiAutomationName(_stopButton, IDS_IOS_ACCNAME_STOP, @"Stop"); 592 SetA11yLabelAndUiAutomationName(_stopButton, IDS_IOS_ACCNAME_STOP, @"Stop");
582 SetA11yLabelAndUiAutomationName(_starButton, IDS_TOOLTIP_STAR, @"Bookmark"); 593 SetA11yLabelAndUiAutomationName(_starButton, IDS_TOOLTIP_STAR, @"Bookmark");
583 SetA11yLabelAndUiAutomationName( 594 SetA11yLabelAndUiAutomationName(
584 _voiceSearchButton, IDS_IOS_ACCNAME_VOICE_SEARCH, @"Voice Search"); 595 _voiceSearchButton, IDS_IOS_ACCNAME_VOICE_SEARCH, @"Voice Search");
585 SetA11yLabelAndUiAutomationName(_omniBox, IDS_ACCNAME_LOCATION, @"Address"); 596 SetA11yLabelAndUiAutomationName(_omniBox, IDS_ACCNAME_LOCATION, @"Address");
(...skipping 1881 matching lines...) Expand 10 before | Expand all | Expand 10 after
2467 2478
2468 - (BOOL)isPrerenderAnimationRunning { 2479 - (BOOL)isPrerenderAnimationRunning {
2469 return _prerenderAnimating; 2480 return _prerenderAnimating;
2470 } 2481 }
2471 2482
2472 - (OmniboxTextFieldIOS*)omnibox { 2483 - (OmniboxTextFieldIOS*)omnibox {
2473 return _omniBox; 2484 return _omniBox;
2474 } 2485 }
2475 2486
2476 @end 2487 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698