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 | 11 |
12 namespace blink { | 12 namespace blink { |
13 | 13 |
14 StylePath::StylePath(PassRefPtr<SVGPathByteStream> pathByteStream) | 14 StylePath::StylePath(PassRefPtr<SVGPathByteStream> pathByteStream) |
15 : m_byteStream(pathByteStream) | 15 : m_byteStream(pathByteStream) |
| 16 , m_pathLength(std::numeric_limits<float>::quiet_NaN()) |
16 { | 17 { |
17 ASSERT(m_byteStream); | 18 ASSERT(m_byteStream); |
18 } | 19 } |
19 | 20 |
20 StylePath::~StylePath() | 21 StylePath::~StylePath() |
21 { | 22 { |
22 } | 23 } |
23 | 24 |
24 PassRefPtr<StylePath> StylePath::create(PassRefPtr<SVGPathByteStream> pathByteSt
ream) | 25 PassRefPtr<StylePath> StylePath::create(PassRefPtr<SVGPathByteStream> pathByteSt
ream) |
25 { | 26 { |
26 return adoptRef(new StylePath(pathByteStream)); | 27 return adoptRef(new StylePath(pathByteStream)); |
27 } | 28 } |
28 | 29 |
29 StylePath* StylePath::emptyPath() | 30 StylePath* StylePath::emptyPath() |
30 { | 31 { |
31 DEFINE_STATIC_REF(StylePath, emptyPath, StylePath::create(SVGPathByteStream:
:create())); | 32 DEFINE_STATIC_REF(StylePath, emptyPath, StylePath::create(SVGPathByteStream:
:create())); |
32 return emptyPath; | 33 return emptyPath; |
33 } | 34 } |
34 | 35 |
35 const Path& StylePath::path() const | 36 const Path& StylePath::path() const |
36 { | 37 { |
37 if (!m_path) { | 38 if (!m_path) { |
38 m_path = adoptPtr(new Path); | 39 m_path = adoptPtr(new Path); |
39 buildPathFromByteStream(*m_byteStream, *m_path); | 40 buildPathFromByteStream(*m_byteStream, *m_path); |
40 } | 41 } |
41 return *m_path; | 42 return *m_path; |
42 } | 43 } |
43 | 44 |
| 45 float StylePath::length() const |
| 46 { |
| 47 if (std::isnan(m_pathLength)) |
| 48 m_pathLength = path().length(); |
| 49 return m_pathLength; |
| 50 } |
| 51 |
| 52 bool StylePath::isClosed() const |
| 53 { |
| 54 return path().isClosed(); |
| 55 } |
| 56 |
44 const SVGPathByteStream& StylePath::byteStream() const | 57 const SVGPathByteStream& StylePath::byteStream() const |
45 { | 58 { |
46 return *m_byteStream; | 59 return *m_byteStream; |
47 } | 60 } |
48 | 61 |
49 PassRefPtrWillBeRawPtr<CSSValue> StylePath::computedCSSValue() const | 62 PassRefPtrWillBeRawPtr<CSSValue> StylePath::computedCSSValue() const |
50 { | 63 { |
51 return CSSPathValue::create(m_byteStream, const_cast<StylePath*>(this)); | 64 return CSSPathValue::create(m_byteStream, const_cast<StylePath*>(this)); |
52 } | 65 } |
53 | 66 |
54 bool StylePath::equals(const StylePath& other) const | 67 bool StylePath::equals(const StylePath& other) const |
55 { | 68 { |
56 return *m_byteStream == *other.m_byteStream; | 69 return *m_byteStream == *other.m_byteStream; |
57 } | 70 } |
58 | 71 |
59 } // namespace blink | 72 } // namespace blink |
OLD | NEW |