Bug 1936278 - Prevent search mode chiclet from being dismissed when clicking in page...
[gecko.git] / dom / svg / SVGAnimatedString.cpp
blob25eb68b49b7aef6035ca3b0279be94fc8d1837c8
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "SVGAnimatedString.h"
9 #include <utility>
11 #include "SMILStringType.h"
12 #include "SVGAttrTearoffTable.h"
13 #include "mozilla/SMILValue.h"
15 using namespace mozilla::dom;
17 namespace mozilla {
19 /* Implementation */
21 void SVGAnimatedString::SetBaseValue(const nsAString& aValue,
22 SVGElement* aSVGElement, bool aDoSetAttr) {
23 NS_ASSERTION(aSVGElement, "Null element passed to SetBaseValue");
25 mIsBaseSet = true;
26 if (aDoSetAttr) {
27 aSVGElement->SetStringBaseValue(mAttrEnum, aValue);
29 if (mAnimVal) {
30 aSVGElement->AnimationNeedsResample();
33 aSVGElement->DidChangeString(mAttrEnum);
36 void SVGAnimatedString::GetAnimValue(nsAString& aResult,
37 const SVGElement* aSVGElement) const {
38 if (mAnimVal) {
39 aResult = *mAnimVal;
40 return;
43 aSVGElement->GetStringBaseValue(mAttrEnum, aResult);
46 void SVGAnimatedString::SetAnimValue(const nsAString& aValue,
47 SVGElement* aSVGElement) {
48 if (aSVGElement->IsStringAnimatable(mAttrEnum)) {
49 if (mAnimVal && mAnimVal->Equals(aValue)) {
50 return;
52 if (!mAnimVal) {
53 mAnimVal = MakeUnique<nsString>();
55 *mAnimVal = aValue;
56 aSVGElement->DidAnimateString(mAttrEnum);
60 UniquePtr<SMILAttr> SVGAnimatedString::ToSMILAttr(SVGElement* aSVGElement) {
61 return MakeUnique<SMILString>(this, aSVGElement);
64 nsresult SVGAnimatedString::SMILString::ValueFromString(
65 const nsAString& aStr, const dom::SVGAnimationElement* /*aSrcElement*/,
66 SMILValue& aValue, bool& aPreventCachingOfSandwich) const {
67 SMILValue val(SMILStringType::Singleton());
69 *static_cast<nsAString*>(val.mU.mPtr) = aStr;
70 aValue = std::move(val);
71 return NS_OK;
74 SMILValue SVGAnimatedString::SMILString::GetBaseValue() const {
75 SMILValue val(SMILStringType::Singleton());
76 mSVGElement->GetStringBaseValue(mVal->mAttrEnum,
77 *static_cast<nsAString*>(val.mU.mPtr));
78 return val;
81 void SVGAnimatedString::SMILString::ClearAnimValue() {
82 if (mVal->mAnimVal) {
83 mVal->mAnimVal = nullptr;
84 mSVGElement->DidAnimateString(mVal->mAttrEnum);
88 nsresult SVGAnimatedString::SMILString::SetAnimValue(const SMILValue& aValue) {
89 NS_ASSERTION(aValue.mType == SMILStringType::Singleton(),
90 "Unexpected type to assign animated value");
91 if (aValue.mType == SMILStringType::Singleton()) {
92 mVal->SetAnimValue(*static_cast<nsAString*>(aValue.mU.mPtr), mSVGElement);
94 return NS_OK;
97 } // namespace mozilla