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#pragma once
27
28#include "GraphicsLayerClient.h"
29#include "PageOverlay.h"
30#include <wtf/HashMap.h>
31#include <wtf/RefPtr.h>
32#include <wtf/Vector.h>
33
34namespace WebCore {
35
36class Frame;
37class Page;
38class PlatformMouseEvent;
39
40class PageOverlayController final : public GraphicsLayerClient {
41 WTF_MAKE_FAST_ALLOCATED;
42 friend class MockPageOverlayClient;
43public:
44 PageOverlayController(Page&);
45 virtual ~PageOverlayController();
46
47 bool hasDocumentOverlays() const;
48 bool hasViewOverlays() const;
49
50 GraphicsLayer& layerWithDocumentOverlays();
51 GraphicsLayer& layerWithViewOverlays();
52
53 const Vector<RefPtr<PageOverlay>>& pageOverlays() const { return m_pageOverlays; }
54
55 WEBCORE_EXPORT void installPageOverlay(PageOverlay&, PageOverlay::FadeMode);
56 WEBCORE_EXPORT void uninstallPageOverlay(PageOverlay&, PageOverlay::FadeMode);
57
58 void setPageOverlayNeedsDisplay(PageOverlay&, const IntRect&);
59 void setPageOverlayOpacity(PageOverlay&, float);
60 void clearPageOverlay(PageOverlay&);
61 GraphicsLayer& layerForOverlay(PageOverlay&) const;
62
63 void didChangeViewSize();
64 void didChangeDocumentSize();
65 void didChangeSettings();
66 WEBCORE_EXPORT void didChangeDeviceScaleFactor();
67 void didChangeViewExposedRect();
68 void didScrollFrame(Frame&);
69
70 void didChangeOverlayFrame(PageOverlay&);
71 void didChangeOverlayBackgroundColor(PageOverlay&);
72
73 int overlayCount() const { return m_overlayGraphicsLayers.size(); }
74
75 bool handleMouseEvent(const PlatformMouseEvent&);
76
77 WEBCORE_EXPORT bool copyAccessibilityAttributeStringValueForPoint(String attribute, FloatPoint, String& value);
78 WEBCORE_EXPORT bool copyAccessibilityAttributeBoolValueForPoint(String attribute, FloatPoint, bool& value);
79 WEBCORE_EXPORT Vector<String> copyAccessibilityAttributesNames(bool parameterizedNames);
80
81private:
82 void createRootLayersIfNeeded();
83
84 WEBCORE_EXPORT GraphicsLayer* documentOverlayRootLayer() const;
85 WEBCORE_EXPORT GraphicsLayer* viewOverlayRootLayer() const;
86
87 void installedPageOverlaysChanged();
88 void attachViewOverlayLayers();
89 void detachViewOverlayLayers();
90
91 void updateSettingsForLayer(GraphicsLayer&);
92 void updateForceSynchronousScrollLayerPositionUpdates();
93
94 // GraphicsLayerClient
95 void notifyFlushRequired(const GraphicsLayer*) override;
96 void paintContents(const GraphicsLayer*, GraphicsContext&, OptionSet<GraphicsLayerPaintingPhase>, const FloatRect& clipRect, GraphicsLayerPaintBehavior) override;
97 float deviceScaleFactor() const override;
98 bool shouldSkipLayerInDump(const GraphicsLayer*, LayerTreeAsTextBehavior) const override;
99 void tiledBackingUsageChanged(const GraphicsLayer*, bool) override;
100
101 Page& m_page;
102 RefPtr<GraphicsLayer> m_documentOverlayRootLayer;
103 RefPtr<GraphicsLayer> m_viewOverlayRootLayer;
104
105 HashMap<PageOverlay*, Ref<GraphicsLayer>> m_overlayGraphicsLayers;
106 Vector<RefPtr<PageOverlay>> m_pageOverlays;
107 bool m_initialized { false };
108};
109
110} // namespace WebKit
111