Home | History | Annotate | Download | only in rendering
      1 /*
      2  * Copyright (C) 2003, 2009, 2012 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. ``AS IS'' AND ANY
     14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
     17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     24  */
     25 
     26 #ifndef ClipRect_h
     27 #define ClipRect_h
     28 
     29 #include "platform/geometry/LayoutRect.h"
     30 
     31 namespace blink {
     32 
     33 class RenderLayer;
     34 class HitTestLocation;
     35 
     36 class ClipRect {
     37 public:
     38     ClipRect()
     39         : m_hasRadius(false)
     40     { }
     41 
     42     ClipRect(const LayoutRect& rect)
     43         : m_rect(rect)
     44         , m_hasRadius(false)
     45     { }
     46 
     47     const LayoutRect& rect() const { return m_rect; }
     48     void setRect(const LayoutRect& rect) { m_rect = rect; }
     49 
     50     bool hasRadius() const { return m_hasRadius; }
     51     void setHasRadius(bool hasRadius) { m_hasRadius = hasRadius; }
     52 
     53     bool operator==(const ClipRect& other) const { return rect() == other.rect() && hasRadius() == other.hasRadius(); }
     54     bool operator!=(const ClipRect& other) const { return rect() != other.rect() || hasRadius() != other.hasRadius(); }
     55     bool operator!=(const LayoutRect& otherRect) const { return rect() != otherRect; }
     56 
     57     void intersect(const LayoutRect& other) { m_rect.intersect(other); }
     58     void intersect(const ClipRect& other)
     59     {
     60         m_rect.intersect(other.rect());
     61         if (other.hasRadius())
     62             m_hasRadius = true;
     63     }
     64     void move(LayoutUnit x, LayoutUnit y) { m_rect.move(x, y); }
     65     void move(const LayoutSize& size) { m_rect.move(size); }
     66     void moveBy(const LayoutPoint& point) { m_rect.moveBy(point); }
     67 
     68     bool isEmpty() const { return m_rect.isEmpty(); }
     69     bool intersects(const LayoutRect& rect) const { return m_rect.intersects(rect); }
     70     bool intersects(const HitTestLocation&) const;
     71 
     72 private:
     73     LayoutRect m_rect;
     74     bool m_hasRadius;
     75 };
     76 
     77 inline ClipRect intersection(const ClipRect& a, const ClipRect& b)
     78 {
     79     ClipRect c = a;
     80     c.intersect(b);
     81     return c;
     82 }
     83 
     84 } // namespace blink
     85 
     86 #endif // ClipRect_h
     87