OSDN Git Service

Merge Webkit at r70949: Initial merge by git.
[android-x86/external-webkit.git] / WebCore / page / 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, 2009, 2010 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 "Editor.h"
34 #include "EventHandler.h"
35 #include "FrameLoader.h"
36 #include "FrameTree.h"
37 #include "ScriptController.h"
38 #include "UserScriptTypes.h"
39
40 #if PLATFORM(WIN)
41 #include "FrameWin.h"
42 #endif
43
44 #if ENABLE(TILED_BACKING_STORE)
45 #include "TiledBackingStoreClient.h"
46 #endif
47
48 #if PLATFORM(MAC)
49 #ifndef __OBJC__
50 class NSArray;
51 class NSMutableDictionary;
52 class NSString;
53 #endif
54 #endif
55
56 #if PLATFORM(WIN)
57 typedef struct HBITMAP__* HBITMAP;
58 #endif
59
60 namespace WebCore {
61
62     class HTMLTableCellElement;
63     class RegularExpression;
64     class RenderPart;
65     class TiledBackingStore;
66
67 #if !ENABLE(TILED_BACKING_STORE)
68     class TiledBackingStoreClient { };
69 #endif
70
71     class Frame : public RefCounted<Frame>, public TiledBackingStoreClient {
72     public:
73         static PassRefPtr<Frame> create(Page*, HTMLFrameOwnerElement*, FrameLoaderClient*);
74
75         void init();
76         void setView(PassRefPtr<FrameView>);
77         void createView(const IntSize&, const Color&, bool, const IntSize&, bool,
78             ScrollbarMode = ScrollbarAuto, bool horizontalLock = false,
79             ScrollbarMode = ScrollbarAuto, bool verticalLock = false);
80
81         ~Frame();
82
83         void detachFromPage();
84         void pageDestroyed();
85         void disconnectOwnerElement();
86
87         Page* page() const;
88         HTMLFrameOwnerElement* ownerElement() const;
89
90         Document* document() const;
91         FrameView* view() const;
92
93         Editor* editor() const;
94         EventHandler* eventHandler() const;
95         FrameLoader* loader() const;
96         NavigationScheduler* navigationScheduler() const;
97         SelectionController* selection() const;
98         FrameTree* tree() const;
99         AnimationController* animation() const;
100         ScriptController* script();
101
102         RenderView* contentRenderer() const; // Root of the render tree for the document contained in this frame.
103         RenderPart* ownerRenderer() const; // Renderer for the element that contains this frame.
104
105         void transferChildFrameToNewDocument();
106
107     // ======== All public functions below this point are candidates to move out of Frame into another class. ========
108
109         bool isDisconnected() const;
110         void setIsDisconnected(bool);
111         bool excludeFromTextSearch() const;
112         void setExcludeFromTextSearch(bool);
113
114         void injectUserScripts(UserScriptInjectionTime);
115         
116         String layerTreeAsText() const;
117
118         // Unlike most accessors in this class, domWindow() always creates a new DOMWindow if m_domWindow is null.
119         // Callers that don't need a new DOMWindow to be created should use existingDOMWindow().
120         DOMWindow* domWindow() const;
121         DOMWindow* existingDOMWindow() { return m_domWindow.get(); }
122         void setDOMWindow(DOMWindow*);
123         void clearFormerDOMWindow(DOMWindow*);
124         void clearDOMWindow();
125
126         static Frame* frameForWidget(const Widget*);
127
128         Settings* settings() const; // can be NULL
129
130         enum AdjustViewSizeOrNot { DoNotAdjustViewSize, AdjustViewSize };
131         void setPrinting(bool printing, const FloatSize& pageSize, float maximumShrinkRatio, AdjustViewSizeOrNot);
132
133         bool inViewSourceMode() const;
134         void setInViewSourceMode(bool = true);
135
136         void keepAlive(); // Used to keep the frame alive when running a script that might destroy it.
137         static void cancelAllKeepAlive();
138
139         void setDocument(PassRefPtr<Document>);
140
141         void setPageZoomFactor(float factor);
142         float pageZoomFactor() const { return m_pageZoomFactor; }
143         void setTextZoomFactor(float factor);
144         float textZoomFactor() const { return m_textZoomFactor; }
145         void setPageAndTextZoomFactors(float pageZoomFactor, float textZoomFactor);
146
147         void scalePage(float scale);
148         float pageScaleFactor() const { return m_pageScaleFactor; }
149
150 #if ENABLE(ORIENTATION_EVENTS)
151         // Orientation is the interface orientation in degrees. Some examples are:
152         //  0 is straight up; -90 is when the device is rotated 90 clockwise;
153         //  90 is when rotated counter clockwise.
154         void sendOrientationChangeEvent(int orientation);
155         int orientation() const { return m_orientation; }
156 #endif
157
158         void clearTimers();
159         static void clearTimers(FrameView*, Document*);
160
161         String documentTypeString() const;
162
163         String displayStringModifiedByEncoding(const String& str) const
164         {
165             return document() ? document()->displayStringModifiedByEncoding(str) : str;
166         }
167
168         DragImageRef nodeImage(Node*);
169         DragImageRef dragImageForSelection();
170
171         bool isContentEditable() const; // if true, everything in frame is editable
172
173         VisiblePosition visiblePositionForPoint(const IntPoint& framePoint);
174         Document* documentAtPoint(const IntPoint& windowPoint);
175
176         String searchForLabelsAboveCell(RegularExpression*, HTMLTableCellElement*, size_t* resultDistanceFromStartOfCell);
177         String searchForLabelsBeforeElement(const Vector<String>& labels, Element*, size_t* resultDistance, bool* resultIsInCellAbove);
178         String matchLabelsAgainstElement(const Vector<String>& labels, Element*);
179
180 #if PLATFORM(MAC)
181         NSString* searchForLabelsBeforeElement(NSArray* labels, Element*, size_t* resultDistance, bool* resultIsInCellAbove);
182         NSString* matchLabelsAgainstElement(NSArray* labels, Element*);
183
184         NSImage* selectionImage(bool forceBlackText = false) const;
185         NSImage* snapshotDragImage(Node*, NSRect* imageRect, NSRect* elementRect) const;
186         NSImage* imageFromRect(NSRect) const;
187 #endif
188
189     // ========
190
191     private:
192         Frame(Page*, HTMLFrameOwnerElement*, FrameLoaderClient*);
193
194         void injectUserScriptsForWorld(DOMWrapperWorld*, const UserScriptVector&, UserScriptInjectionTime);
195         void lifeSupportTimerFired(Timer<Frame>*);
196
197         Page* m_page;
198         mutable FrameTree m_treeNode;
199         mutable FrameLoader m_loader;
200         mutable NavigationScheduler m_navigationScheduler;
201
202         mutable RefPtr<DOMWindow> m_domWindow;
203         HashSet<DOMWindow*> m_liveFormerWindows;
204
205         HTMLFrameOwnerElement* m_ownerElement;
206         RefPtr<FrameView> m_view;
207         RefPtr<Document> m_doc;
208
209         ScriptController m_script;
210
211         mutable Editor m_editor;
212         mutable SelectionController m_selectionController;
213         mutable EventHandler m_eventHandler;
214         mutable AnimationController m_animationController;
215
216         Timer<Frame> m_lifeSupportTimer;
217
218         float m_pageZoomFactor;
219         float m_textZoomFactor;
220
221         float m_pageScaleFactor;
222
223 #if ENABLE(ORIENTATION_EVENTS)
224         int m_orientation;
225 #endif
226
227         bool m_inViewSourceMode;
228         bool m_isDisconnected;
229         bool m_excludeFromTextSearch;
230
231 #if ENABLE(TILED_BACKING_STORE)
232     // FIXME: The tiled backing store belongs in FrameView, not Frame.
233
234     public:
235         TiledBackingStore* tiledBackingStore() const { return m_tiledBackingStore.get(); }
236         void setTiledBackingStoreEnabled(bool);
237
238     private:
239         // TiledBackingStoreClient interface
240         virtual void tiledBackingStorePaintBegin();
241         virtual void tiledBackingStorePaint(GraphicsContext*, const IntRect&);
242         virtual void tiledBackingStorePaintEnd(const Vector<IntRect>& paintedArea);
243         virtual IntRect tiledBackingStoreContentsRect();
244         virtual IntRect tiledBackingStoreVisibleRect();
245         virtual Color tiledBackingStoreBackgroundColor() const;
246
247         OwnPtr<TiledBackingStore> m_tiledBackingStore;
248 #endif
249     };
250
251     inline void Frame::init()
252     {
253         m_loader.init();
254     }
255
256     inline FrameLoader* Frame::loader() const
257     {
258         return &m_loader;
259     }
260
261     inline NavigationScheduler* Frame::navigationScheduler() const
262     {
263         return &m_navigationScheduler;
264     }
265
266     inline FrameView* Frame::view() const
267     {
268         return m_view.get();
269     }
270
271     inline ScriptController* Frame::script()
272     {
273         return &m_script;
274     }
275
276     inline Document* Frame::document() const
277     {
278         return m_doc.get();
279     }
280
281     inline SelectionController* Frame::selection() const
282     {
283         return &m_selectionController;
284     }
285
286     inline Editor* Frame::editor() const
287     {
288         return &m_editor;
289     }
290
291     inline AnimationController* Frame::animation() const
292     {
293         return &m_animationController;
294     }
295
296     inline HTMLFrameOwnerElement* Frame::ownerElement() const
297     {
298         return m_ownerElement;
299     }
300
301     inline bool Frame::isDisconnected() const
302     {
303         return m_isDisconnected;
304     }
305
306     inline void Frame::setIsDisconnected(bool isDisconnected)
307     {
308         m_isDisconnected = isDisconnected;
309     }
310
311     inline bool Frame::excludeFromTextSearch() const
312     {
313         return m_excludeFromTextSearch;
314     }
315
316     inline void Frame::setExcludeFromTextSearch(bool exclude)
317     {
318         m_excludeFromTextSearch = exclude;
319     }
320
321     inline bool Frame::inViewSourceMode() const
322     {
323         return m_inViewSourceMode;
324     }
325
326     inline void Frame::setInViewSourceMode(bool mode)
327     {
328         m_inViewSourceMode = mode;
329     }
330
331     inline FrameTree* Frame::tree() const
332     {
333         return &m_treeNode;
334     }
335
336     inline Page* Frame::page() const
337     {
338         return m_page;
339     }
340
341     inline void Frame::detachFromPage()
342     {
343         m_page = 0;
344     }
345
346     inline EventHandler* Frame::eventHandler() const
347     {
348         return &m_eventHandler;
349     }
350
351 } // namespace WebCore
352
353 #endif // Frame_h