Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion fixtures/html/simple.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
padding: 0 20px;
margin: 20px;
border: 15px solid #e8b51cd8;
background-color: #343755d8;
background-color: #0f1a93d8;
background-image: url(https://ar.rokidcdn.com/web-assets/yodaos-jsar/dist/images/a.jpg);
background-blend-mode: multiply;
border-radius: 5px;
box-sizing: border-box;
transform: translate3d(0, 0, 15px);
Expand Down
4 changes: 4 additions & 0 deletions src/client/builtin_scene/web_content_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ namespace builtin_scene::web_renderer
if (!fillPaint.has_value())
fillPaint = make_optional<SkPaint>();

// Set the blend mode for the paint if the background blend mode is not normal.
if (!style.backgroundBlendMode().isNormal())
fillPaint->setBlendMode(style.backgroundBlendMode());

const auto &image = style.backgroundImage();
if (image.isUrl())
{
Expand Down
10 changes: 10 additions & 0 deletions src/client/cssom/computed_style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "./values/specified/position.hpp"
#include "./values/specified/time.hpp"
#include "./values/specified/transform.hpp"
#include "./values/specified/background.hpp"

namespace client_cssom
{
Expand Down Expand Up @@ -402,6 +403,15 @@ namespace client_cssom
background_image_ = Parse::ParseSingleValue<values::specified::Image>(value).toComputedValue(context);
bitfields_.SetHasBackgroundImage(true);
}
else if (name == "background-blend-mode")
{
background_blend_mode_ = Parse::ParseSingleValue<values::specified::BackgroundBlendMode>(value)
.toComputedValue(context);
}
else if (name == "background-clip")
{
background_clip_ = Parse::ParseSingleValue<values::specified::BackgroundClip>(value).toComputedValue(context);
}

// Flexbox
else if (name == "flex-direction")
Expand Down
10 changes: 10 additions & 0 deletions src/client/cssom/computed_style.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,14 @@ namespace client_cssom
{
return bitfields_.HasBackgroundImage();
}
inline const values::computed::BackgroundBlendMode &backgroundBlendMode() const
{
return background_blend_mode_;
}
inline const values::computed::BackgroundClip &backgroundClip() const
{
return background_clip_;
}

// Visibility utility functions.
inline bool visibleToHitTesting() const
Expand Down Expand Up @@ -515,6 +523,8 @@ namespace client_cssom
// Background
values::computed::Color background_color_ = values::computed::Color::Transparent();
values::computed::Image background_image_ = values::computed::Image::None();
values::computed::BackgroundBlendMode background_blend_mode_ = values::computed::BackgroundBlendMode::Normal();
values::computed::BackgroundClip background_clip_ = values::computed::BackgroundClip::BorderBox();

// 3D Transforms
values::computed::Transform transform_;
Expand Down
1 change: 1 addition & 0 deletions src/client/cssom/style_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <concepts>
#include <string>
#include <vector>
#include <glm/glm.hpp>
#include <common/utility.hpp>

Expand Down
65 changes: 65 additions & 0 deletions src/client/cssom/values/computed/background.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#pragma once

#include <client/cssom/values/generics/background.hpp>
#include <skia/include/core/SkBlendMode.h>

namespace client_cssom::values::specified
{
class BackgroundBlendMode;
class BackgroundClip;
}

namespace client_cssom::values::computed
{
class BackgroundBlendMode : public generics::GenericBackgroundBlendMode<BackgroundBlendMode>
{
using generics::GenericBackgroundBlendMode<BackgroundBlendMode>::GenericBackgroundBlendMode;

public:
operator SkBlendMode() const
{
switch (tag_)
{
case BackgroundBlendMode::kNormal:
return SkBlendMode::kSrcOver;
case BackgroundBlendMode::kMultiply:
return SkBlendMode::kMultiply;
case BackgroundBlendMode::kScreen:
return SkBlendMode::kScreen;
case BackgroundBlendMode::kOverlay:
return SkBlendMode::kOverlay;
case BackgroundBlendMode::kDarken:
return SkBlendMode::kDarken;
case BackgroundBlendMode::kLighten:
return SkBlendMode::kLighten;
case BackgroundBlendMode::kColorDodge:
return SkBlendMode::kColorDodge;
case BackgroundBlendMode::kColorBurn:
return SkBlendMode::kColorBurn;
case BackgroundBlendMode::kHardLight:
return SkBlendMode::kHardLight;
case BackgroundBlendMode::kSoftLight:
return SkBlendMode::kSoftLight;
case BackgroundBlendMode::kDifference:
return SkBlendMode::kDifference;
case BackgroundBlendMode::kExclusion:
return SkBlendMode::kExclusion;
case BackgroundBlendMode::kHue:
return SkBlendMode::kHue;
case BackgroundBlendMode::kSaturation:
return SkBlendMode::kSaturation;
case BackgroundBlendMode::kColor:
return SkBlendMode::kColor;
case BackgroundBlendMode::kLuminosity:
return SkBlendMode::kLuminosity;
default:
return SkBlendMode::kSrcOver; // Default to SrcOver if none match
}
}
};

class BackgroundClip : public generics::GenericBackgroundClip<BackgroundClip>
{
using generics::GenericBackgroundClip<BackgroundClip>::GenericBackgroundClip;
};
}
1 change: 1 addition & 0 deletions src/client/cssom/values/computed/classes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "./align.hpp"
#include "./angle.hpp"
#include "./animation.hpp"
#include "./background.hpp"
#include "./border.hpp"
#include "./box.hpp"
#include "./common.hpp"
Expand Down
Loading