1 | /* |
2 | * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
3 | * Copyright (C) 2018-2019 Apple Inc. All rights reserved. |
4 | * |
5 | * This library is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU Library General Public |
7 | * License as published by the Free Software Foundation; either |
8 | * version 2 of the License, or (at your option) any later version. |
9 | * |
10 | * This library is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * Library General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU Library General Public License |
16 | * along with this library; see the file COPYING.LIB. If not, write to |
17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | * Boston, MA 02110-1301, USA. |
19 | */ |
20 | |
21 | #pragma once |
22 | |
23 | #include "SVGPropertyTraits.h" |
24 | #include "SVGValueProperty.h" |
25 | |
26 | namespace WebCore { |
27 | |
28 | class SVGRect : public SVGValueProperty<FloatRect> { |
29 | using Base = SVGValueProperty<FloatRect>; |
30 | using Base::Base; |
31 | using Base::m_value; |
32 | |
33 | public: |
34 | static Ref<SVGRect> create(const FloatRect& value = { }) |
35 | { |
36 | return adoptRef(*new SVGRect(value)); |
37 | } |
38 | |
39 | static Ref<SVGRect> create(SVGPropertyOwner* owner, SVGPropertyAccess access, const FloatRect& value = { }) |
40 | { |
41 | return adoptRef(*new SVGRect(owner, access, value)); |
42 | } |
43 | |
44 | template<typename T> |
45 | static ExceptionOr<Ref<SVGRect>> create(ExceptionOr<T>&& value) |
46 | { |
47 | if (value.hasException()) |
48 | return value.releaseException(); |
49 | return adoptRef(*new SVGRect(value.releaseReturnValue())); |
50 | } |
51 | |
52 | float x() { return m_value.x(); } |
53 | |
54 | ExceptionOr<void> setX(float xValue) |
55 | { |
56 | if (isReadOnly()) |
57 | return Exception { NoModificationAllowedError }; |
58 | |
59 | m_value.setX(xValue); |
60 | commitChange(); |
61 | return { }; |
62 | } |
63 | |
64 | float y() { return m_value.y(); } |
65 | |
66 | ExceptionOr<void> setY(float xValue) |
67 | { |
68 | if (isReadOnly()) |
69 | return Exception { NoModificationAllowedError }; |
70 | |
71 | m_value.setY(xValue); |
72 | commitChange(); |
73 | return { }; |
74 | } |
75 | |
76 | float width() { return m_value.width(); } |
77 | |
78 | ExceptionOr<void> setWidth(float widthValue) |
79 | { |
80 | if (isReadOnly()) |
81 | return Exception { NoModificationAllowedError }; |
82 | |
83 | m_value.setWidth(widthValue); |
84 | commitChange(); |
85 | return { }; |
86 | } |
87 | |
88 | float height() { return m_value.height(); } |
89 | |
90 | ExceptionOr<void> setHeight(float heightValue) |
91 | { |
92 | if (isReadOnly()) |
93 | return Exception { NoModificationAllowedError }; |
94 | |
95 | m_value.setHeight(heightValue); |
96 | commitChange(); |
97 | return { }; |
98 | } |
99 | |
100 | String valueAsString() const override |
101 | { |
102 | return SVGPropertyTraits<FloatRect>::toString(m_value); |
103 | } |
104 | }; |
105 | |
106 | } |
107 | |