| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/tools_menu/tools_menu_view_controller.h" | 5 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_controller.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/ios/ios_util.h" | 9 #include "base/ios/ios_util.h" |
| 10 #import "base/ios/weak_nsobject.h" | 10 #import "base/ios/weak_nsobject.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/mac/objc_property_releaser.h" | 12 #include "base/mac/objc_property_releaser.h" |
| 13 #include "base/mac/scoped_nsobject.h" | 13 #include "base/mac/scoped_nsobject.h" |
| 14 #include "base/metrics/field_trial.h" | 14 #include "base/metrics/field_trial.h" |
| 15 #include "components/reading_list/core/reading_list_switches.h" | 15 #include "components/reading_list/core/reading_list_switches.h" |
| 16 #include "components/strings/grit/components_strings.h" | 16 #include "components/strings/grit/components_strings.h" |
| 17 #include "ios/chrome/browser/experimental_flags.h" | 17 #include "ios/chrome/browser/experimental_flags.h" |
| 18 #import "ios/chrome/browser/ui/animation_util.h" | 18 #import "ios/chrome/browser/ui/animation_util.h" |
| 19 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" | 19 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" |
| 20 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" | 20 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" |
| 21 #import "ios/chrome/browser/ui/reading_list/reading_list_menu_notification_deleg
ate.h" | 21 #import "ios/chrome/browser/ui/reading_list/reading_list_menu_notification_deleg
ate.h" |
| 22 #import "ios/chrome/browser/ui/reading_list/reading_list_menu_notifier.h" | 22 #import "ios/chrome/browser/ui/reading_list/reading_list_menu_notifier.h" |
| 23 #include "ios/chrome/browser/ui/rtl_geometry.h" | |
| 24 #include "ios/chrome/browser/ui/toolbar/toolbar_resource_macros.h" | |
| 25 #import "ios/chrome/browser/ui/tools_menu/reading_list_menu_view_item.h" | 23 #import "ios/chrome/browser/ui/tools_menu/reading_list_menu_view_item.h" |
| 26 #import "ios/chrome/browser/ui/tools_menu/tools_menu_context.h" | 24 #import "ios/chrome/browser/ui/tools_menu/tools_menu_context.h" |
| 27 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_item.h" | 25 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_item.h" |
| 26 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_tools_cell.h" |
| 28 #import "ios/chrome/browser/ui/tools_menu/tools_popup_controller.h" | 27 #import "ios/chrome/browser/ui/tools_menu/tools_popup_controller.h" |
| 29 #include "ios/chrome/browser/ui/ui_util.h" | 28 #include "ios/chrome/browser/ui/ui_util.h" |
| 30 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 29 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 31 #import "ios/chrome/common/material_timing.h" | 30 #import "ios/chrome/common/material_timing.h" |
| 32 #include "ios/chrome/grit/ios_strings.h" | 31 #include "ios/chrome/grit/ios_strings.h" |
| 33 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 32 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
| 34 #import "ios/public/provider/chrome/browser/user_feedback/user_feedback_provider
.h" | 33 #import "ios/public/provider/chrome/browser/user_feedback/user_feedback_provider
.h" |
| 35 #import "ios/third_party/material_components_ios/src/components/Ink/src/Material
Ink.h" | 34 #import "ios/third_party/material_components_ios/src/components/Ink/src/Material
Ink.h" |
| 36 #include "ui/base/l10n/l10n_util.h" | 35 #include "ui/base/l10n/l10n_util.h" |
| 37 #include "ui/base/l10n/l10n_util_mac.h" | 36 #include "ui/base/l10n/l10n_util_mac.h" |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 setTimingFunction:TimingFunction(ios::material::CurveEaseOut)]; | 210 setTimingFunction:TimingFunction(ios::material::CurveEaseOut)]; |
| 212 [fadeAnimation setBeginTime:beginTime]; | 211 [fadeAnimation setBeginTime:beginTime]; |
| 213 | 212 |
| 214 [[view layer] | 213 [[view layer] |
| 215 addAnimation:AnimationGroupMake(@[ transformAnimation, fadeAnimation ]) | 214 addAnimation:AnimationGroupMake(@[ transformAnimation, fadeAnimation ]) |
| 216 forKey:@"animateIn"]; | 215 forKey:@"animateIn"]; |
| 217 }]; | 216 }]; |
| 218 } | 217 } |
| 219 } // anonymous namespace | 218 } // anonymous namespace |
| 220 | 219 |
| 221 @interface ToolsMenuButton : UIButton | |
| 222 @end | |
| 223 | |
| 224 @implementation ToolsMenuButton | |
| 225 | |
| 226 @end | |
| 227 | |
| 228 @interface ToolsMenuCollectionView : UICollectionView | 220 @interface ToolsMenuCollectionView : UICollectionView |
| 229 @property(nonatomic, assign) CGPoint touchBeginPoint; | 221 @property(nonatomic, assign) CGPoint touchBeginPoint; |
| 230 @property(nonatomic, assign) CGPoint touchEndPoint; | 222 @property(nonatomic, assign) CGPoint touchEndPoint; |
| 231 @end | 223 @end |
| 232 | 224 |
| 233 @implementation ToolsMenuCollectionView | 225 @implementation ToolsMenuCollectionView |
| 234 | 226 |
| 235 @synthesize touchBeginPoint = _touchBeginPoint; | 227 @synthesize touchBeginPoint = _touchBeginPoint; |
| 236 @synthesize touchEndPoint = _touchEndPoint; | 228 @synthesize touchEndPoint = _touchEndPoint; |
| 237 | 229 |
| 238 - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { | 230 - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { |
| 239 _touchBeginPoint = [[touches anyObject] locationInView:self]; | 231 _touchBeginPoint = [[touches anyObject] locationInView:self]; |
| 240 [super touchesBegan:touches withEvent:event]; | 232 [super touchesBegan:touches withEvent:event]; |
| 241 } | 233 } |
| 242 | 234 |
| 243 - (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event { | 235 - (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event { |
| 244 _touchEndPoint = [[touches anyObject] locationInView:self]; | 236 _touchEndPoint = [[touches anyObject] locationInView:self]; |
| 245 [super touchesEnded:touches withEvent:event]; | 237 [super touchesEnded:touches withEvent:event]; |
| 246 } | 238 } |
| 247 | 239 |
| 248 @end | 240 @end |
| 249 | 241 |
| 250 @interface ToolsMenuViewToolsCell : UICollectionViewCell | |
| 251 @property(nonatomic, retain) ToolsMenuButton* reloadButton; | |
| 252 @property(nonatomic, retain) ToolsMenuButton* shareButton; | |
| 253 @property(nonatomic, retain) ToolsMenuButton* starButton; | |
| 254 @property(nonatomic, retain) ToolsMenuButton* starredButton; | |
| 255 @property(nonatomic, retain) ToolsMenuButton* stopButton; | |
| 256 @property(nonatomic, retain) ToolsMenuButton* toolsButton; | |
| 257 @end | |
| 258 | |
| 259 @implementation ToolsMenuViewToolsCell { | |
| 260 base::mac::ObjCPropertyReleaser _propertyReleaser_ToolsMenuViewToolsCell; | |
| 261 } | |
| 262 | |
| 263 @synthesize reloadButton = _reloadButton; | |
| 264 @synthesize shareButton = _shareButton; | |
| 265 @synthesize starButton = _starButton; | |
| 266 @synthesize starredButton = _starredButton; | |
| 267 @synthesize stopButton = _stopButton; | |
| 268 @synthesize toolsButton = _toolsButton; | |
| 269 | |
| 270 - (instancetype)initWithCoder:(NSCoder*)aDecoder { | |
| 271 self = [super initWithCoder:aDecoder]; | |
| 272 if (self) | |
| 273 [self commonInitialization]; | |
| 274 | |
| 275 return self; | |
| 276 } | |
| 277 | |
| 278 - (instancetype)initWithFrame:(CGRect)frame { | |
| 279 self = [super initWithFrame:frame]; | |
| 280 if (self) | |
| 281 [self commonInitialization]; | |
| 282 | |
| 283 return self; | |
| 284 } | |
| 285 | |
| 286 - (void)commonInitialization { | |
| 287 _propertyReleaser_ToolsMenuViewToolsCell.Init(self, | |
| 288 [ToolsMenuViewToolsCell class]); | |
| 289 | |
| 290 [self setBackgroundColor:[UIColor whiteColor]]; | |
| 291 [self setOpaque:YES]; | |
| 292 | |
| 293 int star[2][3] = TOOLBAR_IDR_TWO_STATE(STAR); | |
| 294 _starButton = [self newButtonForImageIds:star | |
| 295 commandID:IDC_BOOKMARK_PAGE | |
| 296 accessibilityLabelID:IDS_BOOKMARK_ADD_EDITOR_TITLE | |
| 297 automationName:@"Add Bookmark"]; | |
| 298 | |
| 299 int star_pressed[2][3] = TOOLBAR_IDR_ONE_STATE(STAR_PRESSED); | |
| 300 _starredButton = [self newButtonForImageIds:star_pressed | |
| 301 commandID:IDC_TEMP_EDIT_BOOKMARK | |
| 302 accessibilityLabelID:IDS_IOS_TOOLS_MENU_EDIT_BOOKMARK | |
| 303 automationName:@"Edit Bookmark"]; | |
| 304 | |
| 305 int reload[2][3] = TOOLBAR_IDR_TWO_STATE(RELOAD); | |
| 306 _reloadButton = [self newButtonForImageIds:reload | |
| 307 commandID:IDC_RELOAD | |
| 308 accessibilityLabelID:IDS_IOS_ACCNAME_RELOAD | |
| 309 automationName:@"Reload" | |
| 310 reverseForRTL:YES]; | |
| 311 | |
| 312 int stop[2][3] = TOOLBAR_IDR_TWO_STATE(STOP); | |
| 313 _stopButton = [self newButtonForImageIds:stop | |
| 314 commandID:IDC_STOP | |
| 315 accessibilityLabelID:IDS_IOS_ACCNAME_STOP | |
| 316 automationName:@"Stop"]; | |
| 317 | |
| 318 int share[2][3] = TOOLBAR_IDR_THREE_STATE(SHARE); | |
| 319 _shareButton = [self newButtonForImageIds:share | |
| 320 commandID:IDC_SHARE_PAGE | |
| 321 accessibilityLabelID:IDS_IOS_TOOLS_MENU_SHARE | |
| 322 automationName:@"Stop"]; | |
| 323 int tools[2][3] = TOOLBAR_IDR_ONE_STATE(TOOLS_PRESSED); | |
| 324 _toolsButton = | |
| 325 [self newButtonForImageIds:tools | |
| 326 commandID:IDC_SHOW_TOOLS_MENU | |
| 327 accessibilityLabelID:IDS_IOS_TOOLBAR_CLOSE_MENU | |
| 328 automationName:@"kToolbarToolsMenuButtonIdentifier"]; | |
| 329 | |
| 330 UIView* contentView = [self contentView]; | |
| 331 [contentView setBackgroundColor:[self backgroundColor]]; | |
| 332 [contentView setOpaque:YES]; | |
| 333 | |
| 334 [contentView addSubview:_starredButton]; | |
| 335 [contentView addSubview:_starButton]; | |
| 336 [contentView addSubview:_stopButton]; | |
| 337 [contentView addSubview:_reloadButton]; | |
| 338 [contentView addSubview:_shareButton]; | |
| 339 | |
| 340 [self addConstraints]; | |
| 341 } | |
| 342 | |
| 343 - (ToolsMenuButton*)newButtonForImageIds:(int[2][3])imageIds | |
| 344 commandID:(int)commandID | |
| 345 accessibilityLabelID:(int)labelID | |
| 346 automationName:(NSString*)name { | |
| 347 return [self newButtonForImageIds:imageIds | |
| 348 commandID:commandID | |
| 349 accessibilityLabelID:labelID | |
| 350 automationName:name | |
| 351 reverseForRTL:NO]; | |
| 352 } | |
| 353 | |
| 354 - (ToolsMenuButton*)newButtonForImageIds:(int[2][3])imageIds | |
| 355 commandID:(int)commandID | |
| 356 accessibilityLabelID:(int)labelID | |
| 357 automationName:(NSString*)name | |
| 358 reverseForRTL:(BOOL)reverseForRTL { | |
| 359 ToolsMenuButton* button = [[ToolsMenuButton alloc] initWithFrame:CGRectZero]; | |
| 360 [button setTranslatesAutoresizingMaskIntoConstraints:NO]; | |
| 361 | |
| 362 if (imageIds[0][0]) { | |
| 363 [button setImage:NativeReversableImage(imageIds[0][0], reverseForRTL) | |
| 364 forState:UIControlStateNormal]; | |
| 365 } | |
| 366 [[button imageView] setContentMode:UIViewContentModeCenter]; | |
| 367 [button setBackgroundColor:[self backgroundColor]]; | |
| 368 [button setTag:commandID]; | |
| 369 [button setOpaque:YES]; | |
| 370 | |
| 371 SetA11yLabelAndUiAutomationName(button, labelID, name); | |
| 372 | |
| 373 if (imageIds[0][1]) { | |
| 374 UIImage* pressedImage = | |
| 375 NativeReversableImage(imageIds[0][1], reverseForRTL); | |
| 376 if (pressedImage) { | |
| 377 [button setImage:pressedImage forState:UIControlStateHighlighted]; | |
| 378 } | |
| 379 } | |
| 380 | |
| 381 if (imageIds[0][2]) { | |
| 382 UIImage* disabledImage = | |
| 383 NativeReversableImage(imageIds[0][2], reverseForRTL); | |
| 384 if (disabledImage) { | |
| 385 [button setImage:disabledImage forState:UIControlStateDisabled]; | |
| 386 } | |
| 387 } | |
| 388 | |
| 389 return button; | |
| 390 } | |
| 391 | |
| 392 - (void)addConstraints { | |
| 393 UIView* contentView = [self contentView]; | |
| 394 | |
| 395 for (UIButton* button in [self allButtons]) { | |
| 396 NSDictionary* view = @{ @"button" : button }; | |
| 397 NSArray* constraints = @[ @"V:|-(0)-[button]-(0)-|", @"H:[button(==48)]" ]; | |
| 398 ApplyVisualConstraints(constraints, view, self); | |
| 399 } | |
| 400 | |
| 401 NSDictionary* views = @{ | |
| 402 @"share" : _shareButton, | |
| 403 @"star" : _starButton, | |
| 404 @"reload" : _reloadButton, | |
| 405 @"starred" : _starredButton, | |
| 406 @"stop" : _stopButton | |
| 407 }; | |
| 408 // Leading offset is 16, minus the button image inset of 12. | |
| 409 NSDictionary* metrics = @{ @"offset" : @4, @"space" : @24 }; | |
| 410 // clang-format off | |
| 411 NSArray* constraints = @[ | |
| 412 @"H:|-(offset)-[share]-(space)-[star]-(space)-[reload]", | |
| 413 @"H:[share]-(space)-[starred]", | |
| 414 @"H:[star]-(space)-[stop]" | |
| 415 ]; | |
| 416 // clang-format on | |
| 417 ApplyVisualConstraintsWithMetricsAndOptions( | |
| 418 constraints, views, metrics, LayoutOptionForRTLSupport(), contentView); | |
| 419 } | |
| 420 | |
| 421 // These should be added in display order, so they are animated in display | |
| 422 // order. | |
| 423 - (NSArray*)allButtons { | |
| 424 NSMutableArray* allButtons = [NSMutableArray array]; | |
| 425 if (_shareButton) | |
| 426 [allButtons addObject:_shareButton]; | |
| 427 | |
| 428 if (_starButton) | |
| 429 [allButtons addObject:_starButton]; | |
| 430 | |
| 431 if (_starredButton) | |
| 432 [allButtons addObject:_starredButton]; | |
| 433 | |
| 434 if (_reloadButton) | |
| 435 [allButtons addObject:_reloadButton]; | |
| 436 | |
| 437 if (_stopButton) | |
| 438 [allButtons addObject:_stopButton]; | |
| 439 | |
| 440 return allButtons; | |
| 441 } | |
| 442 | |
| 443 @end | |
| 444 | |
| 445 // Class Extension for private methods. | 242 // Class Extension for private methods. |
| 446 @interface ToolsMenuViewController ()<UICollectionViewDelegateFlowLayout, | 243 @interface ToolsMenuViewController ()<UICollectionViewDelegateFlowLayout, |
| 447 UICollectionViewDataSource, | 244 UICollectionViewDataSource, |
| 448 ReadingListMenuNotificationDelegate> { | 245 ReadingListMenuNotificationDelegate> { |
| 449 base::mac::ObjCPropertyReleaser _propertyReleaser_ToolsMenuViewController; | 246 base::mac::ObjCPropertyReleaser _propertyReleaser_ToolsMenuViewController; |
| 450 BOOL _waitForInk; | 247 BOOL _waitForInk; |
| 451 // Weak pointer to ReadingListMenuNotifier, used to set the starting values | 248 // Weak pointer to ReadingListMenuNotifier, used to set the starting values |
| 452 // for the reading list badge. | 249 // for the reading list badge. |
| 453 base::WeakNSObject<ReadingListMenuNotifier> _readingListMenuNotifier; | 250 base::WeakNSObject<ReadingListMenuNotifier> _readingListMenuNotifier; |
| 454 } | 251 } |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 | 737 |
| 941 - (void)unreadCountChanged:(NSInteger)unreadCount { | 738 - (void)unreadCountChanged:(NSInteger)unreadCount { |
| 942 [[self readingListCell] updateBadgeCount:unreadCount animated:YES]; | 739 [[self readingListCell] updateBadgeCount:unreadCount animated:YES]; |
| 943 } | 740 } |
| 944 | 741 |
| 945 - (void)unseenStateChanged:(BOOL)unseenItemsExist { | 742 - (void)unseenStateChanged:(BOOL)unseenItemsExist { |
| 946 [[self readingListCell] updateSeenState:unseenItemsExist animated:YES]; | 743 [[self readingListCell] updateSeenState:unseenItemsExist animated:YES]; |
| 947 } | 744 } |
| 948 | 745 |
| 949 @end | 746 @end |
| OLD | NEW |