Home | History | Annotate | Download | only in page
      1 /*
      2  * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2013 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 "core/dom/ViewportArguments.h"
     25 #include "core/page/LayoutMilestones.h"
     26 #include "core/page/PageVisibilityState.h"
     27 #include "core/page/UseCounter.h"
     28 #include "core/platform/LifecycleContext.h"
     29 #include "core/platform/Supplementable.h"
     30 #include "core/platform/graphics/LayoutRect.h"
     31 #include "core/platform/graphics/Region.h"
     32 #include "core/rendering/Pagination.h"
     33 #include "wtf/Forward.h"
     34 #include "wtf/HashSet.h"
     35 #include "wtf/Noncopyable.h"
     36 #include "wtf/text/WTFString.h"
     37 
     38 namespace WebCore {
     39 
     40 class AutoscrollController;
     41 class BackForwardClient;
     42 class BackForwardController;
     43 class Chrome;
     44 class ChromeClient;
     45 class ClientRectList;
     46 class ContextMenuClient;
     47 class ContextMenuController;
     48 class Document;
     49 class DragCaretController;
     50 class DragClient;
     51 class DragController;
     52 class EditorClient;
     53 class FocusController;
     54 class Frame;
     55 class FrameSelection;
     56 class HaltablePlugin;
     57 class HistoryItem;
     58 class InspectorClient;
     59 class InspectorController;
     60 class Node;
     61 class PageConsole;
     62 class PageGroup;
     63 class PageLifecycleNotifier;
     64 class PlatformMouseEvent;
     65 class PluginData;
     66 class PointerLockController;
     67 class ProgressTracker;
     68 class Range;
     69 class RenderBox;
     70 class RenderObject;
     71 class RenderTheme;
     72 class VisibleSelection;
     73 class ScrollableArea;
     74 class ScrollingCoordinator;
     75 class Settings;
     76 class StorageNamespace;
     77 class ValidationMessageClient;
     78 
     79 typedef uint64_t LinkHash;
     80 
     81 float deviceScaleFactor(Frame*);
     82 
     83 class Page : public Supplementable<Page>, public LifecycleContext {
     84     WTF_MAKE_NONCOPYABLE(Page);
     85     friend class Settings;
     86 public:
     87     static void scheduleForcedStyleRecalcForAllPages();
     88 
     89     // It is up to the platform to ensure that non-null clients are provided where required.
     90     struct PageClients {
     91         WTF_MAKE_NONCOPYABLE(PageClients); WTF_MAKE_FAST_ALLOCATED;
     92     public:
     93         PageClients();
     94         ~PageClients();
     95 
     96         ChromeClient* chromeClient;
     97         ContextMenuClient* contextMenuClient;
     98         EditorClient* editorClient;
     99         DragClient* dragClient;
    100         InspectorClient* inspectorClient;
    101         BackForwardClient* backForwardClient;
    102     };
    103 
    104     explicit Page(PageClients&);
    105     ~Page();
    106 
    107     void setNeedsRecalcStyleInAllFrames();
    108 
    109     RenderTheme* theme() const { return m_theme.get(); }
    110 
    111     ViewportArguments viewportArguments() const;
    112 
    113     static void refreshPlugins(bool reload);
    114     PluginData* pluginData() const;
    115 
    116     EditorClient* editorClient() const { return m_editorClient; }
    117 
    118     void setMainFrame(PassRefPtr<Frame>);
    119     Frame* mainFrame() const { return m_mainFrame.get(); }
    120 
    121     bool openedByDOM() const;
    122     void setOpenedByDOM();
    123 
    124     // DEPRECATED. Use backForward() instead of the following function.
    125     void goToItem(HistoryItem*);
    126 
    127     // FIXME: InspectorPageGroup is only needed to support single process debugger layout tests, it should be removed when DumpRenderTree is gone.
    128     enum PageGroupType { InspectorPageGroup, PrivatePageGroup, SharedPageGroup };
    129     void setGroupType(PageGroupType);
    130     void clearPageGroup();
    131     PageGroup& group()
    132     {
    133         if (!m_group)
    134             setGroupType(PrivatePageGroup);
    135         return *m_group;
    136     }
    137 
    138     void incrementSubframeCount() { ++m_subframeCount; }
    139     void decrementSubframeCount() { ASSERT(m_subframeCount); --m_subframeCount; }
    140     int subframeCount() const { checkSubframeCountConsistency(); return m_subframeCount; }
    141 
    142     Chrome& chrome() const { return *m_chrome; }
    143     DragCaretController& dragCaretController() const { return *m_dragCaretController; }
    144     DragController& dragController() const { return *m_dragController; }
    145     FocusController& focusController() const { return *m_focusController; }
    146     ContextMenuController* contextMenuController() const { return m_contextMenuController.get(); }
    147     InspectorController* inspectorController() const { return m_inspectorController.get(); }
    148     PointerLockController* pointerLockController() const { return m_pointerLockController.get(); }
    149     ValidationMessageClient* validationMessageClient() const { return m_validationMessageClient; }
    150     void setValidationMessageClient(ValidationMessageClient* client) { m_validationMessageClient = client; }
    151 
    152     bool autoscrollInProgress() const;
    153     bool autoscrollInProgress(const RenderBox*) const;
    154     bool panScrollInProgress() const;
    155     void startAutoscrollForSelection(RenderObject*);
    156     void stopAutoscrollIfNeeded(RenderObject*);
    157     void stopAutoscrollTimer();
    158     void updateAutoscrollRenderer();
    159     void updateDragAndDrop(Node* targetNode, const IntPoint& eventPosition, double eventTime);
    160 #if OS(WINDOWS)
    161     void handleMouseReleaseForPanScrolling(Frame*, const PlatformMouseEvent&);
    162     void startPanScrolling(RenderBox*, const IntPoint&);
    163 #endif
    164 
    165     ScrollingCoordinator* scrollingCoordinator();
    166 
    167     String mainThreadScrollingReasonsAsText();
    168     PassRefPtr<ClientRectList> nonFastScrollableRects(const Frame*);
    169 
    170     Settings* settings() const { return m_settings.get(); }
    171     ProgressTracker* progress() const { return m_progress.get(); }
    172     BackForwardController* backForward() const { return m_backForwardController.get(); }
    173 
    174     UseCounter* useCounter() { return &m_UseCounter; }
    175 
    176     void setTabKeyCyclesThroughElements(bool b) { m_tabKeyCyclesThroughElements = b; }
    177     bool tabKeyCyclesThroughElements() const { return m_tabKeyCyclesThroughElements; }
    178 
    179     void unmarkAllTextMatches();
    180 
    181     void setDefersLoading(bool);
    182     bool defersLoading() const { return m_defersLoading; }
    183 
    184     void setPageScaleFactor(float scale, const IntPoint& origin);
    185     float pageScaleFactor() const { return m_pageScaleFactor; }
    186 
    187     float deviceScaleFactor() const { return m_deviceScaleFactor; }
    188     void setDeviceScaleFactor(float);
    189 
    190     // Page and FrameView both store a Pagination value. Page::pagination() is set only by API,
    191     // and FrameView::pagination() is set only by CSS. Page::pagination() will affect all
    192     // FrameViews in the page cache, but FrameView::pagination() only affects the current
    193     // FrameView.
    194     const Pagination& pagination() const { return m_pagination; }
    195     void setPagination(const Pagination&);
    196 
    197     void userStyleSheetLocationChanged();
    198     const String& userStyleSheet() const;
    199 
    200     void dnsPrefetchingStateChanged();
    201 
    202     static void allVisitedStateChanged(PageGroup*);
    203     static void visitedStateChanged(PageGroup*, LinkHash visitedHash);
    204 
    205     StorageNamespace* sessionStorage(bool optionalCreate = true);
    206 
    207     // Don't allow more than a certain number of frames in a page.
    208     // This seems like a reasonable upper bound, and otherwise mutually
    209     // recursive frameset pages can quickly bring the program to its knees
    210     // with exponential growth in the number of frames.
    211     static const int maxNumberOfFrames = 1000;
    212 
    213     PageVisibilityState visibilityState() const;
    214     void setVisibilityState(PageVisibilityState, bool);
    215 
    216     bool isCursorVisible() const { return m_isCursorVisible; }
    217     void setIsCursorVisible(bool isVisible) { m_isCursorVisible = isVisible; }
    218 
    219     void addLayoutMilestones(LayoutMilestones);
    220     LayoutMilestones layoutMilestones() const { return m_layoutMilestones; }
    221 
    222     bool isCountingRelevantRepaintedObjects() const;
    223     void startCountingRelevantRepaintedObjects();
    224     void resetRelevantPaintedObjectCounter();
    225     void addRelevantRepaintedObject(RenderObject*, const LayoutRect& objectPaintRect);
    226     void addRelevantUnpaintedObject(RenderObject*, const LayoutRect& objectPaintRect);
    227 
    228 #ifndef NDEBUG
    229     void setIsPainting(bool painting) { m_isPainting = painting; }
    230     bool isPainting() const { return m_isPainting; }
    231 #endif
    232 
    233     PageConsole* console() { return m_console.get(); }
    234 
    235     double timerAlignmentInterval() const;
    236 
    237     class MultisamplingChangedObserver {
    238     public:
    239         virtual void multisamplingChanged(bool) = 0;
    240     };
    241 
    242     void addMultisamplingChangedObserver(MultisamplingChangedObserver*);
    243     void removeMultisamplingChangedObserver(MultisamplingChangedObserver*);
    244     void multisamplingChanged();
    245 
    246     void didCommitLoad(Frame*);
    247 
    248 protected:
    249     PageLifecycleNotifier* lifecycleNotifier();
    250 
    251 private:
    252     void initGroup();
    253 
    254 #if ASSERT_DISABLED
    255     void checkSubframeCountConsistency() const { }
    256 #else
    257     void checkSubframeCountConsistency() const;
    258 #endif
    259 
    260     void setTimerAlignmentInterval(double);
    261 
    262     virtual PassOwnPtr<LifecycleNotifier> createLifecycleNotifier() OVERRIDE;
    263 
    264     OwnPtr<AutoscrollController> m_autoscrollController;
    265     OwnPtr<Chrome> m_chrome;
    266     const OwnPtr<DragCaretController> m_dragCaretController;
    267     const OwnPtr<DragController> m_dragController;
    268     OwnPtr<FocusController> m_focusController;
    269     OwnPtr<ContextMenuController> m_contextMenuController;
    270     OwnPtr<InspectorController> m_inspectorController;
    271     OwnPtr<PointerLockController> m_pointerLockController;
    272     RefPtr<ScrollingCoordinator> m_scrollingCoordinator;
    273 
    274     OwnPtr<Settings> m_settings;
    275     OwnPtr<ProgressTracker> m_progress;
    276 
    277     OwnPtr<BackForwardController> m_backForwardController;
    278     RefPtr<Frame> m_mainFrame;
    279 
    280     mutable RefPtr<PluginData> m_pluginData;
    281 
    282     RefPtr<RenderTheme> m_theme;
    283 
    284     EditorClient* m_editorClient;
    285     ValidationMessageClient* m_validationMessageClient;
    286 
    287     UseCounter m_UseCounter;
    288 
    289     int m_subframeCount;
    290     bool m_openedByDOM;
    291 
    292     bool m_tabKeyCyclesThroughElements;
    293     bool m_defersLoading;
    294 
    295     float m_pageScaleFactor;
    296     float m_deviceScaleFactor;
    297 
    298     Pagination m_pagination;
    299 
    300     mutable String m_userStyleSheet;
    301     mutable bool m_didLoadUserStyleSheet;
    302 
    303     RefPtr<PageGroup> m_group;
    304 
    305     OwnPtr<StorageNamespace> m_sessionStorage;
    306 
    307     double m_timerAlignmentInterval;
    308 
    309     PageVisibilityState m_visibilityState;
    310 
    311     bool m_isCursorVisible;
    312 
    313     LayoutMilestones m_layoutMilestones;
    314 
    315     HashSet<RenderObject*> m_relevantUnpaintedRenderObjects;
    316     Region m_topRelevantPaintedRegion;
    317     Region m_bottomRelevantPaintedRegion;
    318     Region m_relevantUnpaintedRegion;
    319     bool m_isCountingRelevantRepaintedObjects;
    320 #ifndef NDEBUG
    321     bool m_isPainting;
    322 #endif
    323 
    324     const OwnPtr<PageConsole> m_console;
    325 
    326     HashSet<MultisamplingChangedObserver*> m_multisamplingChangedObservers;
    327 };
    328 
    329 } // namespace WebCore
    330 
    331 #endif // Page_h
    332