SVGPreserveAspectRatio.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "SVGPreserveAspectRatio.h"
  6. #include "SVGAnimatedPreserveAspectRatio.h"
  7. #include "mozilla/dom/SVGPreserveAspectRatioBinding.h"
  8. using namespace mozilla;
  9. using namespace dom;
  10. NS_SVG_VAL_IMPL_CYCLE_COLLECTION_WRAPPERCACHED(DOMSVGPreserveAspectRatio, mSVGElement)
  11. NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMSVGPreserveAspectRatio)
  12. NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMSVGPreserveAspectRatio)
  13. NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMSVGPreserveAspectRatio)
  14. NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
  15. NS_INTERFACE_MAP_ENTRY(nsISupports)
  16. NS_INTERFACE_MAP_END
  17. bool
  18. SVGPreserveAspectRatio::operator==(const SVGPreserveAspectRatio& aOther) const
  19. {
  20. return mAlign == aOther.mAlign &&
  21. mMeetOrSlice == aOther.mMeetOrSlice;
  22. }
  23. JSObject*
  24. DOMSVGPreserveAspectRatio::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
  25. {
  26. return mozilla::dom::SVGPreserveAspectRatioBinding::Wrap(aCx, this, aGivenProto);
  27. }
  28. uint16_t
  29. DOMSVGPreserveAspectRatio::Align()
  30. {
  31. if (mIsBaseValue) {
  32. return mVal->GetBaseValue().GetAlign();
  33. }
  34. mSVGElement->FlushAnimations();
  35. return mVal->GetAnimValue().GetAlign();
  36. }
  37. void
  38. DOMSVGPreserveAspectRatio::SetAlign(uint16_t aAlign, ErrorResult& rv)
  39. {
  40. if (!mIsBaseValue) {
  41. rv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
  42. return;
  43. }
  44. rv = mVal->SetBaseAlign(aAlign, mSVGElement);
  45. }
  46. uint16_t
  47. DOMSVGPreserveAspectRatio::MeetOrSlice()
  48. {
  49. if (mIsBaseValue) {
  50. return mVal->GetBaseValue().GetMeetOrSlice();
  51. }
  52. mSVGElement->FlushAnimations();
  53. return mVal->GetAnimValue().GetMeetOrSlice();
  54. }
  55. void
  56. DOMSVGPreserveAspectRatio::SetMeetOrSlice(uint16_t aMeetOrSlice, ErrorResult& rv)
  57. {
  58. if (!mIsBaseValue) {
  59. rv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
  60. return;
  61. }
  62. rv = mVal->SetBaseMeetOrSlice(aMeetOrSlice, mSVGElement);
  63. }