RenderOverflow.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. #ifndef RenderOverflow_h
  21. #define RenderOverflow_h
  22. #include "LayoutRect.h"
  23. namespace WebCore
  24. {
  25. // RenderOverflow is a class for tracking content that spills out of a box. This class is used by RenderBox and
  26. // InlineFlowBox.
  27. //
  28. // There are two types of overflow: layout overflow (which is expected to be reachable via scrolling mechanisms) and
  29. // visual overflow (which is not expected to be reachable via scrolling mechanisms).
  30. //
  31. // Layout overflow examples include other boxes that spill out of our box, For example, in the inline case a tall image
  32. // could spill out of a line box.
  33. // Examples of visual overflow are shadows, text stroke (and eventually outline and border-image).
  34. // This object is allocated only when some of these fields have non-default values in the owning box.
  35. class RenderOverflow {
  36. WTF_MAKE_NONCOPYABLE(RenderOverflow); WTF_MAKE_FAST_ALLOCATED;
  37. public:
  38. RenderOverflow(const LayoutRect& layoutRect, const LayoutRect& visualRect)
  39. : m_layoutOverflow(layoutRect)
  40. , m_visualOverflow(visualRect)
  41. {
  42. }
  43. const LayoutRect layoutOverflowRect() const { return m_layoutOverflow; }
  44. const LayoutRect visualOverflowRect() const { return m_visualOverflow; }
  45. void move(LayoutUnit dx, LayoutUnit dy);
  46. void addLayoutOverflow(const LayoutRect&);
  47. void addVisualOverflow(const LayoutRect&);
  48. void setLayoutOverflow(const LayoutRect&);
  49. void setVisualOverflow(const LayoutRect&);
  50. LayoutUnit layoutClientAfterEdge() const { return m_layoutClientAfterEdge; }
  51. void setLayoutClientAfterEdge(LayoutUnit clientAfterEdge) { m_layoutClientAfterEdge = clientAfterEdge; }
  52. private:
  53. LayoutRect m_layoutOverflow;
  54. LayoutRect m_visualOverflow;
  55. LayoutUnit m_layoutClientAfterEdge;
  56. };
  57. inline void RenderOverflow::move(LayoutUnit dx, LayoutUnit dy)
  58. {
  59. m_layoutOverflow.move(dx, dy);
  60. m_visualOverflow.move(dx, dy);
  61. }
  62. inline void RenderOverflow::addLayoutOverflow(const LayoutRect& rect)
  63. {
  64. LayoutUnit maxX = std::max(rect.maxX(), m_layoutOverflow.maxX());
  65. LayoutUnit maxY = std::max(rect.maxY(), m_layoutOverflow.maxY());
  66. m_layoutOverflow.setX(std::min(rect.x(), m_layoutOverflow.x()));
  67. m_layoutOverflow.setY(std::min(rect.y(), m_layoutOverflow.y()));
  68. m_layoutOverflow.setWidth(maxX - m_layoutOverflow.x());
  69. m_layoutOverflow.setHeight(maxY - m_layoutOverflow.y());
  70. }
  71. inline void RenderOverflow::addVisualOverflow(const LayoutRect& rect)
  72. {
  73. LayoutUnit maxX = std::max(rect.maxX(), m_visualOverflow.maxX());
  74. LayoutUnit maxY = std::max(rect.maxY(), m_visualOverflow.maxY());
  75. m_visualOverflow.setX(std::min(rect.x(), m_visualOverflow.x()));
  76. m_visualOverflow.setY(std::min(rect.y(), m_visualOverflow.y()));
  77. m_visualOverflow.setWidth(maxX - m_visualOverflow.x());
  78. m_visualOverflow.setHeight(maxY - m_visualOverflow.y());
  79. }
  80. inline void RenderOverflow::setLayoutOverflow(const LayoutRect& rect)
  81. {
  82. m_layoutOverflow = rect;
  83. }
  84. inline void RenderOverflow::setVisualOverflow(const LayoutRect& rect)
  85. {
  86. m_visualOverflow = rect;
  87. }
  88. } // namespace WebCore
  89. #endif // RenderOverflow_h