Bug 1838262, part 3: Removed ServoStyleSet::ProbeHighlightPseudoElementStyle(). r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D184709
This commit is contained in:
Jan-Niklas Jaeschke 2023-07-31 13:47:55 +00:00
parent c84288a36d
commit 12f5099c54
15 changed files with 41 additions and 109 deletions

View file

@ -81,7 +81,7 @@ void Highlight::RemoveFromHighlightRegistry(
}
already_AddRefed<Selection> Highlight::CreateHighlightSelection(
const nsAtom* aHighlightName, nsFrameSelection* aFrameSelection) {
nsAtom* aHighlightName, nsFrameSelection* aFrameSelection) {
MOZ_ASSERT(aFrameSelection);
MOZ_ASSERT(aFrameSelection->GetPresShell());
RefPtr<Selection> selection =

View file

@ -36,7 +36,7 @@ class Selection;
* to the `nsFrameSelection` and layout code.
*/
struct HighlightSelectionData {
RefPtr<const nsAtom> mHighlightName;
RefPtr<nsAtom> mHighlightName;
RefPtr<Highlight> mHighlight;
};
@ -92,7 +92,7 @@ class Highlight final : public nsISupports, public nsWrapperCache {
* @brief Creates a Highlight Selection using the given ranges.
*/
MOZ_CAN_RUN_SCRIPT already_AddRefed<Selection> CreateHighlightSelection(
const nsAtom* aHighlightName, nsFrameSelection* aFrameSelection);
nsAtom* aHighlightName, nsFrameSelection* aFrameSelection);
// WebIDL interface
nsPIDOMWindowInner* GetParentObject() const { return mWindow; }

View file

@ -77,7 +77,7 @@ void HighlightRegistry::MaybeAddRangeToHighlightSelection(
continue;
}
const RefPtr<const nsAtom> highlightName = iter.first();
const RefPtr<nsAtom> highlightName = iter.first();
frameSelection->AddHighlightSelectionRange(highlightName, aHighlight,
aRange);
}
@ -96,7 +96,7 @@ void HighlightRegistry::MaybeRemoveRangeFromHighlightSelection(
continue;
}
const RefPtr<const nsAtom> highlightName = iter.first();
const RefPtr<nsAtom> highlightName = iter.first();
frameSelection->RemoveHighlightSelectionRange(highlightName, aRange);
}
}
@ -111,7 +111,7 @@ void HighlightRegistry::RemoveHighlightSelection(Highlight& aHighlight) {
continue;
}
const RefPtr<const nsAtom> highlightName = iter.first();
const RefPtr<nsAtom> highlightName = iter.first();
frameSelection->RemoveHighlightSelection(highlightName);
}
}
@ -125,7 +125,7 @@ void HighlightRegistry::AddHighlightSelectionsToFrameSelection() {
return;
}
for (auto const& iter : mHighlightsOrdered) {
RefPtr<const nsAtom> highlightName = iter.first();
RefPtr<nsAtom> highlightName = iter.first();
RefPtr<Highlight> highlight = iter.second();
frameSelection->AddHighlightSelection(highlightName, *highlight);
}
@ -152,8 +152,8 @@ void HighlightRegistry::Set(const nsAString& aKey, Highlight& aValue,
foundIter->second() = &aValue;
} else {
mHighlightsOrdered.AppendElement(
CompactPair<RefPtr<const nsAtom>, RefPtr<Highlight>>(highlightNameAtom,
&aValue));
CompactPair<RefPtr<nsAtom>, RefPtr<Highlight>>(highlightNameAtom,
&aValue));
}
aValue.AddToHighlightRegistry(*this, *highlightNameAtom);
if (frameSelection) {
@ -170,7 +170,7 @@ void HighlightRegistry::Clear(ErrorResult& aRv) {
AutoFrameSelectionBatcher batcher(__FUNCTION__);
batcher.AddFrameSelection(frameSelection);
for (auto const& iter : mHighlightsOrdered) {
const RefPtr<const nsAtom>& highlightName = iter.first();
const RefPtr<nsAtom>& highlightName = iter.first();
const RefPtr<Highlight>& highlight = iter.second();
highlight->RemoveFromHighlightRegistry(*this, *highlightName);
if (frameSelection) {

View file

@ -148,8 +148,7 @@ class HighlightRegistry final : public nsISupports, public nsWrapperCache {
* b) because the insertion order defines the stacking order of
* of highlights that have the same priority.
*/
nsTArray<CompactPair<RefPtr<const nsAtom>, RefPtr<Highlight>>>
mHighlightsOrdered;
nsTArray<CompactPair<RefPtr<nsAtom>, RefPtr<Highlight>>> mHighlightsOrdered;
};
} // namespace mozilla::dom

View file

@ -1606,7 +1606,7 @@ Selection* nsFrameSelection::GetSelection(SelectionType aSelectionType) const {
}
void nsFrameSelection::AddHighlightSelection(
const nsAtom* aHighlightName, mozilla::dom::Highlight& aHighlight) {
nsAtom* aHighlightName, mozilla::dom::Highlight& aHighlight) {
RefPtr<Selection> selection =
aHighlight.CreateHighlightSelection(aHighlightName, this);
if (auto iter =
@ -1618,12 +1618,12 @@ void nsFrameSelection::AddHighlightSelection(
iter->second() = std::move(selection);
} else {
mHighlightSelections.AppendElement(
CompactPair<RefPtr<const nsAtom>, RefPtr<Selection>>(
aHighlightName, std::move(selection)));
CompactPair<RefPtr<nsAtom>, RefPtr<Selection>>(aHighlightName,
std::move(selection)));
}
}
void nsFrameSelection::RemoveHighlightSelection(const nsAtom* aHighlightName) {
void nsFrameSelection::RemoveHighlightSelection(nsAtom* aHighlightName) {
if (auto iter =
std::find_if(mHighlightSelections.begin(), mHighlightSelections.end(),
[&aHighlightName](auto const& aElm) {
@ -1637,7 +1637,7 @@ void nsFrameSelection::RemoveHighlightSelection(const nsAtom* aHighlightName) {
}
void nsFrameSelection::AddHighlightSelectionRange(
const nsAtom* aHighlightName, mozilla::dom::Highlight& aHighlight,
nsAtom* aHighlightName, mozilla::dom::Highlight& aHighlight,
mozilla::dom::AbstractRange& aRange) {
if (auto iter =
std::find_if(mHighlightSelections.begin(), mHighlightSelections.end(),
@ -1652,13 +1652,13 @@ void nsFrameSelection::AddHighlightSelectionRange(
RefPtr<Selection> selection =
aHighlight.CreateHighlightSelection(aHighlightName, this);
mHighlightSelections.AppendElement(
CompactPair<RefPtr<const nsAtom>, RefPtr<Selection>>(
aHighlightName, std::move(selection)));
CompactPair<RefPtr<nsAtom>, RefPtr<Selection>>(aHighlightName,
std::move(selection)));
}
}
void nsFrameSelection::RemoveHighlightSelectionRange(
const nsAtom* aHighlightName, mozilla::dom::AbstractRange& aRange) {
nsAtom* aHighlightName, mozilla::dom::AbstractRange& aRange) {
if (auto iter =
std::find_if(mHighlightSelections.begin(), mHighlightSelections.end(),
[&aHighlightName](auto const& aElm) {

View file

@ -435,12 +435,11 @@ class nsFrameSelection final {
* @brief Adds a highlight selection for `aHighlight`.
*/
MOZ_CAN_RUN_SCRIPT void AddHighlightSelection(
const nsAtom* aHighlightName, mozilla::dom::Highlight& aHighlight);
nsAtom* aHighlightName, mozilla::dom::Highlight& aHighlight);
/**
* @brief Removes the Highlight selection identified by `aHighlightName`.
*/
MOZ_CAN_RUN_SCRIPT void RemoveHighlightSelection(
const nsAtom* aHighlightName);
MOZ_CAN_RUN_SCRIPT void RemoveHighlightSelection(nsAtom* aHighlightName);
/**
* @brief Adds a new range to the highlight selection.
@ -449,14 +448,14 @@ class nsFrameSelection final {
* created using |AddHighlightSelection|.
*/
MOZ_CAN_RUN_SCRIPT void AddHighlightSelectionRange(
const nsAtom* aHighlightName, mozilla::dom::Highlight& aHighlight,
nsAtom* aHighlightName, mozilla::dom::Highlight& aHighlight,
mozilla::dom::AbstractRange& aRange);
/**
* @brief Removes a range from a highlight selection.
*/
MOZ_CAN_RUN_SCRIPT void RemoveHighlightSelectionRange(
const nsAtom* aHighlightName, mozilla::dom::AbstractRange& aRange);
nsAtom* aHighlightName, mozilla::dom::AbstractRange& aRange);
/**
* ScrollSelectionIntoView scrolls a region of the selection,
* so that it is visible in the scrolled view.
@ -985,8 +984,8 @@ class nsFrameSelection final {
mDomSelections[sizeof(mozilla::kPresentSelectionTypes) /
sizeof(mozilla::SelectionType)];
nsTArray<mozilla::CompactPair<RefPtr<const nsAtom>,
RefPtr<mozilla::dom::Selection>>>
nsTArray<
mozilla::CompactPair<RefPtr<nsAtom>, RefPtr<mozilla::dom::Selection>>>
mHighlightSelections;
struct TableSelection {

View file

@ -2417,13 +2417,13 @@ already_AddRefed<ComputedStyle> nsIFrame::ComputeSelectionStyle(
}
already_AddRefed<ComputedStyle> nsIFrame::ComputeHighlightSelectionStyle(
const nsAtom* aHighlightName) {
nsAtom* aHighlightName) {
Element* element = FindElementAncestorForMozSelection(GetContent());
if (!element) {
return nullptr;
}
return PresContext()->StyleSet()->ProbeHighlightPseudoElementStyle(
*element, aHighlightName, Style());
return PresContext()->StyleSet()->ProbePseudoElementStyle(
*element, PseudoStyleType::highlight, aHighlightName, Style());
}
template <typename SizeOrMaxSize>

View file

@ -895,7 +895,7 @@ class nsIFrame : public nsQueryFrame {
int16_t aSelectionStatus) const;
already_AddRefed<ComputedStyle> ComputeHighlightSelectionStyle(
const nsAtom* aHighlightName);
nsAtom* aHighlightName);
/**
* Accessor functions for geometric parent.

View file

@ -5478,7 +5478,7 @@ void nsTextFrame::DrawSelectionDecorations(
/* static */
bool nsTextFrame::GetSelectionTextColors(SelectionType aSelectionType,
const nsAtom* aHighlightName,
nsAtom* aHighlightName,
nsTextPaintStyle& aTextPaintStyle,
const TextRangeStyle& aRangeStyle,
nscolor* aForeground,
@ -5582,7 +5582,7 @@ class MOZ_STACK_CLASS SelectionRangeIterator {
bool GetNextSegment(gfxFloat* aXOffset, gfxTextRun::Range* aRange,
gfxFloat* aHyphenWidth,
nsTArray<SelectionType>& aSelectionType,
nsTArray<RefPtr<const nsAtom>>& aHighlightName,
nsTArray<RefPtr<nsAtom>>& aHighlightName,
nsTArray<TextRangeStyle>& aStyle);
void UpdateWithAdvance(gfxFloat aAdvance) {
@ -5617,7 +5617,7 @@ SelectionRangeIterator::SelectionRangeIterator(
bool SelectionRangeIterator::GetNextSegment(
gfxFloat* aXOffset, gfxTextRun::Range* aRange, gfxFloat* aHyphenWidth,
nsTArray<SelectionType>& aSelectionType,
nsTArray<RefPtr<const nsAtom>>& aHighlightName,
nsTArray<RefPtr<nsAtom>>& aHighlightName,
nsTArray<TextRangeStyle>& aStyle) {
if (mIterator.GetOriginalOffset() >= int32_t(mOriginalRange.end)) {
return false;
@ -6001,7 +6001,7 @@ bool nsTextFrame::PaintTextWithSelectionColors(
SelectionRangeIterator iterator(selectionRanges, contentRange,
*aParams.provider, mTextRun, startIOffset);
AutoTArray<SelectionType, 1> selectionTypes;
AutoTArray<RefPtr<const nsAtom>, 1> highlightNames;
AutoTArray<RefPtr<nsAtom>, 1> highlightNames;
AutoTArray<TextRangeStyle, 1> rangeStyles;
while (iterator.GetNextSegment(&iOffset, &range, &hyphenWidth,
selectionTypes, highlightNames,
@ -6083,7 +6083,7 @@ bool nsTextFrame::PaintTextWithSelectionColors(
SelectionRangeIterator iterator(selectionRanges, contentRange,
*aParams.provider, mTextRun, startIOffset);
AutoTArray<SelectionType, 1> selectionTypes;
AutoTArray<RefPtr<const nsAtom>, 1> highlightNames;
AutoTArray<RefPtr<nsAtom>, 1> highlightNames;
AutoTArray<TextRangeStyle, 1> rangeStyles;
while (iterator.GetNextSegment(&iOffset, &range, &hyphenWidth, selectionTypes,
highlightNames, rangeStyles)) {
@ -6190,7 +6190,7 @@ void nsTextFrame::PaintTextSelectionDecorations(
pt.y = (aParams.textBaselinePt.y - mAscent) / app;
}
AutoTArray<SelectionType, 1> nextSelectionTypes;
AutoTArray<RefPtr<const nsAtom>, 1> highlightNames;
AutoTArray<RefPtr<nsAtom>, 1> highlightNames;
AutoTArray<TextRangeStyle, 1> selectedStyles;
while (iterator.GetNextSegment(&iOffset, &range, &hyphenWidth,

View file

@ -984,7 +984,7 @@ class nsTextFrame : public nsIFrame {
* @return true if the selection affects colors, false otherwise
*/
static bool GetSelectionTextColors(SelectionType aSelectionType,
const nsAtom* aHighlightName,
nsAtom* aHighlightName,
nsTextPaintStyle& aTextPaintStyle,
const TextRangeStyle& aRangeStyle,
nscolor* aForeground,

View file

@ -216,7 +216,7 @@ void nsTextPaintStyle::GetHighlightColors(nscolor* aForeColor,
*aBackColor = NS_TRANSPARENT;
}
bool nsTextPaintStyle::GetCustomHighlightTextColor(const nsAtom* aHighlightName,
bool nsTextPaintStyle::GetCustomHighlightTextColor(nsAtom* aHighlightName,
nscolor* aForeColor) {
NS_ASSERTION(aForeColor, "aForeColor is null");
@ -239,8 +239,8 @@ bool nsTextPaintStyle::GetCustomHighlightTextColor(const nsAtom* aHighlightName,
return highlightStyle->HasAuthorSpecifiedTextColor();
}
bool nsTextPaintStyle::GetCustomHighlightBackgroundColor(
const nsAtom* aHighlightName, nscolor* aBackColor) {
bool nsTextPaintStyle::GetCustomHighlightBackgroundColor(nsAtom* aHighlightName,
nscolor* aBackColor) {
NS_ASSERTION(aBackColor, "aBackColor is null");
// non-existing highlights will be stored as `aHighlightName->nullptr`,
// so subsequent calls only need a hashtable lookup and don't have

View file

@ -55,9 +55,8 @@ class MOZ_STACK_CLASS nsTextPaintStyle {
void GetHighlightColors(nscolor* aForeColor, nscolor* aBackColor);
// Computes colors for custom highlights.
// Returns false if there are no rules associated with `aHighlightName`.
bool GetCustomHighlightTextColor(const nsAtom* aHighlightName,
nscolor* aForeColor);
bool GetCustomHighlightBackgroundColor(const nsAtom* aHighlightName,
bool GetCustomHighlightTextColor(nsAtom* aHighlightName, nscolor* aForeColor);
bool GetCustomHighlightBackgroundColor(nsAtom* aHighlightName,
nscolor* aBackColor);
void GetURLSecondaryColor(nscolor* aForeColor);
void GetIMESelectionColors(int32_t aIndex, nscolor* aForeColor,

View file

@ -495,20 +495,6 @@ already_AddRefed<ComputedStyle> ServoStyleSet::ResolvePseudoElementStyle(
return style.forget();
}
already_AddRefed<ComputedStyle> ServoStyleSet::ProbeHighlightPseudoElementStyle(
const dom::Element& aOriginatingElement, const nsAtom* aHighlightName,
ComputedStyle* aParentStyle) {
MOZ_ASSERT(!StylistNeedsUpdate());
MOZ_ASSERT(aHighlightName);
RefPtr<ComputedStyle> style =
Servo_ComputedValues_ResolveHighlightPseudoStyle(
&aOriginatingElement, aHighlightName, mRawData.get())
.Consume();
return style ? style.forget() : nullptr;
}
already_AddRefed<ComputedStyle>
ServoStyleSet::ResolveInheritingAnonymousBoxStyle(PseudoStyleType aType,
ComputedStyle* aParentStyle) {

View file

@ -227,18 +227,6 @@ class ServoStyleSet {
IsProbe::Yes);
}
/**
* @brief Get a style for a highlight pseudo element.
*
* The highlight is identified by its name `aHighlightName`.
*
* Returns null if there are no rules matching for the highlight pseudo
* element.
*/
already_AddRefed<ComputedStyle> ProbeHighlightPseudoElementStyle(
const dom::Element& aOriginatingElement, const nsAtom* aHighlightName,
ComputedStyle* aParentStyle);
// Resolves style for a (possibly-pseudo) Element without assuming that the
// style has been resolved. If the element was unstyled and a new style
// was resolved, it is not stored in the DOM. (That is, the element remains

View file

@ -4024,45 +4024,6 @@ fn debug_atom_array(atoms: &nsTArray<structs::RefPtr<nsAtom>>) -> String {
result
}
#[no_mangle]
pub extern "C" fn Servo_ComputedValues_ResolveHighlightPseudoStyle(
element: &RawGeckoElement,
highlight_name: *const nsAtom,
raw_data: &PerDocumentStyleData,
) -> Strong<ComputedValues> {
let element = GeckoElement(element);
let data = element
.borrow_data()
.expect("Calling ResolveHighlightPseudoStyle on unstyled element?");
let pseudo_element = unsafe {
AtomIdent::with(highlight_name, |atom| {
PseudoElement::Highlight(atom.to_owned())
})
};
let doc_data = raw_data.borrow();
let matching_fn = |pseudo: &PseudoElement| *pseudo == pseudo_element;
let global_style_data = &*GLOBAL_STYLE_DATA;
let guard = global_style_data.shared_lock.read();
let style = get_pseudo_style(
&guard,
element,
&pseudo_element,
RuleInclusion::All,
&data.styles,
None,
&doc_data.stylist,
/* is_probe = */ true,
Some(&matching_fn),
);
match style {
Some(s) => s.into(),
None => Strong::null(),
}
}
#[no_mangle]
pub extern "C" fn Servo_ComputedValues_ResolveXULTreePseudoStyle(
element: &RawGeckoElement,