Use the WebView API to create a browser, webviewapi
We can see that there is a WebView In the Ubuntu SDK. It does not use the Qt standard Webkit library. On Ubuntu, we have made a lot of optimizations (oxide engine) to the following engine, which makes our WebView more superior in performance.
The following uses an example to design a simple Browser.
import QtQuick 2.0import Ubuntu.Components 1.1import Ubuntu.Web 0.2import QtQuick.Layouts 1.1/*! \brief MainView with a Label and Button elements.*/MainView { // objectName for functional testing purposes (autopilot-qt5) objectName: "mainView" // Note! applicationName needs to match the "name" field of the click manifest applicationName: "browser.liu-xiao-guo" /* This property enables the application to change orientation when the device is rotated. The default is false. */ //automaticOrientation: true // Removes the old toolbar and enables new features of the new header. useDeprecatedToolbar: false width: units.gu(100) height: units.gu(75) Page { title: i18n.tr("") RowLayout { id:toolbar anchors.top: parent.top width: parent.width height: units.gu(8) spacing: units.gu(1) Icon { id: back anchors.verticalCenter: parent.verticalCenter name: "go-previous" height: input.height width: height visible: webview.canGoBack MouseArea { anchors.fill: parent onClicked: webview.goBack(); } } Icon { id: forward anchors.verticalCenter: parent.verticalCenter name: "go-next" height: input.height width: height visible: webview.canGoForward MouseArea { anchors.fill: parent onClicked: webview.goForward(); } } TextField { id: input anchors.verticalCenter: parent.verticalCenter height: parent.height - units.gu(1) Layout.maximumWidth: parent.width Layout.preferredWidth: parent.width - back.width - forward.width text: "http://www.baidu.com" onAccepted: { webview.url = input.text } } } WebView { id: webview anchors.top: toolbar.bottom height: parent.height - toolbar.height width: parent.width url: "http://www.baidu.com" } }}
Here we use:
Import Ubuntu. Web 0.2
Module. We use two icons to return or forward. At the same time, we designed a TextField to input the address we want to go. Note that the address must be a string starting with http. When we press enter, the page will be opened by ourselves.
There is not much code, but it completes what we want to accomplish.
Source code for the entire project in: git clone https://gitcafe.com/ubuntu/browser.git