Commit 6daf1e26 authored by stkhapugin@chromium.org's avatar stkhapugin@chromium.org Committed by Commit Bot

[iOS] Disable find in page keyboard shortcuts on native content pages.

Disables keyboard shortcuts for FIP (cmd+F, cmd+G, cmd+shift+G) on NTP
and other pages where FIP is not available.

Bug: 694971
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I7f32c55760a2ed976bac085994223afa50c3b976
Reviewed-on: https://chromium-review.googlesource.com/1046829
Commit-Queue: Stepan Khapugin <stkhapugin@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#556437}
parent 9cbbe383
...@@ -4115,6 +4115,16 @@ bubblePresenterForFeature:(const base::Feature&)feature ...@@ -4115,6 +4115,16 @@ bubblePresenterForFeature:(const base::Feature&)feature
return _isOffTheRecord; return _isOffTheRecord;
} }
- (BOOL)isFindInPageAvailable {
Tab* tab = [_model currentTab];
if (!tab) {
return NO;
}
auto* helper = FindTabHelper::FromWebState(tab.webState);
return (helper && helper->CurrentPageSupportsFindInPage());
}
- (NSUInteger)tabsCount { - (NSUInteger)tabsCount {
return [_model count]; return [_model count];
} }
......
...@@ -18,6 +18,10 @@ ...@@ -18,6 +18,10 @@
// Whether the current profile is off-the-record. // Whether the current profile is off-the-record.
- (BOOL)isOffTheRecord; - (BOOL)isOffTheRecord;
// Whether the Find in Page is available on current page. For example it's not
// supported on NTP and other native content pages.
- (BOOL)isFindInPageAvailable;
// Returns the current number of tabs. // Returns the current number of tabs.
- (NSUInteger)tabsCount; - (NSUInteger)tabsCount;
......
...@@ -114,6 +114,33 @@ keyCommandsForConsumer:(id<KeyCommandsPlumbing>)consumer ...@@ -114,6 +114,33 @@ keyCommandsForConsumer:(id<KeyCommandsPlumbing>)consumer
// List the commands that only appear when there is at least a tab. When they // List the commands that only appear when there is at least a tab. When they
// appear, they are in the HUD since they have titles. // appear, they are in the HUD since they have titles.
if (hasTabs) { if (hasTabs) {
if ([consumer isFindInPageAvailable]) {
[keyCommands addObjectsFromArray:@[
[UIKeyCommand
cr_keyCommandWithInput:@"f"
modifierFlags:UIKeyModifierCommand
title:l10n_util::GetNSStringWithFixup(
IDS_IOS_TOOLS_MENU_FIND_IN_PAGE)
action:^{
[weakDispatcher showFindInPage];
}],
[UIKeyCommand cr_keyCommandWithInput:@"g"
modifierFlags:UIKeyModifierCommand
title:nil
action:^{
[weakDispatcher findNextStringInPage];
}],
[UIKeyCommand
cr_keyCommandWithInput:@"g"
modifierFlags:UIKeyModifierCommand | UIKeyModifierShift
title:nil
action:^{
[weakDispatcher findPreviousStringInPage];
}]
]];
}
[keyCommands addObjectsFromArray:@[ [keyCommands addObjectsFromArray:@[
[UIKeyCommand cr_keyCommandWithInput:@"l" [UIKeyCommand cr_keyCommandWithInput:@"l"
modifierFlags:UIKeyModifierCommand modifierFlags:UIKeyModifierCommand
...@@ -137,26 +164,6 @@ keyCommandsForConsumer:(id<KeyCommandsPlumbing>)consumer ...@@ -137,26 +164,6 @@ keyCommandsForConsumer:(id<KeyCommandsPlumbing>)consumer
action:^{ action:^{
[weakDispatcher bookmarkPage]; [weakDispatcher bookmarkPage];
}], }],
[UIKeyCommand cr_keyCommandWithInput:@"f"
modifierFlags:UIKeyModifierCommand
title:l10n_util::GetNSStringWithFixup(
IDS_IOS_TOOLS_MENU_FIND_IN_PAGE)
action:^{
[weakDispatcher showFindInPage];
}],
[UIKeyCommand cr_keyCommandWithInput:@"g"
modifierFlags:UIKeyModifierCommand
title:nil
action:^{
[weakDispatcher findNextStringInPage];
}],
[UIKeyCommand
cr_keyCommandWithInput:@"g"
modifierFlags:UIKeyModifierCommand | UIKeyModifierShift
title:nil
action:^{
[weakDispatcher findPreviousStringInPage];
}],
[UIKeyCommand cr_keyCommandWithInput:@"r" [UIKeyCommand cr_keyCommandWithInput:@"r"
modifierFlags:UIKeyModifierCommand modifierFlags:UIKeyModifierCommand
title:l10n_util::GetNSStringWithFixup( title:l10n_util::GetNSStringWithFixup(
......
...@@ -65,6 +65,7 @@ TEST_F(KeyCommandsProviderTest, MoreKeyboardCommandsWhenTabs) { ...@@ -65,6 +65,7 @@ TEST_F(KeyCommandsProviderTest, MoreKeyboardCommandsWhenTabs) {
// Tabs. // Tabs.
[[[mockConsumer expect] andReturnUnsignedInteger:1] tabsCount]; [[[mockConsumer expect] andReturnUnsignedInteger:1] tabsCount];
[[[mockConsumer expect] andReturnBool:YES] isFindInPageAvailable];
NSUInteger numberOfKeyCommandsWithTabs = NSUInteger numberOfKeyCommandsWithTabs =
[[provider keyCommandsForConsumer:mockConsumer [[provider keyCommandsForConsumer:mockConsumer
baseViewController:nil baseViewController:nil
...@@ -82,6 +83,7 @@ TEST_F(KeyCommandsProviderTest, LessKeyCommandsWhenTabsAndEditingText) { ...@@ -82,6 +83,7 @@ TEST_F(KeyCommandsProviderTest, LessKeyCommandsWhenTabsAndEditingText) {
// Not editing text. // Not editing text.
[[[mockConsumer expect] andReturnUnsignedInteger:1] tabsCount]; [[[mockConsumer expect] andReturnUnsignedInteger:1] tabsCount];
[[[mockConsumer expect] andReturnBool:YES] isFindInPageAvailable];
NSUInteger numberOfKeyCommandsWhenNotEditingText = NSUInteger numberOfKeyCommandsWhenNotEditingText =
[[provider keyCommandsForConsumer:mockConsumer [[provider keyCommandsForConsumer:mockConsumer
baseViewController:nil baseViewController:nil
...@@ -90,6 +92,7 @@ TEST_F(KeyCommandsProviderTest, LessKeyCommandsWhenTabsAndEditingText) { ...@@ -90,6 +92,7 @@ TEST_F(KeyCommandsProviderTest, LessKeyCommandsWhenTabsAndEditingText) {
// Editing text. // Editing text.
[[[mockConsumer expect] andReturnUnsignedInteger:1] tabsCount]; [[[mockConsumer expect] andReturnUnsignedInteger:1] tabsCount];
[[[mockConsumer expect] andReturnBool:YES] isFindInPageAvailable];
NSUInteger numberOfKeyCommandsWhenEditingText = NSUInteger numberOfKeyCommandsWhenEditingText =
[[provider keyCommandsForConsumer:mockConsumer [[provider keyCommandsForConsumer:mockConsumer
baseViewController:nil baseViewController:nil
...@@ -100,4 +103,31 @@ TEST_F(KeyCommandsProviderTest, LessKeyCommandsWhenTabsAndEditingText) { ...@@ -100,4 +103,31 @@ TEST_F(KeyCommandsProviderTest, LessKeyCommandsWhenTabsAndEditingText) {
numberOfKeyCommandsWhenNotEditingText); numberOfKeyCommandsWhenNotEditingText);
} }
TEST_F(KeyCommandsProviderTest, MoreKeyboardCommandsWhenFindInPageAvailable) {
KeyCommandsProvider* provider = [[KeyCommandsProvider alloc] init];
id mockConsumer =
[OCMockObject mockForProtocol:@protocol(KeyCommandsPlumbing)];
id<ApplicationCommands, BrowserCommands, OmniboxFocuser> dispatcher = nil;
// No Find in Page.
[[[mockConsumer expect] andReturnUnsignedInteger:1] tabsCount];
[[[mockConsumer expect] andReturnBool:NO] isFindInPageAvailable];
NSUInteger numberOfKeyCommandsWithoutFIP =
[[provider keyCommandsForConsumer:mockConsumer
baseViewController:nil
dispatcher:dispatcher
editingText:NO] count];
// Tabs.
[[[mockConsumer expect] andReturnUnsignedInteger:1] tabsCount];
[[[mockConsumer expect] andReturnBool:YES] isFindInPageAvailable];
NSUInteger numberOfKeyCommandsWithFIP =
[[provider keyCommandsForConsumer:mockConsumer
baseViewController:nil
dispatcher:dispatcher
editingText:NO] count];
EXPECT_GT(numberOfKeyCommandsWithFIP, numberOfKeyCommandsWithoutFIP);
}
} // namespace } // namespace
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment