Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 22, 2025

This PR implements support for the background-blend-mode and background-clip CSS properties in the CSSOM implementation, extending the runtime's CSS capabilities.

Changes Made

New CSS Properties Supported

background-blend-mode - Controls how background images blend with each other and the background color:

  • normal, multiply, screen, overlay, darken, lighten
  • color-dodge, color-burn, hard-light, soft-light
  • difference, exclusion, hue, saturation, color, luminosity

background-clip - Controls how far a background extends within an element:

  • border-box, padding-box, content-box, text

Implementation Details

Added Files:

  • src/client/cssom/values/specified/background_blend_mode.hpp - Complete enum-based implementation with all 16 CSS blend modes
  • src/client/cssom/values/specified/background_clip.hpp - Complete enum-based implementation with all 4 CSS clip modes

Modified Files:

  • src/client/cssom/computed_style.hpp - Added accessor methods and member variables for the new properties
  • src/client/cssom/computed_style.cpp - Added CSS parsing logic following existing patterns
  • src/client/cssom/values/computed/box.hpp - Added computed value type aliases
  • src/client/cssom/style_traits.hpp - Fixed missing <vector> include

Technical Implementation

The implementation follows the established patterns in the codebase:

  • Enum-based value types with static constructors (e.g., BackgroundBlendMode::Multiply())
  • Implements required interfaces: Parse, ToCss, ToComputedValue
  • Default values match CSS specification (normal for blend-mode, border-box for clip)
  • Computed values are simple aliases to specified values (no complex computation needed)
  • CSS parsing integrated into existing property resolution pipeline

Usage Example

.element {
  background-image: url(image1.png), url(image2.png);
  background-blend-mode: multiply, screen;
  background-clip: content-box;
}

The properties were already declared in properties.hpp but lacked implementation. This PR provides the complete value type definitions and integration into the computed style system.

Fixes #118.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
Copilot AI changed the title [WIP] cssom: add background-blend-mode/background-clip in css values Add support for background-blend-mode and background-clip CSS properties Jul 22, 2025
Copilot AI requested a review from yorkie July 22, 2025 15:05
using BoxSizing = specified::BoxSizing;
using Overflow = specified::Overflow;
using BackgroundBlendMode = specified::BackgroundBlendMode;
using BackgroundClip = specified::BackgroundClip;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BackgroundBlendMode and BackgroundClip should be in background.hpp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 905d0dd. Created values/computed/background.hpp with the BackgroundBlendMode and BackgroundClip aliases, and updated computed/box.hpp to include it instead of the specified files directly.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move common logic to values/generics/background.hpp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 905d0dd. Created values/generics/background.hpp with GenericBackgroundBlendMode<T> template containing the common logic. The specified file now inherits from the generic, reducing code from 200+ lines to just 10 lines.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move common logic to values/generics/background.hpp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 905d0dd. Created values/generics/background.hpp with GenericBackgroundClip<T> template containing the common logic. The specified file now inherits from the generic, reducing code from 100+ lines to just 10 lines.

Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jul 22, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • registry.npmmirror.com
    • Triggering command: npm ci (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from yorkie July 22, 2025 15:24
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this file to values/specified/background.hpp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 84363b4. Moved both background_clip.hpp and background_blend_mode.hpp into a single consolidated values/specified/background.hpp file.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this file to values/specified/background.hpp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 84363b4. Moved both background_blend_mode.hpp and background_clip.hpp into a single consolidated values/specified/background.hpp file.

namespace client_cssom::values::generics
{
template <typename T>
class GenericBackgroundBlendMode : public Parse,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parse should be implemented in specified class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 84363b4. Moved the Parse implementation from the generic class to the BackgroundBlendMode specified class.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Parse inheritance should move the specified class, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 55ea546. Moved Parse inheritance from GenericBackgroundBlendMode to the BackgroundBlendMode specified class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 55ea546. Moved Parse inheritance from GenericBackgroundBlendMode to the BackgroundBlendMode specified class.

};

template <typename T>
class GenericBackgroundClip : public Parse,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto, Parse should be implemented in specified class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 84363b4. Moved the Parse implementation from the generic class to the BackgroundClip specified class.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto, the inheritance from Parse should be moved to specified class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 55ea546. Moved Parse inheritance from GenericBackgroundClip to the BackgroundClip specified class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 55ea546. Moved Parse inheritance from GenericBackgroundClip to the BackgroundClip specified class.


#include <client/cssom/values/generics/rect.hpp>
#include <client/cssom/values/specified/box.hpp>
#include <client/cssom/values/computed/background.hpp>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this #include, this is unnecessary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 84363b4. Removed the unnecessary #include from computed/box.hpp.

… implementation to specified classes

Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
Copilot AI requested a review from yorkie July 22, 2025 15:40
namespace client_cssom::values::generics
{
template <typename T>
class GenericBackgroundBlendMode : public Parse,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Parse inheritance should move the specified class, too.

};

template <typename T>
class GenericBackgroundClip : public Parse,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto, the inheritance from Parse should be moved to specified class.

protected:
Tag tag_;
};
} No newline at end of file
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove EOF

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 55ea546. The file now ends with the closing brace without extra blank lines.

return true;
}
};
} No newline at end of file
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the EOF

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file structure has been updated and there are no trailing newlines at the end of the file. The EOF issue has been resolved in commit 55ea546.

namespace client_cssom::values::computed
{
using BackgroundBlendMode = specified::BackgroundBlendMode;
using BackgroundClip = specified::BackgroundClip;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use generics instead of specified classes in computed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 55ea546. Updated computed/background.hpp to use generics::GenericBackgroundBlendMode and generics::GenericBackgroundClip instead of the specified classes.

template <typename T>
class GenericBackgroundBlendMode : public Parse,
public ToCss,
public ToComputedValue<T>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ToComputeValue should also moved to specified, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 55ea546. Moved ToComputedValue inheritance from GenericBackgroundBlendMode to the BackgroundBlendMode specified class.

template <typename T>
class GenericBackgroundClip : public Parse,
public ToCss,
public ToComputedValue<T>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ToComputeValue should also moved to specified, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 55ea546. Moved ToComputedValue inheritance from GenericBackgroundClip to the BackgroundClip specified class.

…ix computed types

Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jul 22, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • registry.npmmirror.com
    • Triggering command: npm install (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from yorkie July 22, 2025 16:01
@yorkie yorkie marked this pull request as ready for review July 22, 2025 17:11
@yorkie yorkie merged commit 1df9830 into main Jul 22, 2025
2 checks passed
@yorkie yorkie deleted the copilot/fix-118 branch July 22, 2025 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cssom: add background-blend-mode/background-clip in css values

2 participants