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 "AnimationController.h"
32 #include "DragImage.h"
34 #include "EventHandler.h"
35 #include "FrameLoader.h"
36 #include "FrameSelection.h"
37 #include "FrameTree.h"
38 #include "NavigationScheduler.h"
39 #include "ScriptController.h"
40 #include "UserScriptTypes.h"
46 #if ENABLE(TILED_BACKING_STORE)
47 #include "TiledBackingStoreClient.h"
53 class NSMutableDictionary;
59 typedef struct HBITMAP__* HBITMAP;
66 class HTMLTableCellElement;
67 class MediaStreamFrameController;
68 class RegularExpression;
70 class TiledBackingStore;
72 #if !ENABLE(TILED_BACKING_STORE)
73 class TiledBackingStoreClient { };
76 class FrameDestructionObserver {
78 virtual ~FrameDestructionObserver() { }
80 virtual void frameDestroyed() = 0;
83 class Frame : public RefCounted<Frame>, public TiledBackingStoreClient {
85 static PassRefPtr<Frame> create(Page*, HTMLFrameOwnerElement*, FrameLoaderClient*);
88 void setView(PassRefPtr<FrameView>);
89 void createView(const IntSize&, const Color&, bool, const IntSize&, bool,
90 ScrollbarMode = ScrollbarAuto, bool horizontalLock = false,
91 ScrollbarMode = ScrollbarAuto, bool verticalLock = false);
95 void addDestructionObserver(FrameDestructionObserver*);
96 void removeDestructionObserver(FrameDestructionObserver*);
98 void detachFromPage();
100 void disconnectOwnerElement();
103 HTMLFrameOwnerElement* ownerElement() const;
105 Document* document() const;
106 FrameView* view() const;
108 Editor* editor() const;
109 EventHandler* eventHandler() const;
110 FrameLoader* loader() const;
111 NavigationScheduler* navigationScheduler() const;
112 FrameSelection* selection() const;
113 FrameTree* tree() const;
114 AnimationController* animation() const;
115 ScriptController* script();
117 RenderView* contentRenderer() const; // Root of the render tree for the document contained in this frame.
118 RenderPart* ownerRenderer() const; // Renderer for the element that contains this frame.
120 void transferChildFrameToNewDocument();
122 #if ENABLE(PAGE_VISIBILITY_API)
123 void dispatchVisibilityStateChangeEvent();
126 // ======== All public functions below this point are candidates to move out of Frame into another class. ========
128 bool isDisconnected() const;
129 void setIsDisconnected(bool);
130 bool excludeFromTextSearch() const;
131 void setExcludeFromTextSearch(bool);
133 void injectUserScripts(UserScriptInjectionTime);
135 String layerTreeAsText(bool showDebugInfo = false) const;
137 // Unlike most accessors in this class, domWindow() always creates a new DOMWindow if m_domWindow is null.
138 // Callers that don't need a new DOMWindow to be created should use existingDOMWindow().
139 DOMWindow* domWindow() const;
140 DOMWindow* existingDOMWindow() { return m_domWindow.get(); }
141 void setDOMWindow(DOMWindow*);
142 void clearFormerDOMWindow(DOMWindow*);
143 void clearDOMWindow();
145 static Frame* frameForWidget(const Widget*);
147 Settings* settings() const; // can be NULL
149 enum AdjustViewSizeOrNot { DoNotAdjustViewSize, AdjustViewSize };
150 void setPrinting(bool printing, const FloatSize& pageSize, float maximumShrinkRatio, AdjustViewSizeOrNot);
152 bool inViewSourceMode() const;
153 void setInViewSourceMode(bool = true);
155 void keepAlive(); // Used to keep the frame alive when running a script that might destroy it.
156 static void cancelAllKeepAlive();
158 void setDocument(PassRefPtr<Document>);
160 void setPageZoomFactor(float factor);
161 float pageZoomFactor() const { return m_pageZoomFactor; }
162 void setTextZoomFactor(float factor);
163 float textZoomFactor() const { return m_textZoomFactor; }
164 void setPageAndTextZoomFactors(float pageZoomFactor, float textZoomFactor);
166 void scalePage(float scale, const IntPoint& origin);
167 float pageScaleFactor() const { return m_pageScaleFactor; }
169 #if ENABLE(ORIENTATION_EVENTS)
170 // Orientation is the interface orientation in degrees. Some examples are:
171 // 0 is straight up; -90 is when the device is rotated 90 clockwise;
172 // 90 is when rotated counter clockwise.
173 void sendOrientationChangeEvent(int orientation);
174 int orientation() const { return m_orientation; }
178 static void clearTimers(FrameView*, Document*);
180 String documentTypeString() const;
182 String displayStringModifiedByEncoding(const String&) const;
184 DragImageRef nodeImage(Node*);
185 DragImageRef dragImageForSelection();
187 VisiblePosition visiblePositionForPoint(const IntPoint& framePoint);
188 Document* documentAtPoint(const IntPoint& windowPoint);
189 PassRefPtr<Range> rangeForPoint(const IntPoint& framePoint);
191 String searchForLabelsAboveCell(RegularExpression*, HTMLTableCellElement*, size_t* resultDistanceFromStartOfCell);
192 String searchForLabelsBeforeElement(const Vector<String>& labels, Element*, size_t* resultDistance, bool* resultIsInCellAbove);
193 String matchLabelsAgainstElement(const Vector<String>& labels, Element*);
195 Color getDocumentBackgroundColor() const;
198 NSString* searchForLabelsBeforeElement(NSArray* labels, Element*, size_t* resultDistance, bool* resultIsInCellAbove);
199 NSString* matchLabelsAgainstElement(NSArray* labels, Element*);
201 NSImage* selectionImage(bool forceBlackText = false) const;
202 NSImage* snapshotDragImage(Node*, NSRect* imageRect, NSRect* elementRect) const;
203 NSImage* imageFromRect(NSRect) const;
206 #if ENABLE(MEDIA_STREAM)
207 MediaStreamFrameController* mediaStreamFrameController() const { return m_mediaStreamFrameController.get(); }
213 Frame(Page*, HTMLFrameOwnerElement*, FrameLoaderClient*);
215 void injectUserScriptsForWorld(DOMWrapperWorld*, const UserScriptVector&, UserScriptInjectionTime);
216 void lifeSupportTimerFired(Timer<Frame>*);
218 #if USE(ACCELERATED_COMPOSITING)
219 void updateContentsScale(float);
222 HashSet<FrameDestructionObserver*> m_destructionObservers;
225 mutable FrameTree m_treeNode;
226 mutable FrameLoader m_loader;
227 mutable NavigationScheduler m_navigationScheduler;
229 mutable RefPtr<DOMWindow> m_domWindow;
230 HashSet<DOMWindow*> m_liveFormerWindows;
232 HTMLFrameOwnerElement* m_ownerElement;
233 RefPtr<FrameView> m_view;
234 RefPtr<Document> m_doc;
236 ScriptController m_script;
238 mutable Editor m_editor;
239 mutable FrameSelection m_selection;
240 mutable EventHandler m_eventHandler;
241 mutable AnimationController m_animationController;
243 Timer<Frame> m_lifeSupportTimer;
245 float m_pageZoomFactor;
246 float m_textZoomFactor;
248 float m_pageScaleFactor;
250 #if ENABLE(ORIENTATION_EVENTS)
254 bool m_inViewSourceMode;
255 bool m_isDisconnected;
256 bool m_excludeFromTextSearch;
258 #if ENABLE(TILED_BACKING_STORE)
259 // FIXME: The tiled backing store belongs in FrameView, not Frame.
262 TiledBackingStore* tiledBackingStore() const { return m_tiledBackingStore.get(); }
263 void setTiledBackingStoreEnabled(bool);
266 // TiledBackingStoreClient interface
267 virtual void tiledBackingStorePaintBegin();
268 virtual void tiledBackingStorePaint(GraphicsContext*, const IntRect&);
269 virtual void tiledBackingStorePaintEnd(const Vector<IntRect>& paintedArea);
270 virtual IntRect tiledBackingStoreContentsRect();
271 virtual IntRect tiledBackingStoreVisibleRect();
272 virtual Color tiledBackingStoreBackgroundColor() const;
274 OwnPtr<TiledBackingStore> m_tiledBackingStore;
277 #if ENABLE(MEDIA_STREAM)
278 OwnPtr<MediaStreamFrameController> m_mediaStreamFrameController;
282 inline void Frame::init()
287 inline FrameLoader* Frame::loader() const
292 inline NavigationScheduler* Frame::navigationScheduler() const
294 return &m_navigationScheduler;
297 inline FrameView* Frame::view() const
302 inline ScriptController* Frame::script()
307 inline Document* Frame::document() const
312 inline FrameSelection* Frame::selection() const
317 inline Editor* Frame::editor() const
322 inline AnimationController* Frame::animation() const
324 return &m_animationController;
327 inline HTMLFrameOwnerElement* Frame::ownerElement() const
329 return m_ownerElement;
332 inline bool Frame::isDisconnected() const
334 return m_isDisconnected;
337 inline void Frame::setIsDisconnected(bool isDisconnected)
339 m_isDisconnected = isDisconnected;
342 inline bool Frame::excludeFromTextSearch() const
344 return m_excludeFromTextSearch;
347 inline void Frame::setExcludeFromTextSearch(bool exclude)
349 m_excludeFromTextSearch = exclude;
352 inline bool Frame::inViewSourceMode() const
354 return m_inViewSourceMode;
357 inline void Frame::setInViewSourceMode(bool mode)
359 m_inViewSourceMode = mode;
362 inline FrameTree* Frame::tree() const
367 inline Page* Frame::page() const
372 inline void Frame::detachFromPage()
377 inline EventHandler* Frame::eventHandler() const
379 return &m_eventHandler;
382 } // namespace WebCore