 Chromium Code Reviews
 Chromium Code Reviews Issue 236203020:
  Separate repaint and layout requirements of StyleDifference (Step 1)  (Closed) 
  Base URL: svn://svn.chromium.org/blink/trunk
    
  
    Issue 236203020:
  Separate repaint and layout requirements of StyleDifference (Step 1)  (Closed) 
  Base URL: svn://svn.chromium.org/blink/trunk| Index: Source/core/rendering/style/StyleDifference.h | 
| diff --git a/Source/core/rendering/style/StyleDifference.h b/Source/core/rendering/style/StyleDifference.h | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..678513e8a30854e78a958e419c8fd7784e8bd46e | 
| --- /dev/null | 
| +++ b/Source/core/rendering/style/StyleDifference.h | 
| @@ -0,0 +1,159 @@ | 
| +// Copyright 2014 The Chromium Authors. All rights reserved. | 
| +// Use of this source code is governed by a BSD-style license that can be | 
| +// found in the LICENSE file. | 
| + | 
| +#ifndef StyleDifference_h | 
| +#define StyleDifference_h | 
| + | 
| +#include "core/rendering/style/RenderStyleConstants.h" | 
| 
Julien - ping for review
2014/04/18 20:35:15
Once you've removed the legacy type shouldn't this
 
Xianzhu
2014/04/18 22:02:27
Done.
 | 
