Title: [183778] trunk/Source/WebCore
Revision
183778
Author
[email protected]
Date
2015-05-04 16:42:56 -0700 (Mon, 04 May 2015)

Log Message

Create a named CSS property for system colors
https://bugs.webkit.org/show_bug.cgi?id=144423

Follow-up comments from Darin Adler.

* rendering/RenderThemeIOS.h: Cache a Color rather than an RGBA32.
* rendering/RenderThemeIOS.mm:
(WebCore::RenderThemeIOS::systemColor): Use "add" to avoid multiple hits on the HashMap, and
cache invalid responses so that we don't have to keep looking for non-existent colors.
* rendering/RenderThemeMac.h: Same as iOS.
* rendering/RenderThemeMac.mm:
(WebCore::RenderThemeMac::systemColor):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (183777 => 183778)


--- trunk/Source/WebCore/ChangeLog	2015-05-04 23:31:10 UTC (rev 183777)
+++ trunk/Source/WebCore/ChangeLog	2015-05-04 23:42:56 UTC (rev 183778)
@@ -1,3 +1,18 @@
+2015-05-04  Dean Jackson  <[email protected]>
+
+        Create a named CSS property for system colors
+        https://bugs.webkit.org/show_bug.cgi?id=144423
+
+        Follow-up comments from Darin Adler.
+
+        * rendering/RenderThemeIOS.h: Cache a Color rather than an RGBA32.
+        * rendering/RenderThemeIOS.mm:
+        (WebCore::RenderThemeIOS::systemColor): Use "add" to avoid multiple hits on the HashMap, and
+        cache invalid responses so that we don't have to keep looking for non-existent colors.
+        * rendering/RenderThemeMac.h: Same as iOS.
+        * rendering/RenderThemeMac.mm:
+        (WebCore::RenderThemeMac::systemColor):
+
 2015-05-04  Simon Fraser  <[email protected]>
 
         display:none iframes cause repeated compositing flushing

Modified: trunk/Source/WebCore/rendering/RenderThemeIOS.h (183777 => 183778)


--- trunk/Source/WebCore/rendering/RenderThemeIOS.h	2015-05-04 23:31:10 UTC (rev 183777)
+++ trunk/Source/WebCore/rendering/RenderThemeIOS.h	2015-05-04 23:42:56 UTC (rev 183778)
@@ -111,8 +111,6 @@
     virtual String mediaControlsScript() override;
 #endif
 
-    virtual Color systemColor(CSSValueID) const override;
-
 private:
     RenderThemeIOS();
     virtual ~RenderThemeIOS() { }
@@ -120,10 +118,12 @@
     const Color& shadowColor() const;
     FloatRect addRoundedBorderClip(const RenderObject& box, GraphicsContext*, const IntRect&);
 
+    virtual Color systemColor(CSSValueID) const override;
+
     String m_mediaControlsScript;
     String m_mediaControlsStyleSheet;
 
-    mutable HashMap<int, RGBA32> m_systemColorCache;
+    mutable HashMap<int, Color> m_systemColorCache;
 };
 
 }

Modified: trunk/Source/WebCore/rendering/RenderThemeIOS.mm (183777 => 183778)


--- trunk/Source/WebCore/rendering/RenderThemeIOS.mm	2015-05-04 23:31:10 UTC (rev 183777)
+++ trunk/Source/WebCore/rendering/RenderThemeIOS.mm	2015-05-04 23:42:56 UTC (rev 183778)
@@ -1311,16 +1311,14 @@
 }
 #endif // ENABLE(VIDEO)
 
