Chromium Code Reviews| 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 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 413 forControlEvents:UIControlEventTouchUpInside]; | 413 forControlEvents:UIControlEventTouchUpInside]; |
| 414 [_searchTapTarget | 414 [_searchTapTarget |
| 415 setAccessibilityLabel:l10n_util::GetNSString(IDS_OMNIBOX_EMPTY_HINT)]; | 415 setAccessibilityLabel:l10n_util::GetNSString(IDS_OMNIBOX_EMPTY_HINT)]; |
| 416 // Set isAccessibilityElement to NO so that Voice Search button is accessible. | 416 // Set isAccessibilityElement to NO so that Voice Search button is accessible. |
| 417 [_searchTapTarget setIsAccessibilityElement:NO]; | 417 [_searchTapTarget setIsAccessibilityElement:NO]; |
| 418 | 418 |
| 419 // Set up fakebox hint label. | 419 // Set up fakebox hint label. |
| 420 CGRect hintFrame = CGRectInset([_searchTapTarget bounds], 12, 3); | 420 CGRect hintFrame = CGRectInset([_searchTapTarget bounds], 12, 3); |
| 421 const CGFloat kVoiceSearchOffset = 48; | 421 const CGFloat kVoiceSearchOffset = 48; |
| 422 hintFrame.size.width = searchFieldFrame.size.width - kVoiceSearchOffset; | 422 hintFrame.size.width = searchFieldFrame.size.width - kVoiceSearchOffset; |
| 423 base::scoped_nsobject<UILabel> searchHintLabel( | 423 UILabel* searchHintLabel = |
| 424 [[UILabel alloc] initWithFrame:hintFrame]); | 424 [[[UILabel alloc] initWithFrame:hintFrame] autorelease]; |
| 425 [_searchTapTarget addSubview:searchHintLabel]; | 425 [_searchTapTarget addSubview:searchHintLabel]; |
| 426 [searchHintLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; | 426 [searchHintLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; |
| 427 [searchHintLabel | 427 _hintLabelLeadingConstraint.reset([[searchHintLabel.leadingAnchor |
| 428 addConstraint:[NSLayoutConstraint | 428 constraintEqualToAnchor:[_searchTapTarget leadingAnchor] |
| 429 constraintWithItem:searchHintLabel | 429 constant:kHintLabelSidePadding] retain]); |
| 430 attribute:NSLayoutAttributeHeight | 430 |
| 431 relatedBy:NSLayoutRelationEqual | 431 [NSLayoutConstraint activateConstraints:@[ |
| 432 toItem:nil | 432 [searchHintLabel.heightAnchor |
| 433 attribute:NSLayoutAttributeNotAnAttribute | 433 constraintEqualToConstant:hintFrame.size.height], |
| 434 multiplier:1 | 434 [searchHintLabel.centerYAnchor |
| 435 constant:hintFrame.size.height]]; | 435 constraintEqualToAnchor:[_searchTapTarget centerYAnchor]], |
| 436 [_searchTapTarget | 436 _hintLabelLeadingConstraint |
| 437 addConstraint:[NSLayoutConstraint | 437 ]]; |
| 438 constraintWithItem:searchHintLabel | 438 |
| 439 attribute:NSLayoutAttributeCenterY | |
| 440 relatedBy:NSLayoutRelationEqual | |
| 441 toItem:_searchTapTarget | |
| 442 attribute:NSLayoutAttributeCenterY | |
| 443 multiplier:1 | |
| 444 constant:0]]; | |
| 445 _hintLabelLeadingConstraint.reset( | |
| 446 [[NSLayoutConstraint constraintWithItem:searchHintLabel | |
| 447 attribute:NSLayoutAttributeLeading | |
| 448 relatedBy:NSLayoutRelationEqual | |
| 449 toItem:_searchTapTarget | |
| 450 attribute:NSLayoutAttributeLeading | |
| 451 multiplier:1 | |
| 452 constant:kHintLabelSidePadding] retain]); | |
| 453 [_searchTapTarget addConstraint:_hintLabelLeadingConstraint]; | |
| 454 [searchHintLabel setText:l10n_util::GetNSString(IDS_OMNIBOX_EMPTY_HINT)]; | 439 [searchHintLabel setText:l10n_util::GetNSString(IDS_OMNIBOX_EMPTY_HINT)]; |
| 455 if (base::i18n::IsRTL()) { | 440 if (base::i18n::IsRTL()) { |
| 456 [searchHintLabel setTextAlignment:NSTextAlignmentRight]; | 441 [searchHintLabel setTextAlignment:NSTextAlignmentRight]; |
| 457 } | 442 } |
| 458 [searchHintLabel | 443 [searchHintLabel |
| 459 setTextColor:[UIColor | 444 setTextColor:[UIColor |
| 460 colorWithWhite:kiPhoneOmniboxPlaceholderColorBrightness | 445 colorWithWhite:kiPhoneOmniboxPlaceholderColorBrightness |
| 461 alpha:1.0]]; | 446 alpha:1.0]]; |
| 462 [searchHintLabel setFont:[MDCTypography subheadFont]]; | 447 [searchHintLabel setFont:[MDCTypography subheadFont]]; |
| 463 | 448 |
| 464 // Add a voice search button. | 449 // Add a voice search button. |
| 465 UIImage* micImage = [UIImage imageNamed:@"voice_icon"]; | 450 UIImage* micImage = [UIImage imageNamed:@"voice_icon"]; |
| 466 base::scoped_nsobject<UIButton> voiceTapTarget( | 451 UIButton* voiceTapTarget = |
| 467 [[UIButton alloc] initWithFrame:CGRectZero]); | 452 [[[UIButton alloc] initWithFrame:CGRectZero] autorelease]; |
| 468 [_searchTapTarget addSubview:voiceTapTarget]; | 453 [_searchTapTarget addSubview:voiceTapTarget]; |
| 469 | 454 |
| 470 [voiceTapTarget setTranslatesAutoresizingMaskIntoConstraints:NO]; | 455 [voiceTapTarget setTranslatesAutoresizingMaskIntoConstraints:NO]; |
| 471 [_searchTapTarget | 456 _voiceTapTrailingConstraint.reset([[voiceTapTarget.trailingAnchor |
| 472 addConstraint:[NSLayoutConstraint | 457 constraintEqualToAnchor:[_searchTapTarget trailingAnchor]] retain]); |
| 473 constraintWithItem:voiceTapTarget | 458 |
| 474 attribute:NSLayoutAttributeCenterY | 459 [NSLayoutConstraint activateConstraints:@[ |
| 475 relatedBy:NSLayoutRelationEqual | 460 [voiceTapTarget.centerYAnchor |
| 476 toItem:_searchTapTarget | 461 constraintEqualToAnchor:[_searchTapTarget centerYAnchor]], |
| 477 attribute:NSLayoutAttributeCenterY | 462 [voiceTapTarget.heightAnchor |
| 478 multiplier:1 | 463 constraintEqualToConstant:kVoiceSearchButtonWidth], |
|
jif
2017/05/03 13:21:08
Nit:
Make the width equal to kVoiceSearchButtonWid
gambard
2017/05/03 13:25:04
Done.
| |
| 479 constant:0]]; | 464 [voiceTapTarget.widthAnchor |
| 480 _voiceTapTrailingConstraint.reset( | 465 constraintEqualToAnchor:voiceTapTarget.heightAnchor], |
| 481 [[NSLayoutConstraint constraintWithItem:voiceTapTarget | 466 [searchHintLabel.trailingAnchor |
| 482 attribute:NSLayoutAttributeTrailing | 467 constraintEqualToAnchor:voiceTapTarget.leadingAnchor], |
| 483 relatedBy:NSLayoutRelationEqual | 468 _voiceTapTrailingConstraint |
| 484 toItem:_searchTapTarget | 469 ]]; |
| 485 attribute:NSLayoutAttributeTrailing | 470 |
| 486 multiplier:1 | |
| 487 constant:0] retain]); | |
| 488 [_searchTapTarget addConstraint:_voiceTapTrailingConstraint]; | |
| 489 [voiceTapTarget | |
| 490 addConstraint:[NSLayoutConstraint | |
| 491 constraintWithItem:voiceTapTarget | |
| 492 attribute:NSLayoutAttributeHeight | |
| 493 relatedBy:NSLayoutRelationEqual | |
| 494 toItem:nil | |
| 495 attribute:NSLayoutAttributeNotAnAttribute | |
| 496 multiplier:0 | |
| 497 constant:kVoiceSearchButtonWidth]]; | |
| 498 [voiceTapTarget | |
| 499 addConstraint:[NSLayoutConstraint | |
| 500 constraintWithItem:voiceTapTarget | |
| 501 attribute:NSLayoutAttributeWidth | |
| 502 relatedBy:NSLayoutRelationEqual | |
| 503 toItem:nil | |
| 504 attribute:NSLayoutAttributeNotAnAttribute | |
| 505 multiplier:0 | |
| 506 constant:kVoiceSearchButtonWidth]]; | |
| 507 [_searchTapTarget | |
| 508 addConstraint:[NSLayoutConstraint | |
| 509 constraintWithItem:searchHintLabel | |
| 510 attribute:NSLayoutAttributeTrailing | |
| 511 relatedBy:NSLayoutRelationEqual | |
| 512 toItem:voiceTapTarget | |
| 513 attribute:NSLayoutAttributeLeading | |
| 514 multiplier:1 | |
| 515 constant:0]]; | |
| 516 [voiceTapTarget setAdjustsImageWhenHighlighted:NO]; | 471 [voiceTapTarget setAdjustsImageWhenHighlighted:NO]; |
| 517 [voiceTapTarget setImage:micImage forState:UIControlStateNormal]; | 472 [voiceTapTarget setImage:micImage forState:UIControlStateNormal]; |
| 518 [voiceTapTarget setTag:IDC_VOICE_SEARCH]; | 473 [voiceTapTarget setTag:IDC_VOICE_SEARCH]; |
| 519 [voiceTapTarget setAccessibilityLabel:l10n_util::GetNSString( | 474 [voiceTapTarget setAccessibilityLabel:l10n_util::GetNSString( |
| 520 IDS_IOS_ACCNAME_VOICE_SEARCH)]; | 475 IDS_IOS_ACCNAME_VOICE_SEARCH)]; |
| 521 [voiceTapTarget setAccessibilityIdentifier:@"Voice Search"]; | 476 [voiceTapTarget setAccessibilityIdentifier:@"Voice Search"]; |
| 522 | 477 |
| 523 if (self.voiceSearchIsEnabled) { | 478 if (self.voiceSearchIsEnabled) { |
| 524 [voiceTapTarget addTarget:self | 479 [voiceTapTarget addTarget:self |
| 525 action:@selector(loadVoiceSearch:) | 480 action:@selector(loadVoiceSearch:) |
| (...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1409 - (void)setCanGoForward:(BOOL)canGoForward { | 1364 - (void)setCanGoForward:(BOOL)canGoForward { |
| 1410 _canGoForward = canGoForward; | 1365 _canGoForward = canGoForward; |
| 1411 [_headerView setCanGoForward:self.canGoForward]; | 1366 [_headerView setCanGoForward:self.canGoForward]; |
| 1412 } | 1367 } |
| 1413 | 1368 |
| 1414 - (void)setCanGoBack:(BOOL)canGoBack { | 1369 - (void)setCanGoBack:(BOOL)canGoBack { |
| 1415 _canGoBack = canGoBack; | 1370 _canGoBack = canGoBack; |
| 1416 [_headerView setCanGoBack:self.canGoBack]; | 1371 [_headerView setCanGoBack:self.canGoBack]; |
| 1417 } | 1372 } |
| 1418 @end | 1373 @end |
| OLD | NEW |