1 /* 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> 11 * 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. 16 * 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. 21 * 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. 26 */ 27 28 #ifndef Frame_h 29 #define Frame_h 30 31 #include "AnimationController.h" 32 #include "DragImage.h" 33 #include "Editor.h" 34 #include "EventHandler.h" 35 #include "FrameLoader.h" 36 #include "FrameTree.h" 37 #include "NavigationScheduler.h" 38 #include "SelectionController.h" 39 #include "ScriptController.h" 40 #include "UserScriptTypes.h" 41 42 #if PLATFORM(WIN) 43 #include "FrameWin.h" 44 #endif 45 46 #if ENABLE(TILED_BACKING_STORE) 47 #include "TiledBackingStoreClient.h" 48 #endif 49 50 #if PLATFORM(MAC) 51 #ifndef __OBJC__ 52 class NSArray; 53 class NSMutableDictionary; 54 class NSString; 55 #endif 56 #endif 57 58 #if PLATFORM(WIN) 59 typedef struct HBITMAP__* HBITMAP; 60 #endif 61 62 namespace WebCore { 63 64 class Document; 65 class FrameView; 66 class HTMLTableCellElement; 67 class MediaStreamFrameController; 68 class RegularExpression; 69 class RenderPart; 70 class TiledBackingStore; 71 72 #if !ENABLE(TILED_BACKING_STORE) 73 class TiledBackingStoreClient { }; 74 #endif 75 76 class FrameDestructionObserver { 77 public: ~FrameDestructionObserver()78 virtual ~FrameDestructionObserver() { } 79 80 virtual void frameDestroyed() = 0; 81 }; 82 83 class Frame : public RefCounted<Frame>, public TiledBackingStoreClient { 84 public: 85 static PassRefPtr<Frame> create(Page*, HTMLFrameOwnerElement*, FrameLoaderClient*); 86 87 void init(); 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); 92 93 ~Frame(); 94 95 void addDestructionObserver(FrameDestructionObserver*); 96 void removeDestructionObserver(FrameDestructionObserver*); 97 98 void detachFromPage(); 99 void pageDestroyed(); 100 void disconnectOwnerElement(); 101 102 Page* page() const; 103 HTMLFrameOwnerElement* ownerElement() const; 104 105 Document* document() const; 106 FrameView* view() const; 107 108 Editor* editor() const; 109 EventHandler* eventHandler() const; 110 FrameLoader* loader() const; 111 NavigationScheduler* navigationScheduler() const; 112 SelectionController* selection() const; 113 FrameTree* tree() const; 114 AnimationController* animation() const; 115 ScriptController* script(); 116 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. 119 120 void transferChildFrameToNewDocument(); 121 122 // ======== All public functions below this point are candidates to move out of Frame into another class. ======== 123 124 bool isDisconnected() const; 125 void setIsDisconnected(bool); 126 bool excludeFromTextSearch() const; 127 void setExcludeFromTextSearch(bool); 128 129 void injectUserScripts(UserScriptInjectionTime); 130 131 String layerTreeAsText(bool showDebugInfo = false) const; 132 133 // Unlike most accessors in this class, domWindow() always creates a new DOMWindow if m_domWindow is null. 134 // Callers that don't need a new DOMWindow to be created should use existingDOMWindow(). 135 DOMWindow* domWindow() const; existingDOMWindow()136 DOMWindow* existingDOMWindow() { return m_domWindow.get(); } 137 void setDOMWindow(DOMWindow*); 138 void clearFormerDOMWindow(DOMWindow*); 139 void clearDOMWindow(); 140 141 static Frame* frameForWidget(const Widget*); 142 143 Settings* settings() const; // can be NULL 144 145 enum AdjustViewSizeOrNot { DoNotAdjustViewSize, AdjustViewSize }; 146 void setPrinting(bool printing, const FloatSize& pageSize, float maximumShrinkRatio, AdjustViewSizeOrNot); 147 148 bool inViewSourceMode() const; 149 void setInViewSourceMode(bool = true); 150 151 void keepAlive(); // Used to keep the frame alive when running a script that might destroy it. 152 static void cancelAllKeepAlive(); 153 154 void setDocument(PassRefPtr<Document>); 155 156 void setPageZoomFactor(float factor); pageZoomFactor()157 float pageZoomFactor() const { return m_pageZoomFactor; } 158 void setTextZoomFactor(float factor); textZoomFactor()159 float textZoomFactor() const { return m_textZoomFactor; } 160 void setPageAndTextZoomFactors(float pageZoomFactor, float textZoomFactor); 161 162 void scalePage(float scale, const IntPoint& origin); pageScaleFactor()163 float pageScaleFactor() const { return m_pageScaleFactor; } 164 165 #if ENABLE(ORIENTATION_EVENTS) 166 // Orientation is the interface orientation in degrees. Some examples are: 167 // 0 is straight up; -90 is when the device is rotated 90 clockwise; 168 // 90 is when rotated counter clockwise. 169 void sendOrientationChangeEvent(int orientation); orientation()170 int orientation() const { return m_orientation; } 171 #endif 172 173 void clearTimers(); 174 static void clearTimers(FrameView*, Document*); 175 176 String documentTypeString() const; 177 178 String displayStringModifiedByEncoding(const String&) const; 179 180 DragImageRef nodeImage(Node*); 181 DragImageRef dragImageForSelection(); 182 183 VisiblePosition visiblePositionForPoint(const IntPoint& framePoint); 184 Document* documentAtPoint(const IntPoint& windowPoint); 185 PassRefPtr<Range> rangeForPoint(const IntPoint& framePoint); 186 187 String searchForLabelsAboveCell(RegularExpression*, HTMLTableCellElement*, size_t* resultDistanceFromStartOfCell); 188 String searchForLabelsBeforeElement(const Vector<String>& labels, Element*, size_t* resultDistance, bool* resultIsInCellAbove); 189 String matchLabelsAgainstElement(const Vector<String>& labels, Element*); 190 191 Color getDocumentBackgroundColor() const; 192 193 #if PLATFORM(MAC) 194 NSString* searchForLabelsBeforeElement(NSArray* labels, Element*, size_t* resultDistance, bool* resultIsInCellAbove); 195 NSString* matchLabelsAgainstElement(NSArray* labels, Element*); 196 197 NSImage* selectionImage(bool forceBlackText = false) const; 198 NSImage* snapshotDragImage(Node*, NSRect* imageRect, NSRect* elementRect) const; 199 NSImage* imageFromRect(NSRect) const; 200 #endif 201 202 #if ENABLE(MEDIA_STREAM) mediaStreamFrameController()203 MediaStreamFrameController* mediaStreamFrameController() const { return m_mediaStreamFrameController.get(); } 204 #endif 205 206 // ======== 207 208 private: 209 Frame(Page*, HTMLFrameOwnerElement*, FrameLoaderClient*); 210 211 void injectUserScriptsForWorld(DOMWrapperWorld*, const UserScriptVector&, UserScriptInjectionTime); 212 void lifeSupportTimerFired(Timer<Frame>*); 213 214 #if USE(ACCELERATED_COMPOSITING) 215 void updateContentsScale(float); 216 #endif 217 218 HashSet<FrameDestructionObserver*> m_destructionObservers; 219 220 Page* m_page; 221 mutable FrameTree m_treeNode; 222 mutable FrameLoader m_loader; 223 mutable NavigationScheduler m_navigationScheduler; 224 225 mutable RefPtr<DOMWindow> m_domWindow; 226 HashSet<DOMWindow*> m_liveFormerWindows; 227 228 HTMLFrameOwnerElement* m_ownerElement; 229 RefPtr<FrameView> m_view; 230 RefPtr<Document> m_doc; 231 232 ScriptController m_script; 233 234 mutable Editor m_editor; 235 mutable SelectionController m_selectionController; 236 mutable EventHandler m_eventHandler; 237 mutable AnimationController m_animationController; 238 239 Timer<Frame> m_lifeSupportTimer; 240 241 float m_pageZoomFactor; 242 float m_textZoomFactor; 243 244 float m_pageScaleFactor; 245 246 #if ENABLE(ORIENTATION_EVENTS) 247 int m_orientation; 248 #endif 249 250 bool m_inViewSourceMode; 251 bool m_isDisconnected; 252 bool m_excludeFromTextSearch; 253 254 #if ENABLE(TILED_BACKING_STORE) 255 // FIXME: The tiled backing store belongs in FrameView, not Frame. 256 257 public: tiledBackingStore()258 TiledBackingStore* tiledBackingStore() const { return m_tiledBackingStore.get(); } 259 void setTiledBackingStoreEnabled(bool); 260 261 private: 262 // TiledBackingStoreClient interface 263 virtual void tiledBackingStorePaintBegin(); 264 virtual void tiledBackingStorePaint(GraphicsContext*, const IntRect&); 265 virtual void tiledBackingStorePaintEnd(const Vector<IntRect>& paintedArea); 266 virtual IntRect tiledBackingStoreContentsRect(); 267 virtual IntRect tiledBackingStoreVisibleRect(); 268 virtual Color tiledBackingStoreBackgroundColor() const; 269 270 OwnPtr<TiledBackingStore> m_tiledBackingStore; 271 #endif 272 273 #if ENABLE(MEDIA_STREAM) 274 OwnPtr<MediaStreamFrameController> m_mediaStreamFrameController; 275 #endif 276 }; 277 init()278 inline void Frame::init() 279 { 280 m_loader.init(); 281 } 282 loader()283 inline FrameLoader* Frame::loader() const 284 { 285 return &m_loader; 286 } 287 navigationScheduler()288 inline NavigationScheduler* Frame::navigationScheduler() const 289 { 290 return &m_navigationScheduler; 291 } 292 view()293 inline FrameView* Frame::view() const 294 { 295 return m_view.get(); 296 } 297 script()298 inline ScriptController* Frame::script() 299 { 300 return &m_script; 301 } 302 document()303 inline Document* Frame::document() const 304 { 305 return m_doc.get(); 306 } 307 selection()308 inline SelectionController* Frame::selection() const 309 { 310 return &m_selectionController; 311 } 312 editor()313 inline Editor* Frame::editor() const 314 { 315 return &m_editor; 316 } 317 animation()318 inline AnimationController* Frame::animation() const 319 { 320 return &m_animationController; 321 } 322 ownerElement()323 inline HTMLFrameOwnerElement* Frame::ownerElement() const 324 { 325 return m_ownerElement; 326 } 327 isDisconnected()328 inline bool Frame::isDisconnected() const 329 { 330 return m_isDisconnected; 331 } 332 setIsDisconnected(bool isDisconnected)333 inline void Frame::setIsDisconnected(bool isDisconnected) 334 { 335 m_isDisconnected = isDisconnected; 336 } 337 excludeFromTextSearch()338 inline bool Frame::excludeFromTextSearch() const 339 { 340 return m_excludeFromTextSearch; 341 } 342 setExcludeFromTextSearch(bool exclude)343 inline void Frame::setExcludeFromTextSearch(bool exclude) 344 { 345 m_excludeFromTextSearch = exclude; 346 } 347 inViewSourceMode()348 inline bool Frame::inViewSourceMode() const 349 { 350 return m_inViewSourceMode; 351 } 352 setInViewSourceMode(bool mode)353 inline void Frame::setInViewSourceMode(bool mode) 354 { 355 m_inViewSourceMode = mode; 356 } 357 tree()358 inline FrameTree* Frame::tree() const 359 { 360 return &m_treeNode; 361 } 362 page()363 inline Page* Frame::page() const 364 { 365 return m_page; 366 } 367 detachFromPage()368 inline void Frame::detachFromPage() 369 { 370 m_page = 0; 371 } 372 eventHandler()373 inline EventHandler* Frame::eventHandler() const 374 { 375 return &m_eventHandler; 376 } 377 378 } // namespace WebCore 379 380 #endif // Frame_h 381