| 1 | /* |
| 2 | * Copyright (C) 2010 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #pragma once |
| 27 | |
| 28 | #include "Color.h" |
| 29 | #include "FloatPoint.h" |
| 30 | #include "IntRect.h" |
| 31 | #include "Timer.h" |
| 32 | #include <wtf/RefCounted.h> |
| 33 | #include <wtf/WallTime.h> |
| 34 | #include <wtf/text/WTFString.h> |
| 35 | |
| 36 | namespace WebCore { |
| 37 | |
| 38 | class Frame; |
| 39 | class GraphicsContext; |
| 40 | class GraphicsLayer; |
| 41 | class Page; |
| 42 | class PageOverlayController; |
| 43 | class PlatformMouseEvent; |
| 44 | |
| 45 | class PageOverlay final : public RefCounted<PageOverlay> { |
| 46 | WTF_MAKE_NONCOPYABLE(PageOverlay); |
| 47 | WTF_MAKE_FAST_ALLOCATED; |
| 48 | public: |
| 49 | class Client { |
| 50 | protected: |
| 51 | virtual ~Client() = default; |
| 52 | |
| 53 | public: |
| 54 | virtual void willMoveToPage(PageOverlay&, Page*) = 0; |
| 55 | virtual void didMoveToPage(PageOverlay&, Page*) = 0; |
| 56 | virtual void drawRect(PageOverlay&, GraphicsContext&, const IntRect& dirtyRect) = 0; |
| 57 | virtual bool mouseEvent(PageOverlay&, const PlatformMouseEvent&) = 0; |
| 58 | virtual void didScrollFrame(PageOverlay&, Frame&) { } |
| 59 | |
| 60 | virtual bool copyAccessibilityAttributeStringValueForPoint(PageOverlay&, String /* attribute */, FloatPoint, String&) { return false; } |
| 61 | virtual bool copyAccessibilityAttributeBoolValueForPoint(PageOverlay&, String /* attribute */, FloatPoint, bool&) { return false; } |
| 62 | virtual Vector<String> copyAccessibilityAttributeNames(PageOverlay&, bool /* parameterizedNames */) { return { }; } |
| 63 | }; |
| 64 | |
| 65 | enum class OverlayType { |
| 66 | View, // Fixed to the view size; does not scale or scroll with the document, repaints on scroll. |
| 67 | Document, // Scales and scrolls with the document. |
| 68 | }; |
| 69 | |
| 70 | WEBCORE_EXPORT static Ref<PageOverlay> create(Client&, OverlayType = OverlayType::View); |
| 71 | WEBCORE_EXPORT virtual ~PageOverlay(); |
| 72 | |
| 73 | WEBCORE_EXPORT PageOverlayController* controller() const; |
| 74 | |
| 75 | typedef uint64_t PageOverlayID; |
| 76 | virtual PageOverlayID pageOverlayID() const { return m_pageOverlayID; } |
| 77 | |
| 78 | void setPage(Page*); |
| 79 | Page* page() const { return m_page; } |
| 80 | WEBCORE_EXPORT void setNeedsDisplay(const IntRect& dirtyRect); |
| 81 | WEBCORE_EXPORT void setNeedsDisplay(); |
| 82 | |
| 83 | void drawRect(GraphicsContext&, const IntRect& dirtyRect); |
| 84 | bool mouseEvent(const PlatformMouseEvent&); |
| 85 | void didScrollFrame(Frame&); |
| 86 | |
| 87 | bool copyAccessibilityAttributeStringValueForPoint(String attribute, FloatPoint parameter, String& value); |
| 88 | bool copyAccessibilityAttributeBoolValueForPoint(String attribute, FloatPoint parameter, bool& value); |
| 89 | Vector<String> copyAccessibilityAttributeNames(bool parameterizedNames); |
| 90 | |
| 91 | void startFadeInAnimation(); |
| 92 | void startFadeOutAnimation(); |
| 93 | WEBCORE_EXPORT void stopFadeOutAnimation(); |
| 94 | |
| 95 | WEBCORE_EXPORT void clear(); |
| 96 | |
| 97 | Client& client() const { return m_client; } |
| 98 | |
| 99 | enum class FadeMode { DoNotFade, Fade }; |
| 100 | |
| 101 | OverlayType overlayType() { return m_overlayType; } |
| 102 | |
| 103 | WEBCORE_EXPORT IntRect bounds() const; |
| 104 | WEBCORE_EXPORT IntRect frame() const; |
| 105 | WEBCORE_EXPORT void setFrame(IntRect); |
| 106 | |
| 107 | WEBCORE_EXPORT IntSize viewToOverlayOffset() const; |
| 108 | |
| 109 | const Color& backgroundColor() const { return m_backgroundColor; } |
| 110 | void setBackgroundColor(const Color&); |
| 111 | |
| 112 | void setShouldIgnoreMouseEventsOutsideBounds(bool flag) { m_shouldIgnoreMouseEventsOutsideBounds = flag; } |
| 113 | |
| 114 | // FIXME: PageOverlay should own its layer, instead of PageOverlayController. |
| 115 | WEBCORE_EXPORT GraphicsLayer& layer(); |
| 116 | |
| 117 | bool needsSynchronousScrolling() const { return m_needsSynchronousScrolling; } |
| 118 | void setNeedsSynchronousScrolling(bool needsSynchronousScrolling) { m_needsSynchronousScrolling = needsSynchronousScrolling; } |
| 119 | |
| 120 | private: |
| 121 | explicit PageOverlay(Client&, OverlayType); |
| 122 | |
| 123 | void startFadeAnimation(); |
| 124 | void fadeAnimationTimerFired(); |
| 125 | |
| 126 | Client& m_client; |
| 127 | Page* m_page { nullptr }; |
| 128 | |
| 129 | Timer m_fadeAnimationTimer; |
| 130 | WallTime m_fadeAnimationStartTime; |
| 131 | Seconds m_fadeAnimationDuration; |
| 132 | |
| 133 | enum FadeAnimationType { |
| 134 | NoAnimation, |
| 135 | FadeInAnimation, |
| 136 | FadeOutAnimation, |
| 137 | }; |
| 138 | |
| 139 | FadeAnimationType m_fadeAnimationType { NoAnimation }; |
| 140 | float m_fractionFadedIn { 1 }; |
| 141 | |
| 142 | bool m_needsSynchronousScrolling; |
| 143 | |
| 144 | OverlayType m_overlayType; |
| 145 | IntRect m_overrideFrame; |
| 146 | |
| 147 | Color m_backgroundColor { Color::transparent }; |
| 148 | PageOverlayID m_pageOverlayID; |
| 149 | |
| 150 | bool m_shouldIgnoreMouseEventsOutsideBounds { true }; |
| 151 | }; |
| 152 | |
| 153 | } // namespace WebKit |
| 154 | |