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