Home | History | Annotate | Download | only in style
      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 WebCore {
     11 
     12 // This class represents the difference between two computed styles (RenderStyle).
     13 // The difference can be combination of 3 types according to the actions needed:
     14 // - Difference needing layout
     15 // - Difference needing repaint
     16 // - Difference needing recompositing layers
     17 class StyleDifference {
     18 public:
     19     StyleDifference()
     20         : m_needsRecompositeLayer(false)
     21         , m_repaintType(NoRepaint)
     22         , m_layoutType(NoLayout) { }
     23 
     24     // The two styles are identical.
     25     bool hasNoChange() const { return !m_needsRecompositeLayer && !m_repaintType && !m_layoutType; }
     26 
     27     // The layer needs its position and transform updated. Implied by other repaint and layout flags.
     28     bool needsRecompositeLayer() const { return m_needsRecompositeLayer || needsRepaint() || needsLayout(); }
     29     void setNeedsRecompositeLayer() { m_needsRecompositeLayer = true; }
     30 
     31     bool needsRepaint() const { return m_repaintType != NoRepaint; }
     32     void clearNeedsRepaint() { m_repaintType = NoRepaint; }
     33 
     34     // The object just needs to be repainted.
     35     bool needsRepaintObject() const { return m_repaintType == RepaintObject; }
     36     void setNeedsRepaintObject()
     37     {
     38         ASSERT(!needsRepaintLayer());
     39         m_repaintType = RepaintObject;
     40     }
     41 
     42     // The layer and its descendant layers need to be repainted.
     43     bool needsRepaintLayer() const { return m_repaintType == RepaintLayer; }
     44     void setNeedsRepaintLayer() { m_repaintType = RepaintLayer; }
     45 
     46     bool needsLayout() const { return m_layoutType != NoLayout; }
     47     void clearNeedsLayout() { m_layoutType = NoLayout; }
     48 
     49     // The offset of this positioned object has been updated.
     50     bool needsPositionedMovementLayout() const { return m_layoutType == PositionedMovement; }
     51     void setNeedsPositionedMovementLayout()
     52     {
     53         ASSERT(!needsFullLayout());
     54         m_layoutType = PositionedMovement;
     55     }
     56 
     57     bool needsFullLayout() const { return m_layoutType == FullLayout; }
     58     void setNeedsFullLayout() { m_layoutType = FullLayout; }
     59 
     60 private:
     61     unsigned m_needsRecompositeLayer : 1;
     62 
     63     enum RepaintType {
     64         NoRepaint = 0,
     65         RepaintObject,
     66         RepaintLayer
     67     };
     68     unsigned m_repaintType : 2;
     69 
     70     enum LayoutType {
     71         NoLayout = 0,
     72         PositionedMovement,
     73         FullLayout
     74     };
     75     unsigned m_layoutType : 2;
     76 };
     77 
     78 } // namespace WebCore
     79 
     80 #endif // StyleDifference_h
     81