1 // Copyright 2018 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CC_MOJOM_RENDER_FRAME_METADATA_MOJOM_TRAITS_H_
6 #define CC_MOJOM_RENDER_FRAME_METADATA_MOJOM_TRAITS_H_
8 #include "base/component_export.h"
9 #include "build/build_config.h"
10 #include "cc/mojom/render_frame_metadata.mojom-shared.h"
11 #include "cc/trees/render_frame_metadata.h"
12 #include "services/viz/public/cpp/compositing/local_surface_id_mojom_traits.h"
13 #include "skia/public/mojom/skcolor4f_mojom_traits.h"
14 #include "third_party/abseil-cpp/absl/types/optional.h"
15 #include "third_party/skia/include/core/SkColor.h"
20 struct COMPONENT_EXPORT(CC_SHARED_MOJOM_TRAITS)
21 StructTraits<cc::mojom::DelegatedInkBrowserMetadataDataView,
22 cc::DelegatedInkBrowserMetadata> {
23 static bool delegated_ink_is_hovering(
24 const cc::DelegatedInkBrowserMetadata& metadata) {
25 return metadata.delegated_ink_is_hovering;
28 static bool Read(cc::mojom::DelegatedInkBrowserMetadataDataView data,
29 cc::DelegatedInkBrowserMetadata* out);
33 struct COMPONENT_EXPORT(CC_SHARED_MOJOM_TRAITS)
34 StructTraits<cc::mojom::RenderFrameMetadataDataView,
35 cc::RenderFrameMetadata> {
36 static SkColor4f root_background_color(
37 const cc::RenderFrameMetadata& metadata) {
38 return metadata.root_background_color;
41 static const absl::optional<gfx::PointF>& root_scroll_offset(
42 const cc::RenderFrameMetadata& metadata) {
43 return metadata.root_scroll_offset;
46 static bool is_scroll_offset_at_top(const cc::RenderFrameMetadata& metadata) {
47 return metadata.is_scroll_offset_at_top;
50 static const viz::Selection<gfx::SelectionBound>& selection(
51 const cc::RenderFrameMetadata& metadata) {
52 return metadata.selection;
55 static bool is_mobile_optimized(const cc::RenderFrameMetadata& metadata) {
56 return metadata.is_mobile_optimized;
59 static const absl::optional<cc::DelegatedInkBrowserMetadata>&
60 delegated_ink_metadata(const cc::RenderFrameMetadata& metadata) {
61 return metadata.delegated_ink_metadata;
64 static float device_scale_factor(const cc::RenderFrameMetadata& metadata) {
65 return metadata.device_scale_factor;
68 static const gfx::Size& viewport_size_in_pixels(
69 const cc::RenderFrameMetadata& metadata) {
70 return metadata.viewport_size_in_pixels;
73 static const absl::optional<viz::LocalSurfaceId>& local_surface_id(
74 const cc::RenderFrameMetadata& metadata) {
75 return metadata.local_surface_id;
78 static float page_scale_factor(const cc::RenderFrameMetadata& metadata) {
79 return metadata.page_scale_factor;
82 static float external_page_scale_factor(
83 const cc::RenderFrameMetadata& metadata) {
84 return metadata.external_page_scale_factor;
87 static float top_controls_height(const cc::RenderFrameMetadata& metadata) {
88 return metadata.top_controls_height;
91 static float top_controls_shown_ratio(
92 const cc::RenderFrameMetadata& metadata) {
93 return metadata.top_controls_shown_ratio;
96 static viz::VerticalScrollDirection new_vertical_scroll_direction(
97 const cc::RenderFrameMetadata& metadata) {
98 return metadata.new_vertical_scroll_direction;
101 #if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_IOS)
102 static float bottom_controls_height(const cc::RenderFrameMetadata& metadata) {
103 return metadata.bottom_controls_height;
106 static float bottom_controls_shown_ratio(
107 const cc::RenderFrameMetadata& metadata) {
108 return metadata.bottom_controls_shown_ratio;
111 static float top_controls_min_height_offset(
112 const cc::RenderFrameMetadata& metadata) {
113 return metadata.top_controls_min_height_offset;
116 static float bottom_controls_min_height_offset(
117 const cc::RenderFrameMetadata& metadata) {
118 return metadata.bottom_controls_min_height_offset;
121 static float min_page_scale_factor(const cc::RenderFrameMetadata& metadata) {
122 return metadata.min_page_scale_factor;
125 static float max_page_scale_factor(const cc::RenderFrameMetadata& metadata) {
126 return metadata.max_page_scale_factor;
129 static bool root_overflow_y_hidden(const cc::RenderFrameMetadata& metadata) {
130 return metadata.root_overflow_y_hidden;
133 static const gfx::SizeF& scrollable_viewport_size(
134 const cc::RenderFrameMetadata& metadata) {
135 return metadata.scrollable_viewport_size;
138 static const gfx::SizeF& root_layer_size(
139 const cc::RenderFrameMetadata& metadata) {
140 return metadata.root_layer_size;
143 static bool has_transparent_background(
144 const cc::RenderFrameMetadata& metadata) {
145 return metadata.has_transparent_background;
149 static bool Read(cc::mojom::RenderFrameMetadataDataView data,
150 cc::RenderFrameMetadata* out);
155 #endif // CC_MOJOM_RENDER_FRAME_METADATA_MOJOM_TRAITS_H_