diff options
author | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2014-02-05 14:01:54 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-13 12:50:43 +0100 |
commit | b81a337a63710c4f109dc537f7d4b73acc282596 (patch) | |
tree | 204dbb36ba13ab2e97df3d04f114f0b5dd58d372 /examples | |
parent | 185e8a020212756d4e7adfbcd69e16232c8d7dfd (diff) |
QQuickWebEngineView new window API refactoring
Improve the code and API in a few ways:
- Expose a more discoverable "request" argument in the signal.
- Use the request as the carrier of the backend WebContentsAdapter
and get rid of our handle.
- Put the adoption method (renamed to openIn) on the request object
and keep the view API clean of a context-specific adoptHandle method.
- Use an enum instead of strings for the new view destination.
- Do not let JavaScript own the request object since it won't be
necessary until we want to support asynchronous view attachment.
We can create the request object on the heap and let the JavaScript
engine own the object once we want to support it.
- Move the request class to its own header.
- Replace tabs.currentView by currentWebView in the quicknanobrowser
qml code since we now need this property on the root object anyway.
Change-Id: I40d7d15255f516ead9f3e414dd587bf345e6ca4b
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/quick/quicknanobrowser/quickwindow.qml | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/examples/quick/quicknanobrowser/quickwindow.qml b/examples/quick/quicknanobrowser/quickwindow.qml index d72c30021..4b708ffed 100644 --- a/examples/quick/quicknanobrowser/quickwindow.qml +++ b/examples/quick/quicknanobrowser/quickwindow.qml @@ -49,8 +49,8 @@ import QtQuick.Controls.Private 1.0 ApplicationWindow { id: browserWindow - function load(url) { tabs.currentView.url = url } - function adoptHandle(viewHandle) { tabs.currentView.adoptHandle(viewHandle) } + function load(url) { currentWebView.url = url } + property Item currentWebView: tabs.currentIndex < tabs.count ? tabs.getTab(tabs.currentIndex).item : null property bool isFullScreen: visibility == Window.FullScreen onIsFullScreenChanged: { @@ -62,7 +62,7 @@ ApplicationWindow { height: 600 width: 800 visible: true - title: tabs.currentView && tabs.currentView.title + title: currentWebView && currentWebView.title // Make sure the Qt.WindowFullscreenButtonHint is set on Mac. Component.onCompleted: flags = flags | Qt.WindowFullscreenButtonHint @@ -118,21 +118,21 @@ ApplicationWindow { ToolButton { id: backButton iconSource: "icons/go-previous.png" - onClicked: tabs.currentView.goBack() - enabled: tabs.currentView && tabs.currentView.canGoBack + onClicked: currentWebView.goBack() + enabled: currentWebView && currentWebView.canGoBack activeFocusOnTab: !browserWindow.platformIsMac } ToolButton { id: forwardButton iconSource: "icons/go-next.png" - onClicked: tabs.currentView.goForward() - enabled: tabs.currentView && tabs.currentView.canGoForward + onClicked: currentWebView.goForward() + enabled: currentWebView && currentWebView.canGoForward activeFocusOnTab: !browserWindow.platformIsMac } ToolButton { id: reloadButton - iconSource: tabs.currentView && tabs.currentView.loading ? "icons/process-stop.png" : "icons/view-refresh.png" - onClicked: tabs.currentView && tabs.currentView.loading ? tabs.currentView.stop() : tabs.currentView.reload() + iconSource: currentWebView && currentWebView.loading ? "icons/process-stop.png" : "icons/view-refresh.png" + onClicked: currentWebView && currentWebView.loading ? currentWebView.stop() : currentWebView.reload() activeFocusOnTab: !browserWindow.platformIsMac } TextField { @@ -143,7 +143,7 @@ ApplicationWindow { z: 2 id: faviconImage width: 16; height: 16 - source: tabs.currentView && tabs.currentView.icon + source: currentWebView && currentWebView.icon } style: TextFieldStyle { padding { @@ -152,8 +152,8 @@ ApplicationWindow { } focus: true Layout.fillWidth: true - text: tabs.currentView && tabs.currentView.url - onAccepted: tabs.currentView.url = utils.fromUserInput(text) + text: currentWebView && currentWebView.url + onAccepted: currentWebView.url = utils.fromUserInput(text) } } ProgressBar { @@ -172,13 +172,12 @@ ApplicationWindow { z: -2; minimumValue: 0 maximumValue: 100 - value: (tabs.currentView && tabs.currentView.loadProgress < 100) ? tabs.currentView.loadProgress : 0 + value: (currentWebView && currentWebView.loadProgress < 100) ? currentWebView.loadProgress : 0 } } TabView { id: tabs - property Item currentView: currentIndex < count ? getTab(currentIndex).item : null function createEmptyTab() { var tab = addTab("", tabComponent) // We must do this first to make sure that tab.active gets set so that tab.item gets instantiated immediately. @@ -225,16 +224,16 @@ ApplicationWindow { } } - onCreateWindow: { - if (newViewDisposition == "popup") - print("Warning: Ignored a popup window.") - else if (newViewDisposition == "tab") { + onNewViewRequested: { + if (request.popup) + print("Warning: Blocked a popup window.") + else if (request.destination == WebEngineView.NewViewInTab) { var tab = tabs.createEmptyTab() - tab.item.adoptHandle(newViewHandle) + request.openIn(tab.item) } else { var component = Qt.createComponent("quickwindow.qml") var window = component.createObject() - window.adoptHandle(newViewHandle) + request.openIn(window.currentWebView) } } extraContextMenuEntriesComponent: ContextMenuExtras {} |