Home | History | Annotate | Download | only in page
      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/css/StyleColor.h"
     32 #include "core/loader/FrameLoader.h"
     33 #include "core/loader/NavigationScheduler.h"
     34 #include "core/page/AdjustViewSizeOrNot.h"
     35 #include "core/page/FrameTree.h"
     36 #include "core/platform/ScrollTypes.h"
     37 #include "core/platform/graphics/IntSize.h"
     38 #include "wtf/Forward.h"
     39 #include "wtf/RefCounted.h"
     40 
     41 namespace WebCore {
     42 
     43     class AnimationController;
     44     class Color;
     45     class DOMWindow;
     46     class Document;
     47     class DragImage;
     48     class Editor;
     49     class Element;
     50     class EventHandler;
     51     class FloatSize;
     52     class FrameDestructionObserver;
     53     class FrameSelection;
     54     class FrameView;
     55     class HTMLFrameOwnerElement;
     56     class HTMLTableCellElement;
     57     class InputMethodController;
     58     class IntPoint;
     59     class Node;
     60     class Range;
     61     class RenderPart;
     62     class RenderView;
     63     class TreeScope;
     64     class ScriptController;
     65     class Settings;
     66     class TreeScope;
     67     class VisiblePosition;
     68     class Widget;
     69 
     70     class Frame : public RefCounted<Frame> {
     71     public:
     72         static PassRefPtr<Frame> create(Page*, HTMLFrameOwnerElement*, FrameLoaderClient*);
     73 
     74         void init();
     75         void setView(PassRefPtr<FrameView>);
     76         void createView(const IntSize&, const StyleColor&, bool,
     77             const IntSize& fixedLayoutSize = IntSize(), bool useFixedLayout = false, ScrollbarMode = ScrollbarAuto, bool horizontalLock = false,
     78             ScrollbarMode = ScrollbarAuto, bool verticalLock = false);
     79 
     80         ~Frame();
     81 
     82         void addDestructionObserver(FrameDestructionObserver*);
     83         void removeDestructionObserver(FrameDestructionObserver*);
     84 
     85         void willDetachPage();
     86         void detachFromPage();
     87         void disconnectOwnerElement();
     88 
     89         Page* page() const;
     90         HTMLFrameOwnerElement* ownerElement() const;
     91 
     92         void setDOMWindow(PassRefPtr<DOMWindow>);
     93         DOMWindow* domWindow() const;
     94         Document* document() const;
     95         FrameView* view() const;
     96 
     97         Editor* editor() const;
     98         EventHandler* eventHandler() const;
     99         FrameLoader* loader() const;
    100         NavigationScheduler* navigationScheduler() const;
    101         FrameSelection* selection() const;
    102         FrameTree* tree() const;
    103         AnimationController* animation() const;
    104         InputMethodController& inputMethodController() const;
    105         ScriptController* script();
    106 
    107         RenderView* contentRenderer() const; // Root of the render tree for the document contained in this frame.
    108         RenderPart* ownerRenderer() const; // Renderer for the element that contains this frame.
    109 
    110         void dispatchVisibilityStateChangeEvent();
    111 
    112     // ======== All public functions below this point are candidates to move out of Frame into another class. ========
    113 
    114         bool inScope(TreeScope*) const;
    115 
    116         // See GraphicsLayerClient.h for accepted flags.
    117         String layerTreeAsText(unsigned flags = 0) const;
    118         String trackedRepaintRectsAsText() const;
    119 
    120         static Frame* frameForWidget(const Widget*);
    121 
    122         Settings* settings() const; // can be NULL
    123 
    124         void setPrinting(bool printing, const FloatSize& pageSize, const FloatSize& originalPageSize, float maximumShrinkRatio, AdjustViewSizeOrNot);
    125         bool shouldUsePrintingLayout() const;
    126         FloatSize resizePageRectsKeepingRatio(const FloatSize& originalSize, const FloatSize& expectedSize);
    127 
    128         bool inViewSourceMode() const;
    129         void setInViewSourceMode(bool = true);
    130 
    131         void setPageZoomFactor(float factor);
    132         float pageZoomFactor() const { return m_pageZoomFactor; }
    133         void setTextZoomFactor(float factor);
    134         float textZoomFactor() const { return m_textZoomFactor; }
    135         void setPageAndTextZoomFactors(float pageZoomFactor, float textZoomFactor);
    136 
    137         void deviceOrPageScaleFactorChanged();
    138 
    139 #if ENABLE(ORIENTATION_EVENTS)
    140         // Orientation is the interface orientation in degrees. Some examples are:
    141         //  0 is straight up; -90 is when the device is rotated 90 clockwise;
    142         //  90 is when rotated counter clockwise.
    143         void sendOrientationChangeEvent(int orientation);
    144         int orientation() const { return m_orientation; }
    145 #endif
    146 
    147         void clearTimers();
    148         static void clearTimers(FrameView*, Document*);
    149 
    150         String documentTypeString() const;
    151 
    152         String displayStringModifiedByEncoding(const String&) const;
    153 
    154         PassOwnPtr<DragImage> nodeImage(Node*);
    155         PassOwnPtr<DragImage> dragImageForSelection();
    156 
    157         String selectedText() const;
    158         String selectedTextForClipboard() const;
    159 
    160         VisiblePosition visiblePositionForPoint(const IntPoint& framePoint);
    161         Document* documentAtPoint(const IntPoint& windowPoint);
    162         PassRefPtr<Range> rangeForPoint(const IntPoint& framePoint);
    163 
    164         // Should only be called on the main frame of a page.
    165         void notifyChromeClientWheelEventHandlerCountChanged() const;
    166 
    167         bool isURLAllowed(const KURL&) const;
    168 
    169     // ========
    170 
    171     private:
    172         Frame(Page*, HTMLFrameOwnerElement*, FrameLoaderClient*);
    173 
    174         HashSet<FrameDestructionObserver*> m_destructionObservers;
    175 
    176         Page* m_page;
    177         mutable FrameTree m_treeNode;
    178         mutable FrameLoader m_loader;
    179         mutable NavigationScheduler m_navigationScheduler;
    180 
    181         HTMLFrameOwnerElement* m_ownerElement;
    182         RefPtr<FrameView> m_view;
    183         RefPtr<DOMWindow> m_domWindow;
    184 
    185         OwnPtr<ScriptController> m_script;
    186         OwnPtr<Editor> m_editor;
    187         OwnPtr<FrameSelection> m_selection;
    188         OwnPtr<EventHandler> m_eventHandler;
    189         OwnPtr<AnimationController> m_animationController;
    190         OwnPtr<InputMethodController> m_inputMethodController;
    191 
    192         float m_pageZoomFactor;
    193         float m_textZoomFactor;
    194 
    195 #if ENABLE(ORIENTATION_EVENTS)
    196         int m_orientation;
    197 #endif
    198 
    199         bool m_inViewSourceMode;
    200     };
    201 
    202     inline void Frame::init()
    203     {
    204         m_loader.init();
    205     }
    206 
    207     inline FrameLoader* Frame::loader() const
    208     {
    209         return &m_loader;
    210     }
    211 
    212     inline NavigationScheduler* Frame::navigationScheduler() const
    213     {
    214         return &m_navigationScheduler;
    215     }
    216 
    217     inline FrameView* Frame::view() const
    218     {
    219         return m_view.get();
    220     }
    221 
    222     inline ScriptController* Frame::script()
    223     {
    224         return m_script.get();
    225     }
    226 
    227     inline DOMWindow* Frame::domWindow() const
    228     {
    229         return m_domWindow.get();
    230     }
    231 
    232     inline FrameSelection* Frame::selection() const
    233     {
    234         return m_selection.get();
    235     }
    236 
    237     inline Editor* Frame::editor() const
    238     {
    239         return m_editor.get();
    240     }
    241 
    242     inline AnimationController* Frame::animation() const
    243     {
    244         return m_animationController.get();
    245     }
    246 
    247     inline InputMethodController& Frame::inputMethodController() const
    248     {
    249         return *m_inputMethodController;
    250     }
    251 
    252     inline HTMLFrameOwnerElement* Frame::ownerElement() const
    253     {
    254         return m_ownerElement;
    255     }
    256 
    257     inline bool Frame::inViewSourceMode() const
    258     {
    259         return m_inViewSourceMode;
    260     }
    261 
    262     inline void Frame::setInViewSourceMode(bool mode)
    263     {
    264         m_inViewSourceMode = mode;
    265     }
    266 
    267     inline FrameTree* Frame::tree() const
    268     {
    269         return &m_treeNode;
    270     }
    271 
    272     inline Page* Frame::page() const
    273     {
    274         return m_page;
    275     }
    276 
    277     inline EventHandler* Frame::eventHandler() const
    278     {
    279         return m_eventHandler.get();
    280     }
    281 
    282 } // namespace WebCore
    283 
    284 #endif // Frame_h
    285