| + | 
| +namespace WebCore { | 
| + | 
| +// The difference between two styles. | 
| 
Julien - ping for review
2014/04/18 20:35:15
Let's have more class comments:
// This class rep
 
Xianzhu
2014/04/18 22:02:27
Done.
 | 
| +class StyleDifference { | 
| +public: | 
| + StyleDifference() | 
| + : m_needsRecompositeLayer(0) | 
| 
Julien - ping for review
2014/04/18 20:35:15
Let's use false here.
 
Xianzhu
2014/04/18 22:02:27
Done.
 | 
| + , m_repaintType(NoRepaint) | 
| + , m_layoutType(NoLayout) | 
| + , m_contextSensitiveFlags(NotContextSensitive) { } | 
| + | 
| + // Temporary constructor to convert StyleDifferenceLegacy to new StyleDifference. | 
| + // At this step, implicit requirements (e.g. StyleDifferenceLayout implies StyleDifferenceRepaint), | 
| + // is not handled by StyleDifference but need to be handled by the callers. | 
| + StyleDifference(StyleDifferenceLegacy legacyDiff, unsigned context) | 
| + : m_needsRecompositeLayer(0) | 
| + , m_repaintType(NoRepaint) | 
| + , m_layoutType(NoLayout) | 
| + , m_contextSensitiveFlags(NotContextSensitive) | 
| + { | 
| + switch (legacyDiff) { | 
| + case StyleDifferenceEqual: | 
| + break; | 
| + case StyleDifferenceRecompositeLayer: | 
| + m_needsRecompositeLayer = 1; | 
| + break; | 
| + case StyleDifferenceRepaint: | 
| + m_repaintType = RepaintObjectOnly; | 
| + break; | 
| + case StyleDifferenceRepaintLayer: | 
| + m_repaintType = RepaintLayer; | 
| + break; | 
| + case StyleDifferenceLayoutPositionedMovementOnly: | 
| + m_layoutType = PositionedMovementOnly; | 
| + break; | 
| + case StyleDifferenceLayout: | 
| + m_layoutType = FullLayout; | 
| + break; | 
| + } | 
| + | 
| + if (context & ContextSensitivePropertyTransform) | 
| + m_contextSensitiveFlags |= TransformChanged; | 
| + if (context & ContextSensitivePropertyOpacity) | 
| + m_contextSensitiveFlags |= OpacityChanged; | 
| + if (context & ContextSensitivePropertyFilter) | 
| + m_contextSensitiveFlags |= FilterChanged; | 
| + if (context & ContextSensitivePropertyTextOrColor) | 
| + m_contextSensitiveFlags |= TextOrColorChanged; | 
| 
Julien - ping for review
2014/04/18 20:35:15
Why do we need an extra enum instead of reusing th
 
Xianzhu
2014/04/18 22:02:27
This change was reduced from my original whole big
 | 
| + } | 
| + | 
| + // The two styles are identical. | 
| + bool hasNoChange() const | 
| + { | 
| + return !m_needsRecompositeLayer | 
| + && m_repaintType == NoRepaint | 
| + && m_layoutType == NoLayout | 
| + && !isContextSensitive(); | 
| 
Julien - ping for review
2014/04/18 20:35:15
The context sensitive flags are really not differe
 
Xianzhu
2014/04/18 22:02:27
Actually directly treating StyleDifferenceEqual as
 | 
| + } | 
| + | 
| + // The layer needs its position and transform updated. Implied by other repaint and layout flags. | 
| + bool needsRecompositeLayer() const { return m_needsRecompositeLayer || needsRepaint() || needsLayout(); } | 
| + void setNeedsRecompositeLayer() { m_needsRecompositeLayer = 1; } | 
| 
Julien - ping for review
2014/04/18 20:35:15
Please use the boolean 'true' here.
 
Xianzhu
2014/04/18 22:02:27
Done.
 | 
| + | 
| + bool needsRepaint() const { return m_repaintType != NoRepaint; } | 
| + void resetNeedsRepaint() { m_repaintType = NoRepaint; } | 
| 
Julien - ping for review
2014/04/18 20:35:15
See comment below.
 
Xianzhu
2014/04/18 22:02:27
Done.
 | 
| + | 
| + // The object just needs to be repainted. | 
| + bool needsRepaintObjectOnly() const { return m_repaintType == RepaintObjectOnly; } | 
| + void setNeedsRepaintObject() | 
| + { | 
| + if (!needsRepaintLayer()) | 
| + m_repaintType = RepaintObjectOnly; | 
| + } | 
| + | 
| + // The layer and its descendant layers need to be repainted. | 
| + bool needsRepaintLayer() const { return m_repaintType == RepaintLayer; } | 
| + void setNeedsRepaintLayer() { m_repaintType = RepaintLayer; } | 
| + | 
| + bool needsLayout() const { return m_layoutType != NoLayout; } | 
| + void resetNeedsLayout() { m_layoutType = NoLayout; } | 
| 
Julien - ping for review
2014/04/18 20:35:15
These getters are named needsLayout / clearNeedsLa
 
Xianzhu
2014/04/18 22:02:27
Done.
 | 
| + | 
| + // The position of this positioned object has been updated. | 
| 
Julien - ping for review
2014/04/18 20:35:15
I would change position to "offset" as this is wha
 
Xianzhu
2014/04/18 22:02:27
Done.
 | 
| + bool needsPositionedMovementLayoutOnly() const { return m_layoutType == PositionedMovementOnly; } | 
| + void setNeedsPositionedMovementLayout() | 
| + { | 
| + if (!needsFullLayout()) | 
| + m_layoutType = PositionedMovementOnly; | 
| + // FIXME: This is temporary to keep the StyleDifferenceLegacy behavior. | 
| + m_repaintType = NoRepaint; | 
| + } | 
| + | 
| + // A full layout is required. | 
| 
Julien - ping for review
2014/04/18 20:35:15
Not really a helpful comment. A "full layout" is k
 
Xianzhu
2014/04/18 22:02:27
Removed. The function name seems descriptive enoug
 | 
| + bool needsFullLayout() const { return m_layoutType == FullLayout; } | 
| + void setNeedsFullLayout() | 
| + { | 
| + m_layoutType = FullLayout; | 
| + // FIXME: This is temporary to keep the StyleDifferenceLegacy behavior. | 
| + m_repaintType = NoRepaint; | 
| + } | 
| + | 
| + // When some style properties change, different amounts of work have to be done depending on | 
| + // context (e.g. whether the property is changing on an element which has a compositing layer). | 
| + // Caller of RenderStyle::visualInvalidationDiff() needs to check the context and determine | 
| + // what work is needed. | 
| 
Julien - ping for review
2014/04/18 20:35:15
I really think this should be a FIXME: these flags
 
Xianzhu
2014/04/18 22:02:27
Reverted changes about context sensitive propertie
 | 
| + bool isContextSensitive() const { return m_contextSensitiveFlags != NotContextSensitive; } | 
| + void resetContextSensitiveFlags() { m_contextSensitiveFlags = NotContextSensitive; } | 
| + | 
| + bool transformChanged() const { return m_contextSensitiveFlags & TransformChanged; } | 
| + void setTransformChanged() { m_contextSensitiveFlags |= TransformChanged; } | 
| + | 
| + bool opacityChanged() const { return m_contextSensitiveFlags & OpacityChanged; } | 
| 
Julien - ping for review
2014/04/18 20:35:15
Again those getters should have a conjugated verb:
 | 
| + void setOpacityChanged() { m_contextSensitiveFlags |= OpacityChanged; } | 
| + | 
| + bool filterChanged() const { return m_contextSensitiveFlags & FilterChanged; } | 
| + void setFilterChanged() { m_contextSensitiveFlags |= FilterChanged; } | 
| 
Julien - ping for review
2014/04/18 20:35:15
The setters for these properties are unused so we
 | 
| + | 
| + // Text decoration or color changed. Needs repaint if the object contains text or properties dependent or color (e.g., border or outline). | 
| + bool textOrColorChanged() const { return m_contextSensitiveFlags & TextOrColorChanged; } | 
| + void setTextOrColorChanged() { m_contextSensitiveFlags |= TextOrColorChanged; } | 
| + | 
| +private: | 
| + unsigned m_needsRecompositeLayer : 1; | 
| + | 
| + enum RepaintType { | 
| + NoRepaint, | 
| 
Julien - ping for review
2014/04/18 20:35:15
We should probably make these start at 0, it would
 
Xianzhu
2014/04/18 22:02:27
Done.
 | 
| + RepaintObjectOnly, | 
| + RepaintLayer | 
| + }; | 
| + unsigned m_repaintType : 2; | 
| + | 
| + enum LayoutType { | 
| + NoLayout, | 
| 
Julien - ping for review
2014/04/18 20:35:15
Same comment.
 
Xianzhu
2014/04/18 22:02:27
Done.
 | 
| + PositionedMovementOnly, | 
| + FullLayout | 
| + }; | 
| + unsigned m_layoutType : 2; | 
| + | 
| + enum ContextSensitiveFlags { | 
| + NotContextSensitive = 0, | 
| + TransformChanged = 1 << 0, | 
| + OpacityChanged = 1 << 1, | 
| + FilterChanged = 1 << 2, | 
| + TextOrColorChanged = 1 << 3 | 
| + }; | 
| + unsigned m_contextSensitiveFlags : 4; | 
| 
Julien - ping for review
2014/04/18 20:35:15
I think this is my biggest gripe with the change (
 
Xianzhu
2014/04/18 22:02:27
Agreed. Reverted the changes about context sensiti
 | 
| +}; | 
| + | 
| +} // namespace WebCore | 
| + | 
| +#endif // StyleDifference_h |