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
97 changes: 0 additions & 97 deletions bridge/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,36 +171,6 @@ if (DEFINED PLATFORM)
endif()
endif()

# Generate CSS resource headers
# This section generates C++ header files from CSS source files
set(CSS_RESOURCES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/core/css/resources)

# Output generated headers into the source tree under code_gen
set(GENERATED_DIR ${CMAKE_CURRENT_SOURCE_DIR}/code_gen/)

# Ensure the generated directory exists
file(MAKE_DIRECTORY ${GENERATED_DIR})

# Read HTML CSS content (no escaping needed for raw string literals)
file(READ ${CSS_RESOURCES_DIR}/html.css HTML_CSS_CONTENT)

# Generate html_css.h from template
configure_file(
${CSS_RESOURCES_DIR}/html_css.h.in
${GENERATED_DIR}/html_css.h
@ONLY
)

# Read Quirks CSS content (no escaping needed for raw string literals)
file(READ ${CSS_RESOURCES_DIR}/quirks.css QUIRKS_CSS_CONTENT)

# Generate quirks_css.h from template
configure_file(
${CSS_RESOURCES_DIR}/quirks_css.h.in
${GENERATED_DIR}/quirks_css.h
@ONLY
)

# Ensure code_gen is in the include path for generated headers
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/code_gen)

Expand Down Expand Up @@ -451,70 +421,3 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "iOS")
)
endif()
endif ()


#############################
# Logging options
#############################

# Helper to allow env var defaults while preserving -D cache overrides
function(_webf_option_with_env VAR DESC DEFAULT)
set(_default ${DEFAULT})
if(DEFINED ENV{${VAR}})
string(TOUPPER "$ENV{${VAR}}" _env_val)
if(_env_val STREQUAL "1" OR _env_val STREQUAL "ON" OR _env_val STREQUAL "TRUE" OR _env_val STREQUAL "YES")
set(_default ON)
elseif(_env_val STREQUAL "0" OR _env_val STREQUAL "OFF" OR _env_val STREQUAL "FALSE" OR _env_val STREQUAL "NO")
set(_default OFF)
else()
message(WARNING "Ignoring invalid value for ${VAR} environment variable: '$ENV{${VAR}}'. Expected ON/OFF/1/0/TRUE/FALSE/YES/NO.")
endif()
endif()
option(${VAR} "${DESC}" ${_default})
endfunction()

# Master switch to quickly enable all log categories
_webf_option_with_env(WEBF_LOG_ALL "Enable all WebF category logs" OFF)

# Per-category logging switches
_webf_option_with_env(WEBF_LOG_PARSER "Enable Parser logs" OFF)
_webf_option_with_env(WEBF_LOG_STYLEENGINE "Enable StyleEngine logs" OFF)
_webf_option_with_env(WEBF_LOG_CASCADE "Enable Cascade logs" OFF)
_webf_option_with_env(WEBF_LOG_COLLECTOR "Enable Collector logs" OFF)
_webf_option_with_env(WEBF_LOG_STYLESHEET "Enable Stylesheet logs" OFF)
_webf_option_with_env(WEBF_LOG_SELECTOR "Enable Selector logs" OFF)
_webf_option_with_env(WEBF_LOG_ATTR "Enable Attr logs" OFF)
_webf_option_with_env(WEBF_LOG_COMMAND "Enable Command logs" OFF)

macro(_webf_define_log VAR)
if (WEBF_LOG_ALL OR ${VAR})
add_compile_definitions(${VAR}=1)
list(APPEND _WEBF_ENABLED_LOGS ${VAR})
endif()
endmacro()

set(_WEBF_ENABLED_LOGS)
_webf_define_log(WEBF_LOG_PARSER)
_webf_define_log(WEBF_LOG_STYLEENGINE)
_webf_define_log(WEBF_LOG_CASCADE)
_webf_define_log(WEBF_LOG_COLLECTOR)
_webf_define_log(WEBF_LOG_STYLESHEET)
_webf_define_log(WEBF_LOG_SELECTOR)
_webf_define_log(WEBF_LOG_ATTR)
_webf_define_log(WEBF_LOG_COMMAND)

