1 | /* |
2 | * Copyright (C) 2016-2019 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #include "SVGAngleValue.h" |
29 | #include "SVGValueProperty.h" |
30 | |
31 | namespace WebCore { |
32 | |
33 | class SVGAngle : public SVGValueProperty<SVGAngleValue> { |
34 | using Base = SVGValueProperty<SVGAngleValue>; |
35 | using Base::Base; |
36 | using Base::m_value; |
37 | |
38 | public: |
39 | static Ref<SVGAngle> create(const SVGAngleValue& value = { }) |
40 | { |
41 | return adoptRef(*new SVGAngle(value)); |
42 | } |
43 | |
44 | static Ref<SVGAngle> create(SVGPropertyOwner* owner, SVGPropertyAccess access, const SVGAngleValue& value = { }) |
45 | { |
46 | return adoptRef(*new SVGAngle(owner, access, value)); |
47 | } |
48 | |
49 | template<typename T> |
50 | static ExceptionOr<Ref<SVGAngle>> create(ExceptionOr<T>&& value) |
51 | { |
52 | if (value.hasException()) |
53 | return value.releaseException(); |
54 | return adoptRef(*new SVGAngle(value.releaseReturnValue())); |
55 | } |
56 | |
57 | SVGAngleValue::Type unitType() |
58 | { |
59 | return m_value.unitType(); |
60 | } |
61 | |
62 | ExceptionOr<void> setValueForBindings(float value) |
63 | { |
64 | if (isReadOnly()) |
65 | return Exception { NoModificationAllowedError }; |
66 | |
67 | m_value.setValue(value); |
68 | commitChange(); |
69 | return { }; |
70 | } |
71 | |
72 | float valueForBindings() |
73 | { |
74 | return m_value.value(); |
75 | } |
76 | |
77 | ExceptionOr<void> setValueInSpecifiedUnits(float valueInSpecifiedUnits) |
78 | { |
79 | if (isReadOnly()) |
80 | return Exception { NoModificationAllowedError }; |
81 | |
82 | m_value.setValueInSpecifiedUnits(valueInSpecifiedUnits); |
83 | commitChange(); |
84 | return { }; |
85 | } |
86 | |
87 | float valueInSpecifiedUnits() |
88 | { |
89 | return m_value.valueInSpecifiedUnits(); |
90 | } |
91 | |
92 | ExceptionOr<void> setValueAsString(const String& value) |
93 | { |
94 | if (isReadOnly()) |
95 | return Exception { NoModificationAllowedError }; |
96 | |
97 | auto result = m_value.setValueAsString(value); |
98 | if (result.hasException()) |
99 | return result; |
100 | |
101 | commitChange(); |
102 | return result; |
103 | } |
104 | |
105 | String valueAsString() const override |
106 | { |
107 | return m_value.valueAsString(); |
108 | } |
109 | |
110 | ExceptionOr<void> newValueSpecifiedUnits(unsigned short unitType, float valueInSpecifiedUnits) |
111 | { |
112 | if (isReadOnly()) |
113 | return Exception { NoModificationAllowedError }; |
114 | |
115 | auto result = m_value.newValueSpecifiedUnits(unitType, valueInSpecifiedUnits); |
116 | if (result.hasException()) |
117 | return result; |
118 | |
119 | commitChange(); |
120 | return result; |
121 | } |
122 | |
123 | ExceptionOr<void> convertToSpecifiedUnits(unsigned short unitType) |
124 | { |
125 | if (isReadOnly()) |
126 | return Exception { NoModificationAllowedError }; |
127 | |
128 | auto result = m_value.convertToSpecifiedUnits(unitType); |
129 | if (result.hasException()) |
130 | return result; |
131 | |
132 | commitChange(); |
133 | return result; |
134 | } |
135 | }; |
136 | |
137 | } // namespace WebCore |
138 | |