/* THIS FILE IS AUTOGENERATED FROM Element.webidl BY Codegen.py - DO NOT EDIT */

#ifndef mozilla_dom_ElementBinding_h
#define mozilla_dom_ElementBinding_h

#include "ShadowRootBinding.h"
#include "WindowBinding.h"
#include "js/RootingAPI.h"
#include "jspubtd.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/FakeString.h"
#include "mozilla/dom/Nullable.h"
#include "mozilla/dom/UnionMember.h"

namespace mozilla {
namespace dom {

class Element;
struct ElementAtoms;
struct NativePropertyHooks;
class ProtoAndIfaceCache;
struct ScrollIntoViewOptionsAtoms;
struct ShadowRootInitAtoms;

} // namespace dom
} // namespace mozilla

namespace mozilla {
namespace dom {

enum class ScrollLogicalPosition : uint32_t {
  Start,
  Center,
  End,
  Nearest,
  EndGuard_
};

namespace ScrollLogicalPositionValues {
extern const EnumEntry strings[5];
} // namespace ScrollLogicalPositionValues

bool
ToJSValue(JSContext* aCx, ScrollLogicalPosition aArgument, JS::MutableHandle<JS::Value> aValue);


struct ScrollIntoViewOptions : public ScrollOptions
{
  MOZ_INIT_OUTSIDE_CTOR ScrollLogicalPosition mBlock;
  MOZ_INIT_OUTSIDE_CTOR ScrollLogicalPosition mInline;

  ScrollIntoViewOptions();

  explicit inline ScrollIntoViewOptions(const FastDictionaryInitializer& )
    : ScrollOptions(FastDictionaryInitializer())
  {
    // Do nothing here; this is used by our "Fast" subclass
  }

  explicit inline ScrollIntoViewOptions(const ScrollIntoViewOptions& aOther)
  {
    *this = aOther;
  }

  bool
  Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription = "Value", bool passedToJSImpl = false);

  bool
  Init(const nsAString& aJSON);

  bool
  ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const;

  bool
  ToJSON(nsAString& aJSON) const;

  void
  TraceDictionary(JSTracer* trc);

  void
  operator=(const ScrollIntoViewOptions& aOther);

private:
  static bool
  InitIds(JSContext* cx, ScrollIntoViewOptionsAtoms* atomsCache);
};

namespace binding_detail {
struct FastScrollIntoViewOptions : public ScrollIntoViewOptions
{
  inline FastScrollIntoViewOptions()
    : ScrollIntoViewOptions(FastDictionaryInitializer())
  {
    // Doesn't matter what int we pass to the parent constructor
  }
};
} // namespace binding_detail


struct ShadowRootInit : public DictionaryBase
{
  MOZ_INIT_OUTSIDE_CTOR ShadowRootMode mMode;

  ShadowRootInit();

  explicit inline ShadowRootInit(const FastDictionaryInitializer& )
  {
    // Do nothing here; this is used by our "Fast" subclass
  }

  explicit inline ShadowRootInit(const ShadowRootInit& aOther)
  {
    *this = aOther;
  }

  bool
  Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription = "Value", bool passedToJSImpl = false);

  bool
  Init(const nsAString& aJSON);

  bool
  ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const;

  bool
  ToJSON(nsAString& aJSON) const;

  void
  TraceDictionary(JSTracer* trc);

  void
  operator=(const ShadowRootInit& aOther);

private:
  static bool
  InitIds(JSContext* cx, ShadowRootInitAtoms* atomsCache);
};

namespace binding_detail {
struct FastShadowRootInit : public ShadowRootInit
{
  inline FastShadowRootInit()
    : ShadowRootInit(FastDictionaryInitializer())
  {
    // Doesn't matter what int we pass to the parent constructor
  }
};
} // namespace binding_detail


class BooleanOrScrollIntoViewOptions
{
  friend class BooleanOrScrollIntoViewOptionsArgument;
  enum Type
  {
    eUninitialized,
    eBoolean,
    eScrollIntoViewOptions
  };

