2 * Copyright (C) 2003 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef KWQKHTMLPart_H
27 #define KWQKHTMLPart_H
29 #include "khtml_part.h"
31 #include "dom_nodeimpl.h"
32 #include "html_formimpl.h"
33 #include "html_tableimpl.h"
35 #import "WebCoreKeyboardAccess.h"
37 #include <CoreFoundation/CoreFoundation.h>
39 #include <JavaVM/jni.h>
40 #include <JavaScriptCore/jni_jsobject.h>
41 #include <JavaScriptCore/npruntime.h>
42 #include <JavaScriptCore/NP_jsobject.h>
43 #include <JavaScriptCore/runtime.h>
46 #include "KWQClipboard.h"
48 class KHTMLPartPrivate;
50 class KWQWindowWidget;
57 class SavedProperties;
59 class ScheduledAction;
64 // Avoid clashes with KJS::DOMElement in KHTML code.
66 typedef DOMElement ObjCDOMElement;
70 @class NSAttributedString;
76 @class NSMutableDictionary;
81 @class WebScriptObject;
85 // Avoid clashes with KJS::DOMElement in KHTML code.
90 class NSAttributedString;
96 class NSMutableDictionary;
101 class WebScriptObject;
105 enum KWQSelectionDirection {
110 class KWQKHTMLPart : public KHTMLPart
118 void setBridge(WebCoreBridge *p);
119 WebCoreBridge *bridge() const { return _bridge; }
120 void setView(KHTMLView *view);
121 KHTMLView *view() const;
123 void provisionalLoadStarted();
125 virtual bool openURL(const KURL &);
126 virtual bool closeURL();
127 void didNotOpenURL(const KURL &);
129 void openURLRequest(const KURL &, const KParts::URLArgs &);
130 void submitForm(const KURL &, const KParts::URLArgs &);
132 void scheduleHistoryNavigation( int steps );
134 void scrollToAnchor(const KURL &);
135 void jumpToSelection();
136 QString advanceToNextMisspelling();
138 void setEncoding(const QString &encoding, bool userChosen);
139 void addData(const char *bytes, int length);
141 void setTitle(const DOM::DOMString &);
142 void setStatusBarText(const QString &status);
144 void urlSelected(const KURL &url, int button, int state, const KParts::URLArgs &args);
145 bool requestObject(khtml::RenderPart *frame, const QString &url, const QString &serviceType, const QStringList &args);
146 KParts::ReadOnlyPart *createPart(const khtml::ChildFrame &child, const KURL &url, const QString &mimeType);
148 void scheduleClose();
150 void unfocusWindow();
152 QMap<int, KJS::ScheduledAction*> *pauseActions(const void *key);
153 void resumeActions(QMap<int, KJS::ScheduledAction*> *actions, const void *key);
156 void saveWindowProperties(KJS::SavedProperties *windowProperties);
157 void saveLocationProperties(KJS::SavedProperties *locationProperties);
158 void restoreWindowProperties(KJS::SavedProperties *windowProperties);
159 void restoreLocationProperties(KJS::SavedProperties *locationProperties);
160 void saveInterpreterBuiltins(KJS::SavedBuiltins &interpreterBuiltins);
161 void restoreInterpreterBuiltins(const KJS::SavedBuiltins &interpreterBuiltins);
163 void openURLFromPageCache(KWQPageState *state);
165 void saveDocumentState();
166 void restoreDocumentState();
168 bool isFrameSet() const;
170 void updatePolicyBaseURL();
172 NSView *nextKeyView(DOM::NodeImpl *startingPoint, KWQSelectionDirection);
173 NSView *nextKeyViewInFrameHierarchy(DOM::NodeImpl *startingPoint, KWQSelectionDirection);
174 static NSView *nextKeyViewForWidget(QWidget *startingPoint, KWQSelectionDirection);
175 static bool currentEventIsKeyboardOptionTab();
176 static bool handleKeyboardOptionTabInView(NSView *view);
178 virtual bool tabsToLinks() const;
179 virtual bool tabsToAllControls() const;
181 static bool currentEventIsMouseDownInWidget(QWidget *candidate);
183 static void setDocumentFocus(QWidget *);
184 static void clearDocumentFocus(QWidget *);
186 void runJavaScriptAlert(const QString &message);
187 bool runJavaScriptConfirm(const QString &message);
188 bool runJavaScriptPrompt(const QString &message, const QString &defaultValue, QString &result);
189 bool locationbarVisible();
190 bool menubarVisible();
191 bool personalbarVisible();
192 bool scrollbarsVisible();
193 bool statusbarVisible();
194 bool toolbarVisible();
196 void KWQKHTMLPart::addMessageToConsole(const QString &message, unsigned int lineNumber, const QString &sourceID);
197 using KHTMLPart::xmlDocImpl;
198 khtml::RenderObject *renderer();
200 void forceLayoutWithPageWidthRange(float minPageWidth, float maxPageWidth);
201 void sendResizeEvent();
202 void sendScrollEvent();
203 void paint(QPainter *, const QRect &);
205 void adjustPageHeight(float *newBottom, float oldTop, float oldBottom, float bottomLimit);
207 void createEmptyDocument();
209 static WebCoreBridge *bridgeForWidget(const QWidget *);
210 static KWQKHTMLPart *partForWidget(const QWidget *);
212 QString requestedURLString() const;
213 QString incomingReferrer() const;
214 QString userAgent() const;
216 QString mimeTypeForFileName(const QString &) const;
218 DOM::NodeImpl *selectionStart() const;
219 int selectionStartOffset() const;
220 DOM::NodeImpl *selectionEnd() const;
221 int selectionEndOffset() const;
223 QRect selectionRect() const;
224 NSRect visibleSelectionRect() const;
225 NSImage *selectionImage() const;
226 NSImage *snapshotDragImage(DOM::Node node, NSRect *imageRect, NSRect *elementRect) const;
228 NSFont *fontForCurrentPosition() const;
229 void markMisspellingsInSelection(const DOM::Selection &selection);
230 void updateSpellChecking();
232 NSFileWrapper *fileWrapperForElement(DOM::ElementImpl *);
233 NSAttributedString *attributedString(DOM::NodeImpl *startNode, int startOffset, DOM::NodeImpl *endNode, int endOffset);
235 void addMetaData(const QString &key, const QString &value);
237 void mouseDown(NSEvent *);
238 void mouseDragged(NSEvent *);
239 void mouseUp(NSEvent *);
240 void sendFakeEventsAfterWidgetTracking(NSEvent *initiatingEvent);
241 void mouseMoved(NSEvent *);
242 bool keyEvent(NSEvent *);
243 bool lastEventIsMouseUp();
244 void setActivationEventNumber(int num) { _activationEventNumber = num; }
246 bool eventMayStartDrag(NSEvent *);
247 void dragSourceMovedTo(const QPoint &loc);
248 void dragSourceEndedAt(const QPoint &loc, NSDragOperation operation);
257 bool sendContextMenuEvent(NSEvent *);
260 static void clearTimers(KHTMLView *);
262 bool passSubframeEventToSubframe(DOM::NodeImpl::MouseEvent &);
264 void redirectionTimerStartedOrStopped();
266 static const QPtrList<KWQKHTMLPart> &instances() { return mutableInstances(); }
268 void clearRecordedFormValues();
269 void recordFormValue(const QString &name, const QString &value, DOM::HTMLFormElementImpl *element);
270 DOM::HTMLFormElementImpl *currentForm() const;
272 NSString *searchForLabelsAboveCell(QRegExp *regExp, DOM::HTMLTableCellElementImpl *cell);
273 NSString *searchForLabelsBeforeElement(NSArray *labels, DOM::ElementImpl *element);
274 NSString *matchLabelsAgainstElement(NSArray *labels, DOM::ElementImpl *element);
276 bool findString(NSString *str, bool forward, bool caseFlag, bool wrapFlag);
278 void setSettings(KHTMLSettings *);
280 KWQWindowWidget *topLevelWidget();
282 QString overrideMediaType();
284 void setMediaType(const QString &);
286 void setDisplaysWithFocusAttributes(bool flag);
287 bool displaysWithFocusAttributes() const { return _displaysWithFocusAttributes; }
289 // Convenience, to avoid repeating the code to dig down to get this.
290 QChar backslashAsCurrencySymbol() const;
292 NSColor *bodyBackgroundColor() const;
294 WebCoreKeyboardUIMode keyboardUIMode() const;
296 void setName(const QString &name);
298 void didTellBridgeAboutLoad(const QString &urlString);
299 bool haveToldBridgeAboutLoad(const QString &urlString);
301 KJS::Bindings::Instance *getEmbedInstanceForView (NSView *aView);
302 KJS::Bindings::Instance *getAppletInstanceForView (NSView *aView);
303 void addPluginRootObject(const KJS::Bindings::RootObject *root);
304 void cleanupPluginRootObjects();
306 void registerCommandForUndo(const khtml::EditCommand &);
307 void registerCommandForRedo(const khtml::EditCommand &);
308 void clearUndoRedoOperations();
309 void issueUndoCommand();
310 void issueRedoCommand();
311 void issueCutCommand();
312 void issueCopyCommand();
313 void issuePasteCommand();
314 void respondToChangedSelection();
315 void respondToChangedContents();
316 bool isContentEditable() const;
317 bool shouldBeginEditing(const DOM::Range &) const;
318 bool shouldEndEditing(const DOM::Range &) const;
320 KJS::Bindings::RootObject *bindingRootObject();
322 WebScriptObject *windowScriptObject();
323 NPObject *KWQKHTMLPart::windowScriptNPObject();
325 void partClearedInBegin();
327 // Implementation of CSS property -khtml-user-drag == auto
328 bool shouldDragAutoNode(DOM::NodeImpl*, int x, int y) const;
330 DOM::Range markedRange() const;
331 void setMarkedRange(const DOM::Range &);
333 virtual void khtmlMousePressEvent(khtml::MousePressEvent *);
334 virtual void khtmlMouseDoubleClickEvent(khtml::MouseDoubleClickEvent *);
335 virtual void khtmlMouseMoveEvent(khtml::MouseMoveEvent *);
336 virtual void khtmlMouseReleaseEvent(khtml::MouseReleaseEvent *);
338 bool passWidgetMouseDownEventToWidget(khtml::MouseEvent *);
339 bool passWidgetMouseDownEventToWidget(khtml::RenderWidget *);
340 bool passWidgetMouseDownEventToWidget(QWidget *);
342 void setPolicyBaseURL(const DOM::DOMString &);
344 NSView *mouseDownViewIfStillGood();
346 QString generateFrameName();
348 NSView *nextKeyViewInFrame(DOM::NodeImpl *startingPoint, KWQSelectionDirection);
349 static DOM::NodeImpl *nodeForWidget(const QWidget *);
350 static KWQKHTMLPart *partForNode(DOM::NodeImpl *);
351 static NSView *documentViewForNode(DOM::NodeImpl *);
353 bool dragHysteresisExceeded(float dragLocationX, float dragLocationY) const;
354 bool dispatchCPPEvent(int eventId, KWQClipboard::AccessPolicy policy);
355 bool dispatchDragSrcEvent(int eventId, const QPoint &loc) const;
357 NSImage *imageFromRect(NSRect rect) const;
359 void freeClipboard();
361 WebCoreBridge *_bridge;
364 KWQSignal _completed;
365 KWQSignal _completedWithBool;
367 NSView *_mouseDownView;
368 bool _mouseDownWasInSubframe;
369 bool _sendingEventToSubview;
370 bool _mouseDownMayStartDrag;
371 bool _mouseDownMayStartSelect;
372 // in our window's coords
373 int _mouseDownWinX, _mouseDownWinY;
374 // in our view's coords
375 int _mouseDownX, _mouseDownY;
376 float _mouseDownTimestamp;
377 int _activationEventNumber;
379 static NSEvent *_currentEvent;
380 static NSResponder *_firstResponderAtMouseDownTime;
382 KURL _submittedFormURL;
384 NSMutableDictionary *_formValuesAboutToBeSubmitted;
385 ObjCDOMElement *_formAboutToBeSubmitted;
387 static QPtrList<KWQKHTMLPart> &mutableInstances();
389 KWQWindowWidget *_windowWidget;
391 bool _displaysWithFocusAttributes;
392 mutable bool _drawSelectionOnly;
393 bool _haveUndoRedoOperations;
395 QDict<char> urlsBridgeKnowsAbout;
397 friend class KHTMLPart;
399 KJS::Bindings::RootObject *_bindingRoot; // The root object used for objects
400 // bound outside the context of a plugin.
401 QPtrList<KJS::Bindings::RootObject> rootObjects;
402 WebScriptObject *_windowScriptObject;
403 NPObject *_windowScriptNPObject;
405 DOM::Node _dragSrc; // element that may be a drag source, for the current mouse gesture
407 bool _dragSrcIsImage;
408 bool _dragSrcInSelection;
409 bool _dragSrcMayBeDHTML, _dragSrcMayBeUA; // Are DHTML and/or the UserAgent allowed to drag out?
410 bool _dragSrcIsDHTML;
411 KWQClipboard *_dragClipboard; // used on only the source side of dragging
413 mutable DOM::Node _elementToDraw;
415 DOM::Range m_markedRange;
418 inline KWQKHTMLPart *KWQ(KHTMLPart *part) { return static_cast<KWQKHTMLPart *>(part); }
419 inline const KWQKHTMLPart *KWQ(const KHTMLPart *part) { return static_cast<const KWQKHTMLPart *>(part); }