|
1 /* |
|
2 Copyright (C) 2007 Trolltech ASA |
|
3 Copyright (C) 2007 Staikos Computing Services Inc. |
|
4 Copyright (C) 2007 Apple Inc. |
|
5 |
|
6 This library is free software; you can redistribute it and/or |
|
7 modify it under the terms of the GNU Library General Public |
|
8 License as published by the Free Software Foundation; either |
|
9 version 2 of the License, or (at your option) any later version. |
|
10 |
|
11 This library is distributed in the hope that it will be useful, |
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 Library General Public License for more details. |
|
15 |
|
16 You should have received a copy of the GNU Library General Public License |
|
17 along with this library; see the file COPYING.LIB. If not, write to |
|
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
19 Boston, MA 02110-1301, USA. |
|
20 |
|
21 This class provides all functionality needed for loading images, style sheets and html |
|
22 pages from the web. It has a memory cache for these objects. |
|
23 */ |
|
24 |
|
25 #include "qwebpage.h" |
|
26 #include "qwebframe.h" |
|
27 #include "qwebpage_p.h" |
|
28 #include "qwebframe_p.h" |
|
29 #include "qwebnetworkinterface.h" |
|
30 #include "qwebpagehistory.h" |
|
31 #include "qwebpagehistory_p.h" |
|
32 #include "qwebsettings.h" |
|
33 |
|
34 #include "Frame.h" |
|
35 #include "ChromeClientQt.h" |
|
36 #include "ContextMenuClientQt.h" |
|
37 #include "DragClientQt.h" |
|
38 #include "DragController.h" |
|
39 #include "DragData.h" |
|
40 #include "EditorClientQt.h" |
|
41 #include "Settings.h" |
|
42 #include "Page.h" |
|
43 #include "FrameLoader.h" |
|
44 #include "KURL.h" |
|
45 #include "Image.h" |
|
46 #include "IconDatabase.h" |
|
47 #include "InspectorClientQt.h" |
|
48 #include "FocusController.h" |
|
49 #include "Editor.h" |
|
50 #include "PlatformScrollBar.h" |
|
51 #include "PlatformKeyboardEvent.h" |
|
52 #include "ProgressTracker.h" |
|
53 |
|
54 #include <QDebug> |
|
55 #include <QDragEnterEvent> |
|
56 #include <QDragLeaveEvent> |
|
57 #include <QDragMoveEvent> |
|
58 #include <QDropEvent> |
|
59 #include <QFileDialog> |
|
60 #include <QHttpRequestHeader> |
|
61 #include <QInputDialog> |
|
62 #include <QMessageBox> |
|
63 #include <QNetworkProxy> |
|
64 #include <QUndoStack> |
|
65 #include <QUrl> |
|
66 #include <QPainter> |
|
67 |
|
68 using namespace WebCore; |
|
69 |
|
70 QWebPagePrivate::QWebPagePrivate(QWebPage *qq) |
|
71 : q(qq), modified(false) |
|
72 { |
|
73 q->setMouseTracking(true); |
|
74 q->setFocusPolicy(Qt::ClickFocus); |
|
75 chromeClient = new ChromeClientQt(q); |
|
76 contextMenuClient = new ContextMenuClientQt(); |
|
77 editorClient = new EditorClientQt(q); |
|
78 page = new Page(chromeClient, contextMenuClient, editorClient, |
|
79 new DragClientQt(q), new InspectorClientQt()); |
|
80 |
|
81 undoStack = 0; |
|
82 mainFrame = 0; |
|
83 networkInterface = 0; |
|
84 insideOpenCall = false; |
|
85 } |
|
86 |
|
87 QWebPagePrivate::~QWebPagePrivate() |
|
88 { |
|
89 delete undoStack; |
|
90 delete page; |
|
91 } |
|
92 |
|
93 QWebPage::NavigationRequestResponse QWebPagePrivate::navigationRequested(QWebFrame *frame, const QWebNetworkRequest &request, QWebPage::NavigationType type) |
|
94 { |
|
95 if (insideOpenCall |
|
96 && frame == mainFrame) |
|
97 return QWebPage::AcceptNavigationRequest; |
|
98 return q->navigationRequested(frame, request, type); |
|
99 } |
|
100 |
|
101 void QWebPagePrivate::createMainFrame() |
|
102 { |
|
103 if (!mainFrame) { |
|
104 QWebFrameData frameData; |
|
105 frameData.ownerElement = 0; |
|
106 frameData.allowsScrolling = true; |
|
107 frameData.marginWidth = 0; |
|
108 frameData.marginHeight = 0; |
|
109 mainFrame = q->createFrame(0, &frameData); |
|
110 QObject::connect(mainFrame, SIGNAL(titleChanged(const QString&)), |
|
111 q, SIGNAL(titleChanged(const QString&))); |
|
112 QObject::connect(mainFrame, SIGNAL(hoveringOverLink(const QString&, const QString&)), |
|
113 q, SIGNAL(hoveringOverLink(const QString&, const QString&))); |
|
114 |
|
115 mainFrame->d->frameView->setFrameGeometry(q->geometry()); |
|
116 } |
|
117 } |
|
118 |
|
119 |
|
120 QWebPage::QWebPage(QWidget *parent) |
|
121 : QWidget(parent) |
|
122 , d(new QWebPagePrivate(this)) |
|
123 { |
|
124 setSettings(QWebSettings::global()); |
|
125 QPalette pal = palette(); |
|
126 pal.setBrush(QPalette::Background, Qt::white); |
|
127 |
|
128 setAttribute(Qt::WA_OpaquePaintEvent); |
|
129 |
|
130 setPalette(pal); |
|
131 setAcceptDrops(true); |
|
132 connect(this, SIGNAL(loadProgressChanged(int)), this, SLOT(onLoadProgressChanged(int))); |
|
133 } |
|
134 |
|
135 QWebPage::~QWebPage() |
|
136 { |
|
137 FrameLoader *loader = d->mainFrame->d->frame->loader(); |
|
138 if (loader) |
|
139 loader->detachFromParent(); |
|
140 delete d; |
|
141 } |
|
142 |
|
143 QWebFrame *QWebPage::createFrame(QWebFrame *parentFrame, QWebFrameData *frameData) |
|
144 { |
|
145 if (parentFrame) |
|
146 return new QWebFrame(parentFrame, frameData); |
|
147 QWebFrame *f = new QWebFrame(this, frameData); |
|
148 return f; |
|
149 } |
|
150 |
|
151 void QWebPage::open(const QUrl &url) |
|
152 { |
|
153 open(QWebNetworkRequest(url)); |
|
154 } |
|
155 |
|
156 void QWebPage::open(const QWebNetworkRequest &req) |
|
157 { |
|
158 d->insideOpenCall = true; |
|
159 |
|
160 QUrl url = req.url(); |
|
161 QHttpRequestHeader httpHeader = req.httpHeader(); |
|
162 QByteArray postData = req.postData(); |
|
163 |
|
164 WebCore::ResourceRequest request(KURL(url.toString())); |
|
165 |
|
166 QString method = httpHeader.method(); |
|
167 if (!method.isEmpty()) |
|
168 request.setHTTPMethod(method); |
|
169 |
|
170 QList<QPair<QString, QString> > values = httpHeader.values(); |
|
171 for (int i = 0; i < values.size(); ++i) { |
|
172 const QPair<QString, QString> &val = values.at(i); |
|
173 request.addHTTPHeaderField(val.first, val.second); |
|
174 } |
|
175 |
|
176 if (!postData.isEmpty()) { |
|
177 WTF::RefPtr<WebCore::FormData> formData = new WebCore::FormData(postData.constData(), postData.size()); |
|
178 request.setHTTPBody(formData); |
|
179 } |
|
180 |
|
181 mainFrame()->d->frame->loader()->load(request); |
|
182 d->insideOpenCall = false; |
|
183 } |
|
184 |
|
185 QUrl QWebPage::url() const |
|
186 { |
|
187 return QUrl((QString)mainFrame()->d->frame->loader()->url().url()); |
|
188 } |
|
189 |
|
190 QString QWebPage::title() const |
|
191 { |
|
192 return mainFrame()->title(); |
|
193 } |
|
194 |
|
195 QWebFrame *QWebPage::mainFrame() const |
|
196 { |
|
197 d->createMainFrame(); |
|
198 return d->mainFrame; |
|
199 } |
|
200 |
|
201 QSize QWebPage::sizeHint() const |
|
202 { |
|
203 return QSize(800, 600); |
|
204 } |
|
205 |
|
206 void QWebPage::stop() |
|
207 { |
|
208 FrameLoader *f = mainFrame()->d->frame->loader(); |
|
209 f->stopForUserCancel(); |
|
210 } |
|
211 |
|
212 QWebPageHistory QWebPage::history() const |
|
213 { |
|
214 WebCore::BackForwardList *lst = d->page->backForwardList(); |
|
215 QWebPageHistoryPrivate *priv = new QWebPageHistoryPrivate(lst); |
|
216 return QWebPageHistory(priv); |
|
217 } |
|
218 |
|
219 void QWebPage::goBack() |
|
220 { |
|
221 d->page->goBack(); |
|
222 } |
|
223 |
|
224 void QWebPage::goForward() |
|
225 { |
|
226 d->page->goForward(); |
|
227 } |
|
228 |
|
229 void QWebPage::goToHistoryItem(const QWebHistoryItem &item) |
|
230 { |
|
231 d->page->goToItem(item.d->item, FrameLoadTypeIndexedBackForward); |
|
232 } |
|
233 |
|
234 void QWebPage::javaScriptConsoleMessage(const QString& message, unsigned int lineNumber, const QString& sourceID) |
|
235 { |
|
236 } |
|
237 |
|
238 void QWebPage::javaScriptAlert(QWebFrame *frame, const QString& msg) |
|
239 { |
|
240 //FIXME frame pos... |
|
241 QMessageBox::information(this, title(), msg, QMessageBox::Ok); |
|
242 } |
|
243 |
|
244 bool QWebPage::javaScriptConfirm(QWebFrame *frame, const QString& msg) |
|
245 { |
|
246 //FIXME frame pos... |
|
247 return 0 == QMessageBox::information(this, title(), msg, QMessageBox::Yes, QMessageBox::No); |
|
248 } |
|
249 |
|
250 bool QWebPage::javaScriptPrompt(QWebFrame *frame, const QString& msg, const QString& defaultValue, QString* result) |
|
251 { |
|
252 //FIXME frame pos... |
|
253 bool ok = false; |
|
254 #ifndef QT_NO_INPUTDIALOG |
|
255 QString x = QInputDialog::getText(this, title(), msg, QLineEdit::Normal, defaultValue, &ok); |
|
256 if (ok && result) { |
|
257 *result = x; |
|
258 } |
|
259 #endif |
|
260 return ok; |
|
261 } |
|
262 |
|
263 QWebPage *QWebPage::createWindow() |
|
264 { |
|
265 return 0; |
|
266 } |
|
267 |
|
268 QWebPage *QWebPage::createModalDialog() |
|
269 { |
|
270 return 0; |
|
271 } |
|
272 |
|
273 QObject *QWebPage::createPlugin(const QString &classid, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues) |
|
274 { |
|
275 Q_UNUSED(classid) |
|
276 Q_UNUSED(url) |
|
277 Q_UNUSED(paramNames) |
|
278 Q_UNUSED(paramValues) |
|
279 return 0; |
|
280 } |
|
281 |
|
282 QWebPage::NavigationRequestResponse QWebPage::navigationRequested(QWebFrame *frame, const QWebNetworkRequest &request, QWebPage::NavigationType type) |
|
283 { |
|
284 Q_UNUSED(request) |
|
285 return AcceptNavigationRequest; |
|
286 } |
|
287 |
|
288 void QWebPage::setWindowGeometry(const QRect& geom) |
|
289 { |
|
290 Q_UNUSED(geom) |
|
291 } |
|
292 |
|
293 bool QWebPage::canCut() const |
|
294 { |
|
295 return d->page->focusController()->focusedOrMainFrame()->editor()->canCut(); |
|
296 } |
|
297 |
|
298 bool QWebPage::canCopy() const |
|
299 { |
|
300 return d->page->focusController()->focusedOrMainFrame()->editor()->canCopy(); |
|
301 } |
|
302 |
|
303 bool QWebPage::canPaste() const |
|
304 { |
|
305 return d->page->focusController()->focusedOrMainFrame()->editor()->canPaste(); |
|
306 } |
|
307 |
|
308 void QWebPage::cut() |
|
309 { |
|
310 d->page->focusController()->focusedOrMainFrame()->editor()->cut(); |
|
311 } |
|
312 |
|
313 void QWebPage::copy() |
|
314 { |
|
315 d->page->focusController()->focusedOrMainFrame()->editor()->copy(); |
|
316 } |
|
317 |
|
318 void QWebPage::paste() |
|
319 { |
|
320 d->page->focusController()->focusedOrMainFrame()->editor()->paste(); |
|
321 } |
|
322 |
|
323 /*! |
|
324 Returns true if the page contains unsubmitted form data. |
|
325 */ |
|
326 bool QWebPage::isModified() const |
|
327 { |
|
328 return d->modified; |
|
329 } |
|
330 |
|
331 |
|
332 QUndoStack *QWebPage::undoStack() |
|
333 { |
|
334 if (!d->undoStack) |
|
335 d->undoStack = new QUndoStack(this); |
|
336 |
|
337 return d->undoStack; |
|
338 } |
|
339 |
|
340 static inline DragOperation dropActionToDragOp(Qt::DropActions actions) |
|
341 { |
|
342 unsigned result = 0; |
|
343 if (actions & Qt::CopyAction) |
|
344 result |= DragOperationCopy; |
|
345 if (actions & Qt::MoveAction) |
|
346 result |= DragOperationMove; |
|
347 if (actions & Qt::LinkAction) |
|
348 result |= DragOperationLink; |
|
349 return (DragOperation)result; |
|
350 } |
|
351 |
|
352 static inline Qt::DropAction dragOpToDropAction(unsigned actions) |
|
353 { |
|
354 Qt::DropAction result = Qt::IgnoreAction; |
|
355 if (actions & DragOperationCopy) |
|
356 result = Qt::CopyAction; |
|
357 else if (actions & DragOperationMove) |
|
358 result = Qt::MoveAction; |
|
359 else if (actions & DragOperationLink) |
|
360 result = Qt::LinkAction; |
|
361 return result; |
|
362 } |
|
363 |
|
364 void QWebPage::resizeEvent(QResizeEvent *e) |
|
365 { |
|
366 QWidget::resizeEvent(e); |
|
367 if (mainFrame()->d->frame && mainFrame()->d->frameView) { |
|
368 mainFrame()->d->frameView->setFrameGeometry(rect()); |
|
369 mainFrame()->d->frame->forceLayout(); |
|
370 mainFrame()->d->frame->view()->adjustViewSize(); |
|
371 } |
|
372 } |
|
373 |
|
374 void QWebPage::paintEvent(QPaintEvent *ev) |
|
375 { |
|
376 #ifdef QWEBKIT_TIME_RENDERING |
|
377 QTime time; |
|
378 time.start(); |
|
379 #endif |
|
380 |
|
381 QPainter p(this); |
|
382 |
|
383 QVector<QRect> vector = ev->region().rects(); |
|
384 if (!vector.isEmpty()) { |
|
385 for (int i = 0; i < vector.size(); ++i) { |
|
386 mainFrame()->render(&p, vector.at(i)); |
|
387 } |
|
388 } else { |
|
389 mainFrame()->render(&p, ev->rect()); |
|
390 } |
|
391 |
|
392 #ifdef QWEBKIT_TIME_RENDERING |
|
393 int elapsed = time.elapsed(); |
|
394 qDebug()<<"paint event on "<<ev->region()<<", took to render = "<<elapsed; |
|
395 #endif |
|
396 } |
|
397 |
|
398 void QWebPage::mouseMoveEvent(QMouseEvent *ev) |
|
399 { |
|
400 mainFrame()->mouseMoveEvent(ev); |
|
401 } |
|
402 |
|
403 void QWebPage::mousePressEvent(QMouseEvent *ev) |
|
404 { |
|
405 mainFrame()->mousePressEvent(ev); |
|
406 } |
|
407 |
|
408 void QWebPage::mouseDoubleClickEvent(QMouseEvent *ev) |
|
409 { |
|
410 mainFrame()->mouseDoubleClickEvent(ev); |
|
411 } |
|
412 |
|
413 void QWebPage::mouseReleaseEvent(QMouseEvent *ev) |
|
414 { |
|
415 mainFrame()->mouseReleaseEvent(ev); |
|
416 } |
|
417 |
|
418 void QWebPage::wheelEvent(QWheelEvent *ev) |
|
419 { |
|
420 mainFrame()->wheelEvent(ev); |
|
421 if (!ev->isAccepted()) |
|
422 QWidget::wheelEvent(ev); |
|
423 } |
|
424 |
|
425 void QWebPage::keyPressEvent(QKeyEvent *ev) |
|
426 { |
|
427 PlatformKeyboardEvent kevent(ev, false); |
|
428 |
|
429 if (!mainFrame()->d->eventHandler) |
|
430 return; |
|
431 |
|
432 bool handled = mainFrame()->d->eventHandler->keyEvent(kevent); |
|
433 if (handled) { |
|
434 } else { |
|
435 handled = true; |
|
436 PlatformScrollbar *h, *v; |
|
437 h = mainFrame()->d->horizontalScrollBar(); |
|
438 v = mainFrame()->d->verticalScrollBar(); |
|
439 |
|
440 if (ev == QKeySequence::MoveToNextPage) { |
|
441 if (v) |
|
442 v->setValue(v->value() + height()); |
|
443 } else if (ev == QKeySequence::MoveToPreviousPage) { |
|
444 if (v) |
|
445 v->setValue(v->value() - height()); |
|
446 } else { |
|
447 switch (ev->key()) { |
|
448 case Qt::Key_Up: |
|
449 if (v) |
|
450 v->setValue(v->value() - 10); |
|
451 break; |
|
452 case Qt::Key_Down: |
|
453 if (v) |
|
454 v->setValue(v->value() + 10); |
|
455 break; |
|
456 case Qt::Key_Left: |
|
457 if (h) |
|
458 h->setValue(h->value() - 10); |
|
459 break; |
|
460 case Qt::Key_Right: |
|
461 if (h) |
|
462 h->setValue(h->value() + 10); |
|
463 break; |
|
464 default: |
|
465 handled = false; |
|
466 break; |
|
467 } |
|
468 } |
|
469 } |
|
470 |
|
471 ev->setAccepted(handled); |
|
472 } |
|
473 |
|
474 void QWebPage::keyReleaseEvent(QKeyEvent *ev) |
|
475 { |
|
476 if (ev->isAutoRepeat()) { |
|
477 ev->setAccepted(true); |
|
478 return; |
|
479 } |
|
480 |
|
481 PlatformKeyboardEvent kevent(ev, true); |
|
482 |
|
483 if (!mainFrame()->d->eventHandler) |
|
484 return; |
|
485 |
|
486 bool handled = mainFrame()->d->eventHandler->keyEvent(kevent); |
|
487 ev->setAccepted(handled); |
|
488 } |
|
489 |
|
490 void QWebPage::focusInEvent(QFocusEvent *ev) |
|
491 { |
|
492 if (ev->reason() != Qt::PopupFocusReason) { |
|
493 mainFrame()->d->frame->page()->focusController()->setFocusedFrame(mainFrame()->d->frame); |
|
494 mainFrame()->d->frame->setIsActive(true); |
|
495 } |
|
496 QWidget::focusInEvent(ev); |
|
497 } |
|
498 |
|
499 void QWebPage::focusOutEvent(QFocusEvent *ev) |
|
500 { |
|
501 QWidget::focusOutEvent(ev); |
|
502 if (ev->reason() != Qt::PopupFocusReason) { |
|
503 mainFrame()->d->frame->selectionController()->clear(); |
|
504 mainFrame()->d->frame->setIsActive(false); |
|
505 } |
|
506 } |
|
507 |
|
508 bool QWebPage::focusNextPrevChild(bool next) |
|
509 { |
|
510 Q_UNUSED(next) |
|
511 return false; |
|
512 } |
|
513 |
|
514 void QWebPage::dragEnterEvent(QDragEnterEvent *ev) |
|
515 { |
|
516 #ifndef QT_NO_DRAGANDDROP |
|
517 DragData dragData(ev->mimeData(), ev->pos(), QCursor::pos(), |
|
518 dropActionToDragOp(ev->possibleActions())); |
|
519 Qt::DropAction action = dragOpToDropAction(d->page->dragController()->dragEntered(&dragData)); |
|
520 ev->setDropAction(action); |
|
521 ev->accept(); |
|
522 #endif |
|
523 } |
|
524 |
|
525 void QWebPage::dragLeaveEvent(QDragLeaveEvent *ev) |
|
526 { |
|
527 #ifndef QT_NO_DRAGANDDROP |
|
528 DragData dragData(0, IntPoint(), QCursor::pos(), DragOperationNone); |
|
529 d->page->dragController()->dragExited(&dragData); |
|
530 ev->accept(); |
|
531 #endif |
|
532 } |
|
533 |
|
534 void QWebPage::dragMoveEvent(QDragMoveEvent *ev) |
|
535 { |
|
536 #ifndef QT_NO_DRAGANDDROP |
|
537 DragData dragData(ev->mimeData(), ev->pos(), QCursor::pos(), |
|
538 dropActionToDragOp(ev->possibleActions())); |
|
539 Qt::DropAction action = dragOpToDropAction(d->page->dragController()->dragUpdated(&dragData)); |
|
540 ev->setDropAction(action); |
|
541 ev->accept(); |
|
542 #endif |
|
543 } |
|
544 |
|
545 void QWebPage::dropEvent(QDropEvent *ev) |
|
546 { |
|
547 #ifndef QT_NO_DRAGANDDROP |
|
548 DragData dragData(ev->mimeData(), ev->pos(), QCursor::pos(), |
|
549 dropActionToDragOp(ev->possibleActions())); |
|
550 Qt::DropAction action = dragOpToDropAction(d->page->dragController()->performDrag(&dragData)); |
|
551 ev->accept(); |
|
552 #endif |
|
553 } |
|
554 |
|
555 void QWebPage::setNetworkInterface(QWebNetworkInterface *interface) |
|
556 { |
|
557 d->networkInterface = interface; |
|
558 } |
|
559 |
|
560 QWebNetworkInterface *QWebPage::networkInterface() const |
|
561 { |
|
562 if (d->networkInterface) |
|
563 return d->networkInterface; |
|
564 else |
|
565 return QWebNetworkInterface::defaultInterface(); |
|
566 } |
|
567 |
|
568 QPixmap QWebPage::icon() const |
|
569 { |
|
570 Image* image = iconDatabase()->iconForPageURL(url().toString(), IntSize(16, 16)); |
|
571 if (!image || image->isNull()) { |
|
572 image = iconDatabase()->defaultIcon(IntSize(16, 16)); |
|
573 } |
|
574 |
|
575 if (!image) { |
|
576 return QPixmap(); |
|
577 } |
|
578 |
|
579 QPixmap *icon = image->getPixmap(); |
|
580 if (!icon) { |
|
581 return QPixmap(); |
|
582 } |
|
583 return *icon; |
|
584 } |
|
585 |
|
586 void QWebPage::setSettings(const QWebSettings &settings) |
|
587 { |
|
588 WebCore::Settings *wSettings = d->page->settings(); |
|
589 |
|
590 wSettings->setStandardFontFamily( |
|
591 settings.fontFamily(QWebSettings::StandardFont)); |
|
592 wSettings->setFixedFontFamily( |
|
593 settings.fontFamily(QWebSettings::FixedFont)); |
|
594 wSettings->setSerifFontFamily( |
|
595 settings.fontFamily(QWebSettings::SerifFont)); |
|
596 wSettings->setSansSerifFontFamily( |
|
597 settings.fontFamily(QWebSettings::SansSerifFont)); |
|
598 wSettings->setCursiveFontFamily( |
|
599 settings.fontFamily(QWebSettings::CursiveFont)); |
|
600 wSettings->setFantasyFontFamily( |
|
601 settings.fontFamily(QWebSettings::FantasyFont)); |
|
602 |
|
603 wSettings->setMinimumFontSize(settings.minimumFontSize()); |
|
604 wSettings->setMinimumLogicalFontSize(settings.minimumLogicalFontSize()); |
|
605 wSettings->setDefaultFontSize(settings.defaultFontSize()); |
|
606 wSettings->setDefaultFixedFontSize(settings.defaultFixedFontSize()); |
|
607 |
|
608 wSettings->setLoadsImagesAutomatically( |
|
609 settings.testAttribute(QWebSettings::AutoLoadImages)); |
|
610 wSettings->setJavaScriptEnabled( |
|
611 settings.testAttribute(QWebSettings::JavascriptEnabled)); |
|
612 wSettings->setJavaScriptCanOpenWindowsAutomatically( |
|
613 settings.testAttribute(QWebSettings::JavascriptCanOpenWindows)); |
|
614 wSettings->setJavaEnabled( |
|
615 settings.testAttribute(QWebSettings::JavaEnabled)); |
|
616 wSettings->setPluginsEnabled( |
|
617 settings.testAttribute(QWebSettings::PluginsEnabled)); |
|
618 wSettings->setPrivateBrowsingEnabled( |
|
619 settings.testAttribute(QWebSettings::PrivateBrowsingEnabled)); |
|
620 |
|
621 wSettings->setUserStyleSheetLocation(KURL(settings.userStyleSheetLocation())); |
|
622 |
|
623 // ### should be configurable |
|
624 wSettings->setDefaultTextEncodingName("iso-8859-1"); |
|
625 } |
|
626 |
|
627 QWebSettings QWebPage::settings() const |
|
628 { |
|
629 QWebSettings settings; |
|
630 WebCore::Settings *wSettings = d->page->settings(); |
|
631 |
|
632 settings.setFontFamily(QWebSettings::StandardFont, |
|
633 wSettings->standardFontFamily()); |
|
634 settings.setFontFamily(QWebSettings::FixedFont, |
|
635 wSettings->fixedFontFamily()); |
|
636 settings.setFontFamily(QWebSettings::SerifFont, |
|
637 wSettings->serifFontFamily()); |
|
638 settings.setFontFamily(QWebSettings::SansSerifFont, |
|
639 wSettings->sansSerifFontFamily()); |
|
640 settings.setFontFamily(QWebSettings::CursiveFont, |
|
641 wSettings->cursiveFontFamily()); |
|
642 settings.setFontFamily(QWebSettings::FantasyFont, |
|
643 wSettings->fantasyFontFamily()); |
|
644 |
|
645 settings.setMinimumFontSize(wSettings->minimumFontSize()); |
|
646 settings.setMinimumLogicalFontSize(wSettings->minimumLogicalFontSize()); |
|
647 settings.setDefaultFontSize(wSettings->defaultFontSize()); |
|
648 settings.setDefaultFixedFontSize(wSettings->defaultFixedFontSize()); |
|
649 |
|
650 settings.setAttribute(QWebSettings::AutoLoadImages, |
|
651 wSettings->loadsImagesAutomatically()); |
|
652 settings.setAttribute(QWebSettings::JavascriptEnabled, |
|
653 wSettings->isJavaScriptEnabled()); |
|
654 settings.setAttribute(QWebSettings::JavascriptCanOpenWindows, |
|
655 wSettings->JavaScriptCanOpenWindowsAutomatically()); |
|
656 settings.setAttribute(QWebSettings::JavaEnabled, |
|
657 wSettings->isJavaEnabled()); |
|
658 settings.setAttribute(QWebSettings::PluginsEnabled, |
|
659 wSettings->arePluginsEnabled()); |
|
660 settings.setAttribute(QWebSettings::PrivateBrowsingEnabled, |
|
661 wSettings->privateBrowsingEnabled()); |
|
662 |
|
663 settings.setUserStyleSheetLocation( |
|
664 wSettings->userStyleSheetLocation().url()); |
|
665 |
|
666 return settings; |
|
667 } |
|
668 |
|
669 QString QWebPage::chooseFile(QWebFrame *parentFrame, const QString& oldFile) |
|
670 { |
|
671 //FIXME frame pos... |
|
672 #ifndef QT_NO_FILEDIALOG |
|
673 return QFileDialog::getOpenFileName(this, QString::null, oldFile); |
|
674 #else |
|
675 return QString::null; |
|
676 #endif |
|
677 } |
|
678 |
|
679 #ifndef QT_NO_NETWORKPROXY |
|
680 void QWebPage::setNetworkProxy(const QNetworkProxy& proxy) |
|
681 { |
|
682 d->networkProxy = proxy; |
|
683 } |
|
684 |
|
685 QNetworkProxy QWebPage::networkProxy() const |
|
686 { |
|
687 return d->networkProxy; |
|
688 } |
|
689 #endif |
|
690 |
|
691 QString QWebPage::userAgentStringForUrl(const QUrl& forUrl) const { |
|
692 Q_UNUSED(forUrl) |
|
693 return QLatin1String("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/418.9.1 (KHTML, like Gecko) Safari/419.3 Qt"); |
|
694 } |
|
695 |
|
696 |
|
697 void QWebPage::onLoadProgressChanged(int) { |
|
698 d->m_totalBytes = d->page->progress()->totalPageAndResourceBytesToLoad(); |
|
699 d->m_bytesReceived = d->page->progress()->totalBytesReceived(); |
|
700 } |
|
701 |
|
702 |
|
703 quint64 QWebPage::totalBytes() const { |
|
704 return d->m_bytesReceived; |
|
705 } |
|
706 |
|
707 |
|
708 quint64 QWebPage::bytesReceived() const { |
|
709 return d->m_totalBytes; |
|
710 } |