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..274d192b6df3282ef9d925da9f0abafc08fb7fe0 |
--- /dev/null |
+++ b/third_party/WebKit/Source/core/style/BorderWidth.h |
@@ -0,0 +1,48 @@ |
+// 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(); |
+ friend class ComputedStyle; |
shend
2017/05/23 08:05:32
does this need to be a friend?
nainar
2017/05/23 08:10:04
nope artifact of BorderValue which I blatantly cop
|
+ |
+ 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; |
+ } |
+ 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_; |
+ } |
+ |
+ protected: |
shend
2017/05/23 08:05:32
I would just do private.
nainar
2017/05/23 08:10:04
Done.
|
+ static unsigned WidthToFixedPoint(float width) { |
+ DCHECK_GE(width, 0); |
+ return static_cast<unsigned>(std::min<float>(width, kMaxForBorderWidth) * |
+ kBorderWidthDenominator); |
+ } |
+ |
+ unsigned width_ : 26; // Fixed point width |
shend
2017/05/23 08:05:32
there's probably no need to bit pack this anymore,
nainar
2017/05/23 08:10:04
Yup. Done
|
+}; |
+ |
+} // namespace blink |
+ |
+#endif // BorderWidth_h |