RenderTheme does not need to be per-page
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 May 2017 05:35:04 +0000 (05:35 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 May 2017 05:35:04 +0000 (05:35 +0000)
https://bugs.webkit.org/show_bug.cgi?id=172116
<rdar://problem/30426457>

Reviewed by Zalan Bujtas.

There are no implementations of RenderTheme::themeForPage that actually care about the page.
It can be replaced with a singleton, simplifying a bunch of code.

* Modules/mediacontrols/MediaControlsHost.cpp:
(WebCore::MediaControlsHost::shadowRootCSSText):
(WebCore::MediaControlsHost::base64StringForIconNameAndType):
* css/CSSDefaultStyleSheets.cpp:
(WebCore::CSSDefaultStyleSheets::loadFullDefaultStyle):
(WebCore::CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement):

    Fix a potential crash if we get here when page is null (though it doesn't appear to repro on trunk).

* css/StyleColor.cpp:
(WebCore::StyleColor::colorFromKeyword):
* css/StyleResolver.cpp:
(WebCore::StyleResolver::adjustRenderStyle):
* css/parser/CSSParser.cpp:
(WebCore::CSSParser::parseSystemColor):
* css/parser/CSSParser.h:
* css/parser/CSSPropertyParser.cpp:
(WebCore::CSSPropertyParser::consumeSystemFont):
* editing/FrameSelection.cpp:
(WebCore::FrameSelection::updateAppearance):
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::ensureMediaControlsInjectedScript):
* html/HTMLMeterElement.cpp:
(WebCore::HTMLMeterElement::createElementRenderer):
* html/HTMLSelectElement.cpp:
(WebCore::HTMLSelectElement::usesMenuList):
(WebCore::HTMLSelectElement::platformHandleKeydownEvent):
(WebCore::HTMLSelectElement::menuListDefaultEventHandler):
* html/HTMLTextFormControlElement.cpp:
(WebCore::HTMLTextFormControlElement::adjustInnerTextStyle):
* html/InputType.cpp:
(WebCore::InputType::themeSupportsDataListUI):
* html/TextFieldInputType.cpp:
(WebCore::TextFieldInputType::shouldHaveSpinButton):
(WebCore::TextFieldInputType::shouldHaveCapsLockIndicator):
* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::setStrokeColor):
(WebCore::CanvasRenderingContext2D::setFillColor):
* html/canvas/CanvasStyle.cpp:
(WebCore::parseColor):
(WebCore::parseColorOrCurrentColor):
(WebCore::CanvasStyle::createFromString):
* html/canvas/CanvasStyle.h:
* html/shadow/MediaControlElements.cpp:
(WebCore::MediaControlPanelElement::startTimer):
(WebCore::MediaControlPanelElement::makeOpaque):
(WebCore::MediaControlPanelElement::makeTransparent):
* html/shadow/MediaControls.cpp:
(WebCore::MediaControls::reset):
(WebCore::MediaControls::reportedError):
(WebCore::MediaControls::updateCurrentTimeDisplay):
* html/shadow/mac/ImageControlsButtonElementMac.cpp:
(WebCore::ImageControlsButtonElementMac::tryCreate):
* page/MemoryRelease.cpp:
(WebCore::releaseNoncriticalMemory):
* page/Page.cpp:
(WebCore::Page::Page):
* page/Page.h:
(WebCore::Page::theme): Deleted.
* platform/wpe/RenderThemeWPE.cpp:
(WebCore::RenderTheme::singleton):
(WebCore::RenderTheme::themeForPage): Deleted.
* rendering/RenderEmbeddedObject.cpp:
(WebCore::RenderEmbeddedObject::getReplacementTextGeometry):
* rendering/RenderObject.cpp:
(WebCore::RenderObject::theme):
* rendering/RenderTheme.cpp:
(WebCore::RenderTheme::focusRingColor):
* rendering/RenderTheme.h:
(WebCore::RenderTheme::defaultTheme): Deleted.
* rendering/RenderThemeGtk.cpp:
(WebCore::RenderTheme::singleton):
(WebCore::RenderTheme::themeForPage): Deleted.
* rendering/RenderThemeIOS.mm:
(WebCore::RenderTheme::singleton):
(WebCore::RenderTheme::themeForPage): Deleted.
* rendering/RenderThemeMac.mm:
(WebCore::RenderTheme::singleton):
(WebCore::RenderTheme::themeForPage): Deleted.
* rendering/RenderThemeWin.cpp:
(WebCore::RenderTheme::singleton):
(WebCore::RenderTheme::themeForPage): Deleted.
* rendering/TextPaintStyle.cpp:
(WebCore::computeTextPaintStyle):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@216902 268f45cc-cd09-0410-ab3c-d52691b4dbfc

37 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediacontrols/MediaControlsHost.cpp
Source/WebCore/css/CSSDefaultStyleSheets.cpp
Source/WebCore/css/StyleColor.cpp
Source/WebCore/css/StyleResolver.cpp
Source/WebCore/css/parser/CSSParser.cpp
Source/WebCore/css/parser/CSSParser.h
Source/WebCore/css/parser/CSSPropertyParser.cpp
Source/WebCore/editing/FrameSelection.cpp
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMeterElement.cpp
Source/WebCore/html/HTMLSelectElement.cpp
Source/WebCore/html/HTMLTextFormControlElement.cpp
Source/WebCore/html/InputType.cpp
Source/WebCore/html/TextFieldInputType.cpp
Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
Source/WebCore/html/canvas/CanvasStyle.cpp
Source/WebCore/html/canvas/CanvasStyle.h
Source/WebCore/html/shadow/MediaControlElements.cpp
Source/WebCore/html/shadow/MediaControls.cpp
Source/WebCore/html/shadow/mac/ImageControlsButtonElementMac.cpp
Source/WebCore/page/MemoryRelease.cpp
Source/WebCore/page/Page.cpp
Source/WebCore/page/Page.h
Source/WebCore/page/linux/ResourceUsageOverlayLinux.cpp
Source/WebCore/platform/win/PopupMenuWin.cpp
Source/WebCore/platform/wpe/RenderThemeWPE.cpp
Source/WebCore/rendering/RenderEmbeddedObject.cpp
Source/WebCore/rendering/RenderObject.cpp
Source/WebCore/rendering/RenderTheme.cpp
Source/WebCore/rendering/RenderTheme.h
Source/WebCore/rendering/RenderThemeGtk.cpp
Source/WebCore/rendering/RenderThemeIOS.mm
Source/WebCore/rendering/RenderThemeMac.mm
Source/WebCore/rendering/RenderThemeWin.cpp
Source/WebCore/rendering/TextPaintStyle.cpp
Source/WebKit/win/WebView.cpp