  union Value
  {
    UnionMember<bool > mBoolean;
    UnionMember<binding_detail::FastScrollIntoViewOptions > mScrollIntoViewOptions;

  };

  Type mType;
  Value mValue;

  BooleanOrScrollIntoViewOptions(const BooleanOrScrollIntoViewOptions&) = delete;
  void operator=(const BooleanOrScrollIntoViewOptions&) = delete;
public:
  explicit inline BooleanOrScrollIntoViewOptions()
    : mType(eUninitialized)
  {
  }

  inline ~BooleanOrScrollIntoViewOptions()
  {
    Uninit();
  }

  inline bool&
  RawSetAsBoolean()
  {
    if (mType == eBoolean) {
      return mValue.mBoolean.Value();
    }
    MOZ_ASSERT(mType == eUninitialized);
    mType = eBoolean;
    return mValue.mBoolean.SetValue();
  }

  inline bool&
  SetAsBoolean()
  {
    if (mType == eBoolean) {
      return mValue.mBoolean.Value();
    }
    Uninit();
    mType = eBoolean;
    return mValue.mBoolean.SetValue();
  }

  inline bool
  IsBoolean() const
  {
    return mType == eBoolean;
  }

  inline bool&
  GetAsBoolean()
  {
    MOZ_ASSERT(IsBoolean(), "Wrong type!");
    return mValue.mBoolean.Value();
  }

  inline bool
  GetAsBoolean() const
  {
    MOZ_ASSERT(IsBoolean(), "Wrong type!");
    return mValue.mBoolean.Value();
  }

  inline binding_detail::FastScrollIntoViewOptions&
  RawSetAsScrollIntoViewOptions()
  {
    if (mType == eScrollIntoViewOptions) {
      return mValue.mScrollIntoViewOptions.Value();
    }
    MOZ_ASSERT(mType == eUninitialized);
    mType = eScrollIntoViewOptions;
    return mValue.mScrollIntoViewOptions.SetValue();
  }

  inline binding_detail::FastScrollIntoViewOptions&
  SetAsScrollIntoViewOptions()
  {
    if (mType == eScrollIntoViewOptions) {
      return mValue.mScrollIntoViewOptions.Value();
    }
    Uninit();
    mType = eScrollIntoViewOptions;
    return mValue.mScrollIntoViewOptions.SetValue();
  }

  inline bool
  IsScrollIntoViewOptions() const
  {
    return mType == eScrollIntoViewOptions;
  }

  inline binding_detail::FastScrollIntoViewOptions&
  GetAsScrollIntoViewOptions()
  {
    MOZ_ASSERT(IsScrollIntoViewOptions(), "Wrong type!");
    return mValue.mScrollIntoViewOptions.Value();
  }

  inline const ScrollIntoViewOptions&
  GetAsScrollIntoViewOptions() const
  {
    MOZ_ASSERT(IsScrollIntoViewOptions(), "Wrong type!");
    return mValue.mScrollIntoViewOptions.Value();
  }

  inline void
  Uninit()
  {
    switch (mType) {
      case eUninitialized: {
        break;
      }
      case eBoolean: {
        DestroyBoolean();
        break;
      }
      case eScrollIntoViewOptions: {
        DestroyScrollIntoViewOptions();
        break;
      }
    }
  }

  bool
  ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const;

private:
  inline void
  DestroyBoolean()
  {
    MOZ_ASSERT(IsBoolean(), "Wrong type!");
    mValue.mBoolean.Destroy();
    mType = eUninitialized;
  }

  inline void
  DestroyScrollIntoViewOptions()
  {
    MOZ_ASSERT(IsScrollIntoViewOptions(), "Wrong type!");
    mValue.mScrollIntoViewOptions.Destroy();
    mType = eUninitialized;
  }
};


class OwningBooleanOrScrollIntoViewOptions : public AllOwningUnionBase
{
  friend void ImplCycleCollectionUnlink(OwningBooleanOrScrollIntoViewOptions& aUnion);
  enum Type
  {
    eUninitialized,
    eBoolean,
    eScrollIntoViewOptions
  };

