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 USE(TILED_BACKING_STORE)
48 #include "TiledBackingStoreClient.h"
54 class NSMutableDictionary;
60 typedef struct HBITMAP__* HBITMAP;
66 class FrameDestructionObserver;
68 class HTMLTableCellElement;
69 class MemoryObjectInfo;
70 class RegularExpression;
72 class TiledBackingStore;
74 #if !USE(TILED_BACKING_STORE)
75 class TiledBackingStoreClient { };
80 class Frame : public RefCounted<Frame>, public TiledBackingStoreClient {
82 static PassRefPtr<Frame> create(Page*, HTMLFrameOwnerElement*, FrameLoaderClient*);
85 void setView(PassRefPtr<FrameView>);
86 void createView(const IntSize&, const Color&, bool,
87 const IntSize& fixedLayoutSize = IntSize(), const IntRect& fixedVisibleContentRect = IntRect(),
88 bool useFixedLayout = false, ScrollbarMode = ScrollbarAuto, bool horizontalLock = false,
89 ScrollbarMode = ScrollbarAuto, bool verticalLock = false);
93 void addDestructionObserver(FrameDestructionObserver*);
94 void removeDestructionObserver(FrameDestructionObserver*);
96 void willDetachPage();
97 void detachFromPage();
98 void disconnectOwnerElement();
101 HTMLFrameOwnerElement* ownerElement() const;
103 Document* document() const;
104 FrameView* view() const;
106 Editor* editor() const;
107 EventHandler* eventHandler() const;
108 FrameLoader* loader() const;
109 NavigationScheduler* navigationScheduler() const;
110 FrameSelection* selection() const;
111 FrameTree* tree() const;
112 AnimationController* animation() const;
113 ScriptController* script();
115 RenderView* contentRenderer() const; // Root of the render tree for the document contained in this frame.
116 RenderPart* ownerRenderer() const; // Renderer for the element that contains this frame.
118 #if ENABLE(PAGE_VISIBILITY_API)
119 void dispatchVisibilityStateChangeEvent();
122 void reportMemoryUsage(MemoryObjectInfo*) const;
124 // ======== All public functions below this point are candidates to move out of Frame into another class. ========
126 bool inScope(TreeScope*) const;
128 void injectUserScripts(UserScriptInjectionTime);
130 String layerTreeAsText(bool showDebugInfo = false) const;
132 // Unlike most accessors in this class, domWindow() always creates a new DOMWindow if m_domWindow is null.
133 // Callers that don't need a new DOMWindow to be created should use existingDOMWindow().
134 DOMWindow* domWindow() const;
135 DOMWindow* existingDOMWindow() { return m_domWindow.get(); }
136 void setDOMWindow(DOMWindow*);
137 void clearDOMWindow();
138 static Frame* frameForWidget(const Widget*);
140 Settings* settings() const; // can be NULL
142 void setPrinting(bool printing, const FloatSize& pageSize, const FloatSize& originalPageSize, float maximumShrinkRatio, AdjustViewSizeOrNot);
143 bool shouldUsePrintingLayout() const;
144 FloatSize resizePageRectsKeepingRatio(const FloatSize& originalSize, const FloatSize& expectedSize);
146 bool inViewSourceMode() const;
147 void setInViewSourceMode(bool = true);
149 void setDocument(PassRefPtr<Document>);
151 void setPageZoomFactor(float factor);
152 float pageZoomFactor() const { return m_pageZoomFactor; }
153 void setTextZoomFactor(float factor);
154 float textZoomFactor() const { return m_textZoomFactor; }
155 void setPageAndTextZoomFactors(float pageZoomFactor, float textZoomFactor);
157 // Scale factor of this frame with respect to the container.
158 float frameScaleFactor() const;
160 #if ENABLE(TIZEN_WEBKIT2_HISTORICAL_RESTORE_VISIBLE_CONTENT_RECT)
161 float contentsScaleFactor() const;
164 #if USE(ACCELERATED_COMPOSITING)
165 void deviceOrPageScaleFactorChanged();
168 #if ENABLE(ORIENTATION_EVENTS)
169 // Orientation is the interface orientation in degrees. Some examples are:
170 // 0 is straight up; -90 is when the device is rotated 90 clockwise;
171 // 90 is when rotated counter clockwise.
172 void sendOrientationChangeEvent(int orientation);
173 int orientation() const { return m_orientation; }
177 static void clearTimers(FrameView*, Document*);
179 String documentTypeString() const;
181 String displayStringModifiedByEncoding(const String&) const;
183 DragImageRef nodeImage(Node*);
184 DragImageRef dragImageForSelection();
186 VisiblePosition visiblePositionForPoint(const IntPoint& framePoint);
187 Document* documentAtPoint(const IntPoint& windowPoint);
188 PassRefPtr<Range> rangeForPoint(const IntPoint& framePoint);
190 String searchForLabelsAboveCell(RegularExpression*, HTMLTableCellElement*, size_t* resultDistanceFromStartOfCell);
191 String searchForLabelsBeforeElement(const Vector<String>& labels, Element*, size_t* resultDistance, bool* resultIsInCellAbove);
192 String matchLabelsAgainstElement(const Vector<String>& labels, Element*);
195 NSImage* selectionImage(bool forceBlackText = false) const;
196 NSImage* rangeImage(Range*, bool forceBlackText = false) const;
197 NSImage* snapshotDragImage(Node*, NSRect* imageRect, NSRect* elementRect) const;
198 NSImage* imageFromRect(NSRect) const;
200 void suspendActiveDOMObjectsAndAnimations();
201 void resumeActiveDOMObjectsAndAnimations();
202 bool activeDOMObjectsAndAnimationsSuspended() const { return m_activeDOMObjectsAndAnimationsSuspendedCount > 0; }
204 // Should only be called on the main frame of a page.
205 void notifyChromeClientWheelEventHandlerCountChanged() const;
210 Frame(Page*, HTMLFrameOwnerElement*, FrameLoaderClient*);
212 void injectUserScriptsForWorld(DOMWrapperWorld*, const UserScriptVector&, UserScriptInjectionTime);
214 HashSet<FrameDestructionObserver*> m_destructionObservers;
217 mutable FrameTree m_treeNode;
218 mutable FrameLoader m_loader;
219 mutable NavigationScheduler m_navigationScheduler;
221 mutable RefPtr<DOMWindow> m_domWindow;
223 HTMLFrameOwnerElement* m_ownerElement;
224 RefPtr<FrameView> m_view;
225 RefPtr<Document> m_doc;
227 ScriptController m_script;
229 mutable Editor m_editor;
230 mutable FrameSelection m_selection;
231 mutable EventHandler m_eventHandler;
232 mutable AnimationController m_animationController;
234 float m_pageZoomFactor;
235 float m_textZoomFactor;
237 #if ENABLE(ORIENTATION_EVENTS)
241 bool m_inViewSourceMode;
243 #if USE(TILED_BACKING_STORE)
244 // FIXME: The tiled backing store belongs in FrameView, not Frame.
247 TiledBackingStore* tiledBackingStore() const { return m_tiledBackingStore.get(); }
248 void setTiledBackingStoreEnabled(bool);
251 // TiledBackingStoreClient interface
252 virtual void tiledBackingStorePaintBegin();
253 virtual void tiledBackingStorePaint(GraphicsContext*, const IntRect&);
254 virtual void tiledBackingStorePaintEnd(const Vector<IntRect>& paintedArea);
255 virtual IntRect tiledBackingStoreContentsRect();
256 virtual IntRect tiledBackingStoreVisibleRect();
257 virtual Color tiledBackingStoreBackgroundColor() const;
258 #if ENABLE(TIZEN_RECORDING_SURFACE_SET)
259 virtual bool recordingSurfaceSetEnableGet() { return false; }
260 virtual void dirtyRectInvalidate() {}
261 #if ENABLE(TIZEN_RECORDING_SURFACE_PAINT_THREAD)
262 virtual void scheduleUpdateTileBuffersAsync() {}
265 OwnPtr<TiledBackingStore> m_tiledBackingStore;
268 int m_activeDOMObjectsAndAnimationsSuspendedCount;
271 inline void Frame::init()
276 inline FrameLoader* Frame::loader() const
281 inline NavigationScheduler* Frame::navigationScheduler() const
283 return &m_navigationScheduler;
286 inline FrameView* Frame::view() const
291 inline ScriptController* Frame::script()
296 inline Document* Frame::document() const
301 inline FrameSelection* Frame::selection() const
306 inline Editor* Frame::editor() const
311 inline AnimationController* Frame::animation() const
313 return &m_animationController;
316 inline HTMLFrameOwnerElement* Frame::ownerElement() const
318 return m_ownerElement;
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