2 * Copyright (C) 2014 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef ServicesOverlayController_h
28 #if ENABLE(SERVICE_CONTROLS) || ENABLE(TELEPHONE_NUMBER_DETECTION)
30 #include "PageOverlay.h"
32 typedef void* DDHighlightRef;
45 typedef void* DDHighlightRef;
47 struct TelephoneNumberData {
48 TelephoneNumberData(RetainPtr<DDHighlightRef> highlight, PassRefPtr<WebCore::Range> range)
49 : highlight(highlight)
54 RetainPtr<DDHighlightRef> highlight;
55 RefPtr<WebCore::Range> range;
58 class ServicesOverlayController : private PageOverlay::Client {
60 ServicesOverlayController(WebPage&);
61 ~ServicesOverlayController();
63 void selectedTelephoneNumberRangesChanged(const Vector<RefPtr<WebCore::Range>>&);
64 void selectionRectsDidChange(const Vector<WebCore::LayoutRect>&, const Vector<WebCore::GapRects>&);
67 void createOverlayIfNeeded();
68 void handleClick(const WebCore::IntPoint&, DDHighlightRef);
69 void clearHighlightState();
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;
77 bool drawTelephoneNumberHighlightIfVisible(WebCore::GraphicsContext&, const WebCore::IntRect& dirtyRect);
78 void drawSelectionHighlight(WebCore::GraphicsContext&, const WebCore::IntRect& dirtyRect);
79 void drawHighlight(DDHighlightRef, WebCore::GraphicsContext&);
81 void establishHoveredTelephoneHighlight(Boolean& onButton);
82 void maybeCreateSelectionHighlight();
84 void clearSelectionHighlight();
85 void clearHoveredTelephoneNumberHighlight();
88 PageOverlay* m_servicesOverlay;
90 Vector<WebCore::LayoutRect> m_currentSelectionRects;
91 RetainPtr<DDHighlightRef> m_selectionHighlight;
93 Vector<RefPtr<WebCore::Range>> m_currentTelephoneNumberRanges;
94 Vector<RetainPtr<DDHighlightRef>> m_telephoneNumberHighlights;
95 std::unique_ptr<TelephoneNumberData> m_hoveredTelephoneNumberData;
97 RetainPtr<DDHighlightRef> m_currentHoveredHighlight;
98 RetainPtr<DDHighlightRef> m_currentMouseDownOnButtonHighlight;
100 WebCore::IntPoint m_mousePosition;
103 } // namespace WebKit
105 #endif // ENABLE(SERVICE_CONTROLS) && ENABLE(TELEPHONE_NUMBER_DETECTION)
106 #endif // ServicesOverlayController_h