summaryrefslogtreecommitdiff
path: root/Source/WebKit/blackberry/Api/WebOverlay.h
blob: 83d9e0a7a14cbc3b667c0b527c428115e4360eeb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
 * Copyright (C) 2012, 2013 Research In Motion Limited. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#ifndef WebOverlay_h
#define WebOverlay_h

#include "BlackBerryGlobal.h"
#include "WebOverlayOverride.h"

#include <BlackBerryPlatformPrimitives.h>

namespace WebCore {
class GraphicsLayerClient;
}

namespace BlackBerry {
namespace Platform {
class String;
}

namespace WebKit {

class WebAnimation;
class WebOverlayClient;
class WebOverlayOverride;
class WebOverlayPrivate;
class WebPage;

/**
 * Represents an overlay that is rendered superimposed on a web page.
 *
 * The WebOverlay is not thread safe, but it is reentrant when used on either
 * the WebKit or the compositing thread. This means that overlays can be
 * on either of these threads, but each instance must only be used on the
 * thread where it was created. The only exception is the override mechanism.
 *
 * Note that WebKit thread usage of WebOverlay is obsolete and will be removed
 * soon.
 *
 * The WebOverlayOverride object returned by WebOverlay::override() can be used
 * to override the values of specific properties from the UI thread.
 *
 * They have the following semantics: If they are called for a specific overlay
 * on the UI thread, the value set will override any value set on the WK thread
 * until you call resetOverrides(). resetOverrides() is thread safe.
 */
class BLACKBERRY_EXPORT WebOverlay {
public:
    enum ImageDataAdoptionType {
        ReferenceImageData,
        CopyImageData
    };

    WebOverlay();
    WebOverlay(WebCore::GraphicsLayerClient*);
    virtual ~WebOverlay();

    // The position of the layer (the location of its top-left corner in its parent).
    Platform::FloatPoint position() const;
    void setPosition(const Platform::FloatPoint&);

    // Anchor point: (0, 0) is top left, (1, 1) is bottom right. The anchor point
    // affects the origin of the transforms.
    Platform::FloatPoint anchorPoint() const;
    void setAnchorPoint(const Platform::FloatPoint&);

    // The size of the layer.
    Platform::FloatSize size() const;
    void setSize(const Platform::FloatSize&);

    // Whether the layer is scaled together with the web page.
    bool sizeIsScaleInvariant() const;
    void setSizeIsScaleInvariant(bool);

    // Transform can be used to rotate the layer, among other things.
    Platform::TransformationMatrix transform() const;
    void setTransform(const Platform::TransformationMatrix&);

    // Opacity. Can also be used to temporarily hide a layer.
    float opacity() const;
    void setOpacity(float);

    // Adds/removes an animation
    // Note that WebAnimation and BlackBerry::Platform::String are not thread safe and have to be
    // created on the thread where they'll be used.
    void addAnimation(const WebAnimation&);
    void removeAnimation(const BlackBerry::Platform::String& name);

    // Returns the rectangle occupied by this overlay, in pixels, relative to the current viewport
    // Can be used for hit testing (noting though, that the overlay may have transparent pixels that
    // cause it not to occupy the whole rectangle, for example when the overlay draws an image with
    // alpha channel). Not implemented for WebKit-thread overlays.
    Platform::IntRect pixelViewportRect() const;

    WebOverlay* parent() const;
    bool addChild(WebOverlay*);
    void removeFromParent();

    void setContentsToImage(const unsigned char* data, const Platform::IntSize& imageSize, ImageDataAdoptionType = ReferenceImageData);
    void setContentsToColor(int r, int g, int b, int a);
    void setDrawsContent(bool);

    // Will result in a future call to WebOverlayClient::drawContents, if the layer draws custom contents.
    void invalidate();

    // The client can be used to draw layer contents.
    void setClient(WebOverlayClient*);

    // Must be called on UI thread.
    WebOverlayOverride* override();

    /**
     * Thread safe. Next time the attributes are changed on the WK thread, make
     * those values override any set on the UI thread.
     */
    void resetOverrides();

private:
    friend class WebPage;
    friend class WebOverlayPrivate;

    // Disable copy constructor and operator=.
    WebOverlay(const WebOverlay&);
    WebOverlay& operator=(const WebOverlay&);

    WebOverlayPrivate* d;
};

}
}

#endif // WebOverlay_h