1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_STYLE_STYLE_PATH_H_
6 #define THIRD_PARTY_BLINK_RENDERER_CORE_STYLE_STYLE_PATH_H_
7 
8 #include <memory>
9 #include "base/memory/scoped_refptr.h"
10 #include "third_party/blink/renderer/core/style/basic_shapes.h"
11 #include "third_party/blink/renderer/platform/wtf/casting.h"
12 
13 namespace blink {
14 
15 class CSSValue;
16 class Path;
17 class SVGPathByteStream;
18 
19 class StylePath final : public BasicShape {
20  public:
21   static scoped_refptr<StylePath> Create(std::unique_ptr<SVGPathByteStream>,
22                                          WindRule wind_rule = RULE_NONZERO);
23   ~StylePath() override;
24 
25   static const StylePath* EmptyPath();
26 
27   const Path& GetPath() const;
28   float length() const;
29   bool IsClosed() const;
30 
ByteStream()31   const SVGPathByteStream& ByteStream() const { return *byte_stream_; }
32 
33   CSSValue* ComputedCSSValue() const;
34 
35   void GetPath(Path&, const FloatRect&, float zoom) override;
GetWindRule()36   WindRule GetWindRule() const override { return wind_rule_; }
37 
38   bool operator==(const BasicShape&) const override;
39 
GetType()40   ShapeType GetType() const override { return kStylePathType; }
41 
42  private:
43   explicit StylePath(std::unique_ptr<SVGPathByteStream>, WindRule wind_rule);
44 
45   std::unique_ptr<SVGPathByteStream> byte_stream_;
46   mutable std::unique_ptr<Path> path_;
47   mutable float path_length_;
48   WindRule wind_rule_;
49 };
50 
51 template <>
52 struct DowncastTraits<StylePath> {
53   static bool AllowFrom(const BasicShape& value) {
54     return value.GetType() == BasicShape::kStylePathType;
55   }
56 };
57 
58 }  // namespace blink
59 
60 #endif  // THIRD_PARTY_BLINK_RENDERER_CORE_STYLE_STYLE_PATH_H_
61