Frame.h 15 KB
Newer Older
darin's avatar
darin committed
1
/*
kocienda's avatar
kocienda committed
2
 * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
3 4 5 6
 *                     1999-2001 Lars Knoll <knoll@kde.org>
 *                     1999-2001 Antti Koivisto <koivisto@kde.org>
 *                     2000-2001 Simon Hausmann <hausmann@kde.org>
 *                     2000-2001 Dirk Mueller <mueller@kde.org>
kocienda's avatar
kocienda committed
7
 *                     2000 Stefan Schimanski <1Stein@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@webkit.org>
kocienda's avatar
kocienda committed
11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * 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
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * 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
ddkilzer's avatar
ddkilzer committed
24 25
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
kocienda's avatar
kocienda committed
26 27
 */

28 29
#ifndef Frame_h
#define Frame_h
darin's avatar
darin committed
30

31
#include "AdjustViewSizeOrNot.h"
32
#include "FrameLoader.h"
33
#include "FrameTree.h"
34
#include "IntRect.h"
35
#include "NavigationScheduler.h"
36
#include "ScrollTypes.h"
37
#include "UserScriptTypes.h"
38
#include <wtf/RefCounted.h>
kocienda's avatar
kocienda committed
39

40 41 42 43 44
#if PLATFORM(IOS)
#include "ViewportArguments.h"
#include "VisibleSelection.h"
#endif

45 46 47 48
#if PLATFORM(WIN)
#include "FrameWin.h"
#endif

49
#if USE(TILED_BACKING_STORE)
50 51 52
#include "TiledBackingStoreClient.h"
#endif

53 54 55 56 57 58 59
#if PLATFORM(IOS)
OBJC_CLASS DOMCSSStyleDeclaration;
OBJC_CLASS DOMNode;
OBJC_CLASS NSArray;
OBJC_CLASS NSString;
#endif

sfalken@apple.com's avatar
sfalken@apple.com committed
60 61 62 63
#if PLATFORM(WIN)
typedef struct HBITMAP__* HBITMAP;
#endif

darin's avatar
darin committed
64 65
namespace WebCore {

66 67
    class AnimationController;
    class Color;
68
    class Document;
69 70 71
    class Editor;
    class Element;
    class EventHandler;
72
    class FloatSize;
73
    class FrameDestructionObserver;
74
    class FrameSelection;
75
    class FrameView;
76
    class HTMLFrameOwnerElement;
77
    class HTMLTableCellElement;
78
    class HitTestResult;
79
    class ImageBuffer;
80
    class IntRect;
81
    class MainFrame;
82
    class Node;
zandobersek@gmail.com's avatar
zandobersek@gmail.com committed
83
    class Range;
84
    class RegularExpression;
85
    class RenderLayer;
86
    class RenderView;
87
    class RenderWidget;
88
    class ScriptController;
89 90 91
    class Settings;
    class TiledBackingStore;
    class VisiblePosition;
92
    class Widget;
darin's avatar
darin committed
93

94 95 96 97 98 99 100 101 102 103 104 105 106
#if PLATFORM(IOS)
    enum {
        OverflowScrollNone = 0,
        OverflowScrollLeft = 1 << 0,
        OverflowScrollRight = 1 << 1,
        OverflowScrollUp = 1 << 2,
        OverflowScrollDown = 1 << 3
    };

