tizen beta release
[framework/web/webkit-efl.git] / Tools / MiniBrowser / qt / qml / BrowserWindow.qml
1 /*
2  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
3  * Copyright (C) 2010 University of Szeged
4  *
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
20  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28
29 import QtQuick 2.0
30 import QtWebKit 3.0
31
32 Rectangle {
33     // Do not define anchors or an initial size here! This would mess up with QSGView::SizeRootObjectToView.
34
35     property alias webview: webView
36
37     signal pageTitleChanged(string title)
38
39     function load(address) {
40         webView.load(address)
41     }
42
43     function focusAddressBar() {
44         addressLine.forceActiveFocus()
45         addressLine.selectAll()
46     }
47
48     Rectangle {
49         id: navigationBar
50         color: "#efefef"
51         height: 30
52         anchors {
53             top: parent.top
54             left: parent.left
55             right: parent.right
56         }
57
58         Row {
59             id: controlsRow
60             spacing: 4
61             Rectangle {
62                 id: backButton
63                 height: navigationBar.height - 2
64                 width: height
65                 color: "#efefef"
66
67                 Image {
68                     anchors.centerIn: parent
69                     source: "../icons/previous.png"
70                 }
71
72                 Rectangle {
73                     anchors.fill: parent
74                     color: reloadButton.color
75                     opacity: 0.8
76                     visible: !webView.canGoBack
77                 }
78
79                 MouseArea {
80                     anchors.fill: parent
81                     onClicked: {
82                         console.log("going back")
83                         webView.goBack()
84                     }
85                 }
86             }
87             Rectangle {
88                 id: forwardButton
89                 height: navigationBar.height - 2
90                 width: height
91                 color: "#efefef"
92
93                 Image {
94                     anchors.centerIn: parent
95                     source: "../icons/next.png"
96                 }
97
98                 Rectangle {
99                     anchors.fill: parent
100                     color: forwardButton.color
101                     opacity: 0.8
102                     visible: !webView.canGoForward
103                 }
104
105                 MouseArea {
106                     anchors.fill: parent
107                     onClicked: {
108                         console.log("going forward")
109                         webView.goForward()
110                     }
111                 }
112             }
113             Rectangle {
114                 id: reloadButton
115                 height: navigationBar.height - 2
116                 width: height
117                 color: "#efefef"
118
119                 Image {
120                     anchors.centerIn: parent
121                     source: webView.canStop ? "../icons/stop.png" : "../icons/refresh.png"
122                 }
123
124                 MouseArea {
125                     anchors.fill: parent
126                     onClicked: {
127                         if (webView.canStop) {
128                             console.log("stop loading")
129                             webView.stop()
130                         } else {
131                             console.log("reloading")
132                             webView.reload()
133                         }
134                     }
135                 }
136             }
137         }
138         Rectangle {
139             color: "white"
140             height: navigationBar.height - 4
141             border.width: 1
142             anchors {
143                 left: controlsRow.right
144                 right: parent.right
145                 margins: 2
146                 verticalCenter: parent.verticalCenter
147             }
148             Rectangle {
149                 anchors {
150                     top: parent.top
151                     bottom: parent.bottom
152                     left: parent.left
153                 }
154                 width: parent.width / 100 * webView.loadProgress
155                 color: "blue"
156                 opacity: 0.3
157                 visible: webView.loadProgress != 100
158             }
159
160             TextInput {
161                 id: addressLine
162                 clip: true
163                 selectByMouse: true
164                 font {
165                     pointSize: 14
166                     family: "Helvetica"
167                 }
168                 anchors {
169                     verticalCenter: parent.verticalCenter
170                     left: parent.left
171                     right: parent.right
172                     margins: 2
173                 }
174
175                 Keys.onReturnPressed:{
176                     console.log("going to: ", addressLine.text)
177                     webView.load(utils.urlFromUserInput(addressLine.text))
178                 }
179
180                 Keys.onPressed: {
181                     if (((event.modifiers & Qt.ControlModifier) && event.key == Qt.Key_L) || event.key == Qt.key_F6) {
182                         focusAddressBar()
183                         event.accepted = true
184                     }
185                 }
186             }
187         }
188     }
189
190     WebView {
191         id: webView
192         anchors {
193             top: navigationBar.bottom
194             left: parent.left
195             right: parent.right
196             bottom: parent.bottom
197         }
198
199         onTitleChanged: pageTitleChanged(title)
200         onUrlChanged: {
201             addressLine.text = url
202             if (options.printLoadedUrls)
203                 console.log("Loaded:", webView.url);
204             forceActiveFocus();
205         }
206     }
207
208     Keys.onPressed: {
209         if (((event.modifiers & Qt.ControlModifier) && event.key == Qt.Key_L) || event.key == Qt.key_F6) {
210             focusAddressBar()
211             event.accepted = true
212         }
213     }
214 }