~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebCore/page/Page.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
 
3
 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
 
4
 *
 
5
 * This library is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU Library General Public
 
7
 * License as published by the Free Software Foundation; either
 
8
 * version 2 of the License, or (at your option) any later version.
 
9
 *
 
10
 * This library is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
 * Library General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU Library General Public License
 
16
 * along with this library; see the file COPYING.LIB.  If not, write to
 
17
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
18
 * Boston, MA 02110-1301, USA.
 
19
 */
 
20
 
 
21
#ifndef Page_h
 
22
#define Page_h
 
23
 
 
24
#include "FeatureObserver.h"
 
25
#include "FrameLoaderTypes.h"
 
26
#include "FindOptions.h"
 
27
#include "LayoutMilestones.h"
 
28
#include "LayoutRect.h"
 
29
#include "PageVisibilityState.h"
 
30
#include "Pagination.h"
 
31
#include "PlatformScreen.h"
 
32
#include "Region.h"
 
33
#include "Supplementable.h"
 
34
#include "ViewportArguments.h"
 
35
#include <wtf/Forward.h>
 
36
#include <wtf/HashMap.h>
 
37
#include <wtf/HashSet.h>
 
38
#include <wtf/Noncopyable.h>
 
39
#include <wtf/text/WTFString.h>
 
40
 
 
41
#if OS(SOLARIS)
 
42
#include <sys/time.h> // For time_t structure.
 
43
#endif
 
44
 
 
45
#if PLATFORM(MAC)
 
46
#include "SchedulePair.h"
 
47
#endif
 
48
 
 
49
namespace JSC {
 
50
    class Debugger;
 
51
}
 
