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

Unified Diff: third_party/WebKit/Source/platform/LayoutUnit.h

Issue 1648573002: Transition to explicit constructors in LayoutUnit (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove int constructors for size/point... they result in incorrect conversions until LayoutUnit is … Created 4 years, 11 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/platform/LayoutUnit.h
diff --git a/third_party/WebKit/Source/platform/LayoutUnit.h b/third_party/WebKit/Source/platform/LayoutUnit.h
index 552ec0495cd4a9749a89f3bd050ba7c4a390996b..6dc55022c396d84018b473653d709d7886c6ea4c 100644
--- a/third_party/WebKit/Source/platform/LayoutUnit.h
+++ b/third_party/WebKit/Source/platform/LayoutUnit.h
@@ -35,6 +35,7 @@
#include "wtf/Assertions.h"
#include "wtf/MathExtras.h"
#include "wtf/SaturatedArithmetic.h"
+#include <algorithm>
#include <limits.h>
#include <limits>
#include <stdlib.h>
@@ -65,6 +66,7 @@ class LayoutUnit {
DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
public:
LayoutUnit() : m_value(0) { }
+ // TODO(leviw): All of the below constructors should be explicit. crbug.com/581254
LayoutUnit(int value) { setValue(value); }
LayoutUnit(unsigned short value) { setValue(value); }
LayoutUnit(unsigned value) { setValue(value); }
@@ -156,6 +158,11 @@ public:
return m_value >> kLayoutUnitFractionalBits;
}
+ LayoutUnit clampToZero() const
+ {
+ return std::max(*this, LayoutUnit());
+ }
+
LayoutUnit fraction() const
{
// Add the fraction to the size (as opposed to the full location) to avoid overflows.
@@ -678,13 +685,13 @@ inline LayoutUnit& operator+=(LayoutUnit& a, const LayoutUnit& b)
inline LayoutUnit& operator+=(LayoutUnit& a, int b)
{
- a = a + b;
+ a = a + LayoutUnit(b);
return a;
}
inline LayoutUnit& operator+=(LayoutUnit& a, float b)
{
- a = a + b;
+ a = LayoutUnit(a + b);
return a;
}
@@ -696,7 +703,7 @@ inline float& operator+=(float& a, const LayoutUnit& b)
inline LayoutUnit& operator-=(LayoutUnit& a, int b)
{
- a = a - b;
+ a = a - LayoutUnit(b);
return a;
}
@@ -708,7 +715,7 @@ inline LayoutUnit& operator-=(LayoutUnit& a, const LayoutUnit& b)
inline LayoutUnit& operator-=(LayoutUnit& a, float b)
{
- a = a - b;
+ a = LayoutUnit(a - b);
return a;
}
@@ -723,11 +730,10 @@ inline LayoutUnit& operator*=(LayoutUnit& a, const LayoutUnit& b)
a = a * b;
return a;
}
-// operator*=(LayoutUnit& a, int b) is supported by the operator above plus LayoutUnit(int).
inline LayoutUnit& operator*=(LayoutUnit& a, float b)
{
- a = a * b;
+ a = LayoutUnit(a * b);
return a;
}
@@ -742,11 +748,10 @@ inline LayoutUnit& operator/=(LayoutUnit& a, const LayoutUnit& b)
a = a / b;
return a;
}
-// operator/=(LayoutUnit& a, int b) is supported by the operator above plus LayoutUnit(int).
inline LayoutUnit& operator/=(LayoutUnit& a, float b)
{
- a = a / b;
+ a = LayoutUnit(a / b);
return a;
}
« no previous file with comments | « third_party/WebKit/Source/core/style/NinePieceImage.h ('k') | third_party/WebKit/Source/platform/LengthFunctions.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698