    enum OverflowScrollAction { DoNotPerformOverflowScroll, PerformOverflowScroll };
    typedef Node* (*NodeQualifier)(const HitTestResult&, Node* terminationNode, IntRect* nodeBounds);
#endif

107
#if !USE(TILED_BACKING_STORE)
108
    class TiledBackingStoreClient { };
109
#endif
110

111 112
    enum {
        LayerTreeFlagsIncludeDebugInfo = 1 << 0,
113
        LayerTreeFlagsIncludeVisibleRects = 1 << 1,
114
        LayerTreeFlagsIncludeTileCaches = 1 << 2,
115
        LayerTreeFlagsIncludeRepaintRects = 1 << 3,
116 117
        LayerTreeFlagsIncludePaintingPhases = 1 << 4,
        LayerTreeFlagsIncludeContentLayers = 1 << 5
118 119 120
    };
    typedef unsigned LayerTreeFlags;

121
    class Frame : public RefCounted<Frame>, public TiledBackingStoreClient {
122
    public:
123
        static PassRefPtr<Frame> create(Page*, HTMLFrameOwnerElement*, FrameLoaderClient*);
mjs's avatar
mjs committed
124

125
        void init();
126 127 128 129
#if PLATFORM(IOS)
        // Creates <html><body style="..."></body></html> doing minimal amount of work.
        void initWithSimpleHTMLDocument(const String& style, const URL&);
#endif
130
        void setView(PassRefPtr<FrameView>);
131 132 133
        void createView(const IntSize&, const Color&, bool,
            const IntSize& fixedLayoutSize = IntSize(), const IntRect& fixedVisibleContentRect = IntRect(),
            bool useFixedLayout = false, ScrollbarMode = ScrollbarAuto, bool horizontalLock = false,
134
            ScrollbarMode = ScrollbarAuto, bool verticalLock = false);
darin's avatar
darin committed
135

darin@apple.com's avatar
darin@apple.com committed
136
        virtual ~Frame();
darin's avatar
darin committed
137

138 139 140
        void addDestructionObserver(FrameDestructionObserver*);
        void removeDestructionObserver(FrameDestructionObserver*);

141
        void willDetachPage();
142
        void detachFromPage();
143
        void disconnectOwnerElement();
darin's avatar
darin committed
144

145 146 147
        MainFrame& mainFrame() const;
        bool isMainFrame() const;

148 149 150
        Page* page() const;
        HTMLFrameOwnerElement* ownerElement() const;

151 152
        Document* document() const;
        FrameView* view() const;
153

154
        Editor& editor() const;
155
        EventHandler& eventHandler() const;
156
        FrameLoader& loader() const;
157
        NavigationScheduler& navigationScheduler() const;
158
        FrameSelection& selection() const;
159
        FrameTree& tree() const;
160
        AnimationController& animation() const;
161
        ScriptController& script();
162
        
163
        RenderView* contentRenderer() const; // Root of the render tree for the document contained in this frame.
164
        RenderWidget* ownerRenderer() const; // Renderer for the element that contains this frame.
165 166

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

168
        void injectUserScripts(UserScriptInjectionTime);
169
        
170
        String layerTreeAsText(LayerTreeFlags = 0) const;
171
        String trackedRepaintRectsAsText() const;
172

173
        static Frame* frameForWidget(const Widget*);
hyatt's avatar
hyatt committed
174

175
        Settings& settings() const { return *m_settings; }
ggaren's avatar
ggaren committed
176

177
        void setPrinting(bool printing, const FloatSize& pageSize, const FloatSize& originalPageSize, float maximumShrinkRatio, AdjustViewSizeOrNot);
178
        bool shouldUsePrintingLayout() const;
179
        FloatSize resizePageRectsKeepingRatio(const FloatSize& originalSize, const FloatSize& expectedSize);
darin's avatar
darin committed
180

181 182
        bool inViewSourceMode() const;
        void setInViewSourceMode(bool = true);
darin's avatar
darin committed
183

184
        void setDocument(PassRefPtr<Document>);
darin's avatar
darin committed
185

186 187 188 189 190 191
        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);

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

195 196 197
#if USE(ACCELERATED_COMPOSITING)
        void deviceOrPageScaleFactorChanged();
#endif
198

199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
#if PLATFORM(IOS)
        const ViewportArguments& viewportArguments() const;
        void setViewportArguments(const ViewportArguments&);

        Node* deepestNodeAtLocation(const FloatPoint& viewportLocation);
        Node* nodeRespondingToClickEvents(const FloatPoint& viewportLocation, FloatPoint& adjustedViewportLocation);
        Node* nodeRespondingToScrollWheelEvents(const FloatPoint& viewportLocation);

        int indexCountOfWordPrecedingSelection(NSString* word) const;
        NSArray* wordsInCurrentParagraph() const;
        CGRect renderRectForPoint(CGPoint, bool* isReplaced, float* fontSize) const;

        void setSelectionChangeCallbacksDisabled(bool = true);
        bool selectionChangeCallbacksDisabled() const;

