1/*
2 * Copyright (C) 2010 Apple Inc. All rights reserved.
3 * Portions Copyright (c) 2010 Motorola Mobility, Inc.  All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24 * THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#ifndef DrawingAreaProxy_h
28#define DrawingAreaProxy_h
29
30#include "DrawingAreaInfo.h"
31#include "GenericCallback.h"
32#include "MessageReceiver.h"
33#include <WebCore/FloatRect.h>
34#include <WebCore/IntRect.h>
35#include <WebCore/IntSize.h>
36#include <chrono>
37#include <stdint.h>
38#include <wtf/Noncopyable.h>
39#include <wtf/RunLoop.h>
40
41namespace WebKit {
42
43class LayerTreeContext;
44class CoordinatedLayerTreeHostProxy;
45class UpdateInfo;
46class WebPageProxy;
47
48class DrawingAreaProxy : public IPC::MessageReceiver {
49    WTF_MAKE_NONCOPYABLE(DrawingAreaProxy);
50
51public:
52    virtual ~DrawingAreaProxy();
53
54    DrawingAreaType type() const { return m_type; }
55
56    virtual void deviceScaleFactorDidChange() = 0;
57
58    // FIXME: These should be pure virtual.
59    virtual void setBackingStoreIsDiscardable(bool) { }
60
61    virtual void waitForBackingStoreUpdateOnNextPaint() { }
62
63    const WebCore::IntSize& size() const { return m_size; }
64    void setSize(const WebCore::IntSize&, const WebCore::IntSize&, const WebCore::IntSize& scrollOffset);
65
66    // The timeout we use when waiting for a DidUpdateGeometry message.
67    static constexpr std::chrono::milliseconds didUpdateBackingStoreStateTimeout() { return std::chrono::milliseconds(500); }
68
69    virtual void waitForPossibleGeometryUpdate(std::chrono::milliseconds = didUpdateBackingStoreStateTimeout()) { }
70
71    virtual void colorSpaceDidChange() { }
72    virtual void minimumLayoutSizeDidChange() { }
73
74    virtual void adjustTransientZoom(double, WebCore::FloatPoint) { }
75    virtual void commitTransientZoom(double, WebCore::FloatPoint) { }
76
77#if PLATFORM(MAC)
78    virtual void setExposedRect(const WebCore::FloatRect&);
79    WebCore::FloatRect exposedRect() const { return m_exposedRect; }
80#endif
81#if PLATFORM(COCOA)
82    void exposedRectChangedTimerFired();
83#endif
84
85    virtual void updateDebugIndicator() { }
86
87    virtual void waitForDidUpdateViewState() { }
88
89    virtual void dispatchAfterEnsuringDrawing(std::function<void (CallbackBase::Error)>) { ASSERT_NOT_REACHED(); }
90
91    virtual void hideContentUntilNextUpdate() { ASSERT_NOT_REACHED(); }
92
93protected:
94    explicit DrawingAreaProxy(DrawingAreaType, WebPageProxy*);
95
96    DrawingAreaType m_type;
97    WebPageProxy* m_webPageProxy;
98
99    WebCore::IntSize m_size;
100    WebCore::IntSize m_layerPosition;
101    WebCore::IntSize m_scrollOffset;
102
103    // IPC::MessageReceiver
104    virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override;
105
106private:
107    virtual void sizeDidChange() = 0;
108
109    // Message handlers.
110    // FIXME: These should be pure virtual.
111    virtual void update(uint64_t /* backingStoreStateID */, const UpdateInfo&) { }
112    virtual void didUpdateBackingStoreState(uint64_t /* backingStoreStateID */, const UpdateInfo&, const LayerTreeContext&) { }
113    virtual void enterAcceleratedCompositingMode(uint64_t /* backingStoreStateID */, const LayerTreeContext&) { }
114    virtual void exitAcceleratedCompositingMode(uint64_t /* backingStoreStateID */, const UpdateInfo&) { }
115    virtual void updateAcceleratedCompositingMode(uint64_t /* backingStoreStateID */, const LayerTreeContext&) { }
116#if PLATFORM(COCOA)
117    virtual void didUpdateGeometry() { }
118    virtual void intrinsicContentSizeDidChange(const WebCore::IntSize& newIntrinsicContentSize) { }
119
120#if PLATFORM(MAC)
121    RunLoop::Timer<DrawingAreaProxy> m_exposedRectChangedTimer;
122    WebCore::FloatRect m_exposedRect;
123    WebCore::FloatRect m_lastSentExposedRect;
124#endif // PLATFORM(MAC)
125#endif
126};
127
128#define DRAWING_AREA_PROXY_TYPE_CASTS(ToValueTypeName, predicate) \
129    TYPE_CASTS_BASE(ToValueTypeName, DrawingAreaProxy, value, value->predicate, value.predicate)
130
131} // namespace WebKit
132
133#endif // DrawingAreaProxy_h
134