Title: [95860] trunk/Source
Revision
95860
Author
[email protected]
Date
2011-09-23 14:39:52 -0700 (Fri, 23 Sep 2011)

Log Message

Refactor paintOverhangAreas to allow non-Mac Chromium platforms to reuse code
https://bugs.webkit.org/show_bug.cgi?id=68648

Reviewed by Dimitri Glazkov.

Source/WebCore:

No new tests because there's no change in functionality (yet).

* platform/chromium/ScrollbarThemeChromium.cpp:
(WebCore::ScrollbarThemeChromium::ScrollbarThemeChromium):
(WebCore::ScrollbarThemeChromium::~ScrollbarThemeChromium):
(WebCore::ScrollbarThemeChromium::paintOverhangAreas):
* platform/chromium/ScrollbarThemeChromium.h:
* platform/chromium/ScrollbarThemeChromiumMac.h:
* platform/chromium/ScrollbarThemeChromiumMac.mm:
(WebCore::ScrollbarThemeChromiumMac::ScrollbarThemeChromiumMac):

Source/WebKit/chromium:

* features.gypi:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (95859 => 95860)


--- trunk/Source/WebCore/ChangeLog	2011-09-23 21:35:30 UTC (rev 95859)
+++ trunk/Source/WebCore/ChangeLog	2011-09-23 21:39:52 UTC (rev 95860)
@@ -1,3 +1,21 @@
+2011-09-23  Fady Samuel  <[email protected]>
+
+        Refactor paintOverhangAreas to allow non-Mac Chromium platforms to reuse code
+        https://bugs.webkit.org/show_bug.cgi?id=68648
+
+        Reviewed by Dimitri Glazkov.
+
+        No new tests because there's no change in functionality (yet).
+
+        * platform/chromium/ScrollbarThemeChromium.cpp:
+        (WebCore::ScrollbarThemeChromium::ScrollbarThemeChromium):
+        (WebCore::ScrollbarThemeChromium::~ScrollbarThemeChromium):
+        (WebCore::ScrollbarThemeChromium::paintOverhangAreas):
+        * platform/chromium/ScrollbarThemeChromium.h:
+        * platform/chromium/ScrollbarThemeChromiumMac.h:
+        * platform/chromium/ScrollbarThemeChromiumMac.mm:
+        (WebCore::ScrollbarThemeChromiumMac::ScrollbarThemeChromiumMac):
+
 2011-09-23  Ojan Vafai  <[email protected]>
 
         remove physical flex-flow values to match the updated spec

Modified: trunk/Source/WebCore/platform/chromium/ScrollbarThemeChromium.cpp (95859 => 95860)


--- trunk/Source/WebCore/platform/chromium/ScrollbarThemeChromium.cpp	2011-09-23 21:35:30 UTC (rev 95859)
+++ trunk/Source/WebCore/platform/chromium/ScrollbarThemeChromium.cpp	2011-09-23 21:39:52 UTC (rev 95860)
@@ -28,6 +28,11 @@
 #include "ScrollbarThemeChromium.h"
 
 #include "PlatformMouseEvent.h"
+
+#if ENABLE(RUBBER_BANDING)
+#include "ScrollView.h"
+#endif
+
 #include "ScrollableArea.h"
 #include "Scrollbar.h"
 #include "ScrollbarThemeComposite.h"
