Chromium Mac: Tweak rubber banding overhang shadows. Add a drop shadow from the brows...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 31 Aug 2011 21:24:51 +0000 (21:24 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 31 Aug 2011 21:24:51 +0000 (21:24 +0000)
https://bugs.webkit.org/show_bug.cgi?id=67289

Chromium bug: http://crbug.com/93228

Patch by Alexei Svitkine <asvitkine@chromium.org> on 2011-08-31
Reviewed by Dimitri Glazkov.

No new tests, since this merely tweaks Chromium overhang area appearance.

* platform/chromium/ScrollbarThemeChromiumMac.mm:
(WebCore::ScrollbarThemeChromiumMac::paintGivenTickmarks):
(WebCore::ScrollbarThemeChromiumMac::paintOverhangAreas):

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

Source/WebCore/ChangeLog
Source/WebCore/platform/chromium/ScrollbarThemeChromiumMac.mm

index a4f25e6..58520ab 100644 (file)
@@ -1,3 +1,18 @@
+2011-08-31  Alexei Svitkine  <asvitkine@chromium.org>
+
+        Chromium Mac: Tweak rubber banding overhang shadows. Add a drop shadow from the browser's toolbar.
+        https://bugs.webkit.org/show_bug.cgi?id=67289
+
+        Chromium bug: http://crbug.com/93228
+
+        Reviewed by Dimitri Glazkov.
+
+        No new tests, since this merely tweaks Chromium overhang area appearance.
+
+        * platform/chromium/ScrollbarThemeChromiumMac.mm:
+        (WebCore::ScrollbarThemeChromiumMac::paintGivenTickmarks):
+        (WebCore::ScrollbarThemeChromiumMac::paintOverhangAreas):
+
 2011-08-31  Tony Chang  <tony@chromium.org>
 
         Remove webcore_bindings (including DerivedSources##.cpp) from the critical path
index 1466839..e74b612 100644 (file)
@@ -655,7 +655,7 @@ void ScrollbarThemeChromiumMac::paintGivenTickmarks(GraphicsContext* context, Sc
     if (!tickmarks.size())
         return;
 
-    context->save();
+    GraphicsContextStateSaver stateSaver(*context);
     context->setShouldAntialias(false);
     context->setStrokeColor(Color(0xCC, 0xAA, 0x00, 0xFF), ColorSpaceDeviceRGB);
     context->setFillColor(Color(0xFF, 0xDD, 0x00, 0xFF), ColorSpaceDeviceRGB);
@@ -674,28 +674,33 @@ void ScrollbarThemeChromiumMac::paintGivenTickmarks(GraphicsContext* context, Sc
         context->fillRect(tickRect);
         context->strokeRect(tickRect, 1);
     }
-
-    context->restore();
 }
 
 void ScrollbarThemeChromiumMac::paintOverhangAreas(ScrollView* view, GraphicsContext* context, const IntRect& horizontalOverhangRect, const IntRect& verticalOverhangRect, const IntRect& dirtyRect)
 {
-    const int kShadowSize = 5;
+    // 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.0, Color(0, 0, 0, 141) },
-        { 0.2, Color(0, 0, 0, 89) },
-        { 0.6, Color(0, 0, 0, 30) },
-        { 1.0, Color(0, 0, 0, 0) }
+        { 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]);
 
-    bool hasHorizontalOverhang = !horizontalOverhangRect.isEmpty();
-    bool hasVerticalOverhang = !verticalOverhangRect.isEmpty();
+    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;
 
-    context->save();
+    GraphicsContextStateSaver stateSaver(*context);
 
     context->setFillPattern(m_overhangPattern);
     if (hasHorizontalOverhang)
@@ -709,20 +714,27 @@ void ScrollbarThemeChromiumMac::paintOverhangAreas(ScrollView* view, GraphicsCon
 
     // 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) {
-            shadowRect.setY(shadowRect.maxY() - kShadowSize);
-            shadowRect.setHeight(kShadowSize);
-            gradient = Gradient::create(FloatPoint(0, shadowRect.maxY()), FloatPoint(0, shadowRect.y()));
+            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 {
-            shadowRect.setHeight(kShadowSize);
             gradient = Gradient::create(FloatPoint(0, shadowRect.y()), FloatPoint(0, shadowRect.maxY()));
             shadowCornerOrigin.setY(shadowRect.y());
         }
-        if (hasHorizontalOverhang) {
+        if (hasVerticalOverhang) {
             shadowRect.setWidth(shadowRect.width() - verticalOverhangRect.width());
             if (scrollOffset.width() < 0) {
                 shadowRect.setX(shadowRect.x() + verticalOverhangRect.width());
@@ -733,39 +745,57 @@ void ScrollbarThemeChromiumMac::paintOverhangAreas(ScrollView* view, GraphicsCon
             }
         }
         for (unsigned i = 0; i < kNumShadowColors; i++)
-          gradient->addColorStop(kShadowColors[i].stop, kShadowColors[i].color);
+            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(shadowRect.maxX() - kShadowSize);
-            shadowRect.setWidth(kShadowSize);
+            shadowRect.setX(verticalOverhangRect.maxX() - shadowRect.width());
             gradient = Gradient::create(FloatPoint(shadowRect.maxX(), 0), FloatPoint(shadowRect.x(), 0));
         } else {
-            shadowRect.setWidth(kShadowSize);
             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);
+            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));
+        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));
     }
-
-    context->restore();
 }