Chromium Code Reviews| 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 #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" |
| 24 #import "ios/chrome/browser/ui/tools_menu/tools_menu_context.h" | 24 #import "ios/chrome/browser/ui/tools_menu/tools_menu_configuration.h" |
| 25 #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" | 26 #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" | 27 #import "ios/chrome/browser/ui/tools_menu/tools_popup_controller.h" |
| 28 #include "ios/chrome/browser/ui/ui_util.h" | 28 #include "ios/chrome/browser/ui/ui_util.h" |
| 29 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 29 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 30 #import "ios/chrome/common/material_timing.h" | 30 #import "ios/chrome/common/material_timing.h" |
| 31 #include "ios/chrome/grit/ios_strings.h" | 31 #include "ios/chrome/grit/ios_strings.h" |
| 32 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 32 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
| 33 #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" |
| 34 #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" |
| 35 #include "ios/web/public/user_agent.h" | |
| 35 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/l10n/l10n_util.h" |
| 36 #include "ui/base/l10n/l10n_util_mac.h" | 37 #include "ui/base/l10n/l10n_util_mac.h" |
| 37 | 38 |
| 38 using ios::material::TimingFunction; | 39 using ios::material::TimingFunction; |
| 39 | 40 |
| 40 NSString* const kToolsMenuNewTabId = @"kToolsMenuNewTabId"; | 41 NSString* const kToolsMenuNewTabId = @"kToolsMenuNewTabId"; |
| 41 NSString* const kToolsMenuNewIncognitoTabId = @"kToolsMenuNewIncognitoTabId"; | 42 NSString* const kToolsMenuNewIncognitoTabId = @"kToolsMenuNewIncognitoTabId"; |
| 42 NSString* const kToolsMenuCloseAllTabsId = @"kToolsMenuCloseAllTabsId"; | 43 NSString* const kToolsMenuCloseAllTabsId = @"kToolsMenuCloseAllTabsId"; |
| 43 NSString* const kToolsMenuCloseAllIncognitoTabsId = | 44 NSString* const kToolsMenuCloseAllIncognitoTabsId = |
| 44 @"kToolsMenuCloseAllIncognitoTabsId"; | 45 @"kToolsMenuCloseAllIncognitoTabsId"; |
| 45 NSString* const kToolsMenuBookmarksId = @"kToolsMenuBookmarksId"; | 46 NSString* const kToolsMenuBookmarksId = @"kToolsMenuBookmarksId"; |
| 46 NSString* const kToolsMenuReadingListId = @"kToolsMenuReadingListId"; | 47 NSString* const kToolsMenuReadingListId = @"kToolsMenuReadingListId"; |
| 47 NSString* const kToolsMenuOtherDevicesId = @"kToolsMenuOtherDevicesId"; | 48 NSString* const kToolsMenuOtherDevicesId = @"kToolsMenuOtherDevicesId"; |
| 48 NSString* const kToolsMenuHistoryId = @"kToolsMenuHistoryId"; | 49 NSString* const kToolsMenuHistoryId = @"kToolsMenuHistoryId"; |
| 49 NSString* const kToolsMenuReportAnIssueId = @"kToolsMenuReportAnIssueId"; | 50 NSString* const kToolsMenuReportAnIssueId = @"kToolsMenuReportAnIssueId"; |
| 50 NSString* const kToolsMenuFindInPageId = @"kToolsMenuFindInPageId"; | 51 NSString* const kToolsMenuFindInPageId = @"kToolsMenuFindInPageId"; |
| 51 NSString* const kToolsMenuReaderMode = @"kToolsMenuReaderMode"; | 52 NSString* const kToolsMenuReaderMode = @"kToolsMenuReaderMode"; |
| 52 NSString* const kToolsMenuRequestDesktopId = @"kToolsMenuRequestDesktopId"; | 53 NSString* const kToolsMenuRequestDesktopId = @"kToolsMenuRequestDesktopId"; |
| 54 NSString* const kToolsMenuRequestMobileId = @"kToolsMenuRequestMobileId"; | |
| 53 NSString* const kToolsMenuSettingsId = @"kToolsMenuSettingsId"; | 55 NSString* const kToolsMenuSettingsId = @"kToolsMenuSettingsId"; |
| 54 NSString* const kToolsMenuHelpId = @"kToolsMenuHelpId"; | 56 NSString* const kToolsMenuHelpId = @"kToolsMenuHelpId"; |
| 55 NSString* const kToolsMenuSuggestionsId = @"kToolsMenuSuggestionsId"; | 57 NSString* const kToolsMenuSuggestionsId = @"kToolsMenuSuggestionsId"; |
| 56 | 58 |
| 57 namespace { | 59 namespace { |
| 58 | 60 |
| 59 // Time for ink to fade into view. | 61 // Time for ink to fade into view. |
| 60 static const NSTimeInterval kMDCInkTouchDelayInterval = 0.15; | 62 static const NSTimeInterval kMDCInkTouchDelayInterval = 0.15; |
| 61 | 63 |
| 62 static const CGFloat kMenuItemHeight = 48; | 64 static const CGFloat kMenuItemHeight = 48; |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 91 kToolbarTypeWebiPad = 1 << 1, | 93 kToolbarTypeWebiPad = 1 << 1, |
| 92 kToolbarTypeNoTabsiPad = 1 << 2, | 94 kToolbarTypeNoTabsiPad = 1 << 2, |
| 93 kToolbarTypeSwitcheriPhone = 1 << 3, | 95 kToolbarTypeSwitcheriPhone = 1 << 3, |
| 94 kToolbarTypeWebAll = kToolbarTypeWebiPhone | kToolbarTypeWebiPad, | 96 kToolbarTypeWebAll = kToolbarTypeWebiPhone | kToolbarTypeWebiPad, |
| 95 kToolbarTypeAll = kToolbarTypeWebAll | | 97 kToolbarTypeAll = kToolbarTypeWebAll | |
| 96 kToolbarTypeSwitcheriPhone | | 98 kToolbarTypeSwitcheriPhone | |
| 97 kToolbarTypeNoTabsiPad, | 99 kToolbarTypeNoTabsiPad, |
| 98 // clang-format on | 100 // clang-format on |
| 99 }; | 101 }; |
| 100 | 102 |
| 101 // Declare all the possible items. | 103 // Declares all the possible items. |
| 102 static MenuItemInfo itemInfoList[] = { | 104 static MenuItemInfo itemInfoList[] = { |
| 103 // clang-format off | 105 // clang-format off |
| 104 { IDS_IOS_TOOLS_MENU_NEW_TAB, kToolsMenuNewTabId, | 106 { IDS_IOS_TOOLS_MENU_NEW_TAB, kToolsMenuNewTabId, |
| 105 IDC_NEW_TAB, kToolbarTypeAll, | 107 IDC_NEW_TAB, kToolbarTypeAll, |
| 106 0, nil }, | 108 0, nil }, |
| 107 { IDS_IOS_TOOLS_MENU_NEW_INCOGNITO_TAB, kToolsMenuNewIncognitoTabId, | 109 { IDS_IOS_TOOLS_MENU_NEW_INCOGNITO_TAB, kToolsMenuNewIncognitoTabId, |
| 108 IDC_NEW_INCOGNITO_TAB, kToolbarTypeAll, | 110 IDC_NEW_INCOGNITO_TAB, kToolbarTypeAll, |
| 109 0, nil }, | 111 0, nil }, |
| 110 { IDS_IOS_TOOLS_MENU_CLOSE_ALL_TABS, kToolsMenuCloseAllTabsId, | 112 { IDS_IOS_TOOLS_MENU_CLOSE_ALL_TABS, kToolsMenuCloseAllTabsId, |
| 111 IDC_CLOSE_ALL_TABS, kToolbarTypeSwitcheriPhone, | 113 IDC_CLOSE_ALL_TABS, kToolbarTypeSwitcheriPhone, |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 131 0, nil }, | 133 0, nil }, |
| 132 { IDS_IOS_OPTIONS_REPORT_AN_ISSUE, kToolsMenuReportAnIssueId, | 134 { IDS_IOS_OPTIONS_REPORT_AN_ISSUE, kToolsMenuReportAnIssueId, |
| 133 IDC_REPORT_AN_ISSUE, kToolbarTypeAll, | 135 IDC_REPORT_AN_ISSUE, kToolbarTypeAll, |
| 134 0, nil }, | 136 0, nil }, |
| 135 { IDS_IOS_TOOLS_MENU_FIND_IN_PAGE, kToolsMenuFindInPageId, | 137 { IDS_IOS_TOOLS_MENU_FIND_IN_PAGE, kToolsMenuFindInPageId, |
| 136 IDC_FIND, kToolbarTypeWebAll, | 138 IDC_FIND, kToolbarTypeWebAll, |
| 137 0, nil }, | 139 0, nil }, |
| 138 { IDS_IOS_TOOLS_MENU_REQUEST_DESKTOP_SITE, kToolsMenuRequestDesktopId, | 140 { IDS_IOS_TOOLS_MENU_REQUEST_DESKTOP_SITE, kToolsMenuRequestDesktopId, |
| 139 IDC_REQUEST_DESKTOP_SITE, kToolbarTypeWebAll, | 141 IDC_REQUEST_DESKTOP_SITE, kToolbarTypeWebAll, |
| 140 0, nil }, | 142 0, nil }, |
| 143 { IDS_IOS_TOOLS_MENU_REQUEST_MOBILE_SITE, kToolsMenuRequestMobileId, | |
| 144 IDC_REQUEST_MOBILE_SITE, kToolbarTypeWebAll, | |
| 145 0, nil }, | |
| 141 { IDS_IOS_TOOLS_MENU_READER_MODE, kToolsMenuReaderMode, | 146 { IDS_IOS_TOOLS_MENU_READER_MODE, kToolsMenuReaderMode, |
| 142 IDC_READER_MODE, kToolbarTypeWebAll, | 147 IDC_READER_MODE, kToolbarTypeWebAll, |
| 143 0, nil }, | 148 0, nil }, |
| 144 { IDS_IOS_TOOLS_MENU_SETTINGS, kToolsMenuSettingsId, | 149 { IDS_IOS_TOOLS_MENU_SETTINGS, kToolsMenuSettingsId, |
| 145 IDC_OPTIONS, kToolbarTypeAll, | 150 IDC_OPTIONS, kToolbarTypeAll, |
| 146 0, nil }, | 151 0, nil }, |
| 147 { IDS_IOS_TOOLS_MENU_HELP_MOBILE, kToolsMenuHelpId, | 152 { IDS_IOS_TOOLS_MENU_HELP_MOBILE, kToolsMenuHelpId, |
| 148 IDC_HELP_PAGE_VIA_MENU, kToolbarTypeWebAll, | 153 IDC_HELP_PAGE_VIA_MENU, kToolbarTypeWebAll, |
| 149 0, nil }, | 154 0, nil }, |
| 150 // clang-format on | 155 // clang-format on |
| 151 }; | 156 }; |
| 152 | 157 |
| 153 NS_INLINE BOOL ItemShouldBeVisible(const MenuItemInfo& item, | 158 NS_INLINE BOOL ItemShouldBeVisible(const MenuItemInfo& item, |
| 154 BOOL incognito, | 159 kToolbarType toolbarType, |
| 155 kToolbarType toolbarType) { | 160 ToolsMenuConfiguration* configuration) { |
| 156 if (!(item.toolbar_types & toolbarType)) | 161 if (!(item.toolbar_types & toolbarType)) |
| 157 return NO; | 162 return NO; |
| 158 | 163 |
| 159 if (incognito && (item.visibility & kVisibleNotIncognitoOnly)) | 164 if (configuration.inIncognito && (item.visibility & kVisibleNotIncognitoOnly)) |
| 160 return NO; | 165 return NO; |
| 161 | 166 |
| 162 if (!incognito && (item.visibility & kVisibleIncognitoOnly)) | 167 if (!configuration.inIncognito && (item.visibility & kVisibleIncognitoOnly)) |
| 163 return NO; | 168 return NO; |
| 164 | 169 |
| 165 if (item.title_id == IDS_IOS_TOOLBAR_SHOW_TABS) { | 170 if (item.title_id == IDS_IOS_TOOLBAR_SHOW_TABS) { |
| 166 if (!IsIPadIdiom()) { | 171 if (!IsIPadIdiom()) { |
| 167 return NO; | 172 return NO; |
| 168 } | 173 } |
| 169 } | 174 } |
| 170 | 175 |
| 171 if (item.title_id == IDS_IOS_TOOLS_MENU_READER_MODE) { | 176 if (item.title_id == IDS_IOS_TOOLS_MENU_READER_MODE) { |
| 172 if (!experimental_flags::IsReaderModeEnabled()) { | 177 if (!experimental_flags::IsReaderModeEnabled()) { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 187 } | 192 } |
| 188 | 193 |
| 189 if (item.title_id == IDS_IOS_OPTIONS_REPORT_AN_ISSUE) { | 194 if (item.title_id == IDS_IOS_OPTIONS_REPORT_AN_ISSUE) { |
| 190 if (!ios::GetChromeBrowserProvider() | 195 if (!ios::GetChromeBrowserProvider() |
| 191 ->GetUserFeedbackProvider() | 196 ->GetUserFeedbackProvider() |
| 192 ->IsUserFeedbackEnabled()) { | 197 ->IsUserFeedbackEnabled()) { |
| 193 return NO; | 198 return NO; |
| 194 } | 199 } |
| 195 } | 200 } |
| 196 | 201 |
| 202 // TODO(crbug.com/696676): Talk to UI/UX people to decide the correct behavior | |
| 203 // of "Requestion Desktop/Mobile Site" (e.g. Whether user agent flag should | |
| 204 // stick when going backward and which cell should be visible when navigating | |
| 205 // to native pages). | |
| 206 if (item.title_id == IDS_IOS_TOOLS_MENU_REQUEST_DESKTOP_SITE) { | |
| 207 if (configuration.userAgentType == web::UserAgentType::DESKTOP) | |
| 208 return NO; | |
| 209 } | |
| 210 | |
| 211 if (item.title_id == IDS_IOS_TOOLS_MENU_REQUEST_MOBILE_SITE) { | |
| 212 if (configuration.userAgentType == web::UserAgentType::NONE || | |
|
Eugene But (OOO till 7-30)
2017/03/03 02:30:25
Maybe |configuration.userAgentType ! web::UserAgen
liaoyuke
2017/03/03 23:39:42
Done.
| |
| 213 configuration.userAgentType == web::UserAgentType::MOBILE) | |
| 214 return NO; | |
| 215 } | |
| 216 | |
| 197 return YES; | 217 return YES; |
| 198 } | 218 } |
| 199 | 219 |
| 200 NS_INLINE void AnimateInViews(NSArray* views, | 220 NS_INLINE void AnimateInViews(NSArray* views, |
| 201 CGFloat initialX, | 221 CGFloat initialX, |
| 202 CGFloat initialY) { | 222 CGFloat initialY) { |
| 203 [views enumerateObjectsUsingBlock:^(UIView* view, NSUInteger index, | 223 [views enumerateObjectsUsingBlock:^(UIView* view, NSUInteger index, |
| 204 BOOL* stop) { | 224 BOOL* stop) { |
| 205 CGFloat beginTime = index * .035; | 225 CGFloat beginTime = index * .035; |
| 206 CABasicAnimation* transformAnimation = | 226 CABasicAnimation* transformAnimation = |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 257 BOOL _waitForInk; | 277 BOOL _waitForInk; |
| 258 // Weak pointer to ReadingListMenuNotifier, used to set the starting values | 278 // Weak pointer to ReadingListMenuNotifier, used to set the starting values |
| 259 // for the reading list badge. | 279 // for the reading list badge. |
| 260 base::WeakNSObject<ReadingListMenuNotifier> _readingListMenuNotifier; | 280 base::WeakNSObject<ReadingListMenuNotifier> _readingListMenuNotifier; |
| 261 } | 281 } |
| 262 @property(nonatomic, retain) ToolsMenuCollectionView* menuView; | 282 @property(nonatomic, retain) ToolsMenuCollectionView* menuView; |
| 263 @property(nonatomic, retain) MDCInkView* touchFeedbackView; | 283 @property(nonatomic, retain) MDCInkView* touchFeedbackView; |
| 264 @property(nonatomic, retain) NSMutableArray* menuItems; | 284 @property(nonatomic, retain) NSMutableArray* menuItems; |
| 265 @property(nonatomic, assign) kToolbarType toolbarType; | 285 @property(nonatomic, assign) kToolbarType toolbarType; |
| 266 | 286 |
| 267 // Get the reading list cell. | 287 // Gets the reading list cell. |
|
Eugene But (OOO till 7-30)
2017/03/03 02:30:25
nit: s/Gets/Returns since you touching this :)
liaoyuke
2017/03/03 23:39:42
Done.
| |
| 268 - (ReadingListMenuViewCell*)readingListCell; | 288 - (ReadingListMenuViewCell*)readingListCell; |
| 269 @end | 289 @end |
| 270 | 290 |
| 271 @implementation ToolsMenuViewController | 291 @implementation ToolsMenuViewController |
| 272 | 292 |
| 273 @synthesize menuView = _menuView; | 293 @synthesize menuView = _menuView; |
| 274 @synthesize isCurrentPageBookmarked = _isCurrentPageBookmarked; | 294 @synthesize isCurrentPageBookmarked = _isCurrentPageBookmarked; |
| 275 @synthesize touchFeedbackView = _touchFeedbackView; | 295 @synthesize touchFeedbackView = _touchFeedbackView; |
| 276 @synthesize isTabLoading = _isTabLoading; | 296 @synthesize isTabLoading = _isTabLoading; |
| 277 @synthesize toolbarType = _toolbarType; | 297 @synthesize toolbarType = _toolbarType; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 | 341 |
| 322 ToolsMenuViewToolsCell* toolsCell = [self toolsCell]; | 342 ToolsMenuViewToolsCell* toolsCell = [self toolsCell]; |
| 323 [[toolsCell starButton] setHidden:_isCurrentPageBookmarked]; | 343 [[toolsCell starButton] setHidden:_isCurrentPageBookmarked]; |
| 324 [[toolsCell starredButton] setHidden:!_isCurrentPageBookmarked]; | 344 [[toolsCell starredButton] setHidden:!_isCurrentPageBookmarked]; |
| 325 } | 345 } |
| 326 | 346 |
| 327 - (void)setCanUseReaderMode:(BOOL)enabled { | 347 - (void)setCanUseReaderMode:(BOOL)enabled { |
| 328 [self setItemEnabled:enabled withTag:IDC_READER_MODE]; | 348 [self setItemEnabled:enabled withTag:IDC_READER_MODE]; |
| 329 } | 349 } |
| 330 | 350 |
| 331 - (void)setCanUseDesktopUserAgent:(BOOL)enabled { | |
| 332 [self setItemEnabled:enabled withTag:IDC_REQUEST_DESKTOP_SITE]; | |
| 333 } | |
| 334 | |
| 335 - (void)setCanShowFindBar:(BOOL)enabled { | 351 - (void)setCanShowFindBar:(BOOL)enabled { |
| 336 [self setItemEnabled:enabled withTag:IDC_FIND]; | 352 [self setItemEnabled:enabled withTag:IDC_FIND]; |
| 337 } | 353 } |
| 338 | 354 |
| 339 - (void)setCanShowShareMenu:(BOOL)enabled { | 355 - (void)setCanShowShareMenu:(BOOL)enabled { |
| 340 ToolsMenuViewToolsCell* toolsCell = [self toolsCell]; | 356 ToolsMenuViewToolsCell* toolsCell = [self toolsCell]; |
| 341 [[toolsCell shareButton] setEnabled:enabled]; | 357 [[toolsCell shareButton] setEnabled:enabled]; |
| 342 [self setItemEnabled:enabled withTag:IDC_SHARE_PAGE]; | 358 [self setItemEnabled:enabled withTag:IDC_SHARE_PAGE]; |
| 343 } | 359 } |
| 344 | 360 |
| 345 - (UIButton*)toolsButton { | 361 - (UIButton*)toolsButton { |
| 346 UIButton* toolsButton = [[self toolsCell] toolsButton]; | 362 UIButton* toolsButton = [[self toolsCell] toolsButton]; |
| 347 [toolsButton addTarget:self | 363 [toolsButton addTarget:self |
| 348 action:@selector(buttonPressed:) | 364 action:@selector(buttonPressed:) |
| 349 forControlEvents:UIControlEventTouchUpInside]; | 365 forControlEvents:UIControlEventTouchUpInside]; |
| 350 [toolsButton setTranslatesAutoresizingMaskIntoConstraints:YES]; | 366 [toolsButton setTranslatesAutoresizingMaskIntoConstraints:YES]; |
| 351 [toolsButton setOpaque:NO]; | 367 [toolsButton setOpaque:NO]; |
| 352 [toolsButton setBackgroundColor:[UIColor clearColor]]; | 368 [toolsButton setBackgroundColor:[UIColor clearColor]]; |
| 353 return toolsButton; | 369 return toolsButton; |
| 354 } | 370 } |
| 355 | 371 |
| 356 - (void)setIsTabLoading:(BOOL)isTabLoading { | 372 - (void)setIsTabLoading:(BOOL)isTabLoading { |
| 357 _isTabLoading = isTabLoading; | 373 _isTabLoading = isTabLoading; |
| 358 | 374 |
| 359 ToolsMenuViewToolsCell* toolsCell = [self toolsCell]; | 375 ToolsMenuViewToolsCell* toolsCell = [self toolsCell]; |
| 360 [[toolsCell stopButton] setHidden:!isTabLoading]; | 376 [[toolsCell stopButton] setHidden:!isTabLoading]; |
| 361 [[toolsCell reloadButton] setHidden:isTabLoading]; | 377 [[toolsCell reloadButton] setHidden:isTabLoading]; |
| 362 } | 378 } |
| 363 | 379 |
| 364 - (void)initializeMenu:(ToolsMenuContext*)context { | 380 - (void)initializeMenuWithConfiguration:(ToolsMenuConfiguration*)configuration { |
| 365 if (context.readingListMenuNotifier) { | 381 if (configuration.readingListMenuNotifier) { |
| 366 _readingListMenuNotifier.reset(context.readingListMenuNotifier); | 382 _readingListMenuNotifier.reset(configuration.readingListMenuNotifier); |
| 367 [context.readingListMenuNotifier setDelegate:self]; | 383 [configuration.readingListMenuNotifier setDelegate:self]; |
| 368 } | 384 } |
| 369 | 385 |
| 370 if (IsIPadIdiom()) { | 386 if (IsIPadIdiom()) { |
| 371 _toolbarType = context.hasNoOpenedTabs | 387 _toolbarType = configuration.hasNoOpenedTabs |
| 372 ? kToolbarTypeNoTabsiPad | 388 ? kToolbarTypeNoTabsiPad |
| 373 : (!IsCompactTablet() ? kToolbarTypeWebiPad | 389 : (!IsCompactTablet() ? kToolbarTypeWebiPad |
| 374 : kToolbarTypeWebiPhone); | 390 : kToolbarTypeWebiPhone); |
| 375 } else { | 391 } else { |
| 376 // kOptionInTabSwitcher option must be enabled on iPhone with | 392 // kOptionInTabSwitcher option must be enabled on iPhone with |
| 377 // no opened tabs. | 393 // no opened tabs. |
| 378 DCHECK(!context.hasNoOpenedTabs || context.isInTabSwitcher); | 394 DCHECK(!configuration.hasNoOpenedTabs || configuration.isInTabSwitcher); |
| 379 _toolbarType = context.isInTabSwitcher ? kToolbarTypeSwitcheriPhone | 395 _toolbarType = configuration.isInTabSwitcher ? kToolbarTypeSwitcheriPhone |
| 380 : kToolbarTypeWebiPhone; | 396 : kToolbarTypeWebiPhone; |
| 381 } | 397 } |
| 382 | 398 |
| 383 // Build the menu, adding all relevant items. | 399 // Build the menu, adding all relevant items. |
| 384 NSMutableArray* menu = [NSMutableArray array]; | 400 NSMutableArray* menu = [NSMutableArray array]; |
| 385 | 401 |
| 386 for (size_t i = 0; i < arraysize(itemInfoList); ++i) { | 402 for (size_t i = 0; i < arraysize(itemInfoList); ++i) { |
| 387 const MenuItemInfo& item = itemInfoList[i]; | 403 const MenuItemInfo& item = itemInfoList[i]; |
| 388 if (!ItemShouldBeVisible(item, context.isInIncognito, _toolbarType)) | 404 if (!ItemShouldBeVisible(item, _toolbarType, configuration)) |
| 389 continue; | 405 continue; |
| 390 | 406 |
| 391 NSString* title = l10n_util::GetNSStringWithFixup(item.title_id); | 407 NSString* title = l10n_util::GetNSStringWithFixup(item.title_id); |
| 392 Class itemClass = | 408 Class itemClass = |
| 393 item.item_class ? item.item_class : [ToolsMenuViewItem class]; | 409 item.item_class ? item.item_class : [ToolsMenuViewItem class]; |
| 394 // Sanity check that the class is a useful one. | 410 // Sanity check that the class is a useful one. |
| 395 DCHECK([itemClass respondsToSelector:@selector(menuItemWithTitle: | 411 DCHECK([itemClass respondsToSelector:@selector(menuItemWithTitle: |
| 396 accessibilityIdentifier: | 412 accessibilityIdentifier: |
| 397 command:)]); | 413 command:)]); |
| 398 [menu addObject:[itemClass menuItemWithTitle:title | 414 [menu addObject:[itemClass menuItemWithTitle:title |
| 399 accessibilityIdentifier:item.accessibility_id | 415 accessibilityIdentifier:item.accessibility_id |
| 400 command:item.command_id]]; | 416 command:item.command_id]]; |
| 401 } | 417 } |
| 402 | 418 |
| 403 #if !defined(NDEBUG) | 419 #if !defined(NDEBUG) |
| 404 NSUserDefaults* standardDefaults = [NSUserDefaults standardUserDefaults]; | 420 NSUserDefaults* standardDefaults = [NSUserDefaults standardUserDefaults]; |
| 405 if ((_toolbarType & kToolbarTypeWebAll) && | 421 if ((_toolbarType & kToolbarTypeWebAll) && |
| 406 [standardDefaults boolForKey:@"DevViewSource"]) { | 422 [standardDefaults boolForKey:@"DevViewSource"]) { |
| 407 // Debug menu, not localized, only visible if turned on by a default. | 423 // Debug menu, not localized, only visible if turned on by a default. |
| 408 [menu addObject:[self createViewSourceItem]]; | 424 [menu addObject:[self createViewSourceItem]]; |
| 409 } | 425 } |
| 410 #endif // !defined(NDEBUG) | 426 #endif // !defined(NDEBUG) |
| 411 | 427 |
| 412 [self setMenuItems:menu]; | 428 [self setMenuItems:menu]; |
| 413 | 429 |
| 430 // Decide the enabled state of the currently visible item between | |
| 431 // "Request Desktop Site" and "Request Mobile Site". | |
| 432 if (configuration.userAgentType == web::UserAgentType::NONE) | |
|
Eugene But (OOO till 7-30)
2017/03/03 02:30:25
Should this be a switch case?
liaoyuke
2017/03/03 23:39:43
Done.
| |
| 433 [self setItemEnabled:NO withTag:IDC_REQUEST_DESKTOP_SITE]; | |
|
kkhorimoto
2017/03/03 18:42:43
Can we add a TODO referencing your bug to decide w
liaoyuke
2017/03/03 23:39:42
I have a TODO at the 202th line in this file, and
| |
| 434 else if (configuration.userAgentType == web::UserAgentType::MOBILE) | |
| 435 [self setItemEnabled:YES withTag:IDC_REQUEST_DESKTOP_SITE]; | |
| 436 else | |
| 437 [self setItemEnabled:YES withTag:IDC_REQUEST_MOBILE_SITE]; | |
| 438 | |
| 414 // Disable IDC_CLOSE_ALL_TABS menu item if on phone with no tabs. | 439 // Disable IDC_CLOSE_ALL_TABS menu item if on phone with no tabs. |
| 415 if (!IsIPadIdiom()) { | 440 if (!IsIPadIdiom()) { |
| 416 [self setItemEnabled:!context.hasNoOpenedTabs withTag:IDC_CLOSE_ALL_TABS]; | 441 [self setItemEnabled:!configuration.hasNoOpenedTabs |
| 442 withTag:IDC_CLOSE_ALL_TABS]; | |
| 417 } | 443 } |
| 418 } | 444 } |
| 419 | 445 |
| 420 #if !defined(NDEBUG) | 446 #if !defined(NDEBUG) |
| 421 - (ToolsMenuViewItem*)createViewSourceItem { | 447 - (ToolsMenuViewItem*)createViewSourceItem { |
| 422 return [ToolsMenuViewItem menuItemWithTitle:@"View Source" | 448 return [ToolsMenuViewItem menuItemWithTitle:@"View Source" |
| 423 accessibilityIdentifier:@"View Source" | 449 accessibilityIdentifier:@"View Source" |
| 424 command:IDC_VIEW_SOURCE]; | 450 command:IDC_VIEW_SOURCE]; |
| 425 } | 451 } |
| 426 #endif // !defined(NDEBUG) | 452 #endif // !defined(NDEBUG) |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 747 | 773 |
| 748 - (void)unreadCountChanged:(NSInteger)unreadCount { | 774 - (void)unreadCountChanged:(NSInteger)unreadCount { |
| 749 [[self readingListCell] updateBadgeCount:unreadCount animated:YES]; | 775 [[self readingListCell] updateBadgeCount:unreadCount animated:YES]; |
| 750 } | 776 } |
| 751 | 777 |
| 752 - (void)unseenStateChanged:(BOOL)unseenItemsExist { | 778 - (void)unseenStateChanged:(BOOL)unseenItemsExist { |
| 753 [[self readingListCell] updateSeenState:unseenItemsExist animated:YES]; | 779 [[self readingListCell] updateSeenState:unseenItemsExist animated:YES]; |
| 754 } | 780 } |
| 755 | 781 |
| 756 @end | 782 @end |
| OLD | NEW |