Chromium Code Reviews| 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/CSSPrimitiveValue.h" |
| 26 #include "core/css/CSSValue.h" | |
| 26 #include "wtf/RefPtr.h" | 27 #include "wtf/RefPtr.h" |
| 27 #include "wtf/text/StringBuilder.h" | 28 #include "wtf/text/StringBuilder.h" |
| 28 | 29 |
| 29 namespace blink { | 30 namespace blink { |
| 30 | 31 |
| 31 class CORE_EXPORT RectBase : public RefCountedWillBeGarbageCollected<RectBase> { | 32 // TODO rename to CSSQuadValue. |
| 32 DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(RectBase); | 33 class CORE_EXPORT CSSQuadValue : public CSSValue { |
|
esprehn
2015/08/21 09:57:15
copy pasta error?
sashab
2015/08/24 01:56:59
Oops, thanks :) This file should be removed.
| |
| 33 public: | 34 public: |
| 35 static PassRefPtrWillBeRawPtr<CSSQuadValue> createQuad(PassRefPtrWillBeRawPt r<CSSPrimitiveValue> top, PassRefPtrWillBeRawPtr<CSSPrimitiveValue> right, PassR efPtrWillBeRawPtr<CSSPrimitiveValue> bottom, PassRefPtrWillBeRawPtr<CSSPrimitive Value> left) | |
| 36 { | |
| 37 return adoptRefWillBeNoop(new CSSQuadValue(top, right, bottom, left, fal se)); | |
| 38 } | |
| 39 | |
| 40 static PassRefPtrWillBeRawPtr<CSSQuadValue> createRect(PassRefPtrWillBeRawPt r<CSSPrimitiveValue> top, PassRefPtrWillBeRawPtr<CSSPrimitiveValue> right, PassR efPtrWillBeRawPtr<CSSPrimitiveValue> bottom, PassRefPtrWillBeRawPtr<CSSPrimitive Value> left) | |
| 41 { | |
| 42 return adoptRefWillBeNoop(new CSSQuadValue(top, right, bottom, left, tru e)); | |
| 43 } | |
| 44 | |
| 34 CSSPrimitiveValue* top() const { return m_top.get(); } | 45 CSSPrimitiveValue* top() const { return m_top.get(); } |
| 35 CSSPrimitiveValue* right() const { return m_right.get(); } | 46 CSSPrimitiveValue* right() const { return m_right.get(); } |
| 36 CSSPrimitiveValue* bottom() const { return m_bottom.get(); } | 47 CSSPrimitiveValue* bottom() const { return m_bottom.get(); } |
| 37 CSSPrimitiveValue* left() const { return m_left.get(); } | 48 CSSPrimitiveValue* left() const { return m_left.get(); } |
| 38 | 49 |
| 39 void setTop(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> top) { m_top = top; } | 50 void setTop(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> top) { m_top = top; } |
| 40 void setRight(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> right) { m_right = r ight; } | 51 void setRight(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> right) { m_right = r ight; } |
| 41 void setBottom(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> bottom) { m_bottom = bottom; } | 52 void setBottom(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> bottom) { m_bottom = bottom; } |
| 42 void setLeft(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> left) { m_left = left ; } | 53 void setLeft(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> left) { m_left = left ; } |
| 43 | 54 |
| 44 bool equals(const RectBase& other) const | 55 String customCSSText() const |
| 56 { | |
| 57 if (m_serializeAsRect) | |
| 58 return "rect(" + top()->cssText() + ' ' + right()->cssText() + ' ' + bottom()->cssText() + ' ' + left()->cssText() + ')'; | |
| 59 | |
| 60 StringBuilder result; | |
| 61 // reserve space for the four strings, plus three space separator charac ters. | |
| 62 result.reserveCapacity(top().length() + right().length() + bottom().leng th() + left().length() + 3); | |
| 63 result.append(top()); | |
| 64 if (right() != top() || bottom() != top() || left() != top()) { | |
| 65 result.append(' '); | |
| 66 result.append(right()); | |
| 67 if (bottom() != top() || right() != left()) { | |
| 68 result.append(' '); | |
| 69 result.append(bottom()); | |
| 70 if (left() != right()) { | |
| 71 result.append(' '); | |
| 72 result.append(left()); | |
| 73 } | |
| 74 } | |
| 75 } | |
| 76 return result.toString(); | |
| 77 } | |
| 78 | |
| 79 bool equals(const CSSQuadValue& other) const | |
| 45 { | 80 { |
| 46 return compareCSSValuePtr(m_top, other.m_top) | 81 return compareCSSValuePtr(m_top, other.m_top) |
| 47 && compareCSSValuePtr(m_right, other.m_right) | 82 && compareCSSValuePtr(m_right, other.m_right) |
| 48 && compareCSSValuePtr(m_left, other.m_left) | 83 && compareCSSValuePtr(m_left, other.m_left) |
| 49 && compareCSSValuePtr(m_bottom, other.m_bottom); | 84 && compareCSSValuePtr(m_bottom, other.m_bottom); |
| 50 } | 85 } |
| 51 | 86 |
| 52 DECLARE_TRACE(); | 87 DECLARE_TRACE(); |
| 53 | 88 |
| 54 protected: | 89 protected: |
| 55 RectBase() { } | 90 CSSQuadValue(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> top, PassRefPtrWillBe RawPtr<CSSPrimitiveValue> right, PassRefPtrWillBeRawPtr<CSSPrimitiveValue> botto m, PassRefPtrWillBeRawPtr<CSSPrimitiveValue> left, bool serializeAsRect) |
| 91 : CSSValue(QuadClass) | |
| 92 , m_serializeAsRect(serializeAsRect) | |
| 93 , m_top(top) | |
| 94 , m_right(right) | |
| 95 , m_bottom(bottom) | |
| 96 , m_left(left) { } | |
| 56 | 97 |
| 57 private: | 98 private: |
| 99 bool m_serializeAsRect; | |
| 100 | |
| 101 static String generateCSSString(const String& top, const String& right, cons t String& bottom, const String& left) | |
| 102 { | |
| 103 | |
| 104 } | |
| 105 | |
| 58 RefPtrWillBeMember<CSSPrimitiveValue> m_top; | 106 RefPtrWillBeMember<CSSPrimitiveValue> m_top; |
| 59 RefPtrWillBeMember<CSSPrimitiveValue> m_right; | 107 RefPtrWillBeMember<CSSPrimitiveValue> m_right; |
| 60 RefPtrWillBeMember<CSSPrimitiveValue> m_bottom; | 108 RefPtrWillBeMember<CSSPrimitiveValue> m_bottom; |
| 61 RefPtrWillBeMember<CSSPrimitiveValue> m_left; | 109 RefPtrWillBeMember<CSSPrimitiveValue> m_left; |
| 62 }; | 110 }; |
| 63 | 111 |
| 64 class Rect : public RectBase { | 112 class Rect : public RectBase { |
| 65 public: | 113 public: |
| 66 static PassRefPtrWillBeRawPtr<Rect> create() { return adoptRefWillBeNoop(new Rect); } | 114 static PassRefPtrWillBeRawPtr<Rect> create() { return adoptRefWillBeNoop(new Rect); } |
| 67 | 115 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 81 // method virtual and add a trace method in this subclass tracing the new | 129 // method virtual and add a trace method in this subclass tracing the new |
| 82 // fields. | 130 // fields. |
| 83 }; | 131 }; |
| 84 | 132 |
| 85 class Quad : public RectBase { | 133 class Quad : public RectBase { |
| 86 public: | 134 public: |
| 87 static PassRefPtrWillBeRawPtr<Quad> create() { return adoptRefWillBeNoop(new Quad); } | 135 static PassRefPtrWillBeRawPtr<Quad> create() { return adoptRefWillBeNoop(new Quad); } |
| 88 | 136 |
| 89 String cssText() const | 137 String cssText() const |
| 90 { | 138 { |
| 91 return generateCSSString(top()->cssText(), right()->cssText(), bottom()- >cssText(), left()->cssText()); | 139 |
| 92 } | 140 } |
| 93 | 141 |
| 94 private: | 142 private: |
| 95 Quad() { } | 143 Quad() { } |
| 96 static String generateCSSString(const String& top, const String& right, cons t String& bottom, const String& left) | 144 |
| 97 { | |
| 98 StringBuilder result; | |
| 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); | |
| 101 result.append(top); | |
| 102 if (right != top || bottom != top || left != top) { | |
| 103 result.append(' '); | |
| 104 result.append(right); | |
| 105 if (bottom != top || right != left) { | |
| 106 result.append(' '); | |
| 107 result.append(bottom); | |
| 108 if (left != right) { | |
| 109 result.append(' '); | |
| 110 result.append(left); | |
| 111 } | |
| 112 } | |
| 113 } | |
| 114 return result.toString(); | |
| 115 } | |
| 116 | 145 |
| 117 // NOTE: If adding fields to this class please make the RectBase trace | 146 // 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 | 147 // method virtual and add a trace method in this subclass tracing the new |
| 119 // fields. | 148 // fields. |
| 120 }; | 149 }; |
| 121 | 150 |
| 122 } // namespace blink | 151 } // namespace blink |
| 123 | 152 |
| 124 #endif // Rect_h | 153 #endif // Rect_h |
| OLD | NEW |