Phone number highlights should always be visible if the mouse hovers over.
[WebKit-https.git] / Source / WebKit2 / WebProcess / WebPage / ServicesOverlayController.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 ServicesOverlayController_h
27
28 #if ENABLE(SERVICE_CONTROLS) || ENABLE(TELEPHONE_NUMBER_DETECTION)
29
30 #include "PageOverlay.h"
31
32 typedef void* DDHighlightRef;
33
34 namespace WebCore {
35 class LayoutRect;
36 class Range;
37
38 struct GapRects;
39 }
40
41 namespace WebKit {
42
43 class WebPage;
44
45 typedef void* DDHighlightRef;
46
47 struct TelephoneNumberData {
48     TelephoneNumberData(RetainPtr<DDHighlightRef> highlight, PassRefPtr<WebCore::Range> range)
49         : highlight(highlight)
50         , range(range)
51     {
52     }
53
54     RetainPtr<DDHighlightRef> highlight;
55     RefPtr<WebCore::Range> range;
56 };
57
58 class ServicesOverlayController : private PageOverlay::Client {
59 public:
60     ServicesOverlayController(WebPage&);
61     ~ServicesOverlayController();
62
63     void selectedTelephoneNumberRangesChanged(const Vector<RefPtr<WebCore::Range>>&);
64     void selectionRectsDidChange(const Vector<WebCore::LayoutRect>&, const Vector<WebCore::GapRects>&);
65
66 private:
67     void createOverlayIfNeeded();
68     void handleClick(const WebCore::IntPoint&, DDHighlightRef);
69     void clearHighlightState();
70
71     virtual void pageOverlayDestroyed(PageOverlay*) override;
72     virtual void willMoveToWebPage(PageOverlay*, WebPage*) override;
73     virtual void didMoveToWebPage(PageOverlay*, WebPage*) override;
74     virtual void drawRect(PageOverlay*, WebCore::GraphicsContext&, const WebCore::IntRect& dirtyRect) override;
75     virtual bool mouseEvent(PageOverlay*, const WebMouseEvent&) override;
76
77     bool drawTelephoneNumberHighlightIfVisible(WebCore::GraphicsContext&, const WebCore::IntRect& dirtyRect);
78     void drawSelectionHighlight(WebCore::GraphicsContext&, const WebCore::IntRect& dirtyRect);
79     void drawHighlight(DDHighlightRef, WebCore::GraphicsContext&);
80
81     void establishHoveredTelephoneHighlight(Boolean& onButton);
82     void maybeCreateSelectionHighlight();
83
84     void clearSelectionHighlight();
85     void clearHoveredTelephoneNumberHighlight();
86
87     WebPage* m_webPage;
88     PageOverlay* m_servicesOverlay;
89     
90     Vector<WebCore::LayoutRect> m_currentSelectionRects;
91     RetainPtr<DDHighlightRef> m_selectionHighlight;
92
93     Vector<RefPtr<WebCore::Range>> m_currentTelephoneNumberRanges;
94     Vector<RetainPtr<DDHighlightRef>> m_telephoneNumberHighlights;
95     std::unique_ptr<TelephoneNumberData> m_hoveredTelephoneNumberData;
96
97     RetainPtr<DDHighlightRef> m_currentHoveredHighlight;
98     RetainPtr<DDHighlightRef> m_currentMouseDownOnButtonHighlight;
99
100     WebCore::IntPoint m_mousePosition;
101 };
102
103 } // namespace WebKit
104
105 #endif // ENABLE(SERVICE_CONTROLS) && ENABLE(TELEPHONE_NUMBER_DETECTION)
106 #endif // ServicesOverlayController_h