52
 
 
53
namespace WebCore {
 
54
 
 
55
    class AlternativeTextClient;
 
56
    class BackForwardController;
 
57
    class BackForwardList;
 
58
    class Chrome;
 
59
    class ChromeClient;
 
60
#if ENABLE(CONTEXT_MENUS)
 
61
    class ContextMenuClient;
 
62
    class ContextMenuController;
 
63
#endif
 
64
    class Document;
 
65
    class DragCaretController;
 
66
    class DragClient;
 
67
    class DragController;
 
68
    class EditorClient;
 
69
    class FocusController;
 
70
    class Frame;
 
71
    class FrameSelection;
 
72
    class HaltablePlugin;
 
73
    class HistoryItem;
 
74
    class InspectorClient;
 
75
    class InspectorController;
 
76
    class MediaCanStartListener;
 
77
    class Node;
 
78
    class PageGroup;
 
79
    class PluginData;
 
80
    class PluginViewBase;
 
81
    class PointerLockController;
 
82
    class ProgressTracker;
 
83
    class Range;
 
84
    class RenderObject;
 
85
    class RenderTheme;
 
86
    class VisibleSelection;
 
87
    class ScrollableArea;
 
88
    class ScrollingCoordinator;
 
89
    class Settings;
 
90
    class StorageNamespace;
 
91
    class ValidationMessageClient;
 
92
 
 
93
    typedef uint64_t LinkHash;
 
94
 
 
95
    enum FindDirection { FindDirectionForward, FindDirectionBackward };
 
96
 
 
97
    float deviceScaleFactor(Frame*);
 
98
 
 
99
    struct ArenaSize {
 
100
        ArenaSize(size_t treeSize, size_t allocated)
 
101
            : treeSize(treeSize)
 
102
            , allocated(allocated)
 
103
        {
 
104
        }
 
105
        size_t treeSize;
 
106
        size_t allocated;
 
107
    };
 
108
 
 
109
    class Page : public Supplementable<Page> {
 
110
        WTF_MAKE_NONCOPYABLE(Page);
 
111
        friend class Settings;
 
112
    public:
 
113
        static void scheduleForcedStyleRecalcForAllPages();
 
114
 
 
115
        // It is up to the platform to ensure that non-null clients are provided where required.
 
116
        struct PageClients {
 
117
            WTF_MAKE_NONCOPYABLE(PageClients); WTF_MAKE_FAST_ALLOCATED;
 
118
        public:
 
119
            PageClients();
 
120
            ~PageClients();
 
121
 
 
122
            AlternativeTextClient* alternativeTextClient;
 
123
            ChromeClient* chromeClient;
 
124
#if ENABLE(CONTEXT_MENUS)
 
125
            ContextMenuClient* contextMenuClient;
 
126
#endif
 
127
            EditorClient* editorClient;
 
128
            DragClient* dragClient;
 
129
            InspectorClient* inspectorClient;
 
130
            RefPtr<BackForwardList> backForwardClient;
 
131
            ValidationMessageClient* validationMessageClient;
 
132
        };
 
133
 
 
134
        explicit Page(PageClients&);
 
135
        ~Page();
 
136
 
 
137
        ArenaSize renderTreeSize() const;
 
138
 
 
139
        void setNeedsRecalcStyleInAllFrames();
 
140
 
 
141
        RenderTheme* theme() const { return m_theme.get(); };
 
142
 
 
143
        ViewportArguments viewportArguments() const;
 
144
 
 
145
        static void refreshPlugins(bool reload);
 
146
        PluginData* pluginData() const;
 
147
 
 
148
        void setCanStartMedia(bool);
 
149
        bool canStartMedia() const { return m_canStartMedia; }
 
150
 
 
151
        EditorClient* editorClient() const { return m_editorClient; }
 
152
 
 
153
        void setMainFrame(PassRefPtr<Frame>);
 
154
        Frame* mainFrame() const { return m_mainFrame.get(); }
 
155
 
 
156
        bool openedByDOM() const;
 
157
        void setOpenedByDOM();
 
158
 
 
159
        // DEPRECATED. Use backForward() instead of the following 6 functions.
 
160
        BackForwardList* backForwardList() const;
 
161
        bool goBack();
 
162
        bool goForward();
 
163
        bool canGoBackOrForward(int distance) const;
 
164
        void goBackOrForward(int distance);
 
165
        int getHistoryLength();
 
166
 
 
167
        void goToItem(HistoryItem*, FrameLoadType);
 
168
 
 
169
        void setGroupName(const String&);
 
170
        const String& groupName() const;
 
171
 
 
172
        PageGroup& group() { if (!m_group) initGroup(); return *m_group; }
 
173
        PageGroup* groupPtr() { return m_group; } // can return 0
 
174
 
 
175
        void incrementSubframeCount() { ++m_subframeCount; }
 
176
        void decrementSubframeCount() { ASSERT(m_subframeCount); --m_subframeCount; }
 
177
        int subframeCount() const { checkSubframeCountConsistency(); return m_subframeCount; }
 
178
 
 
179
        Chrome* chrome() const { return m_chrome.get(); }
 
180
        DragCaretController* dragCaretController() const { return m_dragCaretController.get(); }
 
181
#if ENABLE(DRAG_SUPPORT)
 
182
        DragController* dragController() const { return m_dragController.get(); }
 
183
#endif
 
184
        FocusController* focusController() const { return m_focusController.get(); }
 
185
#if ENABLE(CONTEXT_MENUS)
 
186
        ContextMenuController* contextMenuController() const { return m_contextMenuController.get(); }
 
187
#endif
 
188
#if ENABLE(INSPECTOR)
 
189
        InspectorController* inspectorController() const { return m_inspectorController.get(); }
 
190
#endif
 
191
#if ENABLE(POINTER_LOCK)
 
192
        PointerLockController* pointerLockController() const { return m_pointerLockController.get(); }
 
193
#endif
 
194
        ValidationMessageClient* validationMessageClient() const { return m_validationMessageClient; }
 
195
 
 
196
        ScrollingCoordinator* scrollingCoordinator();
 
197
 
 
198
        String scrollingStateTreeAsText();
 
199
 
 
200
        Settings* settings() const { return m_settings.get(); }
 
201
        ProgressTracker* progress() const { return m_progress.get(); }
 
202
        BackForwardController* backForward() const { return m_backForwardController.get(); }
 
203
 
 
204
        FeatureObserver* featureObserver() { return &m_featureObserver; }
 
205
 
 
206
        enum ViewMode {
 
207
            ViewModeInvalid,
 
208
            ViewModeWindowed,
 
209
            ViewModeFloating,
 
210
            ViewModeFullscreen,
 
211
            ViewModeMaximized,
 
212
            ViewModeMinimized
 
213
        };
 
214
        static ViewMode stringToViewMode(const String&);
 
215
 
 
216
        ViewMode viewMode() const { return m_viewMode; }
 
217
        void setViewMode(ViewMode);
 
218
        
 
219
        void setTabKeyCyclesThroughElements(bool b) { m_tabKeyCyclesThroughElements = b; }
 
220
        bool tabKeyCyclesThroughElements() const { return m_tabKeyCyclesThroughElements; }
 
221
 
 
222
        bool findString(const String&, FindOptions);
 
223
        // FIXME: Switch callers over to the FindOptions version and retire this one.
 
224
        bool findString(const String&, TextCaseSensitivity, FindDirection, bool shouldWrap);
 
225
 
 
226
        PassRefPtr<Range> rangeOfString(const String&, Range*, FindOptions);
 
227
 
 
228
        unsigned markAllMatchesForText(const String&, FindOptions, bool shouldHighlight, unsigned);
 
229
        // FIXME: Switch callers over to the FindOptions version and retire this one.
 
230
        unsigned markAllMatchesForText(const String&, TextCaseSensitivity, bool shouldHighlight, unsigned);
 
231
        void unmarkAllTextMatches();
 
232
 
 
233
#if PLATFORM(MAC)
 
234
        void addSchedulePair(PassRefPtr<SchedulePair>);
 
235
        void removeSchedulePair(PassRefPtr<SchedulePair>);
 
236
        SchedulePairHashSet* scheduledRunLoopPairs() { return m_scheduledRunLoopPairs.get(); }
 
237
 
 
238
        OwnPtr<SchedulePairHashSet> m_scheduledRunLoopPairs;
 
239
#endif
 
240
 
 
241
        const VisibleSelection& selection() const;
 
242
 
 
243
        void setDefersLoading(bool);
 
244
        bool defersLoading() const { return m_defersLoading; }
 
245
        
 
246
        void clearUndoRedoOperations();
 
247
 
 
248
        bool inLowQualityImageInterpolationMode() const;
 
249
        void setInLowQualityImageInterpolationMode(bool = true);
 
250
 
 
251
        float mediaVolume() const { return m_mediaVolume; }
 
252
        void setMediaVolume(float volume);
 
253
 
 
254
        void setPageScaleFactor(float scale, const IntPoint& origin);
 
255
        float pageScaleFactor() const { return m_pageScaleFactor; }
 
256
 
 
257
        float deviceScaleFactor() const { return m_deviceScaleFactor; }
 
258
        void setDeviceScaleFactor(float);
 
259
 
 
260
        bool shouldSuppressScrollbarAnimations() const { return m_suppressScrollbarAnimations; }
 
261
        void setShouldSuppressScrollbarAnimations(bool suppressAnimations);
 
262
 
 
263
        // Page and FrameView both store a Pagination value. Page::pagination() is set only by API,
 
264
        // and FrameView::pagination() is set only by CSS. Page::pagination() will affect all
 
265
        // FrameViews in the page cache, but FrameView::pagination() only affects the current
 
266
        // FrameView. 
 
267
        const Pagination& pagination() const { return m_pagination; }
 
268
        void setPagination(const Pagination&);
 
269
 
 
270
        unsigned pageCount() const;
 
271
 
 
272
        // Notifications when the Page starts and stops being presented via a native window.
 
273
        void didMoveOnscreen();
 
274
        void willMoveOffscreen();
 
275
        bool isOnscreen() const { return m_isOnscreen; }
 
276
 
 
277
        void windowScreenDidChange(PlatformDisplayID);
 
278
        
 
279
        void suspendScriptedAnimations();
 
280
        void resumeScriptedAnimations();
 
281
        bool scriptedAnimationsSuspended() const { return m_scriptedAnimationsSuspended; }
 
282
        
 
283
        void userStyleSheetLocationChanged();
 
284
        const String& userStyleSheet() const;
 
285
 
 
286
        void dnsPrefetchingStateChanged();
 
287
        void storageBlockingStateChanged();
 
288
        void privateBrowsingStateChanged();
 
289
 
 
290
        static void setDebuggerForAllPages(JSC::Debugger*);
 
291
        void setDebugger(JSC::Debugger*);
 
292
        JSC::Debugger* debugger() const { return m_debugger; }
 
293
 
 
294
        static void removeAllVisitedLinks();
 
295
 
 
296
        static void allVisitedStateChanged(PageGroup*);
 
297
        static void visitedStateChanged(PageGroup*, LinkHash visitedHash);
 
298
 
 
299
        StorageNamespace* sessionStorage(bool optionalCreate = true);
 
300
        void setSessionStorage(PassRefPtr<StorageNamespace>);
 
301
 
 
302
        void setCustomHTMLTokenizerTimeDelay(double);
 
303
        bool hasCustomHTMLTokenizerTimeDelay() const { return m_customHTMLTokenizerTimeDelay != -1; }
 
304
        double customHTMLTokenizerTimeDelay() const { ASSERT(m_customHTMLTokenizerTimeDelay != -1); return m_customHTMLTokenizerTimeDelay; }
 
305
 
 
306
        void setCustomHTMLTokenizerChunkSize(int);
 
307
        bool hasCustomHTMLTokenizerChunkSize() const { return m_customHTMLTokenizerChunkSize != -1; }
 
308
        int customHTMLTokenizerChunkSize() const { ASSERT(m_customHTMLTokenizerChunkSize != -1); return m_customHTMLTokenizerChunkSize; }
 
309
 
 
310
        void setMemoryCacheClientCallsEnabled(bool);
 
311
        bool areMemoryCacheClientCallsEnabled() const { return m_areMemoryCacheClientCallsEnabled; }
 
312
 
 
313
        // Don't allow more than a certain number of frames in a page.
 
314
        // This seems like a reasonable upper bound, and otherwise mutually
 
315
        // recursive frameset pages can quickly bring the program to its knees
 
316
        // with exponential growth in the number of frames.
 
317
        static const int maxNumberOfFrames = 1000;
 
318
 
 
319
        void setEditable(bool isEditable) { m_isEditable = isEditable; }
 
320
        bool isEditable() { return m_isEditable; }
 
321
 
 
322
#if ENABLE(PAGE_VISIBILITY_API)
 
323
        PageVisibilityState visibilityState() const;
 
324
#endif
 
325
#if ENABLE(PAGE_VISIBILITY_API) || ENABLE(HIDDEN_PAGE_DOM_TIMER_THROTTLING)
 
326
        void setVisibilityState(PageVisibilityState, bool);
 
327
#endif
 
328
 
 
329
        PlatformDisplayID displayID() const { return m_displayID; }
 
330
 
 
331
        void addLayoutMilestones(LayoutMilestones);
 
332
        LayoutMilestones layoutMilestones() const { return m_layoutMilestones; }
 
333
 
 
334
        bool isCountingRelevantRepaintedObjects() const;
 
335
        void startCountingRelevantRepaintedObjects();
 
336
        void resetRelevantPaintedObjectCounter();
 
337
        void addRelevantRepaintedObject(RenderObject*, const LayoutRect& objectPaintRect);
 
338
        void addRelevantUnpaintedObject(RenderObject*, const LayoutRect& objectPaintRect);
 
339
 
 
340
        void suspendActiveDOMObjectsAndAnimations();
 
341
        void resumeActiveDOMObjectsAndAnimations();
 
342
#ifndef NDEBUG
 
343
        void setIsPainting(bool painting) { m_isPainting = painting; }
 
344
        bool isPainting() const { return m_isPainting; }
 
345
#endif
 
346
 
 
347
        AlternativeTextClient* alternativeTextClient() const { return m_alternativeTextClient; }
 
348
 
 
349
        bool hasSeenPlugin(const String& serviceType) const;
 
350
        bool hasSeenAnyPlugin() const;
 
351
        void sawPlugin(const String& serviceType);
 
352
        void resetSeenPlugins();
 
353
 
 
354
        bool hasSeenMediaEngine(const String& engineName) const;
 
355
        bool hasSeenAnyMediaEngine() const;
 
356
        void sawMediaEngine(const String& engineName);
 
357
        void resetSeenMediaEngines();
 
358
 
 
359
        void reportMemoryUsage(MemoryObjectInfo*) const;
 
360
 
 
361
    private:
 
362
        void initGroup();
 
363
 
 
364
#if ASSERT_DISABLED
 
365
        void checkSubframeCountConsistency() const { }
 
366
#else
 
367
        void checkSubframeCountConsistency() const;
 
368
#endif
 
369
 
 
370
        MediaCanStartListener* takeAnyMediaCanStartListener();
 
371
 
 
372
        void setMinimumTimerInterval(double);
 
373
        double minimumTimerInterval() const;
 
374
 
 
375
        void setTimerAlignmentInterval(double);
 
376
        double timerAlignmentInterval() const;
 
377
 
 
378
        void collectPluginViews(Vector<RefPtr<PluginViewBase>, 32>& pluginViewBases);
 
379
 
 
380
        OwnPtr<Chrome> m_chrome;
 
381
        OwnPtr<DragCaretController> m_dragCaretController;
 
382
 
 
383
#if ENABLE(DRAG_SUPPORT)
 
384
        OwnPtr<DragController> m_dragController;
 
385
#endif
 
386
        OwnPtr<FocusController> m_focusController;
 
387
#if ENABLE(CONTEXT_MENUS)
 
388
        OwnPtr<ContextMenuController> m_contextMenuController;
 
389
#endif
 
390
#if ENABLE(INSPECTOR)
 
391
        OwnPtr<InspectorController> m_inspectorController;
 
392
#endif
 
393
#if ENABLE(POINTER_LOCK)
 
394
        OwnPtr<PointerLockController> m_pointerLockController;
 
395
#endif
 
396
        RefPtr<ScrollingCoordinator> m_scrollingCoordinator;
 
397
 
 
398
        OwnPtr<Settings> m_settings;
 
399
        OwnPtr<ProgressTracker> m_progress;
 
400
        
 
401
        OwnPtr<BackForwardController> m_backForwardController;
 
402
        RefPtr<Frame> m_mainFrame;
 
403
 
 
404
        mutable RefPtr<PluginData> m_pluginData;
 
405
 
 
406
        RefPtr<RenderTheme> m_theme;
 
407
 
 
408
        EditorClient* m_editorClient;
 
409
        ValidationMessageClient* m_validationMessageClient;
 
410
 
 
411
        FeatureObserver m_featureObserver;
 
412
 
 
413
        int m_subframeCount;
 
414
        String m_groupName;
 
415
        bool m_openedByDOM;
 
416
 
 
417
        bool m_tabKeyCyclesThroughElements;
 
418
        bool m_defersLoading;
 
419
        unsigned m_defersLoadingCallCount;
 
420
 
 
421
        bool m_inLowQualityInterpolationMode;
 
422
        bool m_cookieEnabled;
 
423
        bool m_areMemoryCacheClientCallsEnabled;
 
424
        float m_mediaVolume;
 
425
 
 
426
        float m_pageScaleFactor;
 
427
        float m_deviceScaleFactor;
 
428
 
 
429
        bool m_suppressScrollbarAnimations;
 
430
 
 
431
        Pagination m_pagination;
 
432
 
 
433
        String m_userStyleSheetPath;
 
434
        mutable String m_userStyleSheet;
 
435
        mutable bool m_didLoadUserStyleSheet;
 
436
        mutable time_t m_userStyleSheetModificationTime;
 
437
 
 
438
        OwnPtr<PageGroup> m_singlePageGroup;
 
439
        PageGroup* m_group;
 
440
 
 
441
        JSC::Debugger* m_debugger;
 
442
 
 
443
        double m_customHTMLTokenizerTimeDelay;
 
444
        int m_customHTMLTokenizerChunkSize;
 
445
 
 
446
        bool m_canStartMedia;
 
447
 
 
448
        RefPtr<StorageNamespace> m_sessionStorage;
 
449
 
 
450
        ViewMode m_viewMode;
 
451
 
 
452
        double m_minimumTimerInterval;
 
453
 
 
454
        double m_timerAlignmentInterval;
 
455
 
 
456
        bool m_isEditable;
 
457
        bool m_isOnscreen;
 
458
 
 
459
#if ENABLE(PAGE_VISIBILITY_API)
 
460
        PageVisibilityState m_visibilityState;
 
461
#endif
 
462
        PlatformDisplayID m_displayID;
 
463
 
 
464
        LayoutMilestones m_layoutMilestones;
 
465
 
 
466
        HashSet<RenderObject*> m_relevantUnpaintedRenderObjects;
 
467
        Region m_relevantPaintedRegion;
 
468
        Region m_relevantUnpaintedRegion;
 
469
        bool m_isCountingRelevantRepaintedObjects;
 
470
#ifndef NDEBUG
 
471
        bool m_isPainting;
 
472
#endif
 
473
        AlternativeTextClient* m_alternativeTextClient;
 
474
 
 
475
        bool m_scriptedAnimationsSuspended;
 
476
 
 
477
        HashSet<String> m_seenPlugins;
 
478
        HashSet<String> m_seenMediaEngines;
 
479
    };
 
480
 
 
481
} // namespace WebCore
 
482
    
 
483
#endif // Page_h