OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ios/chrome/browser/ui/tools_menu/tools_menu_model.h" | |
6 | |
7 #include "components/reading_list/core/reading_list_switches.h" | |
8 #include "components/strings/grit/components_strings.h" | |
9 #include "ios/chrome/browser/experimental_flags.h" | |
10 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" | |
11 #import "ios/chrome/browser/ui/tools_menu/reading_list_menu_view_item.h" | |
12 #include "ios/chrome/browser/ui/ui_util.h" | |
13 #include "ios/chrome/grit/ios_strings.h" | |
14 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" | |
15 #import "ios/public/provider/chrome/browser/user_feedback/user_feedback_provider .h" | |
16 | |
17 NSString* const kToolsMenuNewTabId = @"kToolsMenuNewTabId"; | |
18 NSString* const kToolsMenuNewIncognitoTabId = @"kToolsMenuNewIncognitoTabId"; | |
19 NSString* const kToolsMenuCloseAllTabsId = @"kToolsMenuCloseAllTabsId"; | |
20 NSString* const kToolsMenuCloseAllIncognitoTabsId = | |
21 @"kToolsMenuCloseAllIncognitoTabsId"; | |
22 NSString* const kToolsMenuBookmarksId = @"kToolsMenuBookmarksId"; | |
23 NSString* const kToolsMenuReadingListId = @"kToolsMenuReadingListId"; | |
24 NSString* const kToolsMenuOtherDevicesId = @"kToolsMenuOtherDevicesId"; | |
25 NSString* const kToolsMenuHistoryId = @"kToolsMenuHistoryId"; | |
26 NSString* const kToolsMenuReportAnIssueId = @"kToolsMenuReportAnIssueId"; | |
27 NSString* const kToolsMenuFindInPageId = @"kToolsMenuFindInPageId"; | |
28 NSString* const kToolsMenuReaderMode = @"kToolsMenuReaderMode"; | |
29 NSString* const kToolsMenuRequestDesktopId = @"kToolsMenuRequestDesktopId"; | |
30 NSString* const kToolsMenuSettingsId = @"kToolsMenuSettingsId"; | |
31 NSString* const kToolsMenuHelpId = @"kToolsMenuHelpId"; | |
32 NSString* const kToolsMenuSuggestionsId = @"kToolsMenuSuggestionsId"; | |
33 | |
34 // Menu items can be marked as visible or not when Incognito is enabled. | |
35 // The following bits are used for |visibility| field in |MenuItemInfo|. | |
36 const NSInteger kVisibleIncognitoOnly = 1 << 0; | |
37 const NSInteger kVisibleNotIncognitoOnly = 1 << 1; | |
38 | |
39 // Declare all the possible items. | |
40 const MenuItemInfo itemInfoList[] = { | |
41 // clang-format off | |
42 { IDS_IOS_TOOLS_MENU_NEW_TAB, kToolsMenuNewTabId, | |
43 IDC_NEW_TAB, kToolbarTypeAll, | |
rohitrao (ping after 24h)
2017/02/22 12:17:33
Can you put selectors into structs? We could expa
marq (ping after 24h)
2017/02/22 12:29:07
Yes, that would work. We would need to think about
sczs
2017/02/22 18:05:12
That's exactly what I want to try doing in a next
| |
44 0, nil }, | |
45 { IDS_IOS_TOOLS_MENU_NEW_INCOGNITO_TAB, kToolsMenuNewIncognitoTabId, | |
46 IDC_NEW_INCOGNITO_TAB, kToolbarTypeAll, | |
47 0, nil }, | |
48 { IDS_IOS_TOOLS_MENU_CLOSE_ALL_TABS, kToolsMenuCloseAllTabsId, | |
49 IDC_CLOSE_ALL_TABS, kToolbarTypeSwitcheriPhone, | |
50 kVisibleNotIncognitoOnly, nil }, | |
51 { IDS_IOS_TOOLS_MENU_CLOSE_ALL_INCOGNITO_TABS, | |
52 kToolsMenuCloseAllIncognitoTabsId, | |
53 IDC_CLOSE_ALL_INCOGNITO_TABS, kToolbarTypeSwitcheriPhone, | |
54 kVisibleIncognitoOnly, nil }, | |
55 { IDS_IOS_TOOLS_MENU_BOOKMARKS, kToolsMenuBookmarksId, | |
56 IDC_SHOW_BOOKMARK_MANAGER, kToolbarTypeWebAll, | |
57 0, nil }, | |
58 { IDS_IOS_TOOLS_MENU_READING_LIST, kToolsMenuReadingListId, | |
59 IDC_SHOW_READING_LIST, kToolbarTypeWebAll, | |
60 0, [ReadingListMenuViewItem class] }, | |
61 { IDS_IOS_TOOLS_MENU_SUGGESTIONS, kToolsMenuSuggestionsId, | |
62 IDC_SHOW_SUGGESTIONS, kToolbarTypeWebAll, | |
63 0, nil }, | |
64 { IDS_IOS_TOOLS_MENU_RECENT_TABS, kToolsMenuOtherDevicesId, | |
65 IDC_SHOW_OTHER_DEVICES, kToolbarTypeWebAll, | |
66 kVisibleNotIncognitoOnly, nil }, | |
67 { IDS_HISTORY_SHOW_HISTORY, kToolsMenuHistoryId, | |
68 IDC_SHOW_HISTORY, kToolbarTypeWebAll, | |
69 0, nil }, | |
70 { IDS_IOS_OPTIONS_REPORT_AN_ISSUE, kToolsMenuReportAnIssueId, | |
71 IDC_REPORT_AN_ISSUE, kToolbarTypeAll, | |
72 0, nil }, | |
73 { IDS_IOS_TOOLS_MENU_FIND_IN_PAGE, kToolsMenuFindInPageId, | |
74 IDC_FIND, kToolbarTypeWebAll, | |
75 0, nil }, | |
76 { IDS_IOS_TOOLS_MENU_REQUEST_DESKTOP_SITE, kToolsMenuRequestDesktopId, | |
77 IDC_REQUEST_DESKTOP_SITE, kToolbarTypeWebAll, | |
78 0, nil }, | |
79 { IDS_IOS_TOOLS_MENU_READER_MODE, kToolsMenuReaderMode, | |
80 IDC_READER_MODE, kToolbarTypeWebAll, | |
81 0, nil }, | |
82 { IDS_IOS_TOOLS_MENU_SETTINGS, kToolsMenuSettingsId, | |
83 IDC_OPTIONS, kToolbarTypeAll, | |
84 0, nil }, | |
85 { IDS_IOS_TOOLS_MENU_HELP_MOBILE, kToolsMenuHelpId, | |
86 IDC_HELP_PAGE_VIA_MENU, kToolbarTypeWebAll, | |
87 0, nil }, | |
88 // clang-format on | |
89 }; | |
90 | |
91 bool ToolsMenuModel::ItemShouldBeVisible(const MenuItemInfo& item, | |
edchin
2017/02/22 07:22:29
Just out of curiosity, why did you omit NS_INLINE
marq (ping after 24h)
2017/02/22 11:15:57
Either is OK, but if you change to bool you need t
rohitrao (ping after 24h)
2017/02/22 12:17:33
I have no idea why the NS_INLINE was in here in th
sczs
2017/02/22 18:05:12
Done.
| |
92 bool incognito, | |
93 kToolbarType toolbarType) { | |
94 if (!(item.toolbar_types & toolbarType)) | |
95 return NO; | |
96 | |
97 if (incognito && (item.visibility & kVisibleNotIncognitoOnly)) | |
98 return NO; | |
99 | |
100 if (!incognito && (item.visibility & kVisibleIncognitoOnly)) | |
101 return NO; | |
102 | |
103 if (item.title_id == IDS_IOS_TOOLBAR_SHOW_TABS) { | |
marq (ping after 24h)
2017/02/22 11:15:57
I realize this is a direct lift from the old code,
sczs
2017/02/22 18:05:12
Done.
| |
104 if (!IsIPadIdiom()) { | |
105 return NO; | |
106 } | |
107 } | |
108 | |
109 if (item.title_id == IDS_IOS_TOOLS_MENU_READER_MODE) { | |
110 if (!experimental_flags::IsReaderModeEnabled()) { | |
111 return NO; | |
112 } | |
113 } | |
114 | |
115 if (item.title_id == IDS_IOS_TOOLS_MENU_READING_LIST) { | |
116 if (!reading_list::switches::IsReadingListEnabled()) { | |
117 return NO; | |
118 } | |
119 } | |
120 | |
121 if (item.title_id == IDS_IOS_TOOLS_MENU_SUGGESTIONS) { | |
122 if (!experimental_flags::IsSuggestionsUIEnabled()) { | |
123 return NO; | |
124 } | |
125 } | |
126 | |
127 if (item.title_id == IDS_IOS_OPTIONS_REPORT_AN_ISSUE) { | |
128 if (!ios::GetChromeBrowserProvider() | |
129 ->GetUserFeedbackProvider() | |
130 ->IsUserFeedbackEnabled()) { | |
131 return NO; | |
132 } | |
133 } | |
134 | |
135 return YES; | |
136 } | |
OLD | NEW |