1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
46 property alias title: webView.title
47 property alias icon: webView.icon
48 property alias progress: webView.progress
49 property alias url: webView.url
50 property alias back: webView.back
51 property alias stop: webView.stop
52 property alias reload: webView.reload
53 property alias forward: webView.forward
57 contentWidth: Math.max(parent.width,webView.width)
58 contentHeight: Math.max(parent.height,webView.height)
59 anchors.top: headerSpace.bottom
60 anchors.bottom: parent.top
61 anchors.left: parent.left
62 anchors.right: parent.right
66 // Expand (but not above 1:1) if otherwise would be smaller that available width.
67 if (width > webView.width*webView.contentsScale && webView.contentsScale < 1.0)
68 webView.contentsScale = width / webView.width * webView.contentsScale;
73 transformOrigin: Item.TopLeft
77 if (url == "") return url
78 if (url[0] == "/") return "file://"+url
79 if (url.indexOf(":")<0) {
80 if (url.indexOf(".")<0 || url.indexOf(" ")>=0) {
81 // Fall back to a search engine; hard-code Wikipedia
82 return "http://en.wikipedia.org/w/index.php?search="+url
90 url: fixUrl(webBrowser.urlString)
91 smooth: false // We don't want smooth scaling, since we only scale during (fast) transitions
94 onAlert: console.log(message)
96 function doZoom(zoom,centerX,centerY)
99 var sc = zoom*contentsScale;
101 flickVX.from = flickable.contentX
102 flickVX.to = Math.max(0,Math.min(centerX-flickable.width/2,webView.width*sc-flickable.width))
103 finalX.value = flickVX.to
104 flickVY.from = flickable.contentY
105 flickVY.to = Math.max(0,Math.min(centerY-flickable.height/2,webView.height*sc-flickable.height))
106 finalY.value = flickVY.to
111 Keys.onLeftPressed: webView.contentsScale -= 0.1
112 Keys.onRightPressed: webView.contentsScale += 0.1
114 preferredWidth: flickable.width
115 preferredHeight: flickable.height
117 onContentsSizeChanged: {
119 contentsScale = Math.min(1,flickable.width / contentsSize.width)
123 flickable.contentX = 0
124 flickable.contentY = 0
125 if (url != null) { header.editUrl = url.toString(); }
128 if (!heuristicZoom(clickX,clickY,2.5)) {
129 var zf = flickable.width / contentsSize.width
130 if (zf >= contentsScale)
131 zf = 2.0*contentsScale // zoom in (else zooming out)
132 doZoom(zf,clickX*zf,clickY*zf)
136 SequentialAnimation {
141 property: "renderingEnabled"
148 property: "contentsScale"
149 // the to property is set before calling
150 easing.type: Easing.Linear
157 easing.type: Easing.Linear
159 from: 0 // set before calling
160 to: 0 // set before calling
166 easing.type: Easing.Linear
168 from: 0 // set before calling
169 to: 0 // set before calling
172 // Have to set the contentXY, since the above 2
173 // size changes may have started a correction if
174 // contentsScale < 1.0.
179 value: 0 // set before calling
185 value: 0 // set before calling
189 property: "renderingEnabled"
193 onZoomTo: doZoom(zoom,centerX,centerY)