Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / frame / LocalFrame.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 LocalFrame_h
29 #define LocalFrame_h
30
31 #include "core/frame/Frame.h"
32 #include "core/loader/FrameLoader.h"
33 #include "core/loader/NavigationScheduler.h"
34 #include "core/page/FrameTree.h"
35 #include "platform/Supplementable.h"
36 #include "platform/heap/Handle.h"
37 #include "platform/scroll/ScrollTypes.h"
38
39 namespace WebCore {
40
41     class Color;
42     class Document;
43     class DragImage;
44     class Editor;
45     class EventHandler;
46     class FetchContext;
47     class FloatSize;
48     class FrameConsole;
49     class FrameSelection;
50     class FrameView;
51     class InputMethodController;
52     class IntPoint;
53     class IntSize;
54     class Node;
55     class Range;
56     class RenderView;
57     class TreeScope;
58     class ScriptController;
59     class SpellChecker;
60     class TreeScope;
61     class VisiblePosition;
62
63     class LocalFrame : public Frame, public Supplementable<LocalFrame>  {
64     public:
65         static PassRefPtr<LocalFrame> create(FrameLoaderClient*, FrameHost*, HTMLFrameOwnerElement*);
66
67         virtual bool isLocalFrame() const OVERRIDE { return true; }
68
69         void init();
70         void setView(PassRefPtr<FrameView>);
71         void createView(const IntSize&, const Color&, bool,
72             ScrollbarMode = ScrollbarAuto, bool horizontalLock = false,
73             ScrollbarMode = ScrollbarAuto, bool verticalLock = false);
74
75         virtual ~LocalFrame();
76
77         virtual void willDetachFrameHost() OVERRIDE;
78         virtual void detachFromFrameHost() OVERRIDE;
79
80         virtual void disconnectOwnerElement() OVERRIDE;
81
82         virtual void setDOMWindow(PassRefPtrWillBeRawPtr<DOMWindow>) OVERRIDE;
83         FrameView* view() const;
84         Document* document() const;
85
86         RenderView* contentRenderer() const; // Root of the render tree for the document contained in this frame.
87
88         Editor& editor() const;
89         EventHandler& eventHandler() const;
90         FrameLoader& loader() const;
91         FrameTree& tree() const;
92         NavigationScheduler& navigationScheduler() const;
93         FrameSelection& selection() const;
94         InputMethodController& inputMethodController() const;
95         FetchContext& fetchContext() const { return loader().fetchContext(); }
96         ScriptController& script();
97         SpellChecker& spellChecker() const;
98         FrameConsole& console() const;
99
100         void didChangeVisibilityState();
101
102         // FIXME: This method is only used by EventHandler to get the highest level
103         // LocalFrame in this frame's in-process subtree. When user gesture tokens
104         // are synchronized across processes this method should be removed.
105         LocalFrame* localFrameRoot();
106
107     // ======== All public functions below this point are candidates to move out of LocalFrame into another class. ========
108
109         bool inScope(TreeScope*) const;
110
111         void countObjectsNeedingLayout(unsigned& needsLayoutObjects, unsigned& totalObjects, bool& isPartial);
112
113         // See GraphicsLayerClient.h for accepted flags.
114         String layerTreeAsText(unsigned flags = 0) const;
115         String trackedRepaintRectsAsText() const;
116
117         void setPrinting(bool printing, const FloatSize& pageSize, const FloatSize& originalPageSize, float maximumShrinkRatio);
118         bool shouldUsePrintingLayout() const;
119         FloatSize resizePageRectsKeepingRatio(const FloatSize& originalSize, const FloatSize& expectedSize);
120
121         bool inViewSourceMode() const;
122         void setInViewSourceMode(bool = true);
123
124         void setPageZoomFactor(float factor);
125         float pageZoomFactor() const { return m_pageZoomFactor; }
126         void setTextZoomFactor(float factor);
127         float textZoomFactor() const { return m_textZoomFactor; }
128         void setPageAndTextZoomFactors(float pageZoomFactor, float textZoomFactor);
129
130         void deviceOrPageScaleFactorChanged();
131         double devicePixelRatio() const;
132
133         void sendOrientationChangeEvent();
134
135         String documentTypeString() const;
136
137         PassOwnPtr<DragImage> nodeImage(Node&);
138         PassOwnPtr<DragImage> dragImageForSelection();
139
140         String selectedText() const;
141         String selectedTextForClipboard() const;
142
143         VisiblePosition visiblePositionForPoint(const IntPoint& framePoint);
144         Document* documentAtPoint(const IntPoint& windowPoint);
145         PassRefPtrWillBeRawPtr<Range> rangeForPoint(const IntPoint& framePoint);
146
147         // Should only be called on the main frame of a page.
148         void notifyChromeClientWheelEventHandlerCountChanged() const;
149
150         bool isURLAllowed(const KURL&) const;
151
152     // ========
153
154     private:
155         LocalFrame(FrameLoaderClient*, FrameHost*, HTMLFrameOwnerElement*);
156
157         mutable FrameTree m_treeNode;
158         mutable FrameLoader m_loader;
159         mutable NavigationScheduler m_navigationScheduler;
160
161         RefPtr<FrameView> m_view;
162
163         OwnPtr<ScriptController> m_script;
164         const OwnPtr<Editor> m_editor;
165         const OwnPtr<SpellChecker> m_spellChecker;
166         const OwnPtr<FrameSelection> m_selection;
167         const OwnPtr<EventHandler> m_eventHandler;
168         const OwnPtr<FrameConsole> m_console;
169         OwnPtr<InputMethodController> m_inputMethodController;
170
171         float m_pageZoomFactor;
172         float m_textZoomFactor;
173
174         bool m_inViewSourceMode;
175     };
176
177     inline void LocalFrame::init()
178     {
179         m_loader.init();
180     }
181
182     inline FrameLoader& LocalFrame::loader() const
183     {
184         return m_loader;
185     }
186
187     inline NavigationScheduler& LocalFrame::navigationScheduler() const
188     {
189         return m_navigationScheduler;
190     }
191
192     inline FrameView* LocalFrame::view() const
193     {
194         return m_view.get();
195     }
196
197     inline ScriptController& LocalFrame::script()
198     {
199         return *m_script;
200     }
201
202     inline FrameSelection& LocalFrame::selection() const
203     {
204         return *m_selection;
205     }
206
207     inline Editor& LocalFrame::editor() const
208     {
209         return *m_editor;
210     }
211
212     inline SpellChecker& LocalFrame::spellChecker() const
213     {
214         return *m_spellChecker;
215     }
216
217     inline FrameConsole& LocalFrame::console() const
218     {
219         return *m_console;
220     }
221
222     inline InputMethodController& LocalFrame::inputMethodController() const
223     {
224         return *m_inputMethodController;
225     }
226
227     inline bool LocalFrame::inViewSourceMode() const
228     {
229         return m_inViewSourceMode;
230     }
231
232     inline void LocalFrame::setInViewSourceMode(bool mode)
233     {
234         m_inViewSourceMode = mode;
235     }
236
237     inline FrameTree& LocalFrame::tree() const
238     {
239         return m_treeNode;
240     }
241
242     inline EventHandler& LocalFrame::eventHandler() const
243     {
244         ASSERT(m_eventHandler);
245         return *m_eventHandler;
246     }
247
248     DEFINE_TYPE_CASTS(LocalFrame, Frame, localFrame, localFrame->isLocalFrame(), localFrame.isLocalFrame());
249
250 } // namespace WebCore
251
252 // During refactoring, there are some places where we need to do type conversions that
253 // will not be needed once all instances of LocalFrame and RemoteFrame are sorted out.
254 // At that time this #define will be removed and all the uses of it will need to be corrected.
255 #define toLocalFrameTemporary toLocalFrame
256
257 #endif // LocalFrame_h