Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org) |
| 3 * (C) 2000 Antti Koivisto (koivisto@kde.org) | 3 * (C) 2000 Antti Koivisto (koivisto@kde.org) |
| 4 * (C) 2000 Dirk Mueller (mueller@kde.org) | 4 * (C) 2000 Dirk Mueller (mueller@kde.org) |
| 5 * Copyright (C) 2003, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 5 * Copyright (C) 2003, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
| 6 * Copyright (C) 2006 Graham Dennis (graham.dennis@gmail.com) | 6 * Copyright (C) 2006 Graham Dennis (graham.dennis@gmail.com) |
| 7 * | 7 * |
| 8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
| 9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
| 10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 #ifndef BorderValue_h | 25 #ifndef BorderValue_h |
| 26 #define BorderValue_h | 26 #define BorderValue_h |
| 27 | 27 |
| 28 #include "core/css/StyleColor.h" | 28 #include "core/css/StyleColor.h" |
| 29 #include "core/style/ComputedStyleConstants.h" | 29 #include "core/style/ComputedStyleConstants.h" |
| 30 #include "platform/graphics/Color.h" | 30 #include "platform/graphics/Color.h" |
| 31 #include "wtf/Allocator.h" | 31 #include "wtf/Allocator.h" |
| 32 | 32 |
| 33 namespace blink { | 33 namespace blink { |
| 34 | 34 |
| 35 static const int kBorderWidthFractionalBits = 6; | |
|
pdr.
2017/01/27 20:28:44
Can you add a comment above here describing the fi
| |
| 36 static const int kBorderWidthDenominator = 1 << kBorderWidthFractionalBits; | |
| 37 static const int kMaxForBorderWidth = ((1 << 26) - 1) / kBorderWidthDenominator; | |
| 38 | |
|
pdr.
2017/01/27 20:28:44
Could you add a short unittest for the new fixed p
| |
| 35 class BorderValue { | 39 class BorderValue { |
| 36 DISALLOW_NEW(); | 40 DISALLOW_NEW(); |
| 37 friend class ComputedStyle; | 41 friend class ComputedStyle; |
| 38 | 42 |
| 39 public: | 43 public: |
| 40 BorderValue() | 44 BorderValue() |
| 41 : m_color(0), | 45 : m_color(0), |
| 42 m_colorIsCurrentColor(true), | 46 m_colorIsCurrentColor(true), |
| 43 m_width(3), | |
| 44 m_style(BorderStyleNone), | 47 m_style(BorderStyleNone), |
| 45 m_isAuto(OutlineIsAutoOff) {} | 48 m_isAuto(OutlineIsAutoOff) { |
| 49 setWidth(3); | |
| 50 } | |
| 46 | 51 |
| 47 bool nonZero() const { return width() && (m_style != BorderStyleNone); } | 52 bool nonZero() const { return width() && (m_style != BorderStyleNone); } |
| 48 | 53 |
| 49 bool isTransparent() const { | 54 bool isTransparent() const { |
| 50 return !m_colorIsCurrentColor && !m_color.alpha(); | 55 return !m_colorIsCurrentColor && !m_color.alpha(); |
| 51 } | 56 } |
| 52 | 57 |
| 53 bool operator==(const BorderValue& o) const { | 58 bool operator==(const BorderValue& o) const { |
| 54 return m_width == o.m_width && m_style == o.m_style && | 59 return m_width == o.m_width && m_style == o.m_style && |
| 55 m_color == o.m_color && | 60 m_color == o.m_color && |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 71 void setColor(const StyleColor& color) { | 76 void setColor(const StyleColor& color) { |
| 72 m_color = color.resolve(Color()); | 77 m_color = color.resolve(Color()); |
| 73 m_colorIsCurrentColor = color.isCurrentColor(); | 78 m_colorIsCurrentColor = color.isCurrentColor(); |
| 74 } | 79 } |
| 75 | 80 |
| 76 StyleColor color() const { | 81 StyleColor color() const { |
| 77 return m_colorIsCurrentColor ? StyleColor::currentColor() | 82 return m_colorIsCurrentColor ? StyleColor::currentColor() |
| 78 : StyleColor(m_color); | 83 : StyleColor(m_color); |
| 79 } | 84 } |
| 80 | 85 |
| 81 int width() const { return m_width; } | 86 float width() const { |
| 87 return static_cast<float>(m_width) / kBorderWidthDenominator; | |
| 88 } | |
| 89 void setWidth(float width) { m_width = widthToFixedPoint(width); } | |
| 90 bool widthEquals(float width) const { | |
|
pdr.
2017/01/27 20:28:44
Is this used over checking width() to avoid the pe
Karl Øygard
2017/01/28 16:46:27
We have to do this, since width now loses precisio
| |
| 91 return widthToFixedPoint(width) == m_width; | |
| 92 } | |
| 82 | 93 |
| 83 EBorderStyle style() const { return static_cast<EBorderStyle>(m_style); } | 94 EBorderStyle style() const { return static_cast<EBorderStyle>(m_style); } |
| 84 void setStyle(EBorderStyle style) { m_style = style; } | 95 void setStyle(EBorderStyle style) { m_style = style; } |
| 85 | 96 |
| 86 protected: | 97 protected: |
| 98 static unsigned widthToFixedPoint(float width) { | |
| 99 return static_cast<unsigned>(std::min<float>(width, kMaxForBorderWidth) * | |
|
pdr.
2017/01/27 20:28:44
Is this safe when width is negative? Could you add
Karl Øygard
2017/02/10 12:53:18
Done.
| |
| 100 kBorderWidthDenominator); | |
| 101 } | |
| 102 | |
| 87 Color m_color; | 103 Color m_color; |
| 88 unsigned m_colorIsCurrentColor : 1; | 104 unsigned m_colorIsCurrentColor : 1; |
| 89 | 105 |
| 90 unsigned m_width : 26; | 106 unsigned m_width : 26; // Fixed point width |
|
pdr.
2017/01/27 20:28:44
WDYT of using a typedef to make this a little more
Karl Øygard
2017/02/10 12:53:18
I agree and tried, but the check-webkit-style pres
| |
| 91 unsigned m_style : 4; // EBorderStyle | 107 unsigned m_style : 4; // EBorderStyle |
| 92 | 108 |
| 93 // This is only used by OutlineValue but moved here to keep the bits packed. | 109 // This is only used by OutlineValue but moved here to keep the bits packed. |
| 94 unsigned m_isAuto : 1; // OutlineIsAuto | 110 unsigned m_isAuto : 1; // OutlineIsAuto |
| 95 }; | 111 }; |
| 96 | 112 |
| 97 } // namespace blink | 113 } // namespace blink |
| 98 | 114 |
| 99 #endif // BorderValue_h | 115 #endif // BorderValue_h |
| OLD | NEW |