Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Alternate stylesheets are not present in document.styleSheets
https://bugs.webkit.org/show_bug.cgi?id=56932

Reviewed by Cameron McCormack.

Align the behavior of WebKit with the spec and that of other browsers by always enumerating list of
stylesheets regardless of whether if title is specified or it is an alternate stylesheet.

Also fixed the bug that StyleSheet.title returns an empty string instead of null.

* LayoutTests/imported/w3c/web-platform-tests/css/cssom/stylesheet-title-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/ttwf-cssom-doc-ext-load-tree-order-expected.txt:
* LayoutTests/platform/glib/tables/mozilla_expected_failures/bugs/bug92868_1-expected.txt:
* LayoutTests/platform/ios/tables/mozilla_expected_failures/bugs/bug92868_1-expected.txt:
* LayoutTests/platform/mac/tables/mozilla_expected_failures/bugs/bug92868_1-expected.txt:
* LayoutTests/platform/win/tables/mozilla_expected_failures/bugs/bug92868_1-expected.txt:
* LayoutTests/platform/wincairo/tables/mozilla_expected_failures/bugs/bug92868_1-expected.txt:

* Source/WebCore/css/CSSStyleSheet.h:
(WebCore::XSLStyleSheet::title): Return null if m_title is an empty string.
* Source/WebCore/style/StyleScope.cpp:
(WebCore::Style::Scope::collectActiveStyleSheets): This function now returns two vector's containing
the list of active stylesheets as well as ones for Document/ShadowRoot's styleSheets attribute.
(WebCore::Style::Scope::updateActiveStyleSheets):
* Source/WebCore/style/StyleScope.h:
(WebCore::Style::Scope::ActiveStyleSheetCollection):
* Source/WebCore/xml/XSLStyleSheet.h:
(WebCore::XSLStyleSheet::title): Return null.

Canonical link: https://commits.webkit.org/252781@main
  • Loading branch information
rniwa committed Jul 25, 2022
1 parent a70c7ba commit a39b520
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 16 deletions.
Expand Up @@ -2,5 +2,5 @@ Should be green


PASS Preferred style sheet name
FAIL StyleSheet.title assert_equals: expected 4 but got 3
PASS StyleSheet.title

@@ -1,3 +1,3 @@

FAIL styleSheets.length must be 5 assert_equals: styleSheets.length is incorrect: expected 5 but got 1
PASS styleSheets.length must be 5

@@ -1,4 +1,3 @@
CONSOLE MESSAGE: TypeError: undefined is not an object (evaluating 'document.styleSheets[1].disabled = false')
layer at (0,0) size 800x600
RenderView at (0,0) size 800x600
layer at (0,0) size 800x76
Expand Down
@@ -1,4 +1,3 @@
CONSOLE MESSAGE: TypeError: undefined is not an object (evaluating 'document.styleSheets[1].disabled = false')
layer at (0,0) size 800x600
RenderView at (0,0) size 800x600
layer at (0,0) size 800x82
Expand Down
@@ -1,4 +1,3 @@
CONSOLE MESSAGE: TypeError: undefined is not an object (evaluating 'document.styleSheets[1].disabled = false')
layer at (0,0) size 800x600
RenderView at (0,0) size 800x600
layer at (0,0) size 800x76
Expand Down
@@ -1,4 +1,3 @@
CONSOLE MESSAGE: TypeError: undefined is not an object (evaluating 'document.styleSheets[1].disabled = false')
layer at (0,0) size 800x600
RenderView at (0,0) size 800x600
layer at (0,0) size 800x76
Expand Down
@@ -1,4 +1,3 @@
CONSOLE MESSAGE: TypeError: undefined is not an object (evaluating 'document.styleSheets[1].disabled = false')
layer at (0,0) size 800x600
RenderView at (0,0) size 800x600
layer at (0,0) size 800x82
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/css/CSSStyleSheet.h
Expand Up @@ -60,7 +60,7 @@ class CSSStyleSheet final : public StyleSheet {
Node* ownerNode() const final { return m_ownerNode; }
MediaList* media() const final;
String href() const final;
String title() const final { return m_title; }
String title() const final { return !m_title.isEmpty() ? m_title : String(); }
bool disabled() const final { return m_isDisabled; }
void setDisabled(bool) final;

Expand Down
20 changes: 14 additions & 6 deletions Source/WebCore/style/StyleScope.cpp
Expand Up @@ -338,20 +338,25 @@ Vector<Ref<ProcessingInstruction>> Scope::collectXSLTransforms()
}
#endif

