mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Adjusts code style
Signed-off-by: lfpraca <luisfelippe@protonmail.com>
This commit is contained in:
parent
415f75d5fc
commit
1ae42386f3
1 changed files with 53 additions and 58 deletions
|
@ -42,15 +42,15 @@ pub(crate) struct Selection {
|
||||||
}
|
}
|
||||||
|
|
||||||
// this should be changed once content-visibility gets implemented to check for content-visibility == visible too
|
// this should be changed once content-visibility gets implemented to check for content-visibility == visible too
|
||||||
fn text_node_is_selectable(text_node: &Text) -> bool {
|
fn text_node_should_be_stringified(text_node: &Text, can_gc: CanGc) -> bool {
|
||||||
text_node
|
text_node
|
||||||
.upcast::<Node>()
|
.upcast::<Node>()
|
||||||
.GetParentElement()
|
.GetParentElement()
|
||||||
.and_then(|p| p.style(CanGc::note()))
|
.and_then(|parent| parent.style(can_gc))
|
||||||
.is_some_and(|s| {
|
.is_some_and(|style| {
|
||||||
!s.get_box().display.is_none()
|
!style.get_box().display.is_none() &&
|
||||||
&& s.get_inherited_box().visibility
|
style.get_inherited_box().visibility ==
|
||||||
== longhands::visibility::computed_value::T::Visible
|
longhands::visibility::computed_value::T::Visible
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -532,65 +532,60 @@ impl SelectionMethods<crate::DomTypeHolder> for Selection {
|
||||||
|
|
||||||
// https://w3c.github.io/selection-api/#dom-selection-stringifier
|
// https://w3c.github.io/selection-api/#dom-selection-stringifier
|
||||||
fn Stringifier(&self) -> DOMString {
|
fn Stringifier(&self) -> DOMString {
|
||||||
if let Some(range) = self.range.get() {
|
let Some(range) = self.range.get() else {
|
||||||
let start_node = range.start_container();
|
return DOMString::from("");
|
||||||
let end_node = range.end_container();
|
};
|
||||||
|
|
||||||
// Step 1.
|
let start_node = range.start_container();
|
||||||
let mut s = DOMString::new();
|
let end_node = range.end_container();
|
||||||
|
|
||||||
if let Some(text_node) = start_node.downcast::<Text>() {
|
let mut selection_text = DOMString::new();
|
||||||
if text_node_is_selectable(text_node) {
|
|
||||||
let char_data = text_node.upcast::<CharacterData>();
|
|
||||||
|
|
||||||
// Step 2.
|
if let Some(text_node) = start_node.downcast::<Text>() {
|
||||||
if start_node == end_node {
|
if text_node_should_be_stringified(text_node, CanGc::note()) {
|
||||||
let r = char_data
|
let char_data = text_node.upcast::<CharacterData>();
|
||||||
.SubstringData(
|
|
||||||
range.start_offset(),
|
|
||||||
range.end_offset() - range.start_offset(),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
return r;
|
if start_node == end_node {
|
||||||
}
|
return char_data
|
||||||
|
.SubstringData(
|
||||||
// Step 3.
|
range.start_offset(),
|
||||||
s.push_str(
|
range.end_offset() - range.start_offset(),
|
||||||
&char_data
|
)
|
||||||
.SubstringData(
|
.unwrap();
|
||||||
range.start_offset(),
|
|
||||||
char_data.Length() - range.start_offset(),
|
|
||||||
)
|
|
||||||
.unwrap(),
|
|
||||||
);
|
|
||||||
} else if start_node == end_node {
|
|
||||||
return s;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Step 4.
|
selection_text.push_str(
|
||||||
let ancestor = range.CommonAncestorContainer();
|
&char_data
|
||||||
for child in start_node
|
.SubstringData(
|
||||||
.following_nodes(&ancestor)
|
range.start_offset(),
|
||||||
.filter_map(DomRoot::downcast::<Text>)
|
char_data.Length() - range.start_offset(),
|
||||||
.filter(|t| text_node_is_selectable(t) && range.contains(t.upcast()))
|
)
|
||||||
{
|
.unwrap(),
|
||||||
s.push_str(&child.upcast::<CharacterData>().Data());
|
);
|
||||||
|
} else if start_node == end_node {
|
||||||
|
return selection_text;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 5.
|
|
||||||
if let Some(text_node) = end_node.downcast::<Text>() {
|
|
||||||
if text_node_is_selectable(text_node) {
|
|
||||||
let char_data = text_node.upcast::<CharacterData>();
|
|
||||||
s.push_str(&char_data.SubstringData(0, range.end_offset()).unwrap());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Step 6.
|
|
||||||
s
|
|
||||||
} else {
|
|
||||||
DOMString::from("")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let ancestor = range.CommonAncestorContainer();
|
||||||
|
for child in start_node
|
||||||
|
.following_nodes(&ancestor)
|
||||||
|
.filter_map(DomRoot::downcast::<Text>)
|
||||||
|
.filter(|text_node| {
|
||||||
|
text_node_should_be_stringified(text_node, CanGc::note()) &&
|
||||||
|
range.contains(text_node.upcast())
|
||||||
|
})
|
||||||
|
{
|
||||||
|
selection_text.push_str(&child.upcast::<CharacterData>().Data());
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(text_node) = end_node.downcast::<Text>() {
|
||||||
|
if text_node_should_be_stringified(text_node, CanGc::note()) {
|
||||||
|
let char_data = text_node.upcast::<CharacterData>();
|
||||||
|
selection_text.push_str(&char_data.SubstringData(0, range.end_offset()).unwrap());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
selection_text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue