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