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 "base/metrics/histogram_macros.h" |
15 #include "components/strings/grit/components_strings.h" | 16 #include "components/strings/grit/components_strings.h" |
16 #include "ios/chrome/browser/experimental_flags.h" | 17 #include "ios/chrome/browser/experimental_flags.h" |
17 #import "ios/chrome/browser/ui/animation_util.h" | 18 #import "ios/chrome/browser/ui/animation_util.h" |
18 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" | 19 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" |
19 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" | 20 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" |
20 #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" |
21 #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" |
22 #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" |
23 #import "ios/chrome/browser/ui/tools_menu/tools_menu_constants.h" | 24 #import "ios/chrome/browser/ui/tools_menu/tools_menu_constants.h" |
24 #import "ios/chrome/browser/ui/tools_menu/tools_menu_model.h" | 25 #import "ios/chrome/browser/ui/tools_menu/tools_menu_model.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_item.h" |
26 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_tools_cell.h" | 27 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_tools_cell.h" |
27 #import "ios/chrome/browser/ui/tools_menu/tools_popup_controller.h" | 28 #import "ios/chrome/browser/ui/tools_menu/tools_popup_controller.h" |
28 #include "ios/chrome/browser/ui/ui_util.h" | 29 #include "ios/chrome/browser/ui/ui_util.h" |
29 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 30 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
30 #import "ios/chrome/common/material_timing.h" | 31 #import "ios/chrome/common/material_timing.h" |
31 #include "ios/chrome/grit/ios_strings.h" | 32 #include "ios/chrome/grit/ios_strings.h" |
32 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 33 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
33 #import "ios/public/provider/chrome/browser/user_feedback/user_feedback_provider
.h" | 34 #import "ios/public/provider/chrome/browser/user_feedback/user_feedback_provider
.h" |
34 #import "ios/shared/chrome/browser/ui/tools_menu/tools_menu_configuration.h" | 35 #import "ios/shared/chrome/browser/ui/tools_menu/tools_menu_configuration.h" |
35 #import "ios/third_party/material_components_ios/src/components/Ink/src/Material
Ink.h" | 36 #import "ios/third_party/material_components_ios/src/components/Ink/src/Material
Ink.h" |
36 #include "ios/web/public/user_agent.h" | 37 #include "ios/web/public/user_agent.h" |
37 #include "ui/base/l10n/l10n_util.h" | 38 #include "ui/base/l10n/l10n_util.h" |
38 #include "ui/base/l10n/l10n_util_mac.h" | 39 #include "ui/base/l10n/l10n_util_mac.h" |
39 | |
40 using ios::material::TimingFunction; | 40 using ios::material::TimingFunction; |
41 | 41 |
42 namespace { | 42 namespace { |
43 | 43 |
44 // Time for ink to fade into view. | 44 // Time for ink to fade into view. |
45 static const NSTimeInterval kMDCInkTouchDelayInterval = 0.15; | 45 static const NSTimeInterval kMDCInkTouchDelayInterval = 0.15; |
46 | 46 |
47 static const CGFloat kMenuItemHeight = 48; | 47 static const CGFloat kMenuItemHeight = 48; |
48 | 48 |
49 static NSString* const kToolsItemCellID = @"ToolsItemCellID"; | 49 static NSString* const kToolsItemCellID = @"ToolsItemCellID"; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 ReadingListMenuNotificationDelegate> { | 107 ReadingListMenuNotificationDelegate> { |
108 base::mac::ObjCPropertyReleaser _propertyReleaser_ToolsMenuViewController; | 108 base::mac::ObjCPropertyReleaser _propertyReleaser_ToolsMenuViewController; |
109 BOOL _waitForInk; | 109 BOOL _waitForInk; |
110 // Weak pointer to ReadingListMenuNotifier, used to set the starting values | 110 // Weak pointer to ReadingListMenuNotifier, used to set the starting values |
111 // for the reading list badge. | 111 // for the reading list badge. |
112 base::WeakNSObject<ReadingListMenuNotifier> _readingListMenuNotifier; | 112 base::WeakNSObject<ReadingListMenuNotifier> _readingListMenuNotifier; |
113 } | 113 } |
114 @property(nonatomic, retain) ToolsMenuCollectionView* menuView; | 114 @property(nonatomic, retain) ToolsMenuCollectionView* menuView; |
115 @property(nonatomic, retain) MDCInkView* touchFeedbackView; | 115 @property(nonatomic, retain) MDCInkView* touchFeedbackView; |
116 @property(nonatomic, assign) ToolbarType toolbarType; | 116 @property(nonatomic, assign) ToolbarType toolbarType; |
| 117 // Populated by the configuration object in |initializeMenuWithConfiguration:| |
| 118 // stores the time this view controller was requested by the user for the |
| 119 // reporting of metrics. |
| 120 @property(nonatomic, assign) NSTimeInterval requestStartTime; |
117 | 121 |
118 // Returns the reading list cell. | 122 // Returns the reading list cell. |
119 - (ReadingListMenuViewCell*)readingListCell; | 123 - (ReadingListMenuViewCell*)readingListCell; |
120 @end | 124 @end |
121 | 125 |
122 @implementation ToolsMenuViewController | 126 @implementation ToolsMenuViewController |
123 | 127 |
124 @synthesize menuView = _menuView; | 128 @synthesize menuView = _menuView; |
125 @synthesize isCurrentPageBookmarked = _isCurrentPageBookmarked; | 129 @synthesize isCurrentPageBookmarked = _isCurrentPageBookmarked; |
126 @synthesize touchFeedbackView = _touchFeedbackView; | 130 @synthesize touchFeedbackView = _touchFeedbackView; |
127 @synthesize isTabLoading = _isTabLoading; | 131 @synthesize isTabLoading = _isTabLoading; |
128 @synthesize toolbarType = _toolbarType; | 132 @synthesize toolbarType = _toolbarType; |
129 @synthesize menuItems = _menuItems; | 133 @synthesize menuItems = _menuItems; |
130 @synthesize delegate = _delegate; | 134 @synthesize delegate = _delegate; |
| 135 @synthesize requestStartTime = _requestStartTime; |
131 | 136 |
132 #pragma mark Public methods | 137 #pragma mark Public methods |
133 | 138 |
134 - (CGFloat)optimalHeight:(CGFloat)suggestedHeight { | 139 - (CGFloat)optimalHeight:(CGFloat)suggestedHeight { |
135 NSInteger numberOfItems = [self.menuItems count]; | 140 NSInteger numberOfItems = [self.menuItems count]; |
136 if (_toolbarType == ToolbarTypeWebiPhone) { | 141 if (_toolbarType == ToolbarTypeWebiPhone) { |
137 // Account for the height of the first row, not included in |menuItems|. | 142 // Account for the height of the first row, not included in |menuItems|. |
138 numberOfItems++; | 143 numberOfItems++; |
139 } | 144 } |
140 CGFloat maxItems = suggestedHeight / kMenuItemHeight; | 145 CGFloat maxItems = suggestedHeight / kMenuItemHeight; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 | 207 |
203 - (void)setIsTabLoading:(BOOL)isTabLoading { | 208 - (void)setIsTabLoading:(BOOL)isTabLoading { |
204 _isTabLoading = isTabLoading; | 209 _isTabLoading = isTabLoading; |
205 | 210 |
206 ToolsMenuViewToolsCell* toolsCell = [self toolsCell]; | 211 ToolsMenuViewToolsCell* toolsCell = [self toolsCell]; |
207 [[toolsCell stopButton] setHidden:!isTabLoading]; | 212 [[toolsCell stopButton] setHidden:!isTabLoading]; |
208 [[toolsCell reloadButton] setHidden:isTabLoading]; | 213 [[toolsCell reloadButton] setHidden:isTabLoading]; |
209 } | 214 } |
210 | 215 |
211 - (void)initializeMenuWithConfiguration:(ToolsMenuConfiguration*)configuration { | 216 - (void)initializeMenuWithConfiguration:(ToolsMenuConfiguration*)configuration { |
| 217 self.requestStartTime = configuration.requestStartTime; |
| 218 |
212 if (configuration.readingListMenuNotifier) { | 219 if (configuration.readingListMenuNotifier) { |
213 _readingListMenuNotifier.reset(configuration.readingListMenuNotifier); | 220 _readingListMenuNotifier.reset(configuration.readingListMenuNotifier); |
214 [configuration.readingListMenuNotifier setDelegate:self]; | 221 [configuration.readingListMenuNotifier setDelegate:self]; |
215 } | 222 } |
216 | 223 |
217 if (IsIPadIdiom()) { | 224 if (IsIPadIdiom()) { |
218 _toolbarType = | 225 _toolbarType = |
219 configuration.hasNoOpenedTabs | 226 configuration.hasNoOpenedTabs |
220 ? ToolbarTypeNoTabsiPad | 227 ? ToolbarTypeNoTabsiPad |
221 : (!IsCompactTablet() ? ToolbarTypeWebiPad : ToolbarTypeWebiPhone); | 228 : (!IsCompactTablet() ? ToolbarTypeWebiPad : ToolbarTypeWebiPhone); |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 subarrayWithRange:NSMakeRange(1, [visibleCells count] - 1)]; | 434 subarrayWithRange:NSMakeRange(1, [visibleCells count] - 1)]; |
428 } else { | 435 } else { |
429 toolsCell = nil; | 436 toolsCell = nil; |
430 } | 437 } |
431 } | 438 } |
432 | 439 |
433 [CATransaction begin]; | 440 [CATransaction begin]; |
434 [CATransaction | 441 [CATransaction |
435 setAnimationTimingFunction:TimingFunction(ios::material::CurveEaseInOut)]; | 442 setAnimationTimingFunction:TimingFunction(ios::material::CurveEaseInOut)]; |
436 [CATransaction setAnimationDuration:ios::material::kDuration5]; | 443 [CATransaction setAnimationDuration:ios::material::kDuration5]; |
| 444 [CATransaction setCompletionBlock:^{ |
| 445 if (self.requestStartTime != 0) { |
| 446 UMA_HISTOGRAM_TIMES( |
| 447 "Toolbar.ShowToolsMenuResponsiveness", |
| 448 base::TimeDelta::FromSecondsD( |
| 449 [NSDate timeIntervalSinceReferenceDate] - self.requestStartTime)); |
| 450 // Reset the start time to ensure that whatever happens, we only record |
| 451 // this once. |
| 452 self.requestStartTime = 0; |
| 453 } |
| 454 |
| 455 }]; |
437 AnimateInViews([toolsCell allButtons], 10, 0); | 456 AnimateInViews([toolsCell allButtons], 10, 0); |
438 AnimateInViews(visibleCells, 0, -10); | 457 AnimateInViews(visibleCells, 0, -10); |
439 [CATransaction commit]; | 458 [CATransaction commit]; |
440 | 459 |
441 [[self readingListCell] | 460 [[self readingListCell] |
442 updateBadgeCount:_readingListMenuNotifier.get().readingListUnreadCount | 461 updateBadgeCount:_readingListMenuNotifier.get().readingListUnreadCount |
443 animated:YES]; | 462 animated:YES]; |
444 [[self readingListCell] | 463 [[self readingListCell] |
445 updateSeenState:_readingListMenuNotifier.get().readingListUnseenItemsExist | 464 updateSeenState:_readingListMenuNotifier.get().readingListUnseenItemsExist |
446 animated:YES]; | 465 animated:YES]; |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 | 628 |
610 - (void)unreadCountChanged:(NSInteger)unreadCount { | 629 - (void)unreadCountChanged:(NSInteger)unreadCount { |
611 [[self readingListCell] updateBadgeCount:unreadCount animated:YES]; | 630 [[self readingListCell] updateBadgeCount:unreadCount animated:YES]; |
612 } | 631 } |
613 | 632 |
614 - (void)unseenStateChanged:(BOOL)unseenItemsExist { | 633 - (void)unseenStateChanged:(BOOL)unseenItemsExist { |
615 [[self readingListCell] updateSeenState:unseenItemsExist animated:YES]; | 634 [[self readingListCell] updateSeenState:unseenItemsExist animated:YES]; |
616 } | 635 } |
617 | 636 |
618 @end | 637 @end |
OLD | NEW |