Modified: trunk/Source/WebCore/platform/chromium/ScrollbarThemeChromiumMac.mm (94233 => 94234)
--- trunk/Source/WebCore/platform/chromium/ScrollbarThemeChromiumMac.mm 2011-08-31 21:19:45 UTC (rev 94233)
+++ trunk/Source/WebCore/platform/chromium/ScrollbarThemeChromiumMac.mm 2011-08-31 21:24:51 UTC (rev 94234)
@@ -655,7 +655,7 @@
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 @@
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 @@
// 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 @@
}
}
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();
}