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,
// added to |hintLabelContainer| with autoresizing. This is done due to the
// way searchHintLabel is later tranformed.
void configureSearchHintLabel(UILabel* searchHintLabel,
UIButton* searchTapTarget);
UIView* searchTapTarget);
// Configure the |voiceSearchButton|, adding it to the |searchTapTarget| and
// constraining it.
void configureVoiceSearchButton(UIButton* voiceSearchButton,
UIButton* searchTapTarget);
UIView* searchTapTarget);
// Returns the nearest ancestor of |view| that is kind of |aClass|.
UIView* nearestAncestor(UIView* view, Class aClass);
......
......@@ -147,7 +147,7 @@ CGFloat heightForLogoHeader(BOOL logoIsShowing,
}
void configureSearchHintLabel(UILabel* searchHintLabel,
UIButton* searchTapTarget) {
UIView* searchTapTarget) {
[searchHintLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
[searchTapTarget addSubview:searchHintLabel];
......@@ -172,7 +172,7 @@ void configureSearchHintLabel(UILabel* searchHintLabel,
}
void configureVoiceSearchButton(UIButton* voiceSearchButton,
UIButton* searchTapTarget) {
UIView* searchTapTarget) {
[voiceSearchButton setTranslatesAutoresizingMaskIntoConstraints:NO];
[searchTapTarget addSubview:voiceSearchButton];
......
......@@ -15,6 +15,9 @@
// Returns the toolbar view.
@property(nonatomic, readonly) UIView* toolBarView;
// Voice search button.
@property(nonatomic, strong, readonly) UIButton* voiceSearchButton;
// Adds the |toolbarView| to the view implementing this protocol.
// Can only be added once.
- (void)addToolbarView:(UIView*)toolbarView;
......@@ -32,8 +35,6 @@
- (void)updateSearchFieldWidth:(NSLayoutConstraint*)widthConstraint
height:(NSLayoutConstraint*)heightConstraint
topMargin:(NSLayoutConstraint*)topMarginConstraint
hintLabel:(UILabel*)hintLabel
subviewConstraints:(NSArray*)constraints
forOffset:(CGFloat)offset
screenWidth:(CGFloat)screenWidth
safeAreaInsets:(UIEdgeInsets)safeAreaInsets;
......
......@@ -62,9 +62,6 @@ using base::UserMetricsAction;
@property(nonatomic, strong) ContentSuggestionsHeaderView* headerView;
@property(nonatomic, strong) UIButton* fakeOmnibox;
@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* doodleTopMarginConstraint;
@property(nonatomic, strong) NSLayoutConstraint* fakeOmniboxWidthConstraint;
......@@ -79,7 +76,6 @@ using base::UserMetricsAction;
@synthesize dispatcher = _dispatcher;
@synthesize delegate = _delegate;
@synthesize commandHandler = _commandHandler;
@synthesize searchHintLabel = _searchHintLabel;
@synthesize collectionSynchronizer = _collectionSynchronizer;
@synthesize readingListModel = _readingListModel;
@synthesize toolbarDelegate = _toolbarDelegate;
......@@ -94,8 +90,6 @@ using base::UserMetricsAction;
@synthesize headerView = _headerView;
@synthesize fakeOmnibox = _fakeOmnibox;
@synthesize accessibilityButton = _accessibilityButton;
@synthesize hintLabelLeadingConstraint = _hintLabelLeadingConstraint;
@synthesize voiceTapTrailingConstraint = _voiceTapTrailingConstraint;
@synthesize doodleHeightConstraint = _doodleHeightConstraint;
@synthesize doodleTopMarginConstraint = _doodleTopMarginConstraint;
@synthesize fakeOmniboxWidthConstraint = _fakeOmniboxWidthConstraint;
......@@ -159,14 +153,9 @@ using base::UserMetricsAction;
}
}
NSArray* constraints =
@[ self.hintLabelLeadingConstraint, self.voiceTapTrailingConstraint ];
[self.headerView updateSearchFieldWidth:self.fakeOmniboxWidthConstraint
height:self.fakeOmniboxHeightConstraint
topMargin:self.fakeOmniboxTopMarginConstraint
hintLabel:self.searchHintLabel
subviewConstraints:constraints
forOffset:offset
screenWidth:screenWidth
safeAreaInsets:safeAreaInsets];
......@@ -247,7 +236,6 @@ using base::UserMetricsAction;
fakeOmnibox:self.fakeOmnibox
andHeaderView:self.headerView];
[self.headerView addViewsToSearchField:self.fakeOmnibox];
[self.logoVendor fetchDoodle];
}
return self.headerView;
......@@ -265,21 +253,10 @@ using base::UserMetricsAction;
self.fakeOmnibox.accessibilityIdentifier =
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
// 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
// allow to select the content below it.
self.searchHintLabel.isAccessibilityElement = NO;
self.accessibilityButton = [[UIButton alloc] init];
[self.accessibilityButton addTarget:self
action:@selector(fakeboxTapped)
......@@ -298,28 +275,17 @@ using base::UserMetricsAction;
self.accessibilityButton.translatesAutoresizingMaskIntoConstraints = NO;
AddSameConstraints(self.fakeOmnibox, self.accessibilityButton);
// Add a voice search button.
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
]];
[self.headerView addViewsToSearchField:self.fakeOmnibox];
if (self.voiceSearchIsEnabled) {
[voiceTapTarget addTarget:self
action:@selector(loadVoiceSearch:)
forControlEvents:UIControlEventTouchUpInside];
[voiceTapTarget addTarget:self
action:@selector(preloadVoiceSearch:)
forControlEvents:UIControlEventTouchDown];
[self.headerView.voiceSearchButton addTarget:self
action:@selector(loadVoiceSearch:)
forControlEvents:UIControlEventTouchUpInside];
[self.headerView.voiceSearchButton addTarget:self
action:@selector(preloadVoiceSearch:)
forControlEvents:UIControlEventTouchDown];
} else {
[voiceTapTarget setEnabled:NO];
[self.headerView.voiceSearchButton setEnabled:NO];
}
}
......
......@@ -22,7 +22,6 @@ CGFloat ToolbarHeight();
extern const CGFloat kScrolledToTopOmniboxBottomMargin;
extern const CGFloat kHintLabelSidePadding;
extern const CGFloat kHintLabelSidePaddingLegacy;
// The margin of the subviews of the fake omnibox when it is pinned to top.
extern const CGFloat kMaxHorizontalMarginDiff;
......
......@@ -18,7 +18,6 @@ const CGFloat kAnimationDistance = 42;
const CGFloat kToolbarHeight = 48;
const CGFloat kScrolledToTopOmniboxBottomMargin = 4;
const CGFloat kHintLabelSidePadding = 37;
const CGFloat kHintLabelSidePaddingLegacy = 12;
const CGFloat kMaxHorizontalMarginDiff = 5;
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