void Scope::collectActiveStyleSheets(Vector<RefPtr<StyleSheet>>& sheets)
auto Scope::collectActiveStyleSheets() -> ActiveStyleSheetCollection
{
if (!m_document.settings().authorAndUserStylesEnabled())
return;
return { };

LOG_WITH_STREAM(StyleSheets, stream << "Scope " << this << " collectActiveStyleSheets()");

Vector<RefPtr<StyleSheet>> sheets;
Vector<RefPtr<StyleSheet>> styleSheetsForStyleSheetsList;

for (auto& node : m_styleSheetCandidateNodes) {
RefPtr<StyleSheet> sheet;
if (is<ProcessingInstruction>(*node)) {
if (!downcast<ProcessingInstruction>(*node).isCSS())
continue;
// We don't support linking to embedded CSS stylesheets, see <https://bugs.webkit.org/show_bug.cgi?id=49281> for discussion.
sheet = downcast<ProcessingInstruction>(*node).sheet();
if (sheet)
styleSheetsForStyleSheetsList.append(sheet);
LOG_WITH_STREAM(StyleSheets, stream << " adding sheet " << sheet << " from ProcessingInstruction node " << *node);
} else if (is<HTMLLinkElement>(*node) || is<HTMLStyleElement>(*node) || is<SVGStyleElement>(*node)) {
Element& element = downcast<Element>(*node);
Expand Down Expand Up @@ -383,6 +388,9 @@ void Scope::collectActiveStyleSheets(Vector<RefPtr<StyleSheet>>& sheets)
else
sheet = downcast<HTMLStyleElement>(element).sheet();

if (sheet)
styleSheetsForStyleSheetsList.append(sheet);

// Check to see if this sheet belongs to a styleset
// (thus making it PREFERRED or ALTERNATE rather than
// PERSISTENT).
Expand Down Expand Up @@ -410,6 +418,7 @@ void Scope::collectActiveStyleSheets(Vector<RefPtr<StyleSheet>>& sheets)
if (sheet)
sheets.append(WTFMove(sheet));
}
return { WTFMove(sheets), WTFMove(styleSheetsForStyleSheetsList) };
}

Scope::StyleSheetChange Scope::analyzeStyleSheetChange(const Vector<RefPtr<CSSStyleSheet>>& newStylesheets)
Expand Down Expand Up @@ -485,8 +494,7 @@ void Scope::updateActiveStyleSheets(UpdateType updateType)
return;
}

Vector<RefPtr<StyleSheet>> activeStyleSheets;
collectActiveStyleSheets(activeStyleSheets);
auto collection = collectActiveStyleSheets();

Vector<RefPtr<CSSStyleSheet>> activeCSSStyleSheets;

Expand All @@ -495,7 +503,7 @@ void Scope::updateActiveStyleSheets(UpdateType updateType)
activeCSSStyleSheets.appendVector(m_document.extensionStyleSheets().authorStyleSheetsForTesting());
}

filterEnabledNonemptyCSSStyleSheets(activeCSSStyleSheets, activeStyleSheets);
filterEnabledNonemptyCSSStyleSheets(activeCSSStyleSheets, collection.activeStyleSheets);

LOG_WITH_STREAM(StyleSheets, stream << "Scope::updateActiveStyleSheets for document " << m_document << " sheets " << activeCSSStyleSheets);

Expand All @@ -507,7 +515,7 @@ void Scope::updateActiveStyleSheets(UpdateType updateType)

m_weakCopyOfActiveStyleSheetListForFastLookup.clear();
m_activeStyleSheets.swap(activeCSSStyleSheets);
m_styleSheetsForStyleSheetList.swap(activeStyleSheets);
m_styleSheetsForStyleSheetList.swap(collection.styleSheetsForStyleSheetList);

InspectorInstrumentation::activeStyleSheetsUpdated(m_document);

Expand Down
7 changes: 6 additions & 1 deletion Source/WebCore/style/StyleScope.h
Expand Up @@ -154,7 +154,12 @@ class Scope : public CanMakeWeakPtr<Scope> {
WEBCORE_EXPORT void flushPendingSelfUpdate();
WEBCORE_EXPORT void flushPendingDescendantUpdates();

void collectActiveStyleSheets(Vector<RefPtr<StyleSheet>>&);
struct ActiveStyleSheetCollection {
Vector<RefPtr<StyleSheet>> activeStyleSheets;
Vector<RefPtr<StyleSheet>> styleSheetsForStyleSheetList;
};

ActiveStyleSheetCollection collectActiveStyleSheets();

enum class ResolverUpdateType {
Reconstruct,
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/xml/XSLStyleSheet.h
Expand Up @@ -89,7 +89,7 @@ class XSLStyleSheet final : public StyleSheet {
void setDisabled(bool b) override { m_isDisabled = b; }
Node* ownerNode() const override { return m_ownerNode; }
String href() const override { return m_originalURL; }
String title() const override { return emptyString(); }
String title() const override { return { }; }

void clearOwnerNode() override { m_ownerNode = nullptr; }
URL baseURL() const override { return m_finalURL; }
Expand Down

0 comments on commit a39b520

Please sign in to comment.