// third_party/blink/public/mojom/widget/device_emulation_params.mojom-shared.h is auto generated by mojom_bindings_generator.py, do not edit

// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_PUBLIC_MOJOM_WIDGET_DEVICE_EMULATION_PARAMS_MOJOM_SHARED_H_
#define THIRD_PARTY_BLINK_PUBLIC_MOJOM_WIDGET_DEVICE_EMULATION_PARAMS_MOJOM_SHARED_H_

#include <stdint.h>

#include <functional>
#include <iosfwd>
#include <type_traits>
#include <utility>
#include "mojo/public/cpp/bindings/array_data_view.h"
#include "mojo/public/cpp/bindings/map_data_view.h"
#include "mojo/public/cpp/bindings/string_data_view.h"
#include "mojo/public/cpp/system/message_pipe.h"

#include "third_party/perfetto/include/perfetto/tracing/traced_value_forward.h"

#include "third_party/blink/public/mojom/widget/device_emulation_params.mojom-shared-internal.h"
#include "third_party/blink/public/mojom/device_posture/device_posture_provider.mojom-shared.h"
#include "ui/gfx/geometry/mojom/geometry.mojom-shared.h"
#include "ui/display/mojom/screen_orientation.mojom-shared.h"




#include "third_party/blink/public/mojom/widget/device_emulation_params.mojom-data-view.h"  // IWYU pragma: export
#include "base/component_export.h"




namespace std {

template <>
struct hash<::blink::mojom::EmulatedScreenType>
    : public mojo::internal::EnumHashImpl<::blink::mojom::EmulatedScreenType> {};

}  // namespace std

namespace mojo {


namespace internal {

template <typename MaybeConstUserType>
struct Serializer<::blink::mojom::EmulatedScreenType, MaybeConstUserType> {
  using UserType = typename std::remove_const<MaybeConstUserType>::type;
  using Traits = EnumTraits<::blink::mojom::EmulatedScreenType, UserType>;

  static void Serialize(UserType input, int32_t* output) {
    *output = static_cast<int32_t>(Traits::ToMojom(input));
  }

  static bool Deserialize(int32_t input, UserType* output) {
    auto known_value = ::mojo::internal::ToKnownEnumValueHelper(
        static_cast<::blink::mojom::EmulatedScreenType>(input));
    if constexpr (requires {
                    {
                      Traits::FromMojom(known_value)
                    } -> std::same_as<UserType>;
                  }) {
      static_assert(std::same_as<::blink::mojom::EmulatedScreenType, UserType> ||
                        HasInfallibleConversion(::blink::mojom::EmulatedScreenType()),
                    "::blink::mojom::EmulatedScreenType does not have an infallible conversion, "
                    "use an optional return type.");
      *output = Traits::FromMojom(known_value);
      return true;
    } else {
      static_assert(
          requires {
            {
              Traits::FromMojom(known_value)
            } -> std::same_as<std::optional<UserType>>;
          }, "FromMojom must return by value or optional.");
      std::optional<UserType> from_mojom = Traits::FromMojom(known_value);
      if (from_mojom) {
        *output = *from_mojom;
      }
      return from_mojom.has_value();
    }
  }
};

}  // namespace internal


namespace internal {

template <typename MaybeConstUserType>
struct Serializer<::blink::mojom::DeviceEmulationParamsDataView, MaybeConstUserType> {
  using UserType = typename std::remove_const<MaybeConstUserType>::type;
  using Traits = StructTraits<::blink::mojom::DeviceEmulationParamsDataView, UserType>;

