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

Side by Side Diff: Source/platform/geometry/FloatRoundedRect.cpp

Issue 815933006: Change all uses of the RoundedRect class to use FloatRoundedRect instead. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 2 * Copyright (C) 2013 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 m_bottomRight.setHeight(std::max<float>(0, m_bottomRight.height() + bott omWidth)); 96 m_bottomRight.setHeight(std::max<float>(0, m_bottomRight.height() + bott omWidth));
97 } 97 }
98 } 98 }
99 99
100 static inline float cornerRectIntercept(float y, const FloatRect& cornerRect) 100 static inline float cornerRectIntercept(float y, const FloatRect& cornerRect)
101 { 101 {
102 ASSERT(cornerRect.height() > 0); 102 ASSERT(cornerRect.height() > 0);
103 return cornerRect.width() * sqrt(1 - (y * y) / (cornerRect.height() * corner Rect.height())); 103 return cornerRect.width() * sqrt(1 - (y * y) / (cornerRect.height() * corner Rect.height()));
104 } 104 }
105 105
106 FloatRect FloatRoundedRect::radiusCenterRect() const
107 {
108 ASSERT(isRenderable());
109 int minX = m_rect.x() + std::max(m_radii.topLeft().width(), m_radii.bottomLe ft().width());
110 int minY = m_rect.y() + std::max(m_radii.topLeft().height(), m_radii.topRigh t().height());
111 int maxX = m_rect.maxX() - std::max(m_radii.topRight().width(), m_radii.bott omRight().width());
112 int maxY = m_rect.maxY() - std::max(m_radii.bottomLeft().height(), m_radii.b ottomRight().height());
113 return FloatRect(minX, minY, maxX - minX, maxY - minY);
114 }
115
106 bool FloatRoundedRect::xInterceptsAtY(float y, float& minXIntercept, float& maxX Intercept) const 116 bool FloatRoundedRect::xInterceptsAtY(float y, float& minXIntercept, float& maxX Intercept) const
107 { 117 {
108 if (y < rect().y() || y > rect().maxY()) 118 if (y < rect().y() || y > rect().maxY())
109 return false; 119 return false;
110 120
111 if (!isRounded()) { 121 if (!isRounded()) {
112 minXIntercept = rect().x(); 122 minXIntercept = rect().x();
113 maxXIntercept = rect().maxX(); 123 maxXIntercept = rect().maxX();
114 return true; 124 return true;
115 } 125 }
(...skipping 14 matching lines...) Expand all
130 if (!topRightRect.isEmpty() && y >= topRightRect.y() && y <= topRightRect.ma xY()) 140 if (!topRightRect.isEmpty() && y >= topRightRect.y() && y <= topRightRect.ma xY())
131 maxXIntercept = topRightRect.x() + cornerRectIntercept(topRightRect.maxY () - y, topRightRect); 141 maxXIntercept = topRightRect.x() + cornerRectIntercept(topRightRect.maxY () - y, topRightRect);
132 else if (!bottomRightRect.isEmpty() && y >= bottomRightRect.y() && y <= bott omRightRect.maxY()) 142 else if (!bottomRightRect.isEmpty() && y >= bottomRightRect.y() && y <= bott omRightRect.maxY())
133 maxXIntercept = bottomRightRect.x() + cornerRectIntercept(y - bottomRigh tRect.y(), bottomRightRect); 143 maxXIntercept = bottomRightRect.x() + cornerRectIntercept(y - bottomRigh tRect.y(), bottomRightRect);
134 else 144 else
135 maxXIntercept = m_rect.maxX(); 145 maxXIntercept = m_rect.maxX();
136 146
137 return true; 147 return true;
138 } 148 }
139 149
150 void FloatRoundedRect::inflateWithRadii(int size)
151 {
152 FloatRect old = m_rect;
153
154 m_rect.inflate(size);
155 // Considering the inflation factor of shorter size to scale the radii seems appropriate here
156 float factor;
157 if (m_rect.width() < m_rect.height())
158 factor = old.width() ? (float)m_rect.width() / old.width() : int(0);
159 else
160 factor = old.height() ? (float)m_rect.height() / old.height() : int(0);
161
162 m_radii.scale(factor);
163 }
164
165 bool FloatRoundedRect::intersectsQuad(const FloatQuad& quad) const
166 {
167 if (!quad.intersectsRect(m_rect))
168 return false;
169
170 const FloatSize& topLeft = m_radii.topLeft();
171 if (!topLeft.isEmpty()) {
172 FloatRect rect(m_rect.x(), m_rect.y(), topLeft.width(), topLeft.height() );
173 if (quad.intersectsRect(rect)) {
174 FloatPoint center(m_rect.x() + topLeft.width(), m_rect.y() + topLeft .height());
175 FloatSize size(topLeft.width(), topLeft.height());
176 if (!quad.intersectsEllipse(center, size))
177 return false;
178 }
179 }
180
181 const FloatSize& topRight = m_radii.topRight();
182 if (!topRight.isEmpty()) {
183 FloatRect rect(m_rect.maxX() - topRight.width(), m_rect.y(), topRight.wi dth(), topRight.height());
184 if (quad.intersectsRect(rect)) {
185 FloatPoint center(m_rect.maxX() - topRight.width(), m_rect.y() + top Right.height());
186 FloatSize size(topRight.width(), topRight.height());
187 if (!quad.intersectsEllipse(center, size))
188 return false;
189 }
190 }
191
192 const FloatSize& bottomLeft = m_radii.bottomLeft();
193 if (!bottomLeft.isEmpty()) {
194 FloatRect rect(m_rect.x(), m_rect.maxY() - bottomLeft.height(), bottomLe ft.width(), bottomLeft.height());
195 if (quad.intersectsRect(rect)) {
196 FloatPoint center(m_rect.x() + bottomLeft.width(), m_rect.maxY() - b ottomLeft.height());
197 FloatSize size(bottomLeft.width(), bottomLeft.height());
198 if (!quad.intersectsEllipse(center, size))
199 return false;
200 }
201 }
202
203 const FloatSize& bottomRight = m_radii.bottomRight();
204 if (!bottomRight.isEmpty()) {
205 FloatRect rect(m_rect.maxX() - bottomRight.width(), m_rect.maxY() - bott omRight.height(), bottomRight.width(), bottomRight.height());
206 if (quad.intersectsRect(rect)) {
207 FloatPoint center(m_rect.maxX() - bottomRight.width(), m_rect.maxY() - bottomRight.height());
208 FloatSize size(bottomRight.width(), bottomRight.height());
209 if (!quad.intersectsEllipse(center, size))
210 return false;
211 }
212 }
213
214 return true;
215 }
216
217 void FloatRoundedRect::Radii::includeLogicalEdges(const FloatRoundedRect::Radii& edges, bool isHorizontal, bool includeLogicalLeftEdge, bool includeLogicalRight Edge)
218 {
219 if (includeLogicalLeftEdge) {
220 if (isHorizontal)
221 m_bottomLeft = edges.bottomLeft();
222 else
223 m_topRight = edges.topRight();
224 m_topLeft = edges.topLeft();
225 }
226
227 if (includeLogicalRightEdge) {
228 if (isHorizontal)
229 m_topRight = edges.topRight();
230 else
231 m_bottomLeft = edges.bottomLeft();
232 m_bottomRight = edges.bottomRight();
233 }
234 }
235
236 void FloatRoundedRect::includeLogicalEdges(const Radii& edges, bool isHorizontal , bool includeLogicalLeftEdge, bool includeLogicalRightEdge)
237 {
238 m_radii.includeLogicalEdges(edges, isHorizontal, includeLogicalLeftEdge, inc ludeLogicalRightEdge);
239 }
240
241 bool FloatRoundedRect::isRenderable() const
242 {
243 return m_radii.topLeft().width() + m_radii.topRight().width() <= m_rect.widt h()
244 && m_radii.bottomLeft().width() + m_radii.bottomRight().width() <= m_rec t.width()
245 && m_radii.topLeft().height() + m_radii.bottomLeft().height() <= m_rect. height()
246 && m_radii.topRight().height() + m_radii.bottomRight().height() <= m_rec t.height();
247 }
248
249 void FloatRoundedRect::adjustRadii()
250 {
251 float maxRadiusWidth = std::max(m_radii.topLeft().width() + m_radii.topRight ().width(), m_radii.bottomLeft().width() + m_radii.bottomRight().width());
252 float maxRadiusHeight = std::max(m_radii.topLeft().height() + m_radii.bottom Left().height(), m_radii.topRight().height() + m_radii.bottomRight().height());
253
254 if (maxRadiusWidth <= 0 || maxRadiusHeight <= 0) {
255 m_radii.scale(0.0f);
256 return;
257 }
258 float widthRatio = static_cast<float>(m_rect.width()) / maxRadiusWidth;
259 float heightRatio = static_cast<float>(m_rect.height()) / maxRadiusHeight;
260 m_radii.scale(widthRatio < heightRatio ? widthRatio : heightRatio);
261 }
262
263
140 } // namespace blink 264 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698