зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1459844: Share more code and fix some inconsistencies between html / svg style elements. r=heycam
MozReview-Commit-ID: IkTrIfJI1iK
This commit is contained in:
Родитель
b73f5b5a53
Коммит
17a92ff99b
|
@ -85,6 +85,34 @@ nsStyleLinkElement::~nsStyleLinkElement()
|
||||||
nsStyleLinkElement::SetStyleSheet(nullptr);
|
nsStyleLinkElement::SetStyleSheet(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
nsStyleLinkElement::GetTitleAndMediaForElement(const Element& aSelf,
|
||||||
|
nsString& aTitle,
|
||||||
|
nsString& aMedia)
|
||||||
|
{
|
||||||
|
aSelf.GetAttr(kNameSpaceID_None, nsGkAtoms::title, aTitle);
|
||||||
|
aTitle.CompressWhitespace();
|
||||||
|
|
||||||
|
aSelf.GetAttr(kNameSpaceID_None, nsGkAtoms::media, aMedia);
|
||||||
|
// The HTML5 spec is formulated in terms of the CSSOM spec, which specifies
|
||||||
|
// that media queries should be ASCII lowercased during serialization.
|
||||||
|
//
|
||||||
|
// FIXME(emilio): How does it matter? This is going to be parsed anyway, CSS
|
||||||
|
// should take care of serializing it properly.
|
||||||
|
nsContentUtils::ASCIIToLower(aMedia);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
nsStyleLinkElement::IsCSSMimeTypeAttribute(const Element& aSelf)
|
||||||
|
{
|
||||||
|
nsAutoString type;
|
||||||
|
nsAutoString mimeType;
|
||||||
|
nsAutoString notUsed;
|
||||||
|
aSelf.GetAttr(kNameSpaceID_None, nsGkAtoms::type, type);
|
||||||
|
nsContentUtils::SplitMimeType(type, mimeType, notUsed);
|
||||||
|
return mimeType.IsEmpty() || mimeType.LowerCaseEqualsLiteral("text/css");
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
nsStyleLinkElement::Unlink()
|
nsStyleLinkElement::Unlink()
|
||||||
{
|
{
|
||||||
|
|
|
@ -93,6 +93,18 @@ protected:
|
||||||
mozilla::dom::ShadowRoot* aOldShadowRoot,
|
mozilla::dom::ShadowRoot* aOldShadowRoot,
|
||||||
ForceUpdate = ForceUpdate::No);
|
ForceUpdate = ForceUpdate::No);
|
||||||
|
|
||||||
|
// Gets a suitable title and media for SheetInfo out of an element, which
|
||||||
|
// needs to be `this`.
|
||||||
|
//
|
||||||
|
// NOTE(emilio): Needs nsString instead of nsAString because of
|
||||||
|
// CompressWhitespace.
|
||||||
|
static void GetTitleAndMediaForElement(const mozilla::dom::Element&,
|
||||||
|
nsString& aTitle,
|
||||||
|
nsString& aMedia);
|
||||||
|
|
||||||
|
// Returns whether the type attribute specifies the text/css mime type.
|
||||||
|
static bool IsCSSMimeTypeAttribute(const mozilla::dom::Element&);
|
||||||
|
|
||||||
virtual mozilla::Maybe<SheetInfo> GetStyleSheetInfo() = 0;
|
virtual mozilla::Maybe<SheetInfo> GetStyleSheetInfo() = 0;
|
||||||
|
|
||||||
// CC methods
|
// CC methods
|
||||||
|
|
|
@ -430,9 +430,13 @@ HTMLLinkElement::GetStyleSheetInfo()
|
||||||
return Nothing();
|
return Nothing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!IsCSSMimeTypeAttribute(*this)) {
|
||||||
|
return Nothing();
|
||||||
|
}
|
||||||
|
|
||||||
nsAutoString title;
|
nsAutoString title;
|
||||||
GetAttr(kNameSpaceID_None, nsGkAtoms::title, title);
|
nsAutoString media;
|
||||||
title.CompressWhitespace();
|
GetTitleAndMediaForElement(*this, title, media);
|
||||||
|
|
||||||
bool alternate = linkTypes & nsStyleLinkElement::eALTERNATE;
|
bool alternate = linkTypes & nsStyleLinkElement::eALTERNATE;
|
||||||
if (alternate && title.IsEmpty()) {
|
if (alternate && title.IsEmpty()) {
|
||||||
|
@ -440,30 +444,12 @@ HTMLLinkElement::GetStyleSheetInfo()
|
||||||
return Nothing();
|
return Nothing();
|
||||||
}
|
}
|
||||||
|
|
||||||
nsAutoString type;
|
|
||||||
nsAutoString mimeType;
|
|
||||||
nsAutoString notUsed;
|
|
||||||
GetAttr(kNameSpaceID_None, nsGkAtoms::type, type);
|
|
||||||
nsContentUtils::SplitMimeType(type, mimeType, notUsed);
|
|
||||||
if (!mimeType.IsEmpty() && !mimeType.LowerCaseEqualsLiteral("text/css")) {
|
|
||||||
return Nothing();
|
|
||||||
}
|
|
||||||
|
|
||||||
nsAutoString href;
|
nsAutoString href;
|
||||||
GetAttr(kNameSpaceID_None, nsGkAtoms::href, href);
|
GetAttr(kNameSpaceID_None, nsGkAtoms::href, href);
|
||||||
if (href.IsEmpty()) {
|
if (href.IsEmpty()) {
|
||||||
return Nothing();
|
return Nothing();
|
||||||
}
|
}
|
||||||
|
|
||||||
nsAutoString media;
|
|
||||||
GetAttr(kNameSpaceID_None, nsGkAtoms::media, media);
|
|
||||||
// The HTML5 spec is formulated in terms of the CSSOM spec, which specifies
|
|
||||||
// that media queries should be ASCII lowercased during serialization.
|
|
||||||
//
|
|
||||||
// FIXME(emilio): How does it matter? This is going to be parsed anyway, CSS
|
|
||||||
// should take care of serializing it properly.
|
|
||||||
nsContentUtils::ASCIIToLower(media);
|
|
||||||
|
|
||||||
nsCOMPtr<nsIURI> uri = Link::GetURI();
|
nsCOMPtr<nsIURI> uri = Link::GetURI();
|
||||||
nsCOMPtr<nsIPrincipal> prin = mTriggeringPrincipal;
|
nsCOMPtr<nsIPrincipal> prin = mTriggeringPrincipal;
|
||||||
return Some(SheetInfo {
|
return Some(SheetInfo {
|
||||||
|
|
|
@ -197,27 +197,14 @@ HTMLStyleElement::SetTextContentInternal(const nsAString& aTextContent,
|
||||||
Maybe<nsStyleLinkElement::SheetInfo>
|
Maybe<nsStyleLinkElement::SheetInfo>
|
||||||
HTMLStyleElement::GetStyleSheetInfo()
|
HTMLStyleElement::GetStyleSheetInfo()
|
||||||
{
|
{
|
||||||
nsAutoString title;
|
if (!IsCSSMimeTypeAttribute(*this)) {
|
||||||
GetAttr(kNameSpaceID_None, nsGkAtoms::title, title);
|
|
||||||
title.CompressWhitespace();
|
|
||||||
|
|
||||||
nsAutoString media;
|
|
||||||
GetAttr(kNameSpaceID_None, nsGkAtoms::media, media);
|
|
||||||
// The HTML5 spec is formulated in terms of the CSSOM spec, which specifies
|
|
||||||
// that media queries should be ASCII lowercased during serialization.
|
|
||||||
//
|
|
||||||
// FIXME(emilio): Doesn't matter I'd think, style should take care of that.
|
|
||||||
nsContentUtils::ASCIIToLower(media);
|
|
||||||
|
|
||||||
nsAutoString type;
|
|
||||||
nsAutoString mimeType;
|
|
||||||
nsAutoString notUsed;
|
|
||||||
GetAttr(kNameSpaceID_None, nsGkAtoms::type, type);
|
|
||||||
nsContentUtils::SplitMimeType(type, mimeType, notUsed);
|
|
||||||
if (!mimeType.IsEmpty() && !mimeType.LowerCaseEqualsLiteral("text/css")) {
|
|
||||||
return Nothing();
|
return Nothing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsAutoString title;
|
||||||
|
nsAutoString media;
|
||||||
|
GetTitleAndMediaForElement(*this, title, media);
|
||||||
|
|
||||||
nsCOMPtr<nsIPrincipal> prin = mTriggeringPrincipal;
|
nsCOMPtr<nsIPrincipal> prin = mTriggeringPrincipal;
|
||||||
return Some(SheetInfo {
|
return Some(SheetInfo {
|
||||||
*OwnerDoc(),
|
*OwnerDoc(),
|
||||||
|
|
|
@ -219,29 +219,24 @@ SVGStyleElement::SetTitle(const nsAString& aTitle, ErrorResult& rv)
|
||||||
Maybe<nsStyleLinkElement::SheetInfo>
|
Maybe<nsStyleLinkElement::SheetInfo>
|
||||||
SVGStyleElement::GetStyleSheetInfo()
|
SVGStyleElement::GetStyleSheetInfo()
|
||||||
{
|
{
|
||||||
nsAutoString title;
|
if (!IsCSSMimeTypeAttribute(*this)) {
|
||||||
GetAttr(kNameSpaceID_None, nsGkAtoms::title, title);
|
|
||||||
title.CompressWhitespace();
|
|
||||||
|
|
||||||
nsAutoString media;
|
|
||||||
GetAttr(kNameSpaceID_None, nsGkAtoms::media, media);
|
|
||||||
// The SVG spec is formulated in terms of the CSS2 spec,
|
|
||||||
// which specifies that media queries are case insensitive.
|
|
||||||
nsContentUtils::ASCIIToLower(media);
|
|
||||||
|
|
||||||
// FIXME(emilio): Why doesn't this do the same as HTMLStyleElement?
|
|
||||||
nsAutoString type;
|
|
||||||
GetAttr(kNameSpaceID_None, nsGkAtoms::type, type);
|
|
||||||
if (!type.IsEmpty() && !type.LowerCaseEqualsLiteral("text/css")) {
|
|
||||||
return Nothing();
|
return Nothing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsAutoString title;
|
||||||
|
nsAutoString media;
|
||||||
|
GetTitleAndMediaForElement(*this, title, media);
|
||||||
|
|
||||||
return Some(SheetInfo {
|
return Some(SheetInfo {
|
||||||
*OwnerDoc(),
|
*OwnerDoc(),
|
||||||
this,
|
this,
|
||||||
nullptr,
|
nullptr,
|
||||||
|
// FIXME(bug 1459822): Why doesn't this need a principal, but
|
||||||
|
// HTMLStyleElement does?
|
||||||
nullptr,
|
nullptr,
|
||||||
net::ReferrerPolicy::RP_Unset,
|
net::ReferrerPolicy::RP_Unset,
|
||||||
|
// FIXME(bug 1459822): Why does this need a crossorigin attribute, but
|
||||||
|
// HTMLStyleElement doesn't?
|
||||||
AttrValueToCORSMode(GetParsedAttr(nsGkAtoms::crossorigin)),
|
AttrValueToCORSMode(GetParsedAttr(nsGkAtoms::crossorigin)),
|
||||||
title,
|
title,
|
||||||
media,
|
media,
|
||||||
|
|
Загрузка…
Ссылка в новой задаче