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