        enum ViewportOffsetChangeType { IncrementalScrollOffset, CompletedScrollOffset };
        void viewportOffsetChanged(ViewportOffsetChangeType);
        bool containsTiledBackingLayers() const;

        void overflowScrollPositionChangedForNode(const IntPoint&, Node*, bool isUserScroll);

        void resetAllGeolocationPermission();
#endif

223 224 225 226 227 228 229 230
#if ENABLE(ORIENTATION_EVENTS)
        // 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; }
#endif

231 232 233
        void clearTimers();
        static void clearTimers(FrameView*, Document*);

234
        String displayStringModifiedByEncoding(const String&) const;
235

236
        VisiblePosition visiblePositionForPoint(const IntPoint& framePoint);
237
        Document* documentAtPoint(const IntPoint& windowPoint);
238
        PassRefPtr<Range> rangeForPoint(const IntPoint& framePoint);
mjs's avatar
mjs committed
239

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

244 245 246 247 248
#if ENABLE(IOS_TEXT_AUTOSIZING)
        void setTextAutosizingWidth(float);
        float textAutosizingWidth() const;
#endif

249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
#if PLATFORM(IOS)
        // Scroll the selection in an overflow layer on iOS.
        void scrollOverflowLayer(RenderLayer* , const IntRect& visibleRect, const IntRect& exposeRect);

        int preferredHeight() const;
        int innerLineHeight(DOMNode*) const;
        void updateLayout() const;
        NSRect caretRect() const;
        NSRect rectForScrollToVisible() const;
        NSRect rectForSelection(VisibleSelection&) const;
        DOMCSSStyleDeclaration* styleAtSelectionStart() const;
        unsigned formElementsCharacterCount() const;
        void setTimersPaused(bool);
        bool timersPaused() const { return m_timersPausedCount; }
        void dispatchPageHideEventBeforePause();
        void dispatchPageShowEventBeforeResume();
        void setRangedSelectionBaseToCurrentSelection();
        void setRangedSelectionBaseToCurrentSelectionStart();
        void setRangedSelectionBaseToCurrentSelectionEnd();
        void clearRangedSelectionInitialExtent();
        void setRangedSelectionInitialExtentToCurrentSelectionStart();
        void setRangedSelectionInitialExtentToCurrentSelectionEnd();
        VisibleSelection rangedSelectionBase() const;
        VisibleSelection rangedSelectionInitialExtent() const;
        void recursiveSetUpdateAppearanceEnabled(bool);
        NSArray* interpretationsForCurrentRoot() const;
#endif
276 277 278
        void suspendActiveDOMObjectsAndAnimations();
        void resumeActiveDOMObjectsAndAnimations();
        bool activeDOMObjectsAndAnimationsSuspended() const { return m_activeDOMObjectsAndAnimationsSuspendedCount > 0; }
279

darin@apple.com's avatar
darin@apple.com committed
280
        bool isURLAllowed(const URL&) const;
281

282 283
    // ========

darin@apple.com's avatar
darin@apple.com committed
284 285
    protected:
        Frame(Page&, HTMLFrameOwnerElement*, FrameLoaderClient&);
286

darin@apple.com's avatar
darin@apple.com committed
287
    private:
288
        void injectUserScriptsForWorld(DOMWrapperWorld&, const UserScriptVector&, UserScriptInjectionTime);
289

290 291
        HashSet<FrameDestructionObserver*> m_destructionObservers;

292
        MainFrame& m_mainFrame;
293
        Page* m_page;
294
        const RefPtr<Settings> m_settings;
295
        mutable FrameTree m_treeNode;
296
        mutable FrameLoader m_loader;
297
        mutable NavigationScheduler m_navigationScheduler;
298

299 300 301
        HTMLFrameOwnerElement* m_ownerElement;
        RefPtr<FrameView> m_view;
        RefPtr<Document> m_doc;
302

andersca@apple.com's avatar
andersca@apple.com committed
303
        const std::unique_ptr<ScriptController> m_script;
304
        const OwnPtr<Editor> m_editor;
305
        const OwnPtr<FrameSelection> m_selection;
306
        const OwnPtr<EventHandler> m_eventHandler;
andersca@apple.com's avatar
andersca@apple.com committed
307
        const std::unique_ptr<AnimationController> m_animationController;
308

309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
#if PLATFORM(IOS)
        void betterApproximateNode(const IntPoint& testPoint, NodeQualifier, Node*& best, Node* failedNode, IntPoint& bestPoint, IntRect& bestRect, const IntRect& testRect);
        bool hitTestResultAtViewportLocation(const FloatPoint& viewportLocation, HitTestResult&, IntPoint& center);
        Node* qualifyingNodeAtViewportLocation(const FloatPoint& viewportLocation, FloatPoint& adjustedViewportLocation, NodeQualifier, bool shouldApproximate);

