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/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"
55 class FrameDestructionObserver;
59 class HTMLFrameOwnerElement;
60 class HTMLTableCellElement;
61 class InputMethodController;
69 class ScriptController;
73 class VisiblePosition;
76 class FrameInit : public RefCounted<FrameInit> {
78 // For creating a dummy Frame
79 static PassRefPtr<FrameInit> create(int64_t frameID, FrameHost* host, FrameLoaderClient* client)
81 return adoptRef(new FrameInit(frameID, host, client));
84 int64_t frameID() const { return m_frameID; }
86 void setFrameHost(FrameHost* host) { m_frameHost = host; }
87 FrameHost* frameHost() const { return m_frameHost; }
89 void setFrameLoaderClient(FrameLoaderClient* client) { m_client = client; }
90 FrameLoaderClient* frameLoaderClient() const { return m_client; }
92 void setOwnerElement(HTMLFrameOwnerElement* ownerElement) { m_ownerElement = ownerElement; }
93 HTMLFrameOwnerElement* ownerElement() const { return m_ownerElement; }
96 FrameInit(int64_t frameID, FrameHost* host = 0, FrameLoaderClient* client = 0)
106 FrameLoaderClient* m_client;
107 FrameHost* m_frameHost;
108 HTMLFrameOwnerElement* m_ownerElement;
111 class Frame : public RefCounted<Frame> {
113 static PassRefPtr<Frame> create(PassRefPtr<FrameInit>);
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);
123 void addDestructionObserver(FrameDestructionObserver*);
124 void removeDestructionObserver(FrameDestructionObserver*);
126 void willDetachFrameHost();
127 void detachFromFrameHost();
128 void disconnectOwnerElement();
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.
134 FrameHost* host() const; // Null when the frame is detached.
136 HTMLFrameOwnerElement* ownerElement() const;
137 bool isMainFrame() const;
139 void setDOMWindow(PassRefPtr<DOMWindow>);
140 DOMWindow* domWindow() const;
141 Document* document() const;
142 FrameView* view() const;
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;
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.
159 void didChangeVisibilityState();
161 int64_t frameID() const { return m_frameInit->frameID(); }
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; }
168 // ======== All public functions below this point are candidates to move out of Frame into another class. ========
170 bool inScope(TreeScope*) const;
172 void countObjectsNeedingLayout(unsigned& needsLayoutObjects, unsigned& totalObjects, bool& isPartial);
174 // See GraphicsLayerClient.h for accepted flags.
175 String layerTreeAsText(unsigned flags = 0) const;
176 String trackedRepaintRectsAsText() const;
178 Settings* settings() const; // can be NULL
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);
184 bool inViewSourceMode() const;
185 void setInViewSourceMode(bool = true);
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);
193 void deviceOrPageScaleFactorChanged();
194 double devicePixelRatio() const;
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; }
202 String documentTypeString() const;
204 PassOwnPtr<DragImage> nodeImage(Node*);
205 PassOwnPtr<DragImage> dragImageForSelection();
207 String selectedText() const;
208 String selectedTextForClipboard() const;
210 VisiblePosition visiblePositionForPoint(const IntPoint& framePoint);
211 Document* documentAtPoint(const IntPoint& windowPoint);
212 PassRefPtr<Range> rangeForPoint(const IntPoint& framePoint);
214 // Should only be called on the main frame of a page.
215 void notifyChromeClientWheelEventHandlerCountChanged() const;
217 bool isURLAllowed(const KURL&) const;
222 Frame(PassRefPtr<FrameInit>);
224 HashSet<FrameDestructionObserver*> m_destructionObservers;
227 mutable FrameTree m_treeNode;
228 mutable FrameLoader m_loader;
229 mutable NavigationScheduler m_navigationScheduler;
231 RefPtr<FrameView> m_view;
232 RefPtr<DOMWindow> m_domWindow;
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;
241 RefPtr<FrameInit> m_frameInit;
243 float m_pageZoomFactor;
244 float m_textZoomFactor;
248 bool m_inViewSourceMode;
250 blink::WebLayer* m_remotePlatformLayer;
253 inline void Frame::init()
258 inline FrameLoader& Frame::loader() const
263 inline NavigationScheduler& Frame::navigationScheduler() const
265 return m_navigationScheduler;
268 inline FrameView* Frame::view() const
273 inline ScriptController& Frame::script()
278 inline DOMWindow* Frame::domWindow() const
280 return m_domWindow.get();
283 inline FrameSelection& Frame::selection() const
288 inline Editor& Frame::editor() const
293 inline SpellChecker& Frame::spellChecker() const
295 return *m_spellChecker;
298 inline InputMethodController& Frame::inputMethodController() const
300 return *m_inputMethodController;
303 inline HTMLFrameOwnerElement* Frame::ownerElement() const
305 return m_frameInit->ownerElement();
308 inline bool Frame::inViewSourceMode() const
310 return m_inViewSourceMode;
313 inline void Frame::setInViewSourceMode(bool mode)
315 m_inViewSourceMode = mode;
318 inline FrameTree& Frame::tree() const
323 inline EventHandler& Frame::eventHandler() const
325 ASSERT(m_eventHandler);
326 return *m_eventHandler;
329 } // namespace WebCore