@@ -39,6 +44,144 @@
 
 namespace WebCore {
 
+#if ENABLE(RUBBER_BANDING)
+ScrollbarThemeChromium::ScrollbarThemeChromium()
+{
+    static bool initialized = false;
+    if (!initialized) {
+        initialized = true;
+        // Load the linen pattern image used for overhang drawing.
+        RefPtr<Image> patternImage = Image::loadPlatformResource("overhangPattern");
+        m_overhangPattern = Pattern::create(patternImage, true, true);
+    }
+}
+
+ScrollbarThemeChromium::~ScrollbarThemeChromium()
+{
+}
+
+void ScrollbarThemeChromium::paintOverhangAreas(ScrollView* view, GraphicsContext* context, const IntRect& horizontalOverhangRect, const IntRect& verticalOverhangRect, const IntRect& dirtyRect)
+{
+    // The extent of each shadow in pixels.
+    const int kShadowSize = 4;
+    // Offset of negative one pixel to make the gradient blend with the toolbar's bottom border.
+    const int kToolbarShadowOffset = -1;
+    const struct {
+        float stop;
+        Color color;
+    } kShadowColors[] = {
+        { 0.000, Color(0, 0, 0, 255) },
+        { 0.125, Color(0, 0, 0, 57) },
+        { 0.375, Color(0, 0, 0, 41) },
+        { 0.625, Color(0, 0, 0, 18) },
+        { 0.875, Color(0, 0, 0, 6) },
+        { 1.000, Color(0, 0, 0, 0) }
+    };
+    const unsigned kNumShadowColors = sizeof(kShadowColors) / sizeof(kShadowColors[0]);
+
+    const bool hasHorizontalOverhang = !horizontalOverhangRect.isEmpty();
+    const bool hasVerticalOverhang = !verticalOverhangRect.isEmpty();
+    // Prefer non-additive shadows, but degrade to additive shadows if there is vertical overhang.
+    const bool useAdditiveShadows = hasVerticalOverhang;
+
+    GraphicsContextStateSaver stateSaver(*context);
+
+    context->setFillPattern(m_overhangPattern);
+    if (hasHorizontalOverhang)
+        context->fillRect(intersection(horizontalOverhangRect, dirtyRect));
+    if (hasVerticalOverhang)
+        context->fillRect(intersection(verticalOverhangRect, dirtyRect));
+
+    IntSize scrollOffset = view->scrollOffset();
+    FloatPoint shadowCornerOrigin;
+    FloatPoint shadowCornerOffset;
+
+    // Draw the shadow for the horizontal overhang.
+    if (hasHorizontalOverhang) {
+        int toolbarShadowHeight = kShadowSize;
+        RefPtr<Gradient> gradient;
+        IntRect shadowRect = horizontalOverhangRect;
+        shadowRect.setHeight(kShadowSize);
+        if (scrollOffset.height() < 0) {
+            if (useAdditiveShadows) {
+                toolbarShadowHeight = std::min(horizontalOverhangRect.height(), kShadowSize);
+            } else if (horizontalOverhangRect.height() < 2 * kShadowSize + kToolbarShadowOffset) {
+                // Split the overhang area between the web content shadow and toolbar shadow if it's too small.
+                shadowRect.setHeight((horizontalOverhangRect.height() + 1) / 2);
+                toolbarShadowHeight = horizontalOverhangRect.height() - shadowRect.height() - kToolbarShadowOffset;
+            }
+            shadowRect.setY(horizontalOverhangRect.maxY() - shadowRect.height());
+            gradient = Gradient::create(FloatPoint(0, shadowRect.maxY()), FloatPoint(0, shadowRect.maxY() - kShadowSize));
+            shadowCornerOrigin.setY(shadowRect.maxY());
+            shadowCornerOffset.setY(-kShadowSize);
+        } else {
+            gradient = Gradient::create(FloatPoint(0, shadowRect.y()), FloatPoint(0, shadowRect.maxY()));
+            shadowCornerOrigin.setY(shadowRect.y());
+        }
+        if (hasVerticalOverhang) {
+            shadowRect.setWidth(shadowRect.width() - verticalOverhangRect.width());
+            if (scrollOffset.width() < 0) {
+                shadowRect.setX(shadowRect.x() + verticalOverhangRect.width());
+                shadowCornerOrigin.setX(shadowRect.x());
+                shadowCornerOffset.setX(-kShadowSize);
+            } else
+                shadowCornerOrigin.setX(shadowRect.maxX());
+        }
+        for (unsigned i = 0; i < kNumShadowColors; i++)
+            gradient->addColorStop(kShadowColors[i].stop, kShadowColors[i].color);
+        context->setFillGradient(gradient);
+        context->fillRect(intersection(shadowRect, dirtyRect));
+
+        // Draw a drop-shadow from the toolbar.
+        if (scrollOffset.height() < 0) {
+            shadowRect.setY(kToolbarShadowOffset);
+            shadowRect.setHeight(toolbarShadowHeight);
+            gradient = Gradient::create(FloatPoint(0, shadowRect.y()), FloatPoint(0, shadowRect.y() + kShadowSize));
+            for (unsigned i = 0; i < kNumShadowColors; i++)
+                gradient->addColorStop(kShadowColors[i].stop, kShadowColors[i].color);
+            context->setFillGradient(gradient);
+            context->fillRect(intersection(shadowRect, dirtyRect));
+        }
+    }
+
+    // Draw the shadow for the vertical overhang.
+    if (hasVerticalOverhang) {
+        RefPtr<Gradient> gradient;
+        IntRect shadowRect = verticalOverhangRect;
+        shadowRect.setWidth(kShadowSize);
+        if (scrollOffset.width() < 0) {
+            shadowRect.setX(verticalOverhangRect.maxX() - shadowRect.width());
+            gradient = Gradient::create(FloatPoint(shadowRect.maxX(), 0), FloatPoint(shadowRect.x(), 0));
+        } else
+            gradient = Gradient::create(FloatPoint(shadowRect.x(), 0), FloatPoint(shadowRect.maxX(), 0));
+
+        for (unsigned i = 0; i < kNumShadowColors; i++)
+            gradient->addColorStop(kShadowColors[i].stop, kShadowColors[i].color);
+        context->setFillGradient(gradient);
+        context->fillRect(intersection(shadowRect, dirtyRect));
+
+        // Draw a drop-shadow from the toolbar.
+        shadowRect = verticalOverhangRect;
+        shadowRect.setY(kToolbarShadowOffset);
+        shadowRect.setHeight(kShadowSize);
+        gradient = Gradient::create(FloatPoint(0, shadowRect.y()), FloatPoint(0, shadowRect.maxY()));
+        for (unsigned i = 0; i < kNumShadowColors; i++)
+            gradient->addColorStop(kShadowColors[i].stop, kShadowColors[i].color);
+        context->setFillGradient(gradient);
+        context->fillRect(intersection(shadowRect, dirtyRect));
+    }
+
+    // If both rectangles present, draw a radial gradient for the corner.
+    if (hasHorizontalOverhang && hasVerticalOverhang) {
+        RefPtr<Gradient> gradient = Gradient::create(shadowCornerOrigin, 0, shadowCornerOrigin, kShadowSize);
+        for (unsigned i = 0; i < kNumShadowColors; i++)
+            gradient->addColorStop(kShadowColors[i].stop, kShadowColors[i].color);
+        context->setFillGradient(gradient);
+        context->fillRect(FloatRect(shadowCornerOrigin.x() + shadowCornerOffset.x(), shadowCornerOrigin.y() + shadowCornerOffset.y(), kShadowSize, kShadowSize));
+    }
+}
+#endif
+
 bool ScrollbarThemeChromium::hasThumb(Scrollbar* scrollbar)
 {
     // This method is just called as a paint-time optimization to see if

Modified: trunk/Source/WebCore/platform/chromium/ScrollbarThemeChromium.h (95859 => 95860)


--- trunk/Source/WebCore/platform/chromium/ScrollbarThemeChromium.h	2011-09-23 21:35:30 UTC (rev 95859)
+++ trunk/Source/WebCore/platform/chromium/ScrollbarThemeChromium.h	2011-09-23 21:39:52 UTC (rev 95860)
@@ -40,6 +40,13 @@
     // This class contains the scrollbar code which is shared between Chromium
     // Windows and Linux.
     class ScrollbarThemeChromium : public ScrollbarThemeComposite {
+#if ENABLE(RUBBER_BANDING)
+    public:
+        ScrollbarThemeChromium();
+        virtual ~ScrollbarThemeChromium();
+        virtual void paintOverhangAreas(ScrollView*, GraphicsContext*, const IntRect& horizontalOverhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect);
+#endif
+
     protected:
         virtual bool hasButtons(Scrollbar*) { return true; }
         virtual bool hasThumb(Scrollbar*);
@@ -52,6 +59,11 @@
         virtual void paintTickmarks(GraphicsContext*, Scrollbar*, const IntRect&);
 
         virtual IntSize buttonSize(Scrollbar*) = 0;
+
+#if ENABLE(RUBBER_BANDING)
+    private:
+        RefPtr<Pattern> m_overhangPattern;
+#endif
     };
 } // namespace WebCore
 

Modified: trunk/Source/WebCore/platform/chromium/ScrollbarThemeChromiumMac.h (95859 => 95860)


--- trunk/Source/WebCore/platform/chromium/ScrollbarThemeChromiumMac.h	2011-09-23 21:35:30 UTC (rev 95859)
+++ trunk/Source/WebCore/platform/chromium/ScrollbarThemeChromiumMac.h	2011-09-23 21:39:52 UTC (rev 95860)
@@ -62,8 +62,6 @@
 
     void setNewPainterForScrollbar(Scrollbar*, WKScrollbarPainterRef);
     WKScrollbarPainterRef painterForScrollbar(Scrollbar*);
-
-    virtual void paintOverhangAreas(ScrollView*, GraphicsContext*, const IntRect& horizontalOverhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect);
     
 protected:
     virtual bool hasButtons(Scrollbar*);
@@ -82,9 +80,6 @@
 
 private:
     void paintGivenTickmarks(GraphicsContext*, Scrollbar*, const IntRect&, const Vector<IntRect>&);
-
-private:
-    RefPtr<Pattern> m_overhangPattern;
 };
 
 }

