Chromium Code Reviews| Index: third_party/WebKit/Source/core/style/BorderWidth.h |
| diff --git a/third_party/WebKit/Source/core/style/BorderWidth.h b/third_party/WebKit/Source/core/style/BorderWidth.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c69fd2cfb35567fdee930ade8fb36b39a6835c1d |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/style/BorderWidth.h |
| @@ -0,0 +1,47 @@ |
| +// Copyright 2017 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 BorderWidth_h |
| +#define BorderWidth_h |
| + |
| +#include "core/style/ComputedStyleConstants.h" |
| + |
| +namespace blink { |
| + |
| +class BorderWidth { |
| + DISALLOW_NEW(); |
| + |
| + public: |
| + BorderWidth() { SetWidth(3); } |
| + |
| + BorderWidth(float width) { SetWidth(width); } |
| + |
| + bool operator==(const BorderWidth& o) const { return width_ == o.width_; } |
| + |
| + bool operator!=(const BorderWidth& o) const { return !(*this == o); } |
| + |
| + float Width() const { |
| + return static_cast<float>(width_) / kBorderWidthDenominator; |
|
alancutter (OOO until 2018)
2017/05/24 01:50:06
I wonder why we don't use LayoutUnit for this. It
nainar1
2017/05/24 01:53:21
Could use LayoutUnit - didn't know it was a thing.
shend
2017/05/24 01:55:08
If it does the same thing and you could get it to
|
| + } |
| + void SetWidth(float width) { width_ = WidthToFixedPoint(width); } |
| + |
| + // Since precision is lost with fixed point, comparisons also have |
| + // to be done in fixed point. |
| + bool WidthEquals(float width) const { |
| + return WidthToFixedPoint(width) == width_; |
| + } |
| + |
| + private: |
| + static unsigned WidthToFixedPoint(float width) { |
| + DCHECK_GE(width, 0); |
| + return static_cast<unsigned>(std::min<float>(width, kMaxForBorderWidth) * |
| + kBorderWidthDenominator); |
| + } |
| + |
| + unsigned width_; // Fixed point width |
| +}; |
| + |
| +} // namespace blink |
| + |
| +#endif // BorderWidth_h |