Skip to content

Commit

Permalink
VT: Change CSS serialization to a map of id to a string property value
Browse files Browse the repository at this point in the history
This patch changes the VT serialization of some CSS properties from
custom serialization to a map of property id to value (as string)

R=bokan@chromium.org, khushalsagar@chromium.org

Change-Id: Ifc0de5b3da7eb66063300ab17510b7e39a550f21
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4907882
Reviewed-by: Khushal Sagar <khushalsagar@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Vladimir Levin <vmpstr@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1208826}
  • Loading branch information
vmpstr authored and Chromium LUCI CQ committed Oct 12, 2023
1 parent 7f78d12 commit 82eb6d5
Show file tree
Hide file tree
Showing 13 changed files with 228 additions and 232 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,11 @@ bool StructTraits<blink::mojom::ViewTransitionElementDataView,
!data.ReadSnapshotId(&out->snapshot_id) ||
!data.ReadCapturedRectInLayoutSpace(
&out->captured_rect_in_layout_space) ||
!data.ReadColorScheme(&out->color_scheme)) {
!data.ReadCapturedCssProperties(&out->captured_css_properties)) {
return false;
}

out->paint_order = data.paint_order();
out->container_writing_mode = data.container_writing_mode();
out->mix_blend_mode = data.mix_blend_mode();
out->text_orientation = data.text_orientation();
return true;
}

Expand Down
7 changes: 3 additions & 4 deletions third_party/blink/public/common/frame/view_transition_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef THIRD_PARTY_BLINK_PUBLIC_COMMON_FRAME_VIEW_TRANSITION_STATE_H_
#define THIRD_PARTY_BLINK_PUBLIC_COMMON_FRAME_VIEW_TRANSITION_STATE_H_

#include "base/containers/flat_map.h"
#include "base/unguessable_token.h"
#include "components/viz/common/view_transition_element_resource_id.h"
#include "third_party/blink/public/common/common_export.h"
Expand Down Expand Up @@ -40,10 +41,8 @@ struct BLINK_COMMON_EXPORT ViewTransitionElement {
viz::ViewTransitionElementResourceId snapshot_id;
int32_t paint_order = 0;
absl::optional<gfx::RectF> captured_rect_in_layout_space;
uint8_t container_writing_mode = 0;
uint8_t mix_blend_mode = 0;
uint8_t text_orientation = 0;
std::string color_scheme;
base::flat_map<blink::mojom::ViewTransitionPropertyId, std::string>
captured_css_properties;
};

struct BLINK_COMMON_EXPORT ViewTransitionState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define THIRD_PARTY_BLINK_PUBLIC_COMMON_FRAME_VIEW_TRANSITION_STATE_MOJOM_TRAITS_H_

#include "base/check_op.h"
#include "base/containers/flat_map.h"
#include "services/viz/public/mojom/compositing/view_transition_element_resource_id.mojom.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/blink/public/common/common_export.h"
Expand Down Expand Up @@ -51,21 +52,10 @@ struct BLINK_COMMON_EXPORT
return r.captured_rect_in_layout_space;
}

static uint8_t container_writing_mode(const blink::ViewTransitionElement& r) {
return r.container_writing_mode;
}

static uint8_t mix_blend_mode(const blink::ViewTransitionElement& r) {
return r.mix_blend_mode;
}

static uint8_t text_orientation(const blink::ViewTransitionElement& r) {
return r.text_orientation;
}

