From d01985cc3d2c1a9eedc2a3f8fc22182ea9f31c79 Mon Sep 17 00:00:00 2001 From: zhongyr Date: Fri, 26 Jun 2026 15:09:45 +0800 Subject: [PATCH] [BugFix] Propagate display none status from Starlight layout to Element - What changed Add a display_none flag to LayoutContext::Delegate::OnLayoutUpdate and Element::UpdateLayout. LayoutContext::UpdateLayoutInfo and FiberElement::UpdateLayoutInfo now read the flag from the Starlight layout result and pass it down. Element stores the flag and exposes it via display_none(). - Why it was needed Downstream code needs to know whether a node is treated as display:none by the layout engine without recomputing it from CSS. - How it was verified Ran layout_context_tests_exec, tasm_unittests_exec, layout_tests_exec, and fragment_test_exec. All passed. TEST: layout_context_tests_exec, tasm_unittests_exec, layout_tests_exec, fragment_test_exec AutoLand: release/4.0 AutoSubmit: true --- core/renderer/dom/element.cc | 3 ++- core/renderer/dom/element.h | 4 +++- core/renderer/dom/fiber/fiber_element.cc | 1 + .../empty/layout_context_empty_implementation.h | 2 +- core/renderer/ui_wrapper/layout/layout_context.cc | 4 +++- core/renderer/ui_wrapper/layout/layout_context.h | 2 +- core/shell/layout_mediator.cc | 11 +++++++---- core/shell/layout_mediator.h | 2 +- core/shell/testing/mock_layout_delegate.h | 2 +- 9 files changed, 20 insertions(+), 11 deletions(-) diff --git a/core/renderer/dom/element.cc b/core/renderer/dom/element.cc index b0eeab2b7c..0ef33042e2 100644 --- a/core/renderer/dom/element.cc +++ b/core/renderer/dom/element.cc @@ -400,7 +400,7 @@ void Element::UpdateLayout(float left, float top, float width, float height, const std::array& margins, const std::array& borders, const std::array* sticky_positions, - float max_height) { + float max_height, bool display_none) { TRACE_EVENT(LYNX_TRACE_CATEGORY, ELEMENT_UPDATE_LAYOUT); // TODO: only leaf node need to update border padding frame_changed_ = true; @@ -411,6 +411,7 @@ void Element::UpdateLayout(float left, float top, float width, float height, paddings_ = paddings; margins_ = margins; borders_ = borders; + display_none_ = display_none; UpdateStickyPosition(sticky_positions); MarkSubtreeNeedUpdate(); NotifyElementSizeUpdated(); diff --git a/core/renderer/dom/element.h b/core/renderer/dom/element.h index f2923d7bd6..7e9ac85b45 100644 --- a/core/renderer/dom/element.h +++ b/core/renderer/dom/element.h @@ -718,7 +718,7 @@ class Element : public lepus::RefCounted, const std::array& margins, const std::array& borders, const std::array* sticky_positions, - float max_height); + float max_height, bool display_none = false); // Used to update child element's left and top value from list element. The // another overloaded function is used to update layout info from starlight, // but if the element is list's child, the left and top's value are always 0. @@ -878,6 +878,7 @@ class Element : public lepus::RefCounted, float height() { return height_; } float top() { return top_; } float left() { return left_; } + bool display_none() { return display_none_; } bool enable_new_animator() { return enable_new_animator_; } @@ -1543,6 +1544,7 @@ class Element : public lepus::RefCounted, bool subtree_need_update_{false}; bool frame_changed_{false}; + bool display_none_{false}; // Determine by Catalyzer bool is_layout_only_{false}; diff --git a/core/renderer/dom/fiber/fiber_element.cc b/core/renderer/dom/fiber/fiber_element.cc index b959b948c3..1756ec76c9 100644 --- a/core/renderer/dom/fiber/fiber_element.cc +++ b/core/renderer/dom/fiber/fiber_element.cc @@ -5601,6 +5601,7 @@ void FiberElement::UpdateLayoutInfo() { borders_[1] = layout_result.border_[starlight::kTop]; borders_[2] = layout_result.border_[starlight::kRight]; borders_[3] = layout_result.border_[starlight::kBottom]; + display_none_ = sl_node_->GetShouldDisplayNone(); if (IsShadowNodeCustom()) { element_manager_->layout_context()->OnLayout(id_, left_, top_, width_, diff --git a/core/renderer/ui_wrapper/layout/empty/layout_context_empty_implementation.h b/core/renderer/ui_wrapper/layout/empty/layout_context_empty_implementation.h index 5502adfd7d..94af709a4c 100644 --- a/core/renderer/ui_wrapper/layout/empty/layout_context_empty_implementation.h +++ b/core/renderer/ui_wrapper/layout/empty/layout_context_empty_implementation.h @@ -23,7 +23,7 @@ class DelegateEmptyImpl : public LayoutContext::Delegate { const std::array& margins, const std::array& borders, const std::array* sticky_positions, - float max_height) override {} + float max_height, bool display_none) override {} virtual void OnLayoutAfter(const std::shared_ptr& options, std::unique_ptr holder, bool has_layout) override {} diff --git a/core/renderer/ui_wrapper/layout/layout_context.cc b/core/renderer/ui_wrapper/layout/layout_context.cc index f92bcb9cf5..6c0326ed20 100644 --- a/core/renderer/ui_wrapper/layout/layout_context.cc +++ b/core/renderer/ui_wrapper/layout/layout_context.cc @@ -942,9 +942,11 @@ void LayoutContext::UpdateLayoutInfo(LayoutNode* node) { } } + bool display_none = sl_node->GetShouldDisplayNone(); delegate_->OnLayoutUpdate( node->id(), left, top, width, height, paddings, margins, borders, - sticky_positions, sl_node->GetCSSStyle()->GetMaxHeight().GetRawValue()); + sticky_positions, sl_node->GetCSSStyle()->GetMaxHeight().GetRawValue(), + display_none); if (node->slnode()->GetSLMeasureFunc()) { // Dispatch OnLayoutAfter to those nodes that have custom measure diff --git a/core/renderer/ui_wrapper/layout/layout_context.h b/core/renderer/ui_wrapper/layout/layout_context.h index 2175763de3..db66579682 100644 --- a/core/renderer/ui_wrapper/layout/layout_context.h +++ b/core/renderer/ui_wrapper/layout/layout_context.h @@ -60,7 +60,7 @@ class LayoutContext : public std::enable_shared_from_this, const std::array& margins, const std::array& borders, const std::array* sticky_positions, - float max_height) = 0; + float max_height, bool display_none) = 0; void OnLayoutAfter(const std::shared_ptr& options) { OnLayoutAfter(options, nullptr, false); }; diff --git a/core/shell/layout_mediator.cc b/core/shell/layout_mediator.cc index 5823e38cb3..da155da43d 100644 --- a/core/shell/layout_mediator.cc +++ b/core/shell/layout_mediator.cc @@ -32,7 +32,8 @@ void LayoutMediator::OnLayoutUpdate( int tag, float x, float y, float width, float height, const std::array &paddings, const std::array &margins, const std::array &borders, - const std::array *sticky_positions, float max_height) { + const std::array *sticky_positions, float max_height, + bool display_none) { std::array sticky_positions_clone; bool has_sticky = false; if (sticky_positions) { @@ -43,15 +44,17 @@ void LayoutMediator::OnLayoutUpdate( if (node_manager_ != nullptr) { operation_queue_->EnqueueOperation( [node_manager = node_manager_, tag, x, y, width, height, paddings, - margins, borders, sticky_positions_clone, has_sticky, max_height]() { + margins, borders, sticky_positions_clone, has_sticky, max_height, + display_none]() { auto *node = node_manager->Get(tag); if (node != nullptr) { if (has_sticky) { node->UpdateLayout(x, y, width, height, paddings, margins, - borders, &sticky_positions_clone, max_height); + borders, &sticky_positions_clone, max_height, + display_none); } else { node->UpdateLayout(x, y, width, height, paddings, margins, - borders, nullptr, max_height); + borders, nullptr, max_height, display_none); } } else { LOGE( diff --git a/core/shell/layout_mediator.h b/core/shell/layout_mediator.h index 318d1477bc..9f16c2d1c3 100644 --- a/core/shell/layout_mediator.h +++ b/core/shell/layout_mediator.h @@ -43,7 +43,7 @@ class LayoutMediator : public tasm::LayoutContext::Delegate, const std::array &margins, const std::array &borders, const std::array *sticky_positions, - float max_height) override; + float max_height, bool display_none) override; void OnLayoutAfter(const std::shared_ptr &option, std::unique_ptr holder, bool has_layout) override; diff --git a/core/shell/testing/mock_layout_delegate.h b/core/shell/testing/mock_layout_delegate.h index 69fd450af2..d3bca0d5e1 100644 --- a/core/shell/testing/mock_layout_delegate.h +++ b/core/shell/testing/mock_layout_delegate.h @@ -25,7 +25,7 @@ class MockLayoutDelegate : public LayoutContext::Delegate { const std::array& margins, const std::array& borders, const std::array* sticky_positions, - float max_height) override {} + float max_height, bool /*display_none*/) override {} void PostPlatformExtraBundle( int32_t id, std::unique_ptr bundle) override {} void OnCalculatedViewportChanged(const CalculatedViewport& viewport,