index 1182ea2..84d1e4c 100644 (file)
@@ -1,3 +1,99 @@
+2017-05-15  Antti Koivisto  <antti@apple.com>
+
+        RenderTheme does not need to be per-page
+        https://bugs.webkit.org/show_bug.cgi?id=172116
+        <rdar://problem/30426457>
+
+        Reviewed by Zalan Bujtas.
+
+        There are no implementations of RenderTheme::themeForPage that actually care about the page.
+        It can be replaced with a singleton, simplifying a bunch of code.
+
+        * Modules/mediacontrols/MediaControlsHost.cpp:
+        (WebCore::MediaControlsHost::shadowRootCSSText):
+        (WebCore::MediaControlsHost::base64StringForIconNameAndType):
+        * css/CSSDefaultStyleSheets.cpp:
+        (WebCore::CSSDefaultStyleSheets::loadFullDefaultStyle):
+        (WebCore::CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement):
+
+            Fix a potential crash if we get here when page is null (though it doesn't appear to repro on trunk).
+
+        * css/StyleColor.cpp:
+        (WebCore::StyleColor::colorFromKeyword):
+        * css/StyleResolver.cpp:
+        (WebCore::StyleResolver::adjustRenderStyle):
+        * css/parser/CSSParser.cpp:
+        (WebCore::CSSParser::parseSystemColor):
+        * css/parser/CSSParser.h:
+        * css/parser/CSSPropertyParser.cpp:
+        (WebCore::CSSPropertyParser::consumeSystemFont):
+        * editing/FrameSelection.cpp:
+        (WebCore::FrameSelection::updateAppearance):
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::ensureMediaControlsInjectedScript):
+        * html/HTMLMeterElement.cpp:
+        (WebCore::HTMLMeterElement::createElementRenderer):
+        * html/HTMLSelectElement.cpp:
+        (WebCore::HTMLSelectElement::usesMenuList):
+        (WebCore::HTMLSelectElement::platformHandleKeydownEvent):
+        (WebCore::HTMLSelectElement::menuListDefaultEventHandler):
+        * html/HTMLTextFormControlElement.cpp:
+        (WebCore::HTMLTextFormControlElement::adjustInnerTextStyle):
+        * html/InputType.cpp:
+        (WebCore::InputType::themeSupportsDataListUI):
+        * html/TextFieldInputType.cpp:
+        (WebCore::TextFieldInputType::shouldHaveSpinButton):
+        (WebCore::TextFieldInputType::shouldHaveCapsLockIndicator):
+        * html/canvas/CanvasRenderingContext2D.cpp:
+        (WebCore::CanvasRenderingContext2D::setStrokeColor):
+        (WebCore::CanvasRenderingContext2D::setFillColor):
+        * html/canvas/CanvasStyle.cpp:
+        (WebCore::parseColor):
+        (WebCore::parseColorOrCurrentColor):
+        (WebCore::CanvasStyle::createFromString):
+        * html/canvas/CanvasStyle.h:
+        * html/shadow/MediaControlElements.cpp:
+        (WebCore::MediaControlPanelElement::startTimer):
+        (WebCore::MediaControlPanelElement::makeOpaque):
+        (WebCore::MediaControlPanelElement::makeTransparent):
+        * html/shadow/MediaControls.cpp:
+        (WebCore::MediaControls::reset):
+        (WebCore::MediaControls::reportedError):
+        (WebCore::MediaControls::updateCurrentTimeDisplay):
+        * html/shadow/mac/ImageControlsButtonElementMac.cpp:
+        (WebCore::ImageControlsButtonElementMac::tryCreate):
+        * page/MemoryRelease.cpp:
+        (WebCore::releaseNoncriticalMemory):
+        * page/Page.cpp:
+        (WebCore::Page::Page):
+        * page/Page.h:
+        (WebCore::Page::theme): Deleted.
+        * platform/wpe/RenderThemeWPE.cpp:
+        (WebCore::RenderTheme::singleton):
+        (WebCore::RenderTheme::themeForPage): Deleted.
+        * rendering/RenderEmbeddedObject.cpp:
+        (WebCore::RenderEmbeddedObject::getReplacementTextGeometry):
+        * rendering/RenderObject.cpp:
+        (WebCore::RenderObject::theme):
+        * rendering/RenderTheme.cpp:
+        (WebCore::RenderTheme::focusRingColor):
+        * rendering/RenderTheme.h:
+        (WebCore::RenderTheme::defaultTheme): Deleted.
+        * rendering/RenderThemeGtk.cpp:
+        (WebCore::RenderTheme::singleton):
+        (WebCore::RenderTheme::themeForPage): Deleted.
+        * rendering/RenderThemeIOS.mm:
+        (WebCore::RenderTheme::singleton):
+        (WebCore::RenderTheme::themeForPage): Deleted.
+        * rendering/RenderThemeMac.mm:
+        (WebCore::RenderTheme::singleton):
+        (WebCore::RenderTheme::themeForPage): Deleted.
+        * rendering/RenderThemeWin.cpp:
+        (WebCore::RenderTheme::singleton):
+        (WebCore::RenderTheme::themeForPage): Deleted.
+        * rendering/TextPaintStyle.cpp:
+        (WebCore::computeTextPaintStyle):
+
 2017-05-15  Said Abou-Hallawa  <sabouhallawa@apple.com>
 
         Do not delete asynchronously decoded frames for large images if their clients are in the viewport
