ported from UXP: Bug 1331322 - Allow tagging of pseudo-implementing native anonymous content with the pseudo type at creation time (b723a5c8)

This commit is contained in:
2022-04-12 13:27:13 +08:00
parent b66784a394
commit 794dd4ef30
24 changed files with 269 additions and 131 deletions
+3 -23
View File
@@ -352,32 +352,12 @@ nsTextControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
// Create the placeholder anonymous content if needed.
if (mUsePlaceholder) {
nsIContent* placeholderNode = txtCtrl->CreatePlaceholderNode();
Element* placeholderNode = txtCtrl->CreatePlaceholderNode();
NS_ENSURE_TRUE(placeholderNode, NS_ERROR_OUT_OF_MEMORY);
// Associate ::placeholder pseudo-element with the placeholder node.
CSSPseudoElementType pseudoType = CSSPseudoElementType::placeholder;
// If this is a text input inside a number input then we want to use the
// main number input as the source of style for the placeholder frame.
nsIFrame* mainInputFrame = this;
if (StyleContext()->GetPseudoType() == CSSPseudoElementType::mozNumberText) {
do {
mainInputFrame = mainInputFrame->GetParent();
} while (mainInputFrame &&
mainInputFrame->GetType() != nsGkAtoms::numberControlFrame);
MOZ_ASSERT(mainInputFrame);
}
RefPtr<nsStyleContext> placeholderStyleContext =
PresContext()->StyleSet()->ResolvePseudoElementStyle(
mainInputFrame->GetContent()->AsElement(), pseudoType, StyleContext(),
placeholderNode->AsElement());
if (!aElements.AppendElement(ContentInfo(placeholderNode,
placeholderStyleContext))) {
return NS_ERROR_OUT_OF_MEMORY;
}
placeholderNode->SetPseudoElementType(CSSPseudoElementType::placeholder);
aElements.AppendElement(placeholderNode);
if (!IsSingleLineTextControl()) {
// For textareas, UpdateValueDisplay doesn't initialize the visibility