summaryrefslogtreecommitdiff
path: root/Libraries/LibWeb
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-09-24 10:33:33 +0200
committerAndreas Kling <kling@serenityos.org>2020-09-24 10:33:33 +0200
commit96fc476107826fa150237f070b5b1012f186cb09 (patch)
treec19be8c349b9e25d7385c132713974d00cdeac81 /Libraries/LibWeb
parent1cb8be9906f41bc0b3533ba04c3abdb44b97e5f3 (diff)
downloadserenity-96fc476107826fa150237f070b5b1012f186cb09.zip
LibWeb: Add a separate UA style sheet for documents in quirks mode
We need to make some additional tweaks to the default UA style when displaying documents in quirks mode.
Diffstat (limited to 'Libraries/LibWeb')
-rw-r--r--Libraries/LibWeb/CMakeLists.txt9
-rw-r--r--Libraries/LibWeb/CSS/Default.css5
-rw-r--r--Libraries/LibWeb/CSS/QuirksMode.css3
-rw-r--r--Libraries/LibWeb/CSS/StyleResolver.cpp13
4 files changed, 25 insertions, 5 deletions
diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt
index 549ea0baa8..2e1b395e31 100644
--- a/Libraries/LibWeb/CMakeLists.txt
+++ b/Libraries/LibWeb/CMakeLists.txt
@@ -16,6 +16,7 @@ set(SOURCES
CSS/Parser/CSSParser.cpp
CSS/PropertyID.cpp
CSS/PropertyID.h
+ CSS/QuirksModeStyleSheetSource.cpp
CSS/Selector.cpp
CSS/SelectorEngine.cpp
CSS/StyleDeclaration.cpp
@@ -329,5 +330,13 @@ add_custom_command(
MAIN_DEPENDENCY CSS/Default.css
)
+add_custom_command(
+ OUTPUT CSS/QuirksModeStyleSheetSource.cpp
+ COMMAND ${write_if_different} CSS/QuirksModeStyleSheetSource.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Scripts/GenerateStyleSheetSource.sh quirks_mode_stylesheet_source ${CMAKE_CURRENT_SOURCE_DIR}/CSS/QuirksMode.css
+ VERBATIM
+ DEPENDS Scripts/GenerateStyleSheetSource.sh
+ MAIN_DEPENDENCY CSS/Default.css
+)
+
serenity_lib(LibWeb web)
target_link_libraries(LibWeb LibCore LibJS LibMarkdown LibGemini LibGUI LibGfx LibTextCodec LibProtocol LibImageDecoderClient)
diff --git a/Libraries/LibWeb/CSS/Default.css b/Libraries/LibWeb/CSS/Default.css
index 285ba23ca7..c5792fc76d 100644
--- a/Libraries/LibWeb/CSS/Default.css
+++ b/Libraries/LibWeb/CSS/Default.css
@@ -147,8 +147,3 @@ blockquote {
margin-left: 25px;
margin-right: 25px;
}
-
-/* FIXME: I think this should only apply in quirks mode. */
-table {
- text-align: left;
-}
diff --git a/Libraries/LibWeb/CSS/QuirksMode.css b/Libraries/LibWeb/CSS/QuirksMode.css
new file mode 100644
index 0000000000..8e1aeb392b
--- /dev/null
+++ b/Libraries/LibWeb/CSS/QuirksMode.css
@@ -0,0 +1,3 @@
+table {
+ text-align: left;
+}
diff --git a/Libraries/LibWeb/CSS/StyleResolver.cpp b/Libraries/LibWeb/CSS/StyleResolver.cpp
index 9ba4519fb5..4d26c66828 100644
--- a/Libraries/LibWeb/CSS/StyleResolver.cpp
+++ b/Libraries/LibWeb/CSS/StyleResolver.cpp
@@ -57,10 +57,23 @@ static StyleSheet& default_stylesheet()
return *sheet;
}
+static StyleSheet& quirks_mode_stylesheet()
+{
+ static StyleSheet* sheet;
+ if (!sheet) {
+ extern const char quirks_mode_stylesheet_source[];
+ String css = quirks_mode_stylesheet_source;
+ sheet = parse_css(CSS::ParsingContext(), css).leak_ref();
+ }
+ return *sheet;
+}
+
template<typename Callback>
void StyleResolver::for_each_stylesheet(Callback callback) const
{
callback(default_stylesheet());
+ if (document().in_quirks_mode())
+ callback(quirks_mode_stylesheet());
for (auto& sheet : document().style_sheets().sheets()) {
callback(sheet);
}