Merge to M86: Don't toggle caret browsing on Mac unless web contents has focus.
Pressing F7 to toggle caret browsing was interfering with a Japanese
IME on Mac, but only when the omnibox has focus. There were no
conflicts when focus is in a web page. So to work around this issue,
ignore the F7 shortcut when focus is
It turns out Firefox has the same behavior: it ignores the F7 toggle
when focus is in its address bar. So that's good motivation that this
is the right fix.
There hasn't been any feedback about a similar issue on other
platforms, so scoping the fix to just Mac.
(cherry picked from commit 624eb0c056f51c70f16cbcf3a244b485f3a77a3f)
Bug: 1138475
Change-Id: I19b5ccaf9aec0b46c76e241887af60b0180a7338
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2472897
Reviewed-by: Elly Fong-Jones <[email protected]>
Commit-Queue: Dominic Mazzoni <[email protected]>
Cr-Original-Commit-Position: refs/heads/master@{#817162}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2485433
Reviewed-by: Dominic Mazzoni <[email protected]>
Cr-Commit-Position: refs/branch-heads/4240@{#1279}
Cr-Branched-From: f297677702651916bbf65e59c0d4bbd4ce57d1ee-refs/heads/master@{#800218}
diff --git a/chrome/browser/ui/browser_commands.cc b/chrome/browser/ui/browser_commands.cc
index dc39693..7b22774 100644
--- a/chrome/browser/ui/browser_commands.cc
+++ b/chrome/browser/ui/browser_commands.cc
@@ -1466,6 +1466,20 @@
}
void ToggleCaretBrowsing(Browser* browser) {
+#if defined(OS_MAC)
+ // On Mac, ignore the keyboard shortcut unless web contents is focused,
+ // because the keyboard shortcut interferes with a Japenese IME when the
+ // omnibox is focused. See https://crbug.com/1138475
+ WebContents* web_contents =
+ browser->tab_strip_model()->GetActiveWebContents();
+ if (!web_contents)
+ return;
+
+ content::RenderWidgetHostView* rwhv = web_contents->GetRenderWidgetHostView();
+ if (!rwhv || !rwhv->HasFocus())
+ return;
+#endif // defined(OS_MAC)
+
PrefService* prefService = browser->profile()->GetPrefs();
bool enabled = prefService->GetBoolean(prefs::kCaretBrowsingEnabled);