  static void Serialize(
      MaybeConstUserType& input,
      mojo::internal::MessageFragment<::blink::mojom::internal::DeviceEmulationParams_Data>& fragment) {
    if (CallIsNullIfExists<Traits>(input))
      return;
    fragment.Allocate();

    
    mojo::internal::Serialize<::blink::mojom::EmulatedScreenType>(
      Traits::screen_type(input),
      &fragment->screen_type);

    decltype(Traits::screen_size(input)) in_screen_size = Traits::screen_size(input);
    mojo::internal::MessageFragment<
        typename decltype(fragment->screen_size)::BaseType> screen_size_fragment(
            fragment.message());
    
    mojo::internal::Serialize<::gfx::mojom::SizeDataView>(
      in_screen_size,
      screen_size_fragment);

    fragment->screen_size.Set(
        screen_size_fragment.is_null() ? nullptr : screen_size_fragment.data());

    
    MOJO_INTERNAL_CHECK_SERIALIZATION(
      mojo::internal::SendValidation::kDefault,
      !(fragment->screen_size.is_null()),
      mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
      "null screen_size in DeviceEmulationParams struct");

    decltype(Traits::view_position(input)) in_view_position = Traits::view_position(input);
    mojo::internal::MessageFragment<
        typename decltype(fragment->view_position)::BaseType> view_position_fragment(
            fragment.message());
    
    mojo::internal::Serialize<::gfx::mojom::PointDataView>(
      in_view_position,
      view_position_fragment);

    fragment->view_position.Set(
        view_position_fragment.is_null() ? nullptr : view_position_fragment.data());

    decltype(Traits::view_size(input)) in_view_size = Traits::view_size(input);
    mojo::internal::MessageFragment<
        typename decltype(fragment->view_size)::BaseType> view_size_fragment(
            fragment.message());
    
    mojo::internal::Serialize<::gfx::mojom::SizeDataView>(
      in_view_size,
      view_size_fragment);

    fragment->view_size.Set(
        view_size_fragment.is_null() ? nullptr : view_size_fragment.data());

    
    MOJO_INTERNAL_CHECK_SERIALIZATION(
      mojo::internal::SendValidation::kDefault,
      !(fragment->view_size.is_null()),
      mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
      "null view_size in DeviceEmulationParams struct");

    fragment->device_scale_factor = Traits::device_scale_factor(input);

    fragment->scale = Traits::scale(input);

    decltype(Traits::viewport_offset(input)) in_viewport_offset = Traits::viewport_offset(input);
    mojo::internal::MessageFragment<
        typename decltype(fragment->viewport_offset)::BaseType> viewport_offset_fragment(
            fragment.message());
    
    mojo::internal::Serialize<::gfx::mojom::PointFDataView>(
      in_viewport_offset,
      viewport_offset_fragment);

    fragment->viewport_offset.Set(
        viewport_offset_fragment.is_null() ? nullptr : viewport_offset_fragment.data());

    
    MOJO_INTERNAL_CHECK_SERIALIZATION(
      mojo::internal::SendValidation::kDefault,
      !(fragment->viewport_offset.is_null()),
      mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
      "null viewport_offset in DeviceEmulationParams struct");

    fragment->viewport_scale = Traits::viewport_scale(input);

    
    mojo::internal::Serialize<::display::mojom::ScreenOrientation>(
      Traits::screen_orientation_type(input),
      &fragment->screen_orientation_type);

    fragment->screen_orientation_angle = Traits::screen_orientation_angle(input);

    decltype(Traits::viewport_segments(input)) in_viewport_segments = Traits::viewport_segments(input);
    mojo::internal::MessageFragment<
        typename decltype(fragment->viewport_segments)::BaseType>
        viewport_segments_fragment(fragment.message());
    constexpr const mojo::internal::ContainerValidateParams& viewport_segments_validate_params =
        mojo::internal::GetArrayValidator<0, false, nullptr>();
    
    mojo::internal::Serialize<mojo::ArrayDataView<::gfx::mojom::RectDataView>>(
      in_viewport_segments,
      viewport_segments_fragment,
      &viewport_segments_validate_params);

    fragment->viewport_segments.Set(
        viewport_segments_fragment.is_null() ? nullptr : viewport_segments_fragment.data());

    
    MOJO_INTERNAL_CHECK_SERIALIZATION(
      mojo::internal::SendValidation::kDefault,
      !(fragment->viewport_segments.is_null()),
      mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
      "null viewport_segments in DeviceEmulationParams struct");

    
    mojo::internal::Serialize<::blink::mojom::DevicePostureType>(
      Traits::device_posture(input),
      &fragment->device_posture);

    fragment->force_android_overlay_scrollbar = Traits::force_android_overlay_scrollbar(input);
  }

  static bool Deserialize(::blink::mojom::internal::DeviceEmulationParams_Data* input,
                          UserType* output,
                          Message* message) {
    if (!input)
      return CallSetToNullIfExists<Traits>(output);

    ::blink::mojom::DeviceEmulationParamsDataView data_view(input, message);
    return CallTraitsRead<Traits>(data_view, output);
  }
};

}  // namespace internal

}  // namespace mojo


namespace blink::mojom {

inline void DeviceEmulationParamsDataView::GetScreenSizeDataView(
    ::gfx::mojom::SizeDataView* output) {
  auto pointer = data_->screen_size.Get();
  *output = ::gfx::mojom::SizeDataView(pointer, message_);
}
inline void DeviceEmulationParamsDataView::GetViewPositionDataView(
    ::gfx::mojom::PointDataView* output) {
  auto pointer = data_->view_position.Get();
  *output = ::gfx::mojom::PointDataView(pointer, message_);
}
inline void DeviceEmulationParamsDataView::GetViewSizeDataView(
    ::gfx::mojom::SizeDataView* output) {
  auto pointer = data_->view_size.Get();
  *output = ::gfx::mojom::SizeDataView(pointer, message_);
}
inline void DeviceEmulationParamsDataView::GetViewportOffsetDataView(
    ::gfx::mojom::PointFDataView* output) {
  auto pointer = data_->viewport_offset.Get();
  *output = ::gfx::mojom::PointFDataView(pointer, message_);
}
inline void DeviceEmulationParamsDataView::GetViewportSegmentsDataView(
    mojo::ArrayDataView<::gfx::mojom::RectDataView>* output) {
  auto pointer = data_->viewport_segments.Get();
  *output = mojo::ArrayDataView<::gfx::mojom::RectDataView>(pointer, message_);
}



}  // blink::mojom

// Declare TraceFormatTraits for enums, which should be defined in ::perfetto
// namespace.

namespace perfetto {

template <>
struct COMPONENT_EXPORT(MOJOM_SHARED_BLINK_COMMON_EXPORT) TraceFormatTraits<::blink::mojom::EmulatedScreenType> {
 static void WriteIntoTrace(perfetto::TracedValue context, ::blink::mojom::EmulatedScreenType value);
};

} // namespace perfetto

#endif  // THIRD_PARTY_BLINK_PUBLIC_MOJOM_WIDGET_DEVICE_EMULATION_PARAMS_MOJOM_SHARED_H_