1 /* 2 * Copyright (C) 1998, 1999 Torben Weis <weis (at) kde.org> 3 * 1999-2001 Lars Knoll <knoll (at) kde.org> 4 * 1999-2001 Antti Koivisto <koivisto (at) kde.org> 5 * 2000-2001 Simon Hausmann <hausmann (at) kde.org> 6 * 2000-2001 Dirk Mueller <mueller (at) kde.org> 7 * 2000 Stefan Schimanski <1Stein (at) 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 (at) 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 "core/loader/FrameLoader.h" 32 #include "core/loader/NavigationScheduler.h" 33 #include "core/frame/AdjustViewSizeOrNot.h" 34 #include "core/page/FrameTree.h" 35 #include "platform/geometry/IntSize.h" 36 #include "platform/scroll/ScrollTypes.h" 37 #include "wtf/Forward.h" 38 #include "wtf/RefCounted.h" 39 40 namespace blink { 41 class WebLayer; 42 } 43 44 namespace WebCore { 45 46 class AnimationController; 47 class ChromeClient; 48 class Color; 49 class DOMWindow; 50 class Document; 51 class DragImage; 52 class Editor; 53 class Element; 54 class EventHandler; 55 class FetchContext; 56 class FloatSize; 57 class FrameDestructionObserver; 58 class FrameSelection; 59 class FrameView; 60 class HTMLFrameOwnerElement; 61 class HTMLTableCellElement; 62 class InputMethodController; 63 class IntPoint; 64 class Node; 65 class Range; 66 class RenderPart; 67 class RenderView; 68 class TreeScope; 69 class ScriptController; 70 class Settings; 71 class SpellChecker; 72 class TreeScope; 73 class VisiblePosition; 74 class Widget; 75 76 class FrameInit : public RefCounted<FrameInit> { 77 public: 78 // For creating a dummy Frame 79 static PassRefPtr<FrameInit> create(int64_t frameID, Page* page, FrameLoaderClient* client) 80 { 81 return adoptRef(new FrameInit(frameID, page, client)); 82 } 83 84 void setFrameLoaderClient(FrameLoaderClient* client) { m_client = client; } 85 FrameLoaderClient* frameLoaderClient() const { return m_client; } 86 87 int64_t frameID() const { return m_frameID; } 88 89 void setPage(Page* page) { m_page = page; } 90 Page* page() const { return m_page; } 91 92 void setOwnerElement(HTMLFrameOwnerElement* ownerElement) { m_ownerElement = ownerElement; } 93 HTMLFrameOwnerElement* ownerElement() const { return m_ownerElement; } 94 95 protected: 96 FrameInit(int64_t frameID, Page* page = 0, FrameLoaderClient* client = 0) 97 : m_frameID(frameID) 98 , m_client(client) 99 , m_page(page) 100 , m_ownerElement(0) 101 { 102 } 103 104 private: 105 int64_t m_frameID; 106 FrameLoaderClient* m_client; 107 Page* m_page; 108 HTMLFrameOwnerElement* m_ownerElement; 109 }; 110 111 class Frame : public RefCounted<Frame> { 112 public: 113 static PassRefPtr<Frame> create(PassRefPtr<FrameInit>); 114 115 void init(); 116 void setView(PassRefPtr<FrameView>); 117 void createView(const IntSize&, const Color&, bool, 118 ScrollbarMode = ScrollbarAuto, bool horizontalLock = false, 119 ScrollbarMode = ScrollbarAuto, bool verticalLock = false); 120 121 ~Frame(); 122 123 void addDestructionObserver(FrameDestructionObserver*); 124 void removeDestructionObserver(FrameDestructionObserver*); 125 126 void willDetachPage(); 127 void detachFromPage(); 128 void disconnectOwnerElement(); 129 130 Page* page() const; 131 HTMLFrameOwnerElement* ownerElement() const; 132 bool isMainFrame() const; 133 134 void setDOMWindow(PassRefPtr<DOMWindow>); 135 DOMWindow* domWindow() const; 136 Document* document() const; 137 FrameView* view() const; 138 139 ChromeClient& chromeClient() const; 140 Editor& editor() const; 141 EventHandler& eventHandler() const; 142 FrameLoader& loader() const; 143 NavigationScheduler& navigationScheduler() const; 144 FrameSelection& selection() const; 145 FrameTree& tree() const; 146 AnimationController& animation() const; 147 InputMethodController& inputMethodController() const; 148 FetchContext& fetchContext() const { return loader().fetchContext(); } 149 ScriptController& script(); 150 SpellChecker& spellChecker() const; 151 152 RenderView* contentRenderer() const; // Root of the render tree for the document contained in this frame. 153 RenderPart* ownerRenderer() const; // Renderer for the element that contains this frame. 154 155 void dispatchVisibilityStateChangeEvent(); 156 157 int64_t frameID() const { return m_frameInit->frameID(); } 158 159 void setRemotePlatformLayer(blink::WebLayer* remotePlatformLayer) { m_remotePlatformLayer = remotePlatformLayer; } 160 blink::WebLayer* remotePlatformLayer() const { return m_remotePlatformLayer; } 161 162 // ======== All public functions below this point are candidates to move out of Frame into another class. ======== 163 164 bool inScope(TreeScope*) const; 165 166 // See GraphicsLayerClient.h for accepted flags. 167 String layerTreeAsText(unsigned flags = 0) const; 168 String trackedRepaintRectsAsText() const; 169 170 Settings* settings() const; // can be NULL 171 172 void setPrinting(bool printing, const FloatSize& pageSize, const FloatSize& originalPageSize, float maximumShrinkRatio, AdjustViewSizeOrNot); 173 bool shouldUsePrintingLayout() const; 174 FloatSize resizePageRectsKeepingRatio(const FloatSize& originalSize, const FloatSize& expectedSize); 175 176 bool inViewSourceMode() const; 177 void setInViewSourceMode(bool = true); 178 179 void setPageZoomFactor(float factor); 180 float pageZoomFactor() const { return m_pageZoomFactor; } 181 void setTextZoomFactor(float factor); 182 float textZoomFactor() const { return m_textZoomFactor; } 183 void setPageAndTextZoomFactors(float pageZoomFactor, float textZoomFactor); 184 185 void deviceOrPageScaleFactorChanged(); 186 double devicePixelRatio() const; 187 188 #if ENABLE(ORIENTATION_EVENTS) 189 // Orientation is the interface orientation in degrees. Some examples are: 190 // 0 is straight up; -90 is when the device is rotated 90 clockwise; 191 // 90 is when rotated counter clockwise. 192 void sendOrientationChangeEvent(int orientation); 193 int orientation() const { return m_orientation; } 194 #endif 195 196 String documentTypeString() const; 197 198 PassOwnPtr<DragImage> nodeImage(Node*); 199 PassOwnPtr<DragImage> dragImageForSelection(); 200 201 String selectedText() const; 202 String selectedTextForClipboard() const; 203 204 VisiblePosition visiblePositionForPoint(const IntPoint& framePoint); 205 Document* documentAtPoint(const IntPoint& windowPoint); 206 PassRefPtr<Range> rangeForPoint(const IntPoint& framePoint); 207 208 // Should only be called on the main frame of a page. 209 void notifyChromeClientWheelEventHandlerCountChanged() const; 210 211 bool isURLAllowed(const KURL&) const; 212 213 // ======== 214 215 private: 216 Frame(PassRefPtr<FrameInit>); 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 RefPtr<FrameView> m_view; 226 RefPtr<DOMWindow> m_domWindow; 227 228 OwnPtr<ScriptController> m_script; 229 const OwnPtr<Editor> m_editor; 230 const OwnPtr<SpellChecker> m_spellChecker; 231 const OwnPtr<FrameSelection> m_selection; 232 const OwnPtr<EventHandler> m_eventHandler; 233 OwnPtr<AnimationController> m_animationController; 234 OwnPtr<InputMethodController> m_inputMethodController; 235 236 RefPtr<FrameInit> m_frameInit; 237 238 float m_pageZoomFactor; 239 float m_textZoomFactor; 240 241 #if ENABLE(ORIENTATION_EVENTS) 242 int m_orientation; 243 #endif 244 245 bool m_inViewSourceMode; 246 247 blink::WebLayer* m_remotePlatformLayer; 248 }; 249 250 inline void Frame::init() 251 { 252 m_loader.init(); 253 } 254 255 inline FrameLoader& Frame::loader() const 256 { 257 return m_loader; 258 } 259 260 inline NavigationScheduler& Frame::navigationScheduler() const 261 { 262 return m_navigationScheduler; 263 } 264 265 inline FrameView* Frame::view() const 266 { 267 return m_view.get(); 268 } 269 270 inline ScriptController& Frame::script() 271 { 272 return *m_script; 273 } 274 275 inline DOMWindow* Frame::domWindow() const 276 { 277 return m_domWindow.get(); 278 } 279 280 inline FrameSelection& Frame::selection() const 281 { 282 return *m_selection; 283 } 284 285 inline Editor& Frame::editor() const 286 { 287 return *m_editor; 288 } 289 290 inline SpellChecker& Frame::spellChecker() const 291 { 292 return *m_spellChecker; 293 } 294 295 inline AnimationController& Frame::animation() const 296 { 297 return *m_animationController; 298 } 299 300 inline InputMethodController& Frame::inputMethodController() const 301 { 302 return *m_inputMethodController; 303 } 304 305 inline HTMLFrameOwnerElement* Frame::ownerElement() const 306 { 307 return m_frameInit->ownerElement(); 308 } 309 310 inline bool Frame::inViewSourceMode() const 311 { 312 return m_inViewSourceMode; 313 } 314 315 inline void Frame::setInViewSourceMode(bool mode) 316 { 317 m_inViewSourceMode = mode; 318 } 319 320 inline FrameTree& Frame::tree() const 321 { 322 return m_treeNode; 323 } 324 325 inline Page* Frame::page() const 326 { 327 return m_page; 328 } 329 330 inline EventHandler& Frame::eventHandler() const 331 { 332 ASSERT(m_eventHandler); 333 return *m_eventHandler; 334 } 335 336 } // namespace WebCore 337 338 #endif // Frame_h 339