Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(704)

Side by Side Diff: Source/core/rendering/style/BasicShapes.cpp

Issue 98723006: Parse new circle shape syntax (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase after 164114 Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. 2 * Copyright (C) 2012 Adobe Systems Incorporated. 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above 8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following 9 * copyright notice, this list of conditions and the following
10 * disclaimer. 10 * disclaimer.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 } 83 }
84 84
85 bool BasicShapeRectangle::operator==(const BasicShape& o) const 85 bool BasicShapeRectangle::operator==(const BasicShape& o) const
86 { 86 {
87 if (!isSameType(o)) 87 if (!isSameType(o))
88 return false; 88 return false;
89 const BasicShapeRectangle& other = toBasicShapeRectangle(o); 89 const BasicShapeRectangle& other = toBasicShapeRectangle(o);
90 return m_y == other.m_y && m_x == other.m_x && m_width == other.m_width && m _height == other.m_height && m_cornerRadiusX == other.m_cornerRadiusX && m_corne rRadiusY == other.m_cornerRadiusY; 90 return m_y == other.m_y && m_x == other.m_x && m_width == other.m_width && m _height == other.m_height && m_cornerRadiusX == other.m_cornerRadiusX && m_corne rRadiusY == other.m_cornerRadiusY;
91 } 91 }
92 92
93 void BasicShapeCircle::path(Path& path, const FloatRect& boundingBox) 93 bool DeprecatedBasicShapeCircle::operator==(const BasicShape& o) const
94 {
95 if (!isSameType(o))
96 return false;
97 const DeprecatedBasicShapeCircle& other = toDeprecatedBasicShapeCircle(o);
98 return m_centerX == other.m_centerX && m_centerY == other.m_centerY && m_rad ius == other.m_radius;
99 }
100
101 void DeprecatedBasicShapeCircle::path(Path& path, const FloatRect& boundingBox)
94 { 102 {
95 ASSERT(path.isEmpty()); 103 ASSERT(path.isEmpty());
96 float diagonal = sqrtf((boundingBox.width() * boundingBox.width() + bounding Box.height() * boundingBox.height()) / 2); 104 float diagonal = sqrtf((boundingBox.width() * boundingBox.width() + bounding Box.height() * boundingBox.height()) / 2);
97 float centerX = floatValueForLength(m_centerX, boundingBox.width()); 105 float centerX = floatValueForLength(m_centerX, boundingBox.width());
98 float centerY = floatValueForLength(m_centerY, boundingBox.height()); 106 float centerY = floatValueForLength(m_centerY, boundingBox.height());
99 float radius = floatValueForLength(m_radius, diagonal); 107 float radius = floatValueForLength(m_radius, diagonal);
100 path.addEllipse(FloatRect( 108 path.addEllipse(FloatRect(
101 centerX - radius + boundingBox.x(), 109 centerX - radius + boundingBox.x(),
102 centerY - radius + boundingBox.y(), 110 centerY - radius + boundingBox.y(),
103 radius * 2, 111 radius * 2,
104 radius * 2 112 radius * 2
105 )); 113 ));
106 } 114 }
107 115
108 PassRefPtr<BasicShape> BasicShapeCircle::blend(const BasicShape* other, double p rogress) const 116 PassRefPtr<BasicShape> DeprecatedBasicShapeCircle::blend(const BasicShape* other , double progress) const
109 { 117 {
110 ASSERT(other && isSameType(*other)); 118 ASSERT(other && isSameType(*other));
111 119
112 const BasicShapeCircle* o = static_cast<const BasicShapeCircle*>(other); 120 const DeprecatedBasicShapeCircle* o = static_cast<const DeprecatedBasicShape Circle*>(other);
113 RefPtr<BasicShapeCircle> result = BasicShapeCircle::create(); 121 RefPtr<DeprecatedBasicShapeCircle> result = DeprecatedBasicShapeCircle::cre ate();
114 result->setCenterX(m_centerX.blend(o->centerX(), progress, ValueRangeAll)); 122 result->setCenterX(m_centerX.blend(o->centerX(), progress, ValueRangeAll));
115 result->setCenterY(m_centerY.blend(o->centerY(), progress, ValueRangeAll)); 123 result->setCenterY(m_centerY.blend(o->centerY(), progress, ValueRangeAll));
116 result->setRadius(m_radius.blend(o->radius(), progress, ValueRangeNonNegativ e)); 124 result->setRadius(m_radius.blend(o->radius(), progress, ValueRangeNonNegativ e));
117 return result.release(); 125 return result.release();
118 } 126 }
119 127
120 bool BasicShapeCircle::operator==(const BasicShape& o) const 128 bool BasicShapeCircle::operator==(const BasicShape& o) const
121 { 129 {
122 if (!isSameType(o)) 130 if (!isSameType(o))
123 return false; 131 return false;
124 const BasicShapeCircle& other = toBasicShapeCircle(o); 132 const BasicShapeCircle& other = toBasicShapeCircle(o);
125 return m_centerX == other.m_centerX && m_centerY == other.m_centerY && m_rad ius == other.m_radius; 133 return m_centerX == other.m_centerX && m_centerY == other.m_centerY && m_rad ius == other.m_radius;
126 } 134 }
127 135
136 void BasicShapeCircle::path(Path& path, const FloatRect& boundingBox)
137 {
138 ASSERT(path.isEmpty());
139 // FIXME Complete implementation of path.
140 // Compute closest-side and farthest-side from boundingBox.
141 // Compute top, left, bottom, right from boundingBox.
142 if (m_radius.type() != BasicShapeRadius::Value)
143 return;
144 if (m_centerX.keyword() != BasicShapeCenterCoordinate::None || m_centerY.key word() != BasicShapeCenterCoordinate::None)
145 return;
146
147 float diagonal = sqrtf((boundingBox.width() * boundingBox.width() + bounding Box.height() * boundingBox.height()) / 2);
148 float centerX = floatValueForLength(m_centerX.length(), boundingBox.width()) ;
149 float centerY = floatValueForLength(m_centerY.length(), boundingBox.height() );
150 float radius = floatValueForLength(m_radius.value(), diagonal);
151 path.addEllipse(FloatRect(
152 centerX - radius + boundingBox.x(),
153 centerY - radius + boundingBox.y(),
154 radius * 2,
155 radius * 2
156 ));
157 }
158
159 PassRefPtr<BasicShape> BasicShapeCircle::blend(const BasicShape* other, double p rogress) const
160 {
161 ASSERT(type() == other->type());
162 const BasicShapeCircle* o = static_cast<const BasicShapeCircle*>(other);
163 RefPtr<BasicShapeCircle> result = BasicShapeCircle::create();
164
165 if (m_radius.type() != BasicShapeRadius::Value || o->radius().type() != Basi cShapeRadius::Value) {
166 result->setCenterX(o->centerX());
167 result->setCenterY(o->centerY());
168 result->setRadius(o->radius());
169 return result;
170 }
171
172 result->setCenterX(m_centerX.blend(o->centerX(), progress));
173 result->setCenterY(m_centerY.blend(o->centerY(), progress));
174 result->setRadius(m_radius.blend(o->radius(), progress));
175 return result.release();
176 }
177
128 void BasicShapeEllipse::path(Path& path, const FloatRect& boundingBox) 178 void BasicShapeEllipse::path(Path& path, const FloatRect& boundingBox)
129 { 179 {
130 ASSERT(path.isEmpty()); 180 ASSERT(path.isEmpty());
131 float centerX = floatValueForLength(m_centerX, boundingBox.width()); 181 float centerX = floatValueForLength(m_centerX, boundingBox.width());
132 float centerY = floatValueForLength(m_centerY, boundingBox.height()); 182 float centerY = floatValueForLength(m_centerY, boundingBox.height());
133 float radiusX = floatValueForLength(m_radiusX, boundingBox.width()); 183 float radiusX = floatValueForLength(m_radiusX, boundingBox.width());
134 float radiusY = floatValueForLength(m_radiusY, boundingBox.height()); 184 float radiusY = floatValueForLength(m_radiusY, boundingBox.height());
135 path.addEllipse(FloatRect( 185 path.addEllipse(FloatRect(
136 centerX - radiusX + boundingBox.x(), 186 centerX - radiusX + boundingBox.x(),
137 centerY - radiusY + boundingBox.y(), 187 centerY - radiusY + boundingBox.y(),
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 } 295 }
246 296
247 bool BasicShapeInsetRectangle::operator==(const BasicShape& o) const 297 bool BasicShapeInsetRectangle::operator==(const BasicShape& o) const
248 { 298 {
249 if (!isSameType(o)) 299 if (!isSameType(o))
250 return false; 300 return false;
251 const BasicShapeInsetRectangle& other = toBasicShapeInsetRectangle(o); 301 const BasicShapeInsetRectangle& other = toBasicShapeInsetRectangle(o);
252 return m_right == other.m_right && m_top == other.m_top && m_bottom == other .m_bottom && m_left == other.m_left && m_cornerRadiusX == other.m_cornerRadiusX && m_cornerRadiusY == other.m_cornerRadiusY; 302 return m_right == other.m_right && m_top == other.m_top && m_bottom == other .m_bottom && m_left == other.m_left && m_cornerRadiusX == other.m_cornerRadiusX && m_cornerRadiusY == other.m_cornerRadiusY;
253 } 303 }
254 } 304 }
OLDNEW
« Source/core/rendering/style/BasicShapes.h ('K') | « Source/core/rendering/style/BasicShapes.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698