Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(434)

Side by Side Diff: third_party/WebKit/Source/core/paint/ThemePainterMac.mm

Issue 1512803004: Use refs for GraphicsContext (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ScrollbarTheme
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2008, 2009 Google, Inc. 3 * Copyright (C) 2008, 2009 Google, Inc.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 // background. We need WebCore to paint styled backgrounds, so we'll use 66 // background. We need WebCore to paint styled backgrounds, so we'll use
67 // this AppKit SPI function instead. 67 // this AppKit SPI function instead.
68 if (!useNSTextFieldCell) { 68 if (!useNSTextFieldCell) {
69 _NSDrawCarbonThemeBezel(r, LayoutTheme::isEnabled(o) && !LayoutTheme::is ReadOnlyControl(o), YES); 69 _NSDrawCarbonThemeBezel(r, LayoutTheme::isEnabled(o) && !LayoutTheme::is ReadOnlyControl(o), YES);
70 return false; 70 return false;
71 } 71 }
72 #endif 72 #endif
73 73
74 NSTextFieldCell *textField = m_layoutTheme.textField(); 74 NSTextFieldCell *textField = m_layoutTheme.textField();
75 75
76 GraphicsContextStateSaver stateSaver(*paintInfo.context); 76 GraphicsContextStateSaver stateSaver(paintInfo.context);
77 77
78 [textField setEnabled:(LayoutTheme::isEnabled(o) && !LayoutTheme::isReadOnly Control(o))]; 78 [textField setEnabled:(LayoutTheme::isEnabled(o) && !LayoutTheme::isReadOnly Control(o))];
79 [textField drawWithFrame:NSRect(r) inView:m_layoutTheme.documentViewFor(o)]; 79 [textField drawWithFrame:NSRect(r) inView:m_layoutTheme.documentViewFor(o)];
80 80
81 [textField setControlView:nil]; 81 [textField setControlView:nil];
82 82
83 return false; 83 return false;
84 } 84 }
85 85
86 bool ThemePainterMac::paintCapsLockIndicator(const LayoutObject&, const PaintInf o& paintInfo, const IntRect& r) 86 bool ThemePainterMac::paintCapsLockIndicator(const LayoutObject&, const PaintInf o& paintInfo, const IntRect& r)
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 // Now inflate it to account for the shadow. 165 // Now inflate it to account for the shadow.
166 IntRect inflatedRect = r; 166 IntRect inflatedRect = r;
167 if (r.width() >= m_layoutTheme.minimumMenuListSize(o.styleRef())) 167 if (r.width() >= m_layoutTheme.minimumMenuListSize(o.styleRef()))
168 inflatedRect = ThemeMac::inflateRect(inflatedRect, size, m_layoutTheme.p opupButtonMargins(), zoomLevel); 168 inflatedRect = ThemeMac::inflateRect(inflatedRect, size, m_layoutTheme.p opupButtonMargins(), zoomLevel);
169 169
170 LocalCurrentGraphicsContext localContext(paintInfo.context, &paintInfo.cullR ect().m_rect, ThemeMac::inflateRectForFocusRing(inflatedRect)); 170 LocalCurrentGraphicsContext localContext(paintInfo.context, &paintInfo.cullR ect().m_rect, ThemeMac::inflateRectForFocusRing(inflatedRect));
171 171
172 if (zoomLevel != 1.0f) { 172 if (zoomLevel != 1.0f) {
173 inflatedRect.setWidth(inflatedRect.width() / zoomLevel); 173 inflatedRect.setWidth(inflatedRect.width() / zoomLevel);
174 inflatedRect.setHeight(inflatedRect.height() / zoomLevel); 174 inflatedRect.setHeight(inflatedRect.height() / zoomLevel);
175 paintInfo.context->translate(inflatedRect.x(), inflatedRect.y()); 175 paintInfo.context.translate(inflatedRect.x(), inflatedRect.y());
176 paintInfo.context->scale(zoomLevel, zoomLevel); 176 paintInfo.context.scale(zoomLevel, zoomLevel);
177 paintInfo.context->translate(-inflatedRect.x(), -inflatedRect.y()); 177 paintInfo.context.translate(-inflatedRect.x(), -inflatedRect.y());
178 } 178 }
179 179
180 NSView *view = m_layoutTheme.documentViewFor(o); 180 NSView *view = m_layoutTheme.documentViewFor(o);
181 [popupButton drawWithFrame:inflatedRect inView:view]; 181 [popupButton drawWithFrame:inflatedRect inView:view];
182 if (!ThemeMac::drawWithFrameDrawsFocusRing() && LayoutTheme::isFocused(o) && o.styleRef().outlineStyleIsAuto()) 182 if (!ThemeMac::drawWithFrameDrawsFocusRing() && LayoutTheme::isFocused(o) && o.styleRef().outlineStyleIsAuto())
183 [popupButton cr_drawFocusRingWithFrame:inflatedRect inView:view]; 183 [popupButton cr_drawFocusRingWithFrame:inflatedRect inView:view];
184 [popupButton setControlView:nil]; 184 [popupButton setControlView:nil];
185 185
186 return false; 186 return false;
187 } 187 }
188 188
189 bool ThemePainterMac::paintMeter(const LayoutObject& layoutObject, const PaintIn fo& paintInfo, const IntRect& rect) 189 bool ThemePainterMac::paintMeter(const LayoutObject& layoutObject, const PaintIn fo& paintInfo, const IntRect& rect)
190 { 190 {
191 if (!layoutObject.isMeter()) 191 if (!layoutObject.isMeter())
192 return true; 192 return true;
193 193
194 LocalCurrentGraphicsContext localContext(paintInfo.context, &paintInfo.cullR ect().m_rect, rect); 194 LocalCurrentGraphicsContext localContext(paintInfo.context, &paintInfo.cullR ect().m_rect, rect);
195 195
196 NSLevelIndicatorCell* cell = m_layoutTheme.levelIndicatorFor(toLayoutMeter(l ayoutObject)); 196 NSLevelIndicatorCell* cell = m_layoutTheme.levelIndicatorFor(toLayoutMeter(l ayoutObject));
197 GraphicsContextStateSaver stateSaver(*paintInfo.context); 197 GraphicsContextStateSaver stateSaver(paintInfo.context);
198 198
199 [cell drawWithFrame:rect inView:m_layoutTheme.documentViewFor(layoutObject)] ; 199 [cell drawWithFrame:rect inView:m_layoutTheme.documentViewFor(layoutObject)] ;
200 [cell setControlView:nil]; 200 [cell setControlView:nil];
201 return false; 201 return false;
202 } 202 }
203 203
204 bool ThemePainterMac::paintProgressBar(const LayoutObject& layoutObject, const P aintInfo& paintInfo, const IntRect& rect) 204 bool ThemePainterMac::paintProgressBar(const LayoutObject& layoutObject, const P aintInfo& paintInfo, const IntRect& rect)
205 { 205 {
206 if (!layoutObject.isProgress()) 206 if (!layoutObject.isProgress())
207 return true; 207 return true;
(...skipping 29 matching lines...) Expand all
237 237
238 OwnPtr<ImageBuffer> imageBuffer = ImageBuffer::create(inflatedRect.size()); 238 OwnPtr<ImageBuffer> imageBuffer = ImageBuffer::create(inflatedRect.size());
239 if (!imageBuffer) 239 if (!imageBuffer)
240 return true; 240 return true;
241 241
242 IntRect clipRect = IntRect(IntPoint(), inflatedRect.size()); 242 IntRect clipRect = IntRect(IntPoint(), inflatedRect.size());
243 LocalCurrentGraphicsContext localContext(imageBuffer->canvas(), 1, &clipRect , clipRect); 243 LocalCurrentGraphicsContext localContext(imageBuffer->canvas(), 1, &clipRect , clipRect);
244 CGContextRef cgContext = localContext.cgContext(); 244 CGContextRef cgContext = localContext.cgContext();
245 HIThemeDrawTrack(&trackInfo, 0, cgContext, kHIThemeOrientationNormal); 245 HIThemeDrawTrack(&trackInfo, 0, cgContext, kHIThemeOrientationNormal);
246 246
247 GraphicsContextStateSaver stateSaver(*paintInfo.context); 247 GraphicsContextStateSaver stateSaver(paintInfo.context);
248 248
249 if (!layoutProgress.styleRef().isLeftToRightDirection()) { 249 if (!layoutProgress.styleRef().isLeftToRightDirection()) {
250 paintInfo.context->translate(2 * inflatedRect.x() + inflatedRect.width() , 0); 250 paintInfo.context.translate(2 * inflatedRect.x() + inflatedRect.width(), 0);
251 paintInfo.context->scale(-1, 1); 251 paintInfo.context.scale(-1, 1);
252 } 252 }
253 253
254 if (!paintInfo.context->contextDisabled()) 254 if (!paintInfo.context.contextDisabled())
255 imageBuffer->draw(paintInfo.context, FloatRect(inflatedRect.location(), FloatSize(imageBuffer->size())), nullptr, SkXfermode::kSrcOver_Mode); 255 imageBuffer->draw(paintInfo.context, FloatRect(inflatedRect.location(), FloatSize(imageBuffer->size())), nullptr, SkXfermode::kSrcOver_Mode);
256 return false; 256 return false;
257 } 257 }
258 258
259 bool ThemePainterMac::paintMenuListButton(const LayoutObject& o, const PaintInfo & paintInfo, const IntRect& r) 259 bool ThemePainterMac::paintMenuListButton(const LayoutObject& o, const PaintInfo & paintInfo, const IntRect& r)
260 { 260 {
261 IntRect bounds = IntRect(r.x() + o.styleRef().borderLeftWidth(), 261 IntRect bounds = IntRect(r.x() + o.styleRef().borderLeftWidth(),
262 r.y() + o.styleRef().borderTopWidth(), 262 r.y() + o.styleRef().borderTopWidth(),
263 r.width() - o.styleRef().borderLeftWidth() - o.styl eRef().borderRightWidth(), 263 r.width() - o.styleRef().borderLeftWidth() - o.styl eRef().borderRightWidth(),
264 r.height() - o.styleRef().borderTopWidth() - o.styl eRef().borderBottomWidth()); 264 r.height() - o.styleRef().borderTopWidth() - o.styl eRef().borderBottomWidth());
(...skipping 11 matching lines...) Expand all
276 return false; 276 return false;
277 277
278 Color color = o.styleRef().visitedDependentColor(CSSPropertyColor); 278 Color color = o.styleRef().visitedDependentColor(CSSPropertyColor);
279 279
280 FloatPoint arrow1[3]; 280 FloatPoint arrow1[3];
281 arrow1[0] = FloatPoint(leftEdge, centerY - spaceBetweenArrows / 2.0f); 281 arrow1[0] = FloatPoint(leftEdge, centerY - spaceBetweenArrows / 2.0f);
282 arrow1[1] = FloatPoint(leftEdge + arrowWidth, centerY - spaceBetweenArrows / 2.0f); 282 arrow1[1] = FloatPoint(leftEdge + arrowWidth, centerY - spaceBetweenArrows / 2.0f);
283 arrow1[2] = FloatPoint(leftEdge + arrowWidth / 2.0f, centerY - spaceBetweenA rrows / 2.0f - arrowHeight); 283 arrow1[2] = FloatPoint(leftEdge + arrowWidth / 2.0f, centerY - spaceBetweenA rrows / 2.0f - arrowHeight);
284 284
285 // Draw the top arrow. 285 // Draw the top arrow.
286 paintInfo.context->fillPolygon(3, arrow1, color, true); 286 paintInfo.context.fillPolygon(3, arrow1, color, true);
287 287
288 FloatPoint arrow2[3]; 288 FloatPoint arrow2[3];
289 arrow2[0] = FloatPoint(leftEdge, centerY + spaceBetweenArrows / 2.0f); 289 arrow2[0] = FloatPoint(leftEdge, centerY + spaceBetweenArrows / 2.0f);
290 arrow2[1] = FloatPoint(leftEdge + arrowWidth, centerY + spaceBetweenArrows / 2.0f); 290 arrow2[1] = FloatPoint(leftEdge + arrowWidth, centerY + spaceBetweenArrows / 2.0f);
291 arrow2[2] = FloatPoint(leftEdge + arrowWidth / 2.0f, centerY + spaceBetweenA rrows / 2.0f + arrowHeight); 291 arrow2[2] = FloatPoint(leftEdge + arrowWidth / 2.0f, centerY + spaceBetweenA rrows / 2.0f + arrowHeight);
292 292
293 // Draw the bottom arrow. 293 // Draw the bottom arrow.
294 paintInfo.context->fillPolygon(3, arrow2, color, true); 294 paintInfo.context.fillPolygon(3, arrow2, color, true);
295 return false; 295 return false;
296 } 296 }
297 297
298 bool ThemePainterMac::paintSliderTrack(const LayoutObject& o, const PaintInfo& p aintInfo, const IntRect& r) 298 bool ThemePainterMac::paintSliderTrack(const LayoutObject& o, const PaintInfo& p aintInfo, const IntRect& r)
299 { 299 {
300 paintSliderTicks(o, paintInfo, r); 300 paintSliderTicks(o, paintInfo, r);
301 301
302 float zoomLevel = o.styleRef().effectiveZoom(); 302 float zoomLevel = o.styleRef().effectiveZoom();
303 FloatRect unzoomedRect = r; 303 FloatRect unzoomedRect = r;
304 304
305 if (o.styleRef().appearance() == SliderHorizontalPart || o.styleRef().appea rance() == MediaSliderPart) { 305 if (o.styleRef().appearance() == SliderHorizontalPart || o.styleRef().appea rance() == MediaSliderPart) {
306 unzoomedRect.setY(ceilf(unzoomedRect.y() + unzoomedRect.height() / 2 - z oomLevel * LayoutThemeMac::sliderTrackWidth / 2)); 306 unzoomedRect.setY(ceilf(unzoomedRect.y() + unzoomedRect.height() / 2 - z oomLevel * LayoutThemeMac::sliderTrackWidth / 2));
307 unzoomedRect.setHeight(zoomLevel * LayoutThemeMac::sliderTrackWidth); 307 unzoomedRect.setHeight(zoomLevel * LayoutThemeMac::sliderTrackWidth);
308 } else if (o.styleRef().appearance() == SliderVerticalPart) { 308 } else if (o.styleRef().appearance() == SliderVerticalPart) {
309 unzoomedRect.setX(ceilf(unzoomedRect.x() + unzoomedRect.width() / 2 - zo omLevel * LayoutThemeMac::sliderTrackWidth / 2)); 309 unzoomedRect.setX(ceilf(unzoomedRect.x() + unzoomedRect.width() / 2 - zo omLevel * LayoutThemeMac::sliderTrackWidth / 2));
310 unzoomedRect.setWidth(zoomLevel * LayoutThemeMac::sliderTrackWidth); 310 unzoomedRect.setWidth(zoomLevel * LayoutThemeMac::sliderTrackWidth);
311 } 311 }
312 312
313 if (zoomLevel != 1) { 313 if (zoomLevel != 1) {
314 unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel); 314 unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel);
315 unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel); 315 unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel);
316 } 316 }
317 317
318 GraphicsContextStateSaver stateSaver(*paintInfo.context); 318 GraphicsContextStateSaver stateSaver(paintInfo.context);
319 if (zoomLevel != 1) { 319 if (zoomLevel != 1) {
320 paintInfo.context->translate(unzoomedRect.x(), unzoomedRect.y()); 320 paintInfo.context.translate(unzoomedRect.x(), unzoomedRect.y());
321 paintInfo.context->scale(zoomLevel, zoomLevel); 321 paintInfo.context.scale(zoomLevel, zoomLevel);
322 paintInfo.context->translate(-unzoomedRect.x(), -unzoomedRect.y()); 322 paintInfo.context.translate(-unzoomedRect.x(), -unzoomedRect.y());
323 } 323 }
324 324
325 Color fillColor(205, 205, 205); 325 Color fillColor(205, 205, 205);
326 Color borderGradientTopColor(109, 109, 109); 326 Color borderGradientTopColor(109, 109, 109);
327 Color borderGradientBottomColor(181, 181, 181); 327 Color borderGradientBottomColor(181, 181, 181);
328 Color shadowColor(0, 0, 0, 118); 328 Color shadowColor(0, 0, 0, 118);
329 329
330 if (!LayoutTheme::isEnabled(o)) { 330 if (!LayoutTheme::isEnabled(o)) {
331 Color tintColor(255, 255, 255, 128); 331 Color tintColor(255, 255, 255, 128);
332 fillColor = fillColor.blend(tintColor); 332 fillColor = fillColor.blend(tintColor);
333 borderGradientTopColor = borderGradientTopColor.blend(tintColor); 333 borderGradientTopColor = borderGradientTopColor.blend(tintColor);
334 borderGradientBottomColor = borderGradientBottomColor.blend(tintColor); 334 borderGradientBottomColor = borderGradientBottomColor.blend(tintColor);
335 shadowColor = shadowColor.blend(tintColor); 335 shadowColor = shadowColor.blend(tintColor);
336 } 336 }
337 337
338 Color tintColor; 338 Color tintColor;
339 if (!LayoutTheme::isEnabled(o)) 339 if (!LayoutTheme::isEnabled(o))
340 tintColor = Color(255, 255, 255, 128); 340 tintColor = Color(255, 255, 255, 128);
341 341
342 bool isVerticalSlider = o.styleRef().appearance() == SliderVerticalPart; 342 bool isVerticalSlider = o.styleRef().appearance() == SliderVerticalPart;
343 343
344 float fillRadiusSize = (LayoutThemeMac::sliderTrackWidth - LayoutThemeMac::s liderTrackBorderWidth) / 2; 344 float fillRadiusSize = (LayoutThemeMac::sliderTrackWidth - LayoutThemeMac::s liderTrackBorderWidth) / 2;
345 FloatSize fillRadius(fillRadiusSize, fillRadiusSize); 345 FloatSize fillRadius(fillRadiusSize, fillRadiusSize);
346 FloatRect fillBounds(enclosedIntRect(unzoomedRect)); 346 FloatRect fillBounds(enclosedIntRect(unzoomedRect));
347 FloatRoundedRect fillRect(fillBounds, fillRadius, fillRadius, fillRadius, fi llRadius); 347 FloatRoundedRect fillRect(fillBounds, fillRadius, fillRadius, fillRadius, fi llRadius);
348 paintInfo.context->fillRoundedRect(fillRect, fillColor); 348 paintInfo.context.fillRoundedRect(fillRect, fillColor);
349 349
350 FloatSize shadowOffset(isVerticalSlider ? 1 : 0, 350 FloatSize shadowOffset(isVerticalSlider ? 1 : 0,
351 isVerticalSlider ? 0 : 1); 351 isVerticalSlider ? 0 : 1);
352 float shadowBlur = 3; 352 float shadowBlur = 3;
353 float shadowSpread = 0; 353 float shadowSpread = 0;
354 paintInfo.context->save(); 354 paintInfo.context.save();
355 paintInfo.context->drawInnerShadow(fillRect, shadowColor, shadowOffset, shad owBlur, shadowSpread); 355 paintInfo.context.drawInnerShadow(fillRect, shadowColor, shadowOffset, shado wBlur, shadowSpread);
356 paintInfo.context->restore(); 356 paintInfo.context.restore();
357 357
358 RefPtr<Gradient> borderGradient = Gradient::create(fillBounds.minXMinYCorner (), 358 RefPtr<Gradient> borderGradient = Gradient::create(fillBounds.minXMinYCorner (),
359 isVerticalSlider ? fillBounds.maxXMinYCorner() : fillBounds.minXMaxYCorn er()); 359 isVerticalSlider ? fillBounds.maxXMinYCorner() : fillBounds.minXMaxYCorn er());
360 borderGradient->addColorStop(0.0, borderGradientTopColor); 360 borderGradient->addColorStop(0.0, borderGradientTopColor);
361 borderGradient->addColorStop(1.0, borderGradientBottomColor); 361 borderGradient->addColorStop(1.0, borderGradientBottomColor);
362 Path borderPath; 362 Path borderPath;
363 FloatRect borderRect(unzoomedRect); 363 FloatRect borderRect(unzoomedRect);
364 borderRect.inflate(-LayoutThemeMac::sliderTrackBorderWidth / 2.0); 364 borderRect.inflate(-LayoutThemeMac::sliderTrackBorderWidth / 2.0);
365 float borderRadiusSize = (isVerticalSlider ? borderRect.width() : borderRect .height()) / 2; 365 float borderRadiusSize = (isVerticalSlider ? borderRect.width() : borderRect .height()) / 2;
366 FloatSize borderRadius(borderRadiusSize, borderRadiusSize); 366 FloatSize borderRadius(borderRadiusSize, borderRadiusSize);
367 borderPath.addRoundedRect(borderRect, borderRadius, borderRadius, borderRadi us, borderRadius); 367 borderPath.addRoundedRect(borderRect, borderRadius, borderRadius, borderRadi us, borderRadius);
368 paintInfo.context->setStrokeGradient(borderGradient); 368 paintInfo.context.setStrokeGradient(borderGradient);
369 paintInfo.context->setStrokeThickness(LayoutThemeMac::sliderTrackBorderWidth ); 369 paintInfo.context.setStrokeThickness(LayoutThemeMac::sliderTrackBorderWidth) ;
370 paintInfo.context->strokePath(borderPath); 370 paintInfo.context.strokePath(borderPath);
371 return false; 371 return false;
372 } 372 }
373 373
374 374
375 bool ThemePainterMac::paintSliderThumb(const LayoutObject& o, const PaintInfo& p aintInfo, const IntRect& r) 375 bool ThemePainterMac::paintSliderThumb(const LayoutObject& o, const PaintInfo& p aintInfo, const IntRect& r)
376 { 376 {
377 GraphicsContextStateSaver stateSaver(*paintInfo.context); 377 GraphicsContextStateSaver stateSaver(paintInfo.context);
378 float zoomLevel = o.styleRef().effectiveZoom(); 378 float zoomLevel = o.styleRef().effectiveZoom();
379 379
380 FloatRect unzoomedRect(r.x(), r.y(), LayoutThemeMac::sliderThumbWidth, Layou tThemeMac::sliderThumbHeight); 380 FloatRect unzoomedRect(r.x(), r.y(), LayoutThemeMac::sliderThumbWidth, Layou tThemeMac::sliderThumbHeight);
381 if (zoomLevel != 1.0f) { 381 if (zoomLevel != 1.0f) {
382 paintInfo.context->translate(unzoomedRect.x(), unzoomedRect.y()); 382 paintInfo.context.translate(unzoomedRect.x(), unzoomedRect.y());
383 paintInfo.context->scale(zoomLevel, zoomLevel); 383 paintInfo.context.scale(zoomLevel, zoomLevel);
384 paintInfo.context->translate(-unzoomedRect.x(), -unzoomedRect.y()); 384 paintInfo.context.translate(-unzoomedRect.x(), -unzoomedRect.y());
385 } 385 }
386 386
387 Color fillGradientTopColor(250, 250, 250); 387 Color fillGradientTopColor(250, 250, 250);
388 Color fillGradientUpperMiddleColor(244, 244, 244); 388 Color fillGradientUpperMiddleColor(244, 244, 244);
389 Color fillGradientLowerMiddleColor(236, 236, 236); 389 Color fillGradientLowerMiddleColor(236, 236, 236);
390 Color fillGradientBottomColor(238, 238, 238); 390 Color fillGradientBottomColor(238, 238, 238);
391 Color borderGradientTopColor(151, 151, 151); 391 Color borderGradientTopColor(151, 151, 151);
392 Color borderGradientBottomColor(128, 128, 128); 392 Color borderGradientBottomColor(128, 128, 128);
393 Color shadowColor(0, 0, 0, 36); 393 Color shadowColor(0, 0, 0, 36);
394 394
(...skipping 15 matching lines...) Expand all
410 borderGradientTopColor = borderGradientTopColor.blend(tintColor); 410 borderGradientTopColor = borderGradientTopColor.blend(tintColor);
411 borderGradientBottomColor = borderGradientBottomColor.blend(tintColor); 411 borderGradientBottomColor = borderGradientBottomColor.blend(tintColor);
412 shadowColor = shadowColor.blend(tintColor); 412 shadowColor = shadowColor.blend(tintColor);
413 } 413 }
414 414
415 FloatRect borderBounds = unzoomedRect; 415 FloatRect borderBounds = unzoomedRect;
416 borderBounds.inflate(LayoutThemeMac::sliderThumbBorderWidth / 2.0); 416 borderBounds.inflate(LayoutThemeMac::sliderThumbBorderWidth / 2.0);
417 417
418 borderBounds.inflate(-LayoutThemeMac::sliderThumbBorderWidth); 418 borderBounds.inflate(-LayoutThemeMac::sliderThumbBorderWidth);
419 FloatSize shadowOffset(0, 1); 419 FloatSize shadowOffset(0, 1);
420 paintInfo.context->setShadow(shadowOffset, LayoutThemeMac::sliderThumbShadow Blur, shadowColor); 420 paintInfo.context.setShadow(shadowOffset, LayoutThemeMac::sliderThumbShadowB lur, shadowColor);
421 paintInfo.context->setFillColor(Color::black); 421 paintInfo.context.setFillColor(Color::black);
422 paintInfo.context->fillEllipse(borderBounds); 422 paintInfo.context.fillEllipse(borderBounds);
423 paintInfo.context->clearDrawLooper(); 423 paintInfo.context.clearDrawLooper();
424 424
425 IntRect fillBounds = enclosedIntRect(unzoomedRect); 425 IntRect fillBounds = enclosedIntRect(unzoomedRect);
426 RefPtr<Gradient> fillGradient = Gradient::create(fillBounds.minXMinYCorner() , fillBounds.minXMaxYCorner()); 426 RefPtr<Gradient> fillGradient = Gradient::create(fillBounds.minXMinYCorner() , fillBounds.minXMaxYCorner());
427 fillGradient->addColorStop(0.0, fillGradientTopColor); 427 fillGradient->addColorStop(0.0, fillGradientTopColor);
428 fillGradient->addColorStop(0.52, fillGradientUpperMiddleColor); 428 fillGradient->addColorStop(0.52, fillGradientUpperMiddleColor);
429 fillGradient->addColorStop(0.52, fillGradientLowerMiddleColor); 429 fillGradient->addColorStop(0.52, fillGradientLowerMiddleColor);
430 fillGradient->addColorStop(1.0, fillGradientBottomColor); 430 fillGradient->addColorStop(1.0, fillGradientBottomColor);
431 paintInfo.context->setFillGradient(fillGradient); 431 paintInfo.context.setFillGradient(fillGradient);
432 paintInfo.context->fillEllipse(borderBounds); 432 paintInfo.context.fillEllipse(borderBounds);
433 433
434 RefPtr<Gradient> borderGradient = Gradient::create(fillBounds.minXMinYCorner (), fillBounds.minXMaxYCorner()); 434 RefPtr<Gradient> borderGradient = Gradient::create(fillBounds.minXMinYCorner (), fillBounds.minXMaxYCorner());
435 borderGradient->addColorStop(0.0, borderGradientTopColor); 435 borderGradient->addColorStop(0.0, borderGradientTopColor);
436 borderGradient->addColorStop(1.0, borderGradientBottomColor); 436 borderGradient->addColorStop(1.0, borderGradientBottomColor);
437 paintInfo.context->setStrokeGradient(borderGradient); 437 paintInfo.context.setStrokeGradient(borderGradient);
438 paintInfo.context->setStrokeThickness(LayoutThemeMac::sliderThumbBorderWidth ); 438 paintInfo.context.setStrokeThickness(LayoutThemeMac::sliderThumbBorderWidth) ;
439 paintInfo.context->strokeEllipse(borderBounds); 439 paintInfo.context.strokeEllipse(borderBounds);
440 440
441 if (LayoutTheme::isFocused(o)) { 441 if (LayoutTheme::isFocused(o)) {
442 Path borderPath; 442 Path borderPath;
443 borderPath.addEllipse(borderBounds); 443 borderPath.addEllipse(borderBounds);
444 paintInfo.context->drawFocusRing(borderPath, 5, -2, m_layoutTheme.focusR ingColor()); 444 paintInfo.context.drawFocusRing(borderPath, 5, -2, m_layoutTheme.focusRi ngColor());
445 } 445 }
446 446
447 return false; 447 return false;
448 } 448 }
449 449
450 // We don't use controlSizeForFont() for search field decorations because it 450 // We don't use controlSizeForFont() for search field decorations because it
451 // needs to fit into the search field. The font size will already be modified by 451 // needs to fit into the search field. The font size will already be modified by
452 // setFontFromControlSize() called on the search field. 452 // setFontFromControlSize() called on the search field.
453 static NSControlSize searchFieldControlSizeForFont(const ComputedStyle& style) 453 static NSControlSize searchFieldControlSizeForFont(const ComputedStyle& style)
454 { 454 {
455 int fontSize = style.fontSize(); 455 int fontSize = style.fontSize();
456 if (fontSize >= 13) 456 if (fontSize >= 13)
457 return NSRegularControlSize; 457 return NSRegularControlSize;
458 if (fontSize >= 11) 458 if (fontSize >= 11)
459 return NSSmallControlSize; 459 return NSSmallControlSize;
460 return NSMiniControlSize; 460 return NSMiniControlSize;
461 } 461 }
462 462
463 bool ThemePainterMac::paintSearchField(const LayoutObject& o, const PaintInfo& p aintInfo, const IntRect& r) 463 bool ThemePainterMac::paintSearchField(const LayoutObject& o, const PaintInfo& p aintInfo, const IntRect& r)
464 { 464 {
465 LocalCurrentGraphicsContext localContext(paintInfo.context, &paintInfo.cullR ect().m_rect, r); 465 LocalCurrentGraphicsContext localContext(paintInfo.context, &paintInfo.cullR ect().m_rect, r);
466 466
467 NSSearchFieldCell* search = m_layoutTheme.search(); 467 NSSearchFieldCell* search = m_layoutTheme.search();
468 m_layoutTheme.setSearchCellState(o, r); 468 m_layoutTheme.setSearchCellState(o, r);
469 [search setControlSize:searchFieldControlSizeForFont(o.styleRef())]; 469 [search setControlSize:searchFieldControlSizeForFont(o.styleRef())];
470 470
471 GraphicsContextStateSaver stateSaver(*paintInfo.context); 471 GraphicsContextStateSaver stateSaver(paintInfo.context);
472 472
473 float zoomLevel = o.styleRef().effectiveZoom(); 473 float zoomLevel = o.styleRef().effectiveZoom();
474 474
475 IntRect unzoomedRect = r; 475 IntRect unzoomedRect = r;
476 476
477 if (zoomLevel != 1.0f) { 477 if (zoomLevel != 1.0f) {
478 unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel); 478 unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel);
479 unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel); 479 unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel);
480 paintInfo.context->translate(unzoomedRect.x(), unzoomedRect.y()); 480 paintInfo.context.translate(unzoomedRect.x(), unzoomedRect.y());
481 paintInfo.context->scale(zoomLevel, zoomLevel); 481 paintInfo.context.scale(zoomLevel, zoomLevel);
482 paintInfo.context->translate(-unzoomedRect.x(), -unzoomedRect.y()); 482 paintInfo.context.translate(-unzoomedRect.x(), -unzoomedRect.y());
483 } 483 }
484 484
485 // Set the search button to nil before drawing. Then reset it so we can 485 // Set the search button to nil before drawing. Then reset it so we can
486 // draw it later. 486 // draw it later.
487 [search setSearchButtonCell:nil]; 487 [search setSearchButtonCell:nil];
488 488
489 [search drawWithFrame:NSRect(unzoomedRect) inView:m_layoutTheme.documentView For(o)]; 489 [search drawWithFrame:NSRect(unzoomedRect) inView:m_layoutTheme.documentView For(o)];
490 490
491 [search setControlView:nil]; 491 [search setControlView:nil];
492 [search resetSearchButtonCell]; 492 [search resetSearchButtonCell];
493 493
494 return false; 494 return false;
495 } 495 }
496 496
497 bool ThemePainterMac::paintSearchFieldCancelButton(const LayoutObject& o, const PaintInfo& paintInfo, const IntRect& r) 497 bool ThemePainterMac::paintSearchFieldCancelButton(const LayoutObject& o, const PaintInfo& paintInfo, const IntRect& r)
498 { 498 {
499 if (!o.node()) 499 if (!o.node())
500 return false; 500 return false;
501 Element* input = o.node()->shadowHost(); 501 Element* input = o.node()->shadowHost();
502 if (!input) 502 if (!input)
503 input = toElement(o.node()); 503 input = toElement(o.node());
504 504
505 if (!input->layoutObject()->isBox()) 505 if (!input->layoutObject()->isBox())
506 return false; 506 return false;
507 507
508 GraphicsContextStateSaver stateSaver(*paintInfo.context); 508 GraphicsContextStateSaver stateSaver(paintInfo.context);
509 509
510 float zoomLevel = o.styleRef().effectiveZoom(); 510 float zoomLevel = o.styleRef().effectiveZoom();
511 FloatRect unzoomedRect(r); 511 FloatRect unzoomedRect(r);
512 if (zoomLevel != 1.0f) { 512 if (zoomLevel != 1.0f) {
513 unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel); 513 unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel);
514 unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel); 514 unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel);
515 paintInfo.context->translate(unzoomedRect.x(), unzoomedRect.y()); 515 paintInfo.context.translate(unzoomedRect.x(), unzoomedRect.y());
516 paintInfo.context->scale(zoomLevel, zoomLevel); 516 paintInfo.context.scale(zoomLevel, zoomLevel);
517 paintInfo.context->translate(-unzoomedRect.x(), -unzoomedRect.y()); 517 paintInfo.context.translate(-unzoomedRect.x(), -unzoomedRect.y());
518 } 518 }
519 519
520 Color fillColor(200, 200, 200); 520 Color fillColor(200, 200, 200);
521 521
522 if (LayoutTheme::isPressed(o)) { 522 if (LayoutTheme::isPressed(o)) {
523 Color tintColor(0, 0, 0, 32); 523 Color tintColor(0, 0, 0, 32);
524 fillColor = fillColor.blend(tintColor); 524 fillColor = fillColor.blend(tintColor);
525 } 525 }
526 526
527 float centerX = unzoomedRect.x() + unzoomedRect.width() / 2; 527 float centerX = unzoomedRect.x() + unzoomedRect.width() / 2;
528 float centerY = unzoomedRect.y() + unzoomedRect.height() / 2; 528 float centerY = unzoomedRect.y() + unzoomedRect.height() / 2;
529 // The line width is 3px on a regular sized, high DPI NSCancelButtonCell 529 // The line width is 3px on a regular sized, high DPI NSCancelButtonCell
530 // (which is 28px wide). 530 // (which is 28px wide).
531 float lineWidth = unzoomedRect.width() * 3 / 28; 531 float lineWidth = unzoomedRect.width() * 3 / 28;
532 // The line length is 16px on a regular sized, high DPI NSCancelButtonCell. 532 // The line length is 16px on a regular sized, high DPI NSCancelButtonCell.
533 float lineLength = unzoomedRect.width() * 16 / 28; 533 float lineLength = unzoomedRect.width() * 16 / 28;
534 534
535 Path xPath; 535 Path xPath;
536 FloatSize lineRectRadius(lineWidth / 2, lineWidth / 2); 536 FloatSize lineRectRadius(lineWidth / 2, lineWidth / 2);
537 xPath.addRoundedRect(FloatRect(-lineLength / 2, -lineWidth / 2, lineLength, lineWidth), 537 xPath.addRoundedRect(FloatRect(-lineLength / 2, -lineWidth / 2, lineLength, lineWidth),
538 lineRectRadius, lineRectRadius, lineRectRadius, lineRectRadius); 538 lineRectRadius, lineRectRadius, lineRectRadius, lineRectRadius);
539 xPath.addRoundedRect(FloatRect(-lineWidth / 2, -lineLength / 2, lineWidth, l ineLength), 539 xPath.addRoundedRect(FloatRect(-lineWidth / 2, -lineLength / 2, lineWidth, l ineLength),
540 lineRectRadius, lineRectRadius, lineRectRadius, lineRectRadius); 540 lineRectRadius, lineRectRadius, lineRectRadius, lineRectRadius);
541 541
542 paintInfo.context->translate(centerX, centerY); 542 paintInfo.context.translate(centerX, centerY);
543 paintInfo.context->rotate(deg2rad(45.0)); 543 paintInfo.context.rotate(deg2rad(45.0));
544 paintInfo.context->clipOut(xPath); 544 paintInfo.context.clipOut(xPath);
545 paintInfo.context->rotate(deg2rad(-45.0)); 545 paintInfo.context.rotate(deg2rad(-45.0));
546 paintInfo.context->translate(-centerX, -centerY); 546 paintInfo.context.translate(-centerX, -centerY);
547 547
548 paintInfo.context->setFillColor(fillColor); 548 paintInfo.context.setFillColor(fillColor);
549 paintInfo.context->fillEllipse(unzoomedRect); 549 paintInfo.context.fillEllipse(unzoomedRect);
550 550
551 return false; 551 return false;
552 } 552 }
553 553
554 bool ThemePainterMac::paintSearchFieldDecoration(const LayoutObject&, const Pain tInfo&, const IntRect&) 554 bool ThemePainterMac::paintSearchFieldDecoration(const LayoutObject&, const Pain tInfo&, const IntRect&)
555 { 555 {
556 return false; 556 return false;
557 } 557 }
558 558
559 bool ThemePainterMac::paintSearchFieldResultsDecoration(const LayoutObject& o, c onst PaintInfo& paintInfo, const IntRect& r) 559 bool ThemePainterMac::paintSearchFieldResultsDecoration(const LayoutObject& o, c onst PaintInfo& paintInfo, const IntRect& r)
560 { 560 {
561 if (!o.node()) 561 if (!o.node())
562 return false; 562 return false;
563 Node* input = o.node()->shadowHost(); 563 Node* input = o.node()->shadowHost();
564 if (!input) 564 if (!input)
565 input = o.node(); 565 input = o.node();
566 if (!input->layoutObject()->isBox()) 566 if (!input->layoutObject()->isBox())
567 return false; 567 return false;
568 568
569 GraphicsContextStateSaver stateSaver(*paintInfo.context); 569 GraphicsContextStateSaver stateSaver(paintInfo.context);
570 570
571 float zoomLevel = o.styleRef().effectiveZoom(); 571 float zoomLevel = o.styleRef().effectiveZoom();
572 FloatRect unzoomedRect(r); 572 FloatRect unzoomedRect(r);
573 if (zoomLevel != 1) { 573 if (zoomLevel != 1) {
574 unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel); 574 unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel);
575 unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel); 575 unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel);
576 paintInfo.context->translate(unzoomedRect.x(), unzoomedRect.y()); 576 paintInfo.context.translate(unzoomedRect.x(), unzoomedRect.y());
577 paintInfo.context->scale(zoomLevel, zoomLevel); 577 paintInfo.context.scale(zoomLevel, zoomLevel);
578 paintInfo.context->translate(-unzoomedRect.x(), -unzoomedRect.y()); 578 paintInfo.context.translate(-unzoomedRect.x(), -unzoomedRect.y());
579 } 579 }
580 580
581 LocalCurrentGraphicsContext localContext(paintInfo.context, &paintInfo.cullR ect().m_rect, r); 581 LocalCurrentGraphicsContext localContext(paintInfo.context, &paintInfo.cullR ect().m_rect, r);
582 582
583 NSSearchFieldCell* search = m_layoutTheme.search(); 583 NSSearchFieldCell* search = m_layoutTheme.search();
584 m_layoutTheme.setSearchCellState(*input->layoutObject(), r); 584 m_layoutTheme.setSearchCellState(*input->layoutObject(), r);
585 [search setControlSize:searchFieldControlSizeForFont(o.styleRef())]; 585 [search setControlSize:searchFieldControlSizeForFont(o.styleRef())];
586 if ([search searchMenuTemplate] != nil) 586 if ([search searchMenuTemplate] != nil)
587 [search setSearchMenuTemplate:nil]; 587 [search setSearchMenuTemplate:nil];
588 588
589 m_layoutTheme.updateActiveState([search searchButtonCell], o); 589 m_layoutTheme.updateActiveState([search searchButtonCell], o);
590 590
591 [[search searchButtonCell] drawWithFrame:unzoomedRect inView:m_layoutTheme.d ocumentViewFor(o)]; 591 [[search searchButtonCell] drawWithFrame:unzoomedRect inView:m_layoutTheme.d ocumentViewFor(o)];
592 [[search searchButtonCell] setControlView:nil]; 592 [[search searchButtonCell] setControlView:nil];
593 return false; 593 return false;
594 } 594 }
595 595
596 } // namespace blink 596 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/paint/ThemePainterDefault.cpp ('k') | third_party/WebKit/Source/core/paint/VideoPainter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698