Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
194 commits
Select commit Hold shift + click to select a range
c0a7754
feat: implement Blink style recalculation and rule matching
CGQAQ Sep 11, 2025
be48263
fix: fix leak of Document and CSSStyleSheet
CGQAQ Sep 11, 2025
7afdb04
fix: parser seems not support 16bit atomic_string for some reason, co…
CGQAQ Sep 11, 2025
1825588
chore: remove debug log
CGQAQ Sep 12, 2025
92d96b6
fix: text encoding issue when parsing keywords
CGQAQ Sep 12, 2025
d22f542
refactor: replace empty URL with NullURL in style engine
CGQAQ Sep 12, 2025
ee7af53
revert: change back to use 16bit string as we fixed the encoding issue
CGQAQ Sep 12, 2025
15cd455
feat: add flag to enableBlink to WebFController
CGQAQ Sep 15, 2025
591faf3
feat: enhance UA stylesheet matching, optimize string utilities
CGQAQ Sep 12, 2025
59042e1
fix: prevent DCHECK in CSSSelector by avoiding unsafe TagQName calls
CGQAQ Sep 17, 2025
6d9cc56
fix: Crash when there's no property that been removed
CGQAQ Sep 17, 2025
7472e94
fix: update class attribute handling for selector matching
CGQAQ Sep 17, 2025
0d2c372
fix: improve color handling and cascade ordering in style engine
CGQAQ Sep 17, 2025
c9b7ecd
feat: enhance CSSStyleDeclaration with extended property handling and…
CGQAQ Sep 23, 2025
9201dbf
fix: use shared_ptr for CSSRatioValue to improve memory management
CGQAQ Sep 24, 2025
aa3456c
fix: handle null string_ safely in AtomicString::Contains
CGQAQ Sep 24, 2025
f27642c
fix: set correct initial value for transition-delay property
CGQAQ Sep 24, 2025
9c17259
fix: use shared_ptr for CSSPrimitiveValue to enhance memory safety
CGQAQ Sep 24, 2025
756de7a
test: replace `fit` with `it` in link spec test
CGQAQ Sep 24, 2025
8845230
fix: correct prototype property query behavior in interface template
CGQAQ Sep 24, 2025
eb7f247
fix: separate Blink and Dart `getComputedStyle` implementations
CGQAQ Sep 25, 2025
d7988f6
fix: implement canonical serialization order for style properties
CGQAQ Sep 25, 2025
5fe4725
fix: set correct initial value for background-size property
CGQAQ Sep 25, 2025
b763e5b
fix: properly resize `property_vector_` when new size is smaller
CGQAQ Sep 25, 2025
013e16d
fix: optimize style attribute mutation handling and caching
CGQAQ Sep 25, 2025
7e1c651
fix: resolve CSSPropertyID before calculating property index
CGQAQ Sep 26, 2025
d33fe62
fix: add generic shorthand serialization and improve shorthand handling
CGQAQ Sep 26, 2025
cb91807
fix: replace DDEBUG with DCHECK_IS_ON and use override in Copy method
CGQAQ Sep 29, 2025
4b44057
fix: add case-insensitive tag rule matching and StringView support fo…
CGQAQ Sep 30, 2025
94d0069
fix: optimize style resolution with fix inherited value maps and inli…
CGQAQ Sep 30, 2025
3783b94
fix: ensure 'vertical' defaults to 'auto' when 'horizontal' is not ex…
CGQAQ Sep 30, 2025
97b92b1
fix: add regression test for background-position parsing with length …
CGQAQ Oct 1, 2025
22d3566
fix: remove redundant VisitCharacters template utility in string_to_n…
CGQAQ Oct 1, 2025
9cf6ed1
fix: add StringImpl::ToDouble for converting string to double
CGQAQ Oct 1, 2025
9e19941
fix: refactor StringToUnitType not handling 16 bit string correctly
CGQAQ Oct 1, 2025
5a25cd5
fix: avoid unsafe pointer arithmetic in CSS parser and improve 8-bit …
CGQAQ Oct 1, 2025
d8abead
fix: improve CSS parser safety and simplify string handling
CGQAQ Oct 1, 2025
60c1325
fix: copy macOS dylibs after build completion
CGQAQ Oct 3, 2025
02406ca
fix: add StringImpl::ToUTF8String and refactor UTF-8 conversion logic
CGQAQ Oct 3, 2025
49bbfa0
fix: remove redundant std::string and std::string_view constructors f…
CGQAQ Oct 3, 2025
e5cdfa8
test: add placeholder test for hash collision scenario in StringImpl
CGQAQ Oct 8, 2025
d3d5799
fix: remove redundant macOS dylib copy step after build completion
CGQAQ Oct 8, 2025
3af8824
fix: support 4/8-digit hex color parsing in CSS parser
CGQAQ Oct 8, 2025
6ce93b0
feat: add conditional tagged logging support
CGQAQ Oct 9, 2025
a3d3431
fix: enhance CSS parser logging and property filtering
CGQAQ Oct 9, 2025
5bae358
feat: improve CSS cascade handling and variable substitution
CGQAQ Oct 9, 2025
aa416b9
feat: enhance UI command buffer logging for style commands
CGQAQ Oct 9, 2025
8592826
feat: add configurable logging options for WebF
CGQAQ Oct 10, 2025
0c07948
feat: add environment variable support for logging options in CMake
CGQAQ Oct 10, 2025
d86537f
chore: update `.gitignore` to exclude `blink_source` soft link
CGQAQ Oct 10, 2025
c830cdf
feat: add support for pseudo-style commands in UI commands system
CGQAQ Oct 10, 2025
85ab4d5
fix: prefer hex serialization for opaque colors in gradients
CGQAQ Oct 10, 2025
f26ac93
fix: correct sRGB legacy channel normalization during CSSOM serializa…
CGQAQ Oct 13, 2025
28e6a38
feat: add support for raw CSS value serialization
CGQAQ Oct 13, 2025
13030fe
feat: introducing CSSRawValue
CGQAQ Oct 16, 2025
98865d8
feat: introduce `CssTextForSerialization` for improved CSS serialization
CGQAQ Oct 16, 2025
7fc7e3c
fix: memory leak and use after free in UICommandType.setPseudoStyle
CGQAQ Oct 17, 2025
23e8b6d
feat: add more parsing logic to CSSValue's raw CSS text
CGQAQ Oct 17, 2025
85640b2
fix: failing serialize test only order diffs should be ok
CGQAQ Oct 17, 2025
dc5de2c
chore: remove redundant debug logs
CGQAQ Oct 17, 2025
1eaee7a
fix: wrong checks of a Pointer type in dart ffi
CGQAQ Oct 17, 2025
f761f83
feat: improve `var(...)` handling in CSS parsing
CGQAQ Oct 17, 2025
189ff60
fix: compile
CGQAQ Oct 21, 2025
c6a7222
fix: remove incorrect FlushUICommand calls
CGQAQ Oct 21, 2025
8fffeef
feat: optimize inline style updates with diff-based emission
CGQAQ Oct 21, 2025
622edfd
feat: preserve `!important` flag during inline style updates
CGQAQ Oct 21, 2025
5d63aea
chore: move UICommandType.clearStyle to the bottom of UICommandType.s…
CGQAQ Oct 21, 2025
8e7b6df
feat: introduce `MetricsRegistry` for thread-safe metrics tracking
CGQAQ Oct 22, 2025
64a7e03
revert: revert some changes that not quite right
CGQAQ Oct 22, 2025
c4dca44
feat: add `RecalcStyleForSubtree` for targeted style recalculations
CGQAQ Oct 22, 2025
394a9d4
fix: ensure inline styles are cleared before applying property updates
CGQAQ Oct 22, 2025
fe92899
log: add destruction log for `DartIsolateContext`
CGQAQ Oct 22, 2025
7e63c16
refactor: optimize inline style updates with diff-based approach
CGQAQ Oct 22, 2025
82026e1
feat: capture raw author input for color parsing in `CSSParserTokenSt…
CGQAQ Oct 23, 2025
cdd3793
fix: ensure proper flushing of UI commands before 'load' dispatch
CGQAQ Oct 23, 2025
96fa11e
refactor: remove verbose logging for style-related UI commands
CGQAQ Oct 23, 2025
460fa38
feat: add support for pseudo-elements ::first-letter and ::first-line
CGQAQ Oct 23, 2025
13370fe
feat: preserve raw CSS input for var() expressions
CGQAQ Oct 23, 2025
1505161
feat: preserve raw author input for custom property values
CGQAQ Oct 23, 2025
8db1644
refactor: remove invalid hack of SanitizeRawTextForSerialization method
CGQAQ Oct 23, 2025
dd7f845
feat: refine variable resolution and shorthand parsing
CGQAQ Oct 24, 2025
0a3c757
fix: remove unnecessary trim
CGQAQ Oct 29, 2025
7ea3c44
refactor: enhance trailing whitespace and comment removal logic
CGQAQ Oct 29, 2025
c119c6d
refactor: simplify shorthand text extraction logic
CGQAQ Oct 29, 2025
e7614b3
feat: preserve shorthand serialization for pending substitutions
CGQAQ Oct 29, 2025
9e0689a
feat: serialize shorthands consistently for var() values
CGQAQ Oct 29, 2025
983d400
feat: prioritize own dynamic properties over prototype lookup
CGQAQ Oct 29, 2025
e413ee1
feat: apply attributes before parsing children in HTML parser
CGQAQ Oct 29, 2025
d33f482
feat: improve CSS property parsing and keyword resolution
CGQAQ Oct 29, 2025
64140e2
feat: enhance verbose logging for HTMLLinkElement stylesheet updates
CGQAQ Oct 29, 2025
3027b68
feat: support base URL for CSS stylesheet parsing and serialization
CGQAQ Oct 30, 2025
154c0c3
feat: preserve raw color text in gradients when safe
CGQAQ Oct 30, 2025
355001a
fix: handle null CSS property values and disable `-webkit-transform` …
CGQAQ Oct 30, 2025
7491028
feat: implement CSS @import asynchronous fetch and rule resolution
CGQAQ Oct 31, 2025
0399c1a
revert: revert interface.cc.tpl to main branch
CGQAQ Nov 3, 2025
1a211b0
fix: preserve declared property names when exporting in style cascade
CGQAQ Nov 3, 2025
0a520ec
feat: add support for `counter()`/`counters()` in content and impleme…
CGQAQ Nov 5, 2025
0daf64d
feat: add support for `list-style-type` property with extended keywor…
CGQAQ Nov 5, 2025
e456fc4
feat: add @font-face registration and unregistration support via bridge
CGQAQ Nov 6, 2025
66e7e88
fix: clear stale inline overrides before emitting pseudo styles
CGQAQ Nov 7, 2025
33f2688
feat: optimize CSS rule matching with rightmost compound type filtering
CGQAQ Nov 7, 2025
2202b62
feat: implements correct `:nth-child` and `:nth-last-child` selector …
CGQAQ Nov 7, 2025
daf0f5b
feat: extend attribute selector matching with enhanced fallback support
CGQAQ Nov 7, 2025
985f577
chore: update snapshots
CGQAQ Nov 7, 2025
bc48429
chore: remove font logs
CGQAQ Nov 12, 2025
ab6ee3f
test: disable Rust test for now
CGQAQ Nov 12, 2025
0152c54
feat: enhance logger with time formatting and level display customiza…
CGQAQ Nov 12, 2025
0b2e356
refactor: update @font-face bridge methods to use `int64_t` for sheet ID
CGQAQ Nov 12, 2025
302c997
feat: add @keyframes bridge for registration and unregistration
CGQAQ Nov 12, 2025
4cbe1c8
feat: implement animation-* longhands and expand shorthand parsing
CGQAQ Nov 12, 2025
d4fb932
feat: relax whitespace rules around '+' and '-' in CSS calc expressions
CGQAQ Nov 12, 2025
9ca036b
test: update snapshots of blink/css1/font_properties/font.ts.
CGQAQ Nov 13, 2025
748cf47
fix: normalize 'initial' CSS values for flex properties in style seri…
CGQAQ Nov 13, 2025
0ae17d8
feat: add support for `word-break` CSS property
CGQAQ Nov 13, 2025
01627e0
fix: store class tokens verbatim to preserve case sensitivity
CGQAQ Nov 14, 2025
55e0d72
feat: add `StripWhiteSpace` utility for string handling
CGQAQ Nov 18, 2025
c6c60a5
feat: simplify media query parser to preserve raw conditions
CGQAQ Nov 18, 2025
8104864
feat: introduce dynamic MediaValues for live context evaluation
CGQAQ Nov 19, 2025
0dc82d8
feat: prefer explicit dark mode override in `colorScheme`
CGQAQ Nov 19, 2025
cdb9a10
feat: implement media-query environment change propagation, @prefer
CGQAQ Nov 21, 2025
892b4a9
feat: normalize CSS property names to camelCase for Dart style engine
CGQAQ Nov 21, 2025
cd97a13
feat: expand initial CSS property values with comprehensive defaults
CGQAQ Nov 21, 2025
9913b54
feat: support legacy rotate3d triple-angle syntax in CSS parser
CGQAQ Nov 21, 2025
ced2312
fix: correct `matrix3d` transform value in CSS transition test
CGQAQ Nov 21, 2025
423eed5
update: refresh snapshot for CSS background shorthand test
CGQAQ Nov 21, 2025
6a8413b
refactor: don't expand shorthand property
CGQAQ Nov 25, 2025
57bc738
update: refresh snapshot for CSS variable declaration test
CGQAQ Nov 25, 2025
05a449d
refactor: use raw text in longhands as well
CGQAQ Nov 25, 2025
d2029c6
feat: add logging for Blink engine enablement
CGQAQ Nov 26, 2025
b30b604
chore: remove verbose logging for author stylesheet rules in HTMLLink…
CGQAQ Nov 26, 2025
cf7c833
refactor: comment out unsupported property serialization logic in `st…
CGQAQ Nov 26, 2025
3ad4df7
chore: remove verbose logging from `StyleCascade`
CGQAQ Nov 26, 2025
dabeb6f
chore: add duration logging for style recalculation functions
CGQAQ Nov 26, 2025
53c8be9
update: refresh snapshot for comprehensive text mixin test
CGQAQ Dec 1, 2025
8520fd2
feat: invalidation set (Descendant Invalidation)
CGQAQ Nov 27, 2025
666f134
fix: prevent spurious MutationObserver callbacks for no-op style updates
CGQAQ Dec 3, 2025
b69c32c
feat: ensure getComputedStyle reflects latest Blink CSS engine styles
CGQAQ Dec 3, 2025
f8a2cd2
fix: make Codec disposal resilient to native peer lifecycle
CGQAQ Dec 3, 2025
5656ead
feat: add baseHref support to CSS style application pipeline
CGQAQ Dec 3, 2025
9071dff
chore: update .gitignore to exclude preview tool bundles (.preview-bu…
CGQAQ Dec 3, 2025
c660ed7
feat: add baseHref support to pseudo styles
CGQAQ Dec 3, 2025
e2d448a
update: refresh snapshots for css-position fixed tests
CGQAQ Dec 3, 2025
f9c5466
test: skip a test in img_css_variables.ts due to var() cannot be in t…
CGQAQ Dec 4, 2025
8e6e033
chore: comment out unused logic in style cascade resolver
CGQAQ Dec 4, 2025
9460c56
feat: improve style recalculation to handle dirty subtrees
CGQAQ Dec 4, 2025
caf9b20
feat: optimize style recalculation for viewport-dependent media queries
CGQAQ Dec 5, 2025
417c77f
fix: Fix pseudo-class resolution in CSSSelector
CGQAQ Dec 8, 2025
03bec65
fix: Fix wrong implementation of QualifiedName::IsNull
CGQAQ Dec 8, 2025
8764bce
fix: Fix potential encoding bugs
CGQAQ Dec 8, 2025
15183e6
fix: fix leak of Document and CSSStyleSheet
CGQAQ Sep 11, 2025
eab8465
feat: add support for pseudo-style commands in UI commands system
CGQAQ Oct 10, 2025
ed4ef5d
feat: Unified style recalc
CGQAQ Dec 10, 2025
18e1412
feat: support sibling and nth-pseudo invalidations in StyleEngine
CGQAQ Dec 12, 2025
773d4c6
chore: remove redundant font-face warning logs
CGQAQ Dec 12, 2025
f0e594b
refactor: replace `AtomicString` with `stringToNativeString` for tran…
CGQAQ Dec 12, 2025
0331e0f
feat: enhance media query evaluation and optimize style recalculation
CGQAQ Dec 17, 2025
6a4168c
docs: add repository guidelines in AGENTS.md
CGQAQ Dec 17, 2025
27d239a
fix: Fix viewport resizing logic in ResponsivePage component
CGQAQ Dec 17, 2025
cd6a2cd
feat: optimize viewport management and enhance media query handling
CGQAQ Dec 17, 2025
acb3554
docs: update AGENTS.md with agent-specific guidelines
CGQAQ Dec 17, 2025
46e0067
fix: Fix build after rebase
CGQAQ Dec 17, 2025
f4ba45f
fix: fix repeat load events for link element.
andycall Dec 17, 2025
d5282a7
fix: Double trace introduced in rebase
CGQAQ Dec 18, 2025
e530a7a
refactor: remove unused media query evaluation code in `HTMLLinkElement`
CGQAQ Dec 18, 2025
da63175
docs: clarify agent guidelines in AGENTS.md
CGQAQ Dec 18, 2025
5dbdd5a
feat: enhance media query evaluation and integrate result tracking
CGQAQ Dec 18, 2025
88d8ec4
feat: extend media query handling to support scoped and text track up…
CGQAQ Dec 18, 2025
5725790
fix: Fix bridge unittests
CGQAQ Dec 19, 2025
06e6b7e
fix: Fix bridge unittests(pt.2)
CGQAQ Dec 19, 2025
b67625d
fix: Fix bridge unittests(pt.3)
CGQAQ Dec 19, 2025
be6708b
fix: Fix bridge unittests(pt.4)
CGQAQ Dec 19, 2025
d05d30e
chore: Log cleanups
CGQAQ Dec 20, 2025
5e35894
feat: add a setup script for msys2 windows
CGQAQ Dec 20, 2025
55126b1
fix: Fix windows build by exclude GDI headers
CGQAQ Dec 20, 2025
73169f6
test: Remove css_default_style_sheets_test
CGQAQ Dec 20, 2025
09a33dc
fix: fix invalid gradient color string.
andycall Dec 19, 2025
3047816
fix: fix invalid css syntax parse errror.
andycall Dec 19, 2025
3437ab0
fix(text): improve small-caps rendering
andycall Dec 19, 2025
ad10136
feat: add more font-variants support.
andycall Dec 20, 2025
17e3fe7
fix: fix none negative percentage font size.
andycall Dec 20, 2025
90b2ff0
fix: fix default cursive font family.
andycall Dec 20, 2025
d6f4a86
fix: fix default font familys
andycall Dec 20, 2025
2ec4698
fix: Fix document leak and replace `TraceAfterDispatch` with `Trace` …
CGQAQ Dec 21, 2025
90151fb
chore: Comment out debug logs in `CSSPropertyValueSet::ParseValue`
CGQAQ Dec 21, 2025
7d49bf2
test: update expected `font-family` computed values in integration tests
CGQAQ Dec 21, 2025
08a6c5a
test: update snapshots for `css-position/fixed` integration tests
CGQAQ Dec 21, 2025
9b8263f
test: update snapshot for `css-box/overflow` integration test
CGQAQ Dec 21, 2025
632e662
fix: ensure inline styles are updated only for active documents
CGQAQ Dec 21, 2025
d223a80
fix: preserve original font-family casing during style rule processing
CGQAQ Dec 21, 2025
e1cab52
test: update snapshots for css-overflow and css-position fixed integr…
CGQAQ Dec 21, 2025
e9764bf
fix: ensure styles are recalculated before snapshot sync in test harness
CGQAQ Dec 21, 2025
333bcdb
chore: clean up logs
andycall Dec 20, 2025
32685ca
fix: sync print logs
andycall Dec 21, 2025
8ddcc3f
fix: fix css style sheet unregistry
andycall Dec 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 7 additions & 1 deletion bridge/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ out
code_gen
.cache

bin
bin

# ignore blink soft link
blink_source

# ignore preview tools
.preview-bundles
43 changes: 43 additions & 0 deletions bridge/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Repository Guidelines

## Project Structure & Module Organization
- `bridge/`: C++17 native bridge (JS runtime, DOM/CSS, bindings). Core code in `bridge/core/`; generated code in `bridge/code_gen/`; unit tests in `bridge/test/`; third-party deps in `bridge/third_party/`.
- `webf/`: Dart/Flutter engine (DOM/layout/painting). Tests in `webf/test/` and `webf/integration_test/`.
- `cli/`: TypeScript CLI/codegen helpers. Tests in `cli/test/`.
- `integration_tests/`: E2E + snapshot runner and tooling.
- `scripts/`: Repo-wide build/codegen utilities invoked by `npm run ...`.

## Build, Test, and Development Commands
Run from repo root (`../`) unless noted:
- Install dependencies: `npm install`
- Build bridge (macOS): `npm run build:bridge:macos` (other targets: `build:bridge:{android,ios,linux,windows}`)
- Clean build artifacts: `npm run build:clean`
- Regenerate bindings/types: `npm run bindgen` (don’t hand-edit files under `bridge/code_gen/`)
- Bridge unit tests: `node scripts/run_bridge_unit_test.js`
- Flutter analyze/format: `npm run lint` / `npm run format`
- Flutter tests: `cd webf && flutter test`
- Integration tests: `cd integration_tests && npm run integration`
- CLI tests: `cd cli && npm test`

## Coding Style & Naming Conventions
- C++ (bridge): 2-space indent, 120 cols, Chromium style via `.clang-format`; files use `.cc`/`.h`.
- Dart (webf): follow `webf/analysis_options.yaml`; files `snake_case.dart`, types `PascalCase`, members `camelCase`.
- TypeScript (cli): strict TS; keep generators deterministic; Jest tests use `*.test.ts`.

## Testing Guidelines
- Bridge uses GoogleTest; keep tests small and behavior-focused, and mirror source paths under `bridge/test/`.
- Do not create or run tests unless explicitly requested.
- Do not modify existing tests unless explicitly instructed.

## Commit & Pull Request Guidelines
- Use Conventional Commits: `type(scope): subject` (e.g., `fix(bridge): handle null QualifiedName`).
- PRs should include rationale, linked issues, and exact verification steps; add screenshots for UI changes in `webf_apps/`.
- Do not commit anything unless explicitly requested.

## Agent-Specific Instructions
- Always explain why changes are needed before making them.
- Do not build anything unless explicitly requested.

## Security & Configuration Tips
- Initialize submodules: `git submodule update --init --recursive`.
- Common build env: `WEBF_BUILD=Release`, `ENABLE_PROFILE=true`. Platform deps include Flutter SDK + CMake/Clang (macOS) and Xcode/NDK where applicable.
73 changes: 73 additions & 0 deletions bridge/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ if(CMAKE_SYSTEM_NAME MATCHES "MSYS" OR MINGW)

# Define math constants that are not in standard C++
add_compile_definitions(_USE_MATH_DEFINES)
# Exclude GDI from Windows.h
add_compile_definitions(NOGDI)

if (DEFINED ENV{LIBRARY_OUTPUT_DIR})
set(CMAKE_INSTALL_PREFIX $ENV{LIBRARY_OUTPUT_DIR})
Expand Down Expand Up @@ -206,6 +208,10 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/code_gen)
set(BRIDGE_SOURCE_LOADED FALSE)
set(_BRIDGE_SOURCES_JSON5 "${CMAKE_CURRENT_SOURCE_DIR}/bridge_sources.json5")
if(EXISTS "${_BRIDGE_SOURCES_JSON5}")
# Ensure changes to bridge_sources.json5 trigger a CMake reconfigure so newly
# added source files are picked up (otherwise builds can fail at link time
# with unresolved symbols).
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${_BRIDGE_SOURCES_JSON5}")
execute_process(
COMMAND node ${CMAKE_CURRENT_SOURCE_DIR}/scripts/read_bridge_sources.js ${_BRIDGE_SOURCES_JSON5}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
Expand Down Expand Up @@ -445,3 +451,70 @@ 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()
44 changes: 44 additions & 0 deletions bridge/bindings/qjs/atomic_string_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <quickjs/quickjs.h>
#include <codecvt>
#include <iterator>
#include "event_type_names.h"
#include "gtest/gtest.h"
#include "native_string_utils.h"
Expand Down Expand Up @@ -197,6 +198,27 @@ TEST(AtomicString, MixedUTF8AndUTF16) {
EXPECT_EQ(str2, "Hello 世界");
}

TEST(AtomicString, ConstructFromStringView) {
TEST_init();

String ascii = String::FromUTF8("string-view");
StringView ascii_view(ascii);
AtomicString from_ascii(ascii_view);
EXPECT_TRUE(from_ascii.Is8Bit());
EXPECT_EQ(from_ascii.ToUTF8String(), "string-view");

const char16_t wide_chars[] = u"Bảo hiểm";
String wide(wide_chars, std::size(wide_chars) - 1);
StringView wide_view(wide);
AtomicString from_wide(wide_view);
EXPECT_FALSE(from_wide.Is8Bit());
EXPECT_EQ(from_wide.ToUTF8String(), "Bảo hiểm");

StringView null_view;
AtomicString from_null(null_view);
EXPECT_TRUE(from_null.IsNull());
}

TEST(AtomicString, UTF16WithSurrogatePairs) {
TEST_init();

Expand Down Expand Up @@ -328,3 +350,25 @@ TEST(StringImpl, CreateFromUTF8Empty) {
EXPECT_TRUE(str2->length() == 0);
EXPECT_EQ(str1, str2); // Should return the same empty string singleton
}

// Adding for hash collision reference
// TEST(StringImpl, HashCollision1) {
// TEST_init();
//
// // Test hash collision
// auto str1 = StringImpl::CreateFromUTF8(R"#(
// * {
// padding: 0;
// margin: 0;
// }
// .q {
// margin: 10px;
// padding: 10px;
// flex: 1 1 auto;
// background: gold;
// }
// )#");
// auto str2 = StringImpl::CreateFromUTF8("screen_async");
//
// EXPECT_EQ(str1->GetHash(), str2->GetHash());
// }
16 changes: 15 additions & 1 deletion bridge/bindings/qjs/converter_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,14 @@ struct Converter<IDLSequence<T>> : public ConverterBase<IDLSequence<T>> {
}

ImplType v;
uint32_t length = Converter<IDLUint32>::FromValue(ctx, JS_GetPropertyStr(ctx, value, "length"), exception_state);
JSValue length_value = JS_GetPropertyStr(ctx, value, "length");
if (JS_IsException(length_value)) {
exception_state.ThrowException(ctx, length_value);
JS_FreeValue(ctx, length_value);
return {};
}
uint32_t length = Converter<IDLUint32>::FromValue(ctx, length_value, exception_state);
JS_FreeValue(ctx, length_value);

v.reserve(length);

Expand Down Expand Up @@ -430,12 +437,19 @@ struct Converter<JSEventListener> : public ConverterBase<JSEventListener> {
if (JS_IsObject(value) && !JS_IsFunction(ctx, value)) {
JSValue handleEventMethod = JS_GetPropertyStr(ctx, value, "handleEvent");

if (JS_IsException(handleEventMethod)) {
exception_state.ThrowException(ctx, handleEventMethod);
JS_FreeValue(ctx, handleEventMethod);
return JSEventListener::CreateOrNull(nullptr);
}

if (JS_IsFunction(ctx, handleEventMethod)) {
auto result = JSEventListener::CreateOrNull(QJSFunction::Create(ctx, handleEventMethod, value));
JS_FreeValue(ctx, handleEventMethod);
return result;
}

JS_FreeValue(ctx, handleEventMethod);
return JSEventListener::CreateOrNull(nullptr);
}
return JSEventListener::CreateOrNull(QJSFunction::Create(ctx, value));
Expand Down
8 changes: 8 additions & 0 deletions bridge/bindings/qjs/heap_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
#ifndef BRIDGE_BINDINGS_QJS_HEAP_VECTOR_H_
#define BRIDGE_BINDINGS_QJS_HEAP_VECTOR_H_

#include <algorithm>
#include <cassert>
#include <cstddef>
#include <iostream>
#include <vector>

#include "bindings/qjs/cppgc/gc_visitor.h"

namespace webf {

template <typename V>
Expand Down
25 changes: 25 additions & 0 deletions bridge/bindings/qjs/native_string_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

#include "native_string_utils.h"

#include <cstring>

#include "foundation/dart_readable.h"
#include "foundation/string/wtf_string.h"

namespace webf {

std::unique_ptr<SharedNativeString> jsValueToNativeString(JSContext* ctx, JSValue value) {
Expand Down Expand Up @@ -44,6 +49,26 @@ std::unique_ptr<SharedNativeString> stringToNativeString(const std::string& stri
return SharedNativeString::FromTemporaryString(tmp.string(), tmp.length());
}

std::unique_ptr<SharedNativeString> stringToNativeString(const String& string) {
uint32_t length = string.length();
if (length == 0) {
return std::make_unique<SharedNativeString>(nullptr, 0);
}

auto* buffer = static_cast<uint16_t*>(dart_malloc(sizeof(uint16_t) * length));
if (string.Is8Bit()) {
const LChar* p = string.Characters8();
for (uint32_t i = 0; i < length; ++i) {
buffer[i] = static_cast<uint16_t>(p[i]);
}
} else {
const UChar* p = string.Characters16();
std::memcpy(buffer, p, sizeof(uint16_t) * length);
}

return std::make_unique<SharedNativeString>(buffer, length);
}

std::string nativeStringToStdString(const SharedNativeString* native_string) {
std::u16string u16EventType =
std::u16string(reinterpret_cast<const char16_t*>(native_string->string()), native_string->length());
Expand Down
7 changes: 7 additions & 0 deletions bridge/bindings/qjs/native_string_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,19 @@

namespace webf {

class String;

// Convert to string and return a full copy of NativeString from JSValue.
std::unique_ptr<SharedNativeString> jsValueToNativeString(JSContext* ctx, JSValue value);

// Encode utf-8 to utf-16, and return a full copy of NativeString.
std::unique_ptr<SharedNativeString> stringToNativeString(const std::string& string);

// Copies a WebF String to a NativeString (UTF-16) without interning.
// Prefer this over AtomicString(value).ToNativeString() for transient values
// (e.g. style values) to avoid growing the AtomicString table.
std::unique_ptr<SharedNativeString> stringToNativeString(const String& string);

std::string nativeStringToStdString(const SharedNativeString* native_string);

template <typename T>
Expand Down
2 changes: 1 addition & 1 deletion bridge/bindings/qjs/script_value.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ ScriptValue::ScriptValue(const ScriptValue& value) {
ScriptValue& ScriptValue::operator=(const ScriptValue& value) {
if (&value != this) {
JS_FreeValueRT(runtime_, value_);
runtime_ = value.runtime_;
value_ = JS_DupValueRT(runtime_, value.value_);
}
runtime_ = value.runtime_;
return *this;
}

Expand Down
24 changes: 20 additions & 4 deletions bridge/bridge_sources.json5
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
BRIDGE_SOURCE: [
"foundation/metrics_registry.cc",
"foundation/logging.cc",
"foundation/ios_logger.mm",
"foundation/native_string.cc",
Expand Down Expand Up @@ -119,10 +120,23 @@
"core/base/strings/utf_string_conversion_utils.cc",
"core/core_initializer.cc",

// Style
"core/css/style_element.cc",
"core/css/style_color.cc",
"core/css/style_engine.cc",
// Style
"core/css/style_element.cc",
"core/css/style_color.cc",
"core/css/active_style_sheets.cc",
"core/css/style_engine.cc",
"core/css/style_traversal_root.cc",
"core/css/style_invalidation_root.cc",
"core/css/style_recalc_root.cc",
"core/css/style_recalc_context.cc",
"core/css/css_global_rule_set.cc",
"core/css/rule_feature_set.cc",
"core/css/invalidation/invalidation_flags.cc",
"core/css/invalidation/invalidation_set.cc",
"core/css/invalidation/pending_invalidations.cc",
"core/css/invalidation/rule_invalidation_data.cc",
"core/css/invalidation/style_invalidator.cc",
"core/inspector/invalidation_set_to_selector_map.cc",

// Animation
"core/animation/animation_time_delta.cc",
Expand Down Expand Up @@ -188,6 +202,7 @@
"core/css/css_selector_list.cc",
"core/css/css_value.cc",
"core/css/media_list.cc",
"core/css/media_values_dynamic.cc",
"core/css/media_values.cc",
"core/css/style_scope.cc",
"core/css/cascade_layer.cc",
Expand Down Expand Up @@ -294,6 +309,7 @@
"core/css/css_value_pool.cc",
"core/css/cssom_utils.cc",
"core/css/css_string_value.cc",
"core/css/css_raw_value.cc",
"core/css/css_initial_value.cc",
"core/css/css_numeric_literal_value",
"core/css/css_color.cc",
Expand Down
3 changes: 2 additions & 1 deletion bridge/core/base/strings/string_number_conversions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "foundation/macros.h"

#include "core/base/strings/string_number_conversions_internal.h"
#include "string/string_types.h"

namespace base {

Expand Down Expand Up @@ -117,7 +118,7 @@ bool StringToDouble(std::string_view input, double* output) {
return internal::StringToDoubleImpl(input, input.data(), *output);
}

bool StringToDouble(std::u16string_view input, double* output) {
bool StringToDouble(webf::UTF16StringView input, double* output) {
return internal::StringToDoubleImpl(input, reinterpret_cast<const uint16_t*>(input.data()), *output);
}

Expand Down
Loading
Loading