Home | History | Annotate | Download | only in frame
      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 LocalFrame_h
     29 #define LocalFrame_h
     30 
     31 #include "core/frame/Frame.h"
     32 #include "core/loader/FrameLoader.h"
     33 #include "core/loader/NavigationScheduler.h"
     34 #include "core/page/FrameTree.h"
     35 #include "platform/Supplementable.h"
     36 #include "platform/heap/Handle.h"
     37 #include "platform/scroll/ScrollTypes.h"
     38 
     39 namespace WebCore {
     40 
     41     class Color;
     42     class Document;
     43     class DragImage;
     44     class Editor;
     45     class EventHandler;
     46     class FetchContext;
     47     class FloatSize;
     48     class FrameConsole;
     49     class FrameSelection;
     50     class FrameView;
     51     class InputMethodController;
     52     class IntPoint;
     53     class IntSize;
     54     class Node;
     55     class Range;
     56     class RenderView;
     57     class TreeScope;
     58     class ScriptController;
     59     class SpellChecker;
     60     class TreeScope;
     61     class VisiblePosition;
     62 
     63     class LocalFrame : public Frame, public WillBePersistentHeapSupplementable<LocalFrame>  {
     64     public:
     65         static PassRefPtr<LocalFrame> create(FrameLoaderClient*, FrameHost*, FrameOwner*);
     66 
     67         virtual bool isLocalFrame() const OVERRIDE { return true; }
     68 
     69         void init();
     70         void setView(PassRefPtr<FrameView>);
     71         void createView(const IntSize&, const Color&, bool,
     72             ScrollbarMode = ScrollbarAuto, bool horizontalLock = false,
     73             ScrollbarMode = ScrollbarAuto, bool verticalLock = false);
     74 
     75         virtual ~LocalFrame();
     76 
     77         virtual void willDetachFrameHost() OVERRIDE;
     78         virtual void detachFromFrameHost() OVERRIDE;
     79 
     80         virtual void disconnectOwnerElement() OVERRIDE;
     81 
     82         virtual void setDOMWindow(PassRefPtrWillBeRawPtr<LocalDOMWindow>) OVERRIDE;
     83         FrameView* view() const;
     84         Document* document() const;
     85 
     86         RenderView* contentRenderer() const; // Root of the render tree for the document contained in this frame.
     87 
     88         Editor& editor() const;
     89         EventHandler& eventHandler() const;
     90         FrameLoader& loader() const;
     91         NavigationScheduler& navigationScheduler() const;
     92         FrameSelection& selection() const;
     93         InputMethodController& inputMethodController() const;
     94         FetchContext& fetchContext() const { return loader().fetchContext(); }
     95         ScriptController& script();
     96         SpellChecker& spellChecker() const;
     97         FrameConsole& console() const;
     98 
     99         void didChangeVisibilityState();
    100 
    101         // FIXME: This method is only used by EventHandler to get the highest level
    102         // LocalFrame in this frame's in-process subtree. When user gesture tokens
    103         // are synchronized across processes this method should be removed.
    104         LocalFrame* localFrameRoot();
    105 
    106     // ======== All public functions below this point are candidates to move out of LocalFrame into another class. ========
    107 
    108         bool inScope(TreeScope*) const;
    109 
    110         void countObjectsNeedingLayout(unsigned& needsLayoutObjects, unsigned& totalObjects, bool& isPartial);
    111 
    112         // See GraphicsLayerClient.h for accepted flags.
    113         String layerTreeAsText(unsigned flags = 0) const;
    114         String trackedRepaintRectsAsText() const;
    115 
    116         void setPrinting(bool printing, const FloatSize& pageSize, const FloatSize& originalPageSize, float maximumShrinkRatio);
    117         bool shouldUsePrintingLayout() const;
    118         FloatSize resizePageRectsKeepingRatio(const FloatSize& originalSize, const FloatSize& expectedSize);
    119 
    120         bool inViewSourceMode() const;
    121         void setInViewSourceMode(bool = true);
    122 
    123         void setPageZoomFactor(float factor);
    124         float pageZoomFactor() const { return m_pageZoomFactor; }
    125         void setTextZoomFactor(float factor);
    126         float textZoomFactor() const { return m_textZoomFactor; }
    127         void setPageAndTextZoomFactors(float pageZoomFactor, float textZoomFactor);
    128 
    129         void deviceOrPageScaleFactorChanged();
    130         double devicePixelRatio() const;
    131 
    132         void sendOrientationChangeEvent();
    133 
    134         String documentTypeString() const;
    135 
    136         PassOwnPtr<DragImage> nodeImage(Node&);
    137         PassOwnPtr<DragImage> dragImageForSelection();
    138 
    139         String selectedText() const;
    140         String selectedTextForClipboard() const;
    141 
    142         VisiblePosition visiblePositionForPoint(const IntPoint& framePoint);
    143         Document* documentAtPoint(const IntPoint& windowPoint);
    144         PassRefPtrWillBeRawPtr<Range> rangeForPoint(const IntPoint& framePoint);
    145 
    146         bool isURLAllowed(const KURL&) const;
    147 
    148     // ========
    149 
    150     private:
    151         LocalFrame(FrameLoaderClient*, FrameHost*, FrameOwner*);
    152 
    153         String localLayerTreeAsText(unsigned flags) const;
    154 
    155         mutable FrameLoader m_loader;
    156         mutable NavigationScheduler m_navigationScheduler;
    157 
    158         RefPtr<FrameView> m_view;
    159 
    160         OwnPtr<ScriptController> m_script;
    161         const OwnPtrWillBePersistent<Editor> m_editor;
    162         const OwnPtr<SpellChecker> m_spellChecker;
    163         const OwnPtrWillBePersistent<FrameSelection> m_selection;
    164         const OwnPtrWillBePersistent<EventHandler> m_eventHandler;
    165         const OwnPtr<FrameConsole> m_console;
    166         OwnPtr<InputMethodController> m_inputMethodController;
    167 
    168         float m_pageZoomFactor;
    169         float m_textZoomFactor;
    170 
    171         bool m_inViewSourceMode;
    172     };
    173 
    174     inline void LocalFrame::init()
    175     {
    176         m_loader.init();
    177     }
    178 
    179     inline FrameLoader& LocalFrame::loader() const
    180     {
    181         return m_loader;
    182     }
    183 
    184     inline NavigationScheduler& LocalFrame::navigationScheduler() const
    185     {
    186         return m_navigationScheduler;
    187     }
    188 
    189     inline FrameView* LocalFrame::view() const
    190     {
    191         return m_view.get();
    192     }
    193 
    194     inline ScriptController& LocalFrame::script()
    195     {
    196         return *m_script;
    197     }
    198 
    199     inline FrameSelection& LocalFrame::selection() const
    200     {
    201         return *m_selection;
    202     }
    203 
    204     inline Editor& LocalFrame::editor() const
    205     {
    206         return *m_editor;
    207     }
    208 
    209     inline SpellChecker& LocalFrame::spellChecker() const
    210     {
    211         return *m_spellChecker;
    212     }
    213 
    214     inline FrameConsole& LocalFrame::console() const
    215     {
    216         return *m_console;
    217     }
    218 
    219     inline InputMethodController& LocalFrame::inputMethodController() const
    220     {
    221         return *m_inputMethodController;
    222     }
    223 
    224     inline bool LocalFrame::inViewSourceMode() const
    225     {
    226         return m_inViewSourceMode;
    227     }
    228 
    229     inline void LocalFrame::setInViewSourceMode(bool mode)
    230     {
    231         m_inViewSourceMode = mode;
    232     }
    233 
    234     inline EventHandler& LocalFrame::eventHandler() const
    235     {
    236         ASSERT(m_eventHandler);
    237         return *m_eventHandler;
    238     }
    239 
    240     DEFINE_TYPE_CASTS(LocalFrame, Frame, localFrame, localFrame->isLocalFrame(), localFrame.isLocalFrame());
    241 
    242 } // namespace WebCore
    243 
    244 // During refactoring, there are some places where we need to do type conversions that
    245 // will not be needed once all instances of LocalFrame and RemoteFrame are sorted out.
    246 // At that time this #define will be removed and all the uses of it will need to be corrected.
    247 #define toLocalFrameTemporary toLocalFrame
    248 
    249 #endif // LocalFrame_h
    250