]> git.saurik.com Git - iphone-api.git/blob - WebCore/Frame.h
Add support for new WinterBoard Settings features.
[iphone-api.git] / WebCore / Frame.h
1 /*
2 * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
3 * 1999-2001 Lars Knoll <knoll@kde.org>
4 * 1999-2001 Antti Koivisto <koivisto@kde.org>
5 * 2000-2001 Simon Hausmann <hausmann@kde.org>
6 * 2000-2001 Dirk Mueller <mueller@kde.org>
7 * 2000 Stefan Schimanski <1Stein@gmx.de>
8 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
9 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
10 * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
11 *
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Library General Public
14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version.
16 *
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Library General Public License for more details.
21 *
22 * You should have received a copy of the GNU Library General Public License
23 * along with this library; see the file COPYING.LIB. If not, write to
24 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 * Boston, MA 02110-1301, USA.
26 */
27
28 #ifndef Frame_h
29 #define Frame_h
30
31 #include "AnimationController.h"
32 #include "DragImage.h"
33 #include "EditAction.h"
34 #include "Editor.h"
35 #include "EventHandler.h"
36 #include "FrameLoader.h"
37 #include "FrameTree.h"
38 #include "Range.h"
39 #include "RenderLayer.h"
40 #include "ScriptController.h"
41 #include "SelectionController.h"
42 #include "TextGranularity.h"
43
44 #include "Frame.h"
45 #include "KURL.h"
46 #include <GraphicsServices/GSEvent.h>
47
48 #if PLATFORM(WIN)
49 #include "FrameWin.h"
50 #endif
51
52 #ifndef __OBJC__
53 class NSArray;
54 class NSDictionary;
55 class NSMutableDictionary;
56 class NSString;
57 typedef int NSWritingDirection;
58 #endif
59
60 #ifdef __OBJC__
61 @class DOMNode;
62 #else
63 class DOMNode;
64 #endif
65
66 #if PLATFORM(WIN)
67 typedef struct HBITMAP__* HBITMAP;
68 #endif
69
70 namespace WebCore {
71
72 class Editor;
73 class EventHandler;
74 class FrameLoader;
75 class FrameLoaderClient;
76 class FramePrivate;
77 class FrameTree;
78 class HTMLFrameOwnerElement;
79 class HTMLTableCellElement;
80 class ScriptController;
81 class RegularExpression;
82 class RenderLayer;
83 class RenderPart;
84 class Selection;
85 class SelectionController;
86 class Widget;
87
88 #if FRAME_LOADS_USER_STYLESHEET
89 class UserStyleSheetLoader;
90 #endif
91
92 template <typename T> class Timer;
93
94 enum {
95 OverflowScrollNone = 0x0,
96 OverflowScrollLeft = 0x1,
97 OverflowScrollRight = 0x2,
98 OverflowScrollUp = 0x4,
99 OverflowScrollDown = 0x8
100 };
101
102 enum OverflowScrollAction { DoNotPerformOverflowScroll, PerformOverflowScroll };
103 typedef Node* (*NodeQualifier)(HitTestResult aHitTestResult, Node* terminationNode, IntRect* frame);
104
105
106 class Frame : public RefCounted<Frame> {
107 public:
108 static PassRefPtr<Frame> create(Page* page, HTMLFrameOwnerElement* ownerElement, FrameLoaderClient* client)
109 {
110 return adoptRef(new Frame(page, ownerElement, client));
111 }
112 void setView(FrameView*);
113 ~Frame();
114
115 void init();
116 // Creates <html (contentEditable="true")><body style="..."></body></html> doing minimal amount of work
117 void initWithSimpleHTMLDocument(const String& style, bool editable, const KURL& url);
118
119 Page* page() const;
120 HTMLFrameOwnerElement* ownerElement() const;
121
122 void pageDestroyed();
123 void disconnectOwnerElement();
124
125 Document* document() const;
126 FrameView* view() const;
127
128 void setDOMWindow(DOMWindow*);
129 DOMWindow* domWindow() const;
130 void clearFormerDOMWindow(DOMWindow*);
131
132 Editor* editor() const;
133 EventHandler* eventHandler() const;
134 FrameLoader* loader() const;
135 SelectionController* selection() const;
136 FrameTree* tree() const;
137 AnimationController* animation() const;
138 ScriptController* script();
139
140 RenderView* contentRenderer() const; // root renderer for the document contained in this frame
141 RenderPart* ownerRenderer() const; // renderer for the element that contains this frame
142
143 bool isDisconnected() const;
144 void setIsDisconnected(bool);
145 bool excludeFromTextSearch() const;
146 void setExcludeFromTextSearch(bool);
147
148 friend class FramePrivate;
149
150 float documentScale() const;
151 void setDocumentScale(float);
152
153 private:
154 Frame(Page*, HTMLFrameOwnerElement*, FrameLoaderClient*);
155
156 // === undecided, would like to consider moving to another class
157
158 public:
159 static Frame* frameForWidget(const Widget*);
160
161 Settings* settings() const; // can be NULL
162
163 #if FRAME_LOADS_USER_STYLESHEET
164 void setUserStyleSheetLocation(const KURL&);
165 void setUserStyleSheet(const String&, bool saveStyleSheet = false);
166 #endif
167
168 void setPrinting(bool printing, float minPageWidth, float maxPageWidth, bool adjustViewSize);
169
170 bool inViewSourceMode() const;
171 void setInViewSourceMode(bool = true);
172
173 void keepAlive(); // Used to keep the frame alive when running a script that might destroy it.
174 #ifndef NDEBUG
175 static void cancelAllKeepAlive();
176 #endif
177
178 #if ENABLE(IPHONE_PPT)
179 void didParse(double);
180 void didLayout(bool, double);
181 void didForcedLayout();
182 void getPPTStats(unsigned& parseCount, unsigned& layoutCount, unsigned& forcedLayoutCount, CFTimeInterval& parseDuration, CFTimeInterval& layoutDuration);
183 void clearPPTStats();
184 #endif
185
186 void formElementDidSetValue(Element*);
187 void formElementDidFocus(Element*);
188 void formElementDidBlur(Element*);
189
190 const ViewportArguments& viewportArguments() const;
191 void setViewportArguments(const ViewportArguments&);
192 NSDictionary* dictionaryForViewportArguments(const ViewportArguments& arguments) const;
193
194 inline void betterApproximateNode(int x, int y, NodeQualifier aQualifer, Node* & best, Node* failedNode, IntPoint &bestPoint, IntRect &bestRect, IntRect& testRect);
195 inline Node* qualifyingNodeAtViewportLocation(CGPoint* aViewportLocation, NodeQualifier aQualifer, bool shouldApproximate);
196
197 Node* nodeRespondingToClickEvents(CGPoint* aViewportLocation);
198 Node* nodeRespondingToScrollWheelEvents(CGPoint* aViewportLocation);
199
200 int indexCountOfWordPrecedingSelection(NSString *word);
201 NSArray *wordsInCurrentParagraph();
202 CGRect renderRectForPoint(CGPoint point, bool *isReplaced, float *fontSize);
203
204 void setEmbeddedEditingMode(bool b = true);
205 bool embeddedEditingMode() const;
206
207 void setDocument(PassRefPtr<Document>);
208
209 void sendOrientationChangeEvent(int orientation);
210 int orientation() const;
211
212 void clearTimers();
213 static void clearTimers(FrameView*, Document*);
214
215 void setNeedsReapplyStyles();
216 bool needsReapplyStyles() const;
217 void reapplyStyles();
218
219 String documentTypeString() const;
220
221 // This method -- and the corresponding list of former DOM windows --
222 // should move onto ScriptController
223 void clearDOMWindow();
224
225 String displayStringModifiedByEncoding(const String& str) const
226 {
227 return document() ? document()->displayStringModifiedByEncoding(str) : str;
228 }
229
230 private:
231 void lifeSupportTimerFired(Timer<Frame>*);
232
233 // === to be moved into Document
234
235 public:
236 bool isFrameSet() const;
237
238 // === to be moved into EventHandler
239
240 public:
241 void sendResizeEvent();
242 void sendScrollEvent();
243
244 // === to be moved into FrameView
245
246 public:
247 void forceLayout(bool allowSubtree = false);
248 void forceLayoutWithPageWidthRange(float minPageWidth, float maxPageWidth, bool adjustViewSize);
249
250 void adjustPageHeight(float* newBottom, float oldTop, float oldBottom, float bottomLimit);
251
252 void setZoomFactor(float scale, bool isTextOnly);
253 float zoomFactor() const;
254 bool isZoomFactorTextOnly() const;
255 bool shouldApplyTextZoom() const;
256 bool shouldApplyPageZoom() const;
257 float pageZoomFactor() const { return shouldApplyPageZoom() ? zoomFactor() : 1.0f; }
258 float textZoomFactor() const { return shouldApplyTextZoom() ? zoomFactor() : 1.0f; }
259
260 // === to be moved into Chrome
261
262 public:
263 void focusWindow();
264 void unfocusWindow();
265 bool shouldClose();
266 void scheduleClose();
267
268 void setJSStatusBarText(const String&);
269 void setJSDefaultStatusBarText(const String&);
270 String jsStatusBarText() const;
271 String jsDefaultStatusBarText() const;
272
273 // === to be moved into Editor
274
275 public:
276 String selectedText() const;
277 bool findString(const String&, bool forward, bool caseFlag, bool wrapFlag, bool startInSelection);
278
279 const Selection& mark() const; // Mark, to be used as emacs uses it.
280 void setMark(const Selection&);
281
282 /**
283 * Clears the current selection.
284 */
285 void clearSelection();
286
287 void computeAndSetTypingStyle(CSSStyleDeclaration* , EditAction = EditActionUnspecified);
288 String selectionStartStylePropertyValue(int stylePropertyID) const;
289 void applyEditingStyleToBodyElement() const;
290 void removeEditingStyleFromBodyElement() const;
291 void applyEditingStyleToElement(Element*) const;
292 void removeEditingStyleFromElement(Element*) const;
293
294 IntRect firstRectForRange(Range*) const;
295
296 void respondToChangedSelection(const Selection& oldSelection, bool closeTyping);
297 bool shouldChangeSelection(const Selection& oldSelection, const Selection& newSelection, EAffinity, bool stillSelecting) const;
298
299 RenderStyle* styleForSelectionStart(Node*& nodeToRemove) const;
300
301 unsigned markAllMatchesForText(const String&, bool caseFlag, unsigned limit);
302 bool markedTextMatchesAreHighlighted() const;
303 void setMarkedTextMatchesAreHighlighted(bool flag);
304
305 PassRefPtr<CSSComputedStyleDeclaration> selectionComputedStyle(Node*& nodeToRemove) const;
306
307 void textFieldDidBeginEditing(Element*);
308 void textFieldDidEndEditing(Element*);
309 void textDidChangeInTextField(Element*);
310 bool doTextFieldCommandFromEvent(Element*, KeyboardEvent*);
311 void textWillBeDeletedInTextField(Element* input);
312 void textDidChangeInTextArea(Element*);
313
314 DragImageRef dragImageForSelection();
315
316 // === to be moved into SelectionController
317
318 public:
319 TextGranularity selectionGranularity() const;
320 void setSelectionGranularity(TextGranularity);
321
322 bool shouldChangeSelection(const Selection&) const;
323 bool shouldDeleteSelection(const Selection&) const;
324 void clearCaretRectIfNeeded();
325 void setFocusedNodeIfNeeded();
326 void selectionLayoutChanged();
327 void notifyRendererOfSelectionChange(bool userTriggered);
328
329 void setSingleLineSelectionBehavior(bool b);
330 bool singleLineSelectionBehavior() const;
331
332 void invalidateSelection();
333
334 void setCaretVisible(bool = true);
335 void paintCaret(GraphicsContext*, int tx, int ty, const IntRect& clipRect) const;
336 void paintDragCaret(GraphicsContext*, int tx, int ty, const IntRect& clipRect) const;
337
338 void setCaretColor(const Color &color);
339
340 /**
341 * Scroll the selection in an overflow layer on iPhone.
342 */
343 void scrollOverflowLayer(RenderLayer *, const IntRect &visibleRect, const IntRect &exposeRect);
344
345 void invalidateOwnerRendererLayoutIfNeeded();
346
347 bool isContentEditable() const; // if true, everything in frame is editable
348
349 void updateSecureKeyboardEntryIfActive();
350
351 CSSMutableStyleDeclaration* typingStyle() const;
352 void setTypingStyle(CSSMutableStyleDeclaration*);
353 void clearTypingStyle();
354
355 FloatRect selectionBounds(bool clipToVisibleContent = true) const;
356 void selectionTextRects(Vector<FloatRect>&, bool clipToVisibleContent = true) const;
357
358 HTMLFormElement* currentForm() const;
359
360 void revealSelection(const RenderLayer::ScrollAlignment& = RenderLayer::gAlignCenterIfNeeded, bool revealExtent = false);
361 void setSelectionFromNone();
362 void setCaretBlinks(bool flag = true);
363
364 void setUseSecureKeyboardEntry(bool);
365
366 private:
367 void caretBlinkTimerFired(Timer<Frame>*);
368
369 void overflowAutoScrollTimerFired(Timer<Frame>*);
370 void startOverflowAutoScroll(const IntPoint &);
371 void stopOverflowAutoScroll();
372 int checkOverflowScroll(OverflowScrollAction);
373
374 public:
375 SelectionController* dragCaretController() const;
376
377 String searchForLabelsAboveCell(RegularExpression*, HTMLTableCellElement*);
378 String searchForLabelsBeforeElement(const Vector<String>& labels, Element*);
379 String matchLabelsAgainstElement(const Vector<String>& labels, Element*);
380
381 VisiblePosition visiblePositionForPoint(const IntPoint& framePoint);
382 Document* documentAtPoint(const IntPoint& windowPoint);
383
384 #if PLATFORM(MAC)
385
386 // === undecided, would like to consider moving to another class
387
388 public:
389 NSString* searchForNSLabelsAboveCell(RegularExpression*, HTMLTableCellElement*);
390 NSString* searchForLabelsBeforeElement(NSArray* labels, Element*);
391 NSString* matchLabelsAgainstElement(NSArray* labels, Element*);
392
393 #if ENABLE(DASHBOARD_SUPPORT)
394 NSMutableDictionary* dashboardRegionsDictionary();
395 #endif
396
397
398 private:
399
400 // === to be moved into Editor
401
402 public:
403 NSDictionary* fontAttributesForSelectionStart() const;
404 NSWritingDirection baseWritingDirectionForSelectionStart() const;
405
406 #endif
407
408 // Used to be in WebCoreFrameBridge
409 public:
410 int preferredHeight() const;
411 int innerLineHeight(DOMNode *node) const;
412 void updateLayout() const;
413 NSRect caretRect() const;
414 NSRect rectForScrollToVisible() const;
415 void createDefaultFieldEditorDocumentStructure() const;
416 void moveSelectionToStartOrEndOfCurrentWord();
417 unsigned formElementsCharacterCount() const;
418 void setTimersPaused(bool);
419 bool timersPaused() const { return m_timersPausedCount; }
420 const FloatSize& visibleSize() const;
421 void setVisibleSize(const FloatSize& size);
422 void setRangedSelectionBaseToCurrentSelection();
423 void setRangedSelectionBaseToCurrentSelectionStart();
424 void setRangedSelectionBaseToCurrentSelectionEnd();
425 void clearRangedSelectionInitialExtent();
426 void setRangedSelectionInitialExtentToCurrentSelectionStart();
427 void setRangedSelectionInitialExtentToCurrentSelectionEnd();
428 Selection rangedSelectionBase() const;
429 Selection rangedSelectionInitialExtent() const;
430
431 #if PLATFORM(WIN)
432
433 public:
434 // FIXME - We should have a single version of nodeImage instead of using platform types.
435 HBITMAP nodeImage(Node*) const;
436
437 #endif
438
439 private:
440 Page* m_page;
441 mutable FrameTree m_treeNode;
442 mutable FrameLoader m_loader;
443
444 mutable RefPtr<DOMWindow> m_domWindow;
445 HashSet<DOMWindow*> m_liveFormerWindows;
446
447 HTMLFrameOwnerElement* m_ownerElement;
448 RefPtr<FrameView> m_view;
449 RefPtr<Document> m_doc;
450
451 ScriptController m_script;
452
453 String m_kjsStatusBarText;
454 String m_kjsDefaultStatusBarText;
455
456 float m_zoomFactor;
457
458 TextGranularity m_selectionGranularity;
459
460 mutable SelectionController m_selectionController;
461 mutable Selection m_mark;
462 Timer<Frame> m_caretBlinkTimer;
463 mutable Editor m_editor;
464 mutable EventHandler m_eventHandler;
465 mutable AnimationController m_animationController;
466
467 RefPtr<CSSMutableStyleDeclaration> m_typingStyle;
468
469 Color m_caretColor;
470 Timer<Frame> m_overflowAutoScrollTimer;
471 float m_overflowAutoScrollDelta;
472 IntPoint m_overflowAutoScrollPos;
473 ViewportArguments m_viewportArguments;
474 bool m_embeddedEditingMode;
475 FloatSize m_visibleSize;
476 int m_orientation;
477 Selection m_rangedSelectionBase;
478 Selection m_rangedSelectionInitialExtent;
479
480 #if ENABLE(IPHONE_PPT)
481 unsigned m_parseCount;
482 unsigned m_layoutCount;
483 unsigned m_forcedLayoutCount;
484 CFTimeInterval m_parseDuration;
485 CFTimeInterval m_layoutDuration;
486 #endif
487
488 Timer<Frame> m_lifeSupportTimer;
489
490 String m_userStyleSheet;
491
492 bool m_caretVisible;
493 bool m_caretBlinks;
494 bool m_caretPaint;
495
496 bool m_highlightTextMatches;
497 bool m_inViewSourceMode;
498 bool m_needsReapplyStyles;
499 bool m_isDisconnected;
500 bool m_excludeFromTextSearch;
501
502 bool m_singleLineSelectionBehavior;
503 int m_timersPausedCount;
504 float m_documentScale;
505
506 #if FRAME_LOADS_USER_STYLESHEET
507 UserStyleSheetLoader* m_userStyleSheetLoader;
508 #endif
509
510 };
511
512 } // namespace WebCore
513
514 #endif // Frame_h