blob: 90018e186b192ac3be6f0550df811627fbd7e9f2 [file] [log] [blame]
zimmermann@webkit.orgbcebe572010-12-01 08:57:20 +00001/*
2 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
commit-queue@webkit.org335a0ed2019-03-20 00:59:50 +00003 * Copyright (C) 2018-2019 Apple Inc. All rights reserved.
zimmermann@webkit.orgbcebe572010-12-01 08:57:20 +00004 *
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
commit-queue@webkit.org46c0f522016-11-13 10:05:43 +000021#pragma once
zimmermann@webkit.orgbcebe572010-12-01 08:57:20 +000022
commit-queue@webkit.org39d8d822018-02-20 02:02:57 +000023#include "SVGPropertyTraits.h"
commit-queue@webkit.org335a0ed2019-03-20 00:59:50 +000024#include "SVGValueProperty.h"
zimmermann@webkit.orgbcebe572010-12-01 08:57:20 +000025
26namespace WebCore {
27
commit-queue@webkit.org335a0ed2019-03-20 00:59:50 +000028class SVGRect : public SVGValueProperty<FloatRect> {
29 using Base = SVGValueProperty<FloatRect>;
30 using Base::Base;
31 using Base::m_value;
32
weinig@apple.comf7867302016-11-14 21:18:41 +000033public:
commit-queue@webkit.org335a0ed2019-03-20 00:59:50 +000034 static Ref<SVGRect> create(const FloatRect& value = { })
zimmermann@webkit.orgbcebe572010-12-01 08:57:20 +000035 {
commit-queue@webkit.org335a0ed2019-03-20 00:59:50 +000036 return adoptRef(*new SVGRect(value));
weinig@apple.comf7867302016-11-14 21:18:41 +000037 }
38
commit-queue@webkit.org335a0ed2019-03-20 00:59:50 +000039 static Ref<SVGRect> create(SVGPropertyOwner* owner, SVGPropertyAccess access, const FloatRect& value = { })
weinig@apple.comf7867302016-11-14 21:18:41 +000040 {
commit-queue@webkit.org335a0ed2019-03-20 00:59:50 +000041 return adoptRef(*new SVGRect(owner, access, value));
weinig@apple.comf7867302016-11-14 21:18:41 +000042 }
43
commit-queue@webkit.org335a0ed2019-03-20 00:59:50 +000044 template<typename T>
45 static ExceptionOr<Ref<SVGRect>> create(ExceptionOr<T>&& value)
weinig@apple.comf7867302016-11-14 21:18:41 +000046 {
commit-queue@webkit.org335a0ed2019-03-20 00:59:50 +000047 if (value.hasException())
48 return value.releaseException();
49 return adoptRef(*new SVGRect(value.releaseReturnValue()));
weinig@apple.comf7867302016-11-14 21:18:41 +000050 }
51
commit-queue@webkit.org335a0ed2019-03-20 00:59:50 +000052 float x() { return m_value.x(); }
weinig@apple.comf7867302016-11-14 21:18:41 +000053
54 ExceptionOr<void> setX(float xValue)
55 {
56 if (isReadOnly())
cdumez@apple.com750df372017-07-25 03:59:12 +000057 return Exception { NoModificationAllowedError };
weinig@apple.comf7867302016-11-14 21:18:41 +000058
commit-queue@webkit.org335a0ed2019-03-20 00:59:50 +000059 m_value.setX(xValue);
weinig@apple.comf7867302016-11-14 21:18:41 +000060 commitChange();
weinig@apple.comf7867302016-11-14 21:18:41 +000061 return { };
62 }
63
commit-queue@webkit.org335a0ed2019-03-20 00:59:50 +000064 float y() { return m_value.y(); }
weinig@apple.comf7867302016-11-14 21:18:41 +000065
66 ExceptionOr<void> setY(float xValue)
67 {
68 if (isReadOnly())
cdumez@apple.com750df372017-07-25 03:59:12 +000069 return Exception { NoModificationAllowedError };
weinig@apple.comf7867302016-11-14 21:18:41 +000070
commit-queue@webkit.org335a0ed2019-03-20 00:59:50 +000071 m_value.setY(xValue);
weinig@apple.comf7867302016-11-14 21:18:41 +000072 commitChange();
weinig@apple.comf7867302016-11-14 21:18:41 +000073 return { };
74 }
75
commit-queue@webkit.org335a0ed2019-03-20 00:59:50 +000076 float width() { return m_value.width(); }
weinig@apple.comf7867302016-11-14 21:18:41 +000077
78 ExceptionOr<void> setWidth(float widthValue)
79 {
80 if (isReadOnly())
cdumez@apple.com750df372017-07-25 03:59:12 +000081 return Exception { NoModificationAllowedError };
weinig@apple.comf7867302016-11-14 21:18:41 +000082
commit-queue@webkit.org335a0ed2019-03-20 00:59:50 +000083 m_value.setWidth(widthValue);
weinig@apple.comf7867302016-11-14 21:18:41 +000084 commitChange();
weinig@apple.comf7867302016-11-14 21:18:41 +000085 return { };
86 }
87
commit-queue@webkit.org335a0ed2019-03-20 00:59:50 +000088 float height() { return m_value.height(); }
weinig@apple.comf7867302016-11-14 21:18:41 +000089
90 ExceptionOr<void> setHeight(float heightValue)
91 {
92 if (isReadOnly())
cdumez@apple.com750df372017-07-25 03:59:12 +000093 return Exception { NoModificationAllowedError };
weinig@apple.comf7867302016-11-14 21:18:41 +000094
commit-queue@webkit.org335a0ed2019-03-20 00:59:50 +000095 m_value.setHeight(heightValue);
weinig@apple.comf7867302016-11-14 21:18:41 +000096 commitChange();
weinig@apple.comf7867302016-11-14 21:18:41 +000097 return { };
98 }
commit-queue@webkit.org335a0ed2019-03-20 00:59:50 +000099
100 String valueAsString() const override
weinig@apple.comf7867302016-11-14 21:18:41 +0000101 {
commit-queue@webkit.org335a0ed2019-03-20 00:59:50 +0000102 return SVGPropertyTraits<FloatRect>::toString(m_value);
weinig@apple.comf7867302016-11-14 21:18:41 +0000103 }
zimmermann@webkit.orgbcebe572010-12-01 08:57:20 +0000104};
105
commit-queue@webkit.org335a0ed2019-03-20 00:59:50 +0000106}