author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 03 May 2010 13:17:34 +0300 | |
changeset 19 | fcece45ef507 |
parent 18 | 2f34d5167611 |
child 22 | 79de32ba3296 |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
Copyright (C) 2008,2009 Nokia Corporation and/or its subsidiary(-ies) |
|
3 |
Copyright (C) 2007 Staikos Computing Services Inc. |
|
4 |
||
5 |
This library is free software; you can redistribute it and/or |
|
6 |
modify it under the terms of the GNU Library General Public |
|
7 |
License as published by the Free Software Foundation; either |
|
8 |
version 2 of the License, or (at your option) any later version. |
|
9 |
||
10 |
This library 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 GNU |
|
13 |
Library General Public License for more details. |
|
14 |
||
15 |
You should have received a copy of the GNU Library General Public License |
|
16 |
along with this library; see the file COPYING.LIB. If not, write to |
|
17 |
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
18 |
Boston, MA 02110-1301, USA. |
|
19 |
*/ |
|
20 |
||
21 |
#include "config.h" |
|
22 |
#include "qwebframe.h" |
|
23 |
||
24 |
#include "CallFrame.h" |
|
25 |
#include "Document.h" |
|
26 |
#include "DocumentLoader.h" |
|
27 |
#include "DragData.h" |
|
28 |
#include "Element.h" |
|
29 |
#include "FocusController.h" |
|
30 |
#include "Frame.h" |
|
31 |
#include "FrameLoaderClientQt.h" |
|
32 |
#include "FrameTree.h" |
|
33 |
#include "FrameView.h" |
|
34 |
#include "GCController.h" |
|
35 |
#include "GraphicsContext.h" |
|
36 |
#include "HTMLMetaElement.h" |
|
37 |
#include "HitTestResult.h" |
|
38 |
#include "IconDatabase.h" |
|
39 |
#include "InspectorController.h" |
|
40 |
#include "JSDOMBinding.h" |
|
41 |
#include "JSDOMWindowBase.h" |
|
42 |
#include "JSLock.h" |
|
43 |
#include "JSObject.h" |
|
44 |
#include "NodeList.h" |
|
45 |
#include "Page.h" |
|
46 |
#include "PlatformMouseEvent.h" |
|
47 |
#include "PlatformWheelEvent.h" |
|
48 |
#include "PrintContext.h" |
|
49 |
#include "PutPropertySlot.h" |
|
50 |
#include "RenderTreeAsText.h" |
|
51 |
#include "RenderView.h" |
|
52 |
#include "ResourceRequest.h" |
|
53 |
#include "ScriptController.h" |
|
54 |
#include "ScriptSourceCode.h" |
|
55 |
#include "ScriptValue.h" |
|
56 |
#include "Scrollbar.h" |
|
57 |
#include "SelectionController.h" |
|
58 |
#include "SubstituteData.h" |
|
59 |
#include "htmlediting.h" |
|
60 |
#include "markup.h" |
|
61 |
#include "qt_instance.h" |
|
62 |
#include "qt_runtime.h" |
|
63 |
#include "qwebelement.h" |
|
64 |
#include "qwebframe_p.h" |
|
65 |
#include "qwebpage.h" |
|
66 |
#include "qwebpage_p.h" |
|
67 |
#include "qwebsecurityorigin.h" |
|
68 |
#include "qwebsecurityorigin_p.h" |
|
69 |
#include "runtime.h" |
|
70 |
#include "runtime_object.h" |
|
71 |
#include "runtime_root.h" |
|
72 |
#include "wtf/HashMap.h" |
|
73 |
#include <QMultiMap> |
|
74 |
#include <qdebug.h> |
|
75 |
#include <qevent.h> |
|
76 |
#include <qfileinfo.h> |
|
77 |
#include <qpainter.h> |
|
78 |
#include <qprinter.h> |
|
79 |
#include <qregion.h> |
|
80 |
||
81 |
#if QT_VERSION < 0x040400 |
|
82 |
#include "qwebnetworkinterface.h" |
|
83 |
#endif |
|
84 |
||
85 |
#if QT_VERSION >= 0x040400 |
|
86 |
#include <qnetworkrequest.h> |
|
87 |
#endif |
|
88 |
||
89 |
using namespace WebCore; |
|
90 |
||
91 |
// from text/qfont.cpp |
|
92 |
QT_BEGIN_NAMESPACE |
|
93 |
extern Q_GUI_EXPORT int qt_defaultDpi(); |
|
94 |
QT_END_NAMESPACE |
|
95 |
||
96 |
void QWEBKIT_EXPORT qt_drt_setJavaScriptProfilingEnabled(QWebFrame* qframe, bool enabled) |
|
97 |
{ |
|
98 |
#if ENABLE(JAVASCRIPT_DEBUGGER) |
|
99 |
Frame* frame = QWebFramePrivate::core(qframe); |
|
100 |
InspectorController* controller = frame->page()->inspectorController(); |
|
101 |
if (!controller) |
|
102 |
return; |
|
103 |
if (enabled) |
|
104 |
controller->enableProfiler(); |
|
105 |
else |
|
106 |
controller->disableProfiler(); |
|
107 |
#endif |
|
108 |
} |
|
109 |
||
110 |
// Pause a given CSS animation or transition on the target node at a specific time. |
|
111 |
// If the animation or transition is already paused, it will update its pause time. |
|
112 |
// This method is only intended to be used for testing the CSS animation and transition system. |
|
113 |
bool QWEBKIT_EXPORT qt_drt_pauseAnimation(QWebFrame *qframe, const QString &animationName, double time, const QString &elementId) |
|
114 |
{ |
|
115 |
Frame* frame = QWebFramePrivate::core(qframe); |
|
116 |
if (!frame) |
|
117 |
return false; |
|
118 |
||
119 |
AnimationController* controller = frame->animation(); |
|
120 |
if (!controller) |
|
121 |
return false; |
|
122 |
||
123 |
Document* doc = frame->document(); |
|
124 |
Q_ASSERT(doc); |
|
125 |
||
126 |
Node* coreNode = doc->getElementById(elementId); |
|
127 |
if (!coreNode || !coreNode->renderer()) |
|
128 |
return false; |
|
129 |
||
130 |
return controller->pauseAnimationAtTime(coreNode->renderer(), animationName, time); |
|
131 |
} |
|
132 |
||
133 |
bool QWEBKIT_EXPORT qt_drt_pauseTransitionOfProperty(QWebFrame *qframe, const QString &propertyName, double time, const QString &elementId) |
|
134 |
{ |
|
135 |
Frame* frame = QWebFramePrivate::core(qframe); |
|
136 |
if (!frame) |
|
137 |
return false; |
|
138 |
||
139 |
AnimationController* controller = frame->animation(); |
|
140 |
if (!controller) |
|
141 |
return false; |
|
142 |
||
143 |
Document* doc = frame->document(); |
|
144 |
Q_ASSERT(doc); |
|
145 |
||
146 |
Node* coreNode = doc->getElementById(elementId); |
|
147 |
if (!coreNode || !coreNode->renderer()) |
|
148 |
return false; |
|
149 |
||
150 |
return controller->pauseTransitionAtTime(coreNode->renderer(), propertyName, time); |
|
151 |
} |
|
152 |
||
153 |
// Returns the total number of currently running animations (includes both CSS transitions and CSS animations). |
|
154 |
int QWEBKIT_EXPORT qt_drt_numberOfActiveAnimations(QWebFrame *qframe) |
|
155 |
{ |
|
156 |
Frame* frame = QWebFramePrivate::core(qframe); |
|
157 |
if (!frame) |
|
158 |
return false; |
|
159 |
||
160 |
AnimationController* controller = frame->animation(); |
|
161 |
if (!controller) |
|
162 |
return false; |
|
163 |
||
164 |
return controller->numberOfActiveAnimations(); |
|
165 |
} |
|
166 |
||
167 |
void QWEBKIT_EXPORT qt_drt_clearFrameName(QWebFrame* qFrame) |
|
168 |
{ |
|
169 |
Frame* frame = QWebFramePrivate::core(qFrame); |
|
170 |
frame->tree()->clearName(); |
|
171 |
} |
|
172 |
||
173 |
int QWEBKIT_EXPORT qt_drt_javaScriptObjectsCount() |
|
174 |
{ |
|
175 |
return JSDOMWindowBase::commonJSGlobalData()->heap.globalObjectCount(); |
|
176 |
} |
|
177 |
||
178 |
void QWEBKIT_EXPORT qt_drt_garbageCollector_collect() |
|
179 |
{ |
|
180 |
gcController().garbageCollectNow(); |
|
181 |
} |
|
182 |
||
183 |
void QWEBKIT_EXPORT qt_drt_garbageCollector_collectOnAlternateThread(bool waitUntilDone) |
|
184 |
{ |
|
185 |
gcController().garbageCollectOnAlternateThreadForDebugging(waitUntilDone); |
|
186 |
} |
|
187 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
188 |
// Returns the value of counter in the element specified by \a id. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
189 |
QString QWEBKIT_EXPORT qt_drt_counterValueForElementById(QWebFrame* qFrame, const QString& id) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
190 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
191 |
Frame* frame = QWebFramePrivate::core(qFrame); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
192 |
if (Document* document = frame->document()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
193 |
Element* element = document->getElementById(id); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
194 |
return WebCore::counterValueForElement(element); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
195 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
196 |
return QString(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
197 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
198 |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
199 |
// Suspend active DOM objects in this frame. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
200 |
void QWEBKIT_EXPORT qt_suspendActiveDOMObjects(QWebFrame* qFrame) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
201 |
{ |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
202 |
Frame* frame = QWebFramePrivate::core(qFrame); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
203 |
if (frame->document()) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
204 |
frame->document()->suspendActiveDOMObjects(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
205 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
206 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
207 |
// Resume active DOM objects in this frame. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
208 |
void QWEBKIT_EXPORT qt_resumeActiveDOMObjects(QWebFrame* qFrame) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
209 |
{ |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
210 |
Frame* frame = QWebFramePrivate::core(qFrame); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
211 |
if (frame->document()) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
212 |
frame->document()->resumeActiveDOMObjects(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
213 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
214 |
|
0 | 215 |
QWebFrameData::QWebFrameData(WebCore::Page* parentPage, WebCore::Frame* parentFrame, |
216 |
WebCore::HTMLFrameOwnerElement* ownerFrameElement, |
|
217 |
const WebCore::String& frameName) |
|
218 |
: name(frameName) |
|
219 |
, ownerElement(ownerFrameElement) |
|
220 |
, page(parentPage) |
|
221 |
, allowsScrolling(true) |
|
222 |
, marginWidth(0) |
|
223 |
, marginHeight(0) |
|
224 |
{ |
|
225 |
frameLoaderClient = new FrameLoaderClientQt(); |
|
226 |
frame = Frame::create(page, ownerElement, frameLoaderClient); |
|
227 |
||
228 |
// FIXME: All of the below should probably be moved over into WebCore |
|
229 |
frame->tree()->setName(name); |
|
230 |
if (parentFrame) |
|
231 |
parentFrame->tree()->appendChild(frame); |
|
232 |
} |
|
233 |
||
234 |
void QWebFramePrivate::init(QWebFrame *qframe, QWebFrameData *frameData) |
|
235 |
{ |
|
236 |
q = qframe; |
|
237 |
||
238 |
allowsScrolling = frameData->allowsScrolling; |
|
239 |
marginWidth = frameData->marginWidth; |
|
240 |
marginHeight = frameData->marginHeight; |
|
241 |
frame = frameData->frame.get(); |
|
242 |
frameLoaderClient = frameData->frameLoaderClient; |
|
243 |
frameLoaderClient->setFrame(qframe, frame); |
|
244 |
||
245 |
frame->init(); |
|
246 |
} |
|
247 |
||
248 |
WebCore::Scrollbar* QWebFramePrivate::horizontalScrollBar() const |
|
249 |
{ |
|
250 |
if (!frame->view()) |
|
251 |
return 0; |
|
252 |
return frame->view()->horizontalScrollbar(); |
|
253 |
} |
|
254 |
||
255 |
WebCore::Scrollbar* QWebFramePrivate::verticalScrollBar() const |
|
256 |
{ |
|
257 |
if (!frame->view()) |
|
258 |
return 0; |
|
259 |
return frame->view()->verticalScrollbar(); |
|
260 |
} |
|
261 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
262 |
void QWebFramePrivate::renderPrivate(QPainter *painter, QWebFrame::RenderLayer layer, const QRegion &clip) |
0 | 263 |
{ |
264 |
if (!frame->view() || !frame->contentRenderer()) |
|
265 |
return; |
|
266 |
||
267 |
QVector<QRect> vector = clip.rects(); |
|
268 |
if (vector.isEmpty()) |
|
269 |
return; |
|
270 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
271 |
GraphicsContext context(painter); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
272 |
if (context.paintingDisabled() && !context.updatingControlTints()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
273 |
return; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
274 |
|
0 | 275 |
WebCore::FrameView* view = frame->view(); |
276 |
view->layoutIfNeededRecursive(); |
|
277 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
278 |
for (int i = 0; i < vector.size(); ++i) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
279 |
const QRect& clipRect = vector.at(i); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
280 |
QRect intersectedRect = clipRect.intersected(view->frameRect()); |
0 | 281 |
|
282 |
painter->save(); |
|
283 |
painter->setClipRect(clipRect, Qt::IntersectClip); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
284 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
285 |
int x = view->x(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
286 |
int y = view->y(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
287 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
288 |
if (layer & QWebFrame::ContentsLayer) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
289 |
context.save(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
290 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
291 |
int scrollX = view->scrollX(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
292 |
int scrollY = view->scrollY(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
293 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
294 |
QRect rect = intersectedRect; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
295 |
context.translate(x, y); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
296 |
rect.translate(-x, -y); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
297 |
context.translate(-scrollX, -scrollY); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
298 |
rect.translate(scrollX, scrollY); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
299 |
context.clip(view->visibleContentRect()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
300 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
301 |
view->paintContents(&context, rect); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
302 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
303 |
context.restore(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
304 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
305 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
306 |
if (layer & QWebFrame::ScrollBarLayer |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
307 |
&& !view->scrollbarsSuppressed() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
308 |
&& (view->horizontalScrollbar() || view->verticalScrollbar())) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
309 |
context.save(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
310 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
311 |
QRect rect = intersectedRect; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
312 |
context.translate(x, y); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
313 |
rect.translate(-x, -y); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
314 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
315 |
view->paintScrollbars(&context, rect); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
316 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
317 |
context.restore(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
318 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
319 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
320 |
if (layer & QWebFrame::PanIconLayer) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
321 |
view->paintPanScrollIcon(&context); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
322 |
|
0 | 323 |
painter->restore(); |
324 |
} |
|
325 |
} |
|
326 |
||
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
327 |
static bool webframe_scrollOverflow(WebCore::Frame* frame, int dx, int dy, const QPoint& pos) |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
328 |
{ |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
329 |
if (!frame || !frame->document() || !frame->eventHandler()) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
330 |
return false; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
331 |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
332 |
Node* node = frame->document()->elementFromPoint(pos.x(), pos.y()); |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
333 |
if (!node) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
334 |
return false; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
335 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
336 |
RenderObject* renderer = node->renderer(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
337 |
if (!renderer) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
338 |
return false; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
339 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
340 |
if (renderer->isListBox()) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
341 |
return false; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
342 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
343 |
RenderLayer* renderLayer = renderer->enclosingLayer(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
344 |
if (!renderLayer) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
345 |
return false; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
346 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
347 |
bool scrolledHorizontal = false; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
348 |
bool scrolledVertical = false; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
349 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
350 |
if (dx > 0) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
351 |
scrolledHorizontal = renderLayer->scroll(ScrollRight, ScrollByPixel, dx); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
352 |
else if (dx < 0) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
353 |
scrolledHorizontal = renderLayer->scroll(ScrollLeft, ScrollByPixel, qAbs(dx)); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
354 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
355 |
if (dy > 0) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
356 |
scrolledVertical = renderLayer->scroll(ScrollDown, ScrollByPixel, dy); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
357 |
else if (dy < 0) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
358 |
scrolledVertical = renderLayer->scroll(ScrollUp, ScrollByPixel, qAbs(dy)); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
359 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
360 |
return (scrolledHorizontal || scrolledVertical); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
361 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
362 |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
363 |
|
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
364 |
|
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
365 |
|
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
366 |
|
0 | 367 |
/*! |
368 |
\class QWebFrame |
|
369 |
\since 4.4 |
|
370 |
\brief The QWebFrame class represents a frame in a web page. |
|
371 |
||
372 |
\inmodule QtWebKit |
|
373 |
||
374 |
QWebFrame represents a frame inside a web page. Each QWebPage |
|
375 |
object contains at least one frame, the main frame, obtained using |
|
376 |
QWebPage::mainFrame(). Additional frames will be created for HTML |
|
377 |
\c{<frame>} or \c{<iframe>} elements. |
|
378 |
||
379 |
A frame can be loaded using load() or setUrl(). Alternatively, if you have |
|
380 |
the HTML content readily available, you can use setHtml() instead. |
|
381 |
||
382 |
The page() function returns a pointer to the web page object. See |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
383 |
\l{QWebView}{Elements of QWebView} for an explanation of how web |
0 | 384 |
frames are related to a web page and web view. |
385 |
||
386 |
The QWebFrame class also offers methods to retrieve both the URL currently |
|
387 |
loaded by the frame (see url()) as well as the URL originally requested |
|
388 |
to be loaded (see requestedUrl()). These methods make possible the retrieval |
|
389 |
of the URL before and after a DNS resolution or a redirection occurs during |
|
390 |
the load process. The requestedUrl() also matches to the URL added to the |
|
391 |
frame history (\l{QWebHistory}) if load is successful. |
|
392 |
||
393 |
The title of an HTML frame can be accessed with the title() property. |
|
394 |
Additionally, a frame may also specify an icon, which can be accessed |
|
395 |
using the icon() property. If the title or the icon changes, the |
|
396 |
corresponding titleChanged() and iconChanged() signals will be emitted. |
|
397 |
The zoomFactor() property can be used to change the overall size |
|
398 |
of the content displayed in the frame. |
|
399 |
||
400 |
QWebFrame objects are created and controlled by the web page. You |
|
401 |
can connect to the web page's \l{QWebPage::}{frameCreated()} signal |
|
402 |
to be notified when a new frame is created. |
|
403 |
||
404 |
The hitTestContent() function can be used to programmatically examine the |
|
405 |
contents of a frame. |
|
406 |
||
407 |
A QWebFrame can be printed onto a QPrinter using the print() function. |
|
408 |
This function is marked as a slot and can be conveniently connected to |
|
409 |
\l{QPrintPreviewDialog}'s \l{QPrintPreviewDialog::}{paintRequested()} |
|
410 |
signal. |
|
411 |
||
412 |
\sa QWebPage |
|
413 |
*/ |
|
414 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
415 |
/*! |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
416 |
\enum QWebFrame::RenderLayer |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
417 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
418 |
This enum describes the layers available for rendering using \l{QWebFrame::}{render()}. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
419 |
The layers can be OR-ed together from the following list: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
420 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
421 |
\value ContentsLayer The web content of the frame |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
422 |
\value ScrollBarLayer The scrollbars of the frame |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
423 |
\value PanIconLayer The icon used when panning the frame |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
424 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
425 |
\value AllLayers Includes all the above layers |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
426 |
*/ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
427 |
|
0 | 428 |
QWebFrame::QWebFrame(QWebPage *parent, QWebFrameData *frameData) |
429 |
: QObject(parent) |
|
430 |
, d(new QWebFramePrivate) |
|
431 |
{ |
|
432 |
d->page = parent; |
|
433 |
d->init(this, frameData); |
|
434 |
||
435 |
if (!frameData->url.isEmpty()) { |
|
436 |
WebCore::ResourceRequest request(frameData->url, frameData->referrer); |
|
437 |
d->frame->loader()->load(request, frameData->name, false); |
|
438 |
} |
|
439 |
} |
|
440 |
||
441 |
QWebFrame::QWebFrame(QWebFrame *parent, QWebFrameData *frameData) |
|
442 |
: QObject(parent) |
|
443 |
, d(new QWebFramePrivate) |
|
444 |
{ |
|
445 |
d->page = parent->d->page; |
|
446 |
d->init(this, frameData); |
|
447 |
} |
|
448 |
||
449 |
QWebFrame::~QWebFrame() |
|
450 |
{ |
|
451 |
if (d->frame && d->frame->loader() && d->frame->loader()->client()) |
|
452 |
static_cast<FrameLoaderClientQt*>(d->frame->loader()->client())->m_webFrame = 0; |
|
453 |
||
454 |
delete d; |
|
455 |
} |
|
456 |
||
457 |
/*! |
|
458 |
Make \a object available under \a name from within the frame's JavaScript |
|
459 |
context. The \a object will be inserted as a child of the frame's window |
|
460 |
object. |
|
461 |
||
462 |
Qt properties will be exposed as JavaScript properties and slots as |
|
463 |
JavaScript methods. |
|
464 |
||
465 |
If you want to ensure that your QObjects remain accessible after loading a |
|
466 |
new URL, you should add them in a slot connected to the |
|
467 |
javaScriptWindowObjectCleared() signal. |
|
468 |
||
469 |
If Javascript is not enabled for this page, then this method does nothing. |
|
470 |
||
471 |
The \a object will never be explicitly deleted by QtWebKit. |
|
472 |
*/ |
|
473 |
void QWebFrame::addToJavaScriptWindowObject(const QString &name, QObject *object) |
|
474 |
{ |
|
475 |
addToJavaScriptWindowObject(name, object, QScriptEngine::QtOwnership); |
|
476 |
} |
|
477 |
||
478 |
/*! |
|
479 |
\fn void QWebFrame::addToJavaScriptWindowObject(const QString &name, QObject *object, QScriptEngine::ValueOwnership own) |
|
480 |
\overload |
|
481 |
||
482 |
Make \a object available under \a name from within the frame's JavaScript |
|
483 |
context. The \a object will be inserted as a child of the frame's window |
|
484 |
object. |
|
485 |
||
486 |
Qt properties will be exposed as JavaScript properties and slots as |
|
487 |
JavaScript methods. |
|
488 |
||
489 |
If you want to ensure that your QObjects remain accessible after loading a |
|
490 |
new URL, you should add them in a slot connected to the |
|
491 |
javaScriptWindowObjectCleared() signal. |
|
492 |
||
493 |
If Javascript is not enabled for this page, then this method does nothing. |
|
494 |
||
495 |
The ownership of \a object is specified using \a own. |
|
496 |
*/ |
|
497 |
void QWebFrame::addToJavaScriptWindowObject(const QString &name, QObject *object, QScriptEngine::ValueOwnership ownership) |
|
498 |
{ |
|
499 |
if (!page()->settings()->testAttribute(QWebSettings::JavascriptEnabled)) |
|
500 |
return; |
|
501 |
||
502 |
JSC::JSLock lock(JSC::SilenceAssertionsOnly); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
503 |
JSDOMWindow* window = toJSDOMWindow(d->frame, mainThreadNormalWorld()); |
0 | 504 |
JSC::Bindings::RootObject* root = d->frame->script()->bindingRootObject(); |
505 |
if (!window) { |
|
506 |
qDebug() << "Warning: couldn't get window object"; |
|
507 |
return; |
|
508 |
} |
|
509 |
||
510 |
JSC::ExecState* exec = window->globalExec(); |
|
511 |
||
512 |
JSC::JSObject* runtimeObject = |
|
513 |
JSC::Bindings::QtInstance::getQtInstance(object, root, ownership)->createRuntimeObject(exec); |
|
514 |
||
515 |
JSC::PutPropertySlot slot; |
|
516 |
window->put(exec, JSC::Identifier(exec, (const UChar *) name.constData(), name.length()), runtimeObject, slot); |
|
517 |
} |
|
518 |
||
519 |
/*! |
|
520 |
Returns the frame's content as HTML, enclosed in HTML and BODY tags. |
|
521 |
||
522 |
\sa setHtml(), toPlainText() |
|
523 |
*/ |
|
524 |
QString QWebFrame::toHtml() const |
|
525 |
{ |
|
526 |
if (!d->frame->document()) |
|
527 |
return QString(); |
|
528 |
return createMarkup(d->frame->document()); |
|
529 |
} |
|
530 |
||
531 |
/*! |
|
532 |
Returns the content of this frame converted to plain text, completely |
|
533 |
stripped of all HTML formatting. |
|
534 |
||
535 |
\sa toHtml() |
|
536 |
*/ |
|
537 |
QString QWebFrame::toPlainText() const |
|
538 |
{ |
|
539 |
if (d->frame->view() && d->frame->view()->layoutPending()) |
|
540 |
d->frame->view()->layout(); |
|
541 |
||
542 |
Element *documentElement = d->frame->document()->documentElement(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
543 |
if (documentElement) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
544 |
return documentElement->innerText(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
545 |
return QString(); |
0 | 546 |
} |
547 |
||
548 |
/*! |
|
549 |
Returns a dump of the rendering tree. This is mainly useful for debugging |
|
550 |
html. |
|
551 |
*/ |
|
552 |
QString QWebFrame::renderTreeDump() const |
|
553 |
{ |
|
554 |
if (d->frame->view() && d->frame->view()->layoutPending()) |
|
555 |
d->frame->view()->layout(); |
|
556 |
||
557 |
return externalRepresentation(d->frame->contentRenderer()); |
|
558 |
} |
|
559 |
||
560 |
/*! |
|
561 |
\property QWebFrame::title |
|
562 |
\brief the title of the frame as defined by the HTML <title> element |
|
563 |
||
564 |
\sa titleChanged() |
|
565 |
*/ |
|
566 |
||
567 |
QString QWebFrame::title() const |
|
568 |
{ |
|
569 |
if (d->frame->document()) |
|
570 |
return d->frame->loader()->documentLoader()->title(); |
|
571 |
return QString(); |
|
572 |
} |
|
573 |
||
574 |
/*! |
|
575 |
\since 4.5 |
|
576 |
\brief Returns the meta data in this frame as a QMultiMap |
|
577 |
||
578 |
The meta data consists of the name and content attributes of the |
|
579 |
of the \c{<meta>} tags in the HTML document. |
|
580 |
||
581 |
For example: |
|
582 |
||
583 |
\code |
|
584 |
<html> |
|
585 |
<head> |
|
586 |
<meta name="description" content="This document is a tutorial about Qt development"> |
|
587 |
<meta name="keywords" content="Qt, WebKit, Programming"> |
|
588 |
</head> |
|
589 |
... |
|
590 |
</html> |
|
591 |
\endcode |
|
592 |
||
593 |
Given the above HTML code the metaData() function will return a map with two entries: |
|
594 |
\table |
|
595 |
\header \o Key |
|
596 |
\o Value |
|
597 |
\row \o "description" |
|
598 |
\o "This document is a tutorial about Qt development" |
|
599 |
\row \o "keywords" |
|
600 |
\o "Qt, WebKit, Programming" |
|
601 |
\endtable |
|
602 |
||
603 |
This function returns a multi map to support multiple meta tags with the same attribute name. |
|
604 |
*/ |
|
605 |
QMultiMap<QString, QString> QWebFrame::metaData() const |
|
606 |
{ |
|
607 |
if (!d->frame->document()) |
|
608 |
return QMap<QString, QString>(); |
|
609 |
||
610 |
QMultiMap<QString, QString> map; |
|
611 |
Document* doc = d->frame->document(); |
|
612 |
RefPtr<NodeList> list = doc->getElementsByTagName("meta"); |
|
613 |
unsigned len = list->length(); |
|
614 |
for (unsigned i = 0; i < len; i++) { |
|
615 |
HTMLMetaElement* meta = static_cast<HTMLMetaElement*>(list->item(i)); |
|
616 |
map.insert(meta->name(), meta->content()); |
|
617 |
} |
|
618 |
return map; |
|
619 |
} |
|
620 |
||
621 |
static inline QUrl ensureAbsoluteUrl(const QUrl &url) |
|
622 |
{ |
|
623 |
if (!url.isRelative()) |
|
624 |
return url; |
|
625 |
||
626 |
return QUrl::fromLocalFile(QFileInfo(url.toLocalFile()).absoluteFilePath()); |
|
627 |
} |
|
628 |
||
629 |
/*! |
|
630 |
\property QWebFrame::url |
|
631 |
\brief the url of the frame currently viewed |
|
632 |
||
633 |
\sa urlChanged() |
|
634 |
*/ |
|
635 |
||
636 |
void QWebFrame::setUrl(const QUrl &url) |
|
637 |
{ |
|
638 |
d->frame->loader()->begin(ensureAbsoluteUrl(url)); |
|
639 |
d->frame->loader()->end(); |
|
640 |
load(ensureAbsoluteUrl(url)); |
|
641 |
} |
|
642 |
||
643 |
QUrl QWebFrame::url() const |
|
644 |
{ |
|
645 |
return d->frame->loader()->url(); |
|
646 |
} |
|
647 |
||
648 |
/*! |
|
649 |
\since 4.6 |
|
650 |
\property QWebFrame::requestedUrl |
|
651 |
||
652 |
The URL requested to loaded by the frame currently viewed. The URL may differ from |
|
653 |
the one returned by url() if a DNS resolution or a redirection occurs. |
|
654 |
||
655 |
\sa url(), setUrl() |
|
656 |
*/ |
|
657 |
QUrl QWebFrame::requestedUrl() const |
|
658 |
{ |
|
659 |
// There are some possible edge cases to be handled here, |
|
660 |
// apart from checking if activeDocumentLoader is valid: |
|
661 |
// |
|
662 |
// * Method can be called while processing an unsucessful load. |
|
663 |
// In this case, frameLoaderClient will hold the current error |
|
664 |
// (m_loadError), and we will make use of it to recover the 'failingURL'. |
|
665 |
// * If the 'failingURL' holds a null'ed string though, we fallback |
|
666 |
// to 'outgoingReferrer' (it yet is safer than originalRequest). |
|
667 |
FrameLoader* loader = d->frame->loader(); |
|
668 |
FrameLoaderClientQt* loaderClient = d->frameLoaderClient; |
|
669 |
||
670 |
if (!loader->activeDocumentLoader() |
|
671 |
|| !loaderClient->m_loadError.isNull()) { |
|
672 |
if (!loaderClient->m_loadError.failingURL().isNull()) |
|
673 |
return QUrl(loaderClient->m_loadError.failingURL()); |
|
674 |
else if (!loader->outgoingReferrer().isEmpty()) |
|
675 |
return QUrl(loader->outgoingReferrer()); |
|
676 |
} |
|
677 |
||
678 |
return loader->originalRequest().url(); |
|
679 |
} |
|
680 |
/*! |
|
681 |
\since 4.6 |
|
682 |
\property QWebFrame::baseUrl |
|
683 |
\brief the base URL of the frame, can be used to resolve relative URLs |
|
684 |
\since 4.6 |
|
685 |
*/ |
|
686 |
||
687 |
QUrl QWebFrame::baseUrl() const |
|
688 |
{ |
|
689 |
return d->frame->loader()->baseURL(); |
|
690 |
} |
|
691 |
||
692 |
/*! |
|
693 |
\property QWebFrame::icon |
|
694 |
\brief the icon associated with this frame |
|
695 |
||
696 |
\sa iconChanged(), QWebSettings::iconForUrl() |
|
697 |
*/ |
|
698 |
||
699 |
QIcon QWebFrame::icon() const |
|
700 |
{ |
|
701 |
return QWebSettings::iconForUrl(d->frame->loader()->url()); |
|
702 |
} |
|
703 |
||
704 |
/*! |
|
705 |
The name of this frame as defined by the parent frame. |
|
706 |
*/ |
|
707 |
QString QWebFrame::frameName() const |
|
708 |
{ |
|
709 |
return d->frame->tree()->name(); |
|
710 |
} |
|
711 |
||
712 |
/*! |
|
713 |
The web page that contains this frame. |
|
714 |
*/ |
|
715 |
QWebPage *QWebFrame::page() const |
|
716 |
{ |
|
717 |
return d->page; |
|
718 |
} |
|
719 |
||
720 |
/*! |
|
721 |
Loads \a url into this frame. |
|
722 |
||
723 |
\note The view remains the same until enough data has arrived to display the new \a url. |
|
724 |
||
725 |
\sa setUrl(), setHtml(), setContent() |
|
726 |
*/ |
|
727 |
void QWebFrame::load(const QUrl &url) |
|
728 |
{ |
|
729 |
#if QT_VERSION < 0x040400 |
|
730 |
load(QWebNetworkRequest(ensureAbsoluteUrl(url))); |
|
731 |
#else |
|
732 |
load(QNetworkRequest(ensureAbsoluteUrl(url))); |
|
733 |
#endif |
|
734 |
} |
|
735 |
||
736 |
#if QT_VERSION < 0x040400 |
|
737 |
/*! |
|
738 |
Loads a network request, \a req, into this frame. |
|
739 |
||
740 |
\note The view remains the same until enough data has arrived to display the new url. |
|
741 |
*/ |
|
742 |
void QWebFrame::load(const QWebNetworkRequest &req) |
|
743 |
{ |
|
744 |
if (d->parentFrame()) |
|
745 |
d->page->d->insideOpenCall = true; |
|
746 |
||
747 |
QUrl url = ensureAbsoluteUrl(req.url()); |
|
748 |
QHttpRequestHeader httpHeader = req.httpHeader(); |
|
749 |
QByteArray postData = req.postData(); |
|
750 |
||
751 |
WebCore::ResourceRequest request(url); |
|
752 |
||
753 |
QString method = httpHeader.method(); |
|
754 |
if (!method.isEmpty()) |
|
755 |
request.setHTTPMethod(method); |
|
756 |
||
757 |
QList<QPair<QString, QString> > values = httpHeader.values(); |
|
758 |
for (int i = 0; i < values.size(); ++i) { |
|
759 |
const QPair<QString, QString> &val = values.at(i); |
|
760 |
request.addHTTPHeaderField(val.first, val.second); |
|
761 |
} |
|
762 |
||
763 |
if (!postData.isEmpty()) |
|
764 |
request.setHTTPBody(WebCore::FormData::create(postData.constData(), postData.size())); |
|
765 |
||
766 |
d->frame->loader()->load(request, false); |
|
767 |
||
768 |
if (d->parentFrame()) |
|
769 |
d->page->d->insideOpenCall = false; |
|
770 |
} |
|
771 |
||
772 |
#else |
|
773 |
||
774 |
/*! |
|
775 |
Loads a network request, \a req, into this frame, using the method specified in \a |
|
776 |
operation. |
|
777 |
||
778 |
\a body is optional and is only used for POST operations. |
|
779 |
||
780 |
\note The view remains the same until enough data has arrived to display the new \a url. |
|
781 |
||
782 |
\sa setUrl() |
|
783 |
*/ |
|
784 |
void QWebFrame::load(const QNetworkRequest &req, |
|
785 |
QNetworkAccessManager::Operation operation, |
|
786 |
const QByteArray &body) |
|
787 |
{ |
|
788 |
if (d->parentFrame()) |
|
789 |
d->page->d->insideOpenCall = true; |
|
790 |
||
791 |
QUrl url = ensureAbsoluteUrl(req.url()); |
|
792 |
||
793 |
WebCore::ResourceRequest request(url); |
|
794 |
||
795 |
switch (operation) { |
|
796 |
case QNetworkAccessManager::HeadOperation: |
|
797 |
request.setHTTPMethod("HEAD"); |
|
798 |
break; |
|
799 |
case QNetworkAccessManager::GetOperation: |
|
800 |
request.setHTTPMethod("GET"); |
|
801 |
break; |
|
802 |
case QNetworkAccessManager::PutOperation: |
|
803 |
request.setHTTPMethod("PUT"); |
|
804 |
break; |
|
805 |
case QNetworkAccessManager::PostOperation: |
|
806 |
request.setHTTPMethod("POST"); |
|
807 |
break; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
808 |
#if QT_VERSION >= 0x040600 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
809 |
case QNetworkAccessManager::DeleteOperation: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
810 |
request.setHTTPMethod("DELETE"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
811 |
break; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
812 |
#endif |
0 | 813 |
case QNetworkAccessManager::UnknownOperation: |
814 |
// eh? |
|
815 |
break; |
|
816 |
} |
|
817 |
||
818 |
QList<QByteArray> httpHeaders = req.rawHeaderList(); |
|
819 |
for (int i = 0; i < httpHeaders.size(); ++i) { |
|
820 |
const QByteArray &headerName = httpHeaders.at(i); |
|
821 |
request.addHTTPHeaderField(QString::fromLatin1(headerName), QString::fromLatin1(req.rawHeader(headerName))); |
|
822 |
} |
|
823 |
||
824 |
if (!body.isEmpty()) |
|
825 |
request.setHTTPBody(WebCore::FormData::create(body.constData(), body.size())); |
|
826 |
||
827 |
d->frame->loader()->load(request, false); |
|
828 |
||
829 |
if (d->parentFrame()) |
|
830 |
d->page->d->insideOpenCall = false; |
|
831 |
} |
|
832 |
#endif |
|
833 |
||
834 |
/*! |
|
835 |
Sets the content of this frame to \a html. \a baseUrl is optional and used to resolve relative |
|
836 |
URLs in the document, such as referenced images or stylesheets. |
|
837 |
||
838 |
The \a html is loaded immediately; external objects are loaded asynchronously. |
|
839 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
840 |
If a script in the \a html runs longer than the default script timeout (currently 10 seconds), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
841 |
for example due to being blocked by a modal JavaScript alert dialog, this method will return |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
842 |
as soon as possible after the timeout and any subsequent \a html will be loaded asynchronously. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
843 |
|
0 | 844 |
When using this method WebKit assumes that external resources such as JavaScript programs or style |
845 |
sheets are encoded in UTF-8 unless otherwise specified. For example, the encoding of an external |
|
846 |
script can be specified through the charset attribute of the HTML script tag. It is also possible |
|
847 |
for the encoding to be specified by web server. |
|
848 |
||
849 |
\note This method will not affect session or global history for the frame. |
|
850 |
||
851 |
\sa toHtml(), setContent() |
|
852 |
*/ |
|
853 |
void QWebFrame::setHtml(const QString &html, const QUrl &baseUrl) |
|
854 |
{ |
|
855 |
KURL kurl(baseUrl); |
|
856 |
WebCore::ResourceRequest request(kurl); |
|
857 |
const QByteArray utf8 = html.toUtf8(); |
|
858 |
WTF::RefPtr<WebCore::SharedBuffer> data = WebCore::SharedBuffer::create(utf8.constData(), utf8.length()); |
|
859 |
WebCore::SubstituteData substituteData(data, WebCore::String("text/html"), WebCore::String("utf-8"), KURL()); |
|
860 |
d->frame->loader()->load(request, substituteData, false); |
|
861 |
} |
|
862 |
||
863 |
/*! |
|
864 |
Sets the content of this frame to the specified content \a data. If the \a mimeType argument |
|
865 |
is empty it is currently assumed that the content is HTML but in future versions we may introduce |
|
866 |
auto-detection. |
|
867 |
||
868 |
External objects referenced in the content are located relative to \a baseUrl. |
|
869 |
||
870 |
The \a data is loaded immediately; external objects are loaded asynchronously. |
|
871 |
||
872 |
\note This method will not affect session or global history for the frame. |
|
873 |
||
874 |
\sa toHtml(), setHtml() |
|
875 |
*/ |
|
876 |
void QWebFrame::setContent(const QByteArray &data, const QString &mimeType, const QUrl &baseUrl) |
|
877 |
{ |
|
878 |
KURL kurl(baseUrl); |
|
879 |
WebCore::ResourceRequest request(kurl); |
|
880 |
WTF::RefPtr<WebCore::SharedBuffer> buffer = WebCore::SharedBuffer::create(data.constData(), data.length()); |
|
881 |
QString actualMimeType = mimeType; |
|
882 |
if (actualMimeType.isEmpty()) |
|
883 |
actualMimeType = QLatin1String("text/html"); |
|
884 |
WebCore::SubstituteData substituteData(buffer, WebCore::String(actualMimeType), WebCore::String(), KURL()); |
|
885 |
d->frame->loader()->load(request, substituteData, false); |
|
886 |
} |
|
887 |
||
888 |
/*! |
|
889 |
Returns the parent frame of this frame, or 0 if the frame is the web pages |
|
890 |
main frame. |
|
891 |
||
892 |
This is equivalent to qobject_cast<QWebFrame*>(frame->parent()). |
|
893 |
||
894 |
\sa childFrames() |
|
895 |
*/ |
|
896 |
QWebFrame *QWebFrame::parentFrame() const |
|
897 |
{ |
|
898 |
return d->parentFrame(); |
|
899 |
} |
|
900 |
||
901 |
/*! |
|
902 |
Returns a list of all frames that are direct children of this frame. |
|
903 |
||
904 |
\sa parentFrame() |
|
905 |
*/ |
|
906 |
QList<QWebFrame*> QWebFrame::childFrames() const |
|
907 |
{ |
|
908 |
QList<QWebFrame*> rc; |
|
909 |
if (d->frame) { |
|
910 |
FrameTree *tree = d->frame->tree(); |
|
911 |
for (Frame *child = tree->firstChild(); child; child = child->tree()->nextSibling()) { |
|
912 |
FrameLoader *loader = child->loader(); |
|
913 |
FrameLoaderClientQt *client = static_cast<FrameLoaderClientQt*>(loader->client()); |
|
914 |
if (client) |
|
915 |
rc.append(client->webFrame()); |
|
916 |
} |
|
917 |
||
918 |
} |
|
919 |
return rc; |
|
920 |
} |
|
921 |
||
922 |
/*! |
|
923 |
Returns the scrollbar policy for the scrollbar defined by \a orientation. |
|
924 |
*/ |
|
925 |
Qt::ScrollBarPolicy QWebFrame::scrollBarPolicy(Qt::Orientation orientation) const |
|
926 |
{ |
|
927 |
if (orientation == Qt::Horizontal) |
|
928 |
return d->horizontalScrollBarPolicy; |
|
929 |
return d->verticalScrollBarPolicy; |
|
930 |
} |
|
931 |
||
932 |
/*! |
|
933 |
Sets the scrollbar policy for the scrollbar defined by \a orientation to \a policy. |
|
934 |
*/ |
|
935 |
void QWebFrame::setScrollBarPolicy(Qt::Orientation orientation, Qt::ScrollBarPolicy policy) |
|
936 |
{ |
|
937 |
Q_ASSERT((int)ScrollbarAuto == (int)Qt::ScrollBarAsNeeded); |
|
938 |
Q_ASSERT((int)ScrollbarAlwaysOff == (int)Qt::ScrollBarAlwaysOff); |
|
939 |
Q_ASSERT((int)ScrollbarAlwaysOn == (int)Qt::ScrollBarAlwaysOn); |
|
940 |
||
941 |
if (orientation == Qt::Horizontal) { |
|
942 |
d->horizontalScrollBarPolicy = policy; |
|
943 |
if (d->frame->view()) { |
|
944 |
d->frame->view()->setHorizontalScrollbarMode((ScrollbarMode)policy); |
|
945 |
} |
|
946 |
} else { |
|
947 |
d->verticalScrollBarPolicy = policy; |
|
948 |
if (d->frame->view()) { |
|
949 |
d->frame->view()->setVerticalScrollbarMode((ScrollbarMode)policy); |
|
950 |
} |
|
951 |
} |
|
952 |
} |
|
953 |
||
954 |
/*! |
|
955 |
Sets the current \a value for the scrollbar with orientation \a orientation. |
|
956 |
||
957 |
The scrollbar forces the \a value to be within the legal range: minimum <= value <= maximum. |
|
958 |
||
959 |
Changing the value also updates the thumb position. |
|
960 |
||
961 |
\sa scrollBarMinimum(), scrollBarMaximum() |
|
962 |
*/ |
|
963 |
void QWebFrame::setScrollBarValue(Qt::Orientation orientation, int value) |
|
964 |
{ |
|
965 |
Scrollbar *sb; |
|
966 |
sb = (orientation == Qt::Horizontal) ? d->horizontalScrollBar() : d->verticalScrollBar(); |
|
967 |
if (sb) { |
|
968 |
if (value < 0) |
|
969 |
value = 0; |
|
970 |
else if (value > scrollBarMaximum(orientation)) |
|
971 |
value = scrollBarMaximum(orientation); |
|
972 |
sb->setValue(value); |
|
973 |
} |
|
974 |
} |
|
975 |
||
976 |
/*! |
|
977 |
Returns the current value for the scrollbar with orientation \a orientation, or 0 |
|
978 |
if no scrollbar is found for \a orientation. |
|
979 |
||
980 |
\sa scrollBarMinimum(), scrollBarMaximum() |
|
981 |
*/ |
|
982 |
int QWebFrame::scrollBarValue(Qt::Orientation orientation) const |
|
983 |
{ |
|
984 |
Scrollbar *sb; |
|
985 |
sb = (orientation == Qt::Horizontal) ? d->horizontalScrollBar() : d->verticalScrollBar(); |
|
986 |
if (sb) |
|
987 |
return sb->value(); |
|
988 |
return 0; |
|
989 |
} |
|
990 |
||
991 |
/*! |
|
992 |
Returns the maximum value for the scrollbar with orientation \a orientation, or 0 |
|
993 |
if no scrollbar is found for \a orientation. |
|
994 |
||
995 |
\sa scrollBarMinimum() |
|
996 |
*/ |
|
997 |
int QWebFrame::scrollBarMaximum(Qt::Orientation orientation) const |
|
998 |
{ |
|
999 |
Scrollbar *sb; |
|
1000 |
sb = (orientation == Qt::Horizontal) ? d->horizontalScrollBar() : d->verticalScrollBar(); |
|
1001 |
if (sb) |
|
1002 |
return sb->maximum(); |
|
1003 |
return 0; |
|
1004 |
} |
|
1005 |
||
1006 |
/*! |
|
1007 |
Returns the minimum value for the scrollbar with orientation \a orientation. |
|
1008 |
||
1009 |
The minimum value is always 0. |
|
1010 |
||
1011 |
\sa scrollBarMaximum() |
|
1012 |
*/ |
|
1013 |
int QWebFrame::scrollBarMinimum(Qt::Orientation orientation) const |
|
1014 |
{ |
|
1015 |
Q_UNUSED(orientation) |
|
1016 |
return 0; |
|
1017 |
} |
|
1018 |
||
1019 |
/*! |
|
1020 |
\since 4.6 |
|
1021 |
Returns the geometry for the scrollbar with orientation \a orientation. |
|
1022 |
||
1023 |
If the scrollbar does not exist an empty rect is returned. |
|
1024 |
*/ |
|
1025 |
QRect QWebFrame::scrollBarGeometry(Qt::Orientation orientation) const |
|
1026 |
{ |
|
1027 |
Scrollbar *sb; |
|
1028 |
sb = (orientation == Qt::Horizontal) ? d->horizontalScrollBar() : d->verticalScrollBar(); |
|
1029 |
if (sb) |
|
1030 |
return sb->frameRect(); |
|
1031 |
return QRect(); |
|
1032 |
} |
|
1033 |
||
1034 |
/*! |
|
1035 |
\since 4.5 |
|
1036 |
Scrolls the frame \a dx pixels to the right and \a dy pixels downward. Both |
|
1037 |
\a dx and \a dy may be negative. |
|
1038 |
||
1039 |
\sa QWebFrame::scrollPosition |
|
1040 |
*/ |
|
1041 |
||
1042 |
void QWebFrame::scroll(int dx, int dy) |
|
1043 |
{ |
|
1044 |
if (!d->frame->view()) |
|
1045 |
return; |
|
1046 |
||
1047 |
d->frame->view()->scrollBy(IntSize(dx, dy)); |
|
1048 |
} |
|
1049 |
||
1050 |
/*! |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1051 |
\internal |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1052 |
Scrolls nested frames starting at this frame, \a dx pixels to the right |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1053 |
and \a dy pixels downward. Both \a dx and \a dy may be negative. First attempts |
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1054 |
to scroll elements with CSS overflow at position pos, followed by this frame. If this |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1055 |
frame doesn't scroll, attempts to scroll the parent |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1056 |
*/ |
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1057 |
void QWEBKIT_EXPORT qtwebkit_webframe_scrollRecursively(QWebFrame* qFrame, int dx, int dy, const QPoint& pos) |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1058 |
{ |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1059 |
Frame* frame = QWebFramePrivate::core(qFrame); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1060 |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1061 |
if (!frame || !frame->view()) |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1062 |
return; |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1063 |
|
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1064 |
if (!webframe_scrollOverflow(frame, dx, dy, pos)) { |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1065 |
do { |
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1066 |
bool scrolledHorizontal = false; |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1067 |
bool scrolledVertical = false; |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1068 |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1069 |
IntSize scrollOffset = frame->view()->scrollOffset(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1070 |
IntPoint maxScrollOffset = frame->view()->maximumScrollPosition(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1071 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1072 |
if (dx > 0) // scroll right |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1073 |
scrolledHorizontal = scrollOffset.width() < maxScrollOffset.x(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1074 |
else if (dx < 0) // scroll left |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1075 |
scrolledHorizontal = scrollOffset.width() > 0; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1076 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1077 |
if (dy > 0) // scroll down |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1078 |
scrolledVertical = scrollOffset.height() < maxScrollOffset.y(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1079 |
else if (dy < 0) //scroll up |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1080 |
scrolledVertical = scrollOffset.height() > 0; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1081 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1082 |
if (scrolledHorizontal || scrolledVertical) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1083 |
frame->view()->scrollBy(IntSize(dx, dy)); |
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1084 |
return; |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1085 |
} |
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1086 |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1087 |
frame = frame->tree()->parent(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1088 |
} while (frame && frame->view()); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1089 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1090 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1091 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1092 |
/*! |
0 | 1093 |
\property QWebFrame::scrollPosition |
1094 |
\since 4.5 |
|
1095 |
\brief the position the frame is currently scrolled to. |
|
1096 |
*/ |
|
1097 |
||
1098 |
QPoint QWebFrame::scrollPosition() const |
|
1099 |
{ |
|
1100 |
if (!d->frame->view()) |
|
1101 |
return QPoint(0, 0); |
|
1102 |
||
1103 |
IntSize ofs = d->frame->view()->scrollOffset(); |
|
1104 |
return QPoint(ofs.width(), ofs.height()); |
|
1105 |
} |
|
1106 |
||
1107 |
void QWebFrame::setScrollPosition(const QPoint &pos) |
|
1108 |
{ |
|
1109 |
QPoint current = scrollPosition(); |
|
1110 |
int dx = pos.x() - current.x(); |
|
1111 |
int dy = pos.y() - current.y(); |
|
1112 |
scroll(dx, dy); |
|
1113 |
} |
|
1114 |
||
1115 |
/*! |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1116 |
\since 4.6 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1117 |
Render the \a layer of the frame using \a painter clipping to \a clip. |
0 | 1118 |
|
1119 |
\sa print() |
|
1120 |
*/ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1121 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1122 |
void QWebFrame::render(QPainter* painter, RenderLayer layer, const QRegion& clip) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1123 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1124 |
if (!clip.isEmpty()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1125 |
d->renderPrivate(painter, layer, clip); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1126 |
else if (d->frame->view()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1127 |
d->renderPrivate(painter, layer, QRegion(d->frame->view()->frameRect())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1128 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1129 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1130 |
/*! |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1131 |
Render the frame into \a painter clipping to \a clip. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1132 |
*/ |
0 | 1133 |
void QWebFrame::render(QPainter *painter, const QRegion &clip) |
1134 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1135 |
d->renderPrivate(painter, AllLayers, clip); |
0 | 1136 |
} |
1137 |
||
1138 |
/*! |
|
1139 |
Render the frame into \a painter. |
|
1140 |
*/ |
|
1141 |
void QWebFrame::render(QPainter *painter) |
|
1142 |
{ |
|
1143 |
if (!d->frame->view()) |
|
1144 |
return; |
|
1145 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1146 |
d->renderPrivate(painter, AllLayers, QRegion(d->frame->view()->frameRect())); |
0 | 1147 |
} |
1148 |
||
1149 |
/*! |
|
1150 |
\property QWebFrame::textSizeMultiplier |
|
1151 |
\brief the scaling factor for all text in the frame |
|
1152 |
\obsolete |
|
1153 |
||
1154 |
Use setZoomFactor instead, in combination with the ZoomTextOnly attribute in |
|
1155 |
QWebSettings. |
|
1156 |
||
1157 |
\note Setting this property also enables the ZoomTextOnly attribute in |
|
1158 |
QWebSettings. |
|
1159 |
*/ |
|
1160 |
||
1161 |
/*! |
|
1162 |
Sets the value of the multiplier used to scale the text in a Web frame to |
|
1163 |
the \a factor specified. |
|
1164 |
*/ |
|
1165 |
void QWebFrame::setTextSizeMultiplier(qreal factor) |
|
1166 |
{ |
|
1167 |
d->frame->setZoomFactor(factor, /*isTextOnly*/true); |
|
1168 |
} |
|
1169 |
||
1170 |
/*! |
|
1171 |
Returns the value of the multiplier used to scale the text in a Web frame. |
|
1172 |
*/ |
|
1173 |
qreal QWebFrame::textSizeMultiplier() const |
|
1174 |
{ |
|
1175 |
return d->frame->zoomFactor(); |
|
1176 |
} |
|
1177 |
||
1178 |
/*! |
|
1179 |
\property QWebFrame::zoomFactor |
|
1180 |
\since 4.5 |
|
1181 |
\brief the zoom factor for the frame |
|
1182 |
*/ |
|
1183 |
||
1184 |
void QWebFrame::setZoomFactor(qreal factor) |
|
1185 |
{ |
|
1186 |
d->frame->setZoomFactor(factor, d->frame->isZoomFactorTextOnly()); |
|
1187 |
} |
|
1188 |
||
1189 |
qreal QWebFrame::zoomFactor() const |
|
1190 |
{ |
|
1191 |
return d->frame->zoomFactor(); |
|
1192 |
} |
|
1193 |
||
1194 |
/*! |
|
1195 |
\property QWebFrame::focus |
|
1196 |
\since 4.6 |
|
1197 |
||
1198 |
Returns true if this frame has keyboard input focus; otherwise, returns false. |
|
1199 |
*/ |
|
1200 |
bool QWebFrame::hasFocus() const |
|
1201 |
{ |
|
1202 |
WebCore::Frame* ff = d->frame->page()->focusController()->focusedFrame(); |
|
1203 |
return ff && QWebFramePrivate::kit(ff) == this; |
|
1204 |
} |
|
1205 |
||
1206 |
/*! |
|
1207 |
\since 4.6 |
|
1208 |
||
1209 |
Gives keyboard input focus to this frame. |
|
1210 |
*/ |
|
1211 |
void QWebFrame::setFocus() |
|
1212 |
{ |
|
1213 |
QWebFramePrivate::core(this)->page()->focusController()->setFocusedFrame(QWebFramePrivate::core(this)); |
|
1214 |
} |
|
1215 |
||
1216 |
/*! |
|
1217 |
Returns the position of the frame relative to it's parent frame. |
|
1218 |
*/ |
|
1219 |
QPoint QWebFrame::pos() const |
|
1220 |
{ |
|
1221 |
if (!d->frame->view()) |
|
1222 |
return QPoint(); |
|
1223 |
||
1224 |
return d->frame->view()->frameRect().topLeft(); |
|
1225 |
} |
|
1226 |
||
1227 |
/*! |
|
1228 |
Return the geometry of the frame relative to it's parent frame. |
|
1229 |
*/ |
|
1230 |
QRect QWebFrame::geometry() const |
|
1231 |
{ |
|
1232 |
if (!d->frame->view()) |
|
1233 |
return QRect(); |
|
1234 |
return d->frame->view()->frameRect(); |
|
1235 |
} |
|
1236 |
||
1237 |
/*! |
|
1238 |
\property QWebFrame::contentsSize |
|
1239 |
\brief the size of the contents in this frame |
|
1240 |
||
1241 |
\sa contentsSizeChanged() |
|
1242 |
*/ |
|
1243 |
QSize QWebFrame::contentsSize() const |
|
1244 |
{ |
|
1245 |
FrameView *view = d->frame->view(); |
|
1246 |
if (!view) |
|
1247 |
return QSize(); |
|
1248 |
return QSize(view->contentsWidth(), view->contentsHeight()); |
|
1249 |
} |
|
1250 |
||
1251 |
/*! |
|
1252 |
\since 4.6 |
|
1253 |
||
1254 |
Returns the document element of this frame. |
|
1255 |
||
1256 |
The document element provides access to the entire structured |
|
1257 |
content of the frame. |
|
1258 |
*/ |
|
1259 |
QWebElement QWebFrame::documentElement() const |
|
1260 |
{ |
|
1261 |
WebCore::Document *doc = d->frame->document(); |
|
1262 |
if (!doc) |
|
1263 |
return QWebElement(); |
|
1264 |
return QWebElement(doc->documentElement()); |
|
1265 |
} |
|
1266 |
||
1267 |
/*! |
|
1268 |
\since 4.6 |
|
1269 |
Returns a new list of elements matching the given CSS selector \a selectorQuery. |
|
1270 |
If there are no matching elements, an empty list is returned. |
|
1271 |
||
1272 |
\l{http://www.w3.org/TR/REC-CSS2/selector.html#q1}{Standard CSS2 selector} syntax is |
|
1273 |
used for the query. |
|
1274 |
||
1275 |
\sa QWebElement::findAll() |
|
1276 |
*/ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1277 |
QWebElementCollection QWebFrame::findAllElements(const QString &selectorQuery) const |
0 | 1278 |
{ |
1279 |
return documentElement().findAll(selectorQuery); |
|
1280 |
} |
|
1281 |
||
1282 |
/*! |
|
1283 |
\since 4.6 |
|
1284 |
Returns the first element in the frame's document that matches the |
|
1285 |
given CSS selector \a selectorQuery. If there is no matching element, a |
|
1286 |
null element is returned. |
|
1287 |
||
1288 |
\l{http://www.w3.org/TR/REC-CSS2/selector.html#q1}{Standard CSS2 selector} syntax is |
|
1289 |
used for the query. |
|
1290 |
||
1291 |
\sa QWebElement::findFirst() |
|
1292 |
*/ |
|
1293 |
QWebElement QWebFrame::findFirstElement(const QString &selectorQuery) const |
|
1294 |
{ |
|
1295 |
return documentElement().findFirst(selectorQuery); |
|
1296 |
} |
|
1297 |
||
1298 |
/*! |
|
1299 |
Performs a hit test on the frame contents at the given position \a pos and returns the hit test result. |
|
1300 |
*/ |
|
1301 |
QWebHitTestResult QWebFrame::hitTestContent(const QPoint &pos) const |
|
1302 |
{ |
|
1303 |
if (!d->frame->view() || !d->frame->contentRenderer()) |
|
1304 |
return QWebHitTestResult(); |
|
1305 |
||
1306 |
HitTestResult result = d->frame->eventHandler()->hitTestResultAtPoint(d->frame->view()->windowToContents(pos), /*allowShadowContent*/ false, /*ignoreClipping*/ true); |
|
1307 |
||
1308 |
if (result.scrollbar()) |
|
1309 |
return QWebHitTestResult(); |
|
1310 |
||
1311 |
return QWebHitTestResult(new QWebHitTestResultPrivate(result)); |
|
1312 |
} |
|
1313 |
||
1314 |
/*! \reimp |
|
1315 |
*/ |
|
1316 |
bool QWebFrame::event(QEvent *e) |
|
1317 |
{ |
|
1318 |
return QObject::event(e); |
|
1319 |
} |
|
1320 |
||
1321 |
#ifndef QT_NO_PRINTER |
|
1322 |
/*! |
|
1323 |
Prints the frame to the given \a printer. |
|
1324 |
||
1325 |
\sa render() |
|
1326 |
*/ |
|
1327 |
void QWebFrame::print(QPrinter *printer) const |
|
1328 |
{ |
|
1329 |
QPainter painter; |
|
1330 |
if (!painter.begin(printer)) |
|
1331 |
return; |
|
1332 |
||
1333 |
const qreal zoomFactorX = printer->logicalDpiX() / qt_defaultDpi(); |
|
1334 |
const qreal zoomFactorY = printer->logicalDpiY() / qt_defaultDpi(); |
|
1335 |
||
1336 |
PrintContext printContext(d->frame); |
|
1337 |
float pageHeight = 0; |
|
1338 |
||
1339 |
QRect qprinterRect = printer->pageRect(); |
|
1340 |
||
1341 |
IntRect pageRect(0, 0, |
|
1342 |
int(qprinterRect.width() / zoomFactorX), |
|
1343 |
int(qprinterRect.height() / zoomFactorY)); |
|
1344 |
||
1345 |
printContext.begin(pageRect.width()); |
|
1346 |
||
1347 |
printContext.computePageRects(pageRect, /* headerHeight */ 0, /* footerHeight */ 0, /* userScaleFactor */ 1.0, pageHeight); |
|
1348 |
||
1349 |
int docCopies; |
|
1350 |
int pageCopies; |
|
1351 |
if (printer->collateCopies()) { |
|
1352 |
docCopies = 1; |
|
1353 |
pageCopies = printer->numCopies(); |
|
1354 |
} else { |
|
1355 |
docCopies = printer->numCopies(); |
|
1356 |
pageCopies = 1; |
|
1357 |
} |
|
1358 |
||
1359 |
int fromPage = printer->fromPage(); |
|
1360 |
int toPage = printer->toPage(); |
|
1361 |
bool ascending = true; |
|
1362 |
||
1363 |
if (fromPage == 0 && toPage == 0) { |
|
1364 |
fromPage = 1; |
|
1365 |
toPage = printContext.pageCount(); |
|
1366 |
} |
|
1367 |
// paranoia check |
|
1368 |
fromPage = qMax(1, fromPage); |
|
1369 |
toPage = qMin(printContext.pageCount(), toPage); |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1370 |
if (toPage < fromPage) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1371 |
// if the user entered a page range outside the actual number |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1372 |
// of printable pages, just return |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1373 |
return; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1374 |
} |
0 | 1375 |
|
1376 |
if (printer->pageOrder() == QPrinter::LastPageFirst) { |
|
1377 |
int tmp = fromPage; |
|
1378 |
fromPage = toPage; |
|
1379 |
toPage = tmp; |
|
1380 |
ascending = false; |
|
1381 |
} |
|
1382 |
||
1383 |
painter.scale(zoomFactorX, zoomFactorY); |
|
1384 |
GraphicsContext ctx(&painter); |
|
1385 |
||
1386 |
for (int i = 0; i < docCopies; ++i) { |
|
1387 |
int page = fromPage; |
|
1388 |
while (true) { |
|
1389 |
for (int j = 0; j < pageCopies; ++j) { |
|
1390 |
if (printer->printerState() == QPrinter::Aborted |
|
1391 |
|| printer->printerState() == QPrinter::Error) { |
|
1392 |
printContext.end(); |
|
1393 |
return; |
|
1394 |
} |
|
1395 |
printContext.spoolPage(ctx, page - 1, pageRect.width()); |
|
1396 |
if (j < pageCopies - 1) |
|
1397 |
printer->newPage(); |
|
1398 |
} |
|
1399 |
||
1400 |
if (page == toPage) |
|
1401 |
break; |
|
1402 |
||
1403 |
if (ascending) |
|
1404 |
++page; |
|
1405 |
else |
|
1406 |
--page; |
|
1407 |
||
1408 |
printer->newPage(); |
|
1409 |
} |
|
1410 |
||
1411 |
if ( i < docCopies - 1) |
|
1412 |
printer->newPage(); |
|
1413 |
} |
|
1414 |
||
1415 |
printContext.end(); |
|
1416 |
} |
|
1417 |
#endif // QT_NO_PRINTER |
|
1418 |
||
1419 |
/*! |
|
1420 |
Evaluates the JavaScript defined by \a scriptSource using this frame as context |
|
1421 |
and returns the result of the last executed statement. |
|
1422 |
||
1423 |
\sa addToJavaScriptWindowObject(), javaScriptWindowObjectCleared() |
|
1424 |
*/ |
|
1425 |
QVariant QWebFrame::evaluateJavaScript(const QString& scriptSource) |
|
1426 |
{ |
|
1427 |
ScriptController *proxy = d->frame->script(); |
|
1428 |
QVariant rc; |
|
1429 |
if (proxy) { |
|
1430 |
JSC::JSValue v = d->frame->script()->executeScript(ScriptSourceCode(scriptSource)).jsValue(); |
|
1431 |
int distance = 0; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1432 |
rc = JSC::Bindings::convertValueToQVariant(proxy->globalObject(mainThreadNormalWorld())->globalExec(), v, QMetaType::Void, &distance); |
0 | 1433 |
} |
1434 |
return rc; |
|
1435 |
} |
|
1436 |
||
1437 |
/*! |
|
1438 |
\since 4.5 |
|
1439 |
||
1440 |
Returns the frame's security origin. |
|
1441 |
*/ |
|
1442 |
QWebSecurityOrigin QWebFrame::securityOrigin() const |
|
1443 |
{ |
|
1444 |
QWebFrame* that = const_cast<QWebFrame*>(this); |
|
1445 |
QWebSecurityOriginPrivate* priv = new QWebSecurityOriginPrivate(QWebFramePrivate::core(that)->document()->securityOrigin()); |
|
1446 |
return QWebSecurityOrigin(priv); |
|
1447 |
} |
|
1448 |
||
1449 |
WebCore::Frame* QWebFramePrivate::core(QWebFrame* webFrame) |
|
1450 |
{ |
|
1451 |
return webFrame->d->frame; |
|
1452 |
} |
|
1453 |
||
1454 |
QWebFrame* QWebFramePrivate::kit(WebCore::Frame* coreFrame) |
|
1455 |
{ |
|
1456 |
return static_cast<FrameLoaderClientQt*>(coreFrame->loader()->client())->webFrame(); |
|
1457 |
} |
|
1458 |
||
1459 |
||
1460 |
/*! |
|
1461 |
\fn void QWebFrame::javaScriptWindowObjectCleared() |
|
1462 |
||
1463 |
This signal is emitted whenever the global window object of the JavaScript |
|
1464 |
environment is cleared, e.g., before starting a new load. |
|
1465 |
||
1466 |
If you intend to add QObjects to a QWebFrame using |
|
1467 |
addToJavaScriptWindowObject(), you should add them in a slot connected |
|
1468 |
to this signal. This ensures that your objects remain accessible when |
|
1469 |
loading new URLs. |
|
1470 |
*/ |
|
1471 |
||
1472 |
/*! |
|
1473 |
\fn void QWebFrame::provisionalLoad() |
|
1474 |
\internal |
|
1475 |
*/ |
|
1476 |
||
1477 |
/*! |
|
1478 |
\fn void QWebFrame::titleChanged(const QString &title) |
|
1479 |
||
1480 |
This signal is emitted whenever the title of the frame changes. |
|
1481 |
The \a title string specifies the new title. |
|
1482 |
||
1483 |
\sa title() |
|
1484 |
*/ |
|
1485 |
||
1486 |
/*! |
|
1487 |
\fn void QWebFrame::urlChanged(const QUrl &url) |
|
1488 |
||
1489 |
This signal is emitted with the URL of the frame when the frame's title is |
|
1490 |
received. The new URL is specified by \a url. |
|
1491 |
||
1492 |
\sa url() |
|
1493 |
*/ |
|
1494 |
||
1495 |
/*! |
|
1496 |
\fn void QWebFrame::initialLayoutCompleted() |
|
1497 |
||
1498 |
This signal is emitted when the frame is laid out the first time. |
|
1499 |
This is the first time you will see contents displayed on the frame. |
|
1500 |
||
1501 |
\note A frame can be laid out multiple times. |
|
1502 |
*/ |
|
1503 |
||
1504 |
/*! |
|
1505 |
\fn void QWebFrame::iconChanged() |
|
1506 |
||
1507 |
This signal is emitted when the icon ("favicon") associated with the frame |
|
1508 |
has been loaded. |
|
1509 |
||
1510 |
\sa icon() |
|
1511 |
*/ |
|
1512 |
||
1513 |
/*! |
|
1514 |
\fn void QWebFrame::contentsSizeChanged(const QSize &size) |
|
1515 |
\since 4.6 |
|
1516 |
||
1517 |
This signal is emitted when the frame's contents size changes |
|
1518 |
to \a size. |
|
1519 |
||
1520 |
\sa contentsSize() |
|
1521 |
*/ |
|
1522 |
||
1523 |
/*! |
|
1524 |
\fn void QWebFrame::loadStarted() |
|
1525 |
\since 4.6 |
|
1526 |
||
1527 |
This signal is emitted when a new load of this frame is started. |
|
1528 |
||
1529 |
\sa loadFinished() |
|
1530 |
*/ |
|
1531 |
||
1532 |
/*! |
|
1533 |
\fn void QWebFrame::loadFinished(bool ok) |
|
1534 |
\since 4.6 |
|
1535 |
||
1536 |
This signal is emitted when a load of this frame is finished. |
|
1537 |
\a ok will indicate whether the load was successful or any error occurred. |
|
1538 |
||
1539 |
\sa loadStarted() |
|
1540 |
*/ |
|
1541 |
||
1542 |
/*! |
|
1543 |
\class QWebHitTestResult |
|
1544 |
\since 4.4 |
|
1545 |
\brief The QWebHitTestResult class provides information about the web |
|
1546 |
page content after a hit test. |
|
1547 |
||
1548 |
\inmodule QtWebKit |
|
1549 |
||
1550 |
QWebHitTestResult is returned by QWebFrame::hitTestContent() to provide |
|
1551 |
information about the content of the web page at the specified position. |
|
1552 |
*/ |
|
1553 |
||
1554 |
/*! |
|
1555 |
\internal |
|
1556 |
*/ |
|
1557 |
QWebHitTestResult::QWebHitTestResult(QWebHitTestResultPrivate *priv) |
|
1558 |
: d(priv) |
|
1559 |
{ |
|
1560 |
} |
|
1561 |
||
1562 |
QWebHitTestResultPrivate::QWebHitTestResultPrivate(const WebCore::HitTestResult &hitTest) |
|
1563 |
: isContentEditable(false) |
|
1564 |
, isContentSelected(false) |
|
1565 |
, isScrollBar(false) |
|
1566 |
{ |
|
1567 |
if (!hitTest.innerNode()) |
|
1568 |
return; |
|
1569 |
pos = hitTest.point(); |
|
1570 |
WebCore::TextDirection dir; |
|
1571 |
title = hitTest.title(dir); |
|
1572 |
linkText = hitTest.textContent(); |
|
1573 |
linkUrl = hitTest.absoluteLinkURL(); |
|
1574 |
linkTitle = hitTest.titleDisplayString(); |
|
1575 |
alternateText = hitTest.altDisplayString(); |
|
1576 |
imageUrl = hitTest.absoluteImageURL(); |
|
1577 |
innerNode = hitTest.innerNode(); |
|
1578 |
innerNonSharedNode = hitTest.innerNonSharedNode(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1579 |
boundingRect = innerNonSharedNode ? innerNonSharedNode->renderer()->absoluteBoundingBoxRect(true) : IntRect(); |
0 | 1580 |
WebCore::Image *img = hitTest.image(); |
1581 |
if (img) { |
|
1582 |
QPixmap *pix = img->nativeImageForCurrentFrame(); |
|
1583 |
if (pix) |
|
1584 |
pixmap = *pix; |
|
1585 |
} |
|
1586 |
WebCore::Frame *wframe = hitTest.targetFrame(); |
|
1587 |
if (wframe) |
|
1588 |
linkTargetFrame = QWebFramePrivate::kit(wframe); |
|
1589 |
linkElement = QWebElement(hitTest.URLElement()); |
|
1590 |
||
1591 |
isContentEditable = hitTest.isContentEditable(); |
|
1592 |
isContentSelected = hitTest.isSelected(); |
|
1593 |
isScrollBar = hitTest.scrollbar(); |
|
1594 |
||
1595 |
if (innerNonSharedNode && innerNonSharedNode->document() |
|
1596 |
&& innerNonSharedNode->document()->frame()) |
|
1597 |
frame = QWebFramePrivate::kit(innerNonSharedNode->document()->frame()); |
|
1598 |
||
1599 |
enclosingBlock = QWebElement(WebCore::enclosingBlock(innerNode.get())); |
|
1600 |
} |
|
1601 |
||
1602 |
/*! |
|
1603 |
Constructs a null hit test result. |
|
1604 |
*/ |
|
1605 |
QWebHitTestResult::QWebHitTestResult() |
|
1606 |
: d(0) |
|
1607 |
{ |
|
1608 |
} |
|
1609 |
||
1610 |
/*! |
|
1611 |
Constructs a hit test result from \a other. |
|
1612 |
*/ |
|
1613 |
QWebHitTestResult::QWebHitTestResult(const QWebHitTestResult &other) |
|
1614 |
: d(0) |
|
1615 |
{ |
|
1616 |
if (other.d) |
|
1617 |
d = new QWebHitTestResultPrivate(*other.d); |
|
1618 |
} |
|
1619 |
||
1620 |
/*! |
|
1621 |
Assigns the \a other hit test result to this. |
|
1622 |
*/ |
|
1623 |
QWebHitTestResult &QWebHitTestResult::operator=(const QWebHitTestResult &other) |
|
1624 |
{ |
|
1625 |
if (this != &other) { |
|
1626 |
if (other.d) { |
|
1627 |
if (!d) |
|
1628 |
d = new QWebHitTestResultPrivate; |
|
1629 |
*d = *other.d; |
|
1630 |
} else { |
|
1631 |
delete d; |
|
1632 |
d = 0; |
|
1633 |
} |
|
1634 |
} |
|
1635 |
return *this; |
|
1636 |
} |
|
1637 |
||
1638 |
/*! |
|
1639 |
Destructor. |
|
1640 |
*/ |
|
1641 |
QWebHitTestResult::~QWebHitTestResult() |
|
1642 |
{ |
|
1643 |
delete d; |
|
1644 |
} |
|
1645 |
||
1646 |
/*! |
|
1647 |
Returns true if the hit test result is null; otherwise returns false. |
|
1648 |
*/ |
|
1649 |
bool QWebHitTestResult::isNull() const |
|
1650 |
{ |
|
1651 |
return !d; |
|
1652 |
} |
|
1653 |
||
1654 |
/*! |
|
1655 |
Returns the position where the hit test occured. |
|
1656 |
*/ |
|
1657 |
QPoint QWebHitTestResult::pos() const |
|
1658 |
{ |
|
1659 |
if (!d) |
|
1660 |
return QPoint(); |
|
1661 |
return d->pos; |
|
1662 |
} |
|
1663 |
||
1664 |
/*! |
|
1665 |
\since 4.5 |
|
1666 |
Returns the bounding rect of the element. |
|
1667 |
*/ |
|
1668 |
QRect QWebHitTestResult::boundingRect() const |
|
1669 |
{ |
|
1670 |
if (!d) |
|
1671 |
return QRect(); |
|
1672 |
return d->boundingRect; |
|
1673 |
} |
|
1674 |
||
1675 |
/*! |
|
1676 |
\since 4.6 |
|
1677 |
Returns the block element that encloses the element hit. |
|
1678 |
||
1679 |
A block element is an element that is rendered using the |
|
1680 |
CSS "block" style. This includes for example text |
|
1681 |
paragraphs. |
|
1682 |
*/ |
|
1683 |
QWebElement QWebHitTestResult::enclosingBlockElement() const |
|
1684 |
{ |
|
1685 |
if (!d) |
|
1686 |
return QWebElement(); |
|
1687 |
return d->enclosingBlock; |
|
1688 |
} |
|
1689 |
||
1690 |
/*! |
|
1691 |
Returns the title of the nearest enclosing HTML element. |
|
1692 |
*/ |
|
1693 |
QString QWebHitTestResult::title() const |
|
1694 |
{ |
|
1695 |
if (!d) |
|
1696 |
return QString(); |
|
1697 |
return d->title; |
|
1698 |
} |
|
1699 |
||
1700 |
/*! |
|
1701 |
Returns the text of the link. |
|
1702 |
*/ |
|
1703 |
QString QWebHitTestResult::linkText() const |
|
1704 |
{ |
|
1705 |
if (!d) |
|
1706 |
return QString(); |
|
1707 |
return d->linkText; |
|
1708 |
} |
|
1709 |
||
1710 |
/*! |
|
1711 |
Returns the url to which the link points to. |
|
1712 |
*/ |
|
1713 |
QUrl QWebHitTestResult::linkUrl() const |
|
1714 |
{ |
|
1715 |
if (!d) |
|
1716 |
return QUrl(); |
|
1717 |
return d->linkUrl; |
|
1718 |
} |
|
1719 |
||
1720 |
/*! |
|
1721 |
Returns the title of the link. |
|
1722 |
*/ |
|
1723 |
QUrl QWebHitTestResult::linkTitle() const |
|
1724 |
{ |
|
1725 |
if (!d) |
|
1726 |
return QUrl(); |
|
1727 |
return d->linkTitle; |
|
1728 |
} |
|
1729 |
||
1730 |
/*! |
|
1731 |
\since 4.6 |
|
1732 |
Returns the element that represents the link. |
|
1733 |
||
1734 |
\sa linkTargetFrame() |
|
1735 |
*/ |
|
1736 |
QWebElement QWebHitTestResult::linkElement() const |
|
1737 |
{ |
|
1738 |
if (!d) |
|
1739 |
return QWebElement(); |
|
1740 |
return d->linkElement; |
|
1741 |
} |
|
1742 |
||
1743 |
/*! |
|
1744 |
Returns the frame that will load the link if it is activated. |
|
1745 |
||
1746 |
\sa linkElement() |
|
1747 |
*/ |
|
1748 |
QWebFrame *QWebHitTestResult::linkTargetFrame() const |
|
1749 |
{ |
|
1750 |
if (!d) |
|
1751 |
return 0; |
|
1752 |
return d->linkTargetFrame; |
|
1753 |
} |
|
1754 |
||
1755 |
/*! |
|
1756 |
Returns the alternate text of the element. This corresponds to the HTML alt attribute. |
|
1757 |
*/ |
|
1758 |
QString QWebHitTestResult::alternateText() const |
|
1759 |
{ |
|
1760 |
if (!d) |
|
1761 |
return QString(); |
|
1762 |
return d->alternateText; |
|
1763 |
} |
|
1764 |
||
1765 |
/*! |
|
1766 |
Returns the url of the image. |
|
1767 |
*/ |
|
1768 |
QUrl QWebHitTestResult::imageUrl() const |
|
1769 |
{ |
|
1770 |
if (!d) |
|
1771 |
return QUrl(); |
|
1772 |
return d->imageUrl; |
|
1773 |
} |
|
1774 |
||
1775 |
/*! |
|
1776 |
Returns a QPixmap containing the image. A null pixmap is returned if the |
|
1777 |
element being tested is not an image. |
|
1778 |
*/ |
|
1779 |
QPixmap QWebHitTestResult::pixmap() const |
|
1780 |
{ |
|
1781 |
if (!d) |
|
1782 |
return QPixmap(); |
|
1783 |
return d->pixmap; |
|
1784 |
} |
|
1785 |
||
1786 |
/*! |
|
1787 |
Returns true if the content is editable by the user; otherwise returns false. |
|
1788 |
*/ |
|
1789 |
bool QWebHitTestResult::isContentEditable() const |
|
1790 |
{ |
|
1791 |
if (!d) |
|
1792 |
return false; |
|
1793 |
return d->isContentEditable; |
|
1794 |
} |
|
1795 |
||
1796 |
/*! |
|
1797 |
Returns true if the content tested is part of the selection; otherwise returns false. |
|
1798 |
*/ |
|
1799 |
bool QWebHitTestResult::isContentSelected() const |
|
1800 |
{ |
|
1801 |
if (!d) |
|
1802 |
return false; |
|
1803 |
return d->isContentSelected; |
|
1804 |
} |
|
1805 |
||
1806 |
/*! |
|
1807 |
\since 4.6 |
|
1808 |
Returns the underlying DOM element as QWebElement. |
|
1809 |
*/ |
|
1810 |
QWebElement QWebHitTestResult::element() const |
|
1811 |
{ |
|
1812 |
if (!d || !d->innerNonSharedNode || !d->innerNonSharedNode->isElementNode()) |
|
1813 |
return QWebElement(); |
|
1814 |
||
1815 |
return QWebElement(static_cast<WebCore::Element*>(d->innerNonSharedNode.get())); |
|
1816 |
} |
|
1817 |
||
1818 |
/*! |
|
1819 |
Returns the frame the hit test was executed in. |
|
1820 |
*/ |
|
1821 |
QWebFrame *QWebHitTestResult::frame() const |
|
1822 |
{ |
|
1823 |
if (!d) |
|
1824 |
return 0; |
|
1825 |
return d->frame; |
|
1826 |
} |