Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(588)

Unified Diff: third_party/WebKit/Source/core/style/BorderWidth.h

Issue 2904453002: Use LayoutUnit for all border-*-width logic (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSProperties.json5 ('k') | third_party/WebKit/Source/core/style/ComputedStyle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698