Merge "[CherryPick] Refactoring: Move the content of HTMLInputElement::subtreeHasChan...
[framework/web/webkit-efl.git] / 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 USE(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 FrameDestructionObserver;
67     class FrameView;
68     class HTMLTableCellElement;
69     class MemoryObjectInfo;
70     class RegularExpression;
71     class RenderPart;
72     class TiledBackingStore;
73
74 #if !USE(TILED_BACKING_STORE)
75     class TiledBackingStoreClient { };
76 #endif
77
78     class TreeScope;
79
80     class Frame : public RefCounted<Frame>, public TiledBackingStoreClient {
81     public:
82         static PassRefPtr<Frame> create(Page*, HTMLFrameOwnerElement*, FrameLoaderClient*);
83
84         void init();
85         void setView(PassRefPtr<FrameView>);
86         void createView(const IntSize&, const Color&, bool,
87             const IntSize& fixedLayoutSize = IntSize(), const IntRect& fixedVisibleContentRect = IntRect(),
88             bool useFixedLayout = false, ScrollbarMode = ScrollbarAuto, bool horizontalLock = false,
89             ScrollbarMode = ScrollbarAuto, bool verticalLock = false);
90
91         ~Frame();
92
93         void addDestructionObserver(FrameDestructionObserver*);
94         void removeDestructionObserver(FrameDestructionObserver*);
95
96         void willDetachPage();
97         void detachFromPage();
98         void disconnectOwnerElement();
99
100         Page* page() const;
101         HTMLFrameOwnerElement* ownerElement() const;
102
103         Document* document() const;
104         FrameView* view() const;
105
106         Editor* editor() const;
107         EventHandler* eventHandler() const;
108         FrameLoader* loader() const;
109         NavigationScheduler* navigationScheduler() const;
110         FrameSelection* selection() const;
111         FrameTree* tree() const;
112         AnimationController* animation() const;
113         ScriptController* script();
114         
115         RenderView* contentRenderer() const; // Root of the render tree for the document contained in this frame.
116         RenderPart* ownerRenderer() const; // Renderer for the element that contains this frame.
117
118 #if ENABLE(PAGE_VISIBILITY_API)
119         void dispatchVisibilityStateChangeEvent();
120 #endif
121
122         void reportMemoryUsage(MemoryObjectInfo*) const;
123
124     // ======== All public functions below this point are candidates to move out of Frame into another class. ========
125
126         bool inScope(TreeScope*) const;
127
128         void injectUserScripts(UserScriptInjectionTime);
129         
130         String layerTreeAsText(bool showDebugInfo = false) const;
131
132         // Unlike most accessors in this class, domWindow() always creates a new DOMWindow if m_domWindow is null.
133         // Callers that don't need a new DOMWindow to be created should use existingDOMWindow().
134         DOMWindow* domWindow() const;
135         DOMWindow* existingDOMWindow() { return m_domWindow.get(); }
136         void setDOMWindow(DOMWindow*);
137         void clearDOMWindow();
138         static Frame* frameForWidget(const Widget*);
139
140         Settings* settings() const; // can be NULL
141
142         void setPrinting(bool printing, const FloatSize& pageSize, const FloatSize& originalPageSize, float maximumShrinkRatio, AdjustViewSizeOrNot);
143         bool shouldUsePrintingLayout() const;
144         FloatSize resizePageRectsKeepingRatio(const FloatSize& originalSize, const FloatSize& expectedSize);
145
146         bool inViewSourceMode() const;
147         void setInViewSourceMode(bool = true);
148
149         void setDocument(PassRefPtr<Document>);
150
151         void setPageZoomFactor(float factor);
152         float pageZoomFactor() const { return m_pageZoomFactor; }
153         void setTextZoomFactor(float factor);
154         float textZoomFactor() const { return m_textZoomFactor; }
155         void setPageAndTextZoomFactors(float pageZoomFactor, float textZoomFactor);
156
157         // Scale factor of this frame with respect to the container.
158         float frameScaleFactor() const;
159
160 #if ENABLE(TIZEN_WEBKIT2_HISTORICAL_RESTORE_VISIBLE_CONTENT_RECT)
161         float contentsScaleFactor() const;
162 #endif
163
164 #if USE(ACCELERATED_COMPOSITING)
165         void deviceOrPageScaleFactorChanged();
166 #endif
167
168 #if ENABLE(ORIENTATION_EVENTS)
169         // Orientation is the interface orientation in degrees. Some examples are:
170         //  0 is straight up; -90 is when the device is rotated 90 clockwise;
171         //  90 is when rotated counter clockwise.
172         void sendOrientationChangeEvent(int orientation);
173         int orientation() const { return m_orientation; }
174 #endif
175
176         void clearTimers();
177         static void clearTimers(FrameView*, Document*);
178
179         String documentTypeString() const;
180
181         String displayStringModifiedByEncoding(const String&) const;
182
183         DragImageRef nodeImage(Node*);
184         DragImageRef dragImageForSelection();
185
186         VisiblePosition visiblePositionForPoint(const IntPoint& framePoint);
187         Document* documentAtPoint(const IntPoint& windowPoint);
188         PassRefPtr<Range> rangeForPoint(const IntPoint& framePoint);
189
190         String searchForLabelsAboveCell(RegularExpression*, HTMLTableCellElement*, size_t* resultDistanceFromStartOfCell);
191         String searchForLabelsBeforeElement(const Vector<String>& labels, Element*, size_t* resultDistance, bool* resultIsInCellAbove);
192         String matchLabelsAgainstElement(const Vector<String>& labels, Element*);
193
194 #if PLATFORM(MAC)
195         NSImage* selectionImage(bool forceBlackText = false) const;
196         NSImage* rangeImage(Range*, bool forceBlackText = false) const;
197         NSImage* snapshotDragImage(Node*, NSRect* imageRect, NSRect* elementRect) const;
198         NSImage* imageFromRect(NSRect) const;
199 #endif
200         void suspendActiveDOMObjectsAndAnimations();
201         void resumeActiveDOMObjectsAndAnimations();
202         bool activeDOMObjectsAndAnimationsSuspended() const { return m_activeDOMObjectsAndAnimationsSuspendedCount > 0; }
203
204         // Should only be called on the main frame of a page.
205         void notifyChromeClientWheelEventHandlerCountChanged() const;
206
207     // ========
208
209     private:
210         Frame(Page*, HTMLFrameOwnerElement*, FrameLoaderClient*);
211
212         void injectUserScriptsForWorld(DOMWrapperWorld*, const UserScriptVector&, UserScriptInjectionTime);
213
214         HashSet<FrameDestructionObserver*> m_destructionObservers;
215
216         Page* m_page;
217         mutable FrameTree m_treeNode;
218         mutable FrameLoader m_loader;
219         mutable NavigationScheduler m_navigationScheduler;
220
221         mutable RefPtr<DOMWindow> m_domWindow;
222
223         HTMLFrameOwnerElement* m_ownerElement;
224         RefPtr<FrameView> m_view;
225         RefPtr<Document> m_doc;
226
227         ScriptController m_script;
228
229         mutable Editor m_editor;
230         mutable FrameSelection m_selection;
231         mutable EventHandler m_eventHandler;
232         mutable AnimationController m_animationController;
233
234         float m_pageZoomFactor;
235         float m_textZoomFactor;
236
237 #if ENABLE(ORIENTATION_EVENTS)
238         int m_orientation;
239 #endif
240
241         bool m_inViewSourceMode;
242
243 #if USE(TILED_BACKING_STORE)
244     // FIXME: The tiled backing store belongs in FrameView, not Frame.
245
246     public:
247         TiledBackingStore* tiledBackingStore() const { return m_tiledBackingStore.get(); }
248         void setTiledBackingStoreEnabled(bool);
249
250     private:
251         // TiledBackingStoreClient interface
252         virtual void tiledBackingStorePaintBegin();
253         virtual void tiledBackingStorePaint(GraphicsContext*, const IntRect&);
254         virtual void tiledBackingStorePaintEnd(const Vector<IntRect>& paintedArea);
255         virtual IntRect tiledBackingStoreContentsRect();
256         virtual IntRect tiledBackingStoreVisibleRect();
257         virtual Color tiledBackingStoreBackgroundColor() const;
258 #if ENABLE(TIZEN_RECORDING_SURFACE_SET)
259         virtual bool recordingSurfaceSetEnableGet() { return false; }
260         virtual void dirtyRectInvalidate() {}
261 #if ENABLE(TIZEN_RECORDING_SURFACE_PAINT_THREAD)
262         virtual void scheduleUpdateTileBuffersAsync() {}
263 #endif
264 #endif
265         OwnPtr<TiledBackingStore> m_tiledBackingStore;
266 #endif
267
268         int m_activeDOMObjectsAndAnimationsSuspendedCount;
269     };
270
271     inline void Frame::init()
272     {
273         m_loader.init();
274     }
275
276     inline FrameLoader* Frame::loader() const
277     {
278         return &m_loader;
279     }
280
281     inline NavigationScheduler* Frame::navigationScheduler() const
282     {
283         return &m_navigationScheduler;
284     }
285
286     inline FrameView* Frame::view() const
287     {
288         return m_view.get();
289     }
290
291     inline ScriptController* Frame::script()
292     {
293         return &m_script;
294     }
295
296     inline Document* Frame::document() const
297     {
298         return m_doc.get();
299     }
300
301     inline FrameSelection* Frame::selection() const
302     {
303         return &m_selection;
304     }
305
306     inline Editor* Frame::editor() const
307     {
308         return &m_editor;
309     }
310
311     inline AnimationController* Frame::animation() const
312     {
313         return &m_animationController;
314     }
315
316     inline HTMLFrameOwnerElement* Frame::ownerElement() const
317     {
318         return m_ownerElement;
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