summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/html/html_slot_element.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/blink/renderer/core/html/html_slot_element.cc')
-rw-r--r--chromium/third_party/blink/renderer/core/html/html_slot_element.cc41
1 files changed, 35 insertions, 6 deletions
diff --git a/chromium/third_party/blink/renderer/core/html/html_slot_element.cc b/chromium/third_party/blink/renderer/core/html/html_slot_element.cc
index f88a1f593c8..fd8cc754219 100644
--- a/chromium/third_party/blink/renderer/core/html/html_slot_element.cc
+++ b/chromium/third_party/blink/renderer/core/html/html_slot_element.cc
@@ -30,6 +30,7 @@
#include "third_party/blink/renderer/core/html/html_slot_element.h"
+#include "third_party/blink/renderer/bindings/core/v8/v8_assigned_nodes_options.h"
#include "third_party/blink/renderer/core/css/style_change_reason.h"
#include "third_party/blink/renderer/core/css/style_engine.h"
#include "third_party/blink/renderer/core/dom/events/event.h"
@@ -42,7 +43,6 @@
#include "third_party/blink/renderer/core/dom/text.h"
#include "third_party/blink/renderer/core/dom/whitespace_attacher.h"
#include "third_party/blink/renderer/core/frame/web_feature.h"
-#include "third_party/blink/renderer/core/html/assigned_nodes_options.h"
#include "third_party/blink/renderer/core/html_names.h"
#include "third_party/blink/renderer/core/probe/core_probes.h"
#include "third_party/blink/renderer/core/style/computed_style.h"
@@ -171,13 +171,33 @@ const HeapVector<Member<Element>> HTMLSlotElement::AssignedElementsForBinding(
return elements;
}
-void HTMLSlotElement::assign(HeapVector<Member<Node>> nodes) {
- if (SupportsAssignment())
- ContainingShadowRoot()->GetSlotAssignment().SetNeedsAssignmentRecalc();
+void HTMLSlotElement::assign(HeapVector<Member<Node>> nodes,
+ ExceptionState& exception_state) {
+ if (!SupportsAssignment() || !ContainingShadowRoot()->IsManualSlotting()) {
+ exception_state.ThrowDOMException(
+ DOMExceptionCode::kNotAllowedError,
+ "This shadow root does not support manual slot assignment.");
+ return;
+ }
+
assigned_nodes_candidates_.clear();
+ auto* host = OwnerShadowHost();
+ bool has_invalid_node = false;
for (auto& node : nodes) {
+ if (node->parentNode() != host) {
+ exception_state.ThrowDOMException(
+ DOMExceptionCode::kNotAllowedError,
+ "Node: '" + node->nodeName() +
+ "' is invalid for manual slot assignment.");
+ assigned_nodes_candidates_.clear();
+ has_invalid_node = true;
+ break;
+ }
assigned_nodes_candidates_.insert(node);
}
+
+ if (!has_invalid_node)
+ ContainingShadowRoot()->GetSlotAssignment().SetNeedsAssignmentRecalc();
}
void HTMLSlotElement::AppendAssignedNode(Node& host_child) {
@@ -197,6 +217,11 @@ void HTMLSlotElement::ClearAssignedNodesAndFlatTreeChildren() {
void HTMLSlotElement::UpdateFlatTreeNodeDataForAssignedNodes() {
Node* previous = nullptr;
for (auto& current : assigned_nodes_) {
+ bool flat_tree_parent_changed = false;
+ if (!current->NeedsStyleRecalc() && !current->GetComputedStyle()) {
+ if (auto* node_data = current->GetFlatTreeNodeData())
+ flat_tree_parent_changed = !node_data->AssignedSlot();
+ }
FlatTreeNodeData& flat_tree_node_data = current->EnsureFlatTreeNodeData();
flat_tree_node_data.SetAssignedSlot(this);
flat_tree_node_data.SetPreviousInAssignedNodes(previous);
@@ -205,6 +230,8 @@ void HTMLSlotElement::UpdateFlatTreeNodeDataForAssignedNodes() {
previous->GetFlatTreeNodeData()->SetNextInAssignedNodes(current);
}
previous = current;
+ if (flat_tree_parent_changed)
+ current->FlatTreeParentChanged();
}
if (previous) {
DCHECK(previous->GetFlatTreeNodeData());
@@ -273,8 +300,10 @@ void HTMLSlotElement::AttachLayoutTree(AttachContext& context) {
void HTMLSlotElement::DetachLayoutTree(bool performing_reattach) {
if (SupportsAssignment()) {
const HeapVector<Member<Node>>& flat_tree_children = assigned_nodes_;
- for (auto& node : flat_tree_children)
- node->DetachLayoutTree(performing_reattach);
+ for (auto& node : flat_tree_children) {
+ if (node->GetDocument() == GetDocument())
+ node->DetachLayoutTree(performing_reattach);
+ }
}
HTMLElement::DetachLayoutTree(performing_reattach);
}