Home | History | Annotate | Download | only in rendering
      1 /*
      2  * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
      3  *
      4  * This library is free software; you can redistribute it and/or
      5  * modify it under the terms of the GNU Library General Public
      6  * License as published by the Free Software Foundation; either
      7  * version 2 of the License, or (at your option) any later version.
      8  *
      9  * This library is distributed in the hope that it will be useful,
     10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     12  * Library General Public License for more details.
     13  *
     14  * You should have received a copy of the GNU Library General Public License
     15  * along with this library; see the file COPYING.LIB.  If not, write to
     16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     17  * Boston, MA 02110-1301, USA.
     18  *
     19  */
     20 
     21 #ifndef RenderOverflow_h
     22 #define RenderOverflow_h
     23 
     24 #include "IntRect.h"
     25 
     26 namespace WebCore
     27 {
     28 // RenderOverflow is a class for tracking content that spills out of a box.  This class is used by RenderBox and
     29 // InlineFlowBox.
     30 //
     31 // There are two types of overflow: layout overflow (which is expected to be reachable via scrolling mechanisms) and
     32 // visual overflow (which is not expected to be reachable via scrolling mechanisms).
     33 //
     34 // Layout overflow examples include other boxes that spill out of our box,  For example, in the inline case a tall image
     35 // could spill out of a line box.
     36 
     37 // Examples of visual overflow are shadows, text stroke (and eventually outline and border-image).
     38 
     39 // This object is allocated only when some of these fields have non-default values in the owning box.
     40 class RenderOverflow {
     41     WTF_MAKE_NONCOPYABLE(RenderOverflow); WTF_MAKE_FAST_ALLOCATED;
     42 public:
     43     RenderOverflow(const IntRect& layoutRect, const IntRect& visualRect)
     44         : m_minYLayoutOverflow(layoutRect.y())
     45         , m_maxYLayoutOverflow(layoutRect.maxY())
     46         , m_minXLayoutOverflow(layoutRect.x())
     47         , m_maxXLayoutOverflow(layoutRect.maxX())
     48         , m_minYVisualOverflow(visualRect.y())
     49         , m_maxYVisualOverflow(visualRect.maxY())
     50         , m_minXVisualOverflow(visualRect.x())
     51         , m_maxXVisualOverflow(visualRect.maxX())
     52     {
     53     }
     54 
     55     int minYLayoutOverflow() const { return m_minYLayoutOverflow; }
     56     int maxYLayoutOverflow() const { return m_maxYLayoutOverflow; }
     57     int minXLayoutOverflow() const { return m_minXLayoutOverflow; }
     58     int maxXLayoutOverflow() const { return m_maxXLayoutOverflow; }
     59     IntRect layoutOverflowRect() const;
     60 
     61     int minYVisualOverflow() const { return m_minYVisualOverflow; }
     62     int maxYVisualOverflow() const { return m_maxYVisualOverflow; }
     63     int minXVisualOverflow() const { return m_minXVisualOverflow; }
     64     int maxXVisualOverflow() const { return m_maxXVisualOverflow; }
     65     IntRect visualOverflowRect() const;
     66 
     67     void setMinYLayoutOverflow(int overflow) { m_minYLayoutOverflow = overflow; }
     68     void setMaxYLayoutOverflow(int overflow) { m_maxYLayoutOverflow = overflow; }
     69     void setMinXLayoutOverflow(int overflow) { m_minXLayoutOverflow = overflow; }
     70     void setMaxXLayoutOverflow(int overflow) { m_maxXLayoutOverflow = overflow; }
     71 
     72     void setMinYVisualOverflow(int overflow) { m_minYVisualOverflow = overflow; }
     73     void setMaxYVisualOverflow(int overflow) { m_maxYVisualOverflow = overflow; }
     74     void setMinXVisualOverflow(int overflow) { m_minXVisualOverflow = overflow; }
     75     void setMaxXVisualOverflow(int overflow) { m_maxXVisualOverflow = overflow; }
     76 
     77     void move(int dx, int dy);
     78 
     79     void addLayoutOverflow(const IntRect&);
     80     void addVisualOverflow(const IntRect&);
     81 
     82     void setLayoutOverflow(const IntRect&);
     83     void setVisualOverflow(const IntRect&);
     84 
     85     void resetLayoutOverflow(const IntRect& defaultRect);
     86 
     87 private:
     88     int m_minYLayoutOverflow;
     89     int m_maxYLayoutOverflow;
     90     int m_minXLayoutOverflow;
     91     int m_maxXLayoutOverflow;
     92 
     93     int m_minYVisualOverflow;
     94     int m_maxYVisualOverflow;
     95     int m_minXVisualOverflow;
     96     int m_maxXVisualOverflow;
     97 };
     98 
     99 inline IntRect RenderOverflow::layoutOverflowRect() const
    100 {
    101     return IntRect(m_minXLayoutOverflow, m_minYLayoutOverflow, m_maxXLayoutOverflow - m_minXLayoutOverflow, m_maxYLayoutOverflow - m_minYLayoutOverflow);
    102 }
    103 
    104 inline IntRect RenderOverflow::visualOverflowRect() const
    105 {
    106     return IntRect(m_minXVisualOverflow, m_minYVisualOverflow, m_maxXVisualOverflow - m_minXVisualOverflow, m_maxYVisualOverflow - m_minYVisualOverflow);
    107 }
    108 
    109 inline void RenderOverflow::move(int dx, int dy)
    110 {
    111     m_minYLayoutOverflow += dy;
    112     m_maxYLayoutOverflow += dy;
    113     m_minXLayoutOverflow += dx;
    114     m_maxXLayoutOverflow += dx;
    115 
    116     m_minYVisualOverflow += dy;
    117     m_maxYVisualOverflow += dy;
    118     m_minXVisualOverflow += dx;
    119     m_maxXVisualOverflow += dx;
    120 }
    121 
    122 inline void RenderOverflow::addLayoutOverflow(const IntRect& rect)
    123 {
    124     m_minYLayoutOverflow = std::min(rect.y(), m_minYLayoutOverflow);
    125     m_maxYLayoutOverflow = std::max(rect.maxY(), m_maxYLayoutOverflow);
    126     m_minXLayoutOverflow = std::min(rect.x(), m_minXLayoutOverflow);
    127     m_maxXLayoutOverflow = std::max(rect.maxX(), m_maxXLayoutOverflow);
    128 }
    129 
    130 inline void RenderOverflow::addVisualOverflow(const IntRect& rect)
    131 {
    132     m_minYVisualOverflow = std::min(rect.y(), m_minYVisualOverflow);
    133     m_maxYVisualOverflow = std::max(rect.maxY(), m_maxYVisualOverflow);
    134     m_minXVisualOverflow = std::min(rect.x(), m_minXVisualOverflow);
    135     m_maxXVisualOverflow = std::max(rect.maxX(), m_maxXVisualOverflow);
    136 }
    137 
    138 inline void RenderOverflow::setLayoutOverflow(const IntRect& rect)
    139 {
    140     m_minYLayoutOverflow = rect.y();
    141     m_maxYLayoutOverflow = rect.maxY();
    142     m_minXLayoutOverflow = rect.x();
    143     m_maxXLayoutOverflow = rect.maxX();
    144 }
    145 
    146 inline void RenderOverflow::setVisualOverflow(const IntRect& rect)
    147 {
    148     m_minYVisualOverflow = rect.y();
    149     m_maxYVisualOverflow = rect.maxY();
    150     m_minXVisualOverflow = rect.x();
    151     m_maxXVisualOverflow = rect.maxX();
    152 }
    153 
    154 inline void RenderOverflow::resetLayoutOverflow(const IntRect& rect)
    155 {
    156     m_minYLayoutOverflow = rect.y();
    157     m_maxYLayoutOverflow = rect.maxY();
    158     m_minXLayoutOverflow = rect.x();
    159     m_maxXLayoutOverflow = rect.maxX();
    160 }
    161 
    162 } // namespace WebCore
    163 
    164 #endif // RenderOverflow_h
    165