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

Unified Diff: third_party/WebKit/Source/core/paint/ClipPathClipper.cpp

Issue 2312713002: Unprefix -webkit-clip-path (Closed)
Patch Set: Baselines Created 4 years, 3 months 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/paint/ClipPathClipper.cpp
diff --git a/third_party/WebKit/Source/core/paint/ClipPathClipper.cpp b/third_party/WebKit/Source/core/paint/ClipPathClipper.cpp
index 723110707b67b346556153faf2addf2e7fc21451..35d496d3f4d767b2dfe2848823fc218cc6c53e67 100644
--- a/third_party/WebKit/Source/core/paint/ClipPathClipper.cpp
+++ b/third_party/WebKit/Source/core/paint/ClipPathClipper.cpp
@@ -5,18 +5,43 @@
#include "core/paint/ClipPathClipper.h"
#include "core/layout/svg/LayoutSVGResourceClipper.h"
+#include "core/layout/svg/SVGResources.h"
+#include "core/layout/svg/SVGResourcesCache.h"
+#include "core/paint/SVGClipPainter.h"
#include "core/style/ClipPathOperation.h"
#include "platform/graphics/paint/ClipPathRecorder.h"
namespace blink {
+namespace {
+
+LayoutSVGResourceClipper* resolveElementReference(
+ const LayoutObject& layoutObject,
+ const ReferenceClipPathOperation& referenceClipPathOperation)
+{
+ if (layoutObject.isSVG() && !layoutObject.isSVGRoot()) {
+ // The reference will have been resolved in
+ // SVGResources::buildResources, so we can just use the LayoutObject's
+ // SVGResources.
+ SVGResources* resources = SVGResourcesCache::cachedResourcesForLayoutObject(&layoutObject);
+ return resources ? resources->clipper() : nullptr;
+ }
+ // TODO(fs): It doesn't work with forward or external SVG references (https://bugs.webkit.org/show_bug.cgi?id=90405)
+ Element* element = layoutObject.document().getElementById(referenceClipPathOperation.fragment());
+ if (!isSVGClipPathElement(element) || !element->layoutObject())
+ return nullptr;
+ return toLayoutSVGResourceClipper(toLayoutSVGResourceContainer(element->layoutObject()));
+}
+
+} // namespace
+
ClipPathClipper::ClipPathClipper(
GraphicsContext& context,
const LayoutObject& layoutObject,
const FloatRect& referenceBox,
const FloatPoint& origin)
: m_resourceClipper(nullptr)
- , m_clipperState(SVGClipPainter::ClipperNotApplied)
+ , m_clipperState(ClipperState::NotApplied)
, m_layoutObject(layoutObject)
, m_context(context)
{
@@ -27,14 +52,13 @@ ClipPathClipper::ClipPathClipper(
if (!shape->isValid())
return;
m_clipPathRecorder.emplace(context, layoutObject, shape->path(referenceBox));
+ m_clipperState = ClipperState::AppliedPath;
} else {
DCHECK_EQ(clipPathOperation->type(), ClipPathOperation::REFERENCE);
- ReferenceClipPathOperation* referenceClipPathOperation = toReferenceClipPathOperation(clipPathOperation);
- // TODO(fs): It doesn't work with forward or external SVG references (https://bugs.webkit.org/show_bug.cgi?id=90405)
- Element* element = layoutObject.document().getElementById(referenceClipPathOperation->fragment());
- if (!isSVGClipPathElement(element) || !element->layoutObject())
+ LayoutSVGResourceClipper* clipper = resolveElementReference(
+ layoutObject, toReferenceClipPathOperation(*clipPathOperation));
+ if (!clipper)
return;
- LayoutSVGResourceClipper* clipper = toLayoutSVGResourceClipper(toLayoutSVGResourceContainer(element->layoutObject()));
// Compute the (conservative) bounds of the clip-path.
FloatRect clipPathBounds = clipper->resourceBoundingBox(referenceBox);
// When SVG applies the clip, and the coordinate system is "userspace on use", we must explicitly pass in

Powered by Google App Engine
This is Rietveld 408576698