        void overflowAutoScrollTimerFired(Timer<Frame>*);
        void startOverflowAutoScroll(const IntPoint&);
        int checkOverflowScroll(OverflowScrollAction);

        void setTimersPausedInternal(bool);

        Timer<Frame> m_overflowAutoScrollTimer;
        float m_overflowAutoScrollDelta;
        IntPoint m_overflowAutoScrollPos;
        ViewportArguments m_viewportArguments;
        bool m_selectionChangeCallbacksDisabled;
        int m_timersPausedCount;
        VisibleSelection m_rangedSelectionBase;
        VisibleSelection m_rangedSelectionInitialExtent;
#endif

330 331 332 333
#if ENABLE(IOS_TEXT_AUTOSIZING)
        float m_textAutosizingWidth;
#endif

334 335 336
        float m_pageZoomFactor;
        float m_textZoomFactor;

337 338 339
#if ENABLE(ORIENTATION_EVENTS)
        int m_orientation;
#endif
340 341

        bool m_inViewSourceMode;
342

343
#if USE(TILED_BACKING_STORE)
344 345 346 347 348 349 350 351
    // FIXME: The tiled backing store belongs in FrameView, not Frame.

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

    private:
        // TiledBackingStoreClient interface
352 353 354 355 356 357
        virtual void tiledBackingStorePaintBegin() override final;
        virtual void tiledBackingStorePaint(GraphicsContext*, const IntRect&) override final;
        virtual void tiledBackingStorePaintEnd(const Vector<IntRect>& paintedArea) override final;
        virtual IntRect tiledBackingStoreContentsRect() override final;
        virtual IntRect tiledBackingStoreVisibleRect() override final;
        virtual Color tiledBackingStoreBackgroundColor() const override final;
358

359 360
        OwnPtr<TiledBackingStore> m_tiledBackingStore;
#endif
361

362
        int m_activeDOMObjectsAndAnimationsSuspendedCount;
363
    };
kocienda's avatar
kocienda committed
364

365 366 367 368 369
    inline void Frame::init()
    {
        m_loader.init();
    }

370
    inline FrameLoader& Frame::loader() const
371
    {
372
        return m_loader;
373 374
    }

375
    inline NavigationScheduler& Frame::navigationScheduler() const
376
    {
377
        return m_navigationScheduler;
378 379 380 381 382 383 384
    }

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

385
    inline ScriptController& Frame::script()
386
    {
387
        return *m_script;
388 389 390 391 392 393 394
    }

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

395
    inline FrameSelection& Frame::selection() const
396
    {
397
        return *m_selection;
398 399
    }

400
    inline Editor& Frame::editor() const
401
    {
402
        return *m_editor;
403 404
    }

405
    inline AnimationController& Frame::animation() const
406
    {
407
        return *m_animationController;
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
    }

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

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

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

425
    inline FrameTree& Frame::tree() const
426
    {
427
        return m_treeNode;
428 429 430 431 432 433 434
    }

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

435 436 437 438 439
    inline void Frame::detachFromPage()
    {
        m_page = 0;
    }

440
    inline EventHandler& Frame::eventHandler() const
441
    {
442
        return *m_eventHandler;
443 444
    }

445 446 447 448 449
    inline MainFrame& Frame::mainFrame() const
    {
        return m_mainFrame;
    }

weinig's avatar
weinig committed
450
} // namespace WebCore
darin's avatar
darin committed
451

452
#endif // Frame_h