Frame.h   [plain text]

 * Copyright (C) 1998, 1999 Torben Weis <>
 *                     1999-2001 Lars Knoll <>
 *                     1999-2001 Antti Koivisto <>
 *                     2000-2001 Simon Hausmann <>
 *                     2000-2001 Dirk Mueller <>
 *                     2000 Stefan Schimanski <>
 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
 * Copyright (C) 2008 Eric Seidel <>
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * Library General Public License for more details.
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.

#ifndef Frame_h
#define Frame_h

#include "AdjustViewSizeOrNot.h"
#include "AnimationController.h"
#include "DragImage.h"
#include "Editor.h"
#include "EventHandler.h"
#include "FrameLoader.h"
#include "FrameSelection.h"
#include "FrameTree.h"
#include "NavigationScheduler.h"
#include "ScriptController.h"
#include "UserScriptTypes.h"

#include "FrameWin.h"

#include "TiledBackingStoreClient.h"

#ifndef __OBJC__
class NSArray;
class NSMutableDictionary;
class NSString;

typedef struct HBITMAP__* HBITMAP;

namespace WebCore {

    class Document;
    class FrameDestructionObserver;
    class FrameView;
    class HTMLTableCellElement;
    class RegularExpression;
    class RenderPart;
    class TiledBackingStore;

    class TiledBackingStoreClient { };

    class TreeScope;

    class Frame : public RefCounted<Frame>, public TiledBackingStoreClient {
        static PassRefPtr<Frame> create(Page*, HTMLFrameOwnerElement*, FrameLoaderClient*);

        void init();
        void setView(PassRefPtr<FrameView>);
        void createView(const IntSize&, const Color&, bool, const IntSize&, bool,
            ScrollbarMode = ScrollbarAuto, bool horizontalLock = false,
            ScrollbarMode = ScrollbarAuto, bool verticalLock = false);


        void addDestructionObserver(FrameDestructionObserver*);
        void removeDestructionObserver(FrameDestructionObserver*);

        void willDetachPage();
        void detachFromPage();
        void disconnectOwnerElement();

        Page* page() const;
        HTMLFrameOwnerElement* ownerElement() const;

        Document* document() const;
        FrameView* view() const;

        Editor* editor() const;
        EventHandler* eventHandler() const;
        FrameLoader* loader() const;
        NavigationScheduler* navigationScheduler() const;
        FrameSelection* selection() const;
        FrameTree* tree() const;
        AnimationController* animation() const;
        ScriptController* script();
        RenderView* contentRenderer() const; // Root of the render tree for the document contained in this frame.
        RenderPart* ownerRenderer() const; // Renderer for the element that contains this frame.

        void dispatchVisibilityStateChangeEvent();

    // ======== All public functions below this point are candidates to move out of Frame into another class. ========

        bool isDisconnected() const;
        void setIsDisconnected(bool);
        bool excludeFromTextSearch() const;
        void setExcludeFromTextSearch(bool);
        bool inScope(TreeScope*) const;

        void injectUserScripts(UserScriptInjectionTime);
        String layerTreeAsText(bool showDebugInfo = false) const;

        // Unlike most accessors in this class, domWindow() always creates a new DOMWindow if m_domWindow is null.
        // Callers that don't need a new DOMWindow to be created should use existingDOMWindow().
        DOMWindow* domWindow() const;
        DOMWindow* existingDOMWindow() { return m_domWindow.get(); }
        void setDOMWindow(DOMWindow*);
        void clearDOMWindow();

        static Frame* frameForWidget(const Widget*);

        Settings* settings() const; // can be NULL

        void setPrinting(bool printing, const FloatSize& pageSize, const FloatSize& originalPageSize, float maximumShrinkRatio, AdjustViewSizeOrNot);
        bool shouldUsePrintingLayout() const;
        FloatSize resizePageRectsKeepingRatio(const FloatSize& originalSize, const FloatSize& expectedSize);

        bool inViewSourceMode() const;
        void setInViewSourceMode(bool = true);

        void setDocument(PassRefPtr<Document>);

        void setPageZoomFactor(float factor);
        float pageZoomFactor() const { return m_pageZoomFactor; }
        void setTextZoomFactor(float factor);
        float textZoomFactor() const { return m_textZoomFactor; }
        void setPageAndTextZoomFactors(float pageZoomFactor, float textZoomFactor);

        // Scale factor of this frame with respect to the container.
        float frameScaleFactor() const;

        void deviceOrPageScaleFactorChanged();

        // Orientation is the interface orientation in degrees. Some examples are:
        //  0 is straight up; -90 is when the device is rotated 90 clockwise;
        //  90 is when rotated counter clockwise.
        void sendOrientationChangeEvent(int orientation);
        int orientation() const { return m_orientation; }

        void clearTimers();
        static void clearTimers(FrameView*, Document*);

        String documentTypeString() const;

        String displayStringModifiedByEncoding(const String&) const;