index 9b37687..a655a7d 100644 (file)
@@ -280,18 +280,13 @@ String MediaControlsHost::generateUUID() const
 
 String MediaControlsHost::shadowRootCSSText() const
 {
-    Page* page = m_mediaElement->document().page();
-    if (!page)
-        return emptyString();
-    return RenderTheme::themeForPage(page)->modernMediaControlsStyleSheet();
+    return RenderTheme::singleton().modernMediaControlsStyleSheet();
 }
 
 String MediaControlsHost::base64StringForIconNameAndType(const String& iconName, const String& iconType) const
 {
-    Page* page = m_mediaElement->document().page();
-    if (!page)
-        return emptyString();
-    return RenderTheme::themeForPage(page)->mediaControlsBase64StringForIconNameAndType(iconName, iconType);
+
+    return RenderTheme::singleton().mediaControlsBase64StringForIconNameAndType(iconName, iconType);
 }
 
 }
index cb6ad28..c313684 100644 (file)
@@ -134,13 +134,13 @@ void CSSDefaultStyleSheets::loadFullDefaultStyle()
     }
 
     // Strict-mode rules.
-    String defaultRules = String(htmlUserAgentStyleSheet, sizeof(htmlUserAgentStyleSheet)) + RenderTheme::defaultTheme()->extraDefaultStyleSheet();
+    String defaultRules = String(htmlUserAgentStyleSheet, sizeof(htmlUserAgentStyleSheet)) + RenderTheme::singleton().extraDefaultStyleSheet();
     defaultStyleSheet = parseUASheet(defaultRules);
     defaultStyle->addRulesFromSheet(*defaultStyleSheet, screenEval());
     defaultPrintStyle->addRulesFromSheet(*defaultStyleSheet, printEval());
 
     // Quirks-mode rules.
-    String quirksRules = String(quirksUserAgentStyleSheet, sizeof(quirksUserAgentStyleSheet)) + RenderTheme::defaultTheme()->extraQuirksStyleSheet();
+    String quirksRules = String(quirksUserAgentStyleSheet, sizeof(quirksUserAgentStyleSheet)) + RenderTheme::singleton().extraQuirksStyleSheet();
     quirksStyleSheet = parseUASheet(quirksRules);
     defaultQuirksStyle->addRulesFromSheet(*quirksStyleSheet, screenEval());
 }
