2 * Copyright (C) 2004 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 #import "khtml_part.h"
31 #import "dom_nodeimpl.h"
32 #import "dom2_range.h"
34 #import "WebCoreKeyboardAccess.h"
36 #import <CoreFoundation/CoreFoundation.h>
38 #import <JavaScriptCore/jni_jsobject.h>
39 #import <JavaScriptCore/npruntime.h>
40 #import <JavaScriptCore/NP_jsobject.h>
41 #import <JavaScriptCore/runtime.h>
44 #import "KWQClipboard.h"
45 #import "KWQScrollBar.h"
47 class KHTMLPartPrivate;
48 class KWQWindowWidget;
51 class DocumentFragmentImpl;
52 class HTMLTableCellElementImpl;
58 class VisiblePosition;
59 struct DashboardRegionValue;
63 class SavedProperties;
65 class ScheduledAction;
70 // Avoid clashes with KJS::DOMElement in KHTML code.
72 typedef DOMElement ObjCDOMElement;
76 @class NSAttributedString;
83 @class NSMutableDictionary;
88 @class WebScriptObject;
92 // Avoid clashes with KJS::DOMElement in KHTML code.
97 class NSAttributedString;
104 class NSMutableDictionary;
109 class WebScriptObject;
113 enum KWQSelectionDirection {
118 class KWQKHTMLPart : public KHTMLPart
126 void setBridge(WebCoreBridge *p);
127 WebCoreBridge *bridge() const { return _bridge; }
128 void setView(KHTMLView *view);
129 KHTMLView *view() const;
131 void provisionalLoadStarted();
133 virtual bool openURL(const KURL &);
134 virtual bool closeURL();
135 void didNotOpenURL(const KURL &);
137 void openURLRequest(const KURL &, const KParts::URLArgs &);
138 void submitForm(const KURL &, const KParts::URLArgs &);
140 void scheduleHistoryNavigation( int steps );
142 void scrollToAnchor(const KURL &);
143 void jumpToSelection();
144 QString advanceToNextMisspelling(bool startBeforeSelection = false);
145 bool scrollOverflow(KWQScrollDirection direction, KWQScrollGranularity granularity);
146 bool scrollOverflowWithScrollWheelEvent(NSEvent *event);
148 void setEncoding(const QString &encoding, bool userChosen);
149 void addData(const char *bytes, int length);
151 void setTitle(const DOM::DOMString &);
152 void setStatusBarText(const QString &status);
154 void urlSelected(const KURL &url, int button, int state, const KParts::URLArgs &args);
155 KParts::ReadOnlyPart *createPart(const khtml::ChildFrame &child, const KURL &url, const QString &mimeType);
157 void scheduleClose();
159 void unfocusWindow();
161 QMap<int, KJS::ScheduledAction*> *pauseActions(const void *key);
162 void resumeActions(QMap<int, KJS::ScheduledAction*> *actions, const void *key);
165 void saveWindowProperties(KJS::SavedProperties *windowProperties);
166 void saveLocationProperties(KJS::SavedProperties *locationProperties);
167 void restoreWindowProperties(KJS::SavedProperties *windowProperties);
168 void restoreLocationProperties(KJS::SavedProperties *locationProperties);
169 void saveInterpreterBuiltins(KJS::SavedBuiltins &interpreterBuiltins);
170 void restoreInterpreterBuiltins(const KJS::SavedBuiltins &interpreterBuiltins);
172 void openURLFromPageCache(KWQPageState *state);
174 void saveDocumentState();
175 void restoreDocumentState();
177 bool isFrameSet() const;
179 void updatePolicyBaseURL();
181 NSView *nextKeyView(DOM::NodeImpl *startingPoint, KWQSelectionDirection);
182 NSView *nextKeyViewInFrameHierarchy(DOM::NodeImpl *startingPoint, KWQSelectionDirection);
183 static NSView *nextKeyViewForWidget(QWidget *startingPoint, KWQSelectionDirection);
184 static bool currentEventIsKeyboardOptionTab();
185 static bool handleKeyboardOptionTabInView(NSView *view);
187 virtual bool tabsToLinks() const;
188 virtual bool tabsToAllControls() const;
190 static bool currentEventIsMouseDownInWidget(QWidget *candidate);
192 static void setDocumentFocus(QWidget *);
193 static void clearDocumentFocus(QWidget *);
195 void runJavaScriptAlert(const QString &message);
196 bool runJavaScriptConfirm(const QString &message);
197 bool runJavaScriptPrompt(const QString &message, const QString &defaultValue, QString &result);
198 bool locationbarVisible();
199 bool menubarVisible();
200 bool personalbarVisible();
201 bool scrollbarsVisible();
202 bool statusbarVisible();
203 bool toolbarVisible();
205 void KWQKHTMLPart::addMessageToConsole(const QString &message, unsigned int lineNumber, const QString &sourceID);
206 using KHTMLPart::xmlDocImpl;
207 khtml::RenderObject *renderer() const;
209 void forceLayoutWithPageWidthRange(float minPageWidth, float maxPageWidth);
210 void sendResizeEvent();
211 void sendScrollEvent();
212 void paint(QPainter *, const QRect &);
214 void adjustPageHeight(float *newBottom, float oldTop, float oldBottom, float bottomLimit);
216 void createEmptyDocument();
218 static WebCoreBridge *bridgeForWidget(const QWidget *);
219 static KWQKHTMLPart *partForWidget(const QWidget *);
221 QString requestedURLString() const;
222 QString incomingReferrer() const;
223 QString userAgent() const;
225 QString mimeTypeForFileName(const QString &) const;
227 DOM::NodeImpl *selectionStart() const;
228 int selectionStartOffset() const;
229 DOM::NodeImpl *selectionEnd() const;
230 int selectionEndOffset() const;
232 QRect selectionRect() const;
233 NSRect visibleSelectionRect() const;
234 void centerSelectionInVisibleArea() const;
235 NSImage *selectionImage() const;
236 NSImage *snapshotDragImage(DOM::Node node, NSRect *imageRect, NSRect *elementRect) const;
238 NSFont *fontForSelection(bool *hasMultipleFonts) const;
239 NSDictionary *fontAttributesForSelectionStart() const;
241 void markMisspellingsInAdjacentWords(const khtml::VisiblePosition &);
242 void markMisspellings(const khtml::Selection &);
244 NSFileWrapper *fileWrapperForElement(DOM::ElementImpl *);
245 NSAttributedString *attributedString(DOM::NodeImpl *startNode, int startOffset, DOM::NodeImpl *endNode, int endOffset);
247 void addMetaData(const QString &key, const QString &value);
249 void mouseDown(NSEvent *);
250 void mouseDragged(NSEvent *);
251 void mouseUp(NSEvent *);
252 void sendFakeEventsAfterWidgetTracking(NSEvent *initiatingEvent);
253 void mouseMoved(NSEvent *);
254 bool keyEvent(NSEvent *);
256 bool lastEventIsMouseUp() const;
257 void setActivationEventNumber(int num) { _activationEventNumber = num; }
259 bool eventMayStartDrag(NSEvent *) const;
260 void dragSourceMovedTo(const QPoint &loc);
261 void dragSourceEndedAt(const QPoint &loc, NSDragOperation operation);
270 bool sendContextMenuEvent(NSEvent *);
272 // Call this method before handling a new user action, like on a mouse down or key down.
273 // Currently, all this does is clear the "don't submit form twice" data member.
274 void prepareForUserAction();
277 static void clearTimers(KHTMLView *);
279 bool passSubframeEventToSubframe(DOM::NodeImpl::MouseEvent &);
281 void redirectionTimerStartedOrStopped();
283 static const QPtrList<KWQKHTMLPart> &instances() { return mutableInstances(); }
285 void clearRecordedFormValues();
286 void recordFormValue(const QString &name, const QString &value, DOM::HTMLFormElementImpl *element);
287 DOM::HTMLFormElementImpl *currentForm() const;
289 NSString *searchForLabelsAboveCell(QRegExp *regExp, DOM::HTMLTableCellElementImpl *cell);
290 NSString *searchForLabelsBeforeElement(NSArray *labels, DOM::ElementImpl *element);
291 NSString *matchLabelsAgainstElement(NSArray *labels, DOM::ElementImpl *element);
293 bool findString(NSString *str, bool forward, bool caseFlag, bool wrapFlag);
295 void setSettings(KHTMLSettings *);
297 KWQWindowWidget *topLevelWidget();
299 void tokenizerProcessedData();
301 QString overrideMediaType() const;
303 void setMediaType(const QString &);
305 void setSelectionFromNone();
306 void setDisplaysWithFocusAttributes(bool flag);
307 bool displaysWithFocusAttributes() const;
309 // Convenience, to avoid repeating the code to dig down to get this.
310 QChar backslashAsCurrencySymbol() const;
312 NSColor *bodyBackgroundColor() const;
314 WebCoreKeyboardUIMode keyboardUIMode() const;
316 void setName(const QString &name);
318 void didTellBridgeAboutLoad(const QString &urlString);
319 bool haveToldBridgeAboutLoad(const QString &urlString);
321 KJS::Bindings::Instance *getEmbedInstanceForView(NSView *aView);
322 KJS::Bindings::Instance *getAppletInstanceForView(NSView *aView);
323 void addPluginRootObject(const KJS::Bindings::RootObject *root);
324 void cleanupPluginRootObjects();
326 void registerCommandForUndo(const khtml::EditCommandPtr &);
327 void registerCommandForRedo(const khtml::EditCommandPtr &);
328 void clearUndoRedoOperations();
329 void issueUndoCommand();
330 void issueRedoCommand();
331 void issueCutCommand();
332 void issueCopyCommand();
333 void issuePasteCommand();
334 void respondToChangedSelection(const khtml::Selection &oldSelection, bool closeTyping);
335 void respondToChangedContents();
336 virtual bool isContentEditable() const;
337 virtual bool shouldBeginEditing(const DOM::Range &) const;
338 virtual bool shouldEndEditing(const DOM::Range &) const;
340 KJS::Bindings::RootObject *executionContextForDOM();
341 KJS::Bindings::RootObject *bindingRootObject();
343 WebScriptObject *windowScriptObject();
344 NPObject *KWQKHTMLPart::windowScriptNPObject();
346 void partClearedInBegin();
348 // Implementation of CSS property -khtml-user-drag == auto
349 bool shouldDragAutoNode(DOM::NodeImpl*, int x, int y) const;
351 struct MarkedTextUnderline {
352 MarkedTextUnderline(unsigned _startOffset, unsigned _endOffset, const QColor &_color, bool _thick)
353 : startOffset(_startOffset)
354 , endOffset(_endOffset)
358 unsigned startOffset;
364 void setMarkedTextRange(const DOM::Range &, NSArray *attributes, NSArray *ranges);
365 DOM::Range markedTextRange() const;
366 bool markedTextUsesUnderlines() const;
367 QValueList<MarkedTextUnderline> markedTextUnderlines() const;
369 bool canGoBackOrForward(int distance) const;
371 void didFirstLayout();
373 NSMutableDictionary *dashboardRegionsDictionary();
374 void dashboardRegionsChanged();
376 virtual bool isCharacterSmartReplaceExempt(const QChar &, bool);
379 virtual void khtmlMousePressEvent(khtml::MousePressEvent *);
380 virtual void khtmlMouseDoubleClickEvent(khtml::MouseDoubleClickEvent *);
381 virtual void khtmlMouseMoveEvent(khtml::MouseMoveEvent *);
382 virtual void khtmlMouseReleaseEvent(khtml::MouseReleaseEvent *);
384 bool passWidgetMouseDownEventToWidget(khtml::MouseEvent *);
385 bool passWidgetMouseDownEventToWidget(khtml::RenderWidget *);
386 bool passWidgetMouseDownEventToWidget(QWidget *);
388 void setPolicyBaseURL(const DOM::DOMString &);
390 NSView *mouseDownViewIfStillGood();
392 QString generateFrameName();
394 NSView *nextKeyViewInFrame(DOM::NodeImpl *startingPoint, KWQSelectionDirection);
395 static DOM::NodeImpl *nodeForWidget(const QWidget *);
396 static KWQKHTMLPart *partForNode(DOM::NodeImpl *);
397 static NSView *documentViewForNode(DOM::NodeImpl *);
399 bool dragHysteresisExceeded(float dragLocationX, float dragLocationY) const;
400 bool dispatchCPPEvent(int eventId, KWQClipboard::AccessPolicy policy);
401 bool dispatchDragSrcEvent(int eventId, const QPoint &loc) const;
403 NSImage *imageFromRect(NSRect rect) const;
405 void freeClipboard();
407 khtml::RenderStyle *styleForSelectionStart(DOM::NodeImpl *&nodeToRemove) const;
409 virtual bool isKHTMLPart() const;
411 void registerCommandForUndoOrRedo(const khtml::EditCommandPtr &cmd, bool isRedo);
413 WebCoreBridge *_bridge;
416 KWQSignal _completed;
417 KWQSignal _completedWithBool;
419 NSView *_mouseDownView;
420 bool _mouseDownWasInSubframe;
421 bool _sendingEventToSubview;
422 bool _mouseDownMayStartDrag;
423 bool _mouseDownMayStartSelect;
424 // in our window's coords
425 int _mouseDownWinX, _mouseDownWinY;
426 // in our view's coords
427 int _mouseDownX, _mouseDownY;
428 float _mouseDownTimestamp;
429 int _activationEventNumber;
431 static NSEvent *_currentEvent;
433 KURL _submittedFormURL;
435 NSMutableDictionary *_formValuesAboutToBeSubmitted;
436 ObjCDOMElement *_formAboutToBeSubmitted;
438 static QPtrList<KWQKHTMLPart> &mutableInstances();
440 KWQWindowWidget *_windowWidget;
442 mutable bool _drawSelectionOnly;
443 bool _haveUndoRedoOperations;
445 QDict<char> urlsBridgeKnowsAbout;
447 friend class KHTMLPart;
449 KJS::Bindings::RootObject *_bindingRoot; // The root object used for objects
450 // bound outside the context of a plugin.
451 QPtrList<KJS::Bindings::RootObject> rootObjects;
452 WebScriptObject *_windowScriptObject;
453 NPObject *_windowScriptNPObject;
455 DOM::Node _dragSrc; // element that may be a drag source, for the current mouse gesture
457 bool _dragSrcIsImage;
458 bool _dragSrcInSelection;
459 bool _dragSrcMayBeDHTML, _dragSrcMayBeUA; // Are DHTML and/or the UserAgent allowed to drag out?
460 bool _dragSrcIsDHTML;
461 KWQClipboard *_dragClipboard; // used on only the source side of dragging
463 mutable DOM::Node _elementToDraw;
465 DOM::Range m_markedTextRange;
466 bool m_markedTextUsesUnderlines;
467 QValueList<MarkedTextUnderline> m_markedTextUnderlines;
470 inline KWQKHTMLPart *KWQ(KHTMLPart *part) { return static_cast<KWQKHTMLPart *>(part); }
471 inline const KWQKHTMLPart *KWQ(const KHTMLPart *part) { return static_cast<const KWQKHTMLPart *>(part); }