2
* Copyright 2013 Canonical Ltd.
4
* This file is part of webbrowser-app.
6
* webbrowser-app is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 3.
10
* webbrowser-app is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21
import Ubuntu.Components 0.1
22
import Ubuntu.Components.Extras.Browser 0.1
23
import Ubuntu.Unity.Action 1.0 as UnityActions
28
property bool chromeless: false
29
property real qtwebkitdpr
30
property bool developerExtrasEnabled: false
31
// necessary so that all widgets (including popovers) follow that
32
property alias automaticOrientation: orientationHelper.automaticOrientation
34
property alias currentIndex: tabsModel.currentIndex
35
property alias currentWebview: tabsModel.currentWebview
36
property string title: currentWebview ? currentWebview.title : ""
40
UnityActions.ActionManager {
44
// TRANSLATORS: This is a free-form list of keywords associated to the 'Goto' action.
45
// Keywords may actually be sentences, and must be separated by semi-colons.
46
keywords: i18n.tr("Address;URL;www")
47
parameterType: UnityActions.Action.String
48
onTriggered: currentWebview.url = value
52
// TRANSLATORS: This is a free-form list of keywords associated to the 'Back' action.
53
// Keywords may actually be sentences, and must be separated by semi-colons.
54
keywords: i18n.tr("Older Page")
55
enabled: currentWebview ? currentWebview.canGoBack : false
56
onTriggered: currentWebview.goBack()
59
text: i18n.tr("Forward")
60
// TRANSLATORS: This is a free-form list of keywords associated to the 'Forward' action.
61
// Keywords may actually be sentences, and must be separated by semi-colons.
62
keywords: i18n.tr("Newer Page")
63
enabled: currentWebview ? currentWebview.canGoForward : false
64
onTriggered: currentWebview.goForward()
67
text: i18n.tr("Reload")
68
// TRANSLATORS: This is a free-form list of keywords associated to the 'Reload' action.
69
// Keywords may actually be sentences, and must be separated by semi-colons.
70
keywords: i18n.tr("Leave Page")
71
enabled: currentWebview != null
72
onTriggered: currentWebview.reload()
75
text: i18n.tr("Bookmark")
76
// TRANSLATORS: This is a free-form list of keywords associated to the 'Bookmark' action.
77
// Keywords may actually be sentences, and must be separated by semi-colons.
78
keywords: i18n.tr("Add This Page to Bookmarks")
79
enabled: false // TODO: implement bookmarks
82
text: i18n.tr("New Tab")
83
// TRANSLATORS: This is a free-form list of keywords associated to the 'New Tab' action.
84
// Keywords may actually be sentences, and must be separated by semi-colons.
85
keywords: i18n.tr("Open a New Tab")
86
onTriggered: browser.newTab("", true)
102
visible: !activityView.visible
106
anchors.fill: webviewContainer
107
visible: currentWebview ? (currentWebview.lastLoadRequestStatus == WebView.LoadFailedStatus) : false
108
url: currentWebview ? currentWebview.url : ""
109
onRefreshClicked: currentWebview.reload()
118
historyModel: historyModel
120
onHistoryEntryRequested: {
121
currentWebview.url = url
125
browser.newTab("", true)
128
onSwitchToTabRequested: {
129
browser.switchToTab(index)
132
onCloseTabRequested: {
133
browser.closeTab(index)
134
if (tabsModel.count == 0) {
143
property Item chrome: item ? item.contents[0] : null
145
sourceComponent: browser.chromeless ? undefined : panelComponent
150
bottom: (item && item.opened) ? osk.top : parent.bottom
158
left: parent ? parent.left : undefined
159
right: parent ? parent.right : undefined
160
bottom: parent ? parent.bottom : undefined
167
Qt.inputMethod.hide()
174
url: currentWebview ? currentWebview.url : ""
176
loading: currentWebview ? currentWebview.loading || (currentWebview.loadProgress == 0) : false
177
loadProgress: currentWebview ? currentWebview.loadProgress : 0
179
canGoBack: currentWebview ? currentWebview.canGoBack : false
180
onGoBackClicked: currentWebview.goBack()
182
canGoForward: currentWebview ? currentWebview.canGoForward : false
183
onGoForwardClicked: currentWebview.goForward()
185
onUrlValidated: currentWebview.url = url
187
property bool stopped: false
191
panel.item.opened = true
193
} else if (stopped) {
195
} else if (!addressBar.activeFocus) {
197
panel.item.opened = false
199
if (currentWebview) {
200
currentWebview.forceActiveFocus()
205
onRequestReload: currentWebview.reload()
208
currentWebview.stop()
211
onToggleTabsClicked: {
212
activityView.visible = !activityView.visible
213
if (activityView.visible) {
214
currentWebview.forceActiveFocus()
215
panel.item.opened = false
224
opacity: (panel.chrome && (panel.item.state == "spread") &&
225
panel.chrome.addressBar.activeFocus && (count > 0)) ? 1.0 : 0.0
226
Behavior on opacity {
227
UbuntuNumberAnimation {}
232
horizontalCenter: parent.horizontalCenter
234
width: panel.width - units.gu(5)
235
height: Math.min(contentHeight, panel.y - units.gu(2))
236
model: historyMatches
238
currentWebview.url = url
239
currentWebview.forceActiveFocus()
250
databasePath: dataLocation + "/history.sqlite"
253
HistoryMatchesModel {
255
sourceModel: historyModel
256
query: panel.chrome ? panel.chrome.addressBar.text : ""
271
enabled: !activityView.visible
272
visible: tabsModel.currentWebview === webview
274
devicePixelRatio: browser.qtwebkitdpr
276
experimental.preferences.developerExtrasEnabled: browser.developerExtrasEnabled
278
property int lastLoadRequestStatus: -1
280
lastLoadRequestStatus = loadRequest.status
281
if (loadRequest.status === WebView.LoadSucceededStatus) {
282
historyModel.add(webview.url, webview.title, webview.icon)
286
onNewTabRequested: browser.newTab(url, true)
290
function newTab(url, setCurrent) {
291
var webview = webviewComponent.createObject(webviewContainer, {"url": url})
292
var index = tabsModel.add(webview)
294
tabsModel.currentIndex = index
295
if (!browser.chromeless) {
297
panel.chrome.addressBar.forceActiveFocus()
298
panel.item.opened = true
304
function closeTab(index) {
305
var webview = tabsModel.remove(index)
311
function switchToTab(index) {
312
tabsModel.currentIndex = index
313
currentWebview.forceActiveFocus()