summaryrefslogtreecommitdiff
path: root/Source/WebCore/rendering/ClipPathOperation.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/rendering/ClipPathOperation.h')
-rw-r--r--Source/WebCore/rendering/ClipPathOperation.h104
1 files changed, 48 insertions, 56 deletions
diff --git a/Source/WebCore/rendering/ClipPathOperation.h b/Source/WebCore/rendering/ClipPathOperation.h
index cab91dd67..6c8bee858 100644
--- a/Source/WebCore/rendering/ClipPathOperation.h
+++ b/Source/WebCore/rendering/ClipPathOperation.h
@@ -27,15 +27,13 @@
* SUCH DAMAGE.
*/
-#ifndef ClipPathOperation_h
-#define ClipPathOperation_h
+#pragma once
#include "BasicShapes.h"
#include "Path.h"
#include "RenderStyleConstants.h"
-#include <wtf/OwnPtr.h>
-#include <wtf/PassOwnPtr.h>
#include <wtf/RefCounted.h>
+#include <wtf/TypeCasts.h>
#include <wtf/text/WTFString.h>
namespace WebCore {
@@ -53,8 +51,8 @@ public:
virtual bool operator==(const ClipPathOperation&) const = 0;
bool operator!=(const ClipPathOperation& o) const { return !(*this == o); }
- virtual OperationType type() const { return m_type; }
- virtual bool isSameType(const ClipPathOperation& o) const { return o.type() == m_type; }
+ OperationType type() const { return m_type; }
+ bool isSameType(const ClipPathOperation& o) const { return o.type() == m_type; }
protected:
explicit ClipPathOperation(OperationType type)
@@ -65,23 +63,23 @@ protected:
OperationType m_type;
};
-class ReferenceClipPathOperation : public ClipPathOperation {
+class ReferenceClipPathOperation final : public ClipPathOperation {
public:
- static PassRefPtr<ReferenceClipPathOperation> create(const String& url, const String& fragment)
+ static Ref<ReferenceClipPathOperation> create(const String& url, const String& fragment)
{
- return adoptRef(new ReferenceClipPathOperation(url, fragment));
+ return adoptRef(*new ReferenceClipPathOperation(url, fragment));
}
const String& url() const { return m_url; }
const String& fragment() const { return m_fragment; }
private:
- virtual bool operator==(const ClipPathOperation& o) const override
+ bool operator==(const ClipPathOperation& other) const override
{
- if (!isSameType(o))
+ if (!isSameType(other))
return false;
- const ReferenceClipPathOperation* other = static_cast<const ReferenceClipPathOperation*>(&o);
- return m_url == other->m_url;
+ auto& referenceClip = downcast<ReferenceClipPathOperation>(other);
+ return m_url == referenceClip.m_url;
}
ReferenceClipPathOperation(const String& url, const String& fragment)
@@ -95,87 +93,81 @@ private:
String m_fragment;
};
-class ShapeClipPathOperation : public ClipPathOperation {
+class ShapeClipPathOperation final : public ClipPathOperation {
public:
- static PassRefPtr<ShapeClipPathOperation> create(PassRefPtr<BasicShape> shape)
+ static Ref<ShapeClipPathOperation> create(Ref<BasicShape>&& shape)
{
- return adoptRef(new ShapeClipPathOperation(shape));
+ return adoptRef(*new ShapeClipPathOperation(WTFMove(shape)));
}
- const BasicShape* basicShape() const { return m_shape.get(); }
- WindRule windRule() const { return m_shape->windRule(); }
- const Path pathForReferenceRect(const FloatRect& boundingRect) const
- {
- ASSERT(m_shape);
- Path path;
- m_shape->path(path, boundingRect);
- return path;
- }
+ const BasicShape& basicShape() const { return m_shape; }
+ WindRule windRule() const { return m_shape.get().windRule(); }
+ const Path& pathForReferenceRect(const FloatRect& boundingRect) { return m_shape.get().path(boundingRect); }
- void setReferenceBox(LayoutBox referenceBox) { m_referenceBox = referenceBox; }
- LayoutBox referenceBox() const { return m_referenceBox; }
+ void setReferenceBox(CSSBoxType referenceBox) { m_referenceBox = referenceBox; }
+ CSSBoxType referenceBox() const { return m_referenceBox; }
private:
- virtual bool operator==(const ClipPathOperation& o) const override
+ bool operator==(const ClipPathOperation& other) const override
{
- if (!isSameType(o))
+ if (!isSameType(other))
return false;
- const ShapeClipPathOperation* other = static_cast<const ShapeClipPathOperation*>(&o);
- return m_shape == other->m_shape;
+ auto& shapeClip = downcast<ShapeClipPathOperation>(other);
+ return m_referenceBox == shapeClip.referenceBox()
+ && (m_shape.ptr() == shapeClip.m_shape.ptr() || m_shape.get() == shapeClip.m_shape.get());
}
- explicit ShapeClipPathOperation(PassRefPtr<BasicShape> shape)
+ explicit ShapeClipPathOperation(Ref<BasicShape>&& shape)
: ClipPathOperation(Shape)
- , m_shape(shape)
+ , m_shape(WTFMove(shape))
, m_referenceBox(BoxMissing)
{
}
- RefPtr<BasicShape> m_shape;
- LayoutBox m_referenceBox;
+ Ref<BasicShape> m_shape;
+ CSSBoxType m_referenceBox;
};
-class BoxClipPathOperation : public ClipPathOperation {
+class BoxClipPathOperation final : public ClipPathOperation {
public:
- static PassRefPtr<BoxClipPathOperation> create(LayoutBox referenceBox)
+ static Ref<BoxClipPathOperation> create(CSSBoxType referenceBox)
{
- return adoptRef(new BoxClipPathOperation(referenceBox));
+ return adoptRef(*new BoxClipPathOperation(referenceBox));
}
- const Path pathForReferenceRect(const FloatRect&) const
+ const Path pathForReferenceRect(const FloatRoundedRect& boundingRect) const
{
Path path;
- // FIXME: Create clipping path from <box>.
- // https://bugs.webkit.org/show_bug.cgi?id=126205
+ path.addRoundedRect(boundingRect);
return path;
}
- LayoutBox referenceBox() const { return m_referenceBox; }
+ CSSBoxType referenceBox() const { return m_referenceBox; }
private:
- virtual bool operator==(const ClipPathOperation& o) const override
+ bool operator==(const ClipPathOperation& other) const override
{
- if (!isSameType(o))
+ if (!isSameType(other))
return false;
- const BoxClipPathOperation* other = static_cast<const BoxClipPathOperation*>(&o);
- return m_referenceBox == other->m_referenceBox;
+ auto& boxClip = downcast<BoxClipPathOperation>(other);
+ return m_referenceBox == boxClip.m_referenceBox;
}
- explicit BoxClipPathOperation(LayoutBox referenceBox)
+ explicit BoxClipPathOperation(CSSBoxType referenceBox)
: ClipPathOperation(Box)
, m_referenceBox(referenceBox)
{
}
- LayoutBox m_referenceBox;
+ CSSBoxType m_referenceBox;
};
-#define CLIP_PATH_OPERATION_CASTS(ToValueTypeName, predicate) \
- TYPE_CASTS_BASE(ToValueTypeName, ClipPathOperation, operation, operation->type() == ClipPathOperation::predicate, operation.type() == ClipPathOperation::predicate)
-
-CLIP_PATH_OPERATION_CASTS(ReferenceClipPathOperation, Reference)
-CLIP_PATH_OPERATION_CASTS(ShapeClipPathOperation, Shape)
-CLIP_PATH_OPERATION_CASTS(BoxClipPathOperation, Box)
-
} // namespace WebCore
-#endif // ClipPathOperation_h
+#define SPECIALIZE_TYPE_TRAITS_CLIP_PATH_OPERATION(ToValueTypeName, predicate) \
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ToValueTypeName) \
+ static bool isType(const WebCore::ClipPathOperation& operation) { return operation.type() == WebCore::predicate; } \
+SPECIALIZE_TYPE_TRAITS_END()
+
+SPECIALIZE_TYPE_TRAITS_CLIP_PATH_OPERATION(ReferenceClipPathOperation, ClipPathOperation::Reference)
+SPECIALIZE_TYPE_TRAITS_CLIP_PATH_OPERATION(ShapeClipPathOperation, ClipPathOperation::Shape)
+SPECIALIZE_TYPE_TRAITS_CLIP_PATH_OPERATION(BoxClipPathOperation, ClipPathOperation::Box)