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 "AdjustViewSizeOrNot.h"
32 #include "AnimationController.h"
33 #include "DragImage.h"
35 #include "EventHandler.h"
36 #include "FrameLoader.h"
37 #include "FrameSelection.h"
38 #include "FrameTree.h"
39 #include "NavigationScheduler.h"
40 #include "ScriptController.h"
41 #include "UserScriptTypes.h"
47 #if ENABLE(TILED_BACKING_STORE)
48 #include "TiledBackingStoreClient.h"
54 class NSMutableDictionary;
60 typedef struct HBITMAP__* HBITMAP;
67 class HTMLTableCellElement;
68 class MediaStreamFrameController;
69 class RegularExpression;
71 class TiledBackingStore;
73 #if !ENABLE(TILED_BACKING_STORE)
74 class TiledBackingStoreClient { };
77 class FrameDestructionObserver {
79 virtual ~FrameDestructionObserver() { }
81 virtual void frameDestroyed() = 0;
84 class Frame : public RefCounted<Frame>, public TiledBackingStoreClient {
86 static PassRefPtr<Frame> create(Page*, HTMLFrameOwnerElement*, FrameLoaderClient*);
89 void setView(PassRefPtr<FrameView>);
90 void createView(const IntSize&, const Color&, bool, const IntSize&, bool,
91 ScrollbarMode = ScrollbarAuto, bool horizontalLock = false,
92 ScrollbarMode = ScrollbarAuto, bool verticalLock = false);
96 void addDestructionObserver(FrameDestructionObserver*);
97 void removeDestructionObserver(FrameDestructionObserver*);
99 void detachFromPage();
100 void pageDestroyed();
101 void disconnectOwnerElement();
104 HTMLFrameOwnerElement* ownerElement() const;
106 Document* document() const;
107 FrameView* view() const;
109 Editor* editor() const;
110 EventHandler* eventHandler() const;
111 FrameLoader* loader() const;
112 NavigationScheduler* navigationScheduler() const;
113 FrameSelection* selection() const;
114 FrameTree* tree() const;
115 AnimationController* animation() const;
116 ScriptController* script();
118 RenderView* contentRenderer() const; // Root of the render tree for the document contained in this frame.
119 RenderPart* ownerRenderer() const; // Renderer for the element that contains this frame.
121 void transferChildFrameToNewDocument();
123 #if ENABLE(PAGE_VISIBILITY_API)
124 void dispatchVisibilityStateChangeEvent();
127 // ======== All public functions below this point are candidates to move out of Frame into another class. ========
129 bool isDisconnected() const;
130 void setIsDisconnected(bool);
131 bool excludeFromTextSearch() const;
132 void setExcludeFromTextSearch(bool);
134 void injectUserScripts(UserScriptInjectionTime);
136 String layerTreeAsText(bool showDebugInfo = false) const;
138 // Unlike most accessors in this class, domWindow() always creates a new DOMWindow if m_domWindow is null.
139 // Callers that don't need a new DOMWindow to be created should use existingDOMWindow().
140 DOMWindow* domWindow() const;
141 DOMWindow* existingDOMWindow() { return m_domWindow.get(); }
142 void setDOMWindow(DOMWindow*);
143 void clearFormerDOMWindow(DOMWindow*);
144 void clearDOMWindow();
146 static Frame* frameForWidget(const Widget*);
148 Settings* settings() const; // can be NULL
150 void setPrinting(bool printing, const FloatSize& pageSize, float maximumShrinkRatio, AdjustViewSizeOrNot);
151 FloatSize resizePageRectsKeepingRatio(const FloatSize& originalSize, const FloatSize& expectedSize);
153 bool inViewSourceMode() const;
154 void setInViewSourceMode(bool = true);
156 void setDocument(PassRefPtr<Document>);
158 void setPageZoomFactor(float factor);
159 float pageZoomFactor() const { return m_pageZoomFactor; }
160 void setTextZoomFactor(float factor);
161 float textZoomFactor() const { return m_textZoomFactor; }
162 void setPageAndTextZoomFactors(float pageZoomFactor, float textZoomFactor);
164 // Convenience helper method that grabs the pageScaleFactor from Page.
165 float pageScaleFactor() const;
167 #if USE(ACCELERATED_COMPOSITING)
168 void deviceOrPageScaleFactorChanged();
171 #if ENABLE(ORIENTATION_EVENTS)
172 // Orientation is the interface orientation in degrees. Some examples are:
173 // 0 is straight up; -90 is when the device is rotated 90 clockwise;
174 // 90 is when rotated counter clockwise.
175 void sendOrientationChangeEvent(int orientation);
176 int orientation() const { return m_orientation; }
180 static void clearTimers(FrameView*, Document*);
182 String documentTypeString() const;
184 String displayStringModifiedByEncoding(const String&) const;
186 DragImageRef nodeImage(Node*);
187 DragImageRef dragImageForSelection();
189 VisiblePosition visiblePositionForPoint(const LayoutPoint& framePoint);
190 Document* documentAtPoint(const LayoutPoint& windowPoint);
191 PassRefPtr<Range> rangeForPoint(const LayoutPoint& framePoint);
193 String searchForLabelsAboveCell(RegularExpression*, HTMLTableCellElement*, size_t* resultDistanceFromStartOfCell);
194 String searchForLabelsBeforeElement(const Vector<String>& labels, Element*, size_t* resultDistance, bool* resultIsInCellAbove);
195 String matchLabelsAgainstElement(const Vector<String>& labels, Element*);
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(); }
210 // Should only be called on the main frame of a page.
211 void notifyChromeClientWheelEventHandlerCountChanged() const;
216 Frame(Page*, HTMLFrameOwnerElement*, FrameLoaderClient*);
218 void injectUserScriptsForWorld(DOMWrapperWorld*, const UserScriptVector&, UserScriptInjectionTime);
220 HashSet<FrameDestructionObserver*> m_destructionObservers;
223 mutable FrameTree m_treeNode;
224 mutable FrameLoader m_loader;
225 mutable NavigationScheduler m_navigationScheduler;
227 mutable RefPtr<DOMWindow> m_domWindow;
228 HashSet<DOMWindow*> m_liveFormerWindows;
230 HTMLFrameOwnerElement* m_ownerElement;
231 RefPtr<FrameView> m_view;
232 RefPtr<Document> m_doc;
234 ScriptController m_script;
236 mutable Editor m_editor;
237 mutable FrameSelection m_selection;
238 mutable EventHandler m_eventHandler;
239 mutable AnimationController m_animationController;
241 float m_pageZoomFactor;
242 float m_textZoomFactor;
244 #if ENABLE(ORIENTATION_EVENTS)
248 bool m_inViewSourceMode;
249 bool m_isDisconnected;
250 bool m_excludeFromTextSearch;
252 #if ENABLE(TILED_BACKING_STORE)
253 // FIXME: The tiled backing store belongs in FrameView, not Frame.
256 TiledBackingStore* tiledBackingStore() const { return m_tiledBackingStore.get(); }
257 void setTiledBackingStoreEnabled(bool);
260 // TiledBackingStoreClient interface
261 virtual void tiledBackingStorePaintBegin();
262 virtual void tiledBackingStorePaint(GraphicsContext*, const IntRect&);
263 virtual void tiledBackingStorePaintEnd(const Vector<IntRect>& paintedArea);
264 virtual IntRect tiledBackingStoreContentsRect();
265 virtual IntRect tiledBackingStoreVisibleRect();
266 virtual Color tiledBackingStoreBackgroundColor() const;
268 OwnPtr<TiledBackingStore> m_tiledBackingStore;
271 #if ENABLE(MEDIA_STREAM)
272 OwnPtr<MediaStreamFrameController> m_mediaStreamFrameController;
276 inline void Frame::init()
281 inline FrameLoader* Frame::loader() const
286 inline NavigationScheduler* Frame::navigationScheduler() const
288 return &m_navigationScheduler;
291 inline FrameView* Frame::view() const
296 inline ScriptController* Frame::script()
301 inline Document* Frame::document() const
306 inline FrameSelection* Frame::selection() const
311 inline Editor* Frame::editor() const
316 inline AnimationController* Frame::animation() const
318 return &m_animationController;
321 inline HTMLFrameOwnerElement* Frame::ownerElement() const
323 return m_ownerElement;
326 inline bool Frame::isDisconnected() const
328 return m_isDisconnected;
331 inline void Frame::setIsDisconnected(bool isDisconnected)
333 m_isDisconnected = isDisconnected;
336 inline bool Frame::excludeFromTextSearch() const
338 return m_excludeFromTextSearch;
341 inline void Frame::setExcludeFromTextSearch(bool exclude)
343 m_excludeFromTextSearch = exclude;
346 inline bool Frame::inViewSourceMode() const
348 return m_inViewSourceMode;
351 inline void Frame::setInViewSourceMode(bool mode)
353 m_inViewSourceMode = mode;
356 inline FrameTree* Frame::tree() const
361 inline Page* Frame::page() const
366 inline void Frame::detachFromPage()
371 inline EventHandler* Frame::eventHandler() const
373 return &m_eventHandler;
376 } // namespace WebCore