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.
29 #import "ClipboardAccessPolicy.h"
31 #import "PlatformMouseEvent.h"
32 #import "WebCoreKeyboardAccess.h"
51 @class NSMutableDictionary;
54 @class WebCoreFrameBridge;
55 @class WebScriptObject;
65 class NSMutableDictionary;
68 class WebCoreFrameBridge;
69 class WebScriptObject;
71 typedef unsigned int NSDragOperation;
72 typedef int NSWritingDirection;
79 class HTMLTableCellElement;
82 enum SelectionDirection {
87 class FrameMac : public Frame {
91 FrameMac(Page*, Element*, PassRefPtr<EditorClient>);
94 void setBridge(WebCoreFrameBridge*);
95 WebCoreFrameBridge* bridge() const { return _bridge; }
98 WebCoreFrameBridge* _bridge;
100 // === undecided, may or may not belong here
103 virtual void setView(FrameView*);
105 static WebCoreFrameBridge* bridgeForWidget(const Widget*);
107 NSString* searchForLabelsAboveCell(RegularExpression*, HTMLTableCellElement*);
108 NSString* searchForLabelsBeforeElement(NSArray* labels, Element*);
109 NSString* matchLabelsAgainstElement(NSArray* labels, Element*);
111 virtual KJS::Bindings::Instance* getEmbedInstanceForWidget(Widget*);
112 virtual KJS::Bindings::Instance* getObjectInstanceForWidget(Widget*);
113 virtual KJS::Bindings::Instance* getAppletInstanceForWidget(Widget*);
114 virtual KJS::Bindings::RootObject* bindingRootObject();
116 void addPluginRootObject(KJS::Bindings::RootObject*);
118 KJS::Bindings::RootObject* executionContextForDOM();
120 WebScriptObject* windowScriptObject();
121 NPObject* windowScriptNPObject();
123 NSMutableDictionary* dashboardRegionsDictionary();
124 void dashboardRegionsChanged();
126 void willPopupMenu(NSMenu *);
128 void cleanupPluginObjects();
132 KJS::Bindings::RootObject* _bindingRoot; // The root object used for objects bound outside the context of a plugin.
133 Vector<KJS::Bindings::RootObject*> m_rootObjects;
134 WebScriptObject* _windowScriptObject;
135 NPObject* _windowScriptNPObject;
137 // === to be moved into Chrome
140 virtual void setStatusBarText(const String&);
142 virtual void focusWindow();
143 virtual void unfocusWindow();
145 virtual void addMessageToConsole(const String& message, unsigned int lineNumber, const String& sourceID);
147 virtual void runJavaScriptAlert(const String&);
148 virtual bool runJavaScriptConfirm(const String&);
149 virtual bool runJavaScriptPrompt(const String& message, const String& defaultValue, String& result);
150 virtual bool shouldInterruptJavaScript();
152 FloatRect customHighlightLineRect(const AtomicString& type, const FloatRect& lineRect);
153 void paintCustomHighlight(const AtomicString& type, const FloatRect& boxRect, const FloatRect& lineRect, bool text, bool line);
155 virtual void print();
157 virtual void scheduleClose();
159 // === to be moved into Editor
162 void advanceToNextMisspelling(bool startBeforeSelection = false);
164 NSFont* fontForSelection(bool* hasMultipleFonts) const;
165 NSDictionary* fontAttributesForSelectionStart() const;
167 NSWritingDirection baseWritingDirectionForSelectionStart() const;
169 virtual void markMisspellingsInAdjacentWords(const VisiblePosition&);
170 virtual void markMisspellings(const Selection&);
172 virtual bool canRedo() const;
173 virtual bool canUndo() const;
177 bool canDHTMLPaste();
180 bool tryDHTMLPaste();
182 virtual void registerCommandForUndo(PassRefPtr<EditCommand>);
183 virtual void registerCommandForRedo(PassRefPtr<EditCommand>);
184 virtual void clearUndoRedoOperations();
185 virtual void issueUndoCommand();
186 virtual void issueRedoCommand();
187 virtual void issueCutCommand();
188 virtual void issueCopyCommand();
189 virtual void issuePasteCommand();
190 virtual void issuePasteAndMatchStyleCommand();
191 virtual void issueTransposeCommand();
192 virtual void respondToChangedSelection(const Selection& oldSelection, bool closeTyping);
193 virtual void respondToChangedContents(const Selection&);
194 virtual bool isContentEditable() const;
195 virtual bool shouldChangeSelection(const Selection& oldSelection, const Selection& newSelection, EAffinity affinity, bool stillSelecting) const;
196 virtual bool shouldDeleteSelection(const Selection&) const;
198 virtual void setSecureKeyboardEntry(bool);
199 virtual bool isSecureKeyboardEntry();
201 void setMarkedTextRange(const Range* , NSArray* attributes, NSArray* ranges);
202 virtual Range* markedTextRange() const { return m_markedTextRange.get(); }
204 virtual void textFieldDidBeginEditing(Element*);
205 virtual void textFieldDidEndEditing(Element*);
206 virtual void textDidChangeInTextField(Element*);
207 virtual bool doTextFieldCommandFromEvent(Element*, KeyboardEvent*);
208 virtual void textWillBeDeletedInTextField(Element*);
209 virtual void textDidChangeInTextArea(Element*);
212 bool dispatchCPPEvent(const AtomicString& eventType, ClipboardAccessPolicy);
214 void freeClipboard();
216 void registerCommandForUndoOrRedo(PassRefPtr<EditCommand>, bool isRedo);
218 bool _haveUndoRedoOperations;
219 RefPtr<Range> m_markedTextRange;
221 // === to be moved into EventHandler
224 NSView* nextKeyView(Node* startingPoint, SelectionDirection);
225 NSView* nextKeyViewInFrameHierarchy(Node* startingPoint, SelectionDirection);
226 static NSView* nextKeyViewForWidget(Widget* startingPoint, SelectionDirection);
228 PassRefPtr<KeyboardEvent> currentKeyboardEvent() const;
230 virtual bool tabsToLinks(KeyboardEvent*) const;
231 virtual bool tabsToAllControls(KeyboardEvent*) const;
233 static bool currentEventIsMouseDownInWidget(Widget* candidate);
235 NSImage* selectionImage(bool forceWhiteText = false) const;
236 NSImage* snapshotDragImage(Node* node, NSRect* imageRect, NSRect* elementRect) const;
238 bool dispatchDragSrcEvent(const AtomicString &eventType, const PlatformMouseEvent&) const;
240 void mouseDown(NSEvent*);
241 void mouseDragged(NSEvent*);
242 void mouseUp(NSEvent*);
243 void mouseMoved(NSEvent*);
244 bool keyEvent(NSEvent*);
245 bool wheelEvent(NSEvent*);
247 void sendFakeEventsAfterWidgetTracking(NSEvent* initiatingEvent);
249 virtual bool lastEventIsMouseUp() const;
250 void setActivationEventNumber(int num) { _activationEventNumber = num; }
252 bool dragHysteresisExceeded(float dragLocationX, float dragLocationY) const;
253 bool eventMayStartDrag(NSEvent*) const;
254 void dragSourceMovedTo(const PlatformMouseEvent&);
255 void dragSourceEndedAt(const PlatformMouseEvent&, NSDragOperation);
257 bool sendContextMenuEvent(NSEvent*);
259 bool passWidgetMouseDownEventToWidget(const MouseEventWithHitTestResults&);
260 bool passWidgetMouseDownEventToWidget(RenderWidget*);
261 bool passMouseDownEventToWidget(Widget*);
262 bool passSubframeEventToSubframe(MouseEventWithHitTestResults&, Frame* subframePart);
263 bool passWheelEventToWidget(Widget*);
265 WebCoreKeyboardUIMode keyboardUIMode() const;
267 virtual bool inputManagerHasMarkedText() const;
269 virtual bool shouldDragAutoNode(Node*, const IntPoint&) const; // -webkit-user-drag == auto
271 virtual bool mouseDownMayStartSelect() const { return _mouseDownMayStartSelect; }
273 NSEvent* currentEvent() { return _currentEvent; }
276 virtual void handleMousePressEvent(const MouseEventWithHitTestResults&);
277 virtual void handleMouseMoveEvent(const MouseEventWithHitTestResults&);
278 virtual void handleMouseReleaseEvent(const MouseEventWithHitTestResults&);
280 NSView* mouseDownViewIfStillGood();
282 NSView* nextKeyViewInFrame(Node* startingPoint, SelectionDirection, bool* focusCallResultedInViewBeingCreated = 0);
283 static NSView* documentViewForNode(Node*);
285 NSImage* imageFromRect(NSRect) const;
287 NSView* _mouseDownView;
288 bool _mouseDownWasInSubframe;
289 bool _sendingEventToSubview;
290 bool _mouseDownMayStartSelect;
291 PlatformMouseEvent m_mouseDown;
292 // in our view's coords
293 IntPoint m_mouseDownPos;
294 float _mouseDownTimestamp;
295 int _activationEventNumber;
297 static NSEvent* _currentEvent;
299 // === to be moved into the Platform directory
302 virtual String mimeTypeForFileName(const String&) const;
303 virtual bool isCharacterSmartReplaceExempt(UChar, bool);
307 inline FrameMac* Mac(Frame* frame) { return static_cast<FrameMac*>(frame); }
308 inline const FrameMac* Mac(const Frame* frame) { return static_cast<const FrameMac*>(frame); }