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>
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.
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.
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.
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"
51 class FrameDestructionObserver;
54 class HTMLPlugInElement;
55 class InputMethodController;
62 class ScriptController;
65 class VisiblePosition;
67 class LocalFrame : public Frame, public WillBeHeapSupplementable<LocalFrame> {
68 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(LocalFrame);
70 static PassRefPtrWillBeRawPtr<LocalFrame> create(FrameLoaderClient*, FrameHost*, FrameOwner*);
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);
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;
87 void addDestructionObserver(FrameDestructionObserver*);
88 void removeDestructionObserver(FrameDestructionObserver*);
90 void willDetachFrameHost();
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(); }
98 RenderView* contentRenderer() const; // Root of the render tree for the document contained in this frame.
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;
111 void didChangeVisibilityState();
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();
119 // ======== All public functions below this point are candidates to move out of LocalFrame into another class. ========
121 bool inScope(TreeScope*) const;
123 void countObjectsNeedingLayout(unsigned& needsLayoutObjects, unsigned& totalObjects, bool& isPartial);
125 // See GraphicsLayerClient.h for accepted flags.
126 String layerTreeAsText(unsigned flags = 0) const;
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);
132 bool inViewSourceMode() const;
133 void setInViewSourceMode(bool = true);
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);
141 void deviceOrPageScaleFactorChanged();
142 double devicePixelRatio() const;
144 String documentTypeString() const;
146 PassOwnPtr<DragImage> nodeImage(Node&);
147 PassOwnPtr<DragImage> dragImageForSelection();
149 String selectedText() const;
150 String selectedTextForClipboard() const;
152 VisiblePosition visiblePositionForPoint(const IntPoint& framePoint);
153 Document* documentAtPoint(const IntPoint& windowPoint);
154 PassRefPtrWillBeRawPtr<Range> rangeForPoint(const IntPoint& framePoint);
156 bool isURLAllowed(const KURL&) const;
157 bool shouldReuseDefaultView(const KURL&) const;
158 void removeSpellingMarkersUnderWords(const Vector<String>& words);
161 void registerPluginElement(HTMLPlugInElement*);
162 void unregisterPluginElement(HTMLPlugInElement*);
163 void clearWeakMembers(Visitor*);
169 LocalFrame(FrameLoaderClient*, FrameHost*, FrameOwner*);
171 String localLayerTreeAsText(unsigned flags) const;
175 WillBeHeapHashSet<RawPtrWillBeWeakMember<FrameDestructionObserver> > m_destructionObservers;
176 mutable FrameLoader m_loader;
177 mutable NavigationScheduler m_navigationScheduler;
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;
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;
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.
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;
209 float m_pageZoomFactor;
210 float m_textZoomFactor;
212 bool m_inViewSourceMode;
215 inline void LocalFrame::init()
220 inline FrameLoader& LocalFrame::loader() const
225 inline NavigationScheduler& LocalFrame::navigationScheduler() const
227 return m_navigationScheduler;
230 inline FrameView* LocalFrame::view() const
235 inline ScriptController& LocalFrame::script() const
240 inline FrameSelection& LocalFrame::selection() const
245 inline Editor& LocalFrame::editor() const
250 inline SpellChecker& LocalFrame::spellChecker() const
252 return *m_spellChecker;
255 inline FrameConsole& LocalFrame::console() const
260 inline InputMethodController& LocalFrame::inputMethodController() const
262 return *m_inputMethodController;
265 inline bool LocalFrame::inViewSourceMode() const
267 return m_inViewSourceMode;
270 inline void LocalFrame::setInViewSourceMode(bool mode)
272 m_inViewSourceMode = mode;
275 inline EventHandler& LocalFrame::eventHandler() const
277 ASSERT(m_eventHandler);
278 return *m_eventHandler;
281 DEFINE_TYPE_CASTS(LocalFrame, Frame, localFrame, localFrame->isLocalFrame(), localFrame.isLocalFrame());
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
290 #endif // LocalFrame_h