        DragImageRef nodeImage(Node*);
        DragImageRef dragImageForSelection();

        VisiblePosition visiblePositionForPoint(const IntPoint& framePoint);
        Document* documentAtPoint(const IntPoint& windowPoint);
        PassRefPtr<Range> rangeForPoint(const IntPoint& framePoint);

        String searchForLabelsAboveCell(RegularExpression*, HTMLTableCellElement*, size_t* resultDistanceFromStartOfCell);
        String searchForLabelsBeforeElement(const Vector<String>& labels, Element*, size_t* resultDistance, bool* resultIsInCellAbove);
        String matchLabelsAgainstElement(const Vector<String>& labels, Element*);

        NSImage* selectionImage(bool forceBlackText = false) const;
        NSImage* rangeImage(Range*, bool forceBlackText = false) const;
        NSImage* snapshotDragImage(Node*, NSRect* imageRect, NSRect* elementRect) const;
        NSImage* imageFromRect(NSRect) const;
        void suspendActiveDOMObjectsAndAnimations();
        void resumeActiveDOMObjectsAndAnimations();
        bool activeDOMObjectsAndAnimationsSuspended() const { return m_activeDOMObjectsAndAnimationsSuspendedCount > 0; }

        // Should only be called on the main frame of a page.
        void notifyChromeClientWheelEventHandlerCountChanged() const;
        void notifyChromeClientTouchEventHandlerCountChanged() const;

    // ========

        Frame(Page*, HTMLFrameOwnerElement*, FrameLoaderClient*);

        void injectUserScriptsForWorld(DOMWrapperWorld*, const UserScriptVector&, UserScriptInjectionTime);

        HashSet<FrameDestructionObserver*> m_destructionObservers;

        Page* m_page;
        mutable FrameTree m_treeNode;
        mutable FrameLoader m_loader;
        mutable NavigationScheduler m_navigationScheduler;

        mutable RefPtr<DOMWindow> m_domWindow;

        HTMLFrameOwnerElement* m_ownerElement;
        RefPtr<FrameView> m_view;
        RefPtr<Document> m_doc;

        ScriptController m_script;

        mutable Editor m_editor;
        mutable FrameSelection m_selection;
        mutable EventHandler m_eventHandler;
        mutable AnimationController m_animationController;

        float m_pageZoomFactor;
        float m_textZoomFactor;

        int m_orientation;

        bool m_inViewSourceMode;
        bool m_isDisconnected;
        bool m_excludeFromTextSearch;

    // FIXME: The tiled backing store belongs in FrameView, not Frame.

        TiledBackingStore* tiledBackingStore() const { return m_tiledBackingStore.get(); }
        void setTiledBackingStoreEnabled(bool);

        // TiledBackingStoreClient interface
        virtual void tiledBackingStorePaintBegin();
        virtual void tiledBackingStorePaint(GraphicsContext*, const IntRect&);
        virtual void tiledBackingStorePaintEnd(const Vector<IntRect>& paintedArea);
        virtual IntRect tiledBackingStoreContentsRect();
        virtual IntRect tiledBackingStoreVisibleRect();
        virtual Color tiledBackingStoreBackgroundColor() const;

        OwnPtr<TiledBackingStore> m_tiledBackingStore;

        int m_activeDOMObjectsAndAnimationsSuspendedCount;

    inline void Frame::init()

    inline FrameLoader* Frame::loader() const
        return &m_loader;

    inline NavigationScheduler* Frame::navigationScheduler() const
        return &m_navigationScheduler;

    inline FrameView* Frame::view() const
        return m_view.get();

    inline ScriptController* Frame::script()
        return &m_script;

    inline Document* Frame::document() const
        return m_doc.get();

    inline FrameSelection* Frame::selection() const
        return &m_selection;

    inline Editor* Frame::editor() const
        return &m_editor;

    inline AnimationController* Frame::animation() const
        return &m_animationController;

    inline HTMLFrameOwnerElement* Frame::ownerElement() const
        return m_ownerElement;

    inline bool Frame::isDisconnected() const
        return m_isDisconnected;

    inline void Frame::setIsDisconnected(bool isDisconnected)
        m_isDisconnected = isDisconnected;

    inline bool Frame::excludeFromTextSearch() const
        return m_excludeFromTextSearch;

    inline void Frame::setExcludeFromTextSearch(bool exclude)
        m_excludeFromTextSearch = exclude;

    inline bool Frame::inViewSourceMode() const
        return m_inViewSourceMode;

    inline void Frame::setInViewSourceMode(bool mode)
        m_inViewSourceMode = mode;

    inline FrameTree* Frame::tree() const
        return &m_treeNode;

    inline Page* Frame::page() const
        return m_page;

    inline void Frame::detachFromPage()
        m_page = 0;

    inline EventHandler* Frame::eventHandler() const
        return &m_eventHandler;

} // namespace WebCore

#endif // Frame_h