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