tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

SVGSwitchElement.cpp (3092B)


      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/. */
      6 
      7 #include "mozilla/dom/SVGSwitchElement.h"
      8 
      9 #include "mozilla/SVGUtils.h"
     10 #include "mozilla/dom/SVGSwitchElementBinding.h"
     11 #include "nsLayoutUtils.h"
     12 
     13 class nsIFrame;
     14 
     15 NS_IMPL_NS_NEW_SVG_ELEMENT(Switch)
     16 
     17 namespace mozilla::dom {
     18 
     19 JSObject* SVGSwitchElement::WrapNode(JSContext* aCx,
     20                                     JS::Handle<JSObject*> aGivenProto) {
     21  return SVGSwitchElement_Binding::Wrap(aCx, this, aGivenProto);
     22 }
     23 
     24 //----------------------------------------------------------------------
     25 // nsISupports methods
     26 
     27 NS_IMPL_CYCLE_COLLECTION_INHERITED(SVGSwitchElement, SVGSwitchElementBase,
     28                                   mActiveChild)
     29 
     30 NS_IMPL_ADDREF_INHERITED(SVGSwitchElement, SVGSwitchElementBase)
     31 NS_IMPL_RELEASE_INHERITED(SVGSwitchElement, SVGSwitchElementBase)
     32 
     33 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SVGSwitchElement)
     34 NS_INTERFACE_MAP_END_INHERITING(SVGSwitchElementBase)
     35 
     36 //----------------------------------------------------------------------
     37 // Implementation
     38 
     39 SVGSwitchElement::SVGSwitchElement(
     40    already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
     41    : SVGSwitchElementBase(std::move(aNodeInfo)) {}
     42 
     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.
     47 
     48  auto* newActiveChild = SVGTests::FindActiveSwitchChild(this);
     49 
     50  if (newActiveChild == mActiveChild) {
     51    return;
     52  }
     53 
     54  if (auto* frame = GetPrimaryFrame()) {
     55    nsLayoutUtils::PostRestyleEvent(this, RestyleHint{0},
     56                                    nsChangeHint_InvalidateRenderingObservers);
     57    SVGUtils::ScheduleReflowSVG(frame);
     58  }
     59 
     60  mActiveChild = newActiveChild;
     61 }
     62 
     63 //----------------------------------------------------------------------
     64 // nsINode methods
     65 
     66 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGSwitchElement)
     67 
     68 //----------------------------------------------------------------------
     69 // nsINode methods
     70 
     71 void SVGSwitchElement::InsertChildBefore(
     72    nsIContent* aKid, nsIContent* aBeforeThis, bool aNotify, ErrorResult& aRv,
     73    nsINode* aOldParent, MutationEffectOnScript aMutationEffectOnScript) {
     74  SVGSwitchElementBase::InsertChildBefore(aKid, aBeforeThis, aNotify, aRv,
     75                                          aOldParent, aMutationEffectOnScript);
     76  if (aRv.Failed()) {
     77    return;
     78  }
     79 
     80  MaybeInvalidate();
     81 }
     82 
     83 void SVGSwitchElement::RemoveChildNode(
     84    nsIContent* aKid, bool aNotify, const BatchRemovalState* aState,
     85    nsINode* aNewParent, MutationEffectOnScript aMutationEffectOnScript) {
     86  SVGSwitchElementBase::RemoveChildNode(aKid, aNotify, aState, aNewParent,
     87                                        aMutationEffectOnScript);
     88  MaybeInvalidate();
     89 }
     90 
     91 }  // namespace mozilla::dom