1 /****************************************************************************
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
6 ** This file is part of the QtBrowser project.
8 ** $QT_BEGIN_LICENSE:GPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
17 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 2 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.GPLv2 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU General Public License version 2 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 3.0 as published by the Free Software
28 ** Foundation and appearing in the file LICENSE.GPL included in the
29 ** packaging of this file. Please review the following information to
30 ** ensure the GNU General Public License version 3.0 requirements will be
31 ** met: http://www.gnu.org/copyleft/gpl.html.
36 ****************************************************************************/
39 import QtWebEngine 1.1
41 import QtQuick.Controls 1.0
42 import QtQuick.Controls.Styles 1.0
43 import QtQuick.Layouts 1.0
44 import QtQuick.Window 2.1
45 import QtQuick.Controls.Private 1.0
46 import QtQuick.Dialogs 1.2
47 import QtQuick.Enterprise.VirtualKeyboard 2.0
51 import "Utils.js" as Utils
56 property Item currentWebView: {
57 return tabView.get(tabView.currentIndex) ? tabView.get(tabView.currentIndex).item.webView : null
60 property string googleSearchQuery: "https://www.google.com/search?sourceid=qtbrowser&ie=UTF-8&q="
62 property int toolBarSize: 80
63 property string uiColor: settingsView.privateBrowsingEnabled ? "#26282a" : "#46a2da"
64 property string uiSeparatorColor: settingsView.privateBrowsingEnabled ? "#717273" : "#7ebee5"
65 property string toolBarSeparatorColor: settingsView.privateBrowsingEnabled ? "#929495" : "#a3d1ed"
66 property string toolBarFillColor: settingsView.privateBrowsingEnabled ? "#46484a" : uiSeparatorColor
67 property string buttonPressedColor: settingsView.privateBrowsingEnabled ? "#3b3c3e" : "#3f91c4"
68 property string emptyBackgroundColor: "#e4e4e4"
69 property string uiHighlightColor: "#fddd5c"
70 property string inactivePagerColor: "#bcbdbe"
71 property string textFieldStrokeColor: "#3882ae"
72 property string placeholderColor: "#a0a1a2"
73 property string iconOverlayColor: "#0e202c"
74 property string iconStrokeColor: "#d6d6d6"
75 property string defaultFontFamily: "Open Sans"
77 property int gridViewPageItemCount: 8
78 property int gridViewMaxBookmarks: 3 * gridViewPageItemCount
79 property int tabViewMaxTabs: 10
80 property int animationDuration: 200
81 property int velocityThreshold: 400
82 property int velocityY: 0
83 property real touchY: 0
84 property real touchReference: 0
85 property bool touchGesture: false
94 downloadView.visible = !downloadView.visible
102 navigation.addressBar.forceActiveFocus();
103 navigation.addressBar.selectAll();
110 currentWebView.reload()
111 navigation.addressBar.forceActiveFocus()
118 tabView.get(tabView.currentIndex).item.webView.takeSnapshot()
119 var tab = tabView.createEmptyTab()
124 navigation.addressBar.selectAll();
125 tabView.makeCurrent(tabView.count - 1)
126 navigation.addressBar.forceActiveFocus()
131 onTriggered: tabView.remove(tabView.currentIndex)
137 source: "icons/Btn_Add.png"
138 indicator: tabView.count
146 visible: opacity != 0.0
147 opacity: tabView.viewState == "list" ? 1.0 : 0.0
148 onDoneClicked: tabView.viewState = "page"
149 onOptionClicked: newTabAction.trigger()
155 title: qsTr("Settings")
156 visible: opacity != 0.0
166 settingsView.state = "disabled"
173 title: qsTr("Leave Full Screen Mode")
174 visible: opacity != 0.0
175 opacity: tabView.viewState == "fullscreen" ? 1.0 : 0.0
182 navigation.webView.triggerWebAction(WebEngineView.ExitFullScreen);
198 if (sslDialog.visible || homeScreen.state != "disabled" || urlDropDown.state == "enabled" || settingsView.state == "enabled")
204 top: navigation.bottom
211 Component.onCompleted: {
212 var tab = createEmptyTab()
217 navigation.webView = tab.webView
218 navigation.load(WebEngine.initialUrl);
220 onCurrentIndexChanged: {
221 if (!tabView.get(tabView.currentIndex))
223 navigation.webView = tabView.get(tabView.currentIndex).item.webView
228 id: acceptedCertificates
230 property var acceptedUrls : []
232 function shouldAutoAccept(certificateError){
233 var domain = WebEngine.domainFromString(certificateError.url)
234 return acceptedUrls.indexOf(domain) >= 0
241 property var certErrors: []
242 property var currentError: null
243 visible: certErrors.length > 0
244 icon: StandardIcon.Warning
245 standardButtons: StandardButton.No | StandardButton.Yes
246 title: "Server's certificate not trusted"
247 text: "Do you wish to continue?"
248 detailedText: "If you wish so, you may continue with an unverified certificate. " +
249 "Accepting an unverified certificate means " +
250 "you may not be connected with the host you tried to connect to.\n" +
251 "Do you wish to override the security check and continue?"
253 var cert = certErrors.shift()
254 var domain = WebEngine.domainFromString(cert.url)
255 acceptedCertificates.acceptedUrls.push(domain)
256 cert.ignoreCertificateError()
263 certErrors.shift().rejectCertificate()
266 function enqueue(error){
268 certErrors.push(error)
271 function presentError(){
272 informativeText = "SSL error from URL\n\n" + currentError.url + "\n\n" + currentError.description + "\n"
279 visible: navigation.visible
281 property string searchString: navigation.addressBar.text
286 top: navigation.bottom
296 height: browserWindow.height - toolBarSize - 3
310 color: emptyBackgroundColor
315 target: navigation.webView.navigationHistory.items
316 searchString: urlDropDown.searchString
317 enabled: urlDropDown.state == "enabled"
322 property int remainingHeight: Math.min((historyList.count + 1) * toolBarSize, inputPanel.y - toolBarSize - 3)
325 boundsBehavior: Flickable.StopAtBounds
326 footerPositioning: ListView.InlineFooter
327 visible: urlDropDown.state == "enabled"
334 height: remainingHeight
335 delegate: Rectangle {
337 width: historyList.width
345 navigation.webView.url = url
346 navigation.webView.forceActiveFocus()
351 width: parent.width - 60
352 height: parent.height
354 verticalCenter: parent.verticalCenter
355 horizontalCenter: parent.horizontalCenter
358 property string highlightTitle: title ? title : ""
359 height: wrapper.height / 2
361 elide: Text.ElideRight
362 verticalAlignment: Text.AlignBottom
368 font.family: defaultFontFamily
371 text: Utils.highlight(highlightTitle, urlDropDown.searchString)
374 property string highlightUrl: url ? url : ""
375 height: wrapper.height / 2 - 1
377 elide: Text.ElideRight
378 verticalAlignment: Text.AlignTop
379 font.family: defaultFontFamily
382 text: Utils.highlight(highlightUrl, urlDropDown.searchString)
385 anchors.horizontalCenter: parent.horizontalCenter
386 width: historyList.width
388 color: iconStrokeColor
394 width: historyList.width
399 var string = urlDropDown.searchString
400 var constructedUrl = ""
401 if (WebEngine.isUrl(string)) {
402 constructedUrl = WebEngine.fromUserInput(string)
404 constructedUrl = WebEngine.fromUserInput(googleSearchQuery + string)
406 navigation.webView.url = constructedUrl
407 navigation.webView.forceActiveFocus()
411 height: parent.height
414 height: parent.height
418 anchors.centerIn: parent
419 source: "assets/icons/Btn_Search.png"
424 height: parent.height
425 width: historyList.width - searchIcon.width - 30
426 elide: Text.ElideRight
427 text: urlDropDown.searchString
428 verticalAlignment: Text.AlignVCenter
429 font.family: defaultFontFamily
437 transitions: Transition {
438 PropertyAnimation { property: "height"; duration: animationDuration; easing.type : Easing.InSine }
444 height: parent.height - toolBarSize
446 top: navigation.bottom
454 height: parent.height - toolBarSize
456 top: navigation.bottom
463 y: browserWindow.height
465 left: browserWindow.left
466 right: browserWindow.right
470 when: Qt.inputMethod.visible
473 y: browserWindow.height - inputPanel.height
476 transitions: Transition {
482 duration: animationDuration
483 easing.type: Easing.InOutQuad