OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013, Opera Software ASA. All rights reserved. | 2 * Copyright (c) 2013, Opera Software ASA. 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 24 matching lines...) Expand all Loading... |
35 | 35 |
36 namespace WebCore { | 36 namespace WebCore { |
37 | 37 |
38 // Represents an individual computed border image width or outset. | 38 // Represents an individual computed border image width or outset. |
39 // | 39 // |
40 // http://www.w3.org/TR/css3-background/#border-image-width | 40 // http://www.w3.org/TR/css3-background/#border-image-width |
41 // http://www.w3.org/TR/css3-background/#border-image-outset | 41 // http://www.w3.org/TR/css3-background/#border-image-outset |
42 class BorderImageLength { | 42 class BorderImageLength { |
43 public: | 43 public: |
44 BorderImageLength() | 44 BorderImageLength() |
| 45 : m_length(Auto) |
| 46 , m_number(0) |
| 47 , m_type(LengthType) |
45 { | 48 { |
46 } | 49 } |
47 | 50 |
48 BorderImageLength(double number) | 51 BorderImageLength(double number) |
49 : m_length(number, Relative) | 52 : m_length(Undefined) |
| 53 , m_number(number) |
| 54 , m_type(NumberType) |
50 { | 55 { |
51 } | 56 } |
52 | 57 |
53 BorderImageLength(const Length& length) | 58 BorderImageLength(const Length& length) |
54 : m_length(length) | 59 : m_length(length) |
| 60 , m_number(0) |
| 61 , m_type(LengthType) |
55 { | 62 { |
56 } | 63 } |
57 | 64 |
58 bool isNumber() const { return m_length.isRelative(); } | 65 bool isNumber() const { return m_type == NumberType; } |
59 bool isLength() const { return !isNumber(); } | 66 bool isLength() const { return m_type == LengthType; } |
60 | 67 |
61 const Length& length() const { ASSERT(isLength()); return m_length; } | 68 const Length& length() const { ASSERT(isLength()); return m_length; } |
62 Length& length() { ASSERT(isLength()); return m_length; } | 69 Length& length() { ASSERT(isLength()); return m_length; } |
63 | 70 |
64 double number() const { ASSERT(isNumber()); return m_length.value(); } | 71 double number() const { ASSERT(isNumber()); return m_number; } |
65 | 72 |
66 bool operator==(const BorderImageLength& other) const | 73 bool operator==(const BorderImageLength& other) const |
67 { | 74 { |
68 return m_length == other.m_length; | 75 return m_type == other.m_type && m_length == other.m_length && m_number
== other.m_number; |
69 } | 76 } |
70 | 77 |
71 bool isZero() const | 78 bool isZero() const |
72 { | 79 { |
73 return m_length.isZero(); | 80 return (isLength() && m_length.isZero()) || (isNumber() && m_number); |
74 } | 81 } |
75 | 82 |
76 private: | 83 private: |
| 84 // Ideally we would put the 2 following fields in a union, but Length has a
constructor, |
| 85 // a destructor and a copy assignment which isn't allowed. |
77 Length m_length; | 86 Length m_length; |
| 87 double m_number; |
| 88 enum { |
| 89 LengthType, |
| 90 NumberType |
| 91 } m_type; |
78 }; | 92 }; |
79 | 93 |
80 } // namespace WebCore | 94 } // namespace WebCore |
81 | 95 |
82 #endif // BorderImageLength_h | 96 #endif // BorderImageLength_h |
OLD | NEW |