| OLD | NEW |
| (Empty) | |
| 1 /* |
| 2 * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2008, 2009 Google, Inc. |
| 4 * |
| 5 * This library is free software; you can redistribute it and/or |
| 6 * modify it under the terms of the GNU Library General Public |
| 7 * License as published by the Free Software Foundation; either |
| 8 * version 2 of the License, or (at your option) any later version. |
| 9 * |
| 10 * This library is distributed in the hope that it will be useful, |
| 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 * Library General Public License for more details. |
| 14 * |
| 15 * You should have received a copy of the GNU Library General Public License |
| 16 * along with this library; see the file COPYING.LIB. If not, write to |
| 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 * Boston, MA 02110-1301, USA. |
| 19 */ |
| 20 |
| 21 #import "config.h" |
| 22 #import "core/paint/ThemePainterMac.h" |
| 23 |
| 24 #import "core/layout/LayoutMeter.h" |
| 25 #import "core/layout/LayoutProgress.h" |
| 26 #import "core/layout/LayoutThemeMac.h" |
| 27 #import "core/layout/LayoutView.h" |
| 28 #import "core/paint/MediaControlsPainter.h" |
| 29 #import "core/paint/PaintInfo.h" |
| 30 #import "platform/geometry/FloatRoundedRect.h" |
| 31 #import "platform/graphics/BitmapImage.h" |
| 32 #import "platform/graphics/GraphicsContextStateSaver.h" |
| 33 #import "platform/graphics/Image.h" |
| 34 #import "platform/graphics/ImageBuffer.h" |
| 35 #import "platform/mac/ColorMac.h" |
| 36 #import "platform/mac/LocalCurrentGraphicsContext.h" |
| 37 #import "platform/mac/ThemeMac.h" |
| 38 #import "platform/mac/WebCoreNSCellExtras.h" |
| 39 #import <AvailabilityMacros.h> |
| 40 #import <Carbon/Carbon.h> |
| 41 #import <Cocoa/Cocoa.h> |
| 42 #import <math.h> |
| 43 |
| 44 // The methods in this file are specific to the Mac OS X platform. |
| 45 |
| 46 // Forward declare Mac SPIs. |
| 47 extern "C" { |
| 48 void _NSDrawCarbonThemeBezel(NSRect frame, BOOL enabled, BOOL flipped); |
| 49 // Request for public API: rdar://13787640 |
| 50 void _NSDrawCarbonThemeListBox(NSRect frame, BOOL enabled, BOOL flipped, BOOL al
ways_yes); |
| 51 } |
| 52 |
| 53 namespace blink { |
| 54 |
| 55 bool ThemePainterMac::paintTextField(LayoutObject* o, const PaintInfo& paintInfo
, const IntRect& r) |
| 56 { |
| 57 LocalCurrentGraphicsContext localContext(paintInfo.context, r); |
| 58 |
| 59 #if __MAC_OS_X_VERSION_MIN_REQUIRED <= 1070 |
| 60 bool useNSTextFieldCell = o->style()->hasAppearance() |
| 61 && o->style()->visitedDependentColor(CSSPropertyBackgroundColor) == Colo
r::white |
| 62 && !o->style()->hasBackgroundImage(); |
| 63 |
| 64 // We do not use NSTextFieldCell to draw styled text fields on Lion and |
| 65 // SnowLeopard because there are a number of bugs on those platforms that |
| 66 // require NSTextFieldCell to be in charge of painting its own |
| 67 // background. We need WebCore to paint styled backgrounds, so we'll use |
| 68 // this AppKit SPI function instead. |
| 69 if (!useNSTextFieldCell) { |
| 70 _NSDrawCarbonThemeBezel(r, LayoutTheme::isEnabled(o) && !LayoutTheme::is
ReadOnlyControl(o), YES); |
| 71 return false; |
| 72 } |
| 73 #endif |
| 74 |
| 75 NSTextFieldCell *textField = m_layoutTheme.textField(); |
| 76 |
| 77 GraphicsContextStateSaver stateSaver(*paintInfo.context); |
| 78 |
| 79 [textField setEnabled:(LayoutTheme::isEnabled(o) && !LayoutTheme::isReadOnly
Control(o))]; |
| 80 [textField drawWithFrame:NSRect(r) inView:m_layoutTheme.documentViewFor(o)]; |
| 81 |
| 82 [textField setControlView:nil]; |
| 83 |
| 84 return false; |
| 85 } |
| 86 |
| 87 bool ThemePainterMac::paintCapsLockIndicator(LayoutObject*, const PaintInfo& pai
ntInfo, const IntRect& r) |
| 88 { |
| 89 // This draws the caps lock indicator as it was done by |
| 90 // WKDrawCapsLockIndicator. |
| 91 LocalCurrentGraphicsContext localContext(paintInfo.context, r); |
| 92 CGContextRef c = localContext.cgContext(); |
| 93 CGMutablePathRef shape = CGPathCreateMutable(); |
| 94 |
| 95 // To draw the caps lock indicator, draw the shape into a small |
| 96 // square that is then scaled to the size of r. |
| 97 const CGFloat kSquareSize = 17; |
| 98 |
| 99 // Create a rounted square shape. |
| 100 CGPathMoveToPoint(shape, NULL, 16.5, 4.5); |
| 101 CGPathAddArc(shape, NULL, 12.5, 12.5, 4, 0, M_PI_2, false); |
| 102 CGPathAddArc(shape, NULL, 4.5, 12.5, 4, M_PI_2, M_PI, false); |
| 103 CGPathAddArc(shape, NULL, 4.5, 4.5, 4, M_PI, 3*M_PI/2, false); |
| 104 CGPathAddArc(shape, NULL, 12.5, 4.5, 4, 3*M_PI/2, 0, false); |
| 105 |
| 106 // Draw the arrow - note this is drawing in a flipped coordinate system, so |
| 107 // the arrow is pointing down. |
| 108 CGPathMoveToPoint(shape, NULL, 8.5, 2); // Tip point. |
| 109 CGPathAddLineToPoint(shape, NULL, 4, 7); |
| 110 CGPathAddLineToPoint(shape, NULL, 6.25, 7); |
| 111 CGPathAddLineToPoint(shape, NULL, 6.25, 10.25); |
| 112 CGPathAddLineToPoint(shape, NULL, 10.75, 10.25); |
| 113 CGPathAddLineToPoint(shape, NULL, 10.75, 7); |
| 114 CGPathAddLineToPoint(shape, NULL, 13, 7); |
| 115 CGPathAddLineToPoint(shape, NULL, 8.5, 2); |
| 116 |
| 117 // Draw the rectangle that underneath (or above in the flipped system) the |
| 118 // arrow. |
| 119 CGPathAddLineToPoint(shape, NULL, 10.75, 12); |
| 120 CGPathAddLineToPoint(shape, NULL, 6.25, 12); |
| 121 CGPathAddLineToPoint(shape, NULL, 6.25, 14.25); |
| 122 CGPathAddLineToPoint(shape, NULL, 10.75, 14.25); |
| 123 CGPathAddLineToPoint(shape, NULL, 10.75, 12); |
| 124 |
| 125 // Scale and translate the shape. |
| 126 CGRect cgr = r; |
| 127 CGFloat maxX = CGRectGetMaxX(cgr); |
| 128 CGFloat minY = CGRectGetMinY(cgr); |
| 129 CGFloat heightScale = r.height() / kSquareSize; |
| 130 CGAffineTransform transform = CGAffineTransformMake( |
| 131 heightScale, 0, // A B |
| 132 0, heightScale, // C D |
| 133 maxX - r.height(), minY); // Tx Ty |
| 134 |
| 135 CGMutablePathRef paintPath = CGPathCreateMutable(); |
| 136 CGPathAddPath(paintPath, &transform, shape); |
| 137 CGPathRelease(shape); |
| 138 |
| 139 CGContextSetRGBFillColor(c, 0, 0, 0, 0.4); |
| 140 CGContextBeginPath(c); |
| 141 CGContextAddPath(c, paintPath); |
| 142 CGContextFillPath(c); |
| 143 CGPathRelease(paintPath); |
| 144 |
| 145 return false; |
| 146 } |
| 147 |
| 148 bool ThemePainterMac::paintTextArea(LayoutObject* o, const PaintInfo& paintInfo,
const IntRect& r) |
| 149 { |
| 150 LocalCurrentGraphicsContext localContext(paintInfo.context, r); |
| 151 _NSDrawCarbonThemeListBox(r, LayoutTheme::isEnabled(o) && !LayoutTheme::isRe
adOnlyControl(o), YES, YES); |
| 152 return false; |
| 153 } |
| 154 |
| 155 bool ThemePainterMac::paintMenuList(LayoutObject* o, const PaintInfo& paintInfo,
const IntRect& r) |
| 156 { |
| 157 m_layoutTheme.setPopupButtonCellState(o, r); |
| 158 |
| 159 NSPopUpButtonCell* popupButton = m_layoutTheme.popupButton(); |
| 160 |
| 161 float zoomLevel = o->style()->effectiveZoom(); |
| 162 IntSize size = m_layoutTheme.popupButtonSizes()[[popupButton controlSize]]; |
| 163 size.setHeight(size.height() * zoomLevel); |
| 164 size.setWidth(r.width()); |
| 165 |
| 166 // Now inflate it to account for the shadow. |
| 167 IntRect inflatedRect = r; |
| 168 if (r.width() >= m_layoutTheme.minimumMenuListSize(o->styleRef())) |
| 169 inflatedRect = ThemeMac::inflateRect(inflatedRect, size, m_layoutTheme.p
opupButtonMargins(), zoomLevel); |
| 170 |
| 171 LocalCurrentGraphicsContext localContext(paintInfo.context, ThemeMac::inflat
eRectForFocusRing(inflatedRect)); |
| 172 GraphicsContextStateSaver stateSaver(*paintInfo.context); |
| 173 |
| 174 // On Leopard, the cell will draw outside of the given rect, so we have to |
| 175 // clip to the rect. |
| 176 paintInfo.context->clip(inflatedRect); |
| 177 |
| 178 if (zoomLevel != 1.0f) { |
| 179 inflatedRect.setWidth(inflatedRect.width() / zoomLevel); |
| 180 inflatedRect.setHeight(inflatedRect.height() / zoomLevel); |
| 181 paintInfo.context->translate(inflatedRect.x(), inflatedRect.y()); |
| 182 paintInfo.context->scale(zoomLevel, zoomLevel); |
| 183 paintInfo.context->translate(-inflatedRect.x(), -inflatedRect.y()); |
| 184 } |
| 185 |
| 186 NSView *view = m_layoutTheme.documentViewFor(o); |
| 187 [popupButton drawWithFrame:inflatedRect inView:view]; |
| 188 #if !BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING |
| 189 if (LayoutTheme::isFocused(o) && o->style()->outlineStyleIsAuto()) |
| 190 [popupButton _web_drawFocusRingWithFrame:inflatedRect inView:view]; |
| 191 #endif |
| 192 [popupButton setControlView:nil]; |
| 193 |
| 194 return false; |
| 195 } |
| 196 |
| 197 bool ThemePainterMac::paintMeter(LayoutObject* layoutObject, const PaintInfo& pa
intInfo, const IntRect& rect) |
| 198 { |
| 199 if (!layoutObject->isMeter()) |
| 200 return true; |
| 201 |
| 202 LocalCurrentGraphicsContext localContext(paintInfo.context, rect); |
| 203 |
| 204 NSLevelIndicatorCell* cell = m_layoutTheme.levelIndicatorFor(toLayoutMeter(l
ayoutObject)); |
| 205 GraphicsContextStateSaver stateSaver(*paintInfo.context); |
| 206 |
| 207 [cell drawWithFrame:rect inView:m_layoutTheme.documentViewFor(layoutObject)]
; |
| 208 [cell setControlView:nil]; |
| 209 return false; |
| 210 } |
| 211 |
| 212 bool ThemePainterMac::paintProgressBar(LayoutObject* layoutObject, const PaintIn
fo& paintInfo, const IntRect& rect) |
| 213 { |
| 214 if (!layoutObject->isProgress()) |
| 215 return true; |
| 216 |
| 217 float zoomLevel = layoutObject->style()->effectiveZoom(); |
| 218 NSControlSize controlSize = m_layoutTheme.controlSizeForFont(layoutObject->s
tyleRef()); |
| 219 IntSize size = m_layoutTheme.progressBarSizes()[controlSize]; |
| 220 size.setHeight(size.height() * zoomLevel); |
| 221 size.setWidth(rect.width()); |
| 222 |
| 223 // Now inflate it to account for the shadow. |
| 224 IntRect inflatedRect = rect; |
| 225 if (rect.height() <= m_layoutTheme.minimumProgressBarHeight(layoutObject->st
yleRef())) |
| 226 inflatedRect = ThemeMac::inflateRect(inflatedRect, size, m_layoutTheme.p
rogressBarMargins(controlSize), zoomLevel); |
| 227 |
| 228 LayoutProgress* layoutProgress = toLayoutProgress(layoutObject); |
| 229 HIThemeTrackDrawInfo trackInfo; |
| 230 trackInfo.version = 0; |
| 231 if (controlSize == NSRegularControlSize) |
| 232 trackInfo.kind = layoutProgress->position() < 0 ? kThemeLargeIndetermina
teBar : kThemeLargeProgressBar; |
| 233 else |
| 234 trackInfo.kind = layoutProgress->position() < 0 ? kThemeMediumIndetermin
ateBar : kThemeMediumProgressBar; |
| 235 |
| 236 trackInfo.bounds = IntRect(IntPoint(), inflatedRect.size()); |
| 237 trackInfo.min = 0; |
| 238 trackInfo.max = std::numeric_limits<SInt32>::max(); |
| 239 trackInfo.value = lround(layoutProgress->position() * nextafter(trackInfo.ma
x, 0)); |
| 240 trackInfo.trackInfo.progress.phase = lround(layoutProgress->animationProgres
s() * nextafter(LayoutThemeMac::progressAnimationNumFrames, 0)); |
| 241 trackInfo.attributes = kThemeTrackHorizontal; |
| 242 trackInfo.enableState = LayoutTheme::isActive(layoutObject) ? kThemeTrackAct
ive : kThemeTrackInactive; |
| 243 trackInfo.reserved = 0; |
| 244 trackInfo.filler1 = 0; |
| 245 |
| 246 OwnPtr<ImageBuffer> imageBuffer = ImageBuffer::create(inflatedRect.size()); |
| 247 if (!imageBuffer) |
| 248 return true; |
| 249 |
| 250 LocalCurrentGraphicsContext localContext(imageBuffer->context(), IntRect(Int
Point(), inflatedRect.size())); |
| 251 CGContextRef cgContext = localContext.cgContext(); |
| 252 HIThemeDrawTrack(&trackInfo, 0, cgContext, kHIThemeOrientationNormal); |
| 253 |
| 254 GraphicsContextStateSaver stateSaver(*paintInfo.context); |
| 255 |
| 256 if (!layoutProgress->style()->isLeftToRightDirection()) { |
| 257 paintInfo.context->translate(2 * inflatedRect.x() + inflatedRect.width()
, 0); |
| 258 paintInfo.context->scale(-1, 1); |
| 259 } |
| 260 |
| 261 paintInfo.context->drawImageBuffer(imageBuffer.get(), |
| 262 FloatRect(inflatedRect.location(), imageBuffer->size())); |
| 263 return false; |
| 264 } |
| 265 |
| 266 bool ThemePainterMac::paintMenuListButton(LayoutObject* o, const PaintInfo& pain
tInfo, const IntRect& r) |
| 267 { |
| 268 IntRect bounds = IntRect(r.x() + o->style()->borderLeftWidth(), |
| 269 r.y() + o->style()->borderTopWidth(), |
| 270 r.width() - o->style()->borderLeftWidth() - o->styl
e()->borderRightWidth(), |
| 271 r.height() - o->style()->borderTopWidth() - o->styl
e()->borderBottomWidth()); |
| 272 // Since we actually know the size of the control here, we restrict the font |
| 273 // scale to make sure the arrows will fit vertically in the bounds |
| 274 float fontScale = std::min(o->style()->fontSize() / LayoutThemeMac::baseFont
Size, |
| 275 bounds.height() / (LayoutThemeMac::menuListBaseArrowHeight * 2 + LayoutT
hemeMac::menuListBaseSpaceBetweenArrows)); |
| 276 float centerY = bounds.y() + bounds.height() / 2.0f; |
| 277 float arrowHeight = LayoutThemeMac::menuListBaseArrowHeight * fontScale; |
| 278 float arrowWidth = LayoutThemeMac::menuListBaseArrowWidth * fontScale; |
| 279 float leftEdge = bounds.maxX() - LayoutThemeMac::menuListArrowPaddingRight *
o->style()->effectiveZoom() - arrowWidth; |
| 280 float spaceBetweenArrows = LayoutThemeMac::menuListBaseSpaceBetweenArrows *
fontScale; |
| 281 |
| 282 if (bounds.width() < arrowWidth + LayoutThemeMac::menuListArrowPaddingLeft *
o->style()->effectiveZoom()) |
| 283 return false; |
| 284 |
| 285 Color color = o->style()->visitedDependentColor(CSSPropertyColor); |
| 286 |
| 287 FloatPoint arrow1[3]; |
| 288 arrow1[0] = FloatPoint(leftEdge, centerY - spaceBetweenArrows / 2.0f); |
| 289 arrow1[1] = FloatPoint(leftEdge + arrowWidth, centerY - spaceBetweenArrows /
2.0f); |
| 290 arrow1[2] = FloatPoint(leftEdge + arrowWidth / 2.0f, centerY - spaceBetweenA
rrows / 2.0f - arrowHeight); |
| 291 |
| 292 // Draw the top arrow. |
| 293 paintInfo.context->fillPolygon(3, arrow1, color, true); |
| 294 |
| 295 FloatPoint arrow2[3]; |
| 296 arrow2[0] = FloatPoint(leftEdge, centerY + spaceBetweenArrows / 2.0f); |
| 297 arrow2[1] = FloatPoint(leftEdge + arrowWidth, centerY + spaceBetweenArrows /
2.0f); |
| 298 arrow2[2] = FloatPoint(leftEdge + arrowWidth / 2.0f, centerY + spaceBetweenA
rrows / 2.0f + arrowHeight); |
| 299 |
| 300 // Draw the bottom arrow. |
| 301 paintInfo.context->fillPolygon(3, arrow2, color, true); |
| 302 return false; |
| 303 } |
| 304 |
| 305 bool ThemePainterMac::paintSliderTrack(LayoutObject* o, const PaintInfo& paintIn
fo, const IntRect& r) |
| 306 { |
| 307 paintSliderTicks(o, paintInfo, r); |
| 308 |
| 309 float zoomLevel = o->style()->effectiveZoom(); |
| 310 FloatRect unzoomedRect = r; |
| 311 |
| 312 if (o->style()->appearance() == SliderHorizontalPart || o->style()->appeara
nce() == MediaSliderPart) { |
| 313 unzoomedRect.setY(ceilf(unzoomedRect.y() + unzoomedRect.height() / 2 - z
oomLevel * LayoutThemeMac::sliderTrackWidth / 2)); |
| 314 unzoomedRect.setHeight(zoomLevel * LayoutThemeMac::sliderTrackWidth); |
| 315 } else if (o->style()->appearance() == SliderVerticalPart) { |
| 316 unzoomedRect.setX(ceilf(unzoomedRect.x() + unzoomedRect.width() / 2 - zo
omLevel * LayoutThemeMac::sliderTrackWidth / 2)); |
| 317 unzoomedRect.setWidth(zoomLevel * LayoutThemeMac::sliderTrackWidth); |
| 318 } |
| 319 |
| 320 if (zoomLevel != 1) { |
| 321 unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel); |
| 322 unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel); |
| 323 } |
| 324 |
| 325 GraphicsContextStateSaver stateSaver(*paintInfo.context); |
| 326 if (zoomLevel != 1) { |
| 327 paintInfo.context->translate(unzoomedRect.x(), unzoomedRect.y()); |
| 328 paintInfo.context->scale(zoomLevel, zoomLevel); |
| 329 paintInfo.context->translate(-unzoomedRect.x(), -unzoomedRect.y()); |
| 330 } |
| 331 |
| 332 Color fillColor(205, 205, 205); |
| 333 Color borderGradientTopColor(109, 109, 109); |
| 334 Color borderGradientBottomColor(181, 181, 181); |
| 335 Color shadowColor(0, 0, 0, 118); |
| 336 |
| 337 if (!LayoutTheme::isEnabled(o)) { |
| 338 Color tintColor(255, 255, 255, 128); |
| 339 fillColor = fillColor.blend(tintColor); |
| 340 borderGradientTopColor = borderGradientTopColor.blend(tintColor); |
| 341 borderGradientBottomColor = borderGradientBottomColor.blend(tintColor); |
| 342 shadowColor = shadowColor.blend(tintColor); |
| 343 } |
| 344 |
| 345 Color tintColor; |
| 346 if (!LayoutTheme::isEnabled(o)) |
| 347 tintColor = Color(255, 255, 255, 128); |
| 348 |
| 349 bool isVerticalSlider = o->style()->appearance() == SliderVerticalPart; |
| 350 |
| 351 int fillRadiusSize = (LayoutThemeMac::sliderTrackWidth - LayoutThemeMac::sli
derTrackBorderWidth) / 2; |
| 352 IntSize fillRadius(fillRadiusSize, fillRadiusSize); |
| 353 IntRect fillBounds = enclosedIntRect(unzoomedRect); |
| 354 FloatRoundedRect fillRect(fillBounds, fillRadius, fillRadius, fillRadius, fi
llRadius); |
| 355 paintInfo.context->fillRoundedRect(fillRect, fillColor); |
| 356 |
| 357 IntSize shadowOffset(isVerticalSlider ? 1 : 0, |
| 358 isVerticalSlider ? 0 : 1); |
| 359 int shadowBlur = 3; |
| 360 int shadowSpread = 0; |
| 361 paintInfo.context->save(); |
| 362 paintInfo.context->drawInnerShadow(fillRect, shadowColor, shadowOffset, shad
owBlur, shadowSpread); |
| 363 paintInfo.context->restore(); |
| 364 |
| 365 RefPtr<Gradient> borderGradient = Gradient::create(fillBounds.minXMinYCorner
(), |
| 366 isVerticalSlider ? fillBounds.maxXMinYCorner() : fillBounds.minXMaxYCorn
er()); |
| 367 borderGradient->addColorStop(0.0, borderGradientTopColor); |
| 368 borderGradient->addColorStop(1.0, borderGradientBottomColor); |
| 369 Path borderPath; |
| 370 FloatRect borderRect(unzoomedRect); |
| 371 borderRect.inflate(-LayoutThemeMac::sliderTrackBorderWidth / 2.0); |
| 372 float borderRadiusSize = (isVerticalSlider ? borderRect.width() : borderRect
.height()) / 2; |
| 373 FloatSize borderRadius(borderRadiusSize, borderRadiusSize); |
| 374 borderPath.addRoundedRect(borderRect, borderRadius, borderRadius, borderRadi
us, borderRadius); |
| 375 paintInfo.context->setStrokeGradient(borderGradient); |
| 376 paintInfo.context->setStrokeThickness(LayoutThemeMac::sliderTrackBorderWidth
); |
| 377 paintInfo.context->strokePath(borderPath); |
| 378 return false; |
| 379 } |
| 380 |
| 381 |
| 382 bool ThemePainterMac::paintSliderThumb(LayoutObject* o, const PaintInfo& paintIn
fo, const IntRect& r) |
| 383 { |
| 384 GraphicsContextStateSaver stateSaver(*paintInfo.context); |
| 385 float zoomLevel = o->style()->effectiveZoom(); |
| 386 |
| 387 FloatRect unzoomedRect(r.x(), r.y(), LayoutThemeMac::sliderThumbWidth, Layou
tThemeMac::sliderThumbHeight); |
| 388 if (zoomLevel != 1.0f) { |
| 389 paintInfo.context->translate(unzoomedRect.x(), unzoomedRect.y()); |
| 390 paintInfo.context->scale(zoomLevel, zoomLevel); |
| 391 paintInfo.context->translate(-unzoomedRect.x(), -unzoomedRect.y()); |
| 392 } |
| 393 |
| 394 Color fillGradientTopColor(250, 250, 250); |
| 395 Color fillGradientUpperMiddleColor(244, 244, 244); |
| 396 Color fillGradientLowerMiddleColor(236, 236, 236); |
| 397 Color fillGradientBottomColor(238, 238, 238); |
| 398 Color borderGradientTopColor(151, 151, 151); |
| 399 Color borderGradientBottomColor(128, 128, 128); |
| 400 Color shadowColor(0, 0, 0, 36); |
| 401 |
| 402 if (!LayoutTheme::isEnabled(o)) { |
| 403 Color tintColor(255, 255, 255, 128); |
| 404 fillGradientTopColor = fillGradientTopColor.blend(tintColor); |
| 405 fillGradientUpperMiddleColor = fillGradientUpperMiddleColor.blend(tintCo
lor); |
| 406 fillGradientLowerMiddleColor = fillGradientLowerMiddleColor.blend(tintCo
lor); |
| 407 fillGradientBottomColor = fillGradientBottomColor.blend(tintColor); |
| 408 borderGradientTopColor = borderGradientTopColor.blend(tintColor); |
| 409 borderGradientBottomColor = borderGradientBottomColor.blend(tintColor); |
| 410 shadowColor = shadowColor.blend(tintColor); |
| 411 } else if (LayoutTheme::isPressed(o)) { |
| 412 Color tintColor(0, 0, 0, 32); |
| 413 fillGradientTopColor = fillGradientTopColor.blend(tintColor); |
| 414 fillGradientUpperMiddleColor = fillGradientUpperMiddleColor.blend(tintCo
lor); |
| 415 fillGradientLowerMiddleColor = fillGradientLowerMiddleColor.blend(tintCo
lor); |
| 416 fillGradientBottomColor = fillGradientBottomColor.blend(tintColor); |
| 417 borderGradientTopColor = borderGradientTopColor.blend(tintColor); |
| 418 borderGradientBottomColor = borderGradientBottomColor.blend(tintColor); |
| 419 shadowColor = shadowColor.blend(tintColor); |
| 420 } |
| 421 |
| 422 FloatRect borderBounds = unzoomedRect; |
| 423 borderBounds.inflate(LayoutThemeMac::sliderThumbBorderWidth / 2.0); |
| 424 |
| 425 borderBounds.inflate(-LayoutThemeMac::sliderThumbBorderWidth); |
| 426 FloatSize shadowOffset(0, 1); |
| 427 paintInfo.context->setShadow(shadowOffset, LayoutThemeMac::sliderThumbShadow
Blur, shadowColor); |
| 428 paintInfo.context->setFillColor(Color::black); |
| 429 paintInfo.context->fillEllipse(borderBounds); |
| 430 paintInfo.context->clearShadow(); |
| 431 |
| 432 IntRect fillBounds = enclosedIntRect(unzoomedRect); |
| 433 RefPtr<Gradient> fillGradient = Gradient::create(fillBounds.minXMinYCorner()
, fillBounds.minXMaxYCorner()); |
| 434 fillGradient->addColorStop(0.0, fillGradientTopColor); |
| 435 fillGradient->addColorStop(0.52, fillGradientUpperMiddleColor); |
| 436 fillGradient->addColorStop(0.52, fillGradientLowerMiddleColor); |
| 437 fillGradient->addColorStop(1.0, fillGradientBottomColor); |
| 438 paintInfo.context->setFillGradient(fillGradient); |
| 439 paintInfo.context->fillEllipse(borderBounds); |
| 440 |
| 441 RefPtr<Gradient> borderGradient = Gradient::create(fillBounds.minXMinYCorner
(), fillBounds.minXMaxYCorner()); |
| 442 borderGradient->addColorStop(0.0, borderGradientTopColor); |
| 443 borderGradient->addColorStop(1.0, borderGradientBottomColor); |
| 444 paintInfo.context->setStrokeGradient(borderGradient); |
| 445 paintInfo.context->setStrokeThickness(LayoutThemeMac::sliderThumbBorderWidth
); |
| 446 paintInfo.context->strokeEllipse(borderBounds); |
| 447 |
| 448 if (LayoutTheme::isFocused(o)) { |
| 449 Path borderPath; |
| 450 borderPath.addEllipse(borderBounds); |
| 451 paintInfo.context->drawFocusRing(borderPath, 5, -2, m_layoutTheme.focusR
ingColor()); |
| 452 } |
| 453 |
| 454 return false; |
| 455 } |
| 456 |
| 457 // We don't use controlSizeForFont() for search field decorations because it |
| 458 // needs to fit into the search field. The font size will already be modified by |
| 459 // setFontFromControlSize() called on the search field. |
| 460 static NSControlSize searchFieldControlSizeForFont(const ComputedStyle& style) |
| 461 { |
| 462 int fontSize = style.fontSize(); |
| 463 if (fontSize >= 13) |
| 464 return NSRegularControlSize; |
| 465 if (fontSize >= 11) |
| 466 return NSSmallControlSize; |
| 467 return NSMiniControlSize; |
| 468 } |
| 469 |
| 470 bool ThemePainterMac::paintSearchField(LayoutObject* o, const PaintInfo& paintIn
fo, const IntRect& r) |
| 471 { |
| 472 LocalCurrentGraphicsContext localContext(paintInfo.context, r); |
| 473 |
| 474 NSSearchFieldCell* search = m_layoutTheme.search(); |
| 475 m_layoutTheme.setSearchCellState(o, r); |
| 476 [search setControlSize:searchFieldControlSizeForFont(o->styleRef())]; |
| 477 |
| 478 GraphicsContextStateSaver stateSaver(*paintInfo.context); |
| 479 |
| 480 float zoomLevel = o->style()->effectiveZoom(); |
| 481 |
| 482 IntRect unzoomedRect = r; |
| 483 |
| 484 if (zoomLevel != 1.0f) { |
| 485 unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel); |
| 486 unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel); |
| 487 paintInfo.context->translate(unzoomedRect.x(), unzoomedRect.y()); |
| 488 paintInfo.context->scale(zoomLevel, zoomLevel); |
| 489 paintInfo.context->translate(-unzoomedRect.x(), -unzoomedRect.y()); |
| 490 } |
| 491 |
| 492 // Set the search button to nil before drawing. Then reset it so we can |
| 493 // draw it later. |
| 494 [search setSearchButtonCell:nil]; |
| 495 |
| 496 [search drawWithFrame:NSRect(unzoomedRect) inView:m_layoutTheme.documentView
For(o)]; |
| 497 |
| 498 [search setControlView:nil]; |
| 499 [search resetSearchButtonCell]; |
| 500 |
| 501 return false; |
| 502 } |
| 503 |
| 504 bool ThemePainterMac::paintSearchFieldCancelButton(LayoutObject* o, const PaintI
nfo& paintInfo, const IntRect& r) |
| 505 { |
| 506 if (!o->node()) |
| 507 return false; |
| 508 Element* input = o->node()->shadowHost(); |
| 509 if (!input) |
| 510 input = toElement(o->node()); |
| 511 |
| 512 if (!input->layoutObject()->isBox()) |
| 513 return false; |
| 514 |
| 515 GraphicsContextStateSaver stateSaver(*paintInfo.context); |
| 516 |
| 517 float zoomLevel = o->style()->effectiveZoom(); |
| 518 FloatRect unzoomedRect(r); |
| 519 if (zoomLevel != 1.0f) { |
| 520 unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel); |
| 521 unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel); |
| 522 paintInfo.context->translate(unzoomedRect.x(), unzoomedRect.y()); |
| 523 paintInfo.context->scale(zoomLevel, zoomLevel); |
| 524 paintInfo.context->translate(-unzoomedRect.x(), -unzoomedRect.y()); |
| 525 } |
| 526 |
| 527 Color fillColor(200, 200, 200); |
| 528 |
| 529 if (LayoutTheme::isPressed(o)) { |
| 530 Color tintColor(0, 0, 0, 32); |
| 531 fillColor = fillColor.blend(tintColor); |
| 532 } |
| 533 |
| 534 float centerX = unzoomedRect.x() + unzoomedRect.width() / 2; |
| 535 float centerY = unzoomedRect.y() + unzoomedRect.height() / 2; |
| 536 // The line width is 3px on a regular sized, high DPI NSCancelButtonCell |
| 537 // (which is 28px wide). |
| 538 float lineWidth = unzoomedRect.width() * 3 / 28; |
| 539 // The line length is 16px on a regular sized, high DPI NSCancelButtonCell. |
| 540 float lineLength = unzoomedRect.width() * 16 / 28; |
| 541 |
| 542 Path xPath; |
| 543 FloatSize lineRectRadius(lineWidth / 2, lineWidth / 2); |
| 544 xPath.addRoundedRect(FloatRect(-lineLength / 2, -lineWidth / 2, lineLength,
lineWidth), |
| 545 lineRectRadius, lineRectRadius, lineRectRadius, lineRectRadius); |
| 546 xPath.addRoundedRect(FloatRect(-lineWidth / 2, -lineLength / 2, lineWidth, l
ineLength), |
| 547 lineRectRadius, lineRectRadius, lineRectRadius, lineRectRadius); |
| 548 |
| 549 paintInfo.context->translate(centerX, centerY); |
| 550 paintInfo.context->rotate(deg2rad(45.0)); |
| 551 paintInfo.context->clipOut(xPath); |
| 552 paintInfo.context->rotate(deg2rad(-45.0)); |
| 553 paintInfo.context->translate(-centerX, -centerY); |
| 554 |
| 555 paintInfo.context->setFillColor(fillColor); |
| 556 paintInfo.context->fillEllipse(unzoomedRect); |
| 557 |
| 558 return false; |
| 559 } |
| 560 |
| 561 bool ThemePainterMac::paintSearchFieldDecoration(LayoutObject*, const PaintInfo&
, const IntRect&) |
| 562 { |
| 563 return false; |
| 564 } |
| 565 |
| 566 bool ThemePainterMac::paintSearchFieldResultsDecoration(LayoutObject* o, const P
aintInfo& paintInfo, const IntRect& r) |
| 567 { |
| 568 if (!o->node()) |
| 569 return false; |
| 570 Node* input = o->node()->shadowHost(); |
| 571 if (!input) |
| 572 input = o->node(); |
| 573 if (!input->layoutObject()->isBox()) |
| 574 return false; |
| 575 |
| 576 GraphicsContextStateSaver stateSaver(*paintInfo.context); |
| 577 |
| 578 float zoomLevel = o->style()->effectiveZoom(); |
| 579 FloatRect unzoomedRect(r); |
| 580 if (zoomLevel != 1) { |
| 581 unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel); |
| 582 unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel); |
| 583 paintInfo.context->translate(unzoomedRect.x(), unzoomedRect.y()); |
| 584 paintInfo.context->scale(zoomLevel, zoomLevel); |
| 585 paintInfo.context->translate(-unzoomedRect.x(), -unzoomedRect.y()); |
| 586 } |
| 587 |
| 588 LocalCurrentGraphicsContext localContext(paintInfo.context, r); |
| 589 |
| 590 NSSearchFieldCell* search = m_layoutTheme.search(); |
| 591 m_layoutTheme.setSearchCellState(input->layoutObject(), r); |
| 592 [search setControlSize:searchFieldControlSizeForFont(o->styleRef())]; |
| 593 if ([search searchMenuTemplate] != nil) |
| 594 [search setSearchMenuTemplate:nil]; |
| 595 |
| 596 m_layoutTheme.updateActiveState([search searchButtonCell], o); |
| 597 |
| 598 [[search searchButtonCell] drawWithFrame:unzoomedRect inView:m_layoutTheme.d
ocumentViewFor(o)]; |
| 599 [[search searchButtonCell] setControlView:nil]; |
| 600 return false; |
| 601 } |
| 602 |
| 603 bool ThemePainterMac::paintMediaPlayButton(LayoutObject* object, const PaintInfo
& paintInfo, const IntRect& rect) |
| 604 { |
| 605 return MediaControlsPainter::paintMediaControlsPart(MediaPlayButton, object,
paintInfo, rect); |
| 606 } |
| 607 |
| 608 bool ThemePainterMac::paintMediaOverlayPlayButton(LayoutObject* object, const Pa
intInfo& paintInfo, const IntRect& rect) |
| 609 { |
| 610 return MediaControlsPainter::paintMediaControlsPart(MediaOverlayPlayButton,
object, paintInfo, rect); |
| 611 } |
| 612 |
| 613 bool ThemePainterMac::paintMediaMuteButton(LayoutObject* object, const PaintInfo
& paintInfo, const IntRect& rect) |
| 614 { |
| 615 return MediaControlsPainter::paintMediaControlsPart(MediaMuteButton, object,
paintInfo, rect); |
| 616 } |
| 617 |
| 618 bool ThemePainterMac::paintMediaSliderTrack(LayoutObject* object, const PaintInf
o& paintInfo, const IntRect& rect) |
| 619 { |
| 620 return MediaControlsPainter::paintMediaControlsPart(MediaSlider, object, pai
ntInfo, rect); |
| 621 } |
| 622 |
| 623 bool ThemePainterMac::paintMediaVolumeSliderContainer(LayoutObject* object, cons
t PaintInfo& paintInfo, const IntRect& rect) |
| 624 { |
| 625 return true; |
| 626 } |
| 627 |
| 628 bool ThemePainterMac::paintMediaVolumeSliderTrack(LayoutObject* object, const Pa
intInfo& paintInfo, const IntRect& rect) |
| 629 { |
| 630 return MediaControlsPainter::paintMediaControlsPart(MediaVolumeSlider, objec
t, paintInfo, rect); |
| 631 } |
| 632 |
| 633 bool ThemePainterMac::paintMediaVolumeSliderThumb(LayoutObject* object, const Pa
intInfo& paintInfo, const IntRect& rect) |
| 634 { |
| 635 return MediaControlsPainter::paintMediaControlsPart(MediaVolumeSliderThumb,
object, paintInfo, rect); |
| 636 } |
| 637 |
| 638 bool ThemePainterMac::paintMediaSliderThumb(LayoutObject* object, const PaintInf
o& paintInfo, const IntRect& rect) |
| 639 { |
| 640 return MediaControlsPainter::paintMediaControlsPart(MediaSliderThumb, object
, paintInfo, rect); |
| 641 } |
| 642 |
| 643 bool ThemePainterMac::paintMediaFullscreenButton(LayoutObject* object, const Pai
ntInfo& paintInfo, const IntRect& rect) |
| 644 { |
| 645 return MediaControlsPainter::paintMediaControlsPart(MediaEnterFullscreenButt
on, object, paintInfo, rect); |
| 646 } |
| 647 |
| 648 bool ThemePainterMac::paintMediaToggleClosedCaptionsButton(LayoutObject* object,
const PaintInfo& paintInfo, const IntRect& rect) |
| 649 { |
| 650 return MediaControlsPainter::paintMediaControlsPart(MediaShowClosedCaptionsB
utton, object, paintInfo, rect); |
| 651 } |
| 652 |
| 653 } // namespace blink |
| OLD | NEW |