Modified: trunk/Source/WebCore/platform/chromium/ScrollbarThemeChromiumMac.mm (95859 => 95860)


--- trunk/Source/WebCore/platform/chromium/ScrollbarThemeChromiumMac.mm	2011-09-23 21:35:30 UTC (rev 95859)
+++ trunk/Source/WebCore/platform/chromium/ScrollbarThemeChromiumMac.mm	2011-09-23 21:39:52 UTC (rev 95860)
@@ -194,10 +194,6 @@
     if (!initialized) {
         initialized = true;
 
-        // Load the linen pattern image used for overhang drawing.
-        RefPtr<Image> patternImage = Image::loadPlatformResource("overhangPattern");
-        m_overhangPattern = Pattern::create(patternImage, true, true);
-
         [ScrollbarPrefsObserver registerAsObserver];
         preferencesChanged();
     }
@@ -676,127 +672,4 @@
     }
 }
 
-void ScrollbarThemeChromiumMac::paintOverhangAreas(ScrollView* view, GraphicsContext* context, const IntRect& horizontalOverhangRect, const IntRect& verticalOverhangRect, const IntRect& dirtyRect)
-{
-    // The extent of each shadow in pixels.
-    const int kShadowSize = 4;
-    // Offset of negative one pixel to make the gradient blend with the toolbar's bottom border.
-    const int kToolbarShadowOffset = -1;
-    const struct {
-        float stop;
-        Color color;
-    } kShadowColors[] = {
-        { 0.000, Color(0, 0, 0, 255) },
-        { 0.125, Color(0, 0, 0, 57) },
-        { 0.375, Color(0, 0, 0, 41) },
-        { 0.625, Color(0, 0, 0, 18) },
-        { 0.875, Color(0, 0, 0, 6) },
-        { 1.000, Color(0, 0, 0, 0) }
-    };
-    const unsigned kNumShadowColors = sizeof(kShadowColors)/sizeof(kShadowColors[0]);
-
-    const bool hasHorizontalOverhang = !horizontalOverhangRect.isEmpty();
-    const bool hasVerticalOverhang = !verticalOverhangRect.isEmpty();
-    // Prefer non-additive shadows, but degrade to additive shadows if there is vertical overhang.
-    const bool useAdditiveShadows = hasVerticalOverhang;
-
-    GraphicsContextStateSaver stateSaver(*context);
-
-    context->setFillPattern(m_overhangPattern);
-    if (hasHorizontalOverhang)
-        context->fillRect(intersection(horizontalOverhangRect, dirtyRect));
-    if (hasVerticalOverhang)
-        context->fillRect(intersection(verticalOverhangRect, dirtyRect));
-
-    IntSize scrollOffset = view->scrollOffset();
-    FloatPoint shadowCornerOrigin;
-    FloatPoint shadowCornerOffset;
-
-    // Draw the shadow for the horizontal overhang.
-    if (hasHorizontalOverhang) {
-        int toolbarShadowHeight = kShadowSize;
-        RefPtr<Gradient> gradient;
-        IntRect shadowRect = horizontalOverhangRect;
-        shadowRect.setHeight(kShadowSize);
-        if (scrollOffset.height() < 0) {
-            if (useAdditiveShadows) {
-                toolbarShadowHeight = std::min(horizontalOverhangRect.height(), kShadowSize);
-            } else if (horizontalOverhangRect.height() < 2 * kShadowSize + kToolbarShadowOffset) {
-                // Split the overhang area between the web content shadow and toolbar shadow if it's too small.
-                shadowRect.setHeight((horizontalOverhangRect.height() + 1) / 2);
-                toolbarShadowHeight = horizontalOverhangRect.height() - shadowRect.height() - kToolbarShadowOffset;
-            }
-            shadowRect.setY(horizontalOverhangRect.maxY() - shadowRect.height());
-            gradient = Gradient::create(FloatPoint(0, shadowRect.maxY()), FloatPoint(0, shadowRect.maxY() - kShadowSize));
-            shadowCornerOrigin.setY(shadowRect.maxY());
-            shadowCornerOffset.setY(-kShadowSize);
-        } else {
-            gradient = Gradient::create(FloatPoint(0, shadowRect.y()), FloatPoint(0, shadowRect.maxY()));
-            shadowCornerOrigin.setY(shadowRect.y());
-        }
-        if (hasVerticalOverhang) {
-            shadowRect.setWidth(shadowRect.width() - verticalOverhangRect.width());
-            if (scrollOffset.width() < 0) {
-                shadowRect.setX(shadowRect.x() + verticalOverhangRect.width());
-                shadowCornerOrigin.setX(shadowRect.x());
-                shadowCornerOffset.setX(-kShadowSize);
-            } else {
-                shadowCornerOrigin.setX(shadowRect.maxX());
-            }
-        }
-        for (unsigned i = 0; i < kNumShadowColors; i++)
-            gradient->addColorStop(kShadowColors[i].stop, kShadowColors[i].color);
-        context->setFillGradient(gradient);
-        context->fillRect(intersection(shadowRect, dirtyRect));
-
-        // Draw a drop-shadow from the toolbar.
-        if (scrollOffset.height() < 0) {
-            shadowRect.setY(kToolbarShadowOffset);
-            shadowRect.setHeight(toolbarShadowHeight);
-            gradient = Gradient::create(FloatPoint(0, shadowRect.y()), FloatPoint(0, shadowRect.y() + kShadowSize));
-            for (unsigned i = 0; i < kNumShadowColors; i++)
-                gradient->addColorStop(kShadowColors[i].stop, kShadowColors[i].color);
-            context->setFillGradient(gradient);
-            context->fillRect(intersection(shadowRect, dirtyRect));
-        }
-    }
-
-    // Draw the shadow for the vertical overhang.
-    if (hasVerticalOverhang) {
-        RefPtr<Gradient> gradient;
-        IntRect shadowRect = verticalOverhangRect;
-        shadowRect.setWidth(kShadowSize);
-        if (scrollOffset.width() < 0) {
-            shadowRect.setX(verticalOverhangRect.maxX() - shadowRect.width());
-            gradient = Gradient::create(FloatPoint(shadowRect.maxX(), 0), FloatPoint(shadowRect.x(), 0));
-        } else {
-            gradient = Gradient::create(FloatPoint(shadowRect.x(), 0), FloatPoint(shadowRect.maxX(), 0));
-        }
-        for (unsigned i = 0; i < kNumShadowColors; i++)
-            gradient->addColorStop(kShadowColors[i].stop, kShadowColors[i].color);
-        context->setFillGradient(gradient);
-        context->fillRect(intersection(shadowRect, dirtyRect));
-
-        // Draw a drop-shadow from the toolbar.
-        shadowRect = verticalOverhangRect;
-        shadowRect.setY(kToolbarShadowOffset);
-        shadowRect.setHeight(kShadowSize);
-        gradient = Gradient::create(FloatPoint(0, shadowRect.y()), FloatPoint(0, shadowRect.maxY()));
-        for (unsigned i = 0; i < kNumShadowColors; i++)
-            gradient->addColorStop(kShadowColors[i].stop, kShadowColors[i].color);
-        context->setFillGradient(gradient);
-        context->fillRect(intersection(shadowRect, dirtyRect));
-    }
-
-    // If both rectangles present, draw a radial gradient for the corner.
-    if (hasHorizontalOverhang && hasVerticalOverhang) {
-        RefPtr<Gradient> gradient = Gradient::create(shadowCornerOrigin, 0, shadowCornerOrigin, kShadowSize);
-        for (unsigned i = 0; i < kNumShadowColors; i++)
-            gradient->addColorStop(kShadowColors[i].stop, kShadowColors[i].color);
-        context->setFillGradient(gradient);
-        context->fillRect(FloatRect(shadowCornerOrigin.x() + shadowCornerOffset.x(), shadowCornerOrigin.y() + shadowCornerOffset.y(), kShadowSize, kShadowSize));
-    }
 }
