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