Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / platform / geometry / DoubleSize.h
blob20c67fe2ef7eae64c057fb9dca7339aea259deaa
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef DoubleSize_h
6 #define DoubleSize_h
8 #include "platform/geometry/FloatSize.h"
9 #include "platform/geometry/IntSize.h"
10 #include "wtf/MathExtras.h"
12 namespace blink {
14 class LayoutSize;
16 class PLATFORM_EXPORT DoubleSize {
17 public:
18 DoubleSize() : m_width(0), m_height(0) { }
19 DoubleSize(double width, double height) : m_width(width), m_height(height) { }
20 DoubleSize(const IntSize& p) : m_width(p.width()), m_height(p.height()) { }
21 DoubleSize(const FloatSize& s) : m_width(s.width()), m_height(s.height()) { }
22 explicit DoubleSize(const LayoutSize&);
24 double width() const { return m_width; }
25 double height() const { return m_height; }
27 void setWidth(double width) { m_width = width; }
28 void setHeight(double height) { m_height = height; }
30 bool isEmpty() const { return m_width <= 0 || m_height <= 0; }
32 bool isZero() const;
34 void expand(float width, float height)
36 m_width += width;
37 m_height += height;
40 void scale(float widthScale, float heightScale)
42 m_width = m_width * widthScale;
43 m_height = m_height * heightScale;
46 void scale(float scale)
48 this->scale(scale, scale);
51 private:
52 double m_width, m_height;
55 inline DoubleSize& operator+=(DoubleSize& a, const DoubleSize& b)
57 a.setWidth(a.width() + b.width());
58 a.setHeight(a.height() + b.height());
59 return a;
62 inline DoubleSize& operator-=(DoubleSize& a, const DoubleSize& b)
64 a.setWidth(a.width() - b.width());
65 a.setHeight(a.height() - b.height());
66 return a;
69 inline DoubleSize operator+(const DoubleSize& a, const DoubleSize& b)
71 return DoubleSize(a.width() + b.width(), a.height() + b.height());
74 inline DoubleSize operator-(const DoubleSize& a, const DoubleSize& b)
76 return DoubleSize(a.width() - b.width(), a.height() - b.height());
79 inline bool operator==(const DoubleSize& a, const DoubleSize& b)
81 return a.width() == b.width() && a.height() == b.height();
84 inline bool operator!=(const DoubleSize& a, const DoubleSize& b)
86 return a.width() != b.width() || a.height() != b.height();
89 inline IntSize flooredIntSize(const DoubleSize& p)
91 return IntSize(clampTo<int>(floor(p.width())), clampTo<int>(floor(p.height())));
94 inline IntSize roundedIntSize(const DoubleSize& p)
96 return IntSize(clampTo<int>(roundf(p.width())), clampTo<int>(roundf(p.height())));
99 inline IntSize expandedIntSize(const DoubleSize& p)
101 return IntSize(clampTo<int>(ceilf(p.width())), clampTo<int>(ceilf(p.height())));
104 inline FloatSize toFloatSize(const DoubleSize& p)
106 return FloatSize(p.width(), p.height());
109 } // namespace blink
111 #endif // DoubleSize_h