Upstream version 11.40.277.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 #include "wtf/HashSet.h"
39
40 namespace blink {
41
42     class Color;
43     class Document;
44     class DragImage;
45     class Editor;
46     class Element;
47     class EventHandler;
48     class FetchContext;
49     class FloatSize;
50     class FrameConsole;
51     class FrameDestructionObserver;
52     class FrameSelection;
53     class FrameView;
54     class HTMLPlugInElement;
55     class InputMethodController;
56     class IntPoint;
57     class IntSize;
58     class Node;
59     class Range;
60     class RenderView;
61     class TreeScope;
62     class ScriptController;
63     class SpellChecker;
64     class TreeScope;
65     class VisiblePosition;
66
67     class LocalFrame : public Frame, public WillBeHeapSupplementable<LocalFrame> {
68         WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(LocalFrame);
69     public:
70         static PassRefPtrWillBeRawPtr<LocalFrame> create(FrameLoaderClient*, FrameHost*, FrameOwner*);
71
72         void init();
73         void setView(PassRefPtrWillBeRawPtr<FrameView>);
74         void createView(const IntSize&, const Color&, bool,
75             ScrollbarMode = ScrollbarAuto, bool horizontalLock = false,
76             ScrollbarMode = ScrollbarAuto, bool verticalLock = false);
77
78         // Frame overrides:
79         virtual ~LocalFrame();
80         virtual void trace(Visitor*) override;
81         virtual bool isLocalFrame() const override { return true; }
82         virtual LocalDOMWindow* domWindow() const override;
83         virtual void navigate(Document& originDocument, const KURL&, bool lockBackForwardList) override;
84         virtual void detach() override;
85         virtual void disconnectOwnerElement() override;
86
87         void addDestructionObserver(FrameDestructionObserver*);
88         void removeDestructionObserver(FrameDestructionObserver*);
89
90         void willDetachFrameHost();
91
92         void setDOMWindow(PassRefPtrWillBeRawPtr<LocalDOMWindow>);
93         FrameView* view() const;
94         Document* document() const;
95         void setPagePopupOwner(Element&);
96         Element* pagePopupOwner() const { return m_pagePopupOwner.get(); }
97
98         RenderView* contentRenderer() const; // Root of the render tree for the document contained in this frame.
99
100         Editor& editor() const;
101         EventHandler& eventHandler() const;
102         FrameLoader& loader() const;
103         NavigationScheduler& navigationScheduler() const;
104         FrameSelection& selection() const;
105         InputMethodController& inputMethodController() const;
106         FetchContext& fetchContext() const { return loader().fetchContext(); }
107         ScriptController& script() const;
108         SpellChecker& spellChecker() const;
109         FrameConsole& console() const;
110
111         void didChangeVisibilityState();
112
113         // This method is used to get the highest level LocalFrame in this
114         // frame's in-process subtree.
115         // FIXME: This is a temporary hack to support RemoteFrames, and callers
116         // should be updated to avoid storing things on the main frame.
117         LocalFrame* localFrameRoot();
118
119     // ======== All public functions below this point are candidates to move out of LocalFrame into another class. ========
120
121         bool inScope(TreeScope*) const;
122
123         void countObjectsNeedingLayout(unsigned& needsLayoutObjects, unsigned& totalObjects, bool& isPartial);
124
125         // See GraphicsLayerClient.h for accepted flags.
126         String layerTreeAsText(unsigned flags = 0) const;
127
128         void setPrinting(bool printing, const FloatSize& pageSize, const FloatSize& originalPageSize, float maximumShrinkRatio);
129         bool shouldUsePrintingLayout() const;
130         FloatSize resizePageRectsKeepingRatio(const FloatSize& originalSize, const FloatSize& expectedSize);
131
132         bool inViewSourceMode() const;
133         void setInViewSourceMode(bool = true);
134
135         void setPageZoomFactor(float factor);
136         float pageZoomFactor() const { return m_pageZoomFactor; }
137         void setTextZoomFactor(float factor);
138         float textZoomFactor() const { return m_textZoomFactor; }
139         void setPageAndTextZoomFactors(float pageZoomFactor, float textZoomFactor);
140
141         void deviceOrPageScaleFactorChanged();
142         double devicePixelRatio() const;
143
144         String documentTypeString() const;
145
146         PassOwnPtr<DragImage> nodeImage(Node&);
147         PassOwnPtr<DragImage> dragImageForSelection();
148
149         String selectedText() const;
150         String selectedTextForClipboard() const;
151
152         VisiblePosition visiblePositionForPoint(const IntPoint& framePoint);
153         Document* documentAtPoint(const IntPoint& windowPoint);
154         PassRefPtrWillBeRawPtr<Range> rangeForPoint(const IntPoint& framePoint);
155
156         bool isURLAllowed(const KURL&) const;
157         bool shouldReuseDefaultView(const KURL&) const;
158         void removeSpellingMarkersUnderWords(const Vector<String>& words);
159
160 #if ENABLE(OILPAN)
161         void registerPluginElement(HTMLPlugInElement*);
162         void unregisterPluginElement(HTMLPlugInElement*);
163         void clearWeakMembers(Visitor*);
164 #endif
165
166     // ========
167
168     private:
169         LocalFrame(FrameLoaderClient*, FrameHost*, FrameOwner*);
170
171         String localLayerTreeAsText(unsigned flags) const;
172
173         void detachView();
174
175         WillBeHeapHashSet<RawPtrWillBeWeakMember<FrameDestructionObserver> > m_destructionObservers;
176         mutable FrameLoader m_loader;
177         mutable NavigationScheduler m_navigationScheduler;
178
179         RefPtrWillBeMember<FrameView> m_view;
180         RefPtrWillBeMember<LocalDOMWindow> m_domWindow;
181         // Usually 0. Non-null if this is the top frame of PagePopup.
182         RefPtrWillBeMember<Element> m_pagePopupOwner;
183
184         const OwnPtrWillBeMember<ScriptController> m_script;
185         const OwnPtrWillBeMember<Editor> m_editor;
186         const OwnPtrWillBeMember<SpellChecker> m_spellChecker;
187         const OwnPtrWillBeMember<FrameSelection> m_selection;
188         const OwnPtrWillBeMember<EventHandler> m_eventHandler;
189         const OwnPtrWillBeMember<FrameConsole> m_console;
190         const OwnPtrWillBeMember<InputMethodController> m_inputMethodController;
191
192 #if ENABLE(OILPAN)
193         // Oilpan: in order to reliably finalize plugin elements with
194         // renderer-less plugins, the frame keeps track of them. When
195         // the frame is detached and disposed, these will be disposed
196         // of in the process. This is needed as the plugin element
197         // might not itself be attached to a DOM tree and be
198         // explicitly detached&disposed of.
199         //
200         // A weak reference is all wanted; the plugin element must
201         // otherwise be referenced and kept alive. So as to be able
202         // to process the set of weak references during the LocalFrame's
203         // weak callback, the set itself is not on the heap and the
204         // references are bare pointers (rather than WeakMembers.)
205         // See LocalFrame::clearWeakMembers().
206         HashSet<HTMLPlugInElement*> m_pluginElements;
207 #endif
208
209         float m_pageZoomFactor;
210         float m_textZoomFactor;
211
212         bool m_inViewSourceMode;
213     };
214
215     inline void LocalFrame::init()
216     {
217         m_loader.init();
218     }
219
220     inline FrameLoader& LocalFrame::loader() const
221     {
222         return m_loader;
223     }
224
225     inline NavigationScheduler& LocalFrame::navigationScheduler() const
226     {
227         return m_navigationScheduler;
228     }
229
230     inline FrameView* LocalFrame::view() const
231     {
232         return m_view.get();
233     }
234
235     inline ScriptController& LocalFrame::script() const
236     {
237         return *m_script;
238     }
239
240     inline FrameSelection& LocalFrame::selection() const
241     {
242         return *m_selection;
243     }
244
245     inline Editor& LocalFrame::editor() const
246     {
247         return *m_editor;
248     }
249
250     inline SpellChecker& LocalFrame::spellChecker() const
251     {
252         return *m_spellChecker;
253     }
254
255     inline FrameConsole& LocalFrame::console() const
256     {
257         return *m_console;
258     }
259
260     inline InputMethodController& LocalFrame::inputMethodController() const
261     {
262         return *m_inputMethodController;
263     }
264
265     inline bool LocalFrame::inViewSourceMode() const
266     {
267         return m_inViewSourceMode;
268     }
269
270     inline void LocalFrame::setInViewSourceMode(bool mode)
271     {
272         m_inViewSourceMode = mode;
273     }
274
275     inline EventHandler& LocalFrame::eventHandler() const
276     {
277         ASSERT(m_eventHandler);
278         return *m_eventHandler;
279     }
280
281     DEFINE_TYPE_CASTS(LocalFrame, Frame, localFrame, localFrame->isLocalFrame(), localFrame.isLocalFrame());
282
283 } // namespace blink
284
285 // During refactoring, there are some places where we need to do type conversions that
286 // will not be needed once all instances of LocalFrame and RemoteFrame are sorted out.
287 // At that time this #define will be removed and all the uses of it will need to be corrected.
288 #define toLocalFrameTemporary toLocalFrame
289
290 #endif // LocalFrame_h