15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// found in the LICENSE file.
45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef StyleDifference_h
65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define StyleDifference_h
75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "wtf/Assertions.h"
95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)namespace blink {
115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class StyleDifference {
135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)public:
145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    enum PropertyDifference {
155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        TransformChanged = 1 << 0,
165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        OpacityChanged = 1 << 1,
175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        ZIndexChanged = 1 << 2,
185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        FilterChanged = 1 << 3,
195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        // The object needs to issue paint invalidations if it contains text or properties dependent on color (e.g., border or outline).
205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        TextOrColorChanged = 1 << 4,
215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    };
225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    StyleDifference()
245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        : m_paintInvalidationType(NoPaintInvalidation)
2553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        , m_layoutType(NoLayout)
265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        , m_propertySpecificDifferences(0)
27c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    { }
285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    bool hasDifference() const { return m_paintInvalidationType || m_layoutType || m_propertySpecificDifferences; }
305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    bool hasAtMostPropertySpecificDifferences(unsigned propertyDifferences) const
325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    {
3302772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch        return !m_paintInvalidationType && !m_layoutType && !(m_propertySpecificDifferences & ~propertyDifferences);
34d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    }
355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
36d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    bool needsPaintInvalidation() const { return m_paintInvalidationType != NoPaintInvalidation; }
3702772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch    void clearNeedsPaintInvalidation() { m_paintInvalidationType = NoPaintInvalidation; }
385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // The object just needs to issue paint invalidations.
405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    bool needsPaintInvalidationObject() const { return m_paintInvalidationType == PaintInvalidationObject; }
415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    void setNeedsPaintInvalidationObject()
425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    {
435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        ASSERT(!needsPaintInvalidationLayer());
44d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        m_paintInvalidationType = PaintInvalidationObject;
455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
4602772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch
475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // The layer and its descendant layers need to issue paint invalidations.
485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    bool needsPaintInvalidationLayer() const { return m_paintInvalidationType == PaintInvalidationLayer; }
495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    void setNeedsPaintInvalidationLayer() { m_paintInvalidationType = PaintInvalidationLayer; }
505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
51d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    bool needsLayout() const { return m_layoutType != NoLayout; }
52d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    void clearNeedsLayout() { m_layoutType = NoLayout; }
53d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
54d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    // The offset of this positioned object has been updated.
55d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    bool needsPositionedMovementLayout() const { return m_layoutType == PositionedMovement; }
56323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    void setNeedsPositionedMovementLayout()
57d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    {
58d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        ASSERT(!needsFullLayout());
595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_layoutType = PositionedMovement;
60c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    }
61
62    bool needsFullLayout() const { return m_layoutType == FullLayout; }
63    void setNeedsFullLayout() { m_layoutType = FullLayout; }
64
65    bool transformChanged() const { return m_propertySpecificDifferences & TransformChanged; }
66    void setTransformChanged() { m_propertySpecificDifferences |= TransformChanged; }
67
68    bool opacityChanged() const { return m_propertySpecificDifferences & OpacityChanged; }
69    void setOpacityChanged() { m_propertySpecificDifferences |= OpacityChanged; }
70
71    bool zIndexChanged() const { return m_propertySpecificDifferences & ZIndexChanged; }
72    void setZIndexChanged() { m_propertySpecificDifferences |= ZIndexChanged; }
73
74    bool filterChanged() const { return m_propertySpecificDifferences & FilterChanged; }
75    void setFilterChanged() { m_propertySpecificDifferences |= FilterChanged; }
76
77    bool textOrColorChanged() const { return m_propertySpecificDifferences & TextOrColorChanged; }
78    void setTextOrColorChanged() { m_propertySpecificDifferences |= TextOrColorChanged; }
79
80private:
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