| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008, 2011 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008, 2011 Apple Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 // Calculate how far down (in pixels) the tick-mark should appear. | 123 // Calculate how far down (in pixels) the tick-mark should appear. |
| 124 const int yPos = rect.y() + (rect.height() * percent); | 124 const int yPos = rect.y() + (rect.height() * percent); |
| 125 | 125 |
| 126 // Paint. | 126 // Paint. |
| 127 FloatRect tickRect(rect.x(), yPos, rect.width(), 2); | 127 FloatRect tickRect(rect.x(), yPos, rect.width(), 2); |
| 128 context->fillRect(tickRect); | 128 context->fillRect(tickRect); |
| 129 context->strokeRect(tickRect, 1); | 129 context->strokeRect(tickRect, 1); |
| 130 } | 130 } |
| 131 } | 131 } |
| 132 | 132 |
| 133 void ScrollbarThemeMacCommon::paintOverhangBackground(GraphicsContext* context,
const IntRect& horizontalOverhangRect, const IntRect& verticalOverhangRect, cons
t IntRect& dirtyRect) | |
| 134 { | |
| 135 const bool hasHorizontalOverhang = !horizontalOverhangRect.isEmpty(); | |
| 136 const bool hasVerticalOverhang = !verticalOverhangRect.isEmpty(); | |
| 137 | |
| 138 GraphicsContextStateSaver stateSaver(*context); | |
| 139 | |
| 140 if (!m_overhangPattern) { | |
| 141 // Lazily load the linen pattern image used for overhang drawing. | |
| 142 RefPtr<Image> patternImage = Image::loadPlatformResource("overhangPatter
n"); | |
| 143 m_overhangPattern = Pattern::createBitmapPattern(patternImage); | |
| 144 } | |
| 145 context->setFillPattern(m_overhangPattern); | |
| 146 if (hasHorizontalOverhang) | |
| 147 context->fillRect(intersection(horizontalOverhangRect, dirtyRect)); | |
| 148 if (hasVerticalOverhang) | |
| 149 context->fillRect(intersection(verticalOverhangRect, dirtyRect)); | |
| 150 } | |
| 151 | |
| 152 void ScrollbarThemeMacCommon::paintOverhangShadows(GraphicsContext* context, con
st IntSize& scrollOffset, const IntRect& horizontalOverhangRect, const IntRect&
verticalOverhangRect, const IntRect& dirtyRect) | |
| 153 { | |
| 154 // The extent of each shadow in pixels. | |
| 155 const int kShadowSize = 4; | |
| 156 // Offset of negative one pixel to make the gradient blend with the toolbar'
s bottom border. | |
| 157 const int kToolbarShadowOffset = -1; | |
| 158 const struct { | |
| 159 float stop; | |
| 160 Color color; | |
| 161 } kShadowColors[] = { | |
| 162 { 0.000, Color(0, 0, 0, 255) }, | |
| 163 { 0.125, Color(0, 0, 0, 57) }, | |
| 164 { 0.375, Color(0, 0, 0, 41) }, | |
| 165 { 0.625, Color(0, 0, 0, 18) }, | |
| 166 { 0.875, Color(0, 0, 0, 6) }, | |
| 167 { 1.000, Color(0, 0, 0, 0) } | |
| 168 }; | |
| 169 const unsigned kNumShadowColors = sizeof(kShadowColors)/sizeof(kShadowColors
[0]); | |
| 170 | |
| 171 const bool hasHorizontalOverhang = !horizontalOverhangRect.isEmpty(); | |
| 172 const bool hasVerticalOverhang = !verticalOverhangRect.isEmpty(); | |
| 173 // Prefer non-additive shadows, but degrade to additive shadows if there is
vertical overhang. | |
| 174 const bool useAdditiveShadows = hasVerticalOverhang; | |
| 175 | |
| 176 GraphicsContextStateSaver stateSaver(*context); | |
| 177 | |
| 178 FloatPoint shadowCornerOrigin; | |
| 179 FloatPoint shadowCornerOffset; | |
| 180 | |
| 181 // Draw the shadow for the horizontal overhang. | |
| 182 if (hasHorizontalOverhang) { | |
| 183 int toolbarShadowHeight = kShadowSize; | |
| 184 RefPtr<Gradient> gradient; | |
| 185 IntRect shadowRect = horizontalOverhangRect; | |
| 186 shadowRect.setHeight(kShadowSize); | |
| 187 if (scrollOffset.height() < 0) { | |
| 188 if (useAdditiveShadows) { | |
| 189 toolbarShadowHeight = std::min(horizontalOverhangRect.height(),
kShadowSize); | |
| 190 } else if (horizontalOverhangRect.height() < 2 * kShadowSize + kTool
barShadowOffset) { | |
| 191 // Split the overhang area between the web content shadow and to
olbar shadow if it's too small. | |
| 192 shadowRect.setHeight((horizontalOverhangRect.height() + 1) / 2); | |
| 193 toolbarShadowHeight = horizontalOverhangRect.height() - shadowRe
ct.height() - kToolbarShadowOffset; | |
| 194 } | |
| 195 shadowRect.setY(horizontalOverhangRect.maxY() - shadowRect.height())
; | |
| 196 gradient = Gradient::create(FloatPoint(0, shadowRect.maxY()), FloatP
oint(0, shadowRect.maxY() - kShadowSize)); | |
| 197 shadowCornerOrigin.setY(shadowRect.maxY()); | |
| 198 shadowCornerOffset.setY(-kShadowSize); | |
| 199 } else { | |
| 200 gradient = Gradient::create(FloatPoint(0, shadowRect.y()), FloatPoin
t(0, shadowRect.maxY())); | |
| 201 shadowCornerOrigin.setY(shadowRect.y()); | |
| 202 } | |
| 203 if (hasVerticalOverhang) { | |
| 204 shadowRect.setWidth(shadowRect.width() - verticalOverhangRect.width(
)); | |
| 205 if (scrollOffset.width() < 0) { | |
| 206 shadowRect.setX(shadowRect.x() + verticalOverhangRect.width()); | |
| 207 shadowCornerOrigin.setX(shadowRect.x()); | |
| 208 shadowCornerOffset.setX(-kShadowSize); | |
| 209 } else { | |
| 210 shadowCornerOrigin.setX(shadowRect.maxX()); | |
| 211 } | |
| 212 } | |
| 213 for (unsigned i = 0; i < kNumShadowColors; i++) | |
| 214 gradient->addColorStop(kShadowColors[i].stop, kShadowColors[i].color
); | |
| 215 context->setFillGradient(gradient); | |
| 216 context->fillRect(intersection(shadowRect, dirtyRect)); | |
| 217 | |
| 218 // Draw a drop-shadow from the toolbar. | |
| 219 if (scrollOffset.height() < 0) { | |
| 220 shadowRect.setY(kToolbarShadowOffset); | |
| 221 shadowRect.setHeight(toolbarShadowHeight); | |
| 222 gradient = Gradient::create(FloatPoint(0, shadowRect.y()), FloatPoin
t(0, shadowRect.y() + kShadowSize)); | |
| 223 for (unsigned i = 0; i < kNumShadowColors; i++) | |
| 224 gradient->addColorStop(kShadowColors[i].stop, kShadowColors[i].c
olor); | |
| 225 context->setFillGradient(gradient); | |
| 226 context->fillRect(intersection(shadowRect, dirtyRect)); | |
| 227 } | |
| 228 } | |
| 229 | |
| 230 // Draw the shadow for the vertical overhang. | |
| 231 if (hasVerticalOverhang) { | |
| 232 RefPtr<Gradient> gradient; | |
| 233 IntRect shadowRect = verticalOverhangRect; | |
| 234 shadowRect.setWidth(kShadowSize); | |
| 235 if (scrollOffset.width() < 0) { | |
| 236 shadowRect.setX(verticalOverhangRect.maxX() - shadowRect.width()); | |
| 237 gradient = Gradient::create(FloatPoint(shadowRect.maxX(), 0), FloatP
oint(shadowRect.x(), 0)); | |
| 238 } else { | |
| 239 gradient = Gradient::create(FloatPoint(shadowRect.x(), 0), FloatPoin
t(shadowRect.maxX(), 0)); | |
| 240 } | |
| 241 for (unsigned i = 0; i < kNumShadowColors; i++) | |
| 242 gradient->addColorStop(kShadowColors[i].stop, kShadowColors[i].color
); | |
| 243 context->setFillGradient(gradient); | |
| 244 context->fillRect(intersection(shadowRect, dirtyRect)); | |
| 245 | |
| 246 // Draw a drop-shadow from the toolbar. | |
| 247 shadowRect = verticalOverhangRect; | |
| 248 shadowRect.setY(kToolbarShadowOffset); | |
| 249 shadowRect.setHeight(kShadowSize); | |
| 250 gradient = Gradient::create(FloatPoint(0, shadowRect.y()), FloatPoint(0,
shadowRect.maxY())); | |
| 251 for (unsigned i = 0; i < kNumShadowColors; i++) | |
| 252 gradient->addColorStop(kShadowColors[i].stop, kShadowColors[i].color
); | |
| 253 context->setFillGradient(gradient); | |
| 254 context->fillRect(intersection(shadowRect, dirtyRect)); | |
| 255 } | |
| 256 | |
| 257 // If both rectangles present, draw a radial gradient for the corner. | |
| 258 if (hasHorizontalOverhang && hasVerticalOverhang) { | |
| 259 RefPtr<Gradient> gradient = Gradient::create(shadowCornerOrigin, 0, shad
owCornerOrigin, kShadowSize); | |
| 260 for (unsigned i = 0; i < kNumShadowColors; i++) | |
| 261 gradient->addColorStop(kShadowColors[i].stop, kShadowColors[i].color
); | |
| 262 context->setFillGradient(gradient); | |
| 263 context->fillRect(FloatRect(shadowCornerOrigin.x() + shadowCornerOffset.
x(), shadowCornerOrigin.y() + shadowCornerOffset.y(), kShadowSize, kShadowSize))
; | |
| 264 } | |
| 265 } | |
| 266 | |
| 267 void ScrollbarThemeMacCommon::paintTickmarks(GraphicsContext* context, Scrollbar
ThemeClient* scrollbar, const IntRect& rect) | 133 void ScrollbarThemeMacCommon::paintTickmarks(GraphicsContext* context, Scrollbar
ThemeClient* scrollbar, const IntRect& rect) |
| 268 { | 134 { |
| 269 // Note: This is only used for css-styled scrollbars on mac. | 135 // Note: This is only used for css-styled scrollbars on mac. |
| 270 if (scrollbar->orientation() != VerticalScrollbar) | 136 if (scrollbar->orientation() != VerticalScrollbar) |
| 271 return; | 137 return; |
| 272 | 138 |
| 273 if (rect.height() <= 0 || rect.width() <= 0) | 139 if (rect.height() <= 0 || rect.width() <= 0) |
| 274 return; | 140 return; |
| 275 | 141 |
| 276 Vector<IntRect> tickmarks; | 142 Vector<IntRect> tickmarks; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 // static | 225 // static |
| 360 bool ScrollbarThemeMacCommon::isOverlayAPIAvailable() | 226 bool ScrollbarThemeMacCommon::isOverlayAPIAvailable() |
| 361 { | 227 { |
| 362 static bool apiAvailable = | 228 static bool apiAvailable = |
| 363 [NSClassFromString(@"NSScrollerImp") respondsToSelector:@selector(scroll
erImpWithStyle:controlSize:horizontal:replacingScrollerImp:)] | 229 [NSClassFromString(@"NSScrollerImp") respondsToSelector:@selector(scroll
erImpWithStyle:controlSize:horizontal:replacingScrollerImp:)] |
| 364 && [NSClassFromString(@"NSScrollerImpPair") instancesRespondToSelector:@
selector(scrollerStyle)]; | 230 && [NSClassFromString(@"NSScrollerImpPair") instancesRespondToSelector:@
selector(scrollerStyle)]; |
| 365 return apiAvailable; | 231 return apiAvailable; |
| 366 } | 232 } |
| 367 | 233 |
| 368 } // namespace blink | 234 } // namespace blink |
| OLD | NEW |