OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2003, 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2003, 2006 Apple Computer, Inc. All rights reserved. |
3 * 2006 Rob Buis <buis@kde.org> | 3 * 2006 Rob Buis <buis@kde.org> |
4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> | 4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> |
5 * Copyright (C) 2013 Google Inc. All rights reserved. | 5 * Copyright (C) 2013 Google Inc. All rights reserved. |
6 * | 6 * |
7 * Redistribution and use in source and binary forms, with or without | 7 * Redistribution and use in source and binary forms, with or without |
8 * modification, are permitted provided that the following conditions | 8 * modification, are permitted provided that the following conditions |
9 * are met: | 9 * are met: |
10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 void Path::addEllipse(const FloatRect& rect) | 323 void Path::addEllipse(const FloatRect& rect) |
324 { | 324 { |
325 m_path.addOval(rect); | 325 m_path.addOval(rect); |
326 } | 326 } |
327 | 327 |
328 void Path::addRoundedRect(const RoundedRect& r) | 328 void Path::addRoundedRect(const RoundedRect& r) |
329 { | 329 { |
330 addRoundedRect(r.rect(), r.radii().topLeft(), r.radii().topRight(), r.radii(
).bottomLeft(), r.radii().bottomRight()); | 330 addRoundedRect(r.rect(), r.radii().topLeft(), r.radii().topRight(), r.radii(
).bottomLeft(), r.radii().bottomRight()); |
331 } | 331 } |
332 | 332 |
333 void Path::addRoundedRect(const FloatRect& rect, const FloatSize& roundingRadii,
RoundedRectStrategy strategy) | 333 void Path::addRoundedRect(const FloatRect& rect, const FloatSize& roundingRadii) |
334 { | 334 { |
335 if (rect.isEmpty()) | 335 if (rect.isEmpty()) |
336 return; | 336 return; |
337 | 337 |
338 FloatSize radius(roundingRadii); | 338 FloatSize radius(roundingRadii); |
339 FloatSize halfSize(rect.width() / 2, rect.height() / 2); | 339 FloatSize halfSize(rect.width() / 2, rect.height() / 2); |
340 | 340 |
341 // Apply the SVG corner radius constraints, per the rect section of the SVG
shapes spec: if | 341 // Apply the SVG corner radius constraints, per the rect section of the SVG
shapes spec: if |
342 // one of rx,ry is negative, then the other corner radius value is used. If
both values are | 342 // one of rx,ry is negative, then the other corner radius value is used. If
both values are |
343 // negative then rx = ry = 0. If rx is greater than half of the width of the
rectangle | 343 // negative then rx = ry = 0. If rx is greater than half of the width of the
rectangle |
344 // then set rx to half of the width; ry is handled similarly. | 344 // then set rx to half of the width; ry is handled similarly. |
345 | 345 |
346 if (radius.width() < 0) | 346 if (radius.width() < 0) |
347 radius.setWidth((radius.height() < 0) ? 0 : radius.height()); | 347 radius.setWidth((radius.height() < 0) ? 0 : radius.height()); |
348 | 348 |
349 if (radius.height() < 0) | 349 if (radius.height() < 0) |
350 radius.setHeight(radius.width()); | 350 radius.setHeight(radius.width()); |
351 | 351 |
352 if (radius.width() > halfSize.width()) | 352 if (radius.width() > halfSize.width()) |
353 radius.setWidth(halfSize.width()); | 353 radius.setWidth(halfSize.width()); |
354 | 354 |
355 if (radius.height() > halfSize.height()) | 355 if (radius.height() > halfSize.height()) |
356 radius.setHeight(halfSize.height()); | 356 radius.setHeight(halfSize.height()); |
357 | 357 |
358 addPathForRoundedRect(rect, radius, radius, radius, radius, strategy); | 358 addPathForRoundedRect(rect, radius, radius, radius, radius); |
359 } | 359 } |
360 | 360 |
361 void Path::addRoundedRect(const FloatRect& rect, const FloatSize& topLeftRadius,
const FloatSize& topRightRadius, const FloatSize& bottomLeftRadius, const Float
Size& bottomRightRadius, RoundedRectStrategy strategy) | 361 void Path::addRoundedRect(const FloatRect& rect, const FloatSize& topLeftRadius,
const FloatSize& topRightRadius, const FloatSize& bottomLeftRadius, const Float
Size& bottomRightRadius) |
362 { | 362 { |
363 if (rect.isEmpty()) | 363 if (rect.isEmpty()) |
364 return; | 364 return; |
365 | 365 |
366 if (rect.width() < topLeftRadius.width() + topRightRadius.width() | 366 if (rect.width() < topLeftRadius.width() + topRightRadius.width() |
367 || rect.width() < bottomLeftRadius.width() + bottomRightRadius.width
() | 367 || rect.width() < bottomLeftRadius.width() + bottomRightRadius.width
() |
368 || rect.height() < topLeftRadius.height() + bottomLeftRadius.height(
) | 368 || rect.height() < topLeftRadius.height() + bottomLeftRadius.height(
) |
369 || rect.height() < topRightRadius.height() + bottomRightRadius.heigh
t()) { | 369 || rect.height() < topRightRadius.height() + bottomRightRadius.heigh
t()) { |
370 // If all the radii cannot be accommodated, return a rect. | 370 // If all the radii cannot be accommodated, return a rect. |
371 addRect(rect); | 371 addRect(rect); |
372 return; | 372 return; |
373 } | 373 } |
374 | 374 |
375 addPathForRoundedRect(rect, topLeftRadius, topRightRadius, bottomLeftRadius,
bottomRightRadius, strategy); | 375 addPathForRoundedRect(rect, topLeftRadius, topRightRadius, bottomLeftRadius,
bottomRightRadius); |
376 } | 376 } |
377 | 377 |
378 void Path::addPathForRoundedRect(const FloatRect& rect, const FloatSize& topLeft
Radius, const FloatSize& topRightRadius, const FloatSize& bottomLeftRadius, cons
t FloatSize& bottomRightRadius, RoundedRectStrategy strategy) | 378 void Path::addPathForRoundedRect(const FloatRect& rect, const FloatSize& topLeft
Radius, const FloatSize& topRightRadius, const FloatSize& bottomLeftRadius, cons
t FloatSize& bottomRightRadius) |
379 { | 379 { |
380 addBeziersForRoundedRect(rect, topLeftRadius, topRightRadius, bottomLeftRadi
us, bottomRightRadius); | 380 addBeziersForRoundedRect(rect, topLeftRadius, topRightRadius, bottomLeftRadi
us, bottomRightRadius); |
381 } | 381 } |
382 | 382 |
383 // Approximation of control point positions on a bezier to simulate a quarter of
a circle. | 383 // Approximation of control point positions on a bezier to simulate a quarter of
a circle. |
384 // This is 1-kappa, where kappa = 4 * (sqrt(2) - 1) / 3 | 384 // This is 1-kappa, where kappa = 4 * (sqrt(2) - 1) / 3 |
385 static const float gCircleControlPoint = 0.447715f; | 385 static const float gCircleControlPoint = 0.447715f; |
386 | 386 |
387 void Path::addBeziersForRoundedRect(const FloatRect& rect, const FloatSize& topL
eftRadius, const FloatSize& topRightRadius, const FloatSize& bottomLeftRadius, c
onst FloatSize& bottomRightRadius) | 387 void Path::addBeziersForRoundedRect(const FloatRect& rect, const FloatSize& topL
eftRadius, const FloatSize& topRightRadius, const FloatSize& bottomLeftRadius, c
onst FloatSize& bottomRightRadius) |
388 { | 388 { |
(...skipping 27 matching lines...) Expand all Loading... |
416 { | 416 { |
417 m_path.offset(WebCoreFloatToSkScalar(size.width()), WebCoreFloatToSkScalar(s
ize.height())); | 417 m_path.offset(WebCoreFloatToSkScalar(size.width()), WebCoreFloatToSkScalar(s
ize.height())); |
418 } | 418 } |
419 | 419 |
420 bool Path::unionPath(const Path& other) | 420 bool Path::unionPath(const Path& other) |
421 { | 421 { |
422 return Op(m_path, other.m_path, kUnion_PathOp, &m_path); | 422 return Op(m_path, other.m_path, kUnion_PathOp, &m_path); |
423 } | 423 } |
424 | 424 |
425 } | 425 } |
OLD | NEW |