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 "DOMImplementation.h"
44 #include "BrowserExtensionQt.h"
45 #include "ResourceLoaderInternal.h"
49 #include "FramePrivate.h"
50 #include "GraphicsContext.h"
51 #include "HTMLDocument.h"
52 #include "ResourceLoader.h"
53 #include "PlatformMouseEvent.h"
54 #include "PlatformKeyboardEvent.h"
55 #include "PlatformWheelEvent.h"
56 #include "MouseEventWithHitTestResults.h"
57 #include "SelectionController.h"
58 #include "TypingCommand.h"
60 #include <QScrollArea>
62 #define notImplemented() do { fprintf(stderr, "FIXME: UNIMPLEMENTED: %s:%d\n", __FILE__, __LINE__); } while(0)
66 static void doScroll(const RenderObject* r, bool isHorizontal, int multiplier)
68 // FIXME: The scrolling done here should be done in the default handlers
69 // of the elements rather than here in the part.
73 //broken since it calls scroll on scrollbars
74 //and we have none now
75 //r->scroll(direction, KWQScrollWheel, multiplier);
79 int x = r->layer()->scrollXOffset();
80 int y = r->layer()->scrollYOffset();
86 r->layer()->scrollToOffset(x, y, true, true);
89 FrameQt::FrameQt(Page* page, Element* ownerElement, FrameQtClient* client)
90 : Frame(page, ownerElement)
92 d->m_extension = new BrowserExtensionQt(this);
93 Settings* settings = new Settings;
94 settings->setAutoLoadImages(true);
95 settings->setMinFontSize(5);
96 settings->setMinLogicalFontSize(5);
97 settings->setShouldPrintBackgrounds(true);
98 settings->setIsJavaScriptEnabled(true);
100 settings->setMediumFixedFontSize(14);
101 settings->setMediumFontSize(14);
102 settings->setSerifFontName("Times New Roman");
103 settings->setSansSerifFontName("Arial");
104 settings->setFixedFontName("Courier");
105 settings->setStdFontName("Arial");
107 setSettings(settings);
110 m_client->setFrame(this);
118 clearRecordedFormValues();
121 bool FrameQt::openURL(const KURL& url)
126 m_client->openURL(url);
130 void FrameQt::submitForm(const ResourceRequest& request)
132 // FIXME: this is a hack inherited from FrameMac, and should be pushed into Frame
133 if (d->m_submittedFormURL == request.url())
136 d->m_submittedFormURL = request.url();
139 m_client->submitForm(request.doPost() ? "POST" : "GET", request.url(), &request.postData);
141 clearRecordedFormValues();
144 void FrameQt::urlSelected(const ResourceRequest& request)
149 m_client->openURL(request.url());
152 String FrameQt::userAgent() const
154 return "Mozilla/5.0 (PC; U; Intel; Linux; en) AppleWebKit/420+ (KHTML, like Gecko)";
157 void FrameQt::runJavaScriptAlert(String const& message)
159 m_client->runJavaScriptAlert(message);
162 bool FrameQt::runJavaScriptConfirm(String const& message)
168 bool FrameQt::locationbarVisible()
174 void FrameQt::setTitle(const String& title)
176 if (view() && view()->parentWidget())
177 view()->parentWidget()->setWindowTitle(title);
180 Frame* FrameQt::createFrame(const KURL&, const String& name, Element*, const String& referrer)
186 bool FrameQt::passWheelEventToChildWidget(Node*)
192 bool FrameQt::passSubframeEventToSubframe(MouseEventWithHitTestResults& mev, Frame*)
194 if (mev.targetNode() == 0)
200 ObjectContentType FrameQt::objectContentType(const KURL&, const String& mimeType)
203 return ObjectContentType();
206 Plugin* FrameQt::createPlugin(Element*, const KURL&, const Vector<String>&, const Vector<String>&, const String&)
212 bool FrameQt::passMouseDownEventToWidget(Widget*)
218 bool FrameQt::isLoadTypeReload()
224 bool FrameQt::menubarVisible()
230 bool FrameQt::personalbarVisible()
236 bool FrameQt::statusbarVisible()
242 bool FrameQt::toolbarVisible()
248 void FrameQt::createEmptyDocument()
250 // FIXME: Implement like described in this comment from FrameMac:
252 // Although it's not completely clear from the name of this function,
253 // it does nothing if we already have a document, and just creates an
254 // empty one if we have no document at all.
257 Range* FrameQt::markedTextRange() const
263 String FrameQt::incomingReferrer() const
269 String FrameQt::mimeTypeForFileName(const String&) const
275 void FrameQt::markMisspellingsInAdjacentWords(const VisiblePosition&)
280 void FrameQt::markMisspellings(const Selection&)
285 bool FrameQt::lastEventIsMouseUp() const
291 void FrameQt::saveDocumentState()
293 // FIXME: Implement this as soon a KPart is created...
296 void FrameQt::restoreDocumentState()
298 // FIXME: Implement this as soon a KPart is created...
301 void FrameQt::openURLRequest(const ResourceRequest&)
306 void FrameQt::scheduleClose()
311 void FrameQt::unfocusWindow()
316 void FrameQt::focusWindow()
321 String FrameQt::overrideMediaType() const
326 void FrameQt::addMessageToConsole(const String& message, unsigned lineNumber, const String& sourceID)
328 qDebug("[FrameQt::addMessageToConsole] message=%s lineNumber=%d sourceID=%s",
329 qPrintable(QString(message)), lineNumber, qPrintable(QString(sourceID)));
332 bool FrameQt::runJavaScriptPrompt(const String& message, const String& defaultValue, String& result)
338 KJS::Bindings::Instance* FrameQt::getEmbedInstanceForWidget(Widget*)
344 KJS::Bindings::Instance* FrameQt::getObjectInstanceForWidget(Widget*)
350 KJS::Bindings::Instance* FrameQt::getAppletInstanceForWidget(Widget*)
356 KJS::Bindings::RootObject* FrameQt::bindingRootObject()
362 Widget* FrameQt::createJavaAppletWidget(const IntSize&, Element*, const HashMap<String, String>&)
368 void FrameQt::registerCommandForUndo(PassRefPtr<EditCommand>)
373 void FrameQt::registerCommandForRedo(PassRefPtr<EditCommand>)
378 void FrameQt::clearUndoRedoOperations()
380 // FIXME: Implement this as soon a KPart is created...
383 void FrameQt::issueUndoCommand()
388 void FrameQt::issueRedoCommand()
393 void FrameQt::issueCutCommand()
398 void FrameQt::issueCopyCommand()
403 void FrameQt::issuePasteCommand()
408 void FrameQt::issuePasteAndMatchStyleCommand()
413 void FrameQt::issueTransposeCommand()
418 void FrameQt::respondToChangedSelection(const Selection& oldSelection, bool closeTyping)
423 void FrameQt::respondToChangedContents(const Selection& endingSelection)
428 bool FrameQt::shouldChangeSelection(const Selection& oldSelection, const Selection& newSelection, EAffinity affinity, bool stillSelecting) const
434 void FrameQt::partClearedInBegin()
436 // FIXME: This is only related to the js debugger.
437 // See WebCoreSupport/WebFrameBridge.m "windowObjectCleared",
438 // which is called by FrameMac::partClearedInBegin() ...
441 bool FrameQt::canGoBackOrForward(int distance) const
447 void FrameQt::handledOnloadEvents()
452 bool FrameQt::canPaste() const
458 bool FrameQt::canRedo() const
464 bool FrameQt::canUndo() const
470 void FrameQt::print()
475 bool FrameQt::shouldInterruptJavaScript()
481 KURL FrameQt::originalRequestURL() const
487 bool FrameQt::keyEvent(const PlatformKeyboardEvent& keyEvent)
491 // Check for cases where we are too early for events -- possible unmatched key up
492 // from pressing return in the location bar.
493 Document* doc = document();
497 Node* node = doc->focusNode();
499 if (doc->isHTMLDocument())
502 node = doc->documentElement();
508 if (!keyEvent.isKeyUp())
509 prepareForUserAction();
511 result = !EventTargetNodeCast(node)->dispatchKeyEvent(keyEvent);
513 // FIXME: FrameMac has a keyDown/keyPress hack here which we are not copying.
517 void FrameQt::setFrameGeometry(const IntRect& r)
519 setFrameGeometry(QRect(r));
522 void FrameQt::tokenizerProcessedData()