Home | History | Annotate | Download | only in web
      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 "core/platform/graphics/FloatPoint.h"
     30 #include "core/platform/graphics/GraphicsLayer.h"
     31 #include "core/platform/graphics/IntPoint.h"
     32 #include "core/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 
     39 namespace WebCore {
     40 class RenderLayer;
     41 class Node;
     42 }
     43 
     44 namespace WebKit {
     45 
     46 struct WebFloatRect;
     47 struct WebRect;
     48 class WebViewImpl;
     49 
     50 class LinkHighlight : public WebContentLayerClient, public WebAnimationDelegate, WebCore::LinkHighlightClient {
     51 public:
     52     static PassOwnPtr<LinkHighlight> create(WebCore::Node*, WebViewImpl*);
     53     virtual ~LinkHighlight();
     54 
     55     WebContentLayer* contentLayer();
     56     WebLayer* clipLayer();
     57     void startHighlightAnimationIfNeeded();
     58     void updateGeometry();
     59 
     60     // WebContentLayerClient implementation.
     61     virtual void paintContents(WebCanvas*, const WebRect& clipRect, bool canPaintLCDText, WebFloatRect& opaque) OVERRIDE;
     62 
     63     // WebAnimationDelegate implementation.
     64     virtual void notifyAnimationStarted(double time) OVERRIDE;
     65     virtual void notifyAnimationFinished(double time) OVERRIDE;
     66 
     67     // LinkHighlightClient inplementation.
     68     virtual void invalidate() OVERRIDE;
     69     virtual WebLayer* layer() OVERRIDE;
     70     virtual void clearCurrentGraphicsLayer() OVERRIDE;
     71 
     72     WebCore::GraphicsLayer* currentGraphicsLayerForTesting() const { return m_currentGraphicsLayer; }
     73 
     74 private:
     75     LinkHighlight(WebCore::Node*, WebViewImpl*);
     76 
     77     void releaseResources();
     78 
     79     WebCore::RenderLayer* computeEnclosingCompositingLayer();
     80     void clearGraphicsLayerLinkHighlightPointer();
     81     // This function computes the highlight path, and returns true if it has changed
     82     // size since the last call to this function.
     83     bool computeHighlightLayerPathAndPosition(WebCore::RenderLayer*);
     84 
     85     OwnPtr<WebContentLayer> m_contentLayer;
     86     OwnPtr<WebLayer> m_clipLayer;
     87     WebCore::Path m_path;
     88 
     89     RefPtr<WebCore::Node> m_node;
     90     OwnPtr<WebAnimation> m_animation;
     91     WebViewImpl* m_owningWebViewImpl;
     92     WebCore::GraphicsLayer* m_currentGraphicsLayer;
     93 
     94     bool m_geometryNeedsUpdate;
     95     bool m_isAnimating;
     96     double m_startTime;
     97 };
     98 
     99 } // namespace WebKit
    100 
    101 #endif
    102