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

Side by Side Diff: third_party/WebKit/Source/platform/geometry/LayoutRect.h

Issue 1660863002: Force all LayoutUnit construction to be explicit (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Also fix LayoutRectTest.cpp Created 4 years, 10 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012, Google Inc. All rights reserved. 2 * Copyright (c) 2012, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 class DoubleRect; 45 class DoubleRect;
46 46
47 class PLATFORM_EXPORT LayoutRect { 47 class PLATFORM_EXPORT LayoutRect {
48 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); 48 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
49 public: 49 public:
50 LayoutRect() { } 50 LayoutRect() { }
51 LayoutRect(const LayoutPoint& location, const LayoutSize& size) 51 LayoutRect(const LayoutPoint& location, const LayoutSize& size)
52 : m_location(location), m_size(size) { } 52 : m_location(location), m_size(size) { }
53 LayoutRect(LayoutUnit x, LayoutUnit y, LayoutUnit width, LayoutUnit height) 53 LayoutRect(LayoutUnit x, LayoutUnit y, LayoutUnit width, LayoutUnit height)
54 : m_location(LayoutPoint(x, y)), m_size(LayoutSize(width, height)) { } 54 : m_location(LayoutPoint(x, y)), m_size(LayoutSize(width, height)) { }
55 LayoutRect(int x, int y, int width, int height)
56 : m_location(LayoutPoint(x, y)), m_size(LayoutSize(width, height)) { }
55 LayoutRect(const FloatPoint& location, const FloatSize& size) 57 LayoutRect(const FloatPoint& location, const FloatSize& size)
56 : m_location(location), m_size(size) { } 58 : m_location(location), m_size(size) { }
57 LayoutRect(const DoublePoint& location, const DoubleSize& size) 59 LayoutRect(const DoublePoint& location, const DoubleSize& size)
58 : m_location(location), m_size(size) { } 60 : m_location(location), m_size(size) { }
59 LayoutRect(const IntPoint& location, const IntSize& size) 61 LayoutRect(const IntPoint& location, const IntSize& size)
60 : m_location(location), m_size(size) { } 62 : m_location(location), m_size(size) { }
61 explicit LayoutRect(const IntRect& rect) : m_location(rect.location()), m_si ze(rect.size()) { } 63 explicit LayoutRect(const IntRect& rect) : m_location(rect.location()), m_si ze(rect.size()) { }
62 64
63 explicit LayoutRect(const FloatRect&); // don't do this implicitly since it' s lossy 65 explicit LayoutRect(const FloatRect&); // don't do this implicitly since it' s lossy
64 explicit LayoutRect(const DoubleRect&); // don't do this implicitly since it 's lossy 66 explicit LayoutRect(const DoubleRect&); // don't do this implicitly since it 's lossy
(...skipping 26 matching lines...) Expand all
91 93
92 // NOTE: The result is rounded to integer values, and thus may be not the ex act 94 // NOTE: The result is rounded to integer values, and thus may be not the ex act
93 // center point. 95 // center point.
94 LayoutPoint center() const { return LayoutPoint(x() + width() / 2, y() + hei ght() / 2); } 96 LayoutPoint center() const { return LayoutPoint(x() + width() / 2, y() + hei ght() / 2); }
95 97
96 void move(const LayoutSize& size) { m_location += size; } 98 void move(const LayoutSize& size) { m_location += size; }
97 void move(const IntSize& size) { m_location.move(LayoutUnit(size.width()), L ayoutUnit(size.height())); } 99 void move(const IntSize& size) { m_location.move(LayoutUnit(size.width()), L ayoutUnit(size.height())); }
98 void moveBy(const LayoutPoint& offset) { m_location.move(offset.x(), offset. y()); } 100 void moveBy(const LayoutPoint& offset) { m_location.move(offset.x(), offset. y()); }
99 void moveBy(const IntPoint& offset) { m_location.move(LayoutUnit(offset.x()) , LayoutUnit(offset.y())); } 101 void moveBy(const IntPoint& offset) { m_location.move(LayoutUnit(offset.x()) , LayoutUnit(offset.y())); }
100 void move(LayoutUnit dx, LayoutUnit dy) { m_location.move(dx, dy); } 102 void move(LayoutUnit dx, LayoutUnit dy) { m_location.move(dx, dy); }
103 void move(int dx, int dy) { m_location.move(LayoutUnit(dx), LayoutUnit(dy)); }
101 104
102 void expand(const LayoutSize& size) { m_size += size; } 105 void expand(const LayoutSize& size) { m_size += size; }
103 void expand(const LayoutRectOutsets& box) 106 void expand(const LayoutRectOutsets& box)
104 { 107 {
105 m_location.move(-box.left(), -box.top()); 108 m_location.move(-box.left(), -box.top());
106 m_size.expand(box.left() + box.right(), box.top() + box.bottom()); 109 m_size.expand(box.left() + box.right(), box.top() + box.bottom());
107 } 110 }
108 void expand(LayoutUnit dw, LayoutUnit dh) { m_size.expand(dw, dh); } 111 void expand(LayoutUnit dw, LayoutUnit dh) { m_size.expand(dw, dh); }
109 void expandEdges(LayoutUnit top, LayoutUnit right, LayoutUnit bottom, Layout Unit left) 112 void expandEdges(LayoutUnit top, LayoutUnit right, LayoutUnit bottom, Layout Unit left)
110 { 113 {
111 m_location.move(-left, -top); 114 m_location.move(-left, -top);
112 m_size.expand(left + right, top + bottom); 115 m_size.expand(left + right, top + bottom);
113 } 116 }
114 void contract(const LayoutSize& size) { m_size -= size; } 117 void contract(const LayoutSize& size) { m_size -= size; }
115 void contract(LayoutUnit dw, LayoutUnit dh) { m_size.expand(-dw, -dh); } 118 void contract(LayoutUnit dw, LayoutUnit dh) { m_size.expand(-dw, -dh); }
119 void contract(int dw, int dh) { m_size.expand(-dw, -dh); }
116 void contractEdges(LayoutUnit top, LayoutUnit right, LayoutUnit bottom, Layo utUnit left) 120 void contractEdges(LayoutUnit top, LayoutUnit right, LayoutUnit bottom, Layo utUnit left)
117 { 121 {
118 m_location.move(left, top); 122 m_location.move(left, top);
119 m_size.shrink(left + right, top + bottom); 123 m_size.shrink(left + right, top + bottom);
120 } 124 }
121 125
122 void shiftXEdgeTo(LayoutUnit edge) 126 void shiftXEdgeTo(LayoutUnit edge)
123 { 127 {
124 LayoutUnit delta = edge - x(); 128 LayoutUnit delta = edge - x();
125 setX(edge); 129 setX(edge);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 { 172 {
169 m_location.setX(m_location.x() - dx); 173 m_location.setX(m_location.x() - dx);
170 m_size.setWidth(m_size.width() + dx + dx); 174 m_size.setWidth(m_size.width() + dx + dx);
171 } 175 }
172 void inflateY(LayoutUnit dy) 176 void inflateY(LayoutUnit dy)
173 { 177 {
174 m_location.setY(m_location.y() - dy); 178 m_location.setY(m_location.y() - dy);
175 m_size.setHeight(m_size.height() + dy + dy); 179 m_size.setHeight(m_size.height() + dy + dy);
176 } 180 }
177 void inflate(LayoutUnit d) { inflateX(d); inflateY(d); } 181 void inflate(LayoutUnit d) { inflateX(d); inflateY(d); }
182 void inflate(int d) { inflate(LayoutUnit(d)); }
178 void scale(float s); 183 void scale(float s);
179 void scale(float xAxisScale, float yAxisScale); 184 void scale(float xAxisScale, float yAxisScale);
180 185
181 LayoutRect transposedRect() const { return LayoutRect(m_location.transposedP oint(), m_size.transposedSize()); } 186 LayoutRect transposedRect() const { return LayoutRect(m_location.transposedP oint(), m_size.transposedSize()); }
182 187
183 static IntRect infiniteIntRect() 188 static IntRect infiniteIntRect()
184 { 189 {
185 // Due to saturated arithemetic this value is not the same as LayoutRect (IntRect(INT_MIN/2, INT_MIN/2, INT_MAX, INT_MAX)). 190 // Due to saturated arithemetic this value is not the same as LayoutRect (IntRect(INT_MIN/2, INT_MIN/2, INT_MAX, INT_MAX)).
186 static IntRect infiniteIntRect(LayoutRect(LayoutUnit::nearlyMin() / 2, L ayoutUnit::nearlyMin() / 2, LayoutUnit::nearlyMax(), LayoutUnit::nearlyMax())); 191 static IntRect infiniteIntRect(LayoutRect(LayoutUnit::nearlyMin() / 2, L ayoutUnit::nearlyMin() / 2, LayoutUnit::nearlyMax(), LayoutUnit::nearlyMax()));
187 return infiniteIntRect; 192 return infiniteIntRect;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 return IntRect(roundedIntPoint(location), pixelSnappedIntSize(size, location )); 263 return IntRect(roundedIntPoint(location), pixelSnappedIntSize(size, location ));
259 } 264 }
260 265
261 // Redeclared here to avoid ODR issues. 266 // Redeclared here to avoid ODR issues.
262 // See platform/testing/GeometryPrinters.h. 267 // See platform/testing/GeometryPrinters.h.
263 void PrintTo(const LayoutRect&, std::ostream*); 268 void PrintTo(const LayoutRect&, std::ostream*);
264 269
265 } // namespace blink 270 } // namespace blink
266 271
267 #endif // LayoutRect_h 272 #endif // LayoutRect_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698