| 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 "bindings/core/v8/ScriptWrappable.h" | |
| 25 #include "core/css/CSSPrimitiveValue.h" | 24 #include "core/css/CSSPrimitiveValue.h" |
| 26 #include "wtf/RefPtr.h" | 25 #include "wtf/RefPtr.h" |
| 27 #include "wtf/text/StringBuilder.h" | 26 #include "wtf/text/StringBuilder.h" |
| 28 | 27 |
| 29 namespace blink { | 28 namespace blink { |
| 30 | 29 |
| 31 class RectBase : public RefCountedWillBeGarbageCollected<RectBase>, public Scrip
tWrappableBase { | 30 class RectBase : public RefCountedWillBeGarbageCollected<RectBase> { |
| 32 DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(RectBase); | 31 DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(RectBase); |
| 33 public: | 32 public: |
| 34 CSSPrimitiveValue* top() const { return m_top.get(); } | 33 CSSPrimitiveValue* top() const { return m_top.get(); } |
| 35 CSSPrimitiveValue* right() const { return m_right.get(); } | 34 CSSPrimitiveValue* right() const { return m_right.get(); } |
| 36 CSSPrimitiveValue* bottom() const { return m_bottom.get(); } | 35 CSSPrimitiveValue* bottom() const { return m_bottom.get(); } |
| 37 CSSPrimitiveValue* left() const { return m_left.get(); } | 36 CSSPrimitiveValue* left() const { return m_left.get(); } |
| 38 | 37 |
| 39 void setTop(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> top) { m_top = top; } | 38 void setTop(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> top) { m_top = top; } |
| 40 void setRight(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> right) { m_right = r
ight; } | 39 void setRight(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> right) { m_right = r
ight; } |
| 41 void setBottom(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> bottom) { m_bottom
= bottom; } | 40 void setBottom(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> bottom) { m_bottom
= bottom; } |
| 42 void setLeft(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> left) { m_left = left
; } | 41 void setLeft(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> left) { m_left = left
; } |
| 43 | 42 |
| 44 bool equals(const RectBase& other) const | 43 bool equals(const RectBase& other) const |
| 45 { | 44 { |
| 46 return compareCSSValuePtr(m_top, other.m_top) | 45 return compareCSSValuePtr(m_top, other.m_top) |
| 47 && compareCSSValuePtr(m_right, other.m_right) | 46 && compareCSSValuePtr(m_right, other.m_right) |
| 48 && compareCSSValuePtr(m_left, other.m_left) | 47 && compareCSSValuePtr(m_left, other.m_left) |
| 49 && compareCSSValuePtr(m_bottom, other.m_bottom); | 48 && compareCSSValuePtr(m_bottom, other.m_bottom); |
| 50 } | 49 } |
| 51 | 50 |
| 52 void trace(Visitor*); | 51 void trace(Visitor*); |
| 53 | 52 |
| 54 protected: | 53 protected: |
| 55 RectBase() { } | 54 RectBase() { } |
| 56 RectBase(const RectBase& cloneFrom) | |
| 57 : m_top(cloneFrom.m_top ? cloneFrom.m_top->cloneForCSSOM() : nullptr) | |
| 58 , m_right(cloneFrom.m_right ? cloneFrom.m_right->cloneForCSSOM() : nullp
tr) | |
| 59 , m_bottom(cloneFrom.m_bottom ? cloneFrom.m_bottom->cloneForCSSOM() : nu
llptr) | |
| 60 , m_left(cloneFrom.m_left ? cloneFrom.m_left->cloneForCSSOM() : nullptr) | |
| 61 { | |
| 62 } | |
| 63 | 55 |
| 64 private: | 56 private: |
| 65 RefPtrWillBeMember<CSSPrimitiveValue> m_top; | 57 RefPtrWillBeMember<CSSPrimitiveValue> m_top; |
| 66 RefPtrWillBeMember<CSSPrimitiveValue> m_right; | 58 RefPtrWillBeMember<CSSPrimitiveValue> m_right; |
| 67 RefPtrWillBeMember<CSSPrimitiveValue> m_bottom; | 59 RefPtrWillBeMember<CSSPrimitiveValue> m_bottom; |
| 68 RefPtrWillBeMember<CSSPrimitiveValue> m_left; | 60 RefPtrWillBeMember<CSSPrimitiveValue> m_left; |
| 69 }; | 61 }; |
| 70 | 62 |
| 71 class Rect : public RectBase { | 63 class Rect : public RectBase { |
| 72 public: | 64 public: |
| 73 static PassRefPtrWillBeRawPtr<Rect> create() { return adoptRefWillBeNoop(new
Rect); } | 65 static PassRefPtrWillBeRawPtr<Rect> create() { return adoptRefWillBeNoop(new
Rect); } |
| 74 | 66 |
| 75 PassRefPtrWillBeRawPtr<Rect> cloneForCSSOM() const { return adoptRefWillBeNo
op(new Rect(*this)); } | |
| 76 | |
| 77 String cssText() const | 67 String cssText() const |
| 78 { | 68 { |
| 79 return generateCSSString(top()->cssText(), right()->cssText(), bottom()-
>cssText(), left()->cssText()); | 69 return generateCSSString(top()->cssText(), right()->cssText(), bottom()-
>cssText(), left()->cssText()); |
| 80 } | 70 } |
| 81 | 71 |
| 82 private: | 72 private: |
| 83 Rect() { } | 73 Rect() { } |
| 84 Rect(const Rect& cloneFrom) : RectBase(cloneFrom) { } | |
| 85 static String generateCSSString(const String& top, const String& right, cons
t String& bottom, const String& left) | 74 static String generateCSSString(const String& top, const String& right, cons
t String& bottom, const String& left) |
| 86 { | 75 { |
| 87 return "rect(" + top + ' ' + right + ' ' + bottom + ' ' + left + ')'; | 76 return "rect(" + top + ' ' + right + ' ' + bottom + ' ' + left + ')'; |
| 88 } | 77 } |
| 89 | 78 |
| 90 // NOTE: If adding fields to this class please make the RectBase trace | 79 // NOTE: If adding fields to this class please make the RectBase trace |
| 91 // method virtual and add a trace method in this subclass tracing the new | 80 // method virtual and add a trace method in this subclass tracing the new |
| 92 // fields. | 81 // fields. |
| 93 }; | 82 }; |
| 94 | 83 |
| 95 class Quad : public RectBase { | 84 class Quad : public RectBase { |
| 96 public: | 85 public: |
| 97 static PassRefPtrWillBeRawPtr<Quad> create() { return adoptRefWillBeNoop(new
Quad); } | 86 static PassRefPtrWillBeRawPtr<Quad> create() { return adoptRefWillBeNoop(new
Quad); } |
| 98 | 87 |
| 99 PassRefPtrWillBeRawPtr<Quad> cloneForCSSOM() const { return adoptRefWillBeNo
op(new Quad(*this)); } | |
| 100 | |
| 101 String cssText() const | 88 String cssText() const |
| 102 { | 89 { |
| 103 return generateCSSString(top()->cssText(), right()->cssText(), bottom()-
>cssText(), left()->cssText()); | 90 return generateCSSString(top()->cssText(), right()->cssText(), bottom()-
>cssText(), left()->cssText()); |
| 104 } | 91 } |
| 105 | 92 |
| 106 private: | 93 private: |
| 107 Quad() { } | 94 Quad() { } |
| 108 Quad(const Quad& cloneFrom) : RectBase(cloneFrom) { } | |
| 109 static String generateCSSString(const String& top, const String& right, cons
t String& bottom, const String& left) | 95 static String generateCSSString(const String& top, const String& right, cons
t String& bottom, const String& left) |
| 110 { | 96 { |
| 111 StringBuilder result; | 97 StringBuilder result; |
| 112 // reserve space for the four strings, plus three space separator charac
ters. | 98 // reserve space for the four strings, plus three space separator charac
ters. |
| 113 result.reserveCapacity(top.length() + right.length() + bottom.length() +
left.length() + 3); | 99 result.reserveCapacity(top.length() + right.length() + bottom.length() +
left.length() + 3); |
| 114 result.append(top); | 100 result.append(top); |
| 115 if (right != top || bottom != top || left != top) { | 101 if (right != top || bottom != top || left != top) { |
| 116 result.append(' '); | 102 result.append(' '); |
| 117 result.append(right); | 103 result.append(right); |
| 118 if (bottom != top || right != left) { | 104 if (bottom != top || right != left) { |
| 119 result.append(' '); | 105 result.append(' '); |
| 120 result.append(bottom); | 106 result.append(bottom); |
| 121 if (left != right) { | 107 if (left != right) { |
| 122 result.append(' '); | 108 result.append(' '); |
| 123 result.append(left); | 109 result.append(left); |
| 124 } | 110 } |
| 125 } | 111 } |
| 126 } | 112 } |
| 127 return result.toString(); | 113 return result.toString(); |
| 128 } | 114 } |
| 129 | 115 |
| 130 // NOTE: If adding fields to this class please make the RectBase trace | 116 // NOTE: If adding fields to this class please make the RectBase trace |
| 131 // method virtual and add a trace method in this subclass tracing the new | 117 // method virtual and add a trace method in this subclass tracing the new |
| 132 // fields. | 118 // fields. |
| 133 }; | 119 }; |
| 134 | 120 |
| 135 } // namespace blink | 121 } // namespace blink |
| 136 | 122 |
| 137 #endif // Rect_h | 123 #endif // Rect_h |
| OLD | NEW |