static const std::string& color_scheme(
const blink::ViewTransitionElement& r) {
return r.color_scheme;
static const base::flat_map<blink::mojom::ViewTransitionPropertyId,
std::string>&
captured_css_properties(const blink::ViewTransitionElement& r) {
return r.captured_css_properties;
}

static bool Read(blink::mojom::ViewTransitionElementDataView r,
Expand Down
15 changes: 10 additions & 5 deletions third_party/blink/public/mojom/frame/view_transition_state.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ import "ui/gfx/geometry/mojom/geometry.mojom";
import "ui/gfx/mojom/transform.mojom";
import "services/viz/public/mojom/compositing/view_transition_element_resource_id.mojom";

enum ViewTransitionPropertyId {
kColorScheme,
kMixBlendMode,
kTextOrientation,
kWritingMode
};

// This represents the necessary information for a shared element to
// participate in a view transition. See comment above ViewTransitionState for
// more information.
Expand All @@ -29,11 +36,9 @@ struct ViewTransitionElement {
int32 paint_order;

// Select CSS property values needed for the visual representation of this
// shared element.
uint8 container_writing_mode;
uint8 mix_blend_mode;
uint8 text_orientation;
string color_scheme;
// shared element. The map is from (a subset of) CSSPropertyIDs to the css
// computed value (as string).
map<ViewTransitionPropertyId, string> captured_css_properties;
};

// This represents a document state necessary to initiate a view transition for
Expand Down
1 change: 1 addition & 0 deletions third_party/blink/renderer/core/view_transition/DEPS
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include_rules = [
"+base/containers/flat_map.h",
"+cc/view_transition/view_transition_request.h",
"+components/viz/common/view_transition_element_resource_id.h"
]
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,6 @@ const char* kNewImageTagName = "html::view-transition-new";
const char* kOldImageTagName = "html::view-transition-old";
const char* kKeyframeNamePrefix = "-ua-view-transition-group-anim-";

const char* TextOrientationToString(ETextOrientation text_orientation) {
switch (text_orientation) {
case ETextOrientation::kMixed:
return "mixed";
case ETextOrientation::kSideways:
return "sideways";
case ETextOrientation::kUpright:
return "upright";
}
NOTREACHED();
return "";
}

} // namespace

void ViewTransitionStyleBuilder::AddUAStyle(const String& style) {
Expand Down Expand Up @@ -133,34 +120,27 @@ String ViewTransitionStyleBuilder::AddKeyframes(
void ViewTransitionStyleBuilder::AddContainerStyles(
const String& tag,
const ContainerProperties& properties,
WritingMode writing_mode,
BlendMode blend_mode,
ETextOrientation text_orientation,
const String& color_scheme) {
std::ostringstream writing_mode_stream;
writing_mode_stream << writing_mode;

const base::flat_map<CSSPropertyID, String>& css_properties) {
StringBuilder rule_builder;
rule_builder.AppendFormat(
R"CSS(
width: %.3fpx;
height: %.3fpx;
transform: %s;
writing-mode: %s;
mix-blend-mode: %s;
text-orientation: %s;
color-scheme: %s;
)CSS",
properties.border_box_size_in_css_space.width.ToFloat(),
properties.border_box_size_in_css_space.height.ToFloat(),
ComputedStyleUtils::ValueForTransform(properties.snapshot_matrix, 1,
false)
->CssText()
.Utf8()
.c_str(),
writing_mode_stream.str().c_str(),
BlendModeToString(blend_mode).Utf8().c_str(),
TextOrientationToString(text_orientation), color_scheme.Utf8().c_str());
.c_str());
for (const auto& [id, value] : css_properties) {
rule_builder.AppendFormat(
"%s: %s;\n",
CSSProperty::Get(id).GetPropertyNameAtomicString().Utf8().c_str(),
value.Utf8().c_str());
}

AddRules(kGroupTagName, tag, rule_builder.ReleaseString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_VIEW_TRANSITION_VIEW_TRANSITION_STYLE_BUILDER_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_VIEW_TRANSITION_VIEW_TRANSITION_STYLE_BUILDER_H_

#include "base/containers/flat_map.h"
#include "third_party/blink/renderer/core/css/css_property_names.h"
#include "third_party/blink/renderer/core/view_transition/view_transition_style_tracker.h"
#include "third_party/blink/renderer/platform/geometry/layout_size.h"
#include "third_party/blink/renderer/platform/graphics/graphics_types.h"
Expand All @@ -28,12 +30,10 @@ class ViewTransitionStyleBuilder {
const String& tag,
const ContainerProperties& source_properties);

void AddContainerStyles(const String& tag,
const ContainerProperties& properties,
WritingMode writing_mode,
BlendMode blend_mode,
ETextOrientation text_orientation,
const String& color_scheme);
void AddContainerStyles(
const String& tag,
const ContainerProperties& properties,
const base::flat_map<CSSPropertyID, String>& css_properites);

String Build();

Expand Down

0 comments on commit 82eb6d5

Please sign in to comment.