if (_WEBF_ENABLED_LOGS)
list(JOIN _WEBF_ENABLED_LOGS ", " _WEBF_ENABLED_LOGS_STR)
message(STATUS "WebF logging enabled for: ${_WEBF_ENABLED_LOGS_STR}")
# Ensure targets built in this directory also receive the definitions
foreach(_log ${_WEBF_ENABLED_LOGS})
if (TARGET webf_core)
target_compile_definitions(webf_core PUBLIC ${_log}=1)
endif()
if (TARGET webf)
target_compile_definitions(webf PUBLIC ${_log}=1)
endif()
endforeach()
else()
message(STATUS "WebF logging: no categories enabled (define WEBF_LOG_* or set WEBF_LOG_ALL)")
endif()
1 change: 0 additions & 1 deletion bridge/bridge_sources.json5
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@
"core/css/if_condition.cc",
"core/css/style_sheet_contents.cc",
"core/css/css_style_sheet.cc",
"core/css/css_default_style_sheets.cc",
"core/css/style_rule_import.cc",
"core/css/style_sheet.cc",
"core/css/resolver/style_resolver.cc",
Expand Down
108 changes: 108 additions & 0 deletions bridge/core/css/blink_pseudo_style_gating_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#include "gtest/gtest.h"

#include <cstring>

#include "foundation/string/wtf_string.h"
#include "foundation/ui_command_buffer.h"
#include "webf_test_env.h"

using namespace webf;

namespace {

std::string CommandArg01ToUTF8(const UICommandItem& item) {
if (item.string_01 == 0 || item.args_01_length == 0) {
return "";
}
const auto* utf16 = reinterpret_cast<const UChar*>(static_cast<uintptr_t>(item.string_01));
return String(utf16, static_cast<size_t>(item.args_01_length)).ToUTF8String();
}

int64_t CountPseudoCommands(const UICommandItem* items,
int64_t length,
UICommand command,
const std::string& pseudo_type) {
int64_t count = 0;
for (int64_t i = 0; i < length; ++i) {
const UICommandItem& item = items[i];
if (item.type != static_cast<int32_t>(command)) {
continue;
}
if (CommandArg01ToUTF8(item) == pseudo_type) {
count++;
}
}
return count;
}

} // namespace

TEST(BlinkPseudoStyleGating, DoesNotEmitPseudoStylesWithoutContent) {
auto env = TEST_init(nullptr, nullptr, 0, /*enable_blink=*/1);
auto* context = env->page()->executingContext();

// Flush bootstrap microtasks and drop any initial commands.
TEST_runLoop(context);
context->uiCommandBuffer()->clear();

const char* setup = R"JS(
const style = document.createElement('style');
style.textContent = `.box::before { color: red; } .box { color: blue; }`;
document.body.appendChild(style);

const div = document.createElement('div');
div.className = 'box';
div.textContent = 'hi';
document.body.appendChild(div);
)JS";
env->page()->evaluateScript(setup, strlen(setup), "vm://", 0);
TEST_runLoop(context);

// Ignore DOM creation commands; only inspect style export.
context->uiCommandBuffer()->clear();
{
MemberMutationScope scope{context};
context->document()->UpdateStyleForThisDocument();
}
context->uiCommandBuffer()->SyncAllPackages();

auto* pack = static_cast<UICommandBufferPack*>(context->uiCommandBuffer()->data());
auto* items = static_cast<UICommandItem*>(pack->data);

EXPECT_EQ(CountPseudoCommands(items, pack->length, UICommand::kSetPseudoStyle, "before"), 0);
EXPECT_EQ(CountPseudoCommands(items, pack->length, UICommand::kClearPseudoStyle, "before"), 0);
}

TEST(BlinkPseudoStyleGating, EmitsPseudoStylesWhenContentPresent) {
auto env = TEST_init(nullptr, nullptr, 0, /*enable_blink=*/1);
auto* context = env->page()->executingContext();

TEST_runLoop(context);
context->uiCommandBuffer()->clear();

const char* setup = R"JS(
const style = document.createElement('style');
style.textContent = `.box::before { content: ""; color: red; }`;
document.body.appendChild(style);

const div = document.createElement('div');
div.className = 'box';
div.textContent = 'hi';
document.body.appendChild(div);
)JS";
env->page()->evaluateScript(setup, strlen(setup), "vm://", 0);
TEST_runLoop(context);

context->uiCommandBuffer()->clear();
{
MemberMutationScope scope{context};
context->document()->UpdateStyleForThisDocument();
}
context->uiCommandBuffer()->SyncAllPackages();

auto* pack = static_cast<UICommandBufferPack*>(context->uiCommandBuffer()->data());
auto* items = static_cast<UICommandItem*>(pack->data);

EXPECT_GT(CountPseudoCommands(items, pack->length, UICommand::kSetPseudoStyle, "before"), 0);
EXPECT_GT(CountPseudoCommands(items, pack->length, UICommand::kClearPseudoStyle, "before"), 0);
}
138 changes: 0 additions & 138 deletions bridge/core/css/css_default_style_sheets.cc

This file was deleted.

Loading
Loading