Commit a20f19dd authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

[iOS] Refactor NTP header

This CL refactors the NTP header, changing the name of the variables
to have something more understandable.
It also changes the creation of the subviews of the fake omnibox, moving
it to the view.

Bug: 893522
Change-Id: Ib03f6e25a303016fdb6296011f05153667cfa2c3
Reviewed-on: https://chromium-review.googlesource.com/c/1309836
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarJustin Cohen <justincohen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605682}
parent e24601fe
...@@ -51,11 +51,11 @@ CGFloat heightForLogoHeader(BOOL logoIsShowing, ...@@ -51,11 +51,11 @@ CGFloat heightForLogoHeader(BOOL logoIsShowing,
// added to |hintLabelContainer| with autoresizing. This is done due to the // added to |hintLabelContainer| with autoresizing. This is done due to the
// way searchHintLabel is later tranformed. // way searchHintLabel is later tranformed.
void configureSearchHintLabel(UILabel* searchHintLabel, void configureSearchHintLabel(UILabel* searchHintLabel,
UIButton* searchTapTarget); UIView* searchTapTarget);
// Configure the |voiceSearchButton|, adding it to the |searchTapTarget| and // Configure the |voiceSearchButton|, adding it to the |searchTapTarget| and
// constraining it. // constraining it.
void configureVoiceSearchButton(UIButton* voiceSearchButton, void configureVoiceSearchButton(UIButton* voiceSearchButton,
UIButton* searchTapTarget); UIView* searchTapTarget);
// Returns the nearest ancestor of |view| that is kind of |aClass|. // Returns the nearest ancestor of |view| that is kind of |aClass|.
UIView* nearestAncestor(UIView* view, Class aClass); UIView* nearestAncestor(UIView* view, Class aClass);
......
...@@ -147,7 +147,7 @@ CGFloat heightForLogoHeader(BOOL logoIsShowing, ...@@ -147,7 +147,7 @@ CGFloat heightForLogoHeader(BOOL logoIsShowing,
} }
void configureSearchHintLabel(UILabel* searchHintLabel, void configureSearchHintLabel(UILabel* searchHintLabel,
UIButton* searchTapTarget) { UIView* searchTapTarget) {
[searchHintLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; [searchHintLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
[searchTapTarget addSubview:searchHintLabel]; [searchTapTarget addSubview:searchHintLabel];
...@@ -172,7 +172,7 @@ void configureSearchHintLabel(UILabel* searchHintLabel, ...@@ -172,7 +172,7 @@ void configureSearchHintLabel(UILabel* searchHintLabel,
} }
void configureVoiceSearchButton(UIButton* voiceSearchButton, void configureVoiceSearchButton(UIButton* voiceSearchButton,
UIButton* searchTapTarget) { UIView* searchTapTarget) {
[voiceSearchButton setTranslatesAutoresizingMaskIntoConstraints:NO]; [voiceSearchButton setTranslatesAutoresizingMaskIntoConstraints:NO];
[searchTapTarget addSubview:voiceSearchButton]; [searchTapTarget addSubview:voiceSearchButton];
......
...@@ -15,6 +15,9 @@ ...@@ -15,6 +15,9 @@
// Returns the toolbar view. // Returns the toolbar view.
@property(nonatomic, readonly) UIView* toolBarView; @property(nonatomic, readonly) UIView* toolBarView;
// Voice search button.
@property(nonatomic, strong, readonly) UIButton* voiceSearchButton;
// Adds the |toolbarView| to the view implementing this protocol. // Adds the |toolbarView| to the view implementing this protocol.
// Can only be added once. // Can only be added once.
- (void)addToolbarView:(UIView*)toolbarView; - (void)addToolbarView:(UIView*)toolbarView;
...@@ -32,8 +35,6 @@ ...@@ -32,8 +35,6 @@
- (void)updateSearchFieldWidth:(NSLayoutConstraint*)widthConstraint - (void)updateSearchFieldWidth:(NSLayoutConstraint*)widthConstraint
height:(NSLayoutConstraint*)heightConstraint height:(NSLayoutConstraint*)heightConstraint
topMargin:(NSLayoutConstraint*)topMarginConstraint topMargin:(NSLayoutConstraint*)topMarginConstraint
hintLabel:(UILabel*)hintLabel
subviewConstraints:(NSArray*)constraints
forOffset:(CGFloat)offset forOffset:(CGFloat)offset
screenWidth:(CGFloat)screenWidth screenWidth:(CGFloat)screenWidth
safeAreaInsets:(UIEdgeInsets)safeAreaInsets; safeAreaInsets:(UIEdgeInsets)safeAreaInsets;
......
...@@ -62,9 +62,6 @@ using base::UserMetricsAction; ...@@ -62,9 +62,6 @@ using base::UserMetricsAction;
@property(nonatomic, strong) ContentSuggestionsHeaderView* headerView; @property(nonatomic, strong) ContentSuggestionsHeaderView* headerView;
@property(nonatomic, strong) UIButton* fakeOmnibox; @property(nonatomic, strong) UIButton* fakeOmnibox;
@property(nonatomic, strong) UIButton* accessibilityButton; @property(nonatomic, strong) UIButton* accessibilityButton;
@property(nonatomic, strong) UILabel* searchHintLabel;
@property(nonatomic, strong) NSLayoutConstraint* hintLabelLeadingConstraint;
@property(nonatomic, strong) NSLayoutConstraint* voiceTapTrailingConstraint;
@property(nonatomic, strong) NSLayoutConstraint* doodleHeightConstraint; @property(nonatomic, strong) NSLayoutConstraint* doodleHeightConstraint;
@property(nonatomic, strong) NSLayoutConstraint* doodleTopMarginConstraint; @property(nonatomic, strong) NSLayoutConstraint* doodleTopMarginConstraint;
@property(nonatomic, strong) NSLayoutConstraint* fakeOmniboxWidthConstraint; @property(nonatomic, strong) NSLayoutConstraint* fakeOmniboxWidthConstraint;
...@@ -79,7 +76,6 @@ using base::UserMetricsAction; ...@@ -79,7 +76,6 @@ using base::UserMetricsAction;
@synthesize dispatcher = _dispatcher; @synthesize dispatcher = _dispatcher;
@synthesize delegate = _delegate; @synthesize delegate = _delegate;
@synthesize commandHandler = _commandHandler; @synthesize commandHandler = _commandHandler;
@synthesize searchHintLabel = _searchHintLabel;
@synthesize collectionSynchronizer = _collectionSynchronizer; @synthesize collectionSynchronizer = _collectionSynchronizer;
@synthesize readingListModel = _readingListModel; @synthesize readingListModel = _readingListModel;
@synthesize toolbarDelegate = _toolbarDelegate; @synthesize toolbarDelegate = _toolbarDelegate;
...@@ -94,8 +90,6 @@ using base::UserMetricsAction; ...@@ -94,8 +90,6 @@ using base::UserMetricsAction;
@synthesize headerView = _headerView; @synthesize headerView = _headerView;
@synthesize fakeOmnibox = _fakeOmnibox; @synthesize fakeOmnibox = _fakeOmnibox;
@synthesize accessibilityButton = _accessibilityButton; @synthesize accessibilityButton = _accessibilityButton;
@synthesize hintLabelLeadingConstraint = _hintLabelLeadingConstraint;
@synthesize voiceTapTrailingConstraint = _voiceTapTrailingConstraint;
@synthesize doodleHeightConstraint = _doodleHeightConstraint; @synthesize doodleHeightConstraint = _doodleHeightConstraint;
@synthesize doodleTopMarginConstraint = _doodleTopMarginConstraint; @synthesize doodleTopMarginConstraint = _doodleTopMarginConstraint;
@synthesize fakeOmniboxWidthConstraint = _fakeOmniboxWidthConstraint; @synthesize fakeOmniboxWidthConstraint = _fakeOmniboxWidthConstraint;
...@@ -159,14 +153,9 @@ using base::UserMetricsAction; ...@@ -159,14 +153,9 @@ using base::UserMetricsAction;
} }
} }
NSArray* constraints =
@[ self.hintLabelLeadingConstraint, self.voiceTapTrailingConstraint ];
[self.headerView updateSearchFieldWidth:self.fakeOmniboxWidthConstraint [self.headerView updateSearchFieldWidth:self.fakeOmniboxWidthConstraint
height:self.fakeOmniboxHeightConstraint height:self.fakeOmniboxHeightConstraint
topMargin:self.fakeOmniboxTopMarginConstraint topMargin:self.fakeOmniboxTopMarginConstraint
hintLabel:self.searchHintLabel
subviewConstraints:constraints
forOffset:offset forOffset:offset
screenWidth:screenWidth screenWidth:screenWidth
safeAreaInsets:safeAreaInsets]; safeAreaInsets:safeAreaInsets];
...@@ -247,7 +236,6 @@ using base::UserMetricsAction; ...@@ -247,7 +236,6 @@ using base::UserMetricsAction;
fakeOmnibox:self.fakeOmnibox fakeOmnibox:self.fakeOmnibox
andHeaderView:self.headerView]; andHeaderView:self.headerView];
[self.headerView addViewsToSearchField:self.fakeOmnibox];
[self.logoVendor fetchDoodle]; [self.logoVendor fetchDoodle];
} }
return self.headerView; return self.headerView;
...@@ -265,21 +253,10 @@ using base::UserMetricsAction; ...@@ -265,21 +253,10 @@ using base::UserMetricsAction;
self.fakeOmnibox.accessibilityIdentifier = self.fakeOmnibox.accessibilityIdentifier =
ntp_home::FakeOmniboxAccessibilityID(); ntp_home::FakeOmniboxAccessibilityID();
// Set up fakebox hint label.
self.searchHintLabel = [[UILabel alloc] init];
content_suggestions::configureSearchHintLabel(self.searchHintLabel,
self.fakeOmnibox);
self.hintLabelLeadingConstraint = [self.searchHintLabel.leadingAnchor
constraintGreaterThanOrEqualToAnchor:[self.fakeOmnibox leadingAnchor]
constant:ntp_header::kHintLabelSidePadding];
self.hintLabelLeadingConstraint.active = YES;
// Set a button the same size as the fake omnibox as the accessibility // Set a button the same size as the fake omnibox as the accessibility
// element. If the hint is the only accessible element, when the fake omnibox // element. If the hint is the only accessible element, when the fake omnibox
// is taking the full width, there are few points that are not accessible and // is taking the full width, there are few points that are not accessible and
// allow to select the content below it. // allow to select the content below it.
self.searchHintLabel.isAccessibilityElement = NO;
self.accessibilityButton = [[UIButton alloc] init]; self.accessibilityButton = [[UIButton alloc] init];
[self.accessibilityButton addTarget:self [self.accessibilityButton addTarget:self
action:@selector(fakeboxTapped) action:@selector(fakeboxTapped)
...@@ -298,28 +275,17 @@ using base::UserMetricsAction; ...@@ -298,28 +275,17 @@ using base::UserMetricsAction;
self.accessibilityButton.translatesAutoresizingMaskIntoConstraints = NO; self.accessibilityButton.translatesAutoresizingMaskIntoConstraints = NO;
AddSameConstraints(self.fakeOmnibox, self.accessibilityButton); AddSameConstraints(self.fakeOmnibox, self.accessibilityButton);
// Add a voice search button. [self.headerView addViewsToSearchField:self.fakeOmnibox];
UIButton* voiceTapTarget = [[UIButton alloc] init];
content_suggestions::configureVoiceSearchButton(voiceTapTarget,
self.fakeOmnibox);
self.voiceTapTrailingConstraint = [voiceTapTarget.trailingAnchor
constraintEqualToAnchor:[self.fakeOmnibox trailingAnchor]];
[NSLayoutConstraint activateConstraints:@[
[self.searchHintLabel.trailingAnchor
constraintLessThanOrEqualToAnchor:voiceTapTarget.leadingAnchor],
_voiceTapTrailingConstraint
]];
if (self.voiceSearchIsEnabled) { if (self.voiceSearchIsEnabled) {
[voiceTapTarget addTarget:self [self.headerView.voiceSearchButton addTarget:self
action:@selector(loadVoiceSearch:) action:@selector(loadVoiceSearch:)
forControlEvents:UIControlEventTouchUpInside]; forControlEvents:UIControlEventTouchUpInside];
[voiceTapTarget addTarget:self [self.headerView.voiceSearchButton addTarget:self
action:@selector(preloadVoiceSearch:) action:@selector(preloadVoiceSearch:)
forControlEvents:UIControlEventTouchDown]; forControlEvents:UIControlEventTouchDown];
} else { } else {
[voiceTapTarget setEnabled:NO]; [self.headerView.voiceSearchButton setEnabled:NO];
} }
} }
......
...@@ -22,7 +22,6 @@ CGFloat ToolbarHeight(); ...@@ -22,7 +22,6 @@ CGFloat ToolbarHeight();
extern const CGFloat kScrolledToTopOmniboxBottomMargin; extern const CGFloat kScrolledToTopOmniboxBottomMargin;
extern const CGFloat kHintLabelSidePadding; extern const CGFloat kHintLabelSidePadding;
extern const CGFloat kHintLabelSidePaddingLegacy;
// The margin of the subviews of the fake omnibox when it is pinned to top. // The margin of the subviews of the fake omnibox when it is pinned to top.
extern const CGFloat kMaxHorizontalMarginDiff; extern const CGFloat kMaxHorizontalMarginDiff;
......
...@@ -18,7 +18,6 @@ const CGFloat kAnimationDistance = 42; ...@@ -18,7 +18,6 @@ const CGFloat kAnimationDistance = 42;
const CGFloat kToolbarHeight = 48; const CGFloat kToolbarHeight = 48;
const CGFloat kScrolledToTopOmniboxBottomMargin = 4; const CGFloat kScrolledToTopOmniboxBottomMargin = 4;
const CGFloat kHintLabelSidePadding = 37; const CGFloat kHintLabelSidePadding = 37;
const CGFloat kHintLabelSidePaddingLegacy = 12;
const CGFloat kMaxHorizontalMarginDiff = 5; const CGFloat kMaxHorizontalMarginDiff = 5;
const CGFloat kMaxTopMarginDiff = 4; const CGFloat kMaxTopMarginDiff = 4;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment