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

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

Issue 2265123002: Refactor ClipPathHelper in PaintLayerPainter.cpp for reuse (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move comment Created 4 years, 4 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
new file mode 100644
index 0000000000000000000000000000000000000000..f86ede84123693820931c457b3a9e5d4464bb1d0
--- /dev/null
+++ b/third_party/WebKit/Source/core/paint/ClipPathClipper.cpp
@@ -0,0 +1,58 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/paint/ClipPathClipper.h"
+
+#include "core/layout/svg/LayoutSVGResourceClipper.h"
+#include "core/style/ClipPathOperation.h"
+#include "platform/graphics/paint/ClipPathRecorder.h"
+
+namespace blink {
+
+ClipPathClipper::ClipPathClipper(
+ GraphicsContext& context,
+ const LayoutObject& layoutObject,
+ const FloatRect& referenceBox,
+ const FloatRect& visualOverflowRect,
+ const FloatPoint& origin)
+ : m_resourceClipper(nullptr)
+ , m_clipperState(SVGClipPainter::ClipperNotApplied)
+ , m_layoutObject(layoutObject)
+ , m_context(context)
+{
+ DCHECK(layoutObject.styleRef().clipPath());
+ ClipPathOperation* clipPathOperation = layoutObject.styleRef().clipPath();
+ if (clipPathOperation->type() == ClipPathOperation::SHAPE) {
+ ShapeClipPathOperation* shape = toShapeClipPathOperation(clipPathOperation);
+ if (shape->isValid())
+ m_clipPathRecorder.emplace(context, layoutObject, shape->path(referenceBox));
+ } else {
+ DCHECK_EQ(clipPathOperation->type(), ClipPathOperation::REFERENCE);
+ ReferenceClipPathOperation* referenceClipPathOperation = toReferenceClipPathOperation(clipPathOperation);
+ Document& document = layoutObject.document();
+ // TODO(fs): It doesn't work with forward or external SVG references (https://bugs.webkit.org/show_bug.cgi?id=90405)
+ Element* element = document.getElementById(referenceClipPathOperation->fragment());
+ if (isSVGClipPathElement(element) && element->layoutObject()) {
+ m_resourceClipper = toLayoutSVGResourceClipper(toLayoutSVGResourceContainer(element->layoutObject()));
+ // When SVG applies the clip, and the coordinate system is "userspace on use", we must explicitly pass in
+ // the offset to have the clip paint in the correct location. When the coordinate system is
+ // "object bounding box" the offset should already be accounted for in the visualOverflowRect.
+ FloatPoint originTranslation = m_resourceClipper->clipPathUnits() == SVGUnitTypes::kSvgUnitTypeUserspaceonuse ?
+ origin : FloatPoint();
+ if (!SVGClipPainter(*m_resourceClipper).prepareEffect(layoutObject, referenceBox,
+ visualOverflowRect, originTranslation, context, m_clipperState)) {
+ // No need to "finish" the clipper if this failed.
+ m_resourceClipper = nullptr;
+ }
+ }
+ }
+}
+
+ClipPathClipper::~ClipPathClipper()
+{
+ if (m_resourceClipper)
+ SVGClipPainter(*m_resourceClipper).finishEffect(m_layoutObject, m_context, m_clipperState);
+}
+
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/paint/ClipPathClipper.h ('k') | third_party/WebKit/Source/core/paint/PaintLayerPainter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698