1/*
2 * Copyright (C) 2012 Google 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 *
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 AND ITS CONTRIBUTORS "AS IS" AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#ifndef LinkHighlight_h
27#define LinkHighlight_h
28
29#include "platform/geometry/FloatPoint.h"
30#include "platform/geometry/IntPoint.h"
31#include "platform/graphics/GraphicsLayer.h"
32#include "platform/graphics/Path.h"
33#include "public/platform/WebAnimationDelegate.h"
34#include "public/platform/WebContentLayer.h"
35#include "public/platform/WebContentLayerClient.h"
36#include "public/platform/WebLayer.h"
37#include "wtf/OwnPtr.h"
38#include "wtf/Vector.h"
39
40namespace WebCore {
41class RenderLayer;
42class RenderObject;
43class Node;
44}
45
46namespace blink {
47
48struct WebFloatRect;
49struct WebRect;
50class WebViewImpl;
51
52class LinkHighlight FINAL : public WebContentLayerClient, public WebAnimationDelegate, WebCore::LinkHighlightClient {
53public:
54    static PassOwnPtr<LinkHighlight> create(WebCore::Node*, WebViewImpl*);
55    virtual ~LinkHighlight();
56
57    WebContentLayer* contentLayer();
58    WebLayer* clipLayer();
59    void startHighlightAnimationIfNeeded();
60    void updateGeometry();
61
62    // WebContentLayerClient implementation.
63    virtual void paintContents(WebCanvas*, const WebRect& clipRect, bool canPaintLCDText, WebFloatRect& opaque,
64        WebContentLayerClient::GraphicsContextStatus = GraphicsContextEnabled) OVERRIDE;
65
66    // WebAnimationDelegate implementation.
67    virtual void notifyAnimationStarted(double monotonicTime, blink::WebAnimation::TargetProperty) OVERRIDE;
68    virtual void notifyAnimationFinished(double monotonicTime, blink::WebAnimation::TargetProperty) OVERRIDE;
69
70    // LinkHighlightClient inplementation.
71    virtual void invalidate() OVERRIDE;
72    virtual WebLayer* layer() OVERRIDE;
73    virtual void clearCurrentGraphicsLayer() OVERRIDE;
74
75    WebCore::GraphicsLayer* currentGraphicsLayerForTesting() const { return m_currentGraphicsLayer; }
76
77private:
78    LinkHighlight(WebCore::Node*, WebViewImpl*);
79
80    void releaseResources();
81    void computeQuads(WebCore::Node*, WTF::Vector<WebCore::FloatQuad>&) const;
82
83    WebCore::RenderLayer* computeEnclosingCompositingLayer();
84    void clearGraphicsLayerLinkHighlightPointer();
85    // This function computes the highlight path, and returns true if it has changed
86    // size since the last call to this function.
87    bool computeHighlightLayerPathAndPosition(WebCore::RenderLayer*);
88
89    OwnPtr<WebContentLayer> m_contentLayer;
90    OwnPtr<WebLayer> m_clipLayer;
91    WebCore::Path m_path;
92
93    RefPtrWillBePersistent<WebCore::Node> m_node;
94    WebViewImpl* m_owningWebViewImpl;
95    WebCore::GraphicsLayer* m_currentGraphicsLayer;
96
97    bool m_geometryNeedsUpdate;
98    bool m_isAnimating;
99    double m_startTime;
100};
101
102} // namespace blink
103
104#endif
105