diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2016-06-01 17:54:49 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2016-08-09 06:29:08 +0000 |
commit | 6534b09073791398bad99863821740e986915bff (patch) | |
tree | 1d2476d387e75d691d112f71f74f9094b25cbd8a /src/core | |
parent | 521c3f6c47e3e7e284eaaca40c1820fbcb1b56e0 (diff) |
Add focusOnNavigationEnabled setting
The focusOnNavigationEnabled setting allows changing the behavior of
whether a WebEngine view (widget or quick) will automatically get
focus, whenever a navigation action happens (load, reload, previous
history entry, etc).
The default behavior before this patch was to always grab the focus.
[ChangeLog][QtWebEngine][General] Add focusOnNavigationEnabled setting
which allows controlling whether a web view will receive focus on a
navigation request. Previously the view always received the focus.
Task-number: QTBUG-52999
Change-Id: I6d30d973a41b53011131f21dcecbf6ec4d652759
Reviewed-by: Kai Koehne <kai.koehne@qt.io>
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/web_contents_adapter.cpp | 23 | ||||
-rw-r--r-- | src/core/web_contents_adapter.h | 2 | ||||
-rw-r--r-- | src/core/web_engine_settings.cpp | 1 | ||||
-rw-r--r-- | src/core/web_engine_settings.h | 3 |
4 files changed, 21 insertions, 8 deletions
diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp index b0aae6ca9..a7799544b 100644 --- a/src/core/web_contents_adapter.cpp +++ b/src/core/web_contents_adapter.cpp @@ -470,21 +470,21 @@ void WebContentsAdapter::stop() controller.RemoveEntryAtIndex(index); d->webContents->Stop(); - d->webContents->Focus(); + focusIfNecessary(); } void WebContentsAdapter::reload() { Q_D(WebContentsAdapter); d->webContents->GetController().Reload(/*checkRepost = */false); - d->webContents->Focus(); + focusIfNecessary(); } void WebContentsAdapter::reloadAndBypassCache() { Q_D(WebContentsAdapter); d->webContents->GetController().ReloadBypassingCache(/*checkRepost = */false); - d->webContents->Focus(); + focusIfNecessary(); } void WebContentsAdapter::load(const QUrl &url) @@ -507,7 +507,7 @@ void WebContentsAdapter::load(const QUrl &url) params.transition_type = ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR); params.override_user_agent = content::NavigationController::UA_OVERRIDE_TRUE; d->webContents->GetController().LoadURLWithParams(params); - d->webContents->Focus(); + focusIfNecessary(); } void WebContentsAdapter::setContent(const QByteArray &data, const QString &mimeType, const QUrl &baseUrl) @@ -532,7 +532,7 @@ void WebContentsAdapter::setContent(const QByteArray &data, const QString &mimeT params.transition_type = ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_API); params.override_user_agent = content::NavigationController::UA_OVERRIDE_TRUE; d->webContents->GetController().LoadURLWithParams(params); - d->webContents->Focus(); + focusIfNecessary(); d->webContents->Unselect(); } @@ -646,14 +646,14 @@ void WebContentsAdapter::navigateToIndex(int offset) { Q_D(WebContentsAdapter); d->webContents->GetController().GoToIndex(offset); - d->webContents->Focus(); + focusIfNecessary(); } void WebContentsAdapter::navigateToOffset(int offset) { Q_D(WebContentsAdapter); d->webContents->GetController().GoToOffset(offset); - d->webContents->Focus(); + focusIfNecessary(); } int WebContentsAdapter::navigationEntryCount() @@ -1246,6 +1246,15 @@ void WebContentsAdapter::replaceMisspelling(const QString &word) #endif } +void WebContentsAdapter::focusIfNecessary() +{ + Q_D(WebContentsAdapter); + const WebEngineSettings *settings = d->adapterClient->webEngineSettings(); + bool focusOnNavigation = settings->testAttribute(WebEngineSettings::FocusOnNavigationEnabled); + if (focusOnNavigation) + d->webContents->Focus(); +} + WebContentsAdapterClient::RenderProcessTerminationStatus WebContentsAdapterClient::renderProcessExitStatus(int terminationStatus) { auto status = WebContentsAdapterClient::RenderProcessTerminationStatus(-1); diff --git a/src/core/web_contents_adapter.h b/src/core/web_contents_adapter.h index a29778a7e..08f68e76b 100644 --- a/src/core/web_contents_adapter.h +++ b/src/core/web_contents_adapter.h @@ -180,6 +180,8 @@ public: void viewSource(); bool canViewSource(); + void focusIfNecessary(); + private: Q_DISABLE_COPY(WebContentsAdapter) diff --git a/src/core/web_engine_settings.cpp b/src/core/web_engine_settings.cpp index 6c17c3ce9..a706b860e 100644 --- a/src/core/web_engine_settings.cpp +++ b/src/core/web_engine_settings.cpp @@ -237,6 +237,7 @@ void WebEngineSettings::initDefaults(bool offTheRecord) s_defaultAttributes.insert(Accelerated2dCanvasEnabled, accelerated2dCanvas); s_defaultAttributes.insert(AutoLoadIconsForPage, true); s_defaultAttributes.insert(TouchIconsEnabled, false); + s_defaultAttributes.insert(FocusOnNavigationEnabled, true); } if (offTheRecord) m_attributes.insert(LocalStorageEnabled, false); diff --git a/src/core/web_engine_settings.h b/src/core/web_engine_settings.h index e21eee8a9..55e659b53 100644 --- a/src/core/web_engine_settings.h +++ b/src/core/web_engine_settings.h @@ -79,7 +79,8 @@ public: WebGLEnabled, Accelerated2dCanvasEnabled, AutoLoadIconsForPage, - TouchIconsEnabled + TouchIconsEnabled, + FocusOnNavigationEnabled }; // Must match the values from the public API in qwebenginesettings.h. |