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

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

Issue 2904453002: Use LayoutUnit for all border-*-width logic (Closed)
Patch Set: shend@ suggestions 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..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
« 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