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

Side by Side Diff: third_party/WebKit/Source/platform/mac/ThemeMac.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) 2008, 2010, 2011, 2012 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008, 2010, 2011, 2012 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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 // Set the control size based off the rectangle we're painting into. 258 // Set the control size based off the rectangle we're painting into.
259 setControlSize(checkboxCell, checkboxSizes(), zoomedRect.size(), zoomFactor) ; 259 setControlSize(checkboxCell, checkboxSizes(), zoomedRect.size(), zoomFactor) ;
260 260
261 // Update the various states we respond to. 261 // Update the various states we respond to.
262 updateStates(checkboxCell, states); 262 updateStates(checkboxCell, states);
263 263
264 return checkboxCell; 264 return checkboxCell;
265 } 265 }
266 266
267 // FIXME: Share more code with radio buttons. 267 // FIXME: Share more code with radio buttons.
268 static void paintCheckbox(ControlStates states, GraphicsContext* context, const IntRect& zoomedRect, float zoomFactor, ScrollableArea* scrollableArea) 268 static void paintCheckbox(ControlStates states, GraphicsContext& context, const IntRect& zoomedRect, float zoomFactor, ScrollableArea* scrollableArea)
269 { 269 {
270 BEGIN_BLOCK_OBJC_EXCEPTIONS 270 BEGIN_BLOCK_OBJC_EXCEPTIONS
271 271
272 // Determine the width and height needed for the control and prepare the cel l for painting. 272 // Determine the width and height needed for the control and prepare the cel l for painting.
273 NSButtonCell *checkboxCell = checkbox(states, zoomedRect, zoomFactor); 273 NSButtonCell *checkboxCell = checkbox(states, zoomedRect, zoomFactor);
274 GraphicsContextStateSaver stateSaver(*context); 274 GraphicsContextStateSaver stateSaver(context);
275 275
276 NSControlSize controlSize = [checkboxCell controlSize]; 276 NSControlSize controlSize = [checkboxCell controlSize];
277 IntSize zoomedSize = checkboxSizes()[controlSize]; 277 IntSize zoomedSize = checkboxSizes()[controlSize];
278 zoomedSize.setWidth(zoomedSize.width() * zoomFactor); 278 zoomedSize.setWidth(zoomedSize.width() * zoomFactor);
279 zoomedSize.setHeight(zoomedSize.height() * zoomFactor); 279 zoomedSize.setHeight(zoomedSize.height() * zoomFactor);
280 IntRect inflatedRect = ThemeMac::inflateRect(zoomedRect, zoomedSize, checkbo xMargins(controlSize), zoomFactor); 280 IntRect inflatedRect = ThemeMac::inflateRect(zoomedRect, zoomedSize, checkbo xMargins(controlSize), zoomFactor);
281 281
282 if (zoomFactor != 1.0f) { 282 if (zoomFactor != 1.0f) {
283 inflatedRect.setWidth(inflatedRect.width() / zoomFactor); 283 inflatedRect.setWidth(inflatedRect.width() / zoomFactor);
284 inflatedRect.setHeight(inflatedRect.height() / zoomFactor); 284 inflatedRect.setHeight(inflatedRect.height() / zoomFactor);
285 context->translate(inflatedRect.x(), inflatedRect.y()); 285 context.translate(inflatedRect.x(), inflatedRect.y());
286 context->scale(zoomFactor, zoomFactor); 286 context.scale(zoomFactor, zoomFactor);
287 context->translate(-inflatedRect.x(), -inflatedRect.y()); 287 context.translate(-inflatedRect.x(), -inflatedRect.y());
288 } 288 }
289 289
290 LocalCurrentGraphicsContext localContext(context, ThemeMac::inflateRectForFo cusRing(inflatedRect)); 290 LocalCurrentGraphicsContext localContext(context, ThemeMac::inflateRectForFo cusRing(inflatedRect));
291 NSView* view = ensuredView(scrollableArea); 291 NSView* view = ensuredView(scrollableArea);
292 [checkboxCell drawWithFrame:NSRect(inflatedRect) inView:view]; 292 [checkboxCell drawWithFrame:NSRect(inflatedRect) inView:view];
293 if (!ThemeMac::drawWithFrameDrawsFocusRing() && states & FocusControlState) 293 if (!ThemeMac::drawWithFrameDrawsFocusRing() && states & FocusControlState)
294 [checkboxCell cr_drawFocusRingWithFrame:NSRect(inflatedRect) inView:view ]; 294 [checkboxCell cr_drawFocusRingWithFrame:NSRect(inflatedRect) inView:view ];
295 [checkboxCell setControlView:nil]; 295 [checkboxCell setControlView:nil];
296 296
297 END_BLOCK_OBJC_EXCEPTIONS 297 END_BLOCK_OBJC_EXCEPTIONS
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 setControlSize(radioCell, radioSizes(), zoomedRect.size(), zoomFactor); 340 setControlSize(radioCell, radioSizes(), zoomedRect.size(), zoomFactor);
341 341
342 // Update the various states we respond to. 342 // Update the various states we respond to.
343 // Cocoa draws NSMixedState NSRadioButton as NSOnState so we don't want that . 343 // Cocoa draws NSMixedState NSRadioButton as NSOnState so we don't want that .
344 states &= ~IndeterminateControlState; 344 states &= ~IndeterminateControlState;
345 updateStates(radioCell, states); 345 updateStates(radioCell, states);
346 346
347 return radioCell; 347 return radioCell;
348 } 348 }
349 349
350 static void paintRadio(ControlStates states, GraphicsContext* context, const Int Rect& zoomedRect, float zoomFactor, ScrollableArea* scrollableArea) 350 static void paintRadio(ControlStates states, GraphicsContext& context, const Int Rect& zoomedRect, float zoomFactor, ScrollableArea* scrollableArea)
351 { 351 {
352 // Determine the width and height needed for the control and prepare the cel l for painting. 352 // Determine the width and height needed for the control and prepare the cel l for painting.
353 NSButtonCell *radioCell = radio(states, zoomedRect, zoomFactor); 353 NSButtonCell *radioCell = radio(states, zoomedRect, zoomFactor);
354 GraphicsContextStateSaver stateSaver(*context); 354 GraphicsContextStateSaver stateSaver(context);
355 355
356 NSControlSize controlSize = [radioCell controlSize]; 356 NSControlSize controlSize = [radioCell controlSize];
357 IntSize zoomedSize = radioSizes()[controlSize]; 357 IntSize zoomedSize = radioSizes()[controlSize];
358 zoomedSize.setWidth(zoomedSize.width() * zoomFactor); 358 zoomedSize.setWidth(zoomedSize.width() * zoomFactor);
359 zoomedSize.setHeight(zoomedSize.height() * zoomFactor); 359 zoomedSize.setHeight(zoomedSize.height() * zoomFactor);
360 IntRect inflatedRect = ThemeMac::inflateRect(zoomedRect, zoomedSize, radioMa rgins(controlSize), zoomFactor); 360 IntRect inflatedRect = ThemeMac::inflateRect(zoomedRect, zoomedSize, radioMa rgins(controlSize), zoomFactor);
361 361
362 if (zoomFactor != 1.0f) { 362 if (zoomFactor != 1.0f) {
363 inflatedRect.setWidth(inflatedRect.width() / zoomFactor); 363 inflatedRect.setWidth(inflatedRect.width() / zoomFactor);
364 inflatedRect.setHeight(inflatedRect.height() / zoomFactor); 364 inflatedRect.setHeight(inflatedRect.height() / zoomFactor);
365 context->translate(inflatedRect.x(), inflatedRect.y()); 365 context.translate(inflatedRect.x(), inflatedRect.y());
366 context->scale(zoomFactor, zoomFactor); 366 context.scale(zoomFactor, zoomFactor);
367 context->translate(-inflatedRect.x(), -inflatedRect.y()); 367 context.translate(-inflatedRect.x(), -inflatedRect.y());
368 } 368 }
369 369
370 LocalCurrentGraphicsContext localContext(context, ThemeMac::inflateRectForFo cusRing(inflatedRect)); 370 LocalCurrentGraphicsContext localContext(context, ThemeMac::inflateRectForFo cusRing(inflatedRect));
371 BEGIN_BLOCK_OBJC_EXCEPTIONS 371 BEGIN_BLOCK_OBJC_EXCEPTIONS
372 NSView* view = ensuredView(scrollableArea); 372 NSView* view = ensuredView(scrollableArea);
373 [radioCell drawWithFrame:NSRect(inflatedRect) inView:view]; 373 [radioCell drawWithFrame:NSRect(inflatedRect) inView:view];
374 if (!ThemeMac::drawWithFrameDrawsFocusRing() && states & FocusControlState) 374 if (!ThemeMac::drawWithFrameDrawsFocusRing() && states & FocusControlState)
375 [radioCell cr_drawFocusRingWithFrame:NSRect(inflatedRect) inView:view]; 375 [radioCell cr_drawFocusRingWithFrame:NSRect(inflatedRect) inView:view];
376 [radioCell setControlView:nil]; 376 [radioCell setControlView:nil];
377 END_BLOCK_OBJC_EXCEPTIONS 377 END_BLOCK_OBJC_EXCEPTIONS
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 static NSButtonCell *cell = nil; 419 static NSButtonCell *cell = nil;
420 if (!cell) { 420 if (!cell) {
421 cell = [[NSButtonCell alloc] init]; 421 cell = [[NSButtonCell alloc] init];
422 [cell setTitle:nil]; 422 [cell setTitle:nil];
423 [cell setButtonType:NSMomentaryPushInButton]; 423 [cell setButtonType:NSMomentaryPushInButton];
424 } 424 }
425 setUpButtonCell(cell, part, states, zoomedRect, zoomFactor); 425 setUpButtonCell(cell, part, states, zoomedRect, zoomFactor);
426 return cell; 426 return cell;
427 } 427 }
428 428
429 static void paintButton(ControlPart part, ControlStates states, GraphicsContext* context, const IntRect& zoomedRect, float zoomFactor, ScrollableArea* scrollabl eArea) 429 static void paintButton(ControlPart part, ControlStates states, GraphicsContext& context, const IntRect& zoomedRect, float zoomFactor, ScrollableArea* scrollabl eArea)
430 { 430 {
431 BEGIN_BLOCK_OBJC_EXCEPTIONS 431 BEGIN_BLOCK_OBJC_EXCEPTIONS
432 432
433 // Determine the width and height needed for the control and prepare the cel l for painting. 433 // Determine the width and height needed for the control and prepare the cel l for painting.
434 NSButtonCell *buttonCell = button(part, states, zoomedRect, zoomFactor); 434 NSButtonCell *buttonCell = button(part, states, zoomedRect, zoomFactor);
435 GraphicsContextStateSaver stateSaver(*context); 435 GraphicsContextStateSaver stateSaver(context);
436 436
437 NSControlSize controlSize = [buttonCell controlSize]; 437 NSControlSize controlSize = [buttonCell controlSize];
438 IntSize zoomedSize = buttonSizes()[controlSize]; 438 IntSize zoomedSize = buttonSizes()[controlSize];
439 zoomedSize.setWidth(zoomedRect.width()); // Buttons don't ever constrain wid th, so the zoomed width can just be honored. 439 zoomedSize.setWidth(zoomedRect.width()); // Buttons don't ever constrain wid th, so the zoomed width can just be honored.
440 zoomedSize.setHeight(zoomedSize.height() * zoomFactor); 440 zoomedSize.setHeight(zoomedSize.height() * zoomFactor);
441 IntRect inflatedRect = zoomedRect; 441 IntRect inflatedRect = zoomedRect;
442 if ([buttonCell bezelStyle] == NSRoundedBezelStyle) { 442 if ([buttonCell bezelStyle] == NSRoundedBezelStyle) {
443 // Center the button within the available space. 443 // Center the button within the available space.
444 if (inflatedRect.height() > zoomedSize.height()) { 444 if (inflatedRect.height() > zoomedSize.height()) {
445 inflatedRect.setY(inflatedRect.y() + (inflatedRect.height() - zoomed Size.height()) / 2); 445 inflatedRect.setY(inflatedRect.y() + (inflatedRect.height() - zoomed Size.height()) / 2);
446 inflatedRect.setHeight(zoomedSize.height()); 446 inflatedRect.setHeight(zoomedSize.height());
447 } 447 }
448 448
449 // Now inflate it to account for the shadow. 449 // Now inflate it to account for the shadow.
450 inflatedRect = ThemeMac::inflateRect(inflatedRect, zoomedSize, buttonMar gins(controlSize), zoomFactor); 450 inflatedRect = ThemeMac::inflateRect(inflatedRect, zoomedSize, buttonMar gins(controlSize), zoomFactor);
451 451
452 if (zoomFactor != 1.0f) { 452 if (zoomFactor != 1.0f) {
453 inflatedRect.setWidth(inflatedRect.width() / zoomFactor); 453 inflatedRect.setWidth(inflatedRect.width() / zoomFactor);
454 inflatedRect.setHeight(inflatedRect.height() / zoomFactor); 454 inflatedRect.setHeight(inflatedRect.height() / zoomFactor);
455 context->translate(inflatedRect.x(), inflatedRect.y()); 455 context.translate(inflatedRect.x(), inflatedRect.y());
456 context->scale(zoomFactor, zoomFactor); 456 context.scale(zoomFactor, zoomFactor);
457 context->translate(-inflatedRect.x(), -inflatedRect.y()); 457 context.translate(-inflatedRect.x(), -inflatedRect.y());
458 } 458 }
459 } 459 }
460 460
461 LocalCurrentGraphicsContext localContext(context, ThemeMac::inflateRectForFo cusRing(inflatedRect)); 461 LocalCurrentGraphicsContext localContext(context, ThemeMac::inflateRectForFo cusRing(inflatedRect));
462 NSView* view = ensuredView(scrollableArea); 462 NSView* view = ensuredView(scrollableArea);
463 463
464 [buttonCell drawWithFrame:NSRect(inflatedRect) inView:view]; 464 [buttonCell drawWithFrame:NSRect(inflatedRect) inView:view];
465 if (!ThemeMac::drawWithFrameDrawsFocusRing() && states & FocusControlState) 465 if (!ThemeMac::drawWithFrameDrawsFocusRing() && states & FocusControlState)
466 [buttonCell cr_drawFocusRingWithFrame:NSRect(inflatedRect) inView:view]; 466 [buttonCell cr_drawFocusRingWithFrame:NSRect(inflatedRect) inView:view];
467 [buttonCell setControlView:nil]; 467 [buttonCell setControlView:nil];
(...skipping 14 matching lines...) Expand all
482 static NSControlSize stepperControlSizeForFont(const FontDescription& fontDescri ption) 482 static NSControlSize stepperControlSizeForFont(const FontDescription& fontDescri ption)
483 { 483 {
484 int fontSize = fontDescription.computedPixelSize(); 484 int fontSize = fontDescription.computedPixelSize();
485 if (fontSize >= 27) 485 if (fontSize >= 27)
486 return NSRegularControlSize; 486 return NSRegularControlSize;
487 if (fontSize >= 22) 487 if (fontSize >= 22)
488 return NSSmallControlSize; 488 return NSSmallControlSize;
489 return NSMiniControlSize; 489 return NSMiniControlSize;
490 } 490 }
491 491
492 static void paintStepper(ControlStates states, GraphicsContext* context, const I ntRect& zoomedRect, float zoomFactor, ScrollableArea*) 492 static void paintStepper(ControlStates states, GraphicsContext& context, const I ntRect& zoomedRect, float zoomFactor, ScrollableArea*)
493 { 493 {
494 // We don't use NSStepperCell because there are no ways to draw an 494 // We don't use NSStepperCell because there are no ways to draw an
495 // NSStepperCell with the up button highlighted. 495 // NSStepperCell with the up button highlighted.
496 496
497 HIThemeButtonDrawInfo drawInfo; 497 HIThemeButtonDrawInfo drawInfo;
498 drawInfo.version = 0; 498 drawInfo.version = 0;
499 drawInfo.state = convertControlStatesToThemeDrawState(kThemeIncDecButton, st ates); 499 drawInfo.state = convertControlStatesToThemeDrawState(kThemeIncDecButton, st ates);
500 drawInfo.adornment = kThemeAdornmentDefault; 500 drawInfo.adornment = kThemeAdornmentDefault;
501 ControlSize controlSize = controlSizeFromPixelSize(stepperSizes(), zoomedRec t.size(), zoomFactor); 501 ControlSize controlSize = controlSizeFromPixelSize(stepperSizes(), zoomedRec t.size(), zoomFactor);
502 if (controlSize == NSSmallControlSize) 502 if (controlSize == NSSmallControlSize)
503 drawInfo.kind = kThemeIncDecButtonSmall; 503 drawInfo.kind = kThemeIncDecButtonSmall;
504 else if (controlSize == NSMiniControlSize) 504 else if (controlSize == NSMiniControlSize)
505 drawInfo.kind = kThemeIncDecButtonMini; 505 drawInfo.kind = kThemeIncDecButtonMini;
506 else 506 else
507 drawInfo.kind = kThemeIncDecButton; 507 drawInfo.kind = kThemeIncDecButton;
508 508
509 IntRect rect(zoomedRect); 509 IntRect rect(zoomedRect);
510 GraphicsContextStateSaver stateSaver(*context); 510 GraphicsContextStateSaver stateSaver(context);
511 if (zoomFactor != 1.0f) { 511 if (zoomFactor != 1.0f) {
512 rect.setWidth(rect.width() / zoomFactor); 512 rect.setWidth(rect.width() / zoomFactor);
513 rect.setHeight(rect.height() / zoomFactor); 513 rect.setHeight(rect.height() / zoomFactor);
514 context->translate(rect.x(), rect.y()); 514 context.translate(rect.x(), rect.y());
515 context->scale(zoomFactor, zoomFactor); 515 context.scale(zoomFactor, zoomFactor);
516 context->translate(-rect.x(), -rect.y()); 516 context.translate(-rect.x(), -rect.y());
517 } 517 }
518 CGRect bounds(rect); 518 CGRect bounds(rect);
519 CGRect backgroundBounds; 519 CGRect backgroundBounds;
520 HIThemeGetButtonBackgroundBounds(&bounds, &drawInfo, &backgroundBounds); 520 HIThemeGetButtonBackgroundBounds(&bounds, &drawInfo, &backgroundBounds);
521 // Center the stepper rectangle in the specified area. 521 // Center the stepper rectangle in the specified area.
522 backgroundBounds.origin.x = bounds.origin.x + (bounds.size.width - backgroun dBounds.size.width) / 2; 522 backgroundBounds.origin.x = bounds.origin.x + (bounds.size.width - backgroun dBounds.size.width) / 2;
523 if (backgroundBounds.size.height < bounds.size.height) { 523 if (backgroundBounds.size.height < bounds.size.height) {
524 int heightDiff = clampTo<int>(bounds.size.height - backgroundBounds.size .height); 524 int heightDiff = clampTo<int>(bounds.size.height - backgroundBounds.size .height);
525 backgroundBounds.origin.y = bounds.origin.y + (heightDiff / 2) + 1; 525 backgroundBounds.origin.y = bounds.origin.y + (heightDiff / 2) + 1;
526 } 526 }
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 zoomedSize.setWidth(zoomedSize.width() * zoomFactor); 668 zoomedSize.setWidth(zoomedSize.width() * zoomFactor);
669 zoomedRect = inflateRect(zoomedRect, zoomedSize, stepperMargin, zoom Factor); 669 zoomedRect = inflateRect(zoomedRect, zoomedSize, stepperMargin, zoom Factor);
670 break; 670 break;
671 } 671 }
672 default: 672 default:
673 break; 673 break;
674 } 674 }
675 END_BLOCK_OBJC_EXCEPTIONS 675 END_BLOCK_OBJC_EXCEPTIONS
676 } 676 }
677 677
678 void ThemeMac::paint(ControlPart part, ControlStates states, GraphicsContext* co ntext, const IntRect& zoomedRect, float zoomFactor, ScrollableArea* scrollableAr ea) const 678 void ThemeMac::paint(ControlPart part, ControlStates states, GraphicsContext& co ntext, const IntRect& zoomedRect, float zoomFactor, ScrollableArea* scrollableAr ea) const
679 { 679 {
680 switch (part) { 680 switch (part) {
681 case CheckboxPart: 681 case CheckboxPart:
682 paintCheckbox(states, context, zoomedRect, zoomFactor, scrollableAre a); 682 paintCheckbox(states, context, zoomedRect, zoomFactor, scrollableAre a);
683 break; 683 break;
684 case RadioPart: 684 case RadioPart:
685 paintRadio(states, context, zoomedRect, zoomFactor, scrollableArea); 685 paintRadio(states, context, zoomedRect, zoomFactor, scrollableArea);
686 break; 686 break;
687 case PushButtonPart: 687 case PushButtonPart:
688 case ButtonPart: 688 case ButtonPart:
(...skipping 15 matching lines...) Expand all
704 // focus ring with the frame. 704 // focus ring with the frame.
705 return IsOSLionOrEarlier(); 705 return IsOSLionOrEarlier();
706 #else 706 #else
707 // If compiling an OSX 10.7 or older SDK, OSes up through 10.9 will draw a focus 707 // If compiling an OSX 10.7 or older SDK, OSes up through 10.9 will draw a focus
708 // ring with the frame. 708 // ring with the frame.
709 return IsOSMavericksOrEarlier(); 709 return IsOSMavericksOrEarlier();
710 #endif 710 #endif
711 } 711 }
712 712
713 } 713 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698