OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999-2003 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999-2003 Lars Knoll (knoll@kde.org) |
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
4 * | 4 * |
5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 * Library General Public License for more details. | 13 * Library General Public License for more details. |
14 * | 14 * |
15 * You should have received a copy of the GNU Library General Public License | 15 * You should have received a copy of the GNU Library General Public License |
16 * along with this library; see the file COPYING.LIB. If not, write to | 16 * along with this library; see the file COPYING.LIB. If not, write to |
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 * Boston, MA 02110-1301, USA. | 18 * Boston, MA 02110-1301, USA. |
19 */ | 19 */ |
20 | 20 |
21 #ifndef Rect_h | 21 #ifndef Rect_h |
22 #define Rect_h | 22 #define Rect_h |
23 | 23 |
24 #include "core/CoreExport.h" | 24 #include "core/CoreExport.h" |
25 #include "core/css/CSSPrimitiveValue.h" | 25 #include "core/css/CSSValue.h" |
26 #include "wtf/RefPtr.h" | 26 #include "wtf/RefPtr.h" |
27 #include "wtf/text/StringBuilder.h" | 27 #include "wtf/text/StringBuilder.h" |
28 | 28 |
29 namespace blink { | 29 namespace blink { |
30 | 30 |
31 class CORE_EXPORT RectBase : public RefCountedWillBeGarbageCollected<RectBase> { | 31 class CORE_EXPORT RectBase : public RefCountedWillBeGarbageCollectedFinalized<Re
ctBase> { |
32 DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(RectBase); | 32 DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(RectBase); |
33 public: | 33 public: |
34 CSSPrimitiveValue* top() const { return m_top.get(); } | 34 CSSPrimitiveValue top() const { return toCSSPrimitiveValue(*m_top); } |
35 CSSPrimitiveValue* right() const { return m_right.get(); } | 35 CSSPrimitiveValue right() const { return toCSSPrimitiveValue(*m_right); } |
36 CSSPrimitiveValue* bottom() const { return m_bottom.get(); } | 36 CSSPrimitiveValue bottom() const { return toCSSPrimitiveValue(*m_bottom); } |
37 CSSPrimitiveValue* left() const { return m_left.get(); } | 37 CSSPrimitiveValue left() const { return toCSSPrimitiveValue(*m_left); } |
38 | 38 |
39 void setTop(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> top) { m_top = top; } | 39 void setTop(CSSPrimitiveValue top) { m_top = top; } |
40 void setRight(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> right) { m_right = r
ight; } | 40 void setRight(CSSPrimitiveValue right) { m_right = right; } |
41 void setBottom(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> bottom) { m_bottom
= bottom; } | 41 void setBottom(CSSPrimitiveValue bottom) { m_bottom = bottom; } |
42 void setLeft(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> left) { m_left = left
; } | 42 void setLeft(CSSPrimitiveValue left) { m_left = left; } |
43 | 43 |
44 bool equals(const RectBase& other) const | 44 bool equals(const RectBase& other) const |
45 { | 45 { |
46 return compareCSSValuePtr(m_top, other.m_top) | 46 return m_top == other.m_top |
47 && compareCSSValuePtr(m_right, other.m_right) | 47 && m_right == other.m_right |
48 && compareCSSValuePtr(m_left, other.m_left) | 48 && m_left == other.m_left |
49 && compareCSSValuePtr(m_bottom, other.m_bottom); | 49 && m_bottom == other.m_bottom; |
50 } | 50 } |
51 | 51 |
52 DECLARE_TRACE(); | 52 DECLARE_TRACE(); |
53 | 53 |
54 protected: | 54 protected: |
55 RectBase() { } | 55 RectBase() { } |
56 | 56 |
57 private: | 57 private: |
58 RefPtrWillBeMember<CSSPrimitiveValue> m_top; | 58 NullableCSSValue m_top; |
59 RefPtrWillBeMember<CSSPrimitiveValue> m_right; | 59 NullableCSSValue m_right; |
60 RefPtrWillBeMember<CSSPrimitiveValue> m_bottom; | 60 NullableCSSValue m_bottom; |
61 RefPtrWillBeMember<CSSPrimitiveValue> m_left; | 61 NullableCSSValue m_left; |
62 }; | 62 }; |
63 | 63 |
64 class Rect : public RectBase { | 64 class Rect : public RectBase { |
65 public: | 65 public: |
66 static PassRefPtrWillBeRawPtr<Rect> create() { return adoptRefWillBeNoop(new
Rect); } | 66 static PassRefPtrWillBeRawPtr<Rect> create() { return adoptRefWillBeNoop(new
Rect); } |
67 | 67 |
68 String cssText() const | 68 String cssText() const |
69 { | 69 { |
70 return generateCSSString(top()->cssText(), right()->cssText(), bottom()-
>cssText(), left()->cssText()); | 70 return generateCSSString(top().cssText(), right().cssText(), bottom().cs
sText(), left().cssText()); |
71 } | 71 } |
72 | 72 |
73 private: | 73 private: |
74 Rect() { } | 74 Rect() { } |
75 static String generateCSSString(const String& top, const String& right, cons
t String& bottom, const String& left) | 75 static String generateCSSString(const String& top, const String& right, cons
t String& bottom, const String& left) |
76 { | 76 { |
77 return "rect(" + top + ' ' + right + ' ' + bottom + ' ' + left + ')'; | 77 return "rect(" + top + ' ' + right + ' ' + bottom + ' ' + left + ')'; |
78 } | 78 } |
79 | 79 |
80 // NOTE: If adding fields to this class please make the RectBase trace | 80 // NOTE: If adding fields to this class please make the RectBase trace |
81 // method virtual and add a trace method in this subclass tracing the new | 81 // method virtual and add a trace method in this subclass tracing the new |
82 // fields. | 82 // fields. |
83 }; | 83 }; |
84 | 84 |
85 class Quad : public RectBase { | 85 class Quad : public RectBase { |
86 public: | 86 public: |
87 static PassRefPtrWillBeRawPtr<Quad> create() { return adoptRefWillBeNoop(new
Quad); } | 87 static PassRefPtrWillBeRawPtr<Quad> create() { return adoptRefWillBeNoop(new
Quad); } |
88 | 88 |
89 String cssText() const | 89 String cssText() const |
90 { | 90 { |
91 return generateCSSString(top()->cssText(), right()->cssText(), bottom()-
>cssText(), left()->cssText()); | 91 return generateCSSString(top().cssText(), right().cssText(), bottom().cs
sText(), left().cssText()); |
92 } | 92 } |
93 | 93 |
94 private: | 94 private: |
95 Quad() { } | 95 Quad() { } |
96 static String generateCSSString(const String& top, const String& right, cons
t String& bottom, const String& left) | 96 static String generateCSSString(const String& top, const String& right, cons
t String& bottom, const String& left) |
97 { | 97 { |
98 StringBuilder result; | 98 StringBuilder result; |
99 // reserve space for the four strings, plus three space separator charac
ters. | 99 // reserve space for the four strings, plus three space separator charac
ters. |
100 result.reserveCapacity(top.length() + right.length() + bottom.length() +
left.length() + 3); | 100 result.reserveCapacity(top.length() + right.length() + bottom.length() +
left.length() + 3); |
101 result.append(top); | 101 result.append(top); |
(...skipping 13 matching lines...) Expand all Loading... |
115 } | 115 } |
116 | 116 |
117 // NOTE: If adding fields to this class please make the RectBase trace | 117 // NOTE: If adding fields to this class please make the RectBase trace |
118 // method virtual and add a trace method in this subclass tracing the new | 118 // method virtual and add a trace method in this subclass tracing the new |
119 // fields. | 119 // fields. |
120 }; | 120 }; |
121 | 121 |
122 } // namespace blink | 122 } // namespace blink |
123 | 123 |
124 #endif // Rect_h | 124 #endif // Rect_h |
OLD | NEW |