Bug 1936278 - Prevent search mode chiclet from being dismissed when clicking in page...
[gecko.git] / dom / svg / SVGSwitchElement.cpp
bloba19dfd8631f923e73632dd25050ef5a5cebb797e
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"
13 class nsIFrame;
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,
28 mActiveChild)
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 //----------------------------------------------------------------------
37 // Implementation
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) {
51 return;
54 if (auto* frame = GetPrimaryFrame()) {
55 nsLayoutUtils::PostRestyleEvent(this, RestyleHint{0},
56 nsChangeHint_InvalidateRenderingObservers);
57 SVGUtils::ScheduleReflowSVG(frame);
60 mActiveChild = newActiveChild;
63 //----------------------------------------------------------------------
64 // nsINode methods
66 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGSwitchElement)
68 //----------------------------------------------------------------------
69 // nsINode methods
71 void SVGSwitchElement::InsertChildBefore(nsIContent* aKid,
72 nsIContent* aBeforeThis, bool aNotify,
73 ErrorResult& aRv) {
74 SVGSwitchElementBase::InsertChildBefore(aKid, aBeforeThis, aNotify, aRv);
75 if (aRv.Failed()) {
76 return;
79 MaybeInvalidate();
82 void SVGSwitchElement::RemoveChildNode(nsIContent* aKid, bool aNotify) {
83 SVGSwitchElementBase::RemoveChildNode(aKid, aNotify);
84 MaybeInvalidate();
87 } // namespace mozilla::dom