| 1 | /* |
| 2 | * Copyright (C) 2014 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 | #ifndef WebPageOverlay_h |
| 27 | #define WebPageOverlay_h |
| 28 | |
| 29 | #include "APIObject.h" |
| 30 | #include <WebCore/FloatPoint.h> |
| 31 | #include <WebCore/IntRect.h> |
| 32 | #include <WebCore/PageOverlay.h> |
| 33 | #include <WebCore/Range.h> |
| 34 | #include <wtf/RetainPtr.h> |
| 35 | |
| 36 | OBJC_CLASS DDActionContext; |
| 37 | |
| 38 | namespace WebKit { |
| 39 | |
| 40 | class WebFrame; |
| 41 | class WebPage; |
| 42 | |
| 43 | class WebPageOverlay : public API::ObjectImpl<API::Object::Type::BundlePageOverlay>, private WebCore::PageOverlay::Client { |
| 44 | public: |
| 45 | class Client { |
| 46 | public: |
| 47 | virtual ~Client() { } |
| 48 | |
| 49 | virtual void willMoveToPage(WebPageOverlay&, WebPage*) = 0; |
| 50 | virtual void didMoveToPage(WebPageOverlay&, WebPage*) = 0; |
| 51 | virtual void drawRect(WebPageOverlay&, WebCore::GraphicsContext&, const WebCore::IntRect& dirtyRect) = 0; |
| 52 | virtual bool mouseEvent(WebPageOverlay&, const WebCore::PlatformMouseEvent&) = 0; |
| 53 | virtual void didScrollFrame(WebPageOverlay&, WebFrame*) { } |
| 54 | |
| 55 | #if PLATFORM(MAC) |
| 56 | virtual DDActionContext *actionContextForResultAtPoint(WebPageOverlay&, WebCore::FloatPoint location, RefPtr<WebCore::Range>& rangeHandle) { return nullptr; } |
| 57 | virtual void dataDetectorsDidPresentUI(WebPageOverlay&) { } |
| 58 | virtual void dataDetectorsDidChangeUI(WebPageOverlay&) { } |
| 59 | virtual void dataDetectorsDidHideUI(WebPageOverlay&) { } |
| 60 | #endif |
| 61 | |
| 62 | virtual bool copyAccessibilityAttributeStringValueForPoint(WebPageOverlay&, String /* attribute */, WebCore::FloatPoint /* parameter */, String& /* value */) { return false; } |
| 63 | virtual bool copyAccessibilityAttributeBoolValueForPoint(WebPageOverlay&, String /* attribute */, WebCore::FloatPoint /* parameter */, bool& /* value */) { return false; } |
| 64 | virtual Vector<String> copyAccessibilityAttributeNames(WebPageOverlay&, bool /* parameterizedNames */) { return Vector<String>(); } |
| 65 | }; |
| 66 | |
| 67 | static Ref<WebPageOverlay> create(std::unique_ptr<Client>, WebCore::PageOverlay::OverlayType = WebCore::PageOverlay::OverlayType::View); |
| 68 | static WebPageOverlay* fromCoreOverlay(WebCore::PageOverlay&); |
| 69 | virtual ~WebPageOverlay(); |
| 70 | |
| 71 | void setNeedsDisplay(const WebCore::IntRect& dirtyRect); |
| 72 | void setNeedsDisplay(); |
| 73 | |
| 74 | void clear(); |
| 75 | |
| 76 | WebCore::PageOverlay* coreOverlay() const { return m_overlay.get(); } |
| 77 | Client& client() const { return *m_client; } |
| 78 | |
| 79 | #if PLATFORM(MAC) |
| 80 | DDActionContext *actionContextForResultAtPoint(WebCore::FloatPoint, RefPtr<WebCore::Range>&); |
| 81 | void dataDetectorsDidPresentUI(); |
| 82 | void dataDetectorsDidChangeUI(); |
| 83 | void dataDetectorsDidHideUI(); |
| 84 | #endif |
| 85 | |
| 86 | private: |
| 87 | WebPageOverlay(std::unique_ptr<Client>, WebCore::PageOverlay::OverlayType); |
| 88 | |
| 89 | // WebCore::PageOverlay::Client |
| 90 | void willMoveToPage(WebCore::PageOverlay&, WebCore::Page*) override; |
| 91 | void didMoveToPage(WebCore::PageOverlay&, WebCore::Page*) override; |
| 92 | void drawRect(WebCore::PageOverlay&, WebCore::GraphicsContext&, const WebCore::IntRect& dirtyRect) override; |
| 93 | bool mouseEvent(WebCore::PageOverlay&, const WebCore::PlatformMouseEvent&) override; |
| 94 | void didScrollFrame(WebCore::PageOverlay&, WebCore::Frame&) override; |
| 95 | |
| 96 | bool copyAccessibilityAttributeStringValueForPoint(WebCore::PageOverlay&, String /* attribute */, WebCore::FloatPoint /* parameter */, String& value) override; |
| 97 | bool copyAccessibilityAttributeBoolValueForPoint(WebCore::PageOverlay&, String /* attribute */, WebCore::FloatPoint /* parameter */, bool& value) override; |
| 98 | Vector<String> copyAccessibilityAttributeNames(WebCore::PageOverlay&, bool /* parameterizedNames */) override; |
| 99 | |
| 100 | |
| 101 | RefPtr<WebCore::PageOverlay> m_overlay; |
| 102 | std::unique_ptr<Client> m_client; |
| 103 | }; |
| 104 | |
| 105 | } // namespace WebKit |
| 106 | |
| 107 | #endif // WebPageOverlay_h |
| 108 | |