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

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

Issue 2852713002: Revert of [ObjC ARC] Converts ios/chrome/browser/ui/toolbar:toolbar to ARC. (Closed)
Patch Set: Created 3 years, 7 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/web_toolbar_controller.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>
11 11
12 #include <algorithm> 12 #include <algorithm>
13 #include <memory> 13 #include <memory>
14 14
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/ios/weak_nsobject.h"
16 #include "base/logging.h" 17 #include "base/logging.h"
17 #include "base/mac/bundle_locations.h" 18 #include "base/mac/bundle_locations.h"
18 #include "base/mac/foundation_util.h" 19 #include "base/mac/foundation_util.h"
19 #include "base/memory/ptr_util.h" 20 #include "base/memory/ptr_util.h"
20 #include "base/metrics/histogram_macros.h" 21 #include "base/metrics/histogram_macros.h"
21 #include "base/metrics/user_metrics.h" 22 #include "base/metrics/user_metrics.h"
22 #include "base/metrics/user_metrics_action.h" 23 #include "base/metrics/user_metrics_action.h"
23 #include "base/strings/sys_string_conversions.h" 24 #include "base/strings/sys_string_conversions.h"
24 #include "components/google/core/browser/google_util.h" 25 #include "components/google/core/browser/google_util.h"
25 #include "components/omnibox/browser/omnibox_edit_model.h" 26 #include "components/omnibox/browser/omnibox_edit_model.h"
(...skipping 10 matching lines...) Expand all
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/reversed_animation.h" 47 #import "ios/chrome/browser/ui/reversed_animation.h"
48 #include "ios/chrome/browser/ui/rtl_geometry.h" 48 #include "ios/chrome/browser/ui/rtl_geometry.h"
49 #import "ios/chrome/browser/ui/toolbar/toolbar_controller+protected.h" 49 #import "ios/chrome/browser/ui/toolbar/toolbar_controller+protected.h"
50 #import "ios/chrome/browser/ui/toolbar/toolbar_controller.h" 50 #import "ios/chrome/browser/ui/toolbar/toolbar_controller.h"
51 #import "ios/chrome/browser/ui/toolbar/toolbar_model_ios.h" 51 #import "ios/chrome/browser/ui/toolbar/toolbar_model_ios.h"
52 #include "ios/chrome/browser/ui/toolbar/toolbar_resource_macros.h" 52 #include "ios/chrome/browser/ui/toolbar/toolbar_resource_macros.h"
53 #include "ios/chrome/browser/ui/ui_util.h" 53 #include "ios/chrome/browser/ui/ui_util.h"
54 #import "ios/chrome/browser/ui/uikit_ui_util.h" 54 #import "ios/chrome/browser/ui/uikit_ui_util.h"
55 #import "ios/chrome/browser/ui/url_loader.h" 55 #import "ios/chrome/browser/ui/url_loader.h"
56 #import "ios/chrome/browser/ui/voice/text_to_speech_player.h" 56 #import "ios/chrome/browser/ui/voice/text_to_speech_player.h"
57 #import "ios/chrome/browser/ui/voice/voice_search_notification_names.h" 57 #import "ios/chrome/browser/ui/voice/voice_search_notification_names.h"
58 #import "ios/chrome/common/material_timing.h" 58 #import "ios/chrome/common/material_timing.h"
59 #include "ios/chrome/grit/ios_strings.h" 59 #include "ios/chrome/grit/ios_strings.h"
60 #import "ios/public/provider/chrome/browser/chrome_browser_provider.h" 60 #import "ios/public/provider/chrome/browser/chrome_browser_provider.h"
61 #import "ios/public/provider/chrome/browser/images/branded_image_provider.h" 61 #import "ios/public/provider/chrome/browser/images/branded_image_provider.h"
62 #import "ios/public/provider/chrome/browser/voice/voice_search_provider.h" 62 #import "ios/public/provider/chrome/browser/voice/voice_search_provider.h"
63 #include "ios/shared/chrome/browser/ui/omnibox/location_bar_controller.h" 63 #include "ios/shared/chrome/browser/ui/omnibox/location_bar_controller.h"
64 #include "ios/shared/chrome/browser/ui/omnibox/location_bar_delegate.h" 64 #include "ios/shared/chrome/browser/ui/omnibox/location_bar_delegate.h"
65 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h" 65 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h"
66 #import "ios/third_party/material_components_ios/src/components/ProgressView/src /MaterialProgressView.h" 66 #import "ios/third_party/material_components_ios/src/components/ProgressView/src /MaterialProgressView.h"
67 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h" 67 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h"
68 #include "ios/web/public/referrer.h" 68 #include "ios/web/public/referrer.h"
69 #import "ios/web/public/web_state/web_state.h" 69 #import "ios/web/public/web_state/web_state.h"
70 #import "net/base/mac/url_conversions.h" 70 #import "net/base/mac/url_conversions.h"
71 #include "ui/base/l10n/l10n_util.h" 71 #include "ui/base/l10n/l10n_util.h"
72 #include "ui/base/page_transition_types.h" 72 #include "ui/base/page_transition_types.h"
73 #import "ui/gfx/ios/NSString+CrStringDrawing.h" 73 #import "ui/gfx/ios/NSString+CrStringDrawing.h"
74 74
75 #if !defined(__has_feature) || !__has_feature(objc_arc)
76 #error "This file requires ARC support."
77 #endif
78
79 using base::UserMetricsAction; 75 using base::UserMetricsAction;
80 using ios::material::TimingFunction; 76 using ios::material::TimingFunction;
81 77
82 NSString* const kTabHistoryPopupWillShowNotification = 78 NSString* const kTabHistoryPopupWillShowNotification =
83 @"kTabHistoryPopupWillShowNotification"; 79 @"kTabHistoryPopupWillShowNotification";
84 NSString* const kTabHistoryPopupWillHideNotification = 80 NSString* const kTabHistoryPopupWillHideNotification =
85 @"kTabHistoryPopupWillHideNotification"; 81 @"kTabHistoryPopupWillHideNotification";
86 const CGFloat kiPhoneOmniboxPlaceholderColorBrightness = 150 / 255.0; 82 const CGFloat kiPhoneOmniboxPlaceholderColorBrightness = 150 / 255.0;
87 83
88 // The histogram recording CLAuthorizationStatus for omnibox queries. 84 // The histogram recording CLAuthorizationStatus for omnibox queries.
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 // switch the main bots to Xcode 8. 235 // switch the main bots to Xcode 8.
240 #if defined(__IPHONE_10_0) && (__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0) 236 #if defined(__IPHONE_10_0) && (__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0)
241 @interface WebToolbarController ()<CAAnimationDelegate> 237 @interface WebToolbarController ()<CAAnimationDelegate>
242 @end 238 @end
243 #endif 239 #endif
244 240
245 @interface WebToolbarController ()<LocationBarDelegate, 241 @interface WebToolbarController ()<LocationBarDelegate,
246 OmniboxPopupPositioner, 242 OmniboxPopupPositioner,
247 ToolbarFrameDelegate> { 243 ToolbarFrameDelegate> {
248 // Top-level view for web content. 244 // Top-level view for web content.
249 UIView* _webToolbar; 245 base::scoped_nsobject<UIView> _webToolbar;
250 UIButton* _backButton; 246 base::scoped_nsobject<UIButton> _backButton;
251 UIButton* _forwardButton; 247 base::scoped_nsobject<UIButton> _forwardButton;
252 UIButton* _reloadButton; 248 base::scoped_nsobject<UIButton> _reloadButton;
253 UIButton* _stopButton; 249 base::scoped_nsobject<UIButton> _stopButton;
254 UIButton* _starButton; 250 base::scoped_nsobject<UIButton> _starButton;
255 UIButton* _voiceSearchButton; 251 base::scoped_nsobject<UIButton> _voiceSearchButton;
256 OmniboxTextFieldIOS* _omniBox; 252 base::scoped_nsobject<OmniboxTextFieldIOS> _omniBox;
257 UIButton* _cancelButton; 253 base::scoped_nsobject<UIButton> _cancelButton;
258 UIView* _keyBoardAccessoryView; 254 base::scoped_nsobject<UIView> _keyBoardAccessoryView;
259 UIButton* _keyboardVoiceSearchButton; 255 base::scoped_nsobject<UIButton> _keyboardVoiceSearchButton;
260 // Progress bar used to show what fraction of the page has loaded. 256 // Progress bar used to show what fraction of the page has loaded.
261 MDCProgressView* _determinateProgressView; 257 base::scoped_nsobject<MDCProgressView> _determinateProgressView;
262 UIImageView* _omniboxBackground; 258 base::scoped_nsobject<UIImageView> _omniboxBackground;
263 BOOL _prerenderAnimating; 259 BOOL _prerenderAnimating;
264 UIImageView* _incognitoIcon; 260 base::scoped_nsobject<UIImageView> _incognitoIcon;
265 UIView* _clippingView; 261 base::scoped_nsobject<UIView> _clippingView;
266 262
267 std::unique_ptr<LocationBarController> _locationBar; 263 std::unique_ptr<LocationBarController> _locationBar;
268 BOOL _initialLayoutComplete; 264 BOOL _initialLayoutComplete;
269 // If |YES|, toolbar is incognito. 265 // If |YES|, toolbar is incognito.
270 BOOL _incognito; 266 BOOL _incognito;
271 267
272 // If set to |YES|, disables animations that tests would otherwise trigger. 268 // If set to |YES|, disables animations that tests would otherwise trigger.
273 BOOL _unitTesting; 269 BOOL _unitTesting;
274 270
275 // If set to |YES|, text to speech is currently playing and the toolbar voice 271 // If set to |YES|, text to speech is currently playing and the toolbar voice
276 // icon should indicate so. 272 // icon should indicate so.
277 BOOL _isTTSPlaying; 273 BOOL _isTTSPlaying;
278 274
279 // Keeps track of whether or not the back button's images have been reversed. 275 // Keeps track of whether or not the back button's images have been reversed.
280 ToolbarButtonMode _backButtonMode; 276 ToolbarButtonMode _backButtonMode;
281 277
282 // Keeps track of whether or not the forward button's images have been 278 // Keeps track of whether or not the forward button's images have been
283 // reversed. 279 // reversed.
284 ToolbarButtonMode _forwardButtonMode; 280 ToolbarButtonMode _forwardButtonMode;
285 281
286 // Keeps track of last known trait collection used by the subviews. 282 // Keeps track of last known trait collection used by the subviews.
287 UITraitCollection* _lastKnownTraitCollection; 283 base::scoped_nsobject<UITraitCollection> _lastKnownTraitCollection;
288 284
289 // A snapshot of the current toolbar view. Only valid for phone, will be nil 285 // A snapshot of the current toolbar view. Only valid for phone, will be nil
290 // if on tablet. 286 // if on tablet.
291 UIImage* _snapshot; 287 base::scoped_nsobject<UIImage> _snapshot;
292 // A hash of the state of the toolbar when the snapshot was taken. 288 // A hash of the state of the toolbar when the snapshot was taken.
293 uint32_t _snapshotHash; 289 uint32_t _snapshotHash;
294 290
295 // View controller for displaying tab history when the user long presses the 291 // View controller for displaying tab history when the user long presses the
296 // back or forward button. nil if not visible. 292 // back or forward button. nil if not visible.
297 TabHistoryPopupController* _tabHistoryPopupController; 293 base::scoped_nsobject<TabHistoryPopupController> _tabHistoryPopupController;
298 294
299 // Hardware keyboard watcher, to detect the type of keyboard currently 295 // Hardware keyboard watcher, to detect the type of keyboard currently
300 // attached. 296 // attached.
301 HardwareKeyboardWatcher* _hardwareKeyboardWatcher; 297 base::scoped_nsobject<HardwareKeyboardWatcher> _hardwareKeyboardWatcher;
302 298
303 // The current browser state. 299 // The current browser state.
304 ios::ChromeBrowserState* _browserState; // weak 300 ios::ChromeBrowserState* _browserState; // weak
305 } 301 }
306 302
307 // Accessor for cancel button. Handles lazy initialization. 303 // Accessor for cancel button. Handles lazy initialization.
308 - (UIButton*)cancelButton; 304 - (UIButton*)cancelButton;
309 // Handler called after user pressed the cancel button. 305 // Handler called after user pressed the cancel button.
310 - (void)cancelButtonPressed:(id)sender; 306 - (void)cancelButtonPressed:(id)sender;
311 - (void)layoutCancelButton; 307 - (void)layoutCancelButton;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 : ToolbarControllerStyleLightMode)]; 388 : ToolbarControllerStyleLightMode)];
393 if (!self) 389 if (!self)
394 return nil; 390 return nil;
395 391
396 self.readingListModel = 392 self.readingListModel =
397 ReadingListModelFactory::GetForBrowserState(browserState); 393 ReadingListModelFactory::GetForBrowserState(browserState);
398 394
399 InterfaceIdiom idiom = IsIPadIdiom() ? IPAD_IDIOM : IPHONE_IDIOM; 395 InterfaceIdiom idiom = IsIPadIdiom() ? IPAD_IDIOM : IPHONE_IDIOM;
400 // Note that |_webToolbar| gets its frame set to -specificControlArea later in 396 // Note that |_webToolbar| gets its frame set to -specificControlArea later in
401 // this method. 397 // this method.
402 _webToolbar = 398 _webToolbar.reset([[UIView alloc]
403 [[UIView alloc] initWithFrame:LayoutRectGetRect(kWebToolbarFrame[idiom])]; 399 initWithFrame:LayoutRectGetRect(kWebToolbarFrame[idiom])]);
404 UIColor* textColor = 400 UIColor* textColor =
405 _incognito 401 _incognito
406 ? [UIColor whiteColor] 402 ? [UIColor whiteColor]
407 : [UIColor colorWithWhite:0 alpha:[MDCTypography body1FontOpacity]]; 403 : [UIColor colorWithWhite:0 alpha:[MDCTypography body1FontOpacity]];
408 UIColor* tintColor = _incognito ? textColor : nil; 404 UIColor* tintColor = _incognito ? textColor : nil;
409 CGRect omniboxRect = LayoutRectGetRect(kOmniboxFrame[idiom]); 405 CGRect omniboxRect = LayoutRectGetRect(kOmniboxFrame[idiom]);
410 _omniBox = 406 _omniBox.reset([[OmniboxTextFieldIOS alloc]
411 [[OmniboxTextFieldIOS alloc] initWithFrame:omniboxRect 407 initWithFrame:omniboxRect
412 font:[MDCTypography subheadFont] 408 font:[MDCTypography subheadFont]
413 textColor:textColor 409 textColor:textColor
414 tintColor:tintColor]; 410 tintColor:tintColor]);
415 if (_incognito) { 411 if (_incognito) {
416 [_omniBox setIncognito:YES]; 412 [_omniBox setIncognito:YES];
417 [_omniBox 413 [_omniBox
418 setSelectedTextBackgroundColor:[UIColor colorWithWhite:1 alpha:0.1]]; 414 setSelectedTextBackgroundColor:[UIColor colorWithWhite:1 alpha:0.1]];
419 [_omniBox setPlaceholderTextColor:[UIColor colorWithWhite:1 alpha:0.5]]; 415 [_omniBox setPlaceholderTextColor:[UIColor colorWithWhite:1 alpha:0.5]];
420 } else if (!IsIPadIdiom()) { 416 } else if (!IsIPadIdiom()) {
421 // Set placeholder text color to match fakebox placeholder text color when 417 // Set placeholder text color to match fakebox placeholder text color when
422 // on iPhone and in regular mode. 418 // on iPhone and in regular mode.
423 UIColor* placeholderTextColor = 419 UIColor* placeholderTextColor =
424 [UIColor colorWithWhite:kiPhoneOmniboxPlaceholderColorBrightness 420 [UIColor colorWithWhite:kiPhoneOmniboxPlaceholderColorBrightness
425 alpha:1.0]; 421 alpha:1.0];
426 [_omniBox setPlaceholderTextColor:placeholderTextColor]; 422 [_omniBox setPlaceholderTextColor:placeholderTextColor];
427 } 423 }
428 _backButton = [[UIButton alloc] 424 _backButton.reset([[UIButton alloc]
429 initWithFrame:LayoutRectGetRect(kBackButtonFrame[idiom])]; 425 initWithFrame:LayoutRectGetRect(kBackButtonFrame[idiom])]);
430 [_backButton setAutoresizingMask:UIViewAutoresizingFlexibleTrailingMargin() | 426 [_backButton setAutoresizingMask:UIViewAutoresizingFlexibleTrailingMargin() |
431 UIViewAutoresizingFlexibleTopMargin | 427 UIViewAutoresizingFlexibleTopMargin |
432 UIViewAutoresizingFlexibleBottomMargin]; 428 UIViewAutoresizingFlexibleBottomMargin];
433 // Note that the forward button gets repositioned when -layoutOmnibox is 429 // Note that the forward button gets repositioned when -layoutOmnibox is
434 // called. 430 // called.
435 _forwardButton = [[UIButton alloc] 431 _forwardButton.reset([[UIButton alloc]
436 initWithFrame:LayoutRectGetRect(kForwardButtonFrame[idiom])]; 432 initWithFrame:LayoutRectGetRect(kForwardButtonFrame[idiom])]);
437 [_forwardButton 433 [_forwardButton
438 setAutoresizingMask:UIViewAutoresizingFlexibleTrailingMargin() | 434 setAutoresizingMask:UIViewAutoresizingFlexibleTrailingMargin() |
439 UIViewAutoresizingFlexibleBottomMargin]; 435 UIViewAutoresizingFlexibleBottomMargin];
440 436
441 [_webToolbar addSubview:_backButton]; 437 [_webToolbar addSubview:_backButton];
442 [_webToolbar addSubview:_forwardButton]; 438 [_webToolbar addSubview:_forwardButton];
443 439
444 // _omniboxBackground needs to be added under _omniBox so as not to cover up 440 // _omniboxBackground needs to be added under _omniBox so as not to cover up
445 // _omniBox. 441 // _omniBox.
446 _omniboxBackground = [[UIImageView alloc] initWithFrame:omniboxRect]; 442 _omniboxBackground.reset([[UIImageView alloc] initWithFrame:omniboxRect]);
447 [_omniboxBackground 443 [_omniboxBackground
448 setAutoresizingMask:UIViewAutoresizingFlexibleWidth | 444 setAutoresizingMask:UIViewAutoresizingFlexibleWidth |
449 UIViewAutoresizingFlexibleBottomMargin]; 445 UIViewAutoresizingFlexibleBottomMargin];
450 446
451 if (idiom == IPAD_IDIOM) { 447 if (idiom == IPAD_IDIOM) {
452 [_webToolbar addSubview:_omniboxBackground]; 448 [_webToolbar addSubview:_omniboxBackground];
453 } else { 449 } else {
454 [_backButton setImageEdgeInsets:UIEdgeInsetsMakeDirected(0, 0, 0, -9)]; 450 [_backButton setImageEdgeInsets:UIEdgeInsetsMakeDirected(0, 0, 0, -9)];
455 [_forwardButton setImageEdgeInsets:UIEdgeInsetsMakeDirected(0, -7, 0, 0)]; 451 [_forwardButton setImageEdgeInsets:UIEdgeInsetsMakeDirected(0, -7, 0, 0)];
456 CGRect clippingFrame = 452 CGRect clippingFrame =
457 RectShiftedUpAndResizedForStatusBar(kToolbarFrame[idiom]); 453 RectShiftedUpAndResizedForStatusBar(kToolbarFrame[idiom]);
458 _clippingView = [[UIView alloc] initWithFrame:clippingFrame]; 454 _clippingView.reset([[UIView alloc] initWithFrame:clippingFrame]);
459 [_clippingView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | 455 [_clippingView setAutoresizingMask:UIViewAutoresizingFlexibleWidth |
460 UIViewAutoresizingFlexibleBottomMargin]; 456 UIViewAutoresizingFlexibleBottomMargin];
461 [_clippingView setClipsToBounds:YES]; 457 [_clippingView setClipsToBounds:YES];
462 [_clippingView setUserInteractionEnabled:NO]; 458 [_clippingView setUserInteractionEnabled:NO];
463 [_webToolbar addSubview:_clippingView]; 459 [_webToolbar addSubview:_clippingView];
464 460
465 CGRect omniboxBackgroundFrame = 461 CGRect omniboxBackgroundFrame =
466 RectShiftedDownForStatusBar([_omniboxBackground frame]); 462 RectShiftedDownForStatusBar([_omniboxBackground frame]);
467 [_omniboxBackground setFrame:omniboxBackgroundFrame]; 463 [_omniboxBackground setFrame:omniboxBackgroundFrame];
468 [_clippingView addSubview:_omniboxBackground]; 464 [_clippingView addSubview:_omniboxBackground];
469 [self.view 465 [self.view
470 setBackgroundColor:[UIColor colorWithWhite:kNTPBackgroundColorBrightness 466 setBackgroundColor:[UIColor colorWithWhite:kNTPBackgroundColorBrightness
471 alpha:1.0]]; 467 alpha:1.0]];
472 468
473 if (_incognito) { 469 if (_incognito) {
474 [self.view 470 [self.view
475 setBackgroundColor: 471 setBackgroundColor:
476 [UIColor colorWithWhite:kNTPBackgroundColorBrightnessIncognito 472 [UIColor colorWithWhite:kNTPBackgroundColorBrightnessIncognito
477 alpha:1.0]]; 473 alpha:1.0]];
478 _incognitoIcon = [[UIImageView alloc] 474 _incognitoIcon.reset([[UIImageView alloc]
479 initWithImage:[UIImage imageNamed:@"incognito_marker_typing"]]; 475 initWithImage:[UIImage imageNamed:@"incognito_marker_typing"]]);
480 [_incognitoIcon setAlpha:0]; 476 [_incognitoIcon setAlpha:0];
481 [_incognitoIcon 477 [_incognitoIcon
482 setAutoresizingMask:UIViewAutoresizingFlexibleTrailingMargin()]; 478 setAutoresizingMask:UIViewAutoresizingFlexibleTrailingMargin()];
483 [self layoutIncognitoIcon]; 479 [self layoutIncognitoIcon];
484 [_webToolbar addSubview:_incognitoIcon]; 480 [_webToolbar addSubview:_incognitoIcon];
485 } 481 }
486 } 482 }
487 483
488 [_webToolbar addSubview:_omniBox]; 484 [_webToolbar addSubview:_omniBox];
489 485
490 [_backButton setEnabled:NO]; 486 [_backButton setEnabled:NO];
491 [_forwardButton setEnabled:NO]; 487 [_forwardButton setEnabled:NO];
492 488
493 if (idiom == IPAD_IDIOM) { 489 if (idiom == IPAD_IDIOM) {
494 // Note that the reload button gets repositioned when -layoutOmnibox is 490 // Note that the reload button gets repositioned when -layoutOmnibox is
495 // called. 491 // called.
496 _reloadButton = [[UIButton alloc] 492 _reloadButton.reset([[UIButton alloc]
497 initWithFrame:LayoutRectGetRect(kStopReloadButtonFrame)]; 493 initWithFrame:LayoutRectGetRect(kStopReloadButtonFrame)]);
498 [_reloadButton 494 [_reloadButton
499 setAutoresizingMask:UIViewAutoresizingFlexibleTrailingMargin() | 495 setAutoresizingMask:UIViewAutoresizingFlexibleTrailingMargin() |
500 UIViewAutoresizingFlexibleBottomMargin]; 496 UIViewAutoresizingFlexibleBottomMargin];
501 _stopButton = [[UIButton alloc] 497 _stopButton.reset([[UIButton alloc]
502 initWithFrame:LayoutRectGetRect(kStopReloadButtonFrame)]; 498 initWithFrame:LayoutRectGetRect(kStopReloadButtonFrame)]);
503 [_stopButton 499 [_stopButton
504 setAutoresizingMask:UIViewAutoresizingFlexibleTrailingMargin() | 500 setAutoresizingMask:UIViewAutoresizingFlexibleTrailingMargin() |
505 UIViewAutoresizingFlexibleBottomMargin]; 501 UIViewAutoresizingFlexibleBottomMargin];
506 _starButton = 502 _starButton.reset(
507 [[UIButton alloc] initWithFrame:LayoutRectGetRect(kStarButtonFrame)]; 503 [[UIButton alloc] initWithFrame:LayoutRectGetRect(kStarButtonFrame)]);
508 [_starButton setAutoresizingMask:UIViewAutoresizingFlexibleBottomMargin | 504 [_starButton setAutoresizingMask:UIViewAutoresizingFlexibleBottomMargin |
509 UIViewAutoresizingFlexibleLeadingMargin()]; 505 UIViewAutoresizingFlexibleLeadingMargin()];
510 _voiceSearchButton = [[UIButton alloc] 506 _voiceSearchButton.reset([[UIButton alloc]
511 initWithFrame:LayoutRectGetRect(kVoiceSearchButtonFrame)]; 507 initWithFrame:LayoutRectGetRect(kVoiceSearchButtonFrame)]);
512 [_voiceSearchButton 508 [_voiceSearchButton
513 setAutoresizingMask:UIViewAutoresizingFlexibleBottomMargin | 509 setAutoresizingMask:UIViewAutoresizingFlexibleBottomMargin |
514 UIViewAutoresizingFlexibleLeadingMargin()]; 510 UIViewAutoresizingFlexibleLeadingMargin()];
515 [_webToolbar addSubview:_voiceSearchButton]; 511 [_webToolbar addSubview:_voiceSearchButton];
516 [_webToolbar addSubview:_starButton]; 512 [_webToolbar addSubview:_starButton];
517 [_webToolbar addSubview:_stopButton]; 513 [_webToolbar addSubview:_stopButton];
518 [_webToolbar addSubview:_reloadButton]; 514 [_webToolbar addSubview:_reloadButton];
519 [self setUpButton:_voiceSearchButton 515 [self setUpButton:_voiceSearchButton
520 withImageEnum:WebToolbarButtonNameVoice 516 withImageEnum:WebToolbarButtonNameVoice
521 forInitialState:UIControlStateNormal 517 forInitialState:UIControlStateNormal
(...skipping 26 matching lines...) Expand all
548 hasDisabledImage:YES 544 hasDisabledImage:YES
549 synchronously:NO]; 545 synchronously:NO];
550 [self setUpButton:_forwardButton 546 [self setUpButton:_forwardButton
551 withImageEnum:WebToolbarButtonNameForward 547 withImageEnum:WebToolbarButtonNameForward
552 forInitialState:UIControlStateDisabled 548 forInitialState:UIControlStateDisabled
553 hasDisabledImage:YES 549 hasDisabledImage:YES
554 synchronously:NO]; 550 synchronously:NO];
555 551
556 _backButtonMode = ToolbarButtonModeNormal; 552 _backButtonMode = ToolbarButtonModeNormal;
557 _forwardButtonMode = ToolbarButtonModeNormal; 553 _forwardButtonMode = ToolbarButtonModeNormal;
558 UILongPressGestureRecognizer* backLongPress = 554 base::scoped_nsobject<UILongPressGestureRecognizer> backLongPress(
559 [[UILongPressGestureRecognizer alloc] 555 [[UILongPressGestureRecognizer alloc]
560 initWithTarget:self 556 initWithTarget:self
561 action:@selector(handleLongPress:)]; 557 action:@selector(handleLongPress:)]);
562 [_backButton addGestureRecognizer:backLongPress]; 558 [_backButton addGestureRecognizer:backLongPress];
563 UILongPressGestureRecognizer* forwardLongPress = 559 base::scoped_nsobject<UILongPressGestureRecognizer> forwardLongPress(
564 [[UILongPressGestureRecognizer alloc] 560 [[UILongPressGestureRecognizer alloc]
565 initWithTarget:self 561 initWithTarget:self
566 action:@selector(handleLongPress:)]; 562 action:@selector(handleLongPress:)]);
567 [_forwardButton addGestureRecognizer:forwardLongPress]; 563 [_forwardButton addGestureRecognizer:forwardLongPress];
568 564
569 // TODO(leng): Consider moving this to a pak file as well. For now, 565 // TODO(leng): Consider moving this to a pak file as well. For now,
570 // because it is also used by find_bar_controller_ios, leave it as is. 566 // because it is also used by find_bar_controller_ios, leave it as is.
571 NSString* imageName = 567 NSString* imageName =
572 _incognito ? @"omnibox_transparent_background" : @"omnibox_background"; 568 _incognito ? @"omnibox_transparent_background" : @"omnibox_background";
573 [_omniboxBackground setImage:StretchableImageNamed(imageName, 12, 12)]; 569 [_omniboxBackground setImage:StretchableImageNamed(imageName, 12, 12)];
574 [_omniBox setAutoresizingMask:UIViewAutoresizingFlexibleWidth | 570 [_omniBox setAutoresizingMask:UIViewAutoresizingFlexibleWidth |
575 UIViewAutoresizingFlexibleBottomMargin]; 571 UIViewAutoresizingFlexibleBottomMargin];
576 [_reloadButton addTarget:self 572 [_reloadButton addTarget:self
(...skipping 27 matching lines...) Expand all
604 UIViewAutoresizingFlexibleBottomMargin]; 600 UIViewAutoresizingFlexibleBottomMargin];
605 [_webToolbar setFrame:[self specificControlsArea]]; 601 [_webToolbar setFrame:[self specificControlsArea]];
606 _locationBar = base::MakeUnique<LocationBarControllerImpl>( 602 _locationBar = base::MakeUnique<LocationBarControllerImpl>(
607 _omniBox, _browserState, preloader, self, self); 603 _omniBox, _browserState, preloader, self, self);
608 604
609 // Create the determinate progress bar (phone only). 605 // Create the determinate progress bar (phone only).
610 if (idiom == IPHONE_IDIOM) { 606 if (idiom == IPHONE_IDIOM) {
611 CGFloat progressWidth = self.view.frame.size.width; 607 CGFloat progressWidth = self.view.frame.size.width;
612 CGFloat progressHeight = 0; 608 CGFloat progressHeight = 0;
613 progressHeight = kMaterialProgressBarHeight; 609 progressHeight = kMaterialProgressBarHeight;
614 _determinateProgressView = [[MDCProgressView alloc] init]; 610 _determinateProgressView.reset([[MDCProgressView alloc] init]);
615 _determinateProgressView.hidden = YES; 611 _determinateProgressView.get().hidden = YES;
616 [_determinateProgressView 612 [_determinateProgressView
617 setProgressTintColor:[MDCPalette cr_bluePalette].tint500]; 613 setProgressTintColor:[MDCPalette cr_bluePalette].tint500];
618 [_determinateProgressView 614 [_determinateProgressView
619 setTrackTintColor:[MDCPalette cr_bluePalette].tint100]; 615 setTrackTintColor:[MDCPalette cr_bluePalette].tint100];
620 int progressBarYOffset = 616 int progressBarYOffset =
621 floor(progressHeight / 2) + kDeterminateProgressBarYOffset; 617 floor(progressHeight / 2) + kDeterminateProgressBarYOffset;
622 int progressBarY = self.view.bounds.size.height - progressBarYOffset; 618 int progressBarY = self.view.bounds.size.height - progressBarYOffset;
623 CGRect progressBarFrame = 619 CGRect progressBarFrame =
624 CGRectMake(0, progressBarY, progressWidth, progressHeight); 620 CGRectMake(0, progressBarY, progressWidth, progressHeight);
625 [_determinateProgressView setFrame:progressBarFrame]; 621 [_determinateProgressView setFrame:progressBarFrame];
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 - (void)browserStateDestroyed { 665 - (void)browserStateDestroyed {
670 // The location bar has a browser state reference, so must be destroyed at 666 // The location bar has a browser state reference, so must be destroyed at
671 // this point. 667 // this point.
672 _locationBar.reset(); 668 _locationBar.reset();
673 _browserState = nullptr; 669 _browserState = nullptr;
674 } 670 }
675 671
676 - (void)dealloc { 672 - (void)dealloc {
677 [[NSNotificationCenter defaultCenter] removeObserver:self]; 673 [[NSNotificationCenter defaultCenter] removeObserver:self];
678 [_tabHistoryPopupController setDelegate:nil]; 674 [_tabHistoryPopupController setDelegate:nil];
675 [super dealloc];
679 } 676 }
680 677
681 #pragma mark - 678 #pragma mark -
682 #pragma mark Public methods. 679 #pragma mark Public methods.
683 680
684 - (void)updateToolbarState { 681 - (void)updateToolbarState {
685 ToolbarModelIOS* toolbarModelIOS = [self.delegate toolbarModelIOS]; 682 ToolbarModelIOS* toolbarModelIOS = [self.delegate toolbarModelIOS];
686 if (toolbarModelIOS->IsLoading()) { 683 if (toolbarModelIOS->IsLoading()) {
687 [self showStopButton]; 684 [self showStopButton];
688 [self startProgressBar]; 685 [self startProgressBar];
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 [_backButton setHidden:NO]; 739 [_backButton setHidden:NO];
743 [_forwardButton setHidden:NO]; 740 [_forwardButton setHidden:NO];
744 [_omniboxBackground setHidden:NO]; 741 [_omniboxBackground setHidden:NO];
745 [self.backgroundView setAlpha:1]; 742 [self.backgroundView setAlpha:1];
746 [self hideViewsForNewTabPage:NO]; 743 [self hideViewsForNewTabPage:NO];
747 [self updateToolbarState]; 744 [self updateToolbarState];
748 } 745 }
749 746
750 - (void)showPrerenderingAnimation { 747 - (void)showPrerenderingAnimation {
751 _prerenderAnimating = YES; 748 _prerenderAnimating = YES;
752 __weak MDCProgressView* weakDeterminateProgressView =
753 _determinateProgressView;
754 [_determinateProgressView setProgress:0]; 749 [_determinateProgressView setProgress:0];
755 [_determinateProgressView setHidden:NO 750 [_determinateProgressView setHidden:NO
756 animated:YES 751 animated:YES
757 completion:^(BOOL finished) { 752 completion:^(BOOL finished) {
758 [weakDeterminateProgressView 753 [_determinateProgressView
759 setProgress:1 754 setProgress:1
760 animated:YES 755 animated:YES
761 completion:^(BOOL finished) { 756 completion:^(BOOL finished) {
762 [weakDeterminateProgressView setHidden:YES 757 [_determinateProgressView setHidden:YES
763 animated:YES 758 animated:YES
764 completion:nil]; 759 completion:nil];
765 }]; 760 }];
766 }]; 761 }];
767 } 762 }
768 763
769 - (void)setControlsHidden:(BOOL)hidden { 764 - (void)setControlsHidden:(BOOL)hidden {
770 [self setStandardControlsVisible:!hidden]; 765 [self setStandardControlsVisible:!hidden];
771 [_webToolbar setHidden:hidden]; 766 [_webToolbar setHidden:hidden];
772 } 767 }
773 768
774 - (void)setControlsAlpha:(CGFloat)alpha { 769 - (void)setControlsAlpha:(CGFloat)alpha {
775 [self setStandardControlsAlpha:alpha]; 770 [self setStandardControlsAlpha:alpha];
776 [_webToolbar setAlpha:alpha]; 771 [_webToolbar setAlpha:alpha];
777 } 772 }
778 773
779 - (void)currentPageLoadStarted { 774 - (void)currentPageLoadStarted {
780 [self startProgressBar]; 775 [self startProgressBar];
781 } 776 }
782 777
783 - (void)selectedTabChanged { 778 - (void)selectedTabChanged {
784 [self cancelOmniboxEdit]; 779 [self cancelOmniboxEdit];
785 } 780 }
786 781
787 - (CGRect)bookmarkButtonAnchorRect { 782 - (CGRect)bookmarkButtonAnchorRect {
788 // Shrink the padding around the bookmark button so the popovers are anchored 783 // Shrink the padding around the bookmark button so the popovers are anchored
789 // correctly. 784 // correctly.
790 return CGRectInset([_starButton bounds], 6, 11); 785 return CGRectInset([_starButton bounds], 6, 11);
791 } 786 }
792 787
793 - (UIView*)bookmarkButtonView { 788 - (UIView*)bookmarkButtonView {
794 return _starButton; 789 return _starButton.get();
795 } 790 }
796 791
797 - (CGRect)visibleOmniboxFrame { 792 - (CGRect)visibleOmniboxFrame {
798 CGRect frame = _omniboxBackground.frame; 793 CGRect frame = _omniboxBackground.get().frame;
799 frame = [self.view.superview convertRect:frame 794 frame = [self.view.superview convertRect:frame
800 fromView:[_omniboxBackground superview]]; 795 fromView:[_omniboxBackground superview]];
801 // Account for the omnibox background image transparent sides. 796 // Account for the omnibox background image transparent sides.
802 return CGRectInset(frame, -kBackgroundImageVisibleRectOffset, 0); 797 return CGRectInset(frame, -kBackgroundImageVisibleRectOffset, 0);
803 } 798 }
804 799
805 - (UIImage*)snapshotWithWidth:(CGFloat)width { 800 - (UIImage*)snapshotWithWidth:(CGFloat)width {
806 if (IsIPadIdiom()) 801 if (IsIPadIdiom())
807 return nil; 802 return nil;
808 // Below call will be no-op if cached snapshot is valid. 803 // Below call will be no-op if cached snapshot is valid.
809 [self updateSnapshotWithWidth:width forced:YES]; 804 [self updateSnapshotWithWidth:width forced:YES];
810 return _snapshot; 805 return [[_snapshot retain] autorelease];
811 } 806 }
812 807
813 - (void)showTabHistoryPopupInView:(UIView*)view 808 - (void)showTabHistoryPopupInView:(UIView*)view
814 withItems:(const web::NavigationItemList&)items 809 withItems:(const web::NavigationItemList&)items
815 forBackHistory:(BOOL)isBackHistory { 810 forBackHistory:(BOOL)isBackHistory {
816 if (_tabHistoryPopupController) 811 if (_tabHistoryPopupController)
817 return; 812 return;
818 813
819 base::RecordAction(UserMetricsAction("MobileToolbarShowTabHistoryMenu")); 814 base::RecordAction(UserMetricsAction("MobileToolbarShowTabHistoryMenu"));
820 815
821 UIButton* historyButton = isBackHistory ? _backButton : _forwardButton; 816 UIButton* historyButton = isBackHistory ? _backButton : _forwardButton;
822 // Keep the button pressed by swapping the normal and highlighted images. 817 // Keep the button pressed by swapping the normal and highlighted images.
823 [self setImagesForNavButton:historyButton withTabHistoryVisible:YES]; 818 [self setImagesForNavButton:historyButton withTabHistoryVisible:YES];
824 819
825 // Set the origin for the tools popup to the leading side of the bottom of the 820 // Set the origin for the tools popup to the leading side of the bottom of the
826 // pressed buttons. 821 // pressed buttons.
827 CGRect buttonBounds = [historyButton.imageView bounds]; 822 CGRect buttonBounds = [historyButton.imageView bounds];
828 CGPoint origin = CGPointMake(CGRectGetLeadingEdge(buttonBounds), 823 CGPoint origin = CGPointMake(CGRectGetLeadingEdge(buttonBounds),
829 CGRectGetMaxY(buttonBounds)); 824 CGRectGetMaxY(buttonBounds));
830 CGPoint convertedOrigin = 825 CGPoint convertedOrigin =
831 [view convertPoint:origin fromView:historyButton.imageView]; 826 [view convertPoint:origin fromView:historyButton.imageView];
832 _tabHistoryPopupController = 827 _tabHistoryPopupController.reset([[TabHistoryPopupController alloc]
833 [[TabHistoryPopupController alloc] initWithOrigin:convertedOrigin 828 initWithOrigin:convertedOrigin
834 parentView:view 829 parentView:view
835 items:items]; 830 items:items]);
836 [_tabHistoryPopupController setDelegate:self]; 831 [_tabHistoryPopupController setDelegate:self];
837 832
838 // Fade in the popup and notify observers. 833 // Fade in the popup and notify observers.
839 CGRect containerFrame = [[_tabHistoryPopupController popupContainer] frame]; 834 CGRect containerFrame = [[_tabHistoryPopupController popupContainer] frame];
840 CGPoint destination = CGPointMake(CGRectGetLeadingEdge(containerFrame), 835 CGPoint destination = CGPointMake(CGRectGetLeadingEdge(containerFrame),
841 CGRectGetMinY(containerFrame)); 836 CGRectGetMinY(containerFrame));
842 [_tabHistoryPopupController fadeInPopupFromSource:convertedOrigin 837 [_tabHistoryPopupController fadeInPopupFromSource:convertedOrigin
843 toDestination:destination]; 838 toDestination:destination];
844 [[NSNotificationCenter defaultCenter] 839 [[NSNotificationCenter defaultCenter]
845 postNotificationName:kTabHistoryPopupWillShowNotification 840 postNotificationName:kTabHistoryPopupWillShowNotification
846 object:nil]; 841 object:nil];
847 } 842 }
848 843
849 - (void)dismissTabHistoryPopup { 844 - (void)dismissTabHistoryPopup {
850 if (!_tabHistoryPopupController) 845 if (!_tabHistoryPopupController)
851 return; 846 return;
852 TabHistoryPopupController* tempTHPC = _tabHistoryPopupController; 847 TabHistoryPopupController* tempTHPC = _tabHistoryPopupController.get();
853 [tempTHPC containerView].userInteractionEnabled = NO; 848 [tempTHPC containerView].userInteractionEnabled = NO;
854 [tempTHPC dismissAnimatedWithCompletion:^{ 849 [tempTHPC dismissAnimatedWithCompletion:^{
855 // Unpress the back/forward button by restoring the normal and 850 // Unpress the back/forward button by restoring the normal and
856 // highlighted images to their usual state. 851 // highlighted images to their usual state.
857 [self setImagesForNavButton:_backButton withTabHistoryVisible:NO]; 852 [self setImagesForNavButton:_backButton withTabHistoryVisible:NO];
858 [self setImagesForNavButton:_forwardButton withTabHistoryVisible:NO]; 853 [self setImagesForNavButton:_forwardButton withTabHistoryVisible:NO];
859 // Reference tempTHPC so the block retains it. 854 // Reference tempTHPC so the block retains it.
860 [tempTHPC self]; 855 [tempTHPC self];
861 }]; 856 }];
862 // reset _tabHistoryPopupController to prevent -applicationDidEnterBackground 857 // reset _tabHistoryPopupController to prevent -applicationDidEnterBackground
863 // from posting another kTabHistoryPopupWillHideNotification. 858 // from posting another kTabHistoryPopupWillHideNotification.
864 _tabHistoryPopupController = nil; 859 _tabHistoryPopupController.reset();
865 860
866 [[NSNotificationCenter defaultCenter] 861 [[NSNotificationCenter defaultCenter]
867 postNotificationName:kTabHistoryPopupWillHideNotification 862 postNotificationName:kTabHistoryPopupWillHideNotification
868 object:nil]; 863 object:nil];
869 } 864 }
870 865
871 - (BOOL)isOmniboxFirstResponder { 866 - (BOOL)isOmniboxFirstResponder {
872 return [_omniBox isFirstResponder]; 867 return [_omniBox isFirstResponder];
873 } 868 }
874 869
875 - (BOOL)showingOmniboxPopup { 870 - (BOOL)showingOmniboxPopup {
876 OmniboxViewIOS* omniboxViewIOS = 871 OmniboxViewIOS* omniboxViewIOS =
877 static_cast<OmniboxViewIOS*>(_locationBar.get()->GetLocationEntry()); 872 static_cast<OmniboxViewIOS*>(_locationBar.get()->GetLocationEntry());
878 return omniboxViewIOS->IsPopupOpen(); 873 return omniboxViewIOS->IsPopupOpen();
879 } 874 }
880 875
881 - (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection { 876 - (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection {
882 [super traitCollectionDidChange:previousTraitCollection]; 877 [super traitCollectionDidChange:previousTraitCollection];
883 _lastKnownTraitCollection = [UITraitCollection 878 _lastKnownTraitCollection.reset([[UITraitCollection
884 traitCollectionWithTraitsFromCollections:@[ self.view.traitCollection ]]; 879 traitCollectionWithTraitsFromCollections:@[ self.view.traitCollection ]]
880 retain]);
885 if (IsIPadIdiom()) { 881 if (IsIPadIdiom()) {
886 // Update toolbar accessory views. 882 // Update toolbar accessory views.
887 BOOL isCompactTabletView = IsCompactTablet(self.view); 883 BOOL isCompactTabletView = IsCompactTablet(self.view);
888 [_voiceSearchButton setHidden:isCompactTabletView]; 884 [_voiceSearchButton setHidden:isCompactTabletView];
889 [_starButton setHidden:isCompactTabletView]; 885 [_starButton setHidden:isCompactTabletView];
890 [_reloadButton setHidden:isCompactTabletView]; 886 [_reloadButton setHidden:isCompactTabletView];
891 [_stopButton setHidden:isCompactTabletView]; 887 [_stopButton setHidden:isCompactTabletView];
892 [self updateToolbarState]; 888 [self updateToolbarState];
893 889
894 // Update keyboard accessory views. 890 // Update keyboard accessory views.
895 BOOL hidden = [_keyboardVoiceSearchButton isHidden]; 891 BOOL hidden = [_keyboardVoiceSearchButton isHidden];
896 _keyBoardAccessoryView = nil; 892 _keyBoardAccessoryView.reset();
897 [_omniBox setInputAccessoryView:[self keyboardAccessoryView]]; 893 [_omniBox setInputAccessoryView:[self keyboardAccessoryView]];
898 [_keyboardVoiceSearchButton setHidden:hidden]; 894 [_keyboardVoiceSearchButton setHidden:hidden];
899 if ([_omniBox isFirstResponder]) { 895 if ([_omniBox isFirstResponder]) {
900 [_omniBox reloadInputViews]; 896 [_omniBox reloadInputViews];
901 } 897 }
902 898
903 // Re-layout toolbar and omnibox. 899 // Re-layout toolbar and omnibox.
904 [_webToolbar setFrame:[self specificControlsArea]]; 900 [_webToolbar setFrame:[self specificControlsArea]];
905 [self layoutOmnibox]; 901 [self layoutOmnibox];
906 } 902 }
907 } 903 }
908 904
909 #pragma mark - 905 #pragma mark -
910 #pragma mark Overridden superclass methods. 906 #pragma mark Overridden superclass methods.
911 907
912 - (void)applicationDidEnterBackground:(NSNotification*)notify { 908 - (void)applicationDidEnterBackground:(NSNotification*)notify {
913 if (_tabHistoryPopupController) { 909 if (_tabHistoryPopupController) {
914 // Dismiss the tab history popup without animation. 910 // Dismiss the tab history popup without animation.
915 [self setImagesForNavButton:_backButton withTabHistoryVisible:NO]; 911 [self setImagesForNavButton:_backButton withTabHistoryVisible:NO];
916 [self setImagesForNavButton:_forwardButton withTabHistoryVisible:NO]; 912 [self setImagesForNavButton:_forwardButton withTabHistoryVisible:NO];
917 _tabHistoryPopupController = nil; 913 _tabHistoryPopupController.reset(nil);
918 [[NSNotificationCenter defaultCenter] 914 [[NSNotificationCenter defaultCenter]
919 postNotificationName:kTabHistoryPopupWillHideNotification 915 postNotificationName:kTabHistoryPopupWillHideNotification
920 object:nil]; 916 object:nil];
921 } 917 }
922 [super applicationDidEnterBackground:notify]; 918 [super applicationDidEnterBackground:notify];
923 } 919 }
924 920
925 - (void)setUpButton:(UIButton*)button 921 - (void)setUpButton:(UIButton*)button
926 withImageEnum:(int)imageEnum 922 withImageEnum:(int)imageEnum
927 forInitialState:(UIControlState)initialState 923 forInitialState:(UIControlState)initialState
928 hasDisabledImage:(BOOL)hasDisabledImage 924 hasDisabledImage:(BOOL)hasDisabledImage
929 synchronously:(BOOL)synchronously { 925 synchronously:(BOOL)synchronously {
930 [super setUpButton:button 926 [super setUpButton:button
931 withImageEnum:imageEnum 927 withImageEnum:imageEnum
932 forInitialState:initialState 928 forInitialState:initialState
933 hasDisabledImage:hasDisabledImage 929 hasDisabledImage:hasDisabledImage
934 synchronously:synchronously]; 930 synchronously:synchronously];
935 931
936 if (button != _starButton) 932 if (button != _starButton.get())
937 return; 933 return;
938 // The star button behaves slightly differently. It uses the pressed 934 // The star button behaves slightly differently. It uses the pressed
939 // image for its selected state as well as its pressed state. 935 // image for its selected state as well as its pressed state.
940 void (^starBlock)(void) = ^{ 936 void (^starBlock)(void) = ^{
941 UIImage* starImage = [self imageForImageEnum:WebToolbarButtonNameStar 937 UIImage* starImage = [self imageForImageEnum:WebToolbarButtonNameStar
942 forState:ToolbarButtonUIStatePressed]; 938 forState:ToolbarButtonUIStatePressed];
943 [_starButton setAdjustsImageWhenHighlighted:NO]; 939 [_starButton setAdjustsImageWhenHighlighted:NO];
944 [_starButton setImage:starImage forState:UIControlStateSelected]; 940 [_starButton setImage:starImage forState:UIControlStateSelected];
945 }; 941 };
946 if (synchronously) { 942 if (synchronously) {
947 starBlock(); 943 starBlock();
948 } else { 944 } else {
949 dispatch_time_t addImageDelay = 945 dispatch_time_t addImageDelay =
950 dispatch_time(DISPATCH_TIME_NOW, kNonInitialImageAdditionDelayNanosec); 946 dispatch_time(DISPATCH_TIME_NOW, kNonInitialImageAdditionDelayNanosec);
951 dispatch_after(addImageDelay, dispatch_get_main_queue(), starBlock); 947 dispatch_after(addImageDelay, dispatch_get_main_queue(), starBlock);
952 } 948 }
953 } 949 }
954 950
955 - (void)standardButtonPressed:(UIButton*)sender { 951 - (void)standardButtonPressed:(UIButton*)sender {
956 [super standardButtonPressed:sender]; 952 [super standardButtonPressed:sender];
957 [self cancelOmniboxEdit]; 953 [self cancelOmniboxEdit];
958 } 954 }
959 955
960 - (IBAction)recordUserMetrics:(id)sender { 956 - (IBAction)recordUserMetrics:(id)sender {
961 if (sender == _backButton) { 957 if (sender == _backButton.get()) {
962 base::RecordAction(UserMetricsAction("MobileToolbarBack")); 958 base::RecordAction(UserMetricsAction("MobileToolbarBack"));
963 } else if (sender == _forwardButton) { 959 } else if (sender == _forwardButton.get()) {
964 base::RecordAction(UserMetricsAction("MobileToolbarForward")); 960 base::RecordAction(UserMetricsAction("MobileToolbarForward"));
965 } else if (sender == _reloadButton) { 961 } else if (sender == _reloadButton.get()) {
966 base::RecordAction(UserMetricsAction("MobileToolbarReload")); 962 base::RecordAction(UserMetricsAction("MobileToolbarReload"));
967 } else if (sender == _stopButton) { 963 } else if (sender == _stopButton.get()) {
968 base::RecordAction(UserMetricsAction("MobileToolbarStop")); 964 base::RecordAction(UserMetricsAction("MobileToolbarStop"));
969 } else if (sender == _voiceSearchButton) { 965 } else if (sender == _voiceSearchButton.get()) {
970 base::RecordAction(UserMetricsAction("MobileToolbarVoiceSearch")); 966 base::RecordAction(UserMetricsAction("MobileToolbarVoiceSearch"));
971 } else if (sender == _keyboardVoiceSearchButton) { 967 } else if (sender == _keyboardVoiceSearchButton.get()) {
972 base::RecordAction(UserMetricsAction("MobileCustomRowVoiceSearch")); 968 base::RecordAction(UserMetricsAction("MobileCustomRowVoiceSearch"));
973 } else if (sender == _starButton) { 969 } else if (sender == _starButton.get()) {
974 base::RecordAction(UserMetricsAction("MobileToolbarToggleBookmark")); 970 base::RecordAction(UserMetricsAction("MobileToolbarToggleBookmark"));
975 } else { 971 } else {
976 [super recordUserMetrics:sender]; 972 [super recordUserMetrics:sender];
977 } 973 }
978 } 974 }
979 975
980 - (IBAction)stackButtonTouchDown:(id)sender { 976 - (IBAction)stackButtonTouchDown:(id)sender {
981 [self.delegate prepareToEnterTabSwitcher:self]; 977 [self.delegate prepareToEnterTabSwitcher:self];
982 } 978 }
983 979
984 - (BOOL)imageShouldFlipForRightToLeftLayoutDirection:(int)imageEnum { 980 - (BOOL)imageShouldFlipForRightToLeftLayoutDirection:(int)imageEnum {
985 DCHECK(imageEnum < NumberOfWebToolbarButtonNames); 981 DCHECK(imageEnum < NumberOfWebToolbarButtonNames);
986 if (imageEnum < NumberOfToolbarButtonNames) 982 if (imageEnum < NumberOfToolbarButtonNames)
987 return [super imageShouldFlipForRightToLeftLayoutDirection:imageEnum]; 983 return [super imageShouldFlipForRightToLeftLayoutDirection:imageEnum];
988 if (imageEnum == WebToolbarButtonNameBack || 984 if (imageEnum == WebToolbarButtonNameBack ||
989 imageEnum == WebToolbarButtonNameForward || 985 imageEnum == WebToolbarButtonNameForward ||
990 imageEnum == WebToolbarButtonNameReload || 986 imageEnum == WebToolbarButtonNameReload ||
991 imageEnum == WebToolbarButtonNameCallingApp) { 987 imageEnum == WebToolbarButtonNameCallingApp) {
992 return YES; 988 return YES;
993 } 989 }
994 return NO; 990 return NO;
995 } 991 }
996 992
997 - (int)imageEnumForButton:(UIButton*)button { 993 - (int)imageEnumForButton:(UIButton*)button {
998 if (button == _voiceSearchButton) 994 if (button == _voiceSearchButton.get())
999 return _isTTSPlaying ? WebToolbarButtonNameTTS : WebToolbarButtonNameVoice; 995 return _isTTSPlaying ? WebToolbarButtonNameTTS : WebToolbarButtonNameVoice;
1000 if (button == _starButton) 996 if (button == _starButton.get())
1001 return WebToolbarButtonNameStar; 997 return WebToolbarButtonNameStar;
1002 if (button == _stopButton) 998 if (button == _stopButton.get())
1003 return WebToolbarButtonNameStop; 999 return WebToolbarButtonNameStop;
1004 if (button == _reloadButton) 1000 if (button == _reloadButton.get())
1005 return WebToolbarButtonNameReload; 1001 return WebToolbarButtonNameReload;
1006 if (button == _backButton) 1002 if (button == _backButton.get())
1007 return WebToolbarButtonNameBack; 1003 return WebToolbarButtonNameBack;
1008 if (button == _forwardButton) 1004 if (button == _forwardButton.get())
1009 return WebToolbarButtonNameForward; 1005 return WebToolbarButtonNameForward;
1010 return [super imageEnumForButton:button]; 1006 return [super imageEnumForButton:button];
1011 } 1007 }
1012 1008
1013 - (int)imageIdForImageEnum:(int)index 1009 - (int)imageIdForImageEnum:(int)index
1014 style:(ToolbarControllerStyle)style 1010 style:(ToolbarControllerStyle)style
1015 forState:(ToolbarButtonUIState)state { 1011 forState:(ToolbarButtonUIState)state {
1016 DCHECK(style < ToolbarControllerStyleMaxStyles); 1012 DCHECK(style < ToolbarControllerStyleMaxStyles);
1017 DCHECK(state < NumberOfToolbarButtonUIStates); 1013 DCHECK(state < NumberOfToolbarButtonUIStates);
1018 // Additional checking. These three buttons should only ever be used on iPad. 1014 // Additional checking. These three buttons should only ever be used on iPad.
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 } 1303 }
1308 1304
1309 - (void)locationBarBeganEdit { 1305 - (void)locationBarBeganEdit {
1310 [self.delegate locationBarBeganEdit:self]; 1306 [self.delegate locationBarBeganEdit:self];
1311 } 1307 }
1312 1308
1313 - (void)locationBarChanged { 1309 - (void)locationBarChanged {
1314 // Hide the voice search button once the user starts editing the omnibox but 1310 // Hide the voice search button once the user starts editing the omnibox but
1315 // show it if the omnibox is empty. 1311 // show it if the omnibox is empty.
1316 bool isEditingOrEmpty = _locationBar->GetLocationEntry()->IsEditingOrEmpty(); 1312 bool isEditingOrEmpty = _locationBar->GetLocationEntry()->IsEditingOrEmpty();
1317 BOOL editingAndNotEmpty = isEditingOrEmpty && _omniBox.text.length != 0; 1313 BOOL editingAndNotEmpty = isEditingOrEmpty && _omniBox.get().text.length != 0;
1318 // If the voice search button is visible but about to be hidden (i.e. 1314 // If the voice search button is visible but about to be hidden (i.e.
1319 // the omnibox is no longer empty) then this is the first omnibox text so 1315 // the omnibox is no longer empty) then this is the first omnibox text so
1320 // record a user action. 1316 // record a user action.
1321 if (![_keyboardVoiceSearchButton isHidden] && editingAndNotEmpty) { 1317 if (![_keyboardVoiceSearchButton isHidden] && editingAndNotEmpty) {
1322 base::RecordAction(UserMetricsAction("MobileFirstTextInOmnibox")); 1318 base::RecordAction(UserMetricsAction("MobileFirstTextInOmnibox"));
1323 } 1319 }
1324 [_keyboardVoiceSearchButton setHidden:editingAndNotEmpty]; 1320 [_keyboardVoiceSearchButton setHidden:editingAndNotEmpty];
1325 } 1321 }
1326 1322
1327 - (web::WebState*)getWebState { 1323 - (web::WebState*)getWebState {
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1471 _omniBox); 1467 _omniBox);
1472 } 1468 }
1473 } 1469 }
1474 1470
1475 #pragma mark - 1471 #pragma mark -
1476 #pragma mark Private methods. 1472 #pragma mark Private methods.
1477 1473
1478 - (UIButton*)cancelButton { 1474 - (UIButton*)cancelButton {
1479 if (_cancelButton) 1475 if (_cancelButton)
1480 return _cancelButton; 1476 return _cancelButton;
1481 _cancelButton = [UIButton buttonWithType:UIButtonTypeCustom]; 1477 _cancelButton.reset([[UIButton buttonWithType:UIButtonTypeCustom] retain]);
1482 NSString* collapseName = _incognito ? @"collapse_incognito" : @"collapse"; 1478 NSString* collapseName = _incognito ? @"collapse_incognito" : @"collapse";
1483 [_cancelButton setImage:[UIImage imageNamed:collapseName] 1479 [_cancelButton setImage:[UIImage imageNamed:collapseName]
1484 forState:UIControlStateNormal]; 1480 forState:UIControlStateNormal];
1485 NSString* collapsePressedName = 1481 NSString* collapsePressedName =
1486 _incognito ? @"collapse_pressed_incognito" : @"collapse_pressed"; 1482 _incognito ? @"collapse_pressed_incognito" : @"collapse_pressed";
1487 [_cancelButton setImage:[UIImage imageNamed:collapsePressedName] 1483 [_cancelButton setImage:[UIImage imageNamed:collapsePressedName]
1488 forState:UIControlStateHighlighted]; 1484 forState:UIControlStateHighlighted];
1489 [_cancelButton setAccessibilityLabel:l10n_util::GetNSString(IDS_CANCEL)]; 1485 [_cancelButton setAccessibilityLabel:l10n_util::GetNSString(IDS_CANCEL)];
1490 [_cancelButton setAutoresizingMask:UIViewAutoresizingFlexibleLeadingMargin() | 1486 [_cancelButton setAutoresizingMask:UIViewAutoresizingFlexibleLeadingMargin() |
1491 UIViewAutoresizingFlexibleHeight]; 1487 UIViewAutoresizingFlexibleHeight];
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1627 [_determinateProgressView setHidden:NO animated:YES completion:nil]; 1623 [_determinateProgressView setHidden:NO animated:YES completion:nil];
1628 } 1624 }
1629 } 1625 }
1630 1626
1631 - (void)stopProgressBar { 1627 - (void)stopProgressBar {
1632 if (_determinateProgressView && ![_determinateProgressView isHidden]) { 1628 if (_determinateProgressView && ![_determinateProgressView isHidden]) {
1633 // Update the toolbar snapshot, but only after the progress bar has 1629 // Update the toolbar snapshot, but only after the progress bar has
1634 // disappeared. 1630 // disappeared.
1635 1631
1636 if (!_prerenderAnimating) { 1632 if (!_prerenderAnimating) {
1637 __weak MDCProgressView* weakDeterminateProgressView =
1638 _determinateProgressView;
1639 // Calling -completeAndHide while a prerender animation is in progress 1633 // Calling -completeAndHide while a prerender animation is in progress
1640 // will result in hiding the progress bar before the animation is 1634 // will result in hiding the progress bar before the animation is
1641 // complete. 1635 // complete.
1642 [_determinateProgressView setProgress:1 1636 [_determinateProgressView setProgress:1
1643 animated:YES 1637 animated:YES
1644 completion:^(BOOL finished) { 1638 completion:^(BOOL finished) {
1645 [weakDeterminateProgressView setHidden:YES 1639 [_determinateProgressView setHidden:YES
1646 animated:YES 1640 animated:YES
1647 completion:nil]; 1641 completion:nil];
1648 }]; 1642 }];
1649 } 1643 }
1650 CGFloat delay = _unitTesting ? 0 : kLoadCompleteHideProgressBarDelay; 1644 CGFloat delay = _unitTesting ? 0 : kLoadCompleteHideProgressBarDelay;
1651 [self performSelector:@selector(hideProgressBarAndTakeSnapshot) 1645 [self performSelector:@selector(hideProgressBarAndTakeSnapshot)
1652 withObject:nil 1646 withObject:nil
1653 afterDelay:delay]; 1647 afterDelay:delay];
1654 } 1648 }
1655 } 1649 }
1656 1650
1657 - (void)hideProgressBarAndTakeSnapshot { 1651 - (void)hideProgressBarAndTakeSnapshot {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1702 // Size changes matter. 1696 // Size changes matter.
1703 hash ^= static_cast<uint32_t>(width) << 15; 1697 hash ^= static_cast<uint32_t>(width) << 15;
1704 hash ^= static_cast<uint32_t>([self view].frame.size.height) << 23; 1698 hash ^= static_cast<uint32_t>([self view].frame.size.height) << 23;
1705 return hash; 1699 return hash;
1706 } 1700 }
1707 1701
1708 - (void)handleLongPress:(UILongPressGestureRecognizer*)gesture { 1702 - (void)handleLongPress:(UILongPressGestureRecognizer*)gesture {
1709 if (gesture.state != UIGestureRecognizerStateBegan) 1703 if (gesture.state != UIGestureRecognizerStateBegan)
1710 return; 1704 return;
1711 1705
1712 if (gesture.view == _backButton) { 1706 if (gesture.view == _backButton.get()) {
1713 GenericChromeCommand* command = 1707 base::scoped_nsobject<GenericChromeCommand> command(
1714 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_BACK_HISTORY]; 1708 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_BACK_HISTORY]);
1715 [_backButton chromeExecuteCommand:command]; 1709 [_backButton chromeExecuteCommand:command];
1716 } else if (gesture.view == _forwardButton) { 1710 } else if (gesture.view == _forwardButton.get()) {
1717 GenericChromeCommand* command = 1711 base::scoped_nsobject<GenericChromeCommand> command(
1718 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_FORWARD_HISTORY]; 1712 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_FORWARD_HISTORY]);
1719 [_forwardButton chromeExecuteCommand:command]; 1713 [_forwardButton chromeExecuteCommand:command];
1720 } 1714 }
1721 } 1715 }
1722 1716
1723 - (void)setImagesForNavButton:(UIButton*)button 1717 - (void)setImagesForNavButton:(UIButton*)button
1724 withTabHistoryVisible:(BOOL)tabHistoryVisible { 1718 withTabHistoryVisible:(BOOL)tabHistoryVisible {
1725 BOOL isBackButton = button == _backButton; 1719 BOOL isBackButton = button == _backButton;
1726 ToolbarButtonMode newMode = 1720 ToolbarButtonMode newMode =
1727 tabHistoryVisible ? ToolbarButtonModeReversed : ToolbarButtonModeNormal; 1721 tabHistoryVisible ? ToolbarButtonModeReversed : ToolbarButtonModeNormal;
1728 if (isBackButton && newMode == _backButtonMode) 1722 if (isBackButton && newMode == _backButtonMode)
1729 return; 1723 return;
1730 if (!isBackButton && newMode == _forwardButtonMode) 1724 if (!isBackButton && newMode == _forwardButtonMode)
1731 return; 1725 return;
1732 1726
1733 UIImage* normalImage = [button imageForState:UIControlStateNormal]; 1727 base::scoped_nsobject<UIImage> normalImage(
1734 UIImage* highlightedImage = [button imageForState:UIControlStateHighlighted]; 1728 [[button imageForState:UIControlStateNormal] retain]);
1729 base::scoped_nsobject<UIImage> highlightedImage(
1730 [[button imageForState:UIControlStateHighlighted] retain]);
1735 [button setImage:highlightedImage forState:UIControlStateNormal]; 1731 [button setImage:highlightedImage forState:UIControlStateNormal];
1736 [button setImage:normalImage forState:UIControlStateHighlighted]; 1732 [button setImage:normalImage forState:UIControlStateHighlighted];
1737 if (isBackButton) 1733 if (isBackButton)
1738 _backButtonMode = newMode; 1734 _backButtonMode = newMode;
1739 else 1735 else
1740 _forwardButtonMode = newMode; 1736 _forwardButtonMode = newMode;
1741 } 1737 }
1742 1738
1743 - (void)audioReadyForPlayback:(NSNotification*)notification { 1739 - (void)audioReadyForPlayback:(NSNotification*)notification {
1744 if (![_voiceSearchButton isHidden]) { 1740 if (![_voiceSearchButton isHidden]) {
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1867 if (_keyBoardAccessoryView) 1863 if (_keyBoardAccessoryView)
1868 return _keyBoardAccessoryView; 1864 return _keyBoardAccessoryView;
1869 1865
1870 const BOOL isTablet = IsIPadIdiom() && !IsCompactTablet(self.view); 1866 const BOOL isTablet = IsIPadIdiom() && !IsCompactTablet(self.view);
1871 1867
1872 // TODO(pinkerton): purge this view when low memory. 1868 // TODO(pinkerton): purge this view when low memory.
1873 CGFloat width = [[UIScreen mainScreen] bounds].size.width; 1869 CGFloat width = [[UIScreen mainScreen] bounds].size.width;
1874 CGFloat height = isTablet ? kViewHeightTablet : kViewHeightPhone; 1870 CGFloat height = isTablet ? kViewHeightTablet : kViewHeightPhone;
1875 CGRect frame = CGRectMake(0.0, 0.0, width, height); 1871 CGRect frame = CGRectMake(0.0, 0.0, width, height);
1876 1872
1877 _keyBoardAccessoryView = 1873 _keyBoardAccessoryView.reset([[KeyboardAccessoryView alloc]
1878 [[KeyboardAccessoryView alloc] initWithFrame:frame 1874 initWithFrame:frame
1879 inputViewStyle:UIInputViewStyleKeyboard]; 1875 inputViewStyle:UIInputViewStyleKeyboard]);
1880 [_keyBoardAccessoryView setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; 1876 [_keyBoardAccessoryView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
1881 1877
1882 NSArray* buttonTitles = 1878 NSArray* buttonTitles =
1883 [NSArray arrayWithObjects:@":", @".", @"-", @"/", kDotComTLD, nil]; 1879 [NSArray arrayWithObjects:@":", @".", @"-", @"/", kDotComTLD, nil];
1884 1880
1885 // Center buttons in available space by placing them within a parent view 1881 // Center buttons in available space by placing them within a parent view
1886 // that auto-centers. 1882 // that auto-centers.
1887 CGFloat betweenButtonSpacing = 1883 CGFloat betweenButtonSpacing =
1888 isTablet ? kBetweenButtonSpacing : kBetweenButtonSpacingPhone; 1884 isTablet ? kBetweenButtonSpacing : kBetweenButtonSpacingPhone;
1889 const CGFloat buttonWidth = isTablet ? kButtonSizeXTablet : kButtonSizeXPhone; 1885 const CGFloat buttonWidth = isTablet ? kButtonSizeXTablet : kButtonSizeXPhone;
1890 1886
1891 CGFloat totalWidth = (buttonTitles.count * buttonWidth) + 1887 CGFloat totalWidth = (buttonTitles.count * buttonWidth) +
1892 ((buttonTitles.count - 1) * betweenButtonSpacing); 1888 ((buttonTitles.count - 1) * betweenButtonSpacing);
1893 CGFloat indent = floor((width - totalWidth) / 2.0); 1889 CGFloat indent = floor((width - totalWidth) / 2.0);
1894 if (indent < kButtonInset) 1890 if (indent < kButtonInset)
1895 indent = kButtonInset; 1891 indent = kButtonInset;
1896 CGRect parentViewRect = CGRectMake(indent, 0.0, totalWidth, height); 1892 CGRect parentViewRect = CGRectMake(indent, 0.0, totalWidth, height);
1897 UIView* parentView = [[UIView alloc] initWithFrame:parentViewRect]; 1893 base::scoped_nsobject<UIView> parentView(
1894 [[UIView alloc] initWithFrame:parentViewRect]);
1898 [parentView setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | 1895 [parentView setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin |
1899 UIViewAutoresizingFlexibleRightMargin]; 1896 UIViewAutoresizingFlexibleRightMargin];
1900 [_keyBoardAccessoryView addSubview:parentView]; 1897 [_keyBoardAccessoryView addSubview:parentView];
1901 1898
1902 // Create the buttons, starting at the left edge of |parentView|. 1899 // Create the buttons, starting at the left edge of |parentView|.
1903 CGRect currentFrame = 1900 CGRect currentFrame =
1904 CGRectMake(0.0, kButtonInset, buttonWidth, 1901 CGRectMake(0.0, kButtonInset, buttonWidth,
1905 isTablet ? kButtonSizeYTablet : kButtonSizeYPhone); 1902 isTablet ? kButtonSizeYTablet : kButtonSizeYPhone);
1906 1903
1907 for (NSString* title in buttonTitles) { 1904 for (NSString* title in buttonTitles) {
1908 UIView* button = [self keyboardButtonWithTitle:title frame:currentFrame]; 1905 UIView* button = [self keyboardButtonWithTitle:title frame:currentFrame];
1909 [parentView addSubview:button]; 1906 [parentView addSubview:button];
1910 currentFrame.origin.x = CGRectGetMaxX(currentFrame) + betweenButtonSpacing; 1907 currentFrame.origin.x = CGRectGetMaxX(currentFrame) + betweenButtonSpacing;
1911 } 1908 }
1912 1909
1913 // Create the voice search button and add it to _keyBoardAccessoryView over 1910 // Create the voice search button and add it to _keyBoardAccessoryView over
1914 // the text buttons. 1911 // the text buttons.
1915 _keyboardVoiceSearchButton = [UIButton buttonWithType:UIButtonTypeCustom]; 1912 _keyboardVoiceSearchButton.reset(
1913 [[UIButton buttonWithType:UIButtonTypeCustom] retain]);
1916 [_keyboardVoiceSearchButton 1914 [_keyboardVoiceSearchButton
1917 setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; 1915 setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
1918 [_keyboardVoiceSearchButton setTag:IDC_VOICE_SEARCH]; 1916 [_keyboardVoiceSearchButton setTag:IDC_VOICE_SEARCH];
1919 SetA11yLabelAndUiAutomationName(_keyboardVoiceSearchButton, 1917 SetA11yLabelAndUiAutomationName(_keyboardVoiceSearchButton,
1920 IDS_IOS_ACCNAME_VOICE_SEARCH, 1918 IDS_IOS_ACCNAME_VOICE_SEARCH,
1921 @"Voice Search"); 1919 @"Voice Search");
1922 // TODO(leng): Consider moving these icons into a pak file. 1920 // TODO(leng): Consider moving these icons into a pak file.
1923 UIImage* voiceRow = [UIImage imageNamed:@"custom_row_voice"]; 1921 UIImage* voiceRow = [UIImage imageNamed:@"custom_row_voice"];
1924 UIImage* voiceRowPressed = [UIImage imageNamed:@"custom_row_voice_pressed"]; 1922 UIImage* voiceRowPressed = [UIImage imageNamed:@"custom_row_voice_pressed"];
1925 [_keyboardVoiceSearchButton setBackgroundImage:voiceRow 1923 [_keyboardVoiceSearchButton setBackgroundImage:voiceRow
(...skipping 21 matching lines...) Expand all
1947 forControlEvents:UIControlEventTouchDown]; 1945 forControlEvents:UIControlEventTouchDown];
1948 } else { 1946 } else {
1949 [_keyboardVoiceSearchButton addTarget:self 1947 [_keyboardVoiceSearchButton addTarget:self
1950 action:@selector(ignoreVoiceSearch:) 1948 action:@selector(ignoreVoiceSearch:)
1951 forControlEvents:UIControlEventTouchUpInside]; 1949 forControlEvents:UIControlEventTouchUpInside];
1952 } 1950 }
1953 1951
1954 [_keyBoardAccessoryView addSubview:_keyboardVoiceSearchButton]; 1952 [_keyBoardAccessoryView addSubview:_keyboardVoiceSearchButton];
1955 1953
1956 // Reset the external keyboard watcher. 1954 // Reset the external keyboard watcher.
1957 _hardwareKeyboardWatcher = [[HardwareKeyboardWatcher alloc] 1955 _hardwareKeyboardWatcher.reset([[HardwareKeyboardWatcher alloc]
1958 initWithAccessoryView:_keyBoardAccessoryView]; 1956 initWithAccessoryView:_keyBoardAccessoryView]);
1959 1957
1960 return _keyBoardAccessoryView; 1958 return _keyBoardAccessoryView;
1961 } 1959 }
1962 1960
1963 - (void)preloadVoiceSearch:(id)sender { 1961 - (void)preloadVoiceSearch:(id)sender {
1964 DCHECK(ios::GetChromeBrowserProvider() 1962 DCHECK(ios::GetChromeBrowserProvider()
1965 ->GetVoiceSearchProvider() 1963 ->GetVoiceSearchProvider()
1966 ->IsVoiceSearchEnabled()); 1964 ->IsVoiceSearchEnabled());
1967 [sender removeTarget:self 1965 [sender removeTarget:self
1968 action:@selector(preloadVoiceSearch:) 1966 action:@selector(preloadVoiceSearch:)
1969 forControlEvents:UIControlEventTouchDown]; 1967 forControlEvents:UIControlEventTouchDown];
1970 1968
1971 // Use a GenericChromeCommand because |sender| already has a tag set for a 1969 // Use a GenericChromeCommand because |sender| already has a tag set for a
1972 // different command. 1970 // different command.
1973 GenericChromeCommand* command = 1971 base::scoped_nsobject<GenericChromeCommand> command(
1974 [[GenericChromeCommand alloc] initWithTag:IDC_PRELOAD_VOICE_SEARCH]; 1972 [[GenericChromeCommand alloc] initWithTag:IDC_PRELOAD_VOICE_SEARCH]);
1975 [sender chromeExecuteCommand:command]; 1973 [sender chromeExecuteCommand:command];
1976 } 1974 }
1977 1975
1978 // Called when the keyboard voice search button is tapped with voice search 1976 // Called when the keyboard voice search button is tapped with voice search
1979 // disabled. Hides the voice search button but takes no other action. 1977 // disabled. Hides the voice search button but takes no other action.
1980 - (void)ignoreVoiceSearch:(id)sender { 1978 - (void)ignoreVoiceSearch:(id)sender {
1981 [_keyboardVoiceSearchButton setHidden:YES]; 1979 [_keyboardVoiceSearchButton setHidden:YES];
1982 } 1980 }
1983 1981
1984 - (CGFloat)omniboxLeading { 1982 - (CGFloat)omniboxLeading {
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
2467 // If |width| is 0, the current view's width is acceptable. 2465 // If |width| is 0, the current view's width is acceptable.
2468 if (width < 1) 2466 if (width < 1)
2469 width = [self view].frame.size.width; 2467 width = [self view].frame.size.width;
2470 2468
2471 // Snapshot is not used on the iPad. 2469 // Snapshot is not used on the iPad.
2472 if (IsIPadIdiom()) { 2470 if (IsIPadIdiom()) {
2473 NOTREACHED(); 2471 NOTREACHED();
2474 return; 2472 return;
2475 } 2473 }
2476 // If the snapshot is valid, don't redraw. 2474 // If the snapshot is valid, don't redraw.
2477 if (_snapshot && _snapshotHash == [self snapshotHashWithWidth:width]) 2475 if (_snapshot.get() && _snapshotHash == [self snapshotHashWithWidth:width])
2478 return; 2476 return;
2479 2477
2480 // Don't update the snapshot while the progress bar is moving, or while the 2478 // Don't update the snapshot while the progress bar is moving, or while the
2481 // tools menu is open, unless |force| is true. 2479 // tools menu is open, unless |force| is true.
2482 BOOL shouldRedraw = force || ([self toolsPopupController] == nil && 2480 BOOL shouldRedraw = force || ([self toolsPopupController] == nil &&
2483 [_determinateProgressView isHidden]); 2481 [_determinateProgressView isHidden]);
2484 if (!shouldRedraw) 2482 if (!shouldRedraw)
2485 return; 2483 return;
2486 2484
2487 if ([[self delegate] 2485 if ([[self delegate]
2488 respondsToSelector:@selector(willUpdateToolbarSnapshot)]) { 2486 respondsToSelector:@selector(willUpdateToolbarSnapshot)]) {
2489 [[self delegate] willUpdateToolbarSnapshot]; 2487 [[self delegate] willUpdateToolbarSnapshot];
2490 } 2488 }
2491 2489
2492 // Temporarily resize the toolbar if necessary in order to match the desired 2490 // Temporarily resize the toolbar if necessary in order to match the desired
2493 // width. (Such a mismatch can occur if the device has been rotated while this 2491 // width. (Such a mismatch can occur if the device has been rotated while this
2494 // view was not visible, for example.) 2492 // view was not visible, for example.)
2495 CGRect frame = [self view].frame; 2493 CGRect frame = [self view].frame;
2496 CGFloat oldWidth = frame.size.width; 2494 CGFloat oldWidth = frame.size.width;
2497 frame.size.width = width; 2495 frame.size.width = width;
2498 [self view].frame = frame; 2496 [self view].frame = frame;
2499 2497
2500 UIGraphicsBeginImageContextWithOptions(frame.size, NO, 0.0); 2498 UIGraphicsBeginImageContextWithOptions(frame.size, NO, 0.0);
2501 [[self view].layer renderInContext:UIGraphicsGetCurrentContext()]; 2499 [[self view].layer renderInContext:UIGraphicsGetCurrentContext()];
2502 _snapshot = UIGraphicsGetImageFromCurrentImageContext(); 2500 _snapshot.reset([UIGraphicsGetImageFromCurrentImageContext() retain]);
2503 UIGraphicsEndImageContext(); 2501 UIGraphicsEndImageContext();
2504 2502
2505 // In the past, when the current tab was prerendered, taking a snapshot 2503 // In the past, when the current tab was prerendered, taking a snapshot
2506 // sometimes lead to layout of its UIWebView. As this may be the fist time 2504 // sometimes lead to layout of its UIWebView. As this may be the fist time
2507 // the UIWebViews was layed out, its scroll view was scrolled. This lead 2505 // the UIWebViews was layed out, its scroll view was scrolled. This lead
2508 // to scroll events that changed the frame of the toolbar when fullscreen 2506 // to scroll events that changed the frame of the toolbar when fullscreen
2509 // was enabled. 2507 // was enabled.
2510 // DCHECK that the toolbar frame does not change while taking a snapshot. 2508 // DCHECK that the toolbar frame does not change while taking a snapshot.
2511 DCHECK_EQ(frame.origin.x, [self view].frame.origin.x); 2509 DCHECK_EQ(frame.origin.x, [self view].frame.origin.x);
2512 DCHECK_EQ(frame.origin.y, [self view].frame.origin.y); 2510 DCHECK_EQ(frame.origin.y, [self view].frame.origin.y);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
2567 2565
2568 - (BOOL)isLoading { 2566 - (BOOL)isLoading {
2569 return ![_determinateProgressView isHidden]; 2567 return ![_determinateProgressView isHidden];
2570 } 2568 }
2571 2569
2572 - (BOOL)isPrerenderAnimationRunning { 2570 - (BOOL)isPrerenderAnimationRunning {
2573 return _prerenderAnimating; 2571 return _prerenderAnimating;
2574 } 2572 }
2575 2573
2576 - (OmniboxTextFieldIOS*)omnibox { 2574 - (OmniboxTextFieldIOS*)omnibox {
2577 return _omniBox; 2575 return _omniBox.get();
2578 } 2576 }
2579 2577
2580 @end 2578 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/toolbar/web_toolbar_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698