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

Side by Side Diff: third_party/WebKit/Source/platform/geometry/LayoutSize.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 AspectRatioFitShrink, 45 AspectRatioFitShrink,
46 AspectRatioFitGrow 46 AspectRatioFitGrow
47 }; 47 };
48 48
49 class LayoutSize { 49 class LayoutSize {
50 DISALLOW_NEW(); 50 DISALLOW_NEW();
51 public: 51 public:
52 LayoutSize() { } 52 LayoutSize() { }
53 explicit LayoutSize(const IntSize& size) : m_width(size.width()), m_height(s ize.height()) { } 53 explicit LayoutSize(const IntSize& size) : m_width(size.width()), m_height(s ize.height()) { }
54 LayoutSize(LayoutUnit width, LayoutUnit height) : m_width(width), m_height(h eight) { } 54 LayoutSize(LayoutUnit width, LayoutUnit height) : m_width(width), m_height(h eight) { }
55 LayoutSize(int width, int height) : m_width(LayoutUnit(width)), m_height(Lay outUnit(height)) { }
56 LayoutSize(float width, float height) : m_width(LayoutUnit(width)), m_height (LayoutUnit(height)) { }
55 57
56 explicit LayoutSize(const FloatSize& size) : m_width(size.width()), m_height (size.height()) { } 58 explicit LayoutSize(const FloatSize& size) : m_width(size.width()), m_height (size.height()) { }
57 explicit LayoutSize(const DoubleSize& size) : m_width(size.width()), m_heigh t(size.height()) { } 59 explicit LayoutSize(const DoubleSize& size) : m_width(size.width()), m_heigh t(size.height()) { }
58 60
59 LayoutUnit width() const { return m_width; } 61 LayoutUnit width() const { return m_width; }
60 LayoutUnit height() const { return m_height; } 62 LayoutUnit height() const { return m_height; }
61 63
62 void setWidth(LayoutUnit width) { m_width = width; } 64 void setWidth(LayoutUnit width) { m_width = width; }
63 void setHeight(LayoutUnit height) { m_height = height; } 65 void setHeight(LayoutUnit height) { m_height = height; }
64 66
65 bool isEmpty() const { return m_width.rawValue() <= 0 || m_height.rawValue() <= 0; } 67 bool isEmpty() const { return m_width.rawValue() <= 0 || m_height.rawValue() <= 0; }
66 bool isZero() const { return !m_width && !m_height; } 68 bool isZero() const { return !m_width && !m_height; }
67 69
68 float aspectRatio() const { return m_width.toFloat() / m_height.toFloat(); } 70 float aspectRatio() const { return m_width.toFloat() / m_height.toFloat(); }
69 71
70 void expand(LayoutUnit width, LayoutUnit height) 72 void expand(LayoutUnit width, LayoutUnit height)
71 { 73 {
72 m_width += width; 74 m_width += width;
73 m_height += height; 75 m_height += height;
74 } 76 }
75 77
78 void expand(int width, int height) { expand(LayoutUnit(width), LayoutUnit(he ight)); }
79
80 void shrink(int width, int height) { shrink(LayoutUnit(width), LayoutUnit(he ight)); }
81
76 void shrink(LayoutUnit width, LayoutUnit height) 82 void shrink(LayoutUnit width, LayoutUnit height)
77 { 83 {
78 m_width -= width; 84 m_width -= width;
79 m_height -= height; 85 m_height -= height;
80 } 86 }
81 87
82 void scale(float scale) 88 void scale(float scale)
83 { 89 {
84 m_width *= scale; 90 m_width *= scale;
85 m_height *= scale; 91 m_height *= scale;
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 } 228 }
223 229
224 inline LayoutSize roundedLayoutSize(const FloatSize& s) 230 inline LayoutSize roundedLayoutSize(const FloatSize& s)
225 { 231 {
226 return LayoutSize(s); 232 return LayoutSize(s);
227 } 233 }
228 234
229 } // namespace blink 235 } // namespace blink
230 236
231 #endif // LayoutSize_h 237 #endif // LayoutSize_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698