  union Value
  {
    UnionMember<bool > mBoolean;
    UnionMember<ScrollIntoViewOptions > mScrollIntoViewOptions;

  };

  Type mType;
  Value mValue;

public:
  explicit inline OwningBooleanOrScrollIntoViewOptions()
    : mType(eUninitialized)
  {
  }

  explicit inline OwningBooleanOrScrollIntoViewOptions(const OwningBooleanOrScrollIntoViewOptions& aOther)
    : mType(eUninitialized)
  {
    *this = aOther;
  }

  inline ~OwningBooleanOrScrollIntoViewOptions()
  {
    Uninit();
  }

  bool&
  RawSetAsBoolean();

  bool&
  SetAsBoolean();

  bool
  TrySetToBoolean(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);

  inline bool
  IsBoolean() const
  {
    return mType == eBoolean;
  }

  inline bool&
  GetAsBoolean()
  {
    MOZ_ASSERT(IsBoolean(), "Wrong type!");
    return mValue.mBoolean.Value();
  }

  inline bool const &
  GetAsBoolean() const
  {
    MOZ_ASSERT(IsBoolean(), "Wrong type!");
    return mValue.mBoolean.Value();
  }

  ScrollIntoViewOptions&
  RawSetAsScrollIntoViewOptions();

  ScrollIntoViewOptions&
  SetAsScrollIntoViewOptions();

  bool
  TrySetToScrollIntoViewOptions(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);

  inline bool
  IsScrollIntoViewOptions() const
  {
    return mType == eScrollIntoViewOptions;
  }

  inline ScrollIntoViewOptions&
  GetAsScrollIntoViewOptions()
  {
    MOZ_ASSERT(IsScrollIntoViewOptions(), "Wrong type!");
    return mValue.mScrollIntoViewOptions.Value();
  }

  inline ScrollIntoViewOptions const &
  GetAsScrollIntoViewOptions() const
  {
    MOZ_ASSERT(IsScrollIntoViewOptions(), "Wrong type!");
    return mValue.mScrollIntoViewOptions.Value();
  }

  void
  Uninit();

  bool
  ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const;

  void
  TraceUnion(JSTracer* trc);

  void
  operator=(const OwningBooleanOrScrollIntoViewOptions& aOther);

private:
  void
  DestroyBoolean();

  void
  DestroyScrollIntoViewOptions();
};


namespace ElementBinding {

  typedef mozilla::dom::Element NativeType;

  JSObject*
  DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal);

  const JSClass*
  GetJSClass();

  bool
  Wrap(JSContext* aCx, mozilla::dom::Element* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector);

  template <class T>
  inline JSObject* Wrap(JSContext* aCx, T* aObject, JS::Handle<JSObject*> aGivenProto)
  {
    JS::Rooted<JSObject*> reflector(aCx);
    return Wrap(aCx, aObject, aObject, aGivenProto, &reflector) ? reflector.get() : nullptr;
  }

  // We declare this as an array so that retrieving a pointer to this
  // binding's property hooks only requires compile/link-time resolvable
  // address arithmetic.  Declaring it as a pointer instead would require
  // doing a run-time load to fetch a pointer to this binding's property
  // hooks.  And then structures which embedded a pointer to this structure
  // would require a run-time load for proper initialization, which would
  // then induce static constructors.  Lots of static constructors.
  extern const NativePropertyHooks sNativePropertyHooks[];

  void
  CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal);

  JS::Handle<JSObject*>
  GetProtoObjectHandle(JSContext* aCx);

  JSObject*
  GetProtoObject(JSContext* aCx);

  JS::Handle<JSObject*>
  GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal = true);

  JSObject*
  GetConstructorObject(JSContext* aCx);

} // namespace ElementBinding



} // namespace dom
} // namespace mozilla

#endif // mozilla_dom_ElementBinding_h
