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 PageOverlayController_h
27#define PageOverlayController_h
28
29#include "PageOverlay.h"
30#include "WKBase.h"
31#include <WebCore/GraphicsLayerClient.h>
32#include <wtf/HashMap.h>
33#include <wtf/RefPtr.h>
34#include <wtf/Vector.h>
35
36namespace WebCore {
37class Frame;
38}
39
40namespace WebKit {
41
42class WebMouseEvent;
43class WebPage;
44
45class PageOverlayController : public WebCore::GraphicsLayerClient {
46public:
47    PageOverlayController(WebPage&);
48
49    void initialize();
50
51    WebCore::GraphicsLayer* documentOverlayRootLayer() const { return m_documentOverlayRootLayer.get(); }
52    WebCore::GraphicsLayer* viewOverlayRootLayer() const { return m_viewOverlayRootLayer.get(); }
53
54    void installPageOverlay(PassRefPtr<PageOverlay>, PageOverlay::FadeMode);
55    void uninstallPageOverlay(PageOverlay*, PageOverlay::FadeMode);
56
57    void setPageOverlayNeedsDisplay(PageOverlay&, const WebCore::IntRect&);
58    void setPageOverlayOpacity(PageOverlay&, float);
59    void clearPageOverlay(PageOverlay&);
60    WebCore::GraphicsLayer* layerForOverlay(PageOverlay&) const;
61
62    void didChangeViewSize();
63    void didChangeDocumentSize();
64    void didChangePreferences();
65    void didChangeDeviceScaleFactor();
66    void didChangeExposedRect();
67    void didScrollFrame(WebCore::Frame*);
68
69    void didChangeOverlayFrame(PageOverlay&);
70    void didChangeOverlayBackgroundColor(PageOverlay&);
71
72    void flushPageOverlayLayers(WebCore::FloatRect);
73
74    bool handleMouseEvent(const WebMouseEvent&);
75
76    // FIXME: We shouldn't use API types here.
77    WKTypeRef copyAccessibilityAttributeValue(WKStringRef attribute, WKTypeRef parameter);
78    WKArrayRef copyAccessibilityAttributesNames(bool parameterizedNames);
79
80private:
81    void updateSettingsForLayer(WebCore::GraphicsLayer&);
82    void updateForceSynchronousScrollLayerPositionUpdates();
83
84    // WebCore::GraphicsLayerClient
85    virtual void notifyAnimationStarted(const WebCore::GraphicsLayer*, double) override { }
86    virtual void notifyFlushRequired(const WebCore::GraphicsLayer*) override;
87    virtual void paintContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, WebCore::GraphicsLayerPaintingPhase, const WebCore::FloatRect& clipRect) override;
88    virtual float deviceScaleFactor() const override;
89    virtual void didCommitChangesForLayer(const WebCore::GraphicsLayer*) const override { }
90    virtual bool shouldSkipLayerInDump(const WebCore::GraphicsLayer*) const override { return true; }
91
92    std::unique_ptr<WebCore::GraphicsLayer> m_documentOverlayRootLayer;
93    std::unique_ptr<WebCore::GraphicsLayer> m_viewOverlayRootLayer;
94    HashMap<PageOverlay*, std::unique_ptr<WebCore::GraphicsLayer>> m_overlayGraphicsLayers;
95    Vector<RefPtr<PageOverlay>> m_pageOverlays;
96    WebPage& m_webPage;
97};
98
99} // namespace WebKit
100
101#endif // PageOverlayController_h
102