OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ntp/google_landing_view_controller.h" | 5 #import "ios/chrome/browser/ui/ntp/google_landing_view_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
10 #include "base/metrics/user_metrics.h" | 10 #include "base/metrics/user_metrics.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 using base::UserMetricsAction; | 38 using base::UserMetricsAction; |
39 | 39 |
40 namespace { | 40 namespace { |
41 | 41 |
42 enum { | 42 enum { |
43 SectionWithOmnibox, | 43 SectionWithOmnibox, |
44 SectionWithMostVisited, | 44 SectionWithMostVisited, |
45 NumberOfCollectionViewSections, | 45 NumberOfCollectionViewSections, |
46 }; | 46 }; |
47 | 47 |
48 const CGFloat kVoiceSearchButtonWidth = 48; | |
49 const UIEdgeInsets kSearchBoxStretchInsets = {3, 3, 3, 3}; | 48 const UIEdgeInsets kSearchBoxStretchInsets = {3, 3, 3, 3}; |
50 | 49 |
51 const CGFloat kHintLabelSidePadding = 12; | 50 const CGFloat kHintLabelSidePadding = 12; |
52 const CGFloat kWhatsNewHeaderHiddenHeight = 8; | 51 const CGFloat kWhatsNewHeaderHiddenHeight = 8; |
53 const NSInteger kMaxNumMostVisitedFaviconRows = 2; | 52 const NSInteger kMaxNumMostVisitedFaviconRows = 2; |
54 const CGFloat kShiftTilesDownAnimationDuration = 0.2; | 53 const CGFloat kShiftTilesDownAnimationDuration = 0.2; |
55 | 54 |
56 } // namespace | 55 } // namespace |
57 | 56 |
58 @interface GoogleLandingViewController (UsedByGoogleLandingView) | 57 @interface GoogleLandingViewController (UsedByGoogleLandingView) |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 [_searchTapTarget setAdjustsImageWhenHighlighted:NO]; | 408 [_searchTapTarget setAdjustsImageWhenHighlighted:NO]; |
410 [_searchTapTarget addTarget:self | 409 [_searchTapTarget addTarget:self |
411 action:@selector(searchFieldTapped:) | 410 action:@selector(searchFieldTapped:) |
412 forControlEvents:UIControlEventTouchUpInside]; | 411 forControlEvents:UIControlEventTouchUpInside]; |
413 [_searchTapTarget | 412 [_searchTapTarget |
414 setAccessibilityLabel:l10n_util::GetNSString(IDS_OMNIBOX_EMPTY_HINT)]; | 413 setAccessibilityLabel:l10n_util::GetNSString(IDS_OMNIBOX_EMPTY_HINT)]; |
415 // Set isAccessibilityElement to NO so that Voice Search button is accessible. | 414 // Set isAccessibilityElement to NO so that Voice Search button is accessible. |
416 [_searchTapTarget setIsAccessibilityElement:NO]; | 415 [_searchTapTarget setIsAccessibilityElement:NO]; |
417 | 416 |
418 // Set up fakebox hint label. | 417 // Set up fakebox hint label. |
419 CGRect hintFrame = CGRectInset([_searchTapTarget bounds], 12, 3); | 418 UILabel* searchHintLabel = [[[UILabel alloc] init] autorelease]; |
420 const CGFloat kVoiceSearchOffset = 48; | 419 content_suggestions::configureSearchHintLabel( |
421 hintFrame.size.width = searchFieldFrame.size.width - kVoiceSearchOffset; | 420 searchHintLabel, _searchTapTarget.get(), searchFieldFrame.size.width); |
422 UILabel* searchHintLabel = | 421 |
423 [[[UILabel alloc] initWithFrame:hintFrame] autorelease]; | |
424 [_searchTapTarget addSubview:searchHintLabel]; | |
425 [searchHintLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; | |
426 _hintLabelLeadingConstraint.reset([[searchHintLabel.leadingAnchor | 422 _hintLabelLeadingConstraint.reset([[searchHintLabel.leadingAnchor |
427 constraintEqualToAnchor:[_searchTapTarget leadingAnchor] | 423 constraintEqualToAnchor:[_searchTapTarget leadingAnchor] |
428 constant:kHintLabelSidePadding] retain]); | 424 constant:kHintLabelSidePadding] retain]); |
429 | 425 [_hintLabelLeadingConstraint setActive:YES]; |
430 [NSLayoutConstraint activateConstraints:@[ | |
431 [searchHintLabel.heightAnchor | |
432 constraintEqualToConstant:hintFrame.size.height], | |
433 [searchHintLabel.centerYAnchor | |
434 constraintEqualToAnchor:[_searchTapTarget centerYAnchor]], | |
435 _hintLabelLeadingConstraint | |
436 ]]; | |
437 | |
438 [searchHintLabel setText:l10n_util::GetNSString(IDS_OMNIBOX_EMPTY_HINT)]; | |
439 if (base::i18n::IsRTL()) { | |
440 [searchHintLabel setTextAlignment:NSTextAlignmentRight]; | |
441 } | |
442 [searchHintLabel | |
443 setTextColor:[UIColor | |
444 colorWithWhite:kiPhoneOmniboxPlaceholderColorBrightness | |
445 alpha:1.0]]; | |
446 [searchHintLabel setFont:[MDCTypography subheadFont]]; | |
447 | 426 |
448 // Add a voice search button. | 427 // Add a voice search button. |
449 UIImage* micImage = [UIImage imageNamed:@"voice_icon"]; | 428 UIButton* voiceTapTarget = [[[UIButton alloc] init] autorelease]; |
450 UIButton* voiceTapTarget = | 429 content_suggestions::configureVoiceSearchButton(voiceTapTarget, |
451 [[[UIButton alloc] initWithFrame:CGRectZero] autorelease]; | 430 _searchTapTarget.get()); |
452 [_searchTapTarget addSubview:voiceTapTarget]; | |
453 | 431 |
454 [voiceTapTarget setTranslatesAutoresizingMaskIntoConstraints:NO]; | |
455 _voiceTapTrailingConstraint.reset([[voiceTapTarget.trailingAnchor | 432 _voiceTapTrailingConstraint.reset([[voiceTapTarget.trailingAnchor |
456 constraintEqualToAnchor:[_searchTapTarget trailingAnchor]] retain]); | 433 constraintEqualToAnchor:[_searchTapTarget trailingAnchor]] retain]); |
457 | |
458 [NSLayoutConstraint activateConstraints:@[ | 434 [NSLayoutConstraint activateConstraints:@[ |
459 [voiceTapTarget.centerYAnchor | |
460 constraintEqualToAnchor:[_searchTapTarget centerYAnchor]], | |
461 [voiceTapTarget.widthAnchor | |
462 constraintEqualToConstant:kVoiceSearchButtonWidth], | |
463 [voiceTapTarget.heightAnchor | |
464 constraintEqualToAnchor:voiceTapTarget.widthAnchor], | |
465 [searchHintLabel.trailingAnchor | 435 [searchHintLabel.trailingAnchor |
466 constraintEqualToAnchor:voiceTapTarget.leadingAnchor], | 436 constraintEqualToAnchor:voiceTapTarget.leadingAnchor], |
467 _voiceTapTrailingConstraint | 437 _voiceTapTrailingConstraint |
468 ]]; | 438 ]]; |
469 | 439 |
470 [voiceTapTarget setAdjustsImageWhenHighlighted:NO]; | |
471 [voiceTapTarget setImage:micImage forState:UIControlStateNormal]; | |
472 [voiceTapTarget setTag:IDC_VOICE_SEARCH]; | |
473 [voiceTapTarget setAccessibilityLabel:l10n_util::GetNSString( | |
474 IDS_IOS_ACCNAME_VOICE_SEARCH)]; | |
475 [voiceTapTarget setAccessibilityIdentifier:@"Voice Search"]; | |
476 | |
477 if (self.voiceSearchIsEnabled) { | 440 if (self.voiceSearchIsEnabled) { |
478 [voiceTapTarget addTarget:self | 441 [voiceTapTarget addTarget:self |
479 action:@selector(loadVoiceSearch:) | 442 action:@selector(loadVoiceSearch:) |
480 forControlEvents:UIControlEventTouchUpInside]; | 443 forControlEvents:UIControlEventTouchUpInside]; |
481 [voiceTapTarget addTarget:self | 444 [voiceTapTarget addTarget:self |
482 action:@selector(preloadVoiceSearch:) | 445 action:@selector(preloadVoiceSearch:) |
483 forControlEvents:UIControlEventTouchDown]; | 446 forControlEvents:UIControlEventTouchDown]; |
484 } else { | 447 } else { |
485 [voiceTapTarget setEnabled:NO]; | 448 [voiceTapTarget setEnabled:NO]; |
486 } | 449 } |
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1364 - (void)setCanGoForward:(BOOL)canGoForward { | 1327 - (void)setCanGoForward:(BOOL)canGoForward { |
1365 _canGoForward = canGoForward; | 1328 _canGoForward = canGoForward; |
1366 [_headerView setCanGoForward:self.canGoForward]; | 1329 [_headerView setCanGoForward:self.canGoForward]; |
1367 } | 1330 } |
1368 | 1331 |
1369 - (void)setCanGoBack:(BOOL)canGoBack { | 1332 - (void)setCanGoBack:(BOOL)canGoBack { |
1370 _canGoBack = canGoBack; | 1333 _canGoBack = canGoBack; |
1371 [_headerView setCanGoBack:self.canGoBack]; | 1334 [_headerView setCanGoBack:self.canGoBack]; |
1372 } | 1335 } |
1373 @end | 1336 @end |
OLD | NEW |