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 "FrameTree.h"
37 #include "ScriptController.h"
38 #include "UserScriptTypes.h"
44 #if ENABLE(TILED_BACKING_STORE)
45 #include "TiledBackingStoreClient.h"
51 class NSMutableDictionary;
57 typedef struct HBITMAP__* HBITMAP;
62 class HTMLTableCellElement;
63 class RegularExpression;
65 class TiledBackingStore;
67 #if !ENABLE(TILED_BACKING_STORE)
68 class TiledBackingStoreClient { };
71 class Frame : public RefCounted<Frame>, public TiledBackingStoreClient {
73 static PassRefPtr<Frame> create(Page*, HTMLFrameOwnerElement*, FrameLoaderClient*);
76 void setView(PassRefPtr<FrameView>);
77 void createView(const IntSize&, const Color&, bool, const IntSize&, bool,
78 ScrollbarMode = ScrollbarAuto, bool horizontalLock = false,
79 ScrollbarMode = ScrollbarAuto, bool verticalLock = false);
83 void detachFromPage();
85 void disconnectOwnerElement();
88 HTMLFrameOwnerElement* ownerElement() const;
90 Document* document() const;
91 FrameView* view() const;
93 Editor* editor() const;
94 EventHandler* eventHandler() const;
95 FrameLoader* loader() const;
96 NavigationScheduler* navigationScheduler() const;
97 SelectionController* selection() const;
98 FrameTree* tree() const;
99 AnimationController* animation() const;
100 ScriptController* script();
102 RenderView* contentRenderer() const; // Root of the render tree for the document contained in this frame.
103 RenderPart* ownerRenderer() const; // Renderer for the element that contains this frame.
105 void transferChildFrameToNewDocument();
107 // ======== All public functions below this point are candidates to move out of Frame into another class. ========
109 bool isDisconnected() const;
110 void setIsDisconnected(bool);
111 bool excludeFromTextSearch() const;
112 void setExcludeFromTextSearch(bool);
114 void injectUserScripts(UserScriptInjectionTime);
116 String layerTreeAsText() const;
118 // Unlike most accessors in this class, domWindow() always creates a new DOMWindow if m_domWindow is null.
119 // Callers that don't need a new DOMWindow to be created should use existingDOMWindow().
120 DOMWindow* domWindow() const;
121 DOMWindow* existingDOMWindow() { return m_domWindow.get(); }
122 void setDOMWindow(DOMWindow*);
123 void clearFormerDOMWindow(DOMWindow*);
124 void clearDOMWindow();
126 static Frame* frameForWidget(const Widget*);
128 Settings* settings() const; // can be NULL
130 enum AdjustViewSizeOrNot { DoNotAdjustViewSize, AdjustViewSize };
131 void setPrinting(bool printing, const FloatSize& pageSize, float maximumShrinkRatio, AdjustViewSizeOrNot);
133 bool inViewSourceMode() const;
134 void setInViewSourceMode(bool = true);
136 void keepAlive(); // Used to keep the frame alive when running a script that might destroy it.
137 static void cancelAllKeepAlive();
139 void setDocument(PassRefPtr<Document>);
141 void setPageZoomFactor(float factor);
142 float pageZoomFactor() const { return m_pageZoomFactor; }
143 void setTextZoomFactor(float factor);
144 float textZoomFactor() const { return m_textZoomFactor; }
145 void setPageAndTextZoomFactors(float pageZoomFactor, float textZoomFactor);
147 void scalePage(float scale);
148 float pageScaleFactor() const { return m_pageScaleFactor; }
150 #if ENABLE(ORIENTATION_EVENTS)
151 // Orientation is the interface orientation in degrees. Some examples are:
152 // 0 is straight up; -90 is when the device is rotated 90 clockwise;
153 // 90 is when rotated counter clockwise.
154 void sendOrientationChangeEvent(int orientation);
155 int orientation() const { return m_orientation; }
159 static void clearTimers(FrameView*, Document*);
161 String documentTypeString() const;
163 String displayStringModifiedByEncoding(const String& str) const
165 return document() ? document()->displayStringModifiedByEncoding(str) : str;
168 DragImageRef nodeImage(Node*);
169 DragImageRef dragImageForSelection();
171 bool isContentEditable() const; // if true, everything in frame is editable
173 VisiblePosition visiblePositionForPoint(const IntPoint& framePoint);
174 Document* documentAtPoint(const IntPoint& windowPoint);
176 String searchForLabelsAboveCell(RegularExpression*, HTMLTableCellElement*, size_t* resultDistanceFromStartOfCell);
177 String searchForLabelsBeforeElement(const Vector<String>& labels, Element*, size_t* resultDistance, bool* resultIsInCellAbove);
178 String matchLabelsAgainstElement(const Vector<String>& labels, Element*);
181 NSString* searchForLabelsBeforeElement(NSArray* labels, Element*, size_t* resultDistance, bool* resultIsInCellAbove);
182 NSString* matchLabelsAgainstElement(NSArray* labels, Element*);
184 NSImage* selectionImage(bool forceBlackText = false) const;
185 NSImage* snapshotDragImage(Node*, NSRect* imageRect, NSRect* elementRect) const;
186 NSImage* imageFromRect(NSRect) const;
192 Frame(Page*, HTMLFrameOwnerElement*, FrameLoaderClient*);
194 void injectUserScriptsForWorld(DOMWrapperWorld*, const UserScriptVector&, UserScriptInjectionTime);
195 void lifeSupportTimerFired(Timer<Frame>*);
198 mutable FrameTree m_treeNode;
199 mutable FrameLoader m_loader;
200 mutable NavigationScheduler m_navigationScheduler;
202 mutable RefPtr<DOMWindow> m_domWindow;
203 HashSet<DOMWindow*> m_liveFormerWindows;
205 HTMLFrameOwnerElement* m_ownerElement;
206 RefPtr<FrameView> m_view;
207 RefPtr<Document> m_doc;
209 ScriptController m_script;
211 mutable Editor m_editor;
212 mutable SelectionController m_selectionController;
213 mutable EventHandler m_eventHandler;
214 mutable AnimationController m_animationController;
216 Timer<Frame> m_lifeSupportTimer;
218 float m_pageZoomFactor;
219 float m_textZoomFactor;
221 float m_pageScaleFactor;
223 #if ENABLE(ORIENTATION_EVENTS)
227 bool m_inViewSourceMode;
228 bool m_isDisconnected;
229 bool m_excludeFromTextSearch;
231 #if ENABLE(TILED_BACKING_STORE)
232 // FIXME: The tiled backing store belongs in FrameView, not Frame.
235 TiledBackingStore* tiledBackingStore() const { return m_tiledBackingStore.get(); }
236 void setTiledBackingStoreEnabled(bool);
239 // TiledBackingStoreClient interface
240 virtual void tiledBackingStorePaintBegin();
241 virtual void tiledBackingStorePaint(GraphicsContext*, const IntRect&);
242 virtual void tiledBackingStorePaintEnd(const Vector<IntRect>& paintedArea);
243 virtual IntRect tiledBackingStoreContentsRect();
244 virtual IntRect tiledBackingStoreVisibleRect();
245 virtual Color tiledBackingStoreBackgroundColor() const;
247 OwnPtr<TiledBackingStore> m_tiledBackingStore;
251 inline void Frame::init()
256 inline FrameLoader* Frame::loader() const
261 inline NavigationScheduler* Frame::navigationScheduler() const
263 return &m_navigationScheduler;
266 inline FrameView* Frame::view() const
271 inline ScriptController* Frame::script()
276 inline Document* Frame::document() const
281 inline SelectionController* Frame::selection() const
283 return &m_selectionController;
286 inline Editor* Frame::editor() const
291 inline AnimationController* Frame::animation() const
293 return &m_animationController;
296 inline HTMLFrameOwnerElement* Frame::ownerElement() const
298 return m_ownerElement;
301 inline bool Frame::isDisconnected() const
303 return m_isDisconnected;
306 inline void Frame::setIsDisconnected(bool isDisconnected)
308 m_isDisconnected = isDisconnected;
311 inline bool Frame::excludeFromTextSearch() const
313 return m_excludeFromTextSearch;
316 inline void Frame::setExcludeFromTextSearch(bool exclude)
318 m_excludeFromTextSearch = exclude;
321 inline bool Frame::inViewSourceMode() const
323 return m_inViewSourceMode;
326 inline void Frame::setInViewSourceMode(bool mode)
328 m_inViewSourceMode = mode;
331 inline FrameTree* Frame::tree() const
336 inline Page* Frame::page() const
341 inline void Frame::detachFromPage()
346 inline EventHandler* Frame::eventHandler() const
348 return &m_eventHandler;
351 } // namespace WebCore