OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/content_suggestions/content_suggestions_collectio
n_utils.h" | 5 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_collectio
n_utils.h" |
6 | 6 |
| 7 #include "base/i18n/rtl.h" |
7 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "components/strings/grit/components_strings.h" |
| 10 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" |
8 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_mos
t_visited_item.h" | 11 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_mos
t_visited_item.h" |
| 12 #import "ios/chrome/browser/ui/toolbar/web_toolbar_controller.h" |
9 #include "ios/chrome/browser/ui/ui_util.h" | 13 #include "ios/chrome/browser/ui/ui_util.h" |
| 14 #include "ios/chrome/grit/ios_strings.h" |
| 15 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" |
| 16 #include "ui/base/l10n/l10n_util.h" |
10 | 17 |
11 #if !defined(__has_feature) || !__has_feature(objc_arc) | 18 #if !defined(__has_feature) || !__has_feature(objc_arc) |
12 #error "This file requires ARC support." | 19 #error "This file requires ARC support." |
13 #endif | 20 #endif |
14 | 21 |
15 namespace { | 22 namespace { |
16 const CGFloat kSpacingIPhone = 16; | 23 const CGFloat kSpacingIPhone = 16; |
17 const CGFloat kSpacingIPad = 24; | 24 const CGFloat kSpacingIPad = 24; |
18 | 25 |
19 const CGFloat kMaxSearchFieldFrameMargin = 200; | 26 const CGFloat kMaxSearchFieldFrameMargin = 200; |
20 const CGFloat kDoodleTopMarginIPadPortrait = 82; | 27 const CGFloat kDoodleTopMarginIPadPortrait = 82; |
21 const CGFloat kDoodleTopMarginIPadLandscape = 82; | 28 const CGFloat kDoodleTopMarginIPadLandscape = 82; |
22 const CGFloat kNTPSearchFieldBottomPadding = 16; | 29 const CGFloat kNTPSearchFieldBottomPadding = 16; |
23 | 30 |
| 31 const CGFloat kVoiceSearchButtonWidth = 48; |
| 32 |
24 // Height for the doodle frame when Google is not the default search engine. | 33 // Height for the doodle frame when Google is not the default search engine. |
25 const CGFloat kNonGoogleSearchDoodleHeight = 60; | 34 const CGFloat kNonGoogleSearchDoodleHeight = 60; |
26 // Height for the header view on tablet when Google is not the default search | 35 // Height for the header view on tablet when Google is not the default search |
27 // engine. | 36 // engine. |
28 const CGFloat kNonGoogleSearchHeaderHeightIPad = 10; | 37 const CGFloat kNonGoogleSearchHeaderHeightIPad = 10; |
29 | 38 |
30 enum InterfaceOrientation { | 39 enum InterfaceOrientation { |
31 ALL = 0, | 40 ALL = 0, |
32 IPHONE_LANDSCAPE = 1, | 41 IPHONE_LANDSCAPE = 1, |
33 }; | 42 }; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 const CGFloat kTopSpacingMaterialPortrait = 56; | 136 const CGFloat kTopSpacingMaterialPortrait = 56; |
128 const CGFloat kTopSpacingMaterialLandscape = 32; | 137 const CGFloat kTopSpacingMaterialLandscape = 32; |
129 headerHeight += UIInterfaceOrientationIsPortrait(orient) | 138 headerHeight += UIInterfaceOrientationIsPortrait(orient) |
130 ? kTopSpacingMaterialPortrait | 139 ? kTopSpacingMaterialPortrait |
131 : kTopSpacingMaterialLandscape; | 140 : kTopSpacingMaterialLandscape; |
132 } | 141 } |
133 | 142 |
134 return headerHeight; | 143 return headerHeight; |
135 } | 144 } |
136 | 145 |
| 146 void configureSearchHintLabel(UILabel* searchHintLabel, |
| 147 UIButton* searchTapTarget, |
| 148 CGFloat searchFieldWidth) { |
| 149 CGRect hintFrame = CGRectInset(searchTapTarget.bounds, 12, 3); |
| 150 const CGFloat kVoiceSearchOffset = 48; |
| 151 hintFrame.size.width = searchFieldWidth - kVoiceSearchOffset; |
| 152 [searchHintLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; |
| 153 |
| 154 [searchTapTarget addSubview:searchHintLabel]; |
| 155 |
| 156 [NSLayoutConstraint activateConstraints:@[ |
| 157 [searchHintLabel.heightAnchor |
| 158 constraintEqualToConstant:hintFrame.size.height], |
| 159 [searchHintLabel.centerYAnchor |
| 160 constraintEqualToAnchor:searchTapTarget.centerYAnchor] |
| 161 ]]; |
| 162 |
| 163 [searchHintLabel setText:l10n_util::GetNSString(IDS_OMNIBOX_EMPTY_HINT)]; |
| 164 if (base::i18n::IsRTL()) { |
| 165 [searchHintLabel setTextAlignment:NSTextAlignmentRight]; |
| 166 } |
| 167 [searchHintLabel |
| 168 setTextColor:[UIColor |
| 169 colorWithWhite:kiPhoneOmniboxPlaceholderColorBrightness |
| 170 alpha:1.0]]; |
| 171 [searchHintLabel setFont:[MDCTypography subheadFont]]; |
| 172 } |
| 173 |
| 174 void configureVoiceSearchButton(UIButton* voiceSearchButton, |
| 175 UIButton* searchTapTarget) { |
| 176 UIImage* micImage = [UIImage imageNamed:@"voice_icon"]; |
| 177 [voiceSearchButton setTranslatesAutoresizingMaskIntoConstraints:NO]; |
| 178 [searchTapTarget addSubview:voiceSearchButton]; |
| 179 |
| 180 [NSLayoutConstraint activateConstraints:@[ |
| 181 [voiceSearchButton.centerYAnchor |
| 182 constraintEqualToAnchor:searchTapTarget.centerYAnchor], |
| 183 [voiceSearchButton.widthAnchor |
| 184 constraintEqualToConstant:kVoiceSearchButtonWidth], |
| 185 [voiceSearchButton.heightAnchor |
| 186 constraintEqualToAnchor:voiceSearchButton.widthAnchor], |
| 187 ]]; |
| 188 |
| 189 [voiceSearchButton setAdjustsImageWhenHighlighted:NO]; |
| 190 [voiceSearchButton setImage:micImage forState:UIControlStateNormal]; |
| 191 [voiceSearchButton setTag:IDC_VOICE_SEARCH]; |
| 192 [voiceSearchButton setAccessibilityLabel:l10n_util::GetNSString( |
| 193 IDS_IOS_ACCNAME_VOICE_SEARCH)]; |
| 194 [voiceSearchButton setAccessibilityIdentifier:@"Voice Search"]; |
| 195 } |
| 196 |
137 } // namespace content_suggestions | 197 } // namespace content_suggestions |
OLD | NEW |