mirror of
https://github.com/electron/electron.git
synced 2026-02-19 03:14:51 -05:00
feat: add focusOnNavigation flag to WebPreferences (#49511)
* feat: add focusOnNavigation webPreference Co-authored-by: Kyle Cutler <kycutler@microsoft.com> * WebContentsView tests Co-authored-by: Kyle Cutler <kycutler@microsoft.com> * fix Co-authored-by: Kyle Cutler <kycutler@microsoft.com> * fix Co-authored-by: Kyle Cutler <kycutler@microsoft.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Kyle Cutler <kycutler@microsoft.com>
This commit is contained in:
@@ -2094,6 +2094,10 @@ void WebContents::ReadyToCommitNavigation(
|
||||
// Only focus for top-level contents.
|
||||
if (type_ != Type::kBrowserWindow)
|
||||
return;
|
||||
// Don't focus if focusOnNavigation is disabled.
|
||||
auto* prefs = WebContentsPreferences::From(web_contents());
|
||||
if (prefs && !prefs->ShouldFocusOnNavigation())
|
||||
return;
|
||||
web_contents()->SetInitialFocus();
|
||||
}
|
||||
|
||||
|
||||
@@ -149,6 +149,7 @@ void WebContentsPreferences::Clear() {
|
||||
preload_path_ = std::nullopt;
|
||||
v8_cache_options_ = blink::mojom::V8CacheOptions::kDefault;
|
||||
deprecated_paste_enabled_ = false;
|
||||
focus_on_navigation_ = true;
|
||||
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
scroll_bounce_ = false;
|
||||
@@ -249,6 +250,8 @@ void WebContentsPreferences::SetFromDictionary(
|
||||
web_preferences.Get(options::kEnableDeprecatedPaste,
|
||||
&deprecated_paste_enabled_);
|
||||
|
||||
web_preferences.Get(options::kFocusOnNavigation, &focus_on_navigation_);
|
||||
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
web_preferences.Get(options::kScrollBounce, &scroll_bounce_);
|
||||
#endif
|
||||
|
||||
@@ -78,6 +78,7 @@ class WebContentsPreferences
|
||||
bool ShouldDisablePopups() const { return disable_popups_; }
|
||||
bool IsWebSecurityEnabled() const { return web_security_; }
|
||||
std::optional<base::FilePath> GetPreloadPath() const { return preload_path_; }
|
||||
bool ShouldFocusOnNavigation() const { return focus_on_navigation_; }
|
||||
bool IsSandboxed() const;
|
||||
|
||||
private:
|
||||
@@ -134,6 +135,7 @@ class WebContentsPreferences
|
||||
std::optional<base::FilePath> preload_path_;
|
||||
blink::mojom::V8CacheOptions v8_cache_options_;
|
||||
bool deprecated_paste_enabled_ = false;
|
||||
bool focus_on_navigation_;
|
||||
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
bool scroll_bounce_;
|
||||
|
||||
@@ -222,6 +222,9 @@ inline constexpr std::string_view kSpellcheck = "spellcheck";
|
||||
inline constexpr std::string_view kEnableDeprecatedPaste =
|
||||
"enableDeprecatedPaste";
|
||||
|
||||
// Whether to focus the webContents on navigation.
|
||||
inline constexpr std::string_view kFocusOnNavigation = "focusOnNavigation";
|
||||
|
||||
inline constexpr std::string_view kModal = "modal";
|
||||
|
||||
} // namespace options
|
||||
|
||||
Reference in New Issue
Block a user