zimmermann@webkit.org | bcebe57 | 2010-12-01 08:57:20 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
commit-queue@webkit.org | 335a0ed | 2019-03-20 00:59:50 +0000 | [diff] [blame] | 3 | * Copyright (C) 2018-2019 Apple Inc. All rights reserved. |
zimmermann@webkit.org | bcebe57 | 2010-12-01 08:57:20 +0000 | [diff] [blame] | 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 | |
commit-queue@webkit.org | 46c0f52 | 2016-11-13 10:05:43 +0000 | [diff] [blame] | 21 | #pragma once |
zimmermann@webkit.org | bcebe57 | 2010-12-01 08:57:20 +0000 | [diff] [blame] | 22 | |
commit-queue@webkit.org | 39d8d82 | 2018-02-20 02:02:57 +0000 | [diff] [blame] | 23 | #include "SVGPropertyTraits.h" |
commit-queue@webkit.org | 335a0ed | 2019-03-20 00:59:50 +0000 | [diff] [blame] | 24 | #include "SVGValueProperty.h" |
zimmermann@webkit.org | bcebe57 | 2010-12-01 08:57:20 +0000 | [diff] [blame] | 25 | |
| 26 | namespace WebCore { |
| 27 | |
commit-queue@webkit.org | 335a0ed | 2019-03-20 00:59:50 +0000 | [diff] [blame] | 28 | class SVGRect : public SVGValueProperty<FloatRect> { |
| 29 | using Base = SVGValueProperty<FloatRect>; |
| 30 | using Base::Base; |
| 31 | using Base::m_value; |
| 32 | |
weinig@apple.com | f786730 | 2016-11-14 21:18:41 +0000 | [diff] [blame] | 33 | public: |
commit-queue@webkit.org | 335a0ed | 2019-03-20 00:59:50 +0000 | [diff] [blame] | 34 | static Ref<SVGRect> create(const FloatRect& value = { }) |
zimmermann@webkit.org | bcebe57 | 2010-12-01 08:57:20 +0000 | [diff] [blame] | 35 | { |
commit-queue@webkit.org | 335a0ed | 2019-03-20 00:59:50 +0000 | [diff] [blame] | 36 | return adoptRef(*new SVGRect(value)); |
weinig@apple.com | f786730 | 2016-11-14 21:18:41 +0000 | [diff] [blame] | 37 | } |
| 38 | |
commit-queue@webkit.org | 335a0ed | 2019-03-20 00:59:50 +0000 | [diff] [blame] | 39 | static Ref<SVGRect> create(SVGPropertyOwner* owner, SVGPropertyAccess access, const FloatRect& value = { }) |
weinig@apple.com | f786730 | 2016-11-14 21:18:41 +0000 | [diff] [blame] | 40 | { |
commit-queue@webkit.org | 335a0ed | 2019-03-20 00:59:50 +0000 | [diff] [blame] | 41 | return adoptRef(*new SVGRect(owner, access, value)); |
weinig@apple.com | f786730 | 2016-11-14 21:18:41 +0000 | [diff] [blame] | 42 | } |
| 43 | |
commit-queue@webkit.org | 335a0ed | 2019-03-20 00:59:50 +0000 | [diff] [blame] | 44 | template<typename T> |
| 45 | static ExceptionOr<Ref<SVGRect>> create(ExceptionOr<T>&& value) |
weinig@apple.com | f786730 | 2016-11-14 21:18:41 +0000 | [diff] [blame] | 46 | { |
commit-queue@webkit.org | 335a0ed | 2019-03-20 00:59:50 +0000 | [diff] [blame] | 47 | if (value.hasException()) |
| 48 | return value.releaseException(); |
| 49 | return adoptRef(*new SVGRect(value.releaseReturnValue())); |
weinig@apple.com | f786730 | 2016-11-14 21:18:41 +0000 | [diff] [blame] | 50 | } |
| 51 | |
commit-queue@webkit.org | 335a0ed | 2019-03-20 00:59:50 +0000 | [diff] [blame] | 52 | float x() { return m_value.x(); } |
weinig@apple.com | f786730 | 2016-11-14 21:18:41 +0000 | [diff] [blame] | 53 | |
| 54 | ExceptionOr<void> setX(float xValue) |
| 55 | { |
| 56 | if (isReadOnly()) |
cdumez@apple.com | 750df37 | 2017-07-25 03:59:12 +0000 | [diff] [blame] | 57 | return Exception { NoModificationAllowedError }; |
weinig@apple.com | f786730 | 2016-11-14 21:18:41 +0000 | [diff] [blame] | 58 | |
commit-queue@webkit.org | 335a0ed | 2019-03-20 00:59:50 +0000 | [diff] [blame] | 59 | m_value.setX(xValue); |
weinig@apple.com | f786730 | 2016-11-14 21:18:41 +0000 | [diff] [blame] | 60 | commitChange(); |
weinig@apple.com | f786730 | 2016-11-14 21:18:41 +0000 | [diff] [blame] | 61 | return { }; |
| 62 | } |
| 63 | |
commit-queue@webkit.org | 335a0ed | 2019-03-20 00:59:50 +0000 | [diff] [blame] | 64 | float y() { return m_value.y(); } |
weinig@apple.com | f786730 | 2016-11-14 21:18:41 +0000 | [diff] [blame] | 65 | |
| 66 | ExceptionOr<void> setY(float xValue) |
| 67 | { |
| 68 | if (isReadOnly()) |
cdumez@apple.com | 750df37 | 2017-07-25 03:59:12 +0000 | [diff] [blame] | 69 | return Exception { NoModificationAllowedError }; |
weinig@apple.com | f786730 | 2016-11-14 21:18:41 +0000 | [diff] [blame] | 70 | |
commit-queue@webkit.org | 335a0ed | 2019-03-20 00:59:50 +0000 | [diff] [blame] | 71 | m_value.setY(xValue); |
weinig@apple.com | f786730 | 2016-11-14 21:18:41 +0000 | [diff] [blame] | 72 | commitChange(); |
weinig@apple.com | f786730 | 2016-11-14 21:18:41 +0000 | [diff] [blame] | 73 | return { }; |
| 74 | } |
| 75 | |
commit-queue@webkit.org | 335a0ed | 2019-03-20 00:59:50 +0000 | [diff] [blame] | 76 | float width() { return m_value.width(); } |
weinig@apple.com | f786730 | 2016-11-14 21:18:41 +0000 | [diff] [blame] | 77 | |
| 78 | ExceptionOr<void> setWidth(float widthValue) |
| 79 | { |
| 80 | if (isReadOnly()) |
cdumez@apple.com | 750df37 | 2017-07-25 03:59:12 +0000 | [diff] [blame] | 81 | return Exception { NoModificationAllowedError }; |
weinig@apple.com | f786730 | 2016-11-14 21:18:41 +0000 | [diff] [blame] | 82 | |
commit-queue@webkit.org | 335a0ed | 2019-03-20 00:59:50 +0000 | [diff] [blame] | 83 | m_value.setWidth(widthValue); |
weinig@apple.com | f786730 | 2016-11-14 21:18:41 +0000 | [diff] [blame] | 84 | commitChange(); |
weinig@apple.com | f786730 | 2016-11-14 21:18:41 +0000 | [diff] [blame] | 85 | return { }; |
| 86 | } |
| 87 | |
commit-queue@webkit.org | 335a0ed | 2019-03-20 00:59:50 +0000 | [diff] [blame] | 88 | float height() { return m_value.height(); } |
weinig@apple.com | f786730 | 2016-11-14 21:18:41 +0000 | [diff] [blame] | 89 | |
| 90 | ExceptionOr<void> setHeight(float heightValue) |
| 91 | { |
| 92 | if (isReadOnly()) |
cdumez@apple.com | 750df37 | 2017-07-25 03:59:12 +0000 | [diff] [blame] | 93 | return Exception { NoModificationAllowedError }; |
weinig@apple.com | f786730 | 2016-11-14 21:18:41 +0000 | [diff] [blame] | 94 | |
commit-queue@webkit.org | 335a0ed | 2019-03-20 00:59:50 +0000 | [diff] [blame] | 95 | m_value.setHeight(heightValue); |
weinig@apple.com | f786730 | 2016-11-14 21:18:41 +0000 | [diff] [blame] | 96 | commitChange(); |
weinig@apple.com | f786730 | 2016-11-14 21:18:41 +0000 | [diff] [blame] | 97 | return { }; |
| 98 | } |
commit-queue@webkit.org | 335a0ed | 2019-03-20 00:59:50 +0000 | [diff] [blame] | 99 | |
| 100 | String valueAsString() const override |
weinig@apple.com | f786730 | 2016-11-14 21:18:41 +0000 | [diff] [blame] | 101 | { |
commit-queue@webkit.org | 335a0ed | 2019-03-20 00:59:50 +0000 | [diff] [blame] | 102 | return SVGPropertyTraits<FloatRect>::toString(m_value); |
weinig@apple.com | f786730 | 2016-11-14 21:18:41 +0000 | [diff] [blame] | 103 | } |
zimmermann@webkit.org | bcebe57 | 2010-12-01 08:57:20 +0000 | [diff] [blame] | 104 | }; |
| 105 | |
commit-queue@webkit.org | 335a0ed | 2019-03-20 00:59:50 +0000 | [diff] [blame] | 106 | } |