-
-
-}

Modified: trunk/Source/WebKit/chromium/ChangeLog (95859 => 95860)


--- trunk/Source/WebKit/chromium/ChangeLog	2011-09-23 21:35:30 UTC (rev 95859)
+++ trunk/Source/WebKit/chromium/ChangeLog	2011-09-23 21:39:52 UTC (rev 95860)
@@ -1,3 +1,12 @@
+2011-09-23  Fady Samuel  <[email protected]>
+
+        Refactor paintOverhangAreas to allow non-Mac Chromium platforms to reuse code
+        https://bugs.webkit.org/show_bug.cgi?id=68648
+
+        Reviewed by Dimitri Glazkov.
+
+        * features.gypi:
+
 2011-09-23  Elliot Poger  <[email protected]>
 
         update layout_tests to account for new default of use_skia=1

Modified: trunk/Source/WebKit/chromium/features.gypi (95859 => 95860)


--- trunk/Source/WebKit/chromium/features.gypi	2011-09-23 21:35:30 UTC (rev 95859)
+++ trunk/Source/WebKit/chromium/features.gypi	2011-09-23 21:39:52 UTC (rev 95860)
@@ -140,6 +140,9 @@
       }],
       ['touchui==1', {
         'enable_touch_icon_loading': 1,
+        'feature_defines': [
+          'ENABLE_RUBBER_BANDING=1',
+        ],
       }],
       # Mac OS X uses Accelerate.framework FFT by default instead of FFmpeg.
       ['OS!="mac"', {
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to