2 * Copyright (C) 2006 Dirk Mueller <mueller@kde.org>
3 * Copyright (C) 2006 Zack Rusin <zack@kde.org>
4 * Copyright (C) 2006 George Staikos <staikos@kde.org>
5 * Copyright (C) 2006 Simon Hausmann <hausmann@kde.org>
6 * Copyright (C) 2006 Rob Buis <buis@kde.org>
7 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
21 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
28 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #include "RenderObject.h"
37 #include "RenderWidget.h"
38 #include "RenderLayer.h"
41 #include "HTMLElement.h"
42 #include "DOMWindow.h"
43 #include "FrameLoadRequest.h"
44 #include "DOMImplementation.h"
45 #include "BrowserExtensionQt.h"
46 #include "ResourceLoaderInternal.h"
50 #include "FramePrivate.h"
51 #include "GraphicsContext.h"
52 #include "HTMLDocument.h"
53 #include "ResourceLoader.h"
54 #include "PlatformMouseEvent.h"
55 #include "PlatformKeyboardEvent.h"
56 #include "PlatformWheelEvent.h"
57 #include "MouseEventWithHitTestResults.h"
58 #include "SelectionController.h"
59 #include "TypingCommand.h"
61 #include <QScrollArea>
63 #define notImplemented() do { fprintf(stderr, "FIXME: UNIMPLEMENTED: %s:%d\n", __FILE__, __LINE__); } while(0)
67 static void doScroll(const RenderObject* r, bool isHorizontal, int multiplier)
69 // FIXME: The scrolling done here should be done in the default handlers
70 // of the elements rather than here in the part.
74 //broken since it calls scroll on scrollbars
75 //and we have none now
76 //r->scroll(direction, KWQScrollWheel, multiplier);
80 int x = r->layer()->scrollXOffset();
81 int y = r->layer()->scrollYOffset();
87 r->layer()->scrollToOffset(x, y, true, true);
90 FrameQt::FrameQt(Page* page, Element* ownerElement, FrameQtClient* client)
91 : Frame(page, ownerElement)
93 d->m_extension = new BrowserExtensionQt(this);
94 Settings* settings = new Settings;
95 settings->setAutoLoadImages(true);
96 settings->setMinFontSize(5);
97 settings->setMinLogicalFontSize(5);
98 settings->setShouldPrintBackgrounds(true);
99 settings->setIsJavaScriptEnabled(true);
101 settings->setMediumFixedFontSize(14);
102 settings->setMediumFontSize(14);
103 settings->setSerifFontName("Times New Roman");
104 settings->setSansSerifFontName("Arial");
105 settings->setFixedFontName("Courier");
106 settings->setStdFontName("Arial");
108 setSettings(settings);
111 m_client->setFrame(this);
119 clearRecordedFormValues();
122 bool FrameQt::openURL(const KURL& url)
127 m_client->openURL(url);
131 void FrameQt::submitForm(const FrameLoadRequest& frameLoadRequest)
133 ResourceRequest request = frameLoadRequest.m_request;
135 // FIXME: this is a hack inherited from FrameMac, and should be pushed into Frame
136 if (d->m_submittedFormURL == request.url())
139 d->m_submittedFormURL = request.url();
142 m_client->submitForm(request.doPost() ? "POST" : "GET", request.url(), &request.postData);
144 clearRecordedFormValues();
147 void FrameQt::urlSelected(const FrameLoadRequest& frameLoadRequest)
149 ResourceRequest request = frameLoadRequest.m_request;
154 m_client->openURL(request.url());
157 String FrameQt::userAgent() const
159 return "Mozilla/5.0 (PC; U; Intel; Linux; en) AppleWebKit/420+ (KHTML, like Gecko)";
162 void FrameQt::runJavaScriptAlert(String const& message)
164 m_client->runJavaScriptAlert(message);
167 bool FrameQt::runJavaScriptConfirm(String const& message)
173 bool FrameQt::locationbarVisible()
179 void FrameQt::setTitle(const String& title)
181 if (view() && view()->parentWidget())
182 view()->parentWidget()->setWindowTitle(title);
185 Frame* FrameQt::createFrame(const KURL&, const String& name, Element*, const String& referrer)
191 bool FrameQt::passWheelEventToChildWidget(Node*)
197 bool FrameQt::passSubframeEventToSubframe(MouseEventWithHitTestResults& mev, Frame*)
199 if (mev.targetNode() == 0)
205 ObjectContentType FrameQt::objectContentType(const KURL&, const String& mimeType)
208 return ObjectContentType();
211 Plugin* FrameQt::createPlugin(Element*, const KURL&, const Vector<String>&, const Vector<String>&, const String&)
217 bool FrameQt::passMouseDownEventToWidget(Widget*)
223 bool FrameQt::isLoadTypeReload()
229 bool FrameQt::menubarVisible()
235 bool FrameQt::personalbarVisible()
241 bool FrameQt::statusbarVisible()
247 bool FrameQt::toolbarVisible()
253 void FrameQt::createEmptyDocument()
255 // FIXME: Implement like described in this comment from FrameMac:
257 // Although it's not completely clear from the name of this function,
258 // it does nothing if we already have a document, and just creates an
259 // empty one if we have no document at all.
262 Range* FrameQt::markedTextRange() const
268 String FrameQt::incomingReferrer() const
274 String FrameQt::mimeTypeForFileName(const String&) const
280 void FrameQt::markMisspellingsInAdjacentWords(const VisiblePosition&)
285 void FrameQt::markMisspellings(const Selection&)
290 bool FrameQt::lastEventIsMouseUp() const
296 void FrameQt::saveDocumentState()
298 // FIXME: Implement this as soon a KPart is created...
301 void FrameQt::restoreDocumentState()
303 // FIXME: Implement this as soon a KPart is created...
306 void FrameQt::openURLRequest(const FrameLoadRequest&)
311 void FrameQt::scheduleClose()
316 void FrameQt::unfocusWindow()
321 void FrameQt::focusWindow()
326 String FrameQt::overrideMediaType() const
331 void FrameQt::addMessageToConsole(const String& message, unsigned lineNumber, const String& sourceID)
333 qDebug("[FrameQt::addMessageToConsole] message=%s lineNumber=%d sourceID=%s",
334 qPrintable(QString(message)), lineNumber, qPrintable(QString(sourceID)));
337 bool FrameQt::runJavaScriptPrompt(const String& message, const String& defaultValue, String& result)
343 KJS::Bindings::Instance* FrameQt::getEmbedInstanceForWidget(Widget*)
349 KJS::Bindings::Instance* FrameQt::getObjectInstanceForWidget(Widget*)
355 KJS::Bindings::Instance* FrameQt::getAppletInstanceForWidget(Widget*)
361 KJS::Bindings::RootObject* FrameQt::bindingRootObject()
367 Widget* FrameQt::createJavaAppletWidget(const IntSize&, Element*, const HashMap<String, String>&)
373 void FrameQt::registerCommandForUndo(PassRefPtr<EditCommand>)
378 void FrameQt::registerCommandForRedo(PassRefPtr<EditCommand>)
383 void FrameQt::clearUndoRedoOperations()
385 // FIXME: Implement this as soon a KPart is created...
388 void FrameQt::issueUndoCommand()
393 void FrameQt::issueRedoCommand()
398 void FrameQt::issueCutCommand()
403 void FrameQt::issueCopyCommand()
408 void FrameQt::issuePasteCommand()
413 void FrameQt::issuePasteAndMatchStyleCommand()
418 void FrameQt::issueTransposeCommand()
423 void FrameQt::respondToChangedSelection(const Selection& oldSelection, bool closeTyping)
428 void FrameQt::respondToChangedContents(const Selection& endingSelection)
433 bool FrameQt::shouldChangeSelection(const Selection& oldSelection, const Selection& newSelection, EAffinity affinity, bool stillSelecting) const
439 void FrameQt::partClearedInBegin()
441 // FIXME: This is only related to the js debugger.
442 // See WebCoreSupport/WebFrameBridge.m "windowObjectCleared",
443 // which is called by FrameMac::partClearedInBegin() ...
446 bool FrameQt::canGoBackOrForward(int distance) const
452 void FrameQt::handledOnloadEvents()
454 // TODO: FrameMac doesn't need that - it seems.
455 // It must be handled differently, can't figure it out.
456 // If we won't call this here doc->parsing() remains 'true'
457 // all the time. Calling document.open(); document.write(...)
458 // from JavaScript leaves the parsing state 'true', and DRT will
459 // hang on these tests (fast/dom/Document/document-reopen.html for instance)
463 bool FrameQt::canPaste() const
469 bool FrameQt::canRedo() const
475 bool FrameQt::canUndo() const
481 void FrameQt::print()
486 bool FrameQt::shouldInterruptJavaScript()
492 KURL FrameQt::originalRequestURL() const
498 bool FrameQt::keyEvent(const PlatformKeyboardEvent& keyEvent)
502 // Check for cases where we are too early for events -- possible unmatched key up
503 // from pressing return in the location bar.
504 Document* doc = document();
508 Node* node = doc->focusNode();
510 if (doc->isHTMLDocument())
513 node = doc->documentElement();
519 if (!keyEvent.isKeyUp())
520 prepareForUserAction();
522 result = !EventTargetNodeCast(node)->dispatchKeyEvent(keyEvent);
524 // FIXME: FrameMac has a keyDown/keyPress hack here which we are not copying.
528 void FrameQt::setFrameGeometry(const IntRect& r)
530 setFrameGeometry(QRect(r));
533 void FrameQt::tokenizerProcessedData()