Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / frame / 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 "core/loader/FrameLoader.h"
32 #include "core/loader/NavigationScheduler.h"
33 #include "core/page/FrameTree.h"
34 #include "platform/geometry/IntSize.h"
35 #include "platform/scroll/ScrollTypes.h"
36 #include "wtf/Forward.h"
37 #include "wtf/RefCounted.h"
38
39 namespace blink {
40 class WebLayer;
41 }
42
43 namespace WebCore {
44
45     class ChromeClient;
46     class Color;
47     class DOMWindow;
48     class Document;
49     class DragImage;
50     class Editor;
51     class Element;
52     class EventHandler;
53     class FetchContext;
54     class FloatSize;
55     class FrameDestructionObserver;
56     class FrameHost;
57     class FrameSelection;
58     class FrameView;
59     class HTMLFrameOwnerElement;
60     class HTMLTableCellElement;
61     class InputMethodController;
62     class IntPoint;
63     class Node;
64     class Page;
65     class Range;
66     class RenderPart;
67     class RenderView;
68     class TreeScope;
69     class ScriptController;
70     class Settings;
71     class SpellChecker;
72     class TreeScope;
73     class VisiblePosition;
74     class Widget;
75
76     class FrameInit : public RefCounted<FrameInit> {
77     public:
78         // For creating a dummy Frame
79         static PassRefPtr<FrameInit> create(int64_t frameID, FrameHost* host, FrameLoaderClient* client)
80         {
81             return adoptRef(new FrameInit(frameID, host, client));
82         }
83
84         int64_t frameID() const { return m_frameID; }
85
86         void setFrameHost(FrameHost* host) { m_frameHost = host; }
87         FrameHost* frameHost() const { return m_frameHost; }
88
89         void setFrameLoaderClient(FrameLoaderClient* client) { m_client = client; }
90         FrameLoaderClient* frameLoaderClient() const { return m_client; }
91
92         void setOwnerElement(HTMLFrameOwnerElement* ownerElement) { m_ownerElement = ownerElement; }
93         HTMLFrameOwnerElement* ownerElement() const { return m_ownerElement; }
94
95     protected:
96         FrameInit(int64_t frameID, FrameHost* host = 0, FrameLoaderClient* client = 0)
97             : m_frameID(frameID)
98             , m_client(client)
99             , m_frameHost(host)
100             , m_ownerElement(0)
101         {
102         }
103
104     private:
105         int64_t m_frameID;
106         FrameLoaderClient* m_client;
107         FrameHost* m_frameHost;
108         HTMLFrameOwnerElement* m_ownerElement;
109     };
110
111     class Frame : public RefCounted<Frame> {
112     public:
113         static PassRefPtr<Frame> create(PassRefPtr<FrameInit>);
114
115         void init();
116         void setView(PassRefPtr<FrameView>);
117         void createView(const IntSize&, const Color&, bool,
118             ScrollbarMode = ScrollbarAuto, bool horizontalLock = false,
119             ScrollbarMode = ScrollbarAuto, bool verticalLock = false);
120
121         ~Frame();
122
123         void addDestructionObserver(FrameDestructionObserver*);
124         void removeDestructionObserver(FrameDestructionObserver*);
125
126         void willDetachFrameHost();
127         void detachFromFrameHost();
128         void disconnectOwnerElement();
129
130         // NOTE: Page is moving out of Blink up into the browser process as
131         // part of the site-isolation (out of process iframes) work.
132         // FrameHost should be used instead where possible.
133         Page* page() const;
134         FrameHost* host() const; // Null when the frame is detached.
135
136         HTMLFrameOwnerElement* ownerElement() const;
137         bool isMainFrame() const;
138
139         void setDOMWindow(PassRefPtr<DOMWindow>);
140         DOMWindow* domWindow() const;
141         Document* document() const;
142         FrameView* view() const;
143
144         ChromeClient& chromeClient() const;
145         Editor& editor() const;
146         EventHandler& eventHandler() const;
147         FrameLoader& loader() const;
148         NavigationScheduler& navigationScheduler() const;
149         FrameSelection& selection() const;
150         FrameTree& tree() const;
151         InputMethodController& inputMethodController() const;
152         FetchContext& fetchContext() const { return loader().fetchContext(); }
153         ScriptController& script();
154         SpellChecker& spellChecker() const;
155
156         RenderView* contentRenderer() const; // Root of the render tree for the document contained in this frame.
157         RenderPart* ownerRenderer() const; // Renderer for the element that contains this frame.
158
159         void didChangeVisibilityState();
160
161         int64_t frameID() const { return m_frameInit->frameID(); }
162
163         // FIXME: These should move to RemoteFrame once that exists.
164         // RemotePlatformLayer is only ever set for Frames which exist in another process.
165         void setRemotePlatformLayer(blink::WebLayer* remotePlatformLayer) { m_remotePlatformLayer = remotePlatformLayer; }
166         blink::WebLayer* remotePlatformLayer() const { return m_remotePlatformLayer; }
167
168     // ======== All public functions below this point are candidates to move out of Frame into another class. ========
169
170         bool inScope(TreeScope*) const;
171
172         void countObjectsNeedingLayout(unsigned& needsLayoutObjects, unsigned& totalObjects, bool& isPartial);
173
174         // See GraphicsLayerClient.h for accepted flags.
175         String layerTreeAsText(unsigned flags = 0) const;
176         String trackedRepaintRectsAsText() const;
177
178         Settings* settings() const; // can be NULL
179
180         void setPrinting(bool printing, const FloatSize& pageSize, const FloatSize& originalPageSize, float maximumShrinkRatio);
181         bool shouldUsePrintingLayout() const;
182         FloatSize resizePageRectsKeepingRatio(const FloatSize& originalSize, const FloatSize& expectedSize);
183
184         bool inViewSourceMode() const;
185         void setInViewSourceMode(bool = true);
186
187         void setPageZoomFactor(float factor);
188         float pageZoomFactor() const { return m_pageZoomFactor; }
189         void setTextZoomFactor(float factor);
190         float textZoomFactor() const { return m_textZoomFactor; }
191         void setPageAndTextZoomFactors(float pageZoomFactor, float textZoomFactor);
192
193         void deviceOrPageScaleFactorChanged();
194         double devicePixelRatio() const;
195
196         // Orientation is the interface orientation in degrees. Some examples are:
197         //  0 is straight up; -90 is when the device is rotated 90 clockwise;
198         //  90 is when rotated counter clockwise.
199         void sendOrientationChangeEvent(int orientation);
200         int orientation() const { return m_orientation; }
201
202         String documentTypeString() const;
203
204         PassOwnPtr<DragImage> nodeImage(Node*);
205         PassOwnPtr<DragImage> dragImageForSelection();
206
207         String selectedText() const;
208         String selectedTextForClipboard() const;
209
210         VisiblePosition visiblePositionForPoint(const IntPoint& framePoint);
211         Document* documentAtPoint(const IntPoint& windowPoint);
212         PassRefPtr<Range> rangeForPoint(const IntPoint& framePoint);
213
214         // Should only be called on the main frame of a page.
215         void notifyChromeClientWheelEventHandlerCountChanged() const;
216
217         bool isURLAllowed(const KURL&) const;
218
219     // ========
220
221     private:
222         Frame(PassRefPtr<FrameInit>);
223
224         HashSet<FrameDestructionObserver*> m_destructionObservers;
225
226         FrameHost* m_host;
227         mutable FrameTree m_treeNode;
228         mutable FrameLoader m_loader;
229         mutable NavigationScheduler m_navigationScheduler;
230
231         RefPtr<FrameView> m_view;
232         RefPtr<DOMWindow> m_domWindow;
233
234         OwnPtr<ScriptController> m_script;
235         const OwnPtr<Editor> m_editor;
236         const OwnPtr<SpellChecker> m_spellChecker;
237         const OwnPtr<FrameSelection> m_selection;
238         const OwnPtr<EventHandler> m_eventHandler;
239         OwnPtr<InputMethodController> m_inputMethodController;
240
241         RefPtr<FrameInit> m_frameInit;
242
243         float m_pageZoomFactor;
244         float m_textZoomFactor;
245
246         int m_orientation;
247
248         bool m_inViewSourceMode;
249
250         blink::WebLayer* m_remotePlatformLayer;
251     };
252
253     inline void Frame::init()
254     {
255         m_loader.init();
256     }
257
258     inline FrameLoader& Frame::loader() const
259     {
260         return m_loader;
261     }
262
263     inline NavigationScheduler& Frame::navigationScheduler() const
264     {
265         return m_navigationScheduler;
266     }
267
268     inline FrameView* Frame::view() const
269     {
270         return m_view.get();
271     }
272
273     inline ScriptController& Frame::script()
274     {
275         return *m_script;
276     }
277
278     inline DOMWindow* Frame::domWindow() const
279     {
280         return m_domWindow.get();
281     }
282
283     inline FrameSelection& Frame::selection() const
284     {
285         return *m_selection;
286     }
287
288     inline Editor& Frame::editor() const
289     {
290         return *m_editor;
291     }
292
293     inline SpellChecker& Frame::spellChecker() const
294     {
295         return *m_spellChecker;
296     }
297
298     inline InputMethodController& Frame::inputMethodController() const
299     {
300         return *m_inputMethodController;
301     }
302
303     inline HTMLFrameOwnerElement* Frame::ownerElement() const
304     {
305         return m_frameInit->ownerElement();
306     }
307
308     inline bool Frame::inViewSourceMode() const
309     {
310         return m_inViewSourceMode;
311     }
312
313     inline void Frame::setInViewSourceMode(bool mode)
314     {
315         m_inViewSourceMode = mode;
316     }
317
318     inline FrameTree& Frame::tree() const
319     {
320         return m_treeNode;
321     }
322
323     inline EventHandler& Frame::eventHandler() const
324     {
325         ASSERT(m_eventHandler);
326         return *m_eventHandler;
327     }
328
329 } // namespace WebCore
330
331 #endif // Frame_h