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 #include "wtf/Assertions.h" 9 10 namespace blink { 11 12 class StyleDifference { 13 public: 14 enum PropertyDifference { 15 TransformChanged = 1 << 0, 16 OpacityChanged = 1 << 1, 17 ZIndexChanged = 1 << 2, 18 FilterChanged = 1 << 3, 19 // The object needs to issue paint invalidations if it contains text or properties dependent on color (e.g., border or outline). 20 TextOrColorChanged = 1 << 4, 21 }; 22 StyleDifference()23 StyleDifference() 24 : m_paintInvalidationType(NoPaintInvalidation) 25 , m_layoutType(NoLayout) 26 , m_propertySpecificDifferences(0) 27 { } 28 hasDifference()29 bool hasDifference() const { return m_paintInvalidationType || m_layoutType || m_propertySpecificDifferences; } 30 hasAtMostPropertySpecificDifferences(unsigned propertyDifferences)31 bool hasAtMostPropertySpecificDifferences(unsigned propertyDifferences) const 32 { 33 return !m_paintInvalidationType && !m_layoutType && !(m_propertySpecificDifferences & ~propertyDifferences); 34 } 35 needsPaintInvalidation()36 bool needsPaintInvalidation() const { return m_paintInvalidationType != NoPaintInvalidation; } clearNeedsPaintInvalidation()37 void clearNeedsPaintInvalidation() { m_paintInvalidationType = NoPaintInvalidation; } 38 39 // The object just needs to issue paint invalidations. needsPaintInvalidationObject()40 bool needsPaintInvalidationObject() const { return m_paintInvalidationType == PaintInvalidationObject; } setNeedsPaintInvalidationObject()41 void setNeedsPaintInvalidationObject() 42 { 43 ASSERT(!needsPaintInvalidationLayer()); 44 m_paintInvalidationType = PaintInvalidationObject; 45 } 46 47 // The layer and its descendant layers need to issue paint invalidations. needsPaintInvalidationLayer()48 bool needsPaintInvalidationLayer() const { return m_paintInvalidationType == PaintInvalidationLayer; } setNeedsPaintInvalidationLayer()49 void setNeedsPaintInvalidationLayer() { m_paintInvalidationType = PaintInvalidationLayer; } 50 needsLayout()51 bool needsLayout() const { return m_layoutType != NoLayout; } clearNeedsLayout()52 void clearNeedsLayout() { m_layoutType = NoLayout; } 53 54 // The offset of this positioned object has been updated. needsPositionedMovementLayout()55 bool needsPositionedMovementLayout() const { return m_layoutType == PositionedMovement; } setNeedsPositionedMovementLayout()56 void setNeedsPositionedMovementLayout() 57 { 58 ASSERT(!needsFullLayout()); 59 m_layoutType = PositionedMovement; 60 } 61 needsFullLayout()62 bool needsFullLayout() const { return m_layoutType == FullLayout; } setNeedsFullLayout()63 void setNeedsFullLayout() { m_layoutType = FullLayout; } 64 transformChanged()65 bool transformChanged() const { return m_propertySpecificDifferences & TransformChanged; } setTransformChanged()66 void setTransformChanged() { m_propertySpecificDifferences |= TransformChanged; } 67 opacityChanged()68 bool opacityChanged() const { return m_propertySpecificDifferences & OpacityChanged; } setOpacityChanged()69 void setOpacityChanged() { m_propertySpecificDifferences |= OpacityChanged; } 70 zIndexChanged()71 bool zIndexChanged() const { return m_propertySpecificDifferences & ZIndexChanged; } setZIndexChanged()72 void setZIndexChanged() { m_propertySpecificDifferences |= ZIndexChanged; } 73 filterChanged()74 bool filterChanged() const { return m_propertySpecificDifferences & FilterChanged; } setFilterChanged()75 void setFilterChanged() { m_propertySpecificDifferences |= FilterChanged; } 76 textOrColorChanged()77 bool textOrColorChanged() const { return m_propertySpecificDifferences & TextOrColorChanged; } setTextOrColorChanged()78 void setTextOrColorChanged() { m_propertySpecificDifferences |= TextOrColorChanged; } 79 80 private: 81 enum PaintInvalidationType { 82 NoPaintInvalidation = 0, 83 PaintInvalidationObject, 84 PaintInvalidationLayer 85 }; 86 unsigned m_paintInvalidationType : 2; 87 88 enum LayoutType { 89 NoLayout = 0, 90 PositionedMovement, 91 FullLayout 92 }; 93 unsigned m_layoutType : 2; 94 95 unsigned m_propertySpecificDifferences : 5; 96 }; 97 98 } // namespace blink 99 100 #endif // StyleDifference_h 101