OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef StyleDifference_h |
| 6 #define StyleDifference_h |
| 7 |
| 8 // FIXME: Remove this include after we finish migrating from StyleDifferenceLega
cy. |
| 9 #include "core/rendering/style/RenderStyleConstants.h" |
| 10 |
| 11 namespace WebCore { |
| 12 |
| 13 // This class represents the difference between two computed styles (RenderStyle
). |
| 14 // The difference can be of 3 types: |
| 15 // - Layout difference |
| 16 // - Repaint difference |
| 17 // - Recompositing difference |
| 18 class StyleDifference { |
| 19 public: |
| 20 StyleDifference() |
| 21 : m_needsRecompositeLayer(false) |
| 22 , m_repaintType(NoRepaint) |
| 23 , m_layoutType(NoLayout) { } |
| 24 |
| 25 // Temporary constructor to convert StyleDifferenceLegacy to new StyleDiffer
ence. |
| 26 // At this step, implicit requirements (e.g. StyleDifferenceLayout implies S
tyleDifferenceRepaint), |
| 27 // is not handled by StyleDifference but need to be handled by the callers. |
| 28 StyleDifference(StyleDifferenceLegacy legacyDiff) |
| 29 : m_needsRecompositeLayer(false) |
| 30 , m_repaintType(NoRepaint) |
| 31 , m_layoutType(NoLayout) |
| 32 { |
| 33 switch (legacyDiff) { |
| 34 case StyleDifferenceEqual: |
| 35 break; |
| 36 case StyleDifferenceRecompositeLayer: |
| 37 m_needsRecompositeLayer = true; |
| 38 break; |
| 39 case StyleDifferenceRepaint: |
| 40 m_repaintType = RepaintObjectOnly; |
| 41 break; |
| 42 case StyleDifferenceRepaintLayer: |
| 43 m_repaintType = RepaintLayer; |
| 44 break; |
| 45 case StyleDifferenceLayoutPositionedMovementOnly: |
| 46 m_layoutType = PositionedMovement; |
| 47 break; |
| 48 case StyleDifferenceSimplifiedLayout: |
| 49 m_layoutType = SimplifiedLayout; |
| 50 break; |
| 51 case StyleDifferenceSimplifiedLayoutAndPositionedMovement: |
| 52 m_layoutType = PositionedMovement | SimplifiedLayout; |
| 53 break; |
| 54 case StyleDifferenceLayout: |
| 55 m_layoutType = FullLayout; |
| 56 break; |
| 57 } |
| 58 } |
| 59 |
| 60 // The two styles are identical. |
| 61 bool hasNoChange() const { return !m_needsRecompositeLayer && !m_repaintType
&& !m_layoutType; } |
| 62 |
| 63 // The layer needs its position and transform updated. Implied by other repa
int and layout flags. |
| 64 bool needsRecompositeLayer() const { return m_needsRecompositeLayer || needs
Repaint() || needsLayout(); } |
| 65 void setNeedsRecompositeLayer() { m_needsRecompositeLayer = true; } |
| 66 |
| 67 bool needsRepaint() const { return m_repaintType != NoRepaint; } |
| 68 void clearNeedsRepaint() { m_repaintType = NoRepaint; } |
| 69 |
| 70 // The object just needs to be repainted. |
| 71 bool needsRepaintObjectOnly() const { return m_repaintType == RepaintObjectO
nly; } |
| 72 void setNeedsRepaintObject() |
| 73 { |
| 74 if (!needsRepaintLayer()) |
| 75 m_repaintType = RepaintObjectOnly; |
| 76 } |
| 77 |
| 78 // The layer and its descendant layers need to be repainted. |
| 79 bool needsRepaintLayer() const { return m_repaintType == RepaintLayer; } |
| 80 void setNeedsRepaintLayer() { m_repaintType = RepaintLayer; } |
| 81 |
| 82 bool needsLayout() const { return m_layoutType != NoLayout; } |
| 83 void clearNeedsLayout() { m_layoutType = NoLayout; } |
| 84 |
| 85 // The offset of this positioned object has been updated. |
| 86 bool needsPositionedMovementLayout() const { return m_layoutType & Positione
dMovement; } |
| 87 void setNeedsPositionedMovementLayout() |
| 88 { |
| 89 if (!needsFullLayout()) |
| 90 m_layoutType |= PositionedMovement; |
| 91 // FIXME: This is temporary to keep the StyleDifferenceLegacy behavior. |
| 92 m_repaintType = NoRepaint; |
| 93 } |
| 94 |
| 95 // Only overflow needs to be recomputed. |
| 96 bool needsSimplifiedLayout() const { return m_layoutType & SimplifiedLayout;
} |
| 97 void setNeedsSimplifiedLayout() |
| 98 { |
| 99 if (!needsFullLayout()) |
| 100 m_layoutType |= SimplifiedLayout; |
| 101 // FIXME: This is temporary to keep the StyleDifferenceLegacy behavior. |
| 102 m_repaintType = NoRepaint; |
| 103 } |
| 104 |
| 105 bool needsFullLayout() const { return m_layoutType == FullLayout; } |
| 106 void setNeedsFullLayout() |
| 107 { |
| 108 m_layoutType = FullLayout; |
| 109 // FIXME: This is temporary to keep the StyleDifferenceLegacy behavior. |
| 110 m_repaintType = NoRepaint; |
| 111 } |
| 112 |
| 113 private: |
| 114 unsigned m_needsRecompositeLayer : 1; |
| 115 |
| 116 enum RepaintType { |
| 117 NoRepaint = 0, |
| 118 RepaintObjectOnly, |
| 119 RepaintLayer |
| 120 }; |
| 121 unsigned m_repaintType : 2; |
| 122 |
| 123 enum LayoutType { |
| 124 NoLayout = 0, |
| 125 PositionedMovement = 1 << 0, |
| 126 SimplifiedLayout = 1 << 1, |
| 127 FullLayout = 1 << 2 |
| 128 }; |
| 129 unsigned m_layoutType : 3; |
| 130 }; |
| 131 |
| 132 } // namespace WebCore |
| 133 |
| 134 #endif // StyleDifference_h |
OLD | NEW |