2 * Copyright (C) 2004, 2005, 2006 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.
31 #include "ClipboardMac.h"
32 #include "KWQScrollBar.h"
33 #include "PlatformMouseEvent.h"
35 #include "WebCoreKeyboardAccess.h"
36 #include "TextAffinity.h"
37 #include <kxmlcore/HashSet.h>
39 #import <CoreFoundation/CoreFoundation.h>
45 class SavedProperties;
47 class ScheduledAction;
56 // Avoid clashes with KJS::DOMElement in KHTML code.
58 typedef DOMElement ObjCDOMElement;
62 @class NSAttributedString;
69 @class NSMutableDictionary;
73 @class WebCoreFrameBridge;
74 @class WebScriptObject;
78 // Avoid clashes with KJS::DOMElement in KHTML code.
83 class NSAttributedString;
90 class NSMutableDictionary;
94 class WebCoreFrameBridge;
95 class WebScriptObject;
97 typedef int NSWritingDirection;
103 class DocumentFragment;
105 class HTMLTableCellElement;
108 class VisiblePosition;
110 struct DashboardRegionValue;
112 enum KWQSelectionDirection {
117 class FrameMac : public Frame
120 FrameMac(Page*, RenderPart*);
125 void setBridge(WebCoreFrameBridge* p);
126 WebCoreFrameBridge* bridge() const { return _bridge; }
127 virtual void setView(FrameView*);
128 virtual void frameDetached();
130 virtual bool openURL(const KURL&);
132 virtual void openURLRequest(const ResourceRequest&);
133 virtual void submitForm(const ResourceRequest&);
135 String advanceToNextMisspelling(bool startBeforeSelection = false);
137 virtual void setTitle(const String&);
138 virtual void setStatusBarText(const String&);
140 virtual void urlSelected(const ResourceRequest&);
142 virtual ObjectContentType objectContentType(const KURL& url, const String& mimeType);
143 virtual Plugin* createPlugin(const KURL& url, const Vector<String>& paramNames, const Vector<String>& paramValues, const String& mimeType);
144 virtual Frame* createFrame(const KURL& url, const String& name, RenderPart* renderer, const String& referrer);
146 virtual void scheduleClose();
148 virtual void unfocusWindow();
150 void openURLFromPageCache(KWQPageState* state);
152 virtual void saveDocumentState();
153 virtual void restoreDocumentState();
155 virtual void addMessageToConsole(const String& message, unsigned int lineNumber, const String& sourceID);
156 virtual void setDisplaysWithFocusAttributes(bool flag);
158 NSView* nextKeyView(Node* startingPoint, KWQSelectionDirection);
159 NSView* nextKeyViewInFrameHierarchy(Node* startingPoint, KWQSelectionDirection);
160 static NSView* nextKeyViewForWidget(Widget* startingPoint, KWQSelectionDirection);
161 static bool currentEventIsKeyboardOptionTab();
162 static bool handleKeyboardOptionTabInView(NSView* view);
164 virtual bool tabsToLinks() const;
165 virtual bool tabsToAllControls() const;
167 static bool currentEventIsMouseDownInWidget(Widget* candidate);
169 virtual void runJavaScriptAlert(const String& message);
170 virtual bool runJavaScriptConfirm(const String& message);
171 virtual bool runJavaScriptPrompt(const String& message, const String& defaultValue, String& result);
172 virtual bool locationbarVisible();
173 virtual bool menubarVisible();
174 virtual bool personalbarVisible();
175 virtual bool statusbarVisible();
176 virtual bool toolbarVisible();
180 virtual void createEmptyDocument();
182 static WebCoreFrameBridge* bridgeForWidget(const Widget*);
184 virtual String incomingReferrer() const;
185 virtual String userAgent() const;
187 virtual String mimeTypeForFileName(const String&) const;
189 NSImage* selectionImage() const;
190 NSImage* snapshotDragImage(Node* node, NSRect* imageRect, NSRect* elementRect) const;
192 bool dispatchDragSrcEvent(const AtomicString &eventType, const PlatformMouseEvent&) const;
194 NSFont* fontForSelection(bool* hasMultipleFonts) const;
195 NSDictionary* fontAttributesForSelectionStart() const;
197 NSWritingDirection baseWritingDirectionForSelectionStart() const;
199 virtual void markMisspellingsInAdjacentWords(const VisiblePosition&);
200 virtual void markMisspellings(const SelectionController&);
202 NSFileWrapper* fileWrapperForElement(Element*);
203 NSAttributedString* attributedString(Node* startNode, int startOffset, Node* endNode, int endOffset);
205 void mouseDown(NSEvent*);
206 void mouseDragged(NSEvent*);
207 void mouseUp(NSEvent*);
208 void mouseMoved(NSEvent*);
209 bool keyEvent(NSEvent*);
210 bool wheelEvent(NSEvent*);
212 void sendFakeEventsAfterWidgetTracking(NSEvent* initiatingEvent);
214 virtual bool lastEventIsMouseUp() const;
215 void setActivationEventNumber(int num) { _activationEventNumber = num; }
217 bool dragHysteresisExceeded(float dragLocationX, float dragLocationY) const;
218 bool eventMayStartDrag(NSEvent*) const;
219 void dragSourceMovedTo(const PlatformMouseEvent&);
220 void dragSourceEndedAt(const PlatformMouseEvent&, NSDragOperation);
229 bool sendContextMenuEvent(NSEvent*);
231 virtual bool passMouseDownEventToWidget(Widget*);
232 virtual bool passSubframeEventToSubframe(MouseEventWithHitTestResults&, Frame* subframePart);
233 virtual bool passWheelEventToChildWidget(Node*);
235 NSString* searchForLabelsAboveCell(RegularExpression* regExp, HTMLTableCellElement* cell);
236 NSString* searchForLabelsBeforeElement(NSArray* labels, Element* element);
237 NSString* matchLabelsAgainstElement(NSArray* labels, Element* element);
239 bool findString(NSString* str, bool forward, bool caseFlag, bool wrapFlag);
241 virtual void tokenizerProcessedData();
243 virtual String overrideMediaType() const;
245 NSColor* bodyBackgroundColor() const;
247 WebCoreKeyboardUIMode keyboardUIMode() const;
249 void didTellBridgeAboutLoad(const String& URL);
250 bool haveToldBridgeAboutLoad(const String& URL);
252 virtual KJS::Bindings::Instance* getEmbedInstanceForWidget(Widget*);
253 virtual KJS::Bindings::Instance* getObjectInstanceForWidget(Widget*);
254 virtual KJS::Bindings::Instance* getAppletInstanceForWidget(Widget*);
255 void addPluginRootObject(const KJS::Bindings::RootObject* root);
256 void cleanupPluginRootObjects();
258 virtual void registerCommandForUndo(const EditCommandPtr&);
259 virtual void registerCommandForRedo(const EditCommandPtr&);
260 virtual void clearUndoRedoOperations();
261 virtual void issueUndoCommand();
262 virtual void issueRedoCommand();
263 virtual void issueCutCommand();
264 virtual void issueCopyCommand();
265 virtual void issuePasteCommand();
266 virtual void issuePasteAndMatchStyleCommand();
267 virtual void issueTransposeCommand();
268 virtual void respondToChangedSelection(const SelectionController &oldSelection, bool closeTyping);
269 virtual void respondToChangedContents();
270 virtual bool isContentEditable() const;
271 virtual bool shouldChangeSelection(const SelectionController &oldSelection, const SelectionController &newSelection, EAffinity affinity, bool stillSelecting) const;
272 virtual bool shouldBeginEditing(const Range*) const;
273 virtual bool shouldEndEditing(const Range*) const;
274 virtual void didBeginEditing() const;
275 virtual void didEndEditing() const;
277 KJS::Bindings::RootObject* executionContextForDOM();
278 KJS::Bindings::RootObject* bindingRootObject();
280 WebScriptObject* windowScriptObject();
281 NPObject* windowScriptNPObject();
283 virtual void partClearedInBegin();
285 // Implementation of CSS property -khtml-user-drag == auto
286 virtual bool shouldDragAutoNode(Node*, int x, int y) const;
288 void setMarkedTextRange(const Range* , NSArray* attributes, NSArray* ranges);
289 virtual Range* markedTextRange() const { return m_markedTextRange.get(); }
291 virtual bool canGoBackOrForward(int distance) const;
293 virtual void didFirstLayout();
295 NSMutableDictionary* dashboardRegionsDictionary();
296 void dashboardRegionsChanged();
298 virtual bool isCharacterSmartReplaceExempt(const QChar &, bool);
300 virtual bool mouseDownMayStartSelect() const { return _mouseDownMayStartSelect; }
302 virtual void handledOnloadEvents();
304 virtual bool canPaste() const;
305 virtual bool canRedo() const;
306 virtual bool canUndo() const;
307 virtual void print();
310 virtual void startRedirectionTimer();
311 virtual void stopRedirectionTimer();
312 virtual void redirectionTimerFired(Timer<Frame>*);
315 virtual void handleMousePressEvent(const MouseEventWithHitTestResults&);
316 virtual void handleMouseMoveEvent(const MouseEventWithHitTestResults&);
317 virtual void handleMouseReleaseEvent(const MouseEventWithHitTestResults&);
319 NSView* mouseDownViewIfStillGood();
321 NSView* nextKeyViewInFrame(Node* startingPoint, KWQSelectionDirection);
322 static NSView* documentViewForNode(Node*);
324 bool dispatchCPPEvent(const AtomicString &eventType, ClipboardMac::AccessPolicy policy);
326 NSImage* imageFromRect(NSRect rect) const;
328 void freeClipboard();
330 void registerCommandForUndoOrRedo(const EditCommandPtr &cmd, bool isRedo);
332 virtual void detachFromView();
334 WebCoreFrameBridge* _bridge;
336 NSView* _mouseDownView;
337 bool _mouseDownWasInSubframe;
338 bool _sendingEventToSubview;
339 bool _mouseDownMayStartDrag;
340 bool _mouseDownMayStartSelect;
341 PlatformMouseEvent m_mouseDown;
342 // in our view's coords
343 int _mouseDownX, _mouseDownY;
344 float _mouseDownTimestamp;
345 int _activationEventNumber;
347 static NSEvent* _currentEvent;
349 NSMutableDictionary* _formValuesAboutToBeSubmitted;
350 ObjCDOMElement* _formAboutToBeSubmitted;
352 bool _haveUndoRedoOperations;
354 HashSet<RefPtr<StringImpl> > urlsBridgeKnowsAbout;
358 KJS::Bindings::RootObject* _bindingRoot; // The root object used for objects
359 // bound outside the context of a plugin.
360 DeprecatedPtrList<KJS::Bindings::RootObject> rootObjects;
361 WebScriptObject* _windowScriptObject;
362 NPObject* _windowScriptNPObject;
364 RefPtr<Node> _dragSrc; // element that may be a drag source, for the current mouse gesture
366 bool _dragSrcIsImage;
367 bool _dragSrcInSelection;
368 bool _dragSrcMayBeDHTML, _dragSrcMayBeUA; // Are DHTML and/or the UserAgent allowed to drag out?
369 bool _dragSrcIsDHTML;
370 RefPtr<ClipboardMac> _dragClipboard; // used on only the source side of dragging
372 RefPtr<Range> m_markedTextRange;
375 inline FrameMac* Mac(Frame* frame) { return static_cast<FrameMac*>(frame); }
376 inline const FrameMac* Mac(const Frame* frame) { return static_cast<const FrameMac*>(frame); }