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