Merge "[CherryPick] Refactoring: Move the content of HTMLInputElement::subtreeHasChan...
[framework/web/webkit-efl.git] / Source / WebCore / page / Page.h
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 "LayoutTypes.h"
28 #include "PageVisibilityState.h"
29 #include "PlatformScreen.h"
30 #include "PlatformString.h"
31 #include "Region.h"
32 #include "Supplementable.h"
33 #include "ViewportArguments.h"
34 #include <wtf/Forward.h>
35 #include <wtf/HashMap.h>
36 #include <wtf/HashSet.h>
37 #include <wtf/Noncopyable.h>
38
39 #if OS(SOLARIS)
40 #include <sys/time.h> // For time_t structure.
41 #endif
42
43 #if PLATFORM(MAC)
44 #include "SchedulePair.h"
45 #endif
46
47 namespace JSC {
48     class Debugger;
49 }
50
51 namespace WebCore {
52
53     class AlternativeTextClient;
54     class BackForwardController;
55     class BackForwardList;
56     class Chrome;
57     class ChromeClient;
58 #if ENABLE(CONTEXT_MENUS)
59     class ContextMenuClient;
60     class ContextMenuController;
61 #endif
62     class Document;
63     class DragCaretController;
64     class DragClient;
65     class DragController;
66     class EditorClient;
67     class FocusController;
68     class Frame;
69     class FrameSelection;
70     class HaltablePlugin;
71     class HistoryItem;
72     class InspectorClient;
73     class InspectorController;
74     class MediaCanStartListener;
75     class Node;
76     class PageGroup;
77     class PluginData;
78     class PointerLockController;
79     class ProgressTracker;
80     class Range;
81     class RenderObject;
82     class RenderTheme;
83     class VisibleSelection;
84     class ScrollableArea;
85     class ScrollingCoordinator;
86     class Settings;
87     class StorageNamespace;
88
89     typedef uint64_t LinkHash;
90
91     enum FindDirection { FindDirectionForward, FindDirectionBackward };
92
93     float deviceScaleFactor(Frame*);
94
95     struct ArenaSize {
96         ArenaSize(size_t treeSize, size_t allocated)
97             : treeSize(treeSize)
98             , allocated(allocated)
99         {
100         }
101         size_t treeSize;
102         size_t allocated;
103     };
104
105     class Page : public Supplementable<Page> {
106         WTF_MAKE_NONCOPYABLE(Page);
107         friend class Settings;
108     public:
109         static void scheduleForcedStyleRecalcForAllPages();
110
111         // It is up to the platform to ensure that non-null clients are provided where required.
112         struct PageClients {
113             WTF_MAKE_NONCOPYABLE(PageClients); WTF_MAKE_FAST_ALLOCATED;
114         public:
115             PageClients();
116             ~PageClients();
117
118             AlternativeTextClient* alternativeTextClient;
119             ChromeClient* chromeClient;
120 #if ENABLE(CONTEXT_MENUS)
121             ContextMenuClient* contextMenuClient;
122 #endif
123             EditorClient* editorClient;
124             DragClient* dragClient;
125             InspectorClient* inspectorClient;
126             RefPtr<BackForwardList> backForwardClient;
127         };
128
129         explicit Page(PageClients&);
130         ~Page();
131
132         ArenaSize renderTreeSize() const;
133
134         void setNeedsRecalcStyleInAllFrames();
135
136         RenderTheme* theme() const { return m_theme.get(); };
137
138         ViewportArguments viewportArguments() const;
139
140         static void refreshPlugins(bool reload);
141         PluginData* pluginData() const;
142
143         void setCanStartMedia(bool);
144         bool canStartMedia() const { return m_canStartMedia; }
145
146         EditorClient* editorClient() const { return m_editorClient; }
147
148         void setMainFrame(PassRefPtr<Frame>);
149         Frame* mainFrame() const { return m_mainFrame.get(); }
150
151         bool openedByDOM() const;
152         void setOpenedByDOM();
153
154         // DEPRECATED. Use backForward() instead of the following 6 functions.
155         BackForwardList* backForwardList() const;
156         bool goBack();
157         bool goForward();
158         bool canGoBackOrForward(int distance) const;
159         void goBackOrForward(int distance);
160         int getHistoryLength();
161
162         void goToItem(HistoryItem*, FrameLoadType);
163
164         void setGroupName(const String&);
165         const String& groupName() const;
166
167         PageGroup& group() { if (!m_group) initGroup(); return *m_group; }
168         PageGroup* groupPtr() { return m_group; } // can return 0
169
170         void incrementFrameCount() { ++m_frameCount; }
171         void decrementFrameCount() { ASSERT(m_frameCount); --m_frameCount; }
172         int frameCount() const { checkFrameCountConsistency(); return m_frameCount; }
173
174         Chrome* chrome() const { return m_chrome.get(); }
175         DragCaretController* dragCaretController() const { return m_dragCaretController.get(); }
176 #if ENABLE(DRAG_SUPPORT)
177         DragController* dragController() const { return m_dragController.get(); }
178 #endif
179         FocusController* focusController() const { return m_focusController.get(); }
180 #if ENABLE(CONTEXT_MENUS)
181         ContextMenuController* contextMenuController() const { return m_contextMenuController.get(); }
182 #endif
183 #if ENABLE(INSPECTOR)
184         InspectorController* inspectorController() const { return m_inspectorController.get(); }
185 #endif
186 #if ENABLE(POINTER_LOCK)
187         PointerLockController* pointerLockController() const { return m_pointerLockController.get(); }
188 #endif
189         ScrollingCoordinator* scrollingCoordinator();
190
191         Settings* settings() const { return m_settings.get(); }
192         ProgressTracker* progress() const { return m_progress.get(); }
193         BackForwardController* backForward() const { return m_backForwardController.get(); }
194
195         FeatureObserver* featureObserver() { return &m_featureObserver; }
196
197         enum ViewMode {
198             ViewModeInvalid,
199             ViewModeWindowed,
200             ViewModeFloating,
201             ViewModeFullscreen,
202             ViewModeMaximized,
203             ViewModeMinimized
204         };
205         static ViewMode stringToViewMode(const String&);
206
207         ViewMode viewMode() const { return m_viewMode; }
208         void setViewMode(ViewMode);
209         
210         void setTabKeyCyclesThroughElements(bool b) { m_tabKeyCyclesThroughElements = b; }
211         bool tabKeyCyclesThroughElements() const { return m_tabKeyCyclesThroughElements; }
212
213         bool findString(const String&, FindOptions);
214         // FIXME: Switch callers over to the FindOptions version and retire this one.
215         bool findString(const String&, TextCaseSensitivity, FindDirection, bool shouldWrap);
216
217         PassRefPtr<Range> rangeOfString(const String&, Range*, FindOptions);
218
219         unsigned markAllMatchesForText(const String&, FindOptions, bool shouldHighlight, unsigned);
220         // FIXME: Switch callers over to the FindOptions version and retire this one.
221         unsigned markAllMatchesForText(const String&, TextCaseSensitivity, bool shouldHighlight, unsigned);
222         void unmarkAllTextMatches();
223
224         // find all the Ranges for the matching text.
225         // Upon return, indexForSelection will be one of the following:
226         // 0 if there is no user selection
227         // the index of the first range after the user selection
228         // NoMatchBeforeUserSelection if there is no matching text after the user selection.
229         enum { NoMatchBeforeUserSelection = -1 };
230         void findStringMatchingRanges(const String&, FindOptions, int maxCount, Vector<RefPtr<Range> >*, int& indexForSelection);
231 #if PLATFORM(MAC)
232         void addSchedulePair(PassRefPtr<SchedulePair>);
233         void removeSchedulePair(PassRefPtr<SchedulePair>);
234         SchedulePairHashSet* scheduledRunLoopPairs() { return m_scheduledRunLoopPairs.get(); }
235
236         OwnPtr<SchedulePairHashSet> m_scheduledRunLoopPairs;
237 #endif
238
239         const VisibleSelection& selection() const;
240
241         void setDefersLoading(bool);
242         bool defersLoading() const { return m_defersLoading; }
243         
244         void clearUndoRedoOperations();
245
246         bool inLowQualityImageInterpolationMode() const;
247         void setInLowQualityImageInterpolationMode(bool = true);
248
249         float mediaVolume() const { return m_mediaVolume; }
250         void setMediaVolume(float volume);
251
252         void setPageScaleFactor(float scale, const IntPoint& origin);
253         float pageScaleFactor() const { return m_pageScaleFactor; }
254
255         float deviceScaleFactor() const { return m_deviceScaleFactor; }
256         void setDeviceScaleFactor(float);
257
258         struct Pagination {
259             enum Mode { Unpaginated, LeftToRightPaginated, RightToLeftPaginated, TopToBottomPaginated, BottomToTopPaginated };
260
261             Pagination()
262                 : mode(Unpaginated)
263                 , behavesLikeColumns(false)
264                 , pageLength(0)
265                 , gap(0)
266             {
267             };
268
269             bool operator==(const Pagination& other) const
270             {
271                 return mode == other.mode && behavesLikeColumns == other.behavesLikeColumns && pageLength == other.pageLength && gap == other.gap;
272             }
273
274             Mode mode;
275             bool behavesLikeColumns;
276             unsigned pageLength;
277             unsigned gap;
278         };
279
280         const Pagination& pagination() const { return m_pagination; }
281         void setPagination(const Pagination&);
282
283         unsigned pageCount() const;
284
285         // Notifications when the Page starts and stops being presented via a native window.
286         void didMoveOnscreen();
287         void willMoveOffscreen();
288         bool isOnscreen() const { return m_isOnscreen; }
289
290         void windowScreenDidChange(PlatformDisplayID);
291         
292         void suspendScriptedAnimations();
293         void resumeScriptedAnimations();
294         bool scriptedAnimationsSuspended() const { return m_scriptedAnimationsSuspended; }
295         
296         void userStyleSheetLocationChanged();
297         const String& userStyleSheet() const;
298
299         void dnsPrefetchingStateChanged();
300         void privateBrowsingStateChanged();
301
302         static void setDebuggerForAllPages(JSC::Debugger*);
303         void setDebugger(JSC::Debugger*);
304         JSC::Debugger* debugger() const { return m_debugger; }
305
306         static void removeAllVisitedLinks();
307
308         static void allVisitedStateChanged(PageGroup*);
309         static void visitedStateChanged(PageGroup*, LinkHash visitedHash);
310
311         StorageNamespace* sessionStorage(bool optionalCreate = true);
312         void setSessionStorage(PassRefPtr<StorageNamespace>);
313
314         void setCustomHTMLTokenizerTimeDelay(double);
315         bool hasCustomHTMLTokenizerTimeDelay() const { return m_customHTMLTokenizerTimeDelay != -1; }
316         double customHTMLTokenizerTimeDelay() const { ASSERT(m_customHTMLTokenizerTimeDelay != -1); return m_customHTMLTokenizerTimeDelay; }
317
318         void setCustomHTMLTokenizerChunkSize(int);
319         bool hasCustomHTMLTokenizerChunkSize() const { return m_customHTMLTokenizerChunkSize != -1; }
320         int customHTMLTokenizerChunkSize() const { ASSERT(m_customHTMLTokenizerChunkSize != -1); return m_customHTMLTokenizerChunkSize; }
321
322         void setMemoryCacheClientCallsEnabled(bool);
323         bool areMemoryCacheClientCallsEnabled() const { return m_areMemoryCacheClientCallsEnabled; }
324
325         void setJavaScriptURLsAreAllowed(bool);
326         bool javaScriptURLsAreAllowed() const;
327
328         // Don't allow more than a certain number of frames in a page.
329         // This seems like a reasonable upper bound, and otherwise mutually
330         // recursive frameset pages can quickly bring the program to its knees
331         // with exponential growth in the number of frames.
332         static const int maxNumberOfFrames = 1000;
333
334         void setEditable(bool isEditable) { m_isEditable = isEditable; }
335         bool isEditable() { return m_isEditable; }
336
337 #if ENABLE(PAGE_VISIBILITY_API)
338         PageVisibilityState visibilityState() const;
339         void setVisibilityState(PageVisibilityState, bool);
340 #endif
341
342         PlatformDisplayID displayID() const { return m_displayID; }
343
344         bool isCountingRelevantRepaintedObjects() const;
345         void setRelevantRepaintedObjectsCounterThreshold(uint64_t);
346         void startCountingRelevantRepaintedObjects();
347         void resetRelevantPaintedObjectCounter();
348         void addRelevantRepaintedObject(RenderObject*, const LayoutRect& objectPaintRect);
349         void addRelevantUnpaintedObject(RenderObject*, const LayoutRect& objectPaintRect);
350
351         void suspendActiveDOMObjectsAndAnimations();
352         void resumeActiveDOMObjectsAndAnimations();
353
354 #if ENABLE(TIZEN_RECORDING_SURFACE_SET)
355         bool m_recordingSurfaceSetEnable;
356         bool recordingSurfaceSetEnableGet() { return m_recordingSurfaceSetEnable; }
357 #endif
358
359 #ifndef NDEBUG
360         void setIsPainting(bool painting) { m_isPainting = painting; }
361         bool isPainting() const { return m_isPainting; }
362 #endif
363
364         AlternativeTextClient* alternativeTextClient() const { return m_alternativeTextClient; }
365
366         bool hasSeenPlugin(const String& serviceType) const;
367         bool hasSeenAnyPlugin() const;
368         void sawPlugin(const String& serviceType);
369         void resetSeenPlugins();
370
371     private:
372         void initGroup();
373
374 #if ASSERT_DISABLED
375         void checkFrameCountConsistency() const { }
376 #else
377         void checkFrameCountConsistency() const;
378 #endif
379
380         MediaCanStartListener* takeAnyMediaCanStartListener();
381
382         void setMinimumTimerInterval(double);
383         double minimumTimerInterval() const;
384
385         OwnPtr<Chrome> m_chrome;
386         OwnPtr<DragCaretController> m_dragCaretController;
387
388 #if ENABLE(DRAG_SUPPORT)
389         OwnPtr<DragController> m_dragController;
390 #endif
391         OwnPtr<FocusController> m_focusController;
392 #if ENABLE(CONTEXT_MENUS)
393         OwnPtr<ContextMenuController> m_contextMenuController;
394 #endif
395 #if ENABLE(INSPECTOR)
396         OwnPtr<InspectorController> m_inspectorController;
397 #endif
398 #if ENABLE(POINTER_LOCK)
399         OwnPtr<PointerLockController> m_pointerLockController;
400 #endif
401
402         RefPtr<ScrollingCoordinator> m_scrollingCoordinator;
403
404         OwnPtr<Settings> m_settings;
405         OwnPtr<ProgressTracker> m_progress;
406         
407         OwnPtr<BackForwardController> m_backForwardController;
408         RefPtr<Frame> m_mainFrame;
409
410         mutable RefPtr<PluginData> m_pluginData;
411
412         RefPtr<RenderTheme> m_theme;
413
414         EditorClient* m_editorClient;
415
416         FeatureObserver m_featureObserver;
417
418         int m_frameCount;
419         String m_groupName;
420         bool m_openedByDOM;
421
422         bool m_tabKeyCyclesThroughElements;
423         bool m_defersLoading;
424         unsigned m_defersLoadingCallCount;
425
426         bool m_inLowQualityInterpolationMode;
427         bool m_cookieEnabled;
428         bool m_areMemoryCacheClientCallsEnabled;
429         float m_mediaVolume;
430
431         float m_pageScaleFactor;
432         float m_deviceScaleFactor;
433
434         Pagination m_pagination;
435
436         bool m_javaScriptURLsAreAllowed;
437
438         String m_userStyleSheetPath;
439         mutable String m_userStyleSheet;
440         mutable bool m_didLoadUserStyleSheet;
441         mutable time_t m_userStyleSheetModificationTime;
442
443         OwnPtr<PageGroup> m_singlePageGroup;
444         PageGroup* m_group;
445
446         JSC::Debugger* m_debugger;
447
448         double m_customHTMLTokenizerTimeDelay;
449         int m_customHTMLTokenizerChunkSize;
450
451         bool m_canStartMedia;
452
453         RefPtr<StorageNamespace> m_sessionStorage;
454
455         ViewMode m_viewMode;
456
457         double m_minimumTimerInterval;
458
459         bool m_isEditable;
460         bool m_isOnscreen;
461
462 #if ENABLE(PAGE_VISIBILITY_API)
463         PageVisibilityState m_visibilityState;
464 #endif
465         PlatformDisplayID m_displayID;
466
467         HashSet<RenderObject*> m_relevantUnpaintedRenderObjects;
468         Region m_relevantPaintedRegion;
469         Region m_relevantUnpaintedRegion;
470         bool m_isCountingRelevantRepaintedObjects;
471 #ifndef NDEBUG
472         bool m_isPainting;
473 #endif
474         AlternativeTextClient* m_alternativeTextClient;
475
476         bool m_scriptedAnimationsSuspended;
477
478         HashSet<String> m_seenPlugins;
479     };
480
481 } // namespace WebCore
482     
483 #endif // Page_h