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 "mozilla/dom/SVGSwitchElement.h"
9 #include "nsLayoutUtils.h"
10 #include "mozilla/SVGUtils.h"
11 #include "mozilla/dom/SVGSwitchElementBinding.h"
15 NS_IMPL_NS_NEW_SVG_ELEMENT(Switch
)
17 namespace mozilla::dom
{
19 JSObject
* SVGSwitchElement::WrapNode(JSContext
* aCx
,
20 JS::Handle
<JSObject
*> aGivenProto
) {
21 return SVGSwitchElement_Binding::Wrap(aCx
, this, aGivenProto
);
24 //----------------------------------------------------------------------
25 // nsISupports methods
27 NS_IMPL_CYCLE_COLLECTION_INHERITED(SVGSwitchElement
, SVGSwitchElementBase
,
30 NS_IMPL_ADDREF_INHERITED(SVGSwitchElement
, SVGSwitchElementBase
)
31 NS_IMPL_RELEASE_INHERITED(SVGSwitchElement
, SVGSwitchElementBase
)
33 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SVGSwitchElement
)
34 NS_INTERFACE_MAP_END_INHERITING(SVGSwitchElementBase
)
36 //----------------------------------------------------------------------
39 SVGSwitchElement::SVGSwitchElement(
40 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
)
41 : SVGSwitchElementBase(std::move(aNodeInfo
)) {}
43 void SVGSwitchElement::MaybeInvalidate() {
44 // We must not change mActiveChild until after
45 // InvalidateAndScheduleBoundsUpdate has been called, otherwise
46 // it will not correctly invalidate the old mActiveChild area.
48 auto* newActiveChild
= SVGTests::FindActiveSwitchChild(this);
50 if (newActiveChild
== mActiveChild
) {
54 if (auto* frame
= GetPrimaryFrame()) {
55 nsLayoutUtils::PostRestyleEvent(this, RestyleHint
{0},
56 nsChangeHint_InvalidateRenderingObservers
);
57 SVGUtils::ScheduleReflowSVG(frame
);
60 mActiveChild
= newActiveChild
;
63 //----------------------------------------------------------------------
66 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGSwitchElement
)
68 //----------------------------------------------------------------------
71 void SVGSwitchElement::InsertChildBefore(nsIContent
* aKid
,
72 nsIContent
* aBeforeThis
, bool aNotify
,
74 SVGSwitchElementBase::InsertChildBefore(aKid
, aBeforeThis
, aNotify
, aRv
);
82 void SVGSwitchElement::RemoveChildNode(nsIContent
* aKid
, bool aNotify
) {
83 SVGSwitchElementBase::RemoveChildNode(aKid
, aNotify
);
87 } // namespace mozilla::dom