• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #if PLATFORM(WIN)
45 #include "FrameWin.h"
46 #endif
47 
48 #if PLATFORM(MAC)
49 #ifndef __OBJC__
50 class NSArray;
51 class NSDictionary;
52 class NSMutableDictionary;
53 class NSString;
54 typedef int NSWritingDirection;
55 #endif
56 #endif
57 
58 #if PLATFORM(WIN)
59 typedef struct HBITMAP__* HBITMAP;
60 #endif
61 
62 namespace WebCore {
63 
64 class Editor;
65 class EventHandler;
66 class FrameLoader;
67 class FrameLoaderClient;
68 class FramePrivate;
69 class FrameTree;
70 class HTMLFrameOwnerElement;
71 class HTMLTableCellElement;
72 class ScriptController;
73 class RegularExpression;
74 class RenderPart;
75 class Selection;
76 class SelectionController;
77 class Widget;
78 
79 #if FRAME_LOADS_USER_STYLESHEET
80     class UserStyleSheetLoader;
81 #endif
82 
83 template <typename T> class Timer;
84 
85 class Frame : public RefCounted<Frame> {
86 public:
create(Page * page,HTMLFrameOwnerElement * ownerElement,FrameLoaderClient * client)87     static PassRefPtr<Frame> create(Page* page, HTMLFrameOwnerElement* ownerElement, FrameLoaderClient* client)
88     {
89         return adoptRef(new Frame(page, ownerElement, client));
90     }
91     void setView(FrameView*);
92     ~Frame();
93 
94     void init();
95 
96     Page* page() const;
97     HTMLFrameOwnerElement* ownerElement() const;
98 
99     void pageDestroyed();
100     void disconnectOwnerElement();
101 
102     Document* document() const;
103     FrameView* view() const;
104 
105     void setDOMWindow(DOMWindow*);
106     DOMWindow* domWindow() const;
107     void clearFormerDOMWindow(DOMWindow*);
108 
109     Editor* editor() const;
110     EventHandler* eventHandler() const;
111     FrameLoader* loader() const;
112     SelectionController* selection() const;
113     FrameTree* tree() const;
114     AnimationController* animation() const;
115     ScriptController* script();
116 
117     RenderView* contentRenderer() const; // root renderer for the document contained in this frame
118     RenderPart* ownerRenderer() const; // renderer for the element that contains this frame
119 
120     bool isDisconnected() const;
121     void setIsDisconnected(bool);
122     bool excludeFromTextSearch() const;
123     void setExcludeFromTextSearch(bool);
124 
125     friend class FramePrivate;
126 
127 private:
128     Frame(Page*, HTMLFrameOwnerElement*, FrameLoaderClient*);
129 
130 // === undecided, would like to consider moving to another class
131 
132 public:
133     static Frame* frameForWidget(const Widget*);
134 
135     Settings* settings() const; // can be NULL
136 
137 #if FRAME_LOADS_USER_STYLESHEET
138     void setUserStyleSheetLocation(const KURL&);
139     void setUserStyleSheet(const String& styleSheetData);
140 #endif
141 
142     void setPrinting(bool printing, float minPageWidth, float maxPageWidth, bool adjustViewSize);
143 
144     bool inViewSourceMode() const;
145     void setInViewSourceMode(bool = true);
146 
147     void keepAlive(); // Used to keep the frame alive when running a script that might destroy it.
148 #ifndef NDEBUG
149     static void cancelAllKeepAlive();
150 #endif
151 
152     void setDocument(PassRefPtr<Document>);
153 
154     void clearTimers();
155     static void clearTimers(FrameView*, Document*);
156 
157     void setNeedsReapplyStyles();
158     bool needsReapplyStyles() const;
159     void reapplyStyles();
160 
161     String documentTypeString() const;
162 
163     // This method -- and the corresponding list of former DOM windows --
164     // should move onto ScriptController
165     void clearDOMWindow();
166 
displayStringModifiedByEncoding(const String & str)167     String displayStringModifiedByEncoding(const String& str) const
168     {
169         return document() ? document()->displayStringModifiedByEncoding(str) : str;
170     }
171 
172 private:
173     void lifeSupportTimerFired(Timer<Frame>*);
174 
175 // === to be moved into Document
176 
177 public:
178     bool isFrameSet() const;
179 
180 // === to be moved into EventHandler
181 
182 public:
183     void sendResizeEvent();
184     void sendScrollEvent();
185 
186 // === to be moved into FrameView
187 
188 public:
189     void forceLayout(bool allowSubtree = false);
190     void forceLayoutWithPageWidthRange(float minPageWidth, float maxPageWidth, bool adjustViewSize);
191 
192     void adjustPageHeight(float* newBottom, float oldTop, float oldBottom, float bottomLimit);
193 
194     void setZoomFactor(float scale, bool isTextOnly);
195     float zoomFactor() const;
196     bool isZoomFactorTextOnly() const;
197     bool shouldApplyTextZoom() const;
198     bool shouldApplyPageZoom() const;
pageZoomFactor()199     float pageZoomFactor() const { return shouldApplyPageZoom() ? zoomFactor() : 1.0f; }
textZoomFactor()200     float textZoomFactor() const { return shouldApplyTextZoom() ? zoomFactor() : 1.0f; }
201 
202 // === to be moved into Chrome
203 
204 public:
205     void focusWindow();
206     void unfocusWindow();
207     bool shouldClose();
208     void scheduleClose();
209 
210     void setJSStatusBarText(const String&);
211     void setJSDefaultStatusBarText(const String&);
212     String jsStatusBarText() const;
213     String jsDefaultStatusBarText() const;
214 
215 // === to be moved into Editor
216 
217 public:
218     String selectedText() const;
219     bool findString(const String&, bool forward, bool caseFlag, bool wrapFlag, bool startInSelection);
220 
221     const Selection& mark() const; // Mark, to be used as emacs uses it.
222     void setMark(const Selection&);
223 
224     void computeAndSetTypingStyle(CSSStyleDeclaration* , EditAction = EditActionUnspecified);
225     String selectionStartStylePropertyValue(int stylePropertyID) const;
226     void applyEditingStyleToBodyElement() const;
227     void removeEditingStyleFromBodyElement() const;
228     void applyEditingStyleToElement(Element*) const;
229     void removeEditingStyleFromElement(Element*) const;
230 
231     IntRect firstRectForRange(Range*) const;
232 
233     void respondToChangedSelection(const Selection& oldSelection, bool closeTyping);
234     bool shouldChangeSelection(const Selection& oldSelection, const Selection& newSelection, EAffinity, bool stillSelecting) const;
235 
236     RenderStyle* styleForSelectionStart(Node*& nodeToRemove) const;
237 
238     unsigned markAllMatchesForText(const String&, bool caseFlag, unsigned limit);
239     bool markedTextMatchesAreHighlighted() const;
240     void setMarkedTextMatchesAreHighlighted(bool flag);
241 
242     PassRefPtr<CSSComputedStyleDeclaration> selectionComputedStyle(Node*& nodeToRemove) const;
243 
244     void textFieldDidBeginEditing(Element*);
245     void textFieldDidEndEditing(Element*);
246     void textDidChangeInTextField(Element*);
247     bool doTextFieldCommandFromEvent(Element*, KeyboardEvent*);
248     void textWillBeDeletedInTextField(Element* input);
249     void textDidChangeInTextArea(Element*);
250 
251     DragImageRef dragImageForSelection();
252 
253 // === to be moved into SelectionController
254 
255 public:
256     TextGranularity selectionGranularity() const;
257     void setSelectionGranularity(TextGranularity);
258 
259     bool shouldChangeSelection(const Selection&) const;
260     bool shouldDeleteSelection(const Selection&) const;
261     void clearCaretRectIfNeeded();
262     void setFocusedNodeIfNeeded();
263     void selectionLayoutChanged();
264     void notifyRendererOfSelectionChange(bool userTriggered);
265 
266     void invalidateSelection();
267 
268     void setCaretVisible(bool = true);
269     void paintCaret(GraphicsContext*, int tx, int ty, const IntRect& clipRect) const;
270     void paintDragCaret(GraphicsContext*, int tx, int ty, const IntRect& clipRect) const;
271 
272     bool isContentEditable() const; // if true, everything in frame is editable
273 
274     void updateSecureKeyboardEntryIfActive();
275 
276     CSSMutableStyleDeclaration* typingStyle() const;
277     void setTypingStyle(CSSMutableStyleDeclaration*);
278     void clearTypingStyle();
279 
280     FloatRect selectionBounds(bool clipToVisibleContent = true) const;
281     void selectionTextRects(Vector<FloatRect>&, bool clipToVisibleContent = true) const;
282 
283     HTMLFormElement* currentForm() const;
284 
285     void revealSelection(const RenderLayer::ScrollAlignment& = RenderLayer::gAlignCenterIfNeeded) const;
286     void revealCaret(const RenderLayer::ScrollAlignment& = RenderLayer::gAlignCenterIfNeeded) const;
287     void setSelectionFromNone();
288 
289     void setUseSecureKeyboardEntry(bool);
290 
291 private:
292     void caretBlinkTimerFired(Timer<Frame>*);
293 
294 public:
295     SelectionController* dragCaretController() const;
296 
297     String searchForLabelsAboveCell(RegularExpression*, HTMLTableCellElement*);
298     String searchForLabelsBeforeElement(const Vector<String>& labels, Element*);
299     String matchLabelsAgainstElement(const Vector<String>& labels, Element*);
300 
301     VisiblePosition visiblePositionForPoint(const IntPoint& framePoint);
302     Document* documentAtPoint(const IntPoint& windowPoint);
303 
304 #if PLATFORM(MAC)
305 
306 // === undecided, would like to consider moving to another class
307 
308 public:
309     NSString* searchForNSLabelsAboveCell(RegularExpression*, HTMLTableCellElement*);
310     NSString* searchForLabelsBeforeElement(NSArray* labels, Element*);
311     NSString* matchLabelsAgainstElement(NSArray* labels, Element*);
312 
313 #if ENABLE(DASHBOARD_SUPPORT)
314     NSMutableDictionary* dashboardRegionsDictionary();
315 #endif
316 
317     NSImage* selectionImage(bool forceBlackText = false) const;
318     NSImage* snapshotDragImage(Node*, NSRect* imageRect, NSRect* elementRect) const;
319     NSImage* nodeImage(Node*) const;
320 
321 private:
322     NSImage* imageFromRect(NSRect) const;
323 
324 // === to be moved into Editor
325 
326 public:
327     NSDictionary* fontAttributesForSelectionStart() const;
328     NSWritingDirection baseWritingDirectionForSelectionStart() const;
329 
330 #endif
331 
332 #if PLATFORM(WIN)
333 
334 public:
335     // FIXME - We should have a single version of nodeImage instead of using platform types.
336     HBITMAP nodeImage(Node*) const;
337 
338 #endif
339 
340 private:
341     Page* m_page;
342     mutable FrameTree m_treeNode;
343     mutable FrameLoader m_loader;
344 
345     mutable RefPtr<DOMWindow> m_domWindow;
346     HashSet<DOMWindow*> m_liveFormerWindows;
347 
348     HTMLFrameOwnerElement* m_ownerElement;
349     RefPtr<FrameView> m_view;
350     RefPtr<Document> m_doc;
351 
352     ScriptController m_script;
353 
354     String m_kjsStatusBarText;
355     String m_kjsDefaultStatusBarText;
356 
357     float m_zoomFactor;
358 
359     TextGranularity m_selectionGranularity;
360 
361     mutable SelectionController m_selectionController;
362     mutable Selection m_mark;
363     Timer<Frame> m_caretBlinkTimer;
364     mutable Editor m_editor;
365     mutable EventHandler m_eventHandler;
366     mutable AnimationController m_animationController;
367 
368     RefPtr<CSSMutableStyleDeclaration> m_typingStyle;
369 
370     Timer<Frame> m_lifeSupportTimer;
371 
372     bool m_caretVisible;
373     bool m_caretPaint;
374 
375     bool m_highlightTextMatches;
376     bool m_inViewSourceMode;
377     bool m_needsReapplyStyles;
378     bool m_isDisconnected;
379     bool m_excludeFromTextSearch;
380 
381 #if FRAME_LOADS_USER_STYLESHEET
382     UserStyleSheetLoader* m_userStyleSheetLoader;
383 #endif
384 
385 };
386 
387 } // namespace WebCore
388 
389 #endif // Frame_h
390