OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/style/StylePath.h" | 5 #include "core/style/StylePath.h" |
6 | 6 |
7 #include "core/css/CSSPathValue.h" | 7 #include "core/css/CSSPathValue.h" |
8 #include "core/svg/SVGPathByteStream.h" | 8 #include "core/svg/SVGPathByteStream.h" |
9 #include "core/svg/SVGPathUtilities.h" | 9 #include "core/svg/SVGPathUtilities.h" |
10 #include "platform/graphics/Path.h" | 10 #include "platform/graphics/Path.h" |
11 #include "wtf/PtrUtil.h" | |
12 #include <memory> | |
13 | 11 |
14 namespace blink { | 12 namespace blink { |
15 | 13 |
16 StylePath::StylePath(std::unique_ptr<SVGPathByteStream> pathByteStream) | 14 StylePath::StylePath(PassOwnPtr<SVGPathByteStream> pathByteStream) |
17 : m_byteStream(std::move(pathByteStream)) | 15 : m_byteStream(std::move(pathByteStream)) |
18 , m_pathLength(std::numeric_limits<float>::quiet_NaN()) | 16 , m_pathLength(std::numeric_limits<float>::quiet_NaN()) |
19 { | 17 { |
20 ASSERT(m_byteStream); | 18 ASSERT(m_byteStream); |
21 } | 19 } |
22 | 20 |
23 StylePath::~StylePath() | 21 StylePath::~StylePath() |
24 { | 22 { |
25 } | 23 } |
26 | 24 |
27 PassRefPtr<StylePath> StylePath::create(std::unique_ptr<SVGPathByteStream> pathB
yteStream) | 25 PassRefPtr<StylePath> StylePath::create(PassOwnPtr<SVGPathByteStream> pathByteSt
ream) |
28 { | 26 { |
29 return adoptRef(new StylePath(std::move(pathByteStream))); | 27 return adoptRef(new StylePath(std::move(pathByteStream))); |
30 } | 28 } |
31 | 29 |
32 StylePath* StylePath::emptyPath() | 30 StylePath* StylePath::emptyPath() |
33 { | 31 { |
34 DEFINE_STATIC_REF(StylePath, emptyPath, StylePath::create(SVGPathByteStream:
:create())); | 32 DEFINE_STATIC_REF(StylePath, emptyPath, StylePath::create(SVGPathByteStream:
:create())); |
35 return emptyPath; | 33 return emptyPath; |
36 } | 34 } |
37 | 35 |
38 const Path& StylePath::path() const | 36 const Path& StylePath::path() const |
39 { | 37 { |
40 if (!m_path) { | 38 if (!m_path) { |
41 m_path = wrapUnique(new Path); | 39 m_path = adoptPtr(new Path); |
42 buildPathFromByteStream(*m_byteStream, *m_path); | 40 buildPathFromByteStream(*m_byteStream, *m_path); |
43 } | 41 } |
44 return *m_path; | 42 return *m_path; |
45 } | 43 } |
46 | 44 |
47 float StylePath::length() const | 45 float StylePath::length() const |
48 { | 46 { |
49 if (std::isnan(m_pathLength)) | 47 if (std::isnan(m_pathLength)) |
50 m_pathLength = path().length(); | 48 m_pathLength = path().length(); |
51 return m_pathLength; | 49 return m_pathLength; |
52 } | 50 } |
53 | 51 |
54 bool StylePath::isClosed() const | 52 bool StylePath::isClosed() const |
55 { | 53 { |
56 return path().isClosed(); | 54 return path().isClosed(); |
57 } | 55 } |
58 | 56 |
59 CSSValue* StylePath::computedCSSValue() const | 57 CSSValue* StylePath::computedCSSValue() const |
60 { | 58 { |
61 return CSSPathValue::create(const_cast<StylePath*>(this)); | 59 return CSSPathValue::create(const_cast<StylePath*>(this)); |
62 } | 60 } |
63 | 61 |
64 bool StylePath::operator==(const StylePath& other) const | 62 bool StylePath::operator==(const StylePath& other) const |
65 { | 63 { |
66 return *m_byteStream == *other.m_byteStream; | 64 return *m_byteStream == *other.m_byteStream; |
67 } | 65 } |
68 | 66 |
69 } // namespace blink | 67 } // namespace blink |
OLD | NEW |