@@ -170,8 +170,8 @@ void CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement(const Element& el
 
     if (is<HTMLElement>(element)) {
         if (is<HTMLObjectElement>(element) || is<HTMLEmbedElement>(element)) {
-            if (!plugInsStyleSheet) {
-                String plugInsRules = RenderTheme::themeForPage(element.document().page())->extraPlugInsStyleSheet() + element.document().page()->chrome().client().plugInExtraStyleSheet();
+            if (!plugInsStyleSheet && element.document().page()) {
+                String plugInsRules = RenderTheme::singleton().extraPlugInsStyleSheet() + element.document().page()->chrome().client().plugInExtraStyleSheet();
                 if (plugInsRules.isEmpty())
                     plugInsRules = String(plugInsUserAgentStyleSheet, sizeof(plugInsUserAgentStyleSheet));
                 plugInsStyleSheet = parseUASheet(plugInsRules);
@@ -182,9 +182,9 @@ void CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement(const Element& el
 #if ENABLE(VIDEO)
         else if (is<HTMLMediaElement>(element)) {
             if (!mediaControlsStyleSheet) {
-                String mediaRules = RenderTheme::themeForPage(element.document().page())->mediaControlsStyleSheet();
+                String mediaRules = RenderTheme::singleton().mediaControlsStyleSheet();
                 if (mediaRules.isEmpty())
-                    mediaRules = String(mediaControlsUserAgentStyleSheet, sizeof(mediaControlsUserAgentStyleSheet)) + RenderTheme::themeForPage(element.document().page())->extraMediaControlsStyleSheet();
+                    mediaRules = String(mediaControlsUserAgentStyleSheet, sizeof(mediaControlsUserAgentStyleSheet)) + RenderTheme::singleton().extraMediaControlsStyleSheet();
                 mediaControlsStyleSheet = parseUASheet(mediaRules);
                 defaultStyle->addRulesFromSheet(*mediaControlsStyleSheet, screenEval());
                 defaultPrintStyle->addRulesFromSheet(*mediaControlsStyleSheet, printEval());
@@ -195,7 +195,7 @@ void CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement(const Element& el
 #if ENABLE(SERVICE_CONTROLS)
         else if (is<HTMLDivElement>(element) && element.isImageControlsRootElement()) {
             if (!imageControlsStyleSheet) {
-                String imageControlsRules = RenderTheme::themeForPage(element.document().page())->imageControlsStyleSheet();
+                String imageControlsRules = RenderTheme::singleton().imageControlsStyleSheet();
                 imageControlsStyleSheet = parseUASheet(imageControlsRules);
                 defaultStyle->addRulesFromSheet(*imageControlsStyleSheet, screenEval());
                 defaultPrintStyle->addRulesFromSheet(*imageControlsStyleSheet, printEval());
@@ -226,7 +226,7 @@ void CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement(const Element& el
 
 #if ENABLE(FULLSCREEN_API)
     if (!fullscreenStyleSheet && element.document().webkitIsFullScreen()) {
-        String fullscreenRules = String(fullscreenUserAgentStyleSheet, sizeof(fullscreenUserAgentStyleSheet)) + RenderTheme::defaultTheme()->extraFullScreenStyleSheet();
+        String fullscreenRules = String(fullscreenUserAgentStyleSheet, sizeof(fullscreenUserAgentStyleSheet)) + RenderTheme::singleton().extraFullScreenStyleSheet();
         fullscreenStyleSheet = parseUASheet(fullscreenRules);
         defaultStyle->addRulesFromSheet(*fullscreenStyleSheet, screenEval());
         defaultQuirksStyle->addRulesFromSheet(*fullscreenStyleSheet, screenEval());
index 6403dbb..ba869ad 100644 (file)
@@ -43,7 +43,7 @@ Color StyleColor::colorFromKeyword(CSSValueID keyword)
         if (const NamedColor* namedColor = findColor(valueName, strlen(valueName)))
             return Color(namedColor->ARGBValue);
     }
-    return RenderTheme::defaultTheme()->systemColor(keyword);
+    return RenderTheme::singleton().systemColor(keyword);
 }
 
 bool StyleColor::isColorKeyword(CSSValueID id)
index d7e8af0..ad027b4 100644 (file)
@@ -998,7 +998,7 @@ void StyleResolver::adjustRenderStyle(RenderStyle& style, const RenderStyle& par
 
     // Let the theme also have a crack at adjusting the style.
     if (style.hasAppearance())
-        RenderTheme::defaultTheme()->adjustStyle(*this, style, element, m_state.hasUAAppearance(), m_state.borderData(), m_state.backgroundData(), m_state.backgroundColor());
+        RenderTheme::singleton().adjustStyle(*this, style, element, m_state.hasUAAppearance(), m_state.borderData(), m_state.backgroundData(), m_state.backgroundColor());
 
     // If we have first-letter pseudo style, do not share this style.
     if (style.hasPseudoStyle(FIRST_LETTER))
index 1cd2072..69f9d95 100644 (file)
@@ -173,16 +173,13 @@ Color CSSParser::parseColor(const String& string, bool strict)
     return primitiveValue.color();
 }
 
-Color CSSParser::parseSystemColor(const String& string, Document* document)
+Color CSSParser::parseSystemColor(const String& string)
 {
-    if (!document || !document->page())
-        return Color();
-    
     CSSValueID id = cssValueKeywordID(string);
     if (!StyleColor::isSystemColor(id))
         return Color();
     
-    return document->page()->theme().systemColor(id);
+    return RenderTheme::singleton().systemColor(id);
 }
 
 RefPtr<CSSValue> CSSParser::parseSingleValue(CSSPropertyID propertyID, const String& string, const CSSParserContext& context)
index 0991dff..3610dbf 100644 (file)
@@ -78,7 +78,7 @@ public:
     RefPtr<CSSValue> parseValueWithVariableReferences(CSSPropertyID, const CSSValue&, const CustomPropertyValueMap& customProperties, TextDirection, WritingMode);
 
     static Color parseColor(const String&, bool strict = false);
-    static Color parseSystemColor(const String&, Document*);
+    static Color parseSystemColor(const String&);
 
 private:
     ParseResult parseValue(MutableStyleProperties&, CSSPropertyID, const String&, bool important);
index 977a3a4..3e08726 100644 (file)
@@ -4429,7 +4429,7 @@ bool CSSPropertyParser::consumeSystemFont(bool important)
         return false;
     
     FontCascadeDescription fontDescription;
-    RenderTheme::defaultTheme()->systemFont(systemFontID, fontDescription);
+    RenderTheme::singleton().systemFont(systemFontID, fontDescription);
     if (!fontDescription.isAbsoluteSize())
         return false;
     
index e91b4c2..8bb00db 100644 (file)
@@ -2057,7 +2057,7 @@ void FrameSelection::updateAppearance()
     // Start blinking with a black caret. Be sure not to restart if we're
     // already blinking in the right location.
     if (shouldBlink && !m_caretBlinkTimer.isActive()) {
-        if (Seconds blinkInterval = m_frame->page()->theme().caretBlinkInterval())
+        if (Seconds blinkInterval = RenderTheme::singleton().caretBlinkInterval())
             m_caretBlinkTimer.startRepeating(blinkInterval);
 
         if (!m_caretPaint) {
index 1d863c5..15fa7a4 100644 (file)
@@ -6698,7 +6698,7 @@ bool HTMLMediaElement::ensureMediaControlsInjectedScript()
     if (!page)
         return false;
 
-    String mediaControlsScript = RenderTheme::themeForPage(page)->mediaControlsScript();
+    String mediaControlsScript = RenderTheme::singleton().mediaControlsScript();
     if (!mediaControlsScript.length())
         return false;
 
index 52c88e7..0239b33 100644 (file)
@@ -60,7 +60,7 @@ Ref<HTMLMeterElement> HTMLMeterElement::create(const QualifiedName& tagName, Doc
 
 RenderPtr<RenderElement> HTMLMeterElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&)
 {
-    if (!document().page()->theme().supportsMeter(style.appearance()))
+    if (!RenderTheme::singleton().supportsMeter(style.appearance()))
         return RenderElement::createFor(*this, WTFMove(style));
 
     return createRenderer<RenderMeter>(*this, WTFMove(style));
index f19756b..f4c6143 100644 (file)
@@ -193,7 +193,7 @@ void HTMLSelectElement::listBoxSelectItem(int listIndex, bool allowMultiplySelec
 bool HTMLSelectElement::usesMenuList() const
 {
 #if !PLATFORM(IOS)
-    if (RenderTheme::themeForPage(document().page())->delegatesMenuListRendering())
+    if (RenderTheme::singleton().delegatesMenuListRendering())
         return true;
 
     return !m_multiple && m_size <= 1;
@@ -1085,7 +1085,7 @@ void HTMLSelectElement::reset()
 
 bool HTMLSelectElement::platformHandleKeydownEvent(KeyboardEvent* event)
 {
-    if (!RenderTheme::themeForPage(document().page())->popsMenuByArrowKeys())
+    if (!RenderTheme::singleton().popsMenuByArrowKeys())
         return false;
 
     if (!isSpatialNavigationEnabled(document().frame())) {
@@ -1119,8 +1119,6 @@ void HTMLSelectElement::menuListDefaultEventHandler(Event& event)
     ASSERT(renderer());
     ASSERT(renderer()->isMenuList());
 
-    RefPtr<RenderTheme> renderTheme = RenderTheme::themeForPage(document().page());
-
     if (event.type() == eventNames().keydownEvent) {
         if (!is<KeyboardEvent>(event))
             return;
@@ -1188,7 +1186,7 @@ void HTMLSelectElement::menuListDefaultEventHandler(Event& event)
             return;
         }
 
-        if (renderTheme->popsMenuBySpaceOrReturn()) {
+        if (RenderTheme::singleton().popsMenuBySpaceOrReturn()) {
             if (keyCode == ' ' || keyCode == '\r') {
                 focus();
 
@@ -1205,7 +1203,7 @@ void HTMLSelectElement::menuListDefaultEventHandler(Event& event)
                 downcast<RenderMenuList>(*renderer).showPopup();
                 handled = true;
             }
-        } else if (renderTheme->popsMenuByArrowKeys()) {
+        } else if (RenderTheme::singleton().popsMenuByArrowKeys()) {
             if (keyCode == ' ') {
                 focus();
 
index 6e8bec4..d04c390 100644 (file)
@@ -805,7 +805,7 @@ void HTMLTextFormControlElement::adjustInnerTextStyle(const RenderStyle& parentS
     }
 
     if (isDisabledFormControl())
-        textBlockStyle.setColor(document().page()->theme().disabledTextColor(textBlockStyle.visitedDependentColor(CSSPropertyColor), parentStyle.visitedDependentColor(CSSPropertyBackgroundColor)));
+        textBlockStyle.setColor(RenderTheme::singleton().disabledTextColor(textBlockStyle.visitedDependentColor(CSSPropertyColor), parentStyle.visitedDependentColor(CSSPropertyBackgroundColor)));
 #if PLATFORM(IOS)
     if (textBlockStyle.textSecurity() != TSNONE && !textBlockStyle.isLeftToRightDirection()) {
         // Preserve the alignment but force the direction to LTR so that the last-typed, unmasked character
index bcd9638..ee47a57 100644 (file)
@@ -171,8 +171,7 @@ InputType::~InputType()
 
 bool InputType::themeSupportsDataListUI(InputType* type)
 {
-    Document& document = type->element().document();
-    return RenderTheme::themeForPage(document.page())->supportsDataListUI(type->formControlType());
+    return RenderTheme::singleton().supportsDataListUI(type->formControlType());
 }
 
 bool InputType::isTextField() const
index f35fb4c..87b38b9 100644 (file)
@@ -244,12 +244,12 @@ bool TextFieldInputType::needsContainer() const
 
 bool TextFieldInputType::shouldHaveSpinButton() const
 {
-    return RenderTheme::themeForPage(element().document().page())->shouldHaveSpinButton(element());
+    return RenderTheme::singleton().shouldHaveSpinButton(element());
 }
 
 bool TextFieldInputType::shouldHaveCapsLockIndicator() const
 {
-    return RenderTheme::themeForPage(element().document().page())->shouldHaveCapsLockIndicator(element());
+    return RenderTheme::singleton().shouldHaveCapsLockIndicator(element());
 }
 
 void TextFieldInputType::createShadowSubtree()
index 1314e48..4bc4a41 100644 (file)
@@ -839,7 +839,7 @@ void CanvasRenderingContext2D::setStrokeColor(const String& color, std::optional
         return;
 
     realizeSaves();
-    setStrokeStyle(CanvasStyle::createFromString(color, &canvas().document()));
+    setStrokeStyle(CanvasStyle::createFromString(color));
     modifiableState().unparsedStrokeColor = color;
 }
 
@@ -875,7 +875,7 @@ void CanvasRenderingContext2D::setFillColor(const String& color, std::optional<f
         return;
 
     realizeSaves();
-    setFillStyle(CanvasStyle::createFromString(color, &canvas().document()));
+    setFillStyle(CanvasStyle::createFromString(color));
     modifiableState().unparsedFillColor = color;
 }
 
index 052fa31..791568c 100644 (file)
@@ -48,12 +48,12 @@ static bool isCurrentColorString(const String& colorString)
     return equalLettersIgnoringASCIICase(colorString, "currentcolor");
 }
 
-static Color parseColor(const String& colorString, Document* document = nullptr)
+static Color parseColor(const String& colorString)
 {
     Color color = CSSParser::parseColor(colorString);
     if (color.isValid())
         return color;
-    return CSSParser::parseSystemColor(colorString, document);
+    return CSSParser::parseSystemColor(colorString);
 }
 
 Color currentColor(HTMLCanvasElement* canvas)
@@ -71,7 +71,7 @@ Color parseColorOrCurrentColor(const String& colorString, HTMLCanvasElement* can
     if (isCurrentColorString(colorString))
         return currentColor(canvas);
 
-    return parseColor(colorString, canvas ? &canvas->document() : nullptr);
+    return parseColor(colorString);
 }
 
 CanvasStyle::CanvasStyle(Color color)
@@ -109,12 +109,12 @@ inline CanvasStyle::CanvasStyle(CurrentColor color)
 {
 }
 
-CanvasStyle CanvasStyle::createFromString(const String& colorString, Document* document)
+CanvasStyle CanvasStyle::createFromString(const String& colorString)
 {
     if (isCurrentColorString(colorString))
         return CurrentColor { std::nullopt };
 
-    Color color = parseColor(colorString, document);
+    Color color = parseColor(colorString);
     if (!color.isValid())
         return { };
 
index d78030a..09ba2ff 100644 (file)
@@ -47,7 +47,7 @@ public:
     CanvasStyle(CanvasGradient&);
     CanvasStyle(CanvasPattern&);
 
-    static CanvasStyle createFromString(const String& color, Document* = nullptr);
+    static CanvasStyle createFromString(const String& color);
     static CanvasStyle createFromStringWithOverrideAlpha(const String& color, float alpha);
 
     bool isValid() const { return !WTF::holds_alternative<Invalid>(m_style); }
index 5f3b3c3..3a1e58f 100644 (file)
@@ -137,7 +137,7 @@ void MediaControlPanelElement::startTimer()
     // The timer is required to set the property display:'none' on the panel,
     // such that captions are correctly displayed at the bottom of the video
     // at the end of the fadeout transition.
-    Seconds duration = document().page() ? document().page()->theme().mediaControlsFadeOutDuration() : 0_s;
+    Seconds duration = RenderTheme::singleton().mediaControlsFadeOutDuration();
     m_transitionTimer.startOneShot(duration);
 }
 
@@ -188,7 +188,7 @@ void MediaControlPanelElement::makeOpaque()
     if (m_opaque)
         return;
 
-    double duration = document().page() ? document().page()->theme().mediaControlsFadeInDuration() : 0;
+    double duration = RenderTheme::singleton().mediaControlsFadeInDuration();
 
     setInlineStyleProperty(CSSPropertyTransitionProperty, CSSPropertyOpacity);
     setInlineStyleProperty(CSSPropertyTransitionDuration, duration, CSSPrimitiveValue::CSS_S);
@@ -205,7 +205,7 @@ void MediaControlPanelElement::makeTransparent()
     if (!m_opaque)
         return;
 
-    Seconds duration = document().page() ? document().page()->theme().mediaControlsFadeOutDuration() : 0_s;
+    Seconds duration = RenderTheme::singleton().mediaControlsFadeOutDuration();
 
     setInlineStyleProperty(CSSPropertyTransitionProperty, CSSPropertyOpacity);
     setInlineStyleProperty(CSSPropertyTransitionDuration, duration.value(), CSSPrimitiveValue::CSS_S);
index 2228f49..3e18a10 100644 (file)
@@ -87,21 +87,17 @@ void MediaControls::setMediaController(MediaControllerInterface* controller)
 
 void MediaControls::reset()
 {
-    Page* page = document().page();
-    if (!page)
-        return;
-
     m_playButton->updateDisplayType();
 
     updateCurrentTimeDisplay();
 
     double duration = m_mediaController->duration();
-    if (std::isfinite(duration) || page->theme().hasOwnDisabledStateHandlingFor(MediaSliderPart)) {
+    if (std::isfinite(duration) || RenderTheme::singleton().hasOwnDisabledStateHandlingFor(MediaSliderPart)) {
         m_timeline->setDuration(duration);
         m_timeline->setPosition(m_mediaController->currentTime());
     }
 
-    if (m_mediaController->hasAudio() || page->theme().hasOwnDisabledStateHandlingFor(MediaMuteButtonPart))
+    if (m_mediaController->hasAudio() || RenderTheme::singleton().hasOwnDisabledStateHandlingFor(MediaMuteButtonPart))
         m_panelMuteButton->show();
     else
         m_panelMuteButton->hide();
@@ -129,19 +125,16 @@ void MediaControls::reset()
 
 void MediaControls::reportedError()
 {
-    Page* page = document().page();
-    if (!page)
-        return;
-
-    if (!page->theme().hasOwnDisabledStateHandlingFor(MediaMuteButtonPart)) {
+    auto& theme = RenderTheme::singleton();
+    if (!theme.hasOwnDisabledStateHandlingFor(MediaMuteButtonPart)) {
         m_panelMuteButton->hide();
         m_volumeSlider->hide();
     }
 
-    if (m_toggleClosedCaptionsButton && !page->theme().hasOwnDisabledStateHandlingFor(MediaToggleClosedCaptionsButtonPart))
+    if (m_toggleClosedCaptionsButton && !theme.hasOwnDisabledStateHandlingFor(MediaToggleClosedCaptionsButtonPart))
         m_toggleClosedCaptionsButton->hide();
 
-    if (m_fullScreenButton && !page->theme().hasOwnDisabledStateHandlingFor(MediaEnterFullscreenButtonPart))
+    if (m_fullScreenButton && !theme.hasOwnDisabledStateHandlingFor(MediaEnterFullscreenButtonPart))
         m_fullScreenButton->hide();
 }
 
@@ -218,12 +211,7 @@ void MediaControls::playbackStopped()
 void MediaControls::updateCurrentTimeDisplay()
 {
     double now = m_mediaController->currentTime();
-
-    Page* page = document().page();
-    if (!page)
-        return;
-
-    m_currentTimeDisplay->setInnerText(page->theme().formatMediaControlsTime(now));
+    m_currentTimeDisplay->setInnerText(RenderTheme::singleton().formatMediaControlsTime(now));
     m_currentTimeDisplay->setCurrentValue(now);
 }
 
index ba9badf..2cd6504 100644 (file)
@@ -97,7 +97,7 @@ RefPtr<ImageControlsButtonElementMac> ImageControlsButtonElementMac::tryCreate(D
     auto button = adoptRef(*new ImageControlsButtonElementMac(document));
     button->setAttributeWithoutSynchronization(HTMLNames::classAttr, AtomicString("x-webkit-image-controls-button", AtomicString::ConstructFromLiteral));
 
-    IntSize positionOffset = document.page()->theme().imageControlsButtonPositionOffset();
+    IntSize positionOffset = RenderTheme::singleton().imageControlsButtonPositionOffset();
     button->setInlineStyleProperty(CSSPropertyTop, positionOffset.height(), CSSPrimitiveValue::CSS_PX);
 
     // FIXME: Why is right: 0px off the right edge of the parent?
index 214e9d3..373088b 100644 (file)
@@ -57,7 +57,7 @@ namespace WebCore {
 
 static void releaseNoncriticalMemory()
 {
-    RenderTheme::defaultTheme()->purgeCaches();
+    RenderTheme::singleton().purgeCaches();
 
     FontCache::singleton().purgeInactiveFontData();
 
index 90af4df..04fa066 100644 (file)
@@ -205,7 +205,6 @@ Page::Page(PageConfiguration&& pageConfiguration)
     , m_progress(std::make_unique<ProgressTracker>(*pageConfiguration.progressTrackerClient))
     , m_backForwardController(std::make_unique<BackForwardController>(*this, *WTFMove(pageConfiguration.backForwardClient)))
     , m_mainFrame(MainFrame::create(*this, pageConfiguration))
-    , m_theme(RenderTheme::themeForPage(this))
     , m_editorClient(WTFMove(pageConfiguration.editorClient))
     , m_plugInClient(pageConfiguration.plugInClient)
     , m_validationMessageClient(WTFMove(pageConfiguration.validationMessageClient))
index 1942961..7bef50c 100644 (file)
@@ -166,8 +166,6 @@ public:
 
     void setNeedsRecalcStyleInAllFrames();
 
-    RenderTheme& theme() const { return *m_theme; }
-
     WEBCORE_EXPORT ViewportArguments viewportArguments() const;
 
     static void refreshPlugins(bool reload);
@@ -666,8 +664,6 @@ private:
 
     RefPtr<PluginData> m_pluginData;
 
-    RefPtr<RenderTheme> m_theme;
-
     UniqueRef<EditorClient> m_editorClient;
     PlugInClient* m_plugInClient;
     std::unique_ptr<ValidationMessageClient> m_validationMessageClient;
index dd78ca0..07d88a2 100644 (file)
@@ -74,7 +74,7 @@ public:
         : m_overlay(overlay)
     {
         FontCascadeDescription fontDescription;
-        RenderTheme::defaultTheme()->systemFont(CSSValueMessageBox, fontDescription);
+        RenderTheme::singleton().systemFont(CSSValueMessageBox, fontDescription);
         fontDescription.setComputedSize(gFontSize);
         m_textFont = FontCascade(fontDescription, 0, 0);
         m_textFont.update(nullptr);
index 758eebf..6d079d8 100644 (file)
@@ -622,8 +622,8 @@ void PopupMenuWin::paint(const IntRect& damageRect, HDC hdc)
         Color optionBackgroundColor, optionTextColor;
         PopupMenuStyle itemStyle = client()->itemStyle(index);
         if (index == focusedIndex()) {
-            optionBackgroundColor = RenderTheme::defaultTheme()->activeListBoxSelectionBackgroundColor();
-            optionTextColor = RenderTheme::defaultTheme()->activeListBoxSelectionForegroundColor();
+            optionBackgroundColor = RenderTheme::singleton().activeListBoxSelectionBackgroundColor();
+            optionTextColor = RenderTheme::singleton().activeListBoxSelectionForegroundColor();
         } else {
             optionBackgroundColor = itemStyle.backgroundColor();
             optionTextColor = itemStyle.foregroundColor();
@@ -660,12 +660,12 @@ void PopupMenuWin::paint(const IntRect& damageRect, HDC hdc)
             int textX = 0;
             if (client()->menuStyle().textDirection() == LTR) {
                 textX = std::max<int>(0, client()->clientPaddingLeft() - client()->clientInsetLeft());
-                if (RenderTheme::defaultTheme()->popupOptionSupportsTextIndent())
+                if (RenderTheme::singleton().popupOptionSupportsTextIndent())
                     textX += minimumIntValueForLength(itemStyle.textIndent(), itemRect.width());
             } else {
                 textX = itemRect.width() - client()->menuStyle().font().width(textRun);
                 textX = std::min<int>(textX, textX - client()->clientPaddingRight() + client()->clientInsetRight());
-                if (RenderTheme::defaultTheme()->popupOptionSupportsTextIndent())
+                if (RenderTheme::singleton().popupOptionSupportsTextIndent())
                     textX -= minimumIntValueForLength(itemStyle.textIndent(), itemRect.width());
             }
             int textY = itemRect.y() + itemFont.fontMetrics().ascent() + (itemRect.height() - itemFont.fontMetrics().height()) / 2;
index b59e33b..4d293d8 100644 (file)
 
 namespace WebCore {
 
-Ref<RenderTheme> RenderTheme::themeForPage(Page*)
+RenderTheme& RenderTheme::singleton()
 {
-    static RenderTheme& theme = RenderThemeWPE::create().leakRef();
-    return theme;
+    static NeverDestroyed<Ref<RenderTheme>> theme(RenderThemeWPE::create());
+    return theme.get();
 }
 
 void RenderThemeWPE::updateCachedSystemFontDescription(CSSValueID, FontCascadeDescription&) const
index 755bc07..5bc1b34 100644 (file)
@@ -357,7 +357,7 @@ bool RenderEmbeddedObject::getReplacementTextGeometry(const LayoutPoint& accumul
     contentRect.moveBy(roundedIntPoint(accumulatedOffset));
 
     FontCascadeDescription fontDescription;
-    RenderTheme::defaultTheme()->systemFont(CSSValueWebkitSmallControl, fontDescription);
+    RenderTheme::singleton().systemFont(CSSValueWebkitSmallControl, fontDescription);
     fontDescription.setWeight(boldWeightValue());
     fontDescription.setRenderingMode(settings().fontRenderingMode());
     fontDescription.setComputedSize(12);
index 1169d92..269ac97 100644 (file)
@@ -141,7 +141,7 @@ RenderObject::~RenderObject()
 
 RenderTheme& RenderObject::theme() const
 {
-    return page().theme();
+    return RenderTheme::singleton();
 }
 
 bool RenderObject::isDescendantOf(const RenderObject* ancestor) const
index db4d808..308e0df 100644 (file)
@@ -1278,7 +1278,7 @@ Color RenderTheme::platformInactiveTextSearchHighlightColor() const
 #if ENABLE(TOUCH_EVENTS)
 Color RenderTheme::tapHighlightColor()
 {
-    return defaultTheme()->platformTapHighlightColor();
+    return singleton().platformTapHighlightColor();
 }
 #endif
 
@@ -1313,7 +1313,7 @@ void RenderTheme::setCustomFocusRingColor(const Color& c)
 
 Color RenderTheme::focusRingColor()
 {
-    return customFocusRingColor().isValid() ? customFocusRingColor() : defaultTheme()->platformFocusRingColor();
+    return customFocusRingColor().isValid() ? customFocusRingColor() : RenderTheme::singleton().platformFocusRingColor();
 }
 
 String RenderTheme::fileListDefaultLabel(bool multipleFilesAllowed) const
index 873c1b0..11757ea 100644 (file)
@@ -62,15 +62,8 @@ public:
     virtual ~RenderTheme() { }
 
     // This function is to be implemented in your platform-specific theme implementation to hand back the
-    // appropriate platform theme. When the theme is needed in non-page dependent code, a default theme is
-    // used as fallback, which is returned for a nulled page, so the platform code needs to account for this.
-    static Ref<RenderTheme> themeForPage(Page*);
-
-    // When the theme is needed in non-page dependent code, the defaultTheme() is used as fallback.
-    static inline Ref<RenderTheme> defaultTheme()
-    {
-        return themeForPage(nullptr);
-    };
+    // appropriate platform theme.
+    static RenderTheme& singleton();
 
     virtual void purgeCaches() { }
 
index b069754..be15df6 100644 (file)
@@ -66,10 +66,10 @@ Ref<RenderTheme> RenderThemeGtk::create()
     return adoptRef(*new RenderThemeGtk());
 }
 
-Ref<RenderTheme> RenderTheme::themeForPage(Page*)
+RenderTheme& RenderTheme::singleton()
 {
-    static RenderTheme& rt = RenderThemeGtk::create().leakRef();
-    return rt;
+    static NeverDestroyed<Ref<RenderTheme>> theme(RenderThemeGtk::create());
+    return theme.get();
 }
 
 static double getScreenDPI()
index d62c39f..768a5c5 100644 (file)
@@ -295,10 +295,10 @@ RenderThemeIOS::RenderThemeIOS()
     CFNotificationCenterAddObserver(CFNotificationCenterGetLocalCenter(), this, contentSizeCategoryDidChange, UIContentSizeCategoryDidChangeNotification, 0, CFNotificationSuspensionBehaviorDeliverImmediately);
 }
 
-Ref<RenderTheme> RenderTheme::themeForPage(Page*)
+RenderTheme& RenderTheme::singleton()
 {
-    static RenderTheme& renderTheme = RenderThemeIOS::create().leakRef();
-    return renderTheme;
+    static NeverDestroyed<Ref<RenderTheme>> theme(RenderThemeIOS::create());
+    return theme.get();
 }
 
 Ref<RenderTheme> RenderThemeIOS::create()
index b7c6f35..5c9d78f 100644 (file)
@@ -195,10 +195,10 @@ enum {
     leftPadding
 };
 
-Ref<RenderTheme> RenderTheme::themeForPage(Page*)
+RenderTheme& RenderTheme::singleton()
 {
-    static RenderTheme& rt = RenderThemeMac::create().leakRef();
-    return rt;
+    static NeverDestroyed<Ref<RenderTheme>> theme(RenderThemeMac::create());
+    return theme.get();
 }
 
 Ref<RenderTheme> RenderThemeMac::create()
index 5222090..75f10ea 100644 (file)
@@ -188,10 +188,10 @@ Ref<RenderTheme> RenderThemeWin::create()
     return adoptRef(*new RenderThemeWin);
 }
 
-Ref<RenderTheme> RenderTheme::themeForPage(Page* page)
+RenderTheme& RenderTheme::singleton()
 {
-    static RenderTheme& winTheme = RenderThemeWin::create().leakRef();
-    return winTheme;
+    static NeverDestroyed<Ref<RenderTheme>> theme(RenderThemeWin::create());
+    return theme.get();
 }
 
 RenderThemeWin::RenderThemeWin()
index db20ebb..be4c84a 100644 (file)
@@ -84,7 +84,7 @@ TextPaintStyle computeTextPaintStyle(const Frame& frame, const RenderStyle& line
     if (lineStyle.insideDefaultButton()) {
         Page* page = frame.page();
         if (page && page->focusController().isActive()) {
-            paintStyle.fillColor = page->theme().systemColor(CSSValueActivebuttontext);
+            paintStyle.fillColor = RenderTheme::singleton().systemColor(CSSValueActivebuttontext);
             return paintStyle;
         }
     }
index 00120f8..611ab55 100644 (file)
@@ -2725,7 +2725,7 @@ LRESULT CALLBACK WebView::WebViewWndProc(HWND hWnd, UINT message, WPARAM wParam,
         case WM_XP_THEMECHANGED:
             if (Frame* coreFrame = core(mainFrameImpl)) {
                 webView->deleteBackingStore();
-                coreFrame->page()->theme().themeChanged();
+                RenderTheme::singleton().themeChanged();
                 ScrollbarTheme::theme().themeChanged();
                 RECT windowRect;
                 ::GetClientRect(hWnd, &windowRect);