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

Side by Side Diff: ios/chrome/browser/ui/ntp/google_landing_view_controller.mm

Issue 2860713002: Change the constraint to anchor constraints in GoogleLandingController (Closed)
Patch Set: Rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 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 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 forControlEvents:UIControlEventTouchUpInside]; 505 forControlEvents:UIControlEventTouchUpInside];
506 [_searchTapTarget 506 [_searchTapTarget
507 setAccessibilityLabel:l10n_util::GetNSString(IDS_OMNIBOX_EMPTY_HINT)]; 507 setAccessibilityLabel:l10n_util::GetNSString(IDS_OMNIBOX_EMPTY_HINT)];
508 // Set isAccessibilityElement to NO so that Voice Search button is accessible. 508 // Set isAccessibilityElement to NO so that Voice Search button is accessible.
509 [_searchTapTarget setIsAccessibilityElement:NO]; 509 [_searchTapTarget setIsAccessibilityElement:NO];
510 510
511 // Set up fakebox hint label. 511 // Set up fakebox hint label.
512 CGRect hintFrame = CGRectInset([_searchTapTarget bounds], 12, 3); 512 CGRect hintFrame = CGRectInset([_searchTapTarget bounds], 12, 3);
513 const CGFloat kVoiceSearchOffset = 48; 513 const CGFloat kVoiceSearchOffset = 48;
514 hintFrame.size.width = searchFieldFrame.size.width - kVoiceSearchOffset; 514 hintFrame.size.width = searchFieldFrame.size.width - kVoiceSearchOffset;
515 base::scoped_nsobject<UILabel> searchHintLabel( 515 UILabel* searchHintLabel =
516 [[UILabel alloc] initWithFrame:hintFrame]); 516 [[[UILabel alloc] initWithFrame:hintFrame] autorelease];
517 [_searchTapTarget addSubview:searchHintLabel]; 517 [_searchTapTarget addSubview:searchHintLabel];
518 [searchHintLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; 518 [searchHintLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
519 [searchHintLabel 519 _hintLabelLeadingConstraint.reset([[searchHintLabel.leadingAnchor
520 addConstraint:[NSLayoutConstraint 520 constraintEqualToAnchor:[_searchTapTarget leadingAnchor]
521 constraintWithItem:searchHintLabel 521 constant:kHintLabelSidePadding] retain]);
522 attribute:NSLayoutAttributeHeight 522
523 relatedBy:NSLayoutRelationEqual 523 [NSLayoutConstraint activateConstraints:@[
524 toItem:nil 524 [searchHintLabel.heightAnchor
525 attribute:NSLayoutAttributeNotAnAttribute 525 constraintEqualToConstant:hintFrame.size.height],
526 multiplier:1 526 [searchHintLabel.centerYAnchor
527 constant:hintFrame.size.height]]; 527 constraintEqualToAnchor:[_searchTapTarget centerYAnchor]],
528 [_searchTapTarget 528 _hintLabelLeadingConstraint
529 addConstraint:[NSLayoutConstraint 529 ]];
530 constraintWithItem:searchHintLabel 530
531 attribute:NSLayoutAttributeCenterY
532 relatedBy:NSLayoutRelationEqual
533 toItem:_searchTapTarget
534 attribute:NSLayoutAttributeCenterY
535 multiplier:1
536 constant:0]];
537 _hintLabelLeadingConstraint.reset(
538 [[NSLayoutConstraint constraintWithItem:searchHintLabel
539 attribute:NSLayoutAttributeLeading
540 relatedBy:NSLayoutRelationEqual
541 toItem:_searchTapTarget
542 attribute:NSLayoutAttributeLeading
543 multiplier:1
544 constant:kHintLabelSidePadding] retain]);
545 [_searchTapTarget addConstraint:_hintLabelLeadingConstraint];
546 [searchHintLabel setText:l10n_util::GetNSString(IDS_OMNIBOX_EMPTY_HINT)]; 531 [searchHintLabel setText:l10n_util::GetNSString(IDS_OMNIBOX_EMPTY_HINT)];
547 if (base::i18n::IsRTL()) { 532 if (base::i18n::IsRTL()) {
548 [searchHintLabel setTextAlignment:NSTextAlignmentRight]; 533 [searchHintLabel setTextAlignment:NSTextAlignmentRight];
549 } 534 }
550 [searchHintLabel 535 [searchHintLabel
551 setTextColor:[UIColor 536 setTextColor:[UIColor
552 colorWithWhite:kiPhoneOmniboxPlaceholderColorBrightness 537 colorWithWhite:kiPhoneOmniboxPlaceholderColorBrightness
553 alpha:1.0]]; 538 alpha:1.0]];
554 [searchHintLabel setFont:[MDCTypography subheadFont]]; 539 [searchHintLabel setFont:[MDCTypography subheadFont]];
555 540
556 // Add a voice search button. 541 // Add a voice search button.
557 UIImage* micImage = [UIImage imageNamed:@"voice_icon"]; 542 UIImage* micImage = [UIImage imageNamed:@"voice_icon"];
558 base::scoped_nsobject<UIButton> voiceTapTarget( 543 UIButton* voiceTapTarget =
559 [[UIButton alloc] initWithFrame:CGRectZero]); 544 [[[UIButton alloc] initWithFrame:CGRectZero] autorelease];
560 [_searchTapTarget addSubview:voiceTapTarget]; 545 [_searchTapTarget addSubview:voiceTapTarget];
561 546
562 [voiceTapTarget setTranslatesAutoresizingMaskIntoConstraints:NO]; 547 [voiceTapTarget setTranslatesAutoresizingMaskIntoConstraints:NO];
563 [_searchTapTarget 548 _voiceTapTrailingConstraint.reset([[voiceTapTarget.trailingAnchor
564 addConstraint:[NSLayoutConstraint 549 constraintEqualToAnchor:[_searchTapTarget trailingAnchor]] retain]);
565 constraintWithItem:voiceTapTarget 550
566 attribute:NSLayoutAttributeCenterY 551 [NSLayoutConstraint activateConstraints:@[
567 relatedBy:NSLayoutRelationEqual 552 [voiceTapTarget.centerYAnchor
568 toItem:_searchTapTarget 553 constraintEqualToAnchor:[_searchTapTarget centerYAnchor]],
569 attribute:NSLayoutAttributeCenterY 554 [voiceTapTarget.widthAnchor
570 multiplier:1 555 constraintEqualToConstant:kVoiceSearchButtonWidth],
571 constant:0]]; 556 [voiceTapTarget.heightAnchor
572 _voiceTapTrailingConstraint.reset( 557 constraintEqualToAnchor:voiceTapTarget.widthAnchor],
573 [[NSLayoutConstraint constraintWithItem:voiceTapTarget 558 [searchHintLabel.trailingAnchor
574 attribute:NSLayoutAttributeTrailing 559 constraintEqualToAnchor:voiceTapTarget.leadingAnchor],
575 relatedBy:NSLayoutRelationEqual 560 _voiceTapTrailingConstraint
576 toItem:_searchTapTarget 561 ]];
577 attribute:NSLayoutAttributeTrailing 562
578 multiplier:1
579 constant:0] retain]);
580 [_searchTapTarget addConstraint:_voiceTapTrailingConstraint];
581 [voiceTapTarget
582 addConstraint:[NSLayoutConstraint
583 constraintWithItem:voiceTapTarget
584 attribute:NSLayoutAttributeHeight
585 relatedBy:NSLayoutRelationEqual
586 toItem:nil
587 attribute:NSLayoutAttributeNotAnAttribute
588 multiplier:0
589 constant:kVoiceSearchButtonWidth]];
590 [voiceTapTarget
591 addConstraint:[NSLayoutConstraint
592 constraintWithItem:voiceTapTarget
593 attribute:NSLayoutAttributeWidth
594 relatedBy:NSLayoutRelationEqual
595 toItem:nil
596 attribute:NSLayoutAttributeNotAnAttribute
597 multiplier:0
598 constant:kVoiceSearchButtonWidth]];
599 [_searchTapTarget
600 addConstraint:[NSLayoutConstraint
601 constraintWithItem:searchHintLabel
602 attribute:NSLayoutAttributeTrailing
603 relatedBy:NSLayoutRelationEqual
604 toItem:voiceTapTarget
605 attribute:NSLayoutAttributeLeading
606 multiplier:1
607 constant:0]];
608 [voiceTapTarget setAdjustsImageWhenHighlighted:NO]; 563 [voiceTapTarget setAdjustsImageWhenHighlighted:NO];
609 [voiceTapTarget setImage:micImage forState:UIControlStateNormal]; 564 [voiceTapTarget setImage:micImage forState:UIControlStateNormal];
610 [voiceTapTarget setTag:IDC_VOICE_SEARCH]; 565 [voiceTapTarget setTag:IDC_VOICE_SEARCH];
611 [voiceTapTarget setAccessibilityLabel:l10n_util::GetNSString( 566 [voiceTapTarget setAccessibilityLabel:l10n_util::GetNSString(
612 IDS_IOS_ACCNAME_VOICE_SEARCH)]; 567 IDS_IOS_ACCNAME_VOICE_SEARCH)];
613 [voiceTapTarget setAccessibilityIdentifier:@"Voice Search"]; 568 [voiceTapTarget setAccessibilityIdentifier:@"Voice Search"];
614 569
615 if (self.voiceSearchIsEnabled) { 570 if (self.voiceSearchIsEnabled) {
616 [voiceTapTarget addTarget:self 571 [voiceTapTarget addTarget:self
617 action:@selector(loadVoiceSearch:) 572 action:@selector(loadVoiceSearch:)
(...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after
1514 - (void)setCanGoForward:(BOOL)canGoForward { 1469 - (void)setCanGoForward:(BOOL)canGoForward {
1515 _canGoForward = canGoForward; 1470 _canGoForward = canGoForward;
1516 [_headerView setCanGoForward:self.canGoForward]; 1471 [_headerView setCanGoForward:self.canGoForward];
1517 } 1472 }
1518 1473
1519 - (void)setCanGoBack:(BOOL)canGoBack { 1474 - (void)setCanGoBack:(BOOL)canGoBack {
1520 _canGoBack = canGoBack; 1475 _canGoBack = canGoBack;
1521 [_headerView setCanGoBack:self.canGoBack]; 1476 [_headerView setCanGoBack:self.canGoBack];
1522 } 1477 }
1523 @end 1478 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698