-Color RenderThemeIOS::systemColor(CSSValueID cssValueId) const
+Color RenderThemeIOS::systemColor(CSSValueID cssValueID) const
 {
-    {
-        auto it = m_systemColorCache.find(cssValueId);
-        if (it != m_systemColorCache.end())
-            return it->value;
-    }
+    auto addResult = m_systemColorCache.add(cssValueID, Color());
+    if (!addResult.isNewEntry)
+        return addResult.iterator->value;
 
     Color color;
-    switch (cssValueId) {
+    switch (cssValueID) {
     case CSSValueAppleSystemBlue:
         color = [getUIColorClass() systemBlueColor].CGColor;
         break;
@@ -1347,12 +1345,11 @@
     }
 
     if (!color.isValid())
-        color = RenderTheme::systemColor(cssValueId);
+        color = RenderTheme::systemColor(cssValueID);
 
-    if (color.isValid())
-        m_systemColorCache.set(cssValueId, color.rgb());
+    addResult.iterator->value = color;
 
-    return color;
+    return addResult.iterator->value;
 }
 
 }

Modified: trunk/Source/WebCore/rendering/RenderThemeMac.h (183777 => 183778)


--- trunk/Source/WebCore/rendering/RenderThemeMac.h	2015-05-04 23:31:10 UTC (rev 183777)
+++ trunk/Source/WebCore/rendering/RenderThemeMac.h	2015-05-04 23:42:56 UTC (rev 183778)
@@ -96,7 +96,6 @@
     virtual double animationDurationForProgressBar(RenderProgress&) const override;
     virtual IntRect progressBarRectForBounds(const RenderObject&, const IntRect&) const override;
 
-    virtual Color systemColor(CSSValueID) const override;
     // Controls color values returned from platformFocusRingColor(). systemColor() will be used when false.
     bool usesTestModeFocusRingColor() const;
     // A view associated to the contained document.
@@ -179,6 +178,8 @@
 
     FloatRect convertToPaintingRect(const RenderObject& inputRenderer, const RenderObject& partRenderer, const FloatRect& inputRect, const IntRect&) const;
 
+    virtual Color systemColor(CSSValueID) const override;
+
     // Get the control size based off the font. Used by some of the controls (like buttons).
     NSControlSize controlSizeForFont(RenderStyle&) const;
     NSControlSize controlSizeForSystemFont(RenderStyle&) const;
@@ -247,7 +248,7 @@
     bool m_isSliderThumbHorizontalPressed;
     bool m_isSliderThumbVerticalPressed;
 
-    mutable HashMap<int, RGBA32> m_systemColorCache;
+    mutable HashMap<int, Color> m_systemColorCache;
 
     RetainPtr<WebCoreRenderThemeNotificationObserver> m_notificationObserver;
 

Modified: trunk/Source/WebCore/rendering/RenderThemeMac.mm (183777 => 183778)


--- trunk/Source/WebCore/rendering/RenderThemeMac.mm	2015-05-04 23:31:10 UTC (rev 183777)
+++ trunk/Source/WebCore/rendering/RenderThemeMac.mm	2015-05-04 23:42:56 UTC (rev 183778)
@@ -455,16 +455,14 @@
     RenderTheme::platformColorsDidChange();
 }
 
-Color RenderThemeMac::systemColor(CSSValueID cssValueId) const
+Color RenderThemeMac::systemColor(CSSValueID cssValueID) const
 {
-    {
-        auto it = m_systemColorCache.find(cssValueId);
-        if (it != m_systemColorCache.end())
-            return it->value;
-    }
+    auto addResult = m_systemColorCache.add(cssValueID, Color());
+    if (!addResult.isNewEntry)
+        return addResult.iterator->value;
 
     Color color;
-    switch (cssValueId) {
+    switch (cssValueID) {
     case CSSValueActiveborder:
         color = convertNSColorToColor([NSColor keyboardFocusIndicatorColor]);
         break;
@@ -602,12 +600,11 @@
     }
 
     if (!color.isValid())
-        color = RenderTheme::systemColor(cssValueId);
+        color = RenderTheme::systemColor(cssValueID);
 
-    if (color.isValid())
-        m_systemColorCache.set(cssValueId, color.rgb());
+    addResult.iterator->value = color;
 
-    return color;
+    return addResult.iterator->value;
 }
 
 bool RenderThemeMac::usesTestModeFocusRingColor() const
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to