OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/reading_list/reading_list_toolbar.h" | 5 #import "ios/chrome/browser/ui/reading_list/reading_list_toolbar.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #import "ios/chrome/browser/ui/alert_coordinator/action_sheet_coordinator.h" | 8 #import "ios/chrome/browser/ui/alert_coordinator/action_sheet_coordinator.h" |
9 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" | 9 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" |
10 #include "ios/chrome/browser/ui/rtl_geometry.h" | 10 #include "ios/chrome/browser/ui/rtl_geometry.h" |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 UIColor* textColor = isDestructive ? [[MDCPalette cr_redPalette] tint500] | 243 UIColor* textColor = isDestructive ? [[MDCPalette cr_redPalette] tint500] |
244 : [[MDCPalette cr_bluePalette] tint500]; | 244 : [[MDCPalette cr_bluePalette] tint500]; |
245 [button setTitleColor:textColor forState:UIControlStateNormal]; | 245 [button setTitleColor:textColor forState:UIControlStateNormal]; |
246 [button setTitleColor:[UIColor lightGrayColor] | 246 [button setTitleColor:[UIColor lightGrayColor] |
247 forState:UIControlStateDisabled]; | 247 forState:UIControlStateDisabled]; |
248 [button setTitleColor:[textColor colorWithAlphaComponent:0.3] | 248 [button setTitleColor:[textColor colorWithAlphaComponent:0.3] |
249 forState:UIControlStateHighlighted]; | 249 forState:UIControlStateHighlighted]; |
250 [[button titleLabel] | 250 [[button titleLabel] |
251 setFont:[[MDCTypography fontLoader] regularFontOfSize:14]]; | 251 setFont:[[MDCTypography fontLoader] regularFontOfSize:14]]; |
252 | 252 |
253 NSTextAlignment textAlignement; | |
254 UIControlContentHorizontalAlignment horizontalAlignement; | 253 UIControlContentHorizontalAlignment horizontalAlignement; |
255 | 254 |
256 switch (position) { | 255 switch (position) { |
257 case Leading: | 256 case Leading: |
258 if (UseRTLLayout()) { | 257 if (UseRTLLayout()) { |
259 horizontalAlignement = UIControlContentHorizontalAlignmentRight; | 258 horizontalAlignement = UIControlContentHorizontalAlignmentRight; |
260 textAlignement = NSTextAlignmentRight; | |
261 } else { | 259 } else { |
262 horizontalAlignement = UIControlContentHorizontalAlignmentLeft; | 260 horizontalAlignement = UIControlContentHorizontalAlignmentLeft; |
263 textAlignement = NSTextAlignmentLeft; | |
264 } | 261 } |
265 break; | 262 break; |
266 | 263 |
267 case Centered: | 264 case Centered: |
268 horizontalAlignement = UIControlContentHorizontalAlignmentCenter; | 265 horizontalAlignement = UIControlContentHorizontalAlignmentCenter; |
269 textAlignement = NSTextAlignmentCenter; | |
270 break; | 266 break; |
271 | 267 |
272 case Trailing: | 268 case Trailing: |
273 if (UseRTLLayout()) { | 269 if (UseRTLLayout()) { |
274 horizontalAlignement = UIControlContentHorizontalAlignmentLeft; | 270 horizontalAlignement = UIControlContentHorizontalAlignmentLeft; |
275 textAlignement = NSTextAlignmentLeft; | |
276 } else { | 271 } else { |
277 horizontalAlignement = UIControlContentHorizontalAlignmentRight; | 272 horizontalAlignement = UIControlContentHorizontalAlignmentRight; |
278 textAlignement = NSTextAlignmentRight; | |
279 } | 273 } |
280 break; | 274 break; |
281 } | 275 } |
282 | 276 |
283 button.contentHorizontalAlignment = horizontalAlignement; | 277 button.contentHorizontalAlignment = horizontalAlignement; |
284 button.titleLabel.textAlignment = textAlignement; | 278 button.titleLabel.textAlignment = NSTextAlignmentCenter; |
285 | 279 |
286 return button; | 280 return button; |
287 } | 281 } |
288 | 282 |
289 - (void)setMarkButtonText:(NSString*)text { | 283 - (void)setMarkButtonText:(NSString*)text { |
290 [self.markButton setTitle:text forState:UIControlStateNormal]; | 284 [self.markButton setTitle:text forState:UIControlStateNormal]; |
291 } | 285 } |
292 | 286 |
293 - (void)updateHeight { | 287 - (void)updateHeight { |
294 for (UIButton* button in | 288 for (UIButton* button in |
295 @[ _deleteButton, _deleteAllButton, _markButton, _cancelButton ]) { | 289 @[ _deleteButton, _deleteAllButton, _markButton, _cancelButton ]) { |
296 if (!button.hidden) { | 290 if (!button.hidden) { |
297 CGFloat rect = [button.titleLabel.text | 291 CGFloat rect = [button.titleLabel.text |
298 cr_pixelAlignedSizeWithFont:button.titleLabel.font] | 292 cr_pixelAlignedSizeWithFont:button.titleLabel.font] |
299 .width; | 293 .width; |
300 if (rect > (self.frame.size.width - 2 * kHorizontalMargin - | 294 if (rect > (self.frame.size.width - 2 * kHorizontalMargin - |
301 2 * kHorizontalSpacing) / | 295 2 * kHorizontalSpacing) / |
302 3 - | 296 3 - |
303 16) { | 297 16) { |
304 [self.heightDelegate toolbar:self onHeightChanged:ExpandedHeight]; | 298 [self.heightDelegate toolbar:self onHeightChanged:ExpandedHeight]; |
305 return; | 299 return; |
306 } | 300 } |
307 } | 301 } |
308 } | 302 } |
309 [self.heightDelegate toolbar:self onHeightChanged:NormalHeight]; | 303 [self.heightDelegate toolbar:self onHeightChanged:NormalHeight]; |
310 } | 304 } |
311 | 305 |
312 @end | 306 @end |
OLD | NEW |