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>
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.
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.
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.
31 #include "AnimationController.h"
32 #include "DragImage.h"
33 #include "EditAction.h"
35 #include "EventHandler.h"
36 #include "FrameLoader.h"
37 #include "FrameTree.h"
39 #include "RenderLayer.h"
40 #include "ScriptController.h"
41 #include "SelectionController.h"
42 #include "TextGranularity.h"
46 #include <GraphicsServices/GSEvent.h>
55 class NSMutableDictionary
;
57 typedef int NSWritingDirection
;
67 typedef struct HBITMAP__
* HBITMAP
;
75 class FrameLoaderClient
;
78 class HTMLFrameOwnerElement
;
79 class HTMLTableCellElement
;
80 class ScriptController
;
81 class RegularExpression
;
85 class SelectionController
;
88 #if FRAME_LOADS_USER_STYLESHEET
89 class UserStyleSheetLoader
;
92 template <typename T
> class Timer
;
95 OverflowScrollNone
= 0x0,
96 OverflowScrollLeft
= 0x1,
97 OverflowScrollRight
= 0x2,
98 OverflowScrollUp
= 0x4,
99 OverflowScrollDown
= 0x8
102 enum OverflowScrollAction
{ DoNotPerformOverflowScroll
, PerformOverflowScroll
};
103 typedef Node
* (*NodeQualifier
)(HitTestResult aHitTestResult
, Node
* terminationNode
, IntRect
* frame
);
106 class Frame
: public RefCounted
<Frame
> {
108 static PassRefPtr
<Frame
> create(Page
* page
, HTMLFrameOwnerElement
* ownerElement
, FrameLoaderClient
* client
)
110 return adoptRef(new Frame(page
, ownerElement
, client
));
112 void setView(FrameView
*);
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
);
120 HTMLFrameOwnerElement
* ownerElement() const;
122 void pageDestroyed();
123 void disconnectOwnerElement();
125 Document
* document() const;
126 FrameView
* view() const;
128 void setDOMWindow(DOMWindow
*);
129 DOMWindow
* domWindow() const;
130 void clearFormerDOMWindow(DOMWindow
*);
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();
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
143 bool isDisconnected() const;
144 void setIsDisconnected(bool);
145 bool excludeFromTextSearch() const;
146 void setExcludeFromTextSearch(bool);
148 friend class FramePrivate
;
150 float documentScale() const;
151 void setDocumentScale(float);
154 Frame(Page
*, HTMLFrameOwnerElement
*, FrameLoaderClient
*);
156 // === undecided, would like to consider moving to another class
159 static Frame
* frameForWidget(const Widget
*);
161 Settings
* settings() const; // can be NULL
163 #if FRAME_LOADS_USER_STYLESHEET
164 void setUserStyleSheetLocation(const KURL
&);
165 void setUserStyleSheet(const String
&, bool saveStyleSheet
= false);
168 void setPrinting(bool printing
, float minPageWidth
, float maxPageWidth
, bool adjustViewSize
);
170 bool inViewSourceMode() const;
171 void setInViewSourceMode(bool = true);
173 void keepAlive(); // Used to keep the frame alive when running a script that might destroy it.
175 static void cancelAllKeepAlive();
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();
186 void formElementDidSetValue(Element
*);
187 void formElementDidFocus(Element
*);
188 void formElementDidBlur(Element
*);
190 const ViewportArguments
& viewportArguments() const;
191 void setViewportArguments(const ViewportArguments
&);
192 NSDictionary
* dictionaryForViewportArguments(const ViewportArguments
& arguments
) const;
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
);
197 Node
* nodeRespondingToClickEvents(CGPoint
* aViewportLocation
);
198 Node
* nodeRespondingToScrollWheelEvents(CGPoint
* aViewportLocation
);
200 int indexCountOfWordPrecedingSelection(NSString
*word
);
201 NSArray
*wordsInCurrentParagraph();
202 CGRect
renderRectForPoint(CGPoint point
, bool *isReplaced
, float *fontSize
);
204 void setEmbeddedEditingMode(bool b
= true);
205 bool embeddedEditingMode() const;
207 void setDocument(PassRefPtr
<Document
>);
209 void sendOrientationChangeEvent(int orientation
);
210 int orientation() const;
213 static void clearTimers(FrameView
*, Document
*);
215 void setNeedsReapplyStyles();
216 bool needsReapplyStyles() const;
217 void reapplyStyles();
219 String
documentTypeString() const;
221 // This method -- and the corresponding list of former DOM windows --
222 // should move onto ScriptController
223 void clearDOMWindow();
225 String
displayStringModifiedByEncoding(const String
& str
) const
227 return document() ? document()->displayStringModifiedByEncoding(str
) : str
;
231 void lifeSupportTimerFired(Timer
<Frame
>*);
233 // === to be moved into Document
236 bool isFrameSet() const;
238 // === to be moved into EventHandler
241 void sendResizeEvent();
242 void sendScrollEvent();
244 // === to be moved into FrameView
247 void forceLayout(bool allowSubtree
= false);
248 void forceLayoutWithPageWidthRange(float minPageWidth
, float maxPageWidth
, bool adjustViewSize
);
250 void adjustPageHeight(float* newBottom
, float oldTop
, float oldBottom
, float bottomLimit
);
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
; }
260 // === to be moved into Chrome
264 void unfocusWindow();
266 void scheduleClose();
268 void setJSStatusBarText(const String
&);
269 void setJSDefaultStatusBarText(const String
&);
270 String
jsStatusBarText() const;
271 String
jsDefaultStatusBarText() const;
273 // === to be moved into Editor
276 String
selectedText() const;
277 bool findString(const String
&, bool forward
, bool caseFlag
, bool wrapFlag
, bool startInSelection
);
279 const Selection
& mark() const; // Mark, to be used as emacs uses it.
280 void setMark(const Selection
&);
283 * Clears the current selection.
285 void clearSelection();
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;
294 IntRect
firstRectForRange(Range
*) const;
296 void respondToChangedSelection(const Selection
& oldSelection
, bool closeTyping
);
297 bool shouldChangeSelection(const Selection
& oldSelection
, const Selection
& newSelection
, EAffinity
, bool stillSelecting
) const;
299 RenderStyle
* styleForSelectionStart(Node
*& nodeToRemove
) const;
301 unsigned markAllMatchesForText(const String
&, bool caseFlag
, unsigned limit
);
302 bool markedTextMatchesAreHighlighted() const;
303 void setMarkedTextMatchesAreHighlighted(bool flag
);
305 PassRefPtr
<CSSComputedStyleDeclaration
> selectionComputedStyle(Node
*& nodeToRemove
) const;
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
*);
314 DragImageRef
dragImageForSelection();
316 // === to be moved into SelectionController
319 TextGranularity
selectionGranularity() const;
320 void setSelectionGranularity(TextGranularity
);
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
);
329 void setSingleLineSelectionBehavior(bool b
);
330 bool singleLineSelectionBehavior() const;
332 void invalidateSelection();
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;
338 void setCaretColor(const Color
&color
);
341 * Scroll the selection in an overflow layer on iPhone.
343 void scrollOverflowLayer(RenderLayer
*, const IntRect
&visibleRect
, const IntRect
&exposeRect
);
345 void invalidateOwnerRendererLayoutIfNeeded();
347 bool isContentEditable() const; // if true, everything in frame is editable
349 void updateSecureKeyboardEntryIfActive();
351 CSSMutableStyleDeclaration
* typingStyle() const;
352 void setTypingStyle(CSSMutableStyleDeclaration
*);
353 void clearTypingStyle();
355 FloatRect
selectionBounds(bool clipToVisibleContent
= true) const;
356 void selectionTextRects(Vector
<FloatRect
>&, bool clipToVisibleContent
= true) const;
358 HTMLFormElement
* currentForm() const;
360 void revealSelection(const RenderLayer::ScrollAlignment
& = RenderLayer::gAlignCenterIfNeeded
, bool revealExtent
= false);
361 void setSelectionFromNone();
362 void setCaretBlinks(bool flag
= true);
364 void setUseSecureKeyboardEntry(bool);
367 void caretBlinkTimerFired(Timer
<Frame
>*);
369 void overflowAutoScrollTimerFired(Timer
<Frame
>*);
370 void startOverflowAutoScroll(const IntPoint
&);
371 void stopOverflowAutoScroll();
372 int checkOverflowScroll(OverflowScrollAction
);
375 SelectionController
* dragCaretController() const;
377 String
searchForLabelsAboveCell(RegularExpression
*, HTMLTableCellElement
*);
378 String
searchForLabelsBeforeElement(const Vector
<String
>& labels
, Element
*);
379 String
matchLabelsAgainstElement(const Vector
<String
>& labels
, Element
*);
381 VisiblePosition
visiblePositionForPoint(const IntPoint
& framePoint
);
382 Document
* documentAtPoint(const IntPoint
& windowPoint
);
386 // === undecided, would like to consider moving to another class
389 NSString
* searchForNSLabelsAboveCell(RegularExpression
*, HTMLTableCellElement
*);
390 NSString
* searchForLabelsBeforeElement(NSArray
* labels
, Element
*);
391 NSString
* matchLabelsAgainstElement(NSArray
* labels
, Element
*);
393 #if ENABLE(DASHBOARD_SUPPORT)
394 NSMutableDictionary
* dashboardRegionsDictionary();
400 // === to be moved into Editor
403 NSDictionary
* fontAttributesForSelectionStart() const;
404 NSWritingDirection
baseWritingDirectionForSelectionStart() const;
408 // Used to be in WebCoreFrameBridge
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;
434 // FIXME - We should have a single version of nodeImage instead of using platform types.
435 HBITMAP
nodeImage(Node
*) const;
441 mutable FrameTree m_treeNode
;
442 mutable FrameLoader m_loader
;
444 mutable RefPtr
<DOMWindow
> m_domWindow
;
445 HashSet
<DOMWindow
*> m_liveFormerWindows
;
447 HTMLFrameOwnerElement
* m_ownerElement
;
448 RefPtr
<FrameView
> m_view
;
449 RefPtr
<Document
> m_doc
;
451 ScriptController m_script
;
453 String m_kjsStatusBarText
;
454 String m_kjsDefaultStatusBarText
;
458 TextGranularity m_selectionGranularity
;
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
;
467 RefPtr
<CSSMutableStyleDeclaration
> m_typingStyle
;
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
;
477 Selection m_rangedSelectionBase
;
478 Selection m_rangedSelectionInitialExtent
;
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
;
488 Timer
<Frame
> m_lifeSupportTimer
;
490 String m_userStyleSheet
;
496 bool m_highlightTextMatches
;
497 bool m_inViewSourceMode
;
498 bool m_needsReapplyStyles
;
499 bool m_isDisconnected
;
500 bool m_excludeFromTextSearch
;
502 bool m_singleLineSelectionBehavior
;
503 int m_timersPausedCount
;
504 float m_documentScale
;
506 #if FRAME_LOADS_USER_STYLESHEET
507 UserStyleSheetLoader
* m_userStyleSheetLoader
;
512 } // namespace WebCore