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

Side by Side Diff: Source/platform/mac/ThemeMac.mm

Issue 528413002: Revert 181330 "Revert 180822 "Specify clip rects when drawing Ma..." (Closed) Base URL: svn://svn.chromium.org/blink/branches/chromium/2145/
Patch Set: Created 6 years, 3 months 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 | Annotate | Revision Log
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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 if ([[self familyName] hasPrefix:@"."]) 82 if ([[self familyName] hasPrefix:@"."])
83 return [self fontName]; 83 return [self fontName];
84 84
85 return [self familyName]; 85 return [self familyName];
86 } 86 }
87 87
88 @end 88 @end
89 89
90 namespace blink { 90 namespace blink {
91 91
92 enum {
93 topMargin,
94 rightMargin,
95 bottomMargin,
96 leftMargin
97 };
98
99 Theme* platformTheme() 92 Theme* platformTheme()
100 { 93 {
101 DEFINE_STATIC_LOCAL(ThemeMac, themeMac, ()); 94 DEFINE_STATIC_LOCAL(ThemeMac, themeMac, ());
102 return &themeMac; 95 return &themeMac;
103 } 96 }
104 97
105 // Helper functions used by a bunch of different control parts. 98 // Helper functions used by a bunch of different control parts.
106 99
107 static NSControlSize controlSizeForFont(const FontDescription& fontDescription) 100 static NSControlSize controlSizeForFont(const FontDescription& fontDescription)
108 { 101 {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 188
196 // Do not process PressedState if !EnabledControlState or ReadOnlyControlSta te. 189 // Do not process PressedState if !EnabledControlState or ReadOnlyControlSta te.
197 if (states & PressedControlState) { 190 if (states & PressedControlState) {
198 if (kind == kThemeIncDecButton || kind == kThemeIncDecButtonSmall || kin d == kThemeIncDecButtonMini) 191 if (kind == kThemeIncDecButton || kind == kThemeIncDecButtonSmall || kin d == kThemeIncDecButtonMini)
199 return states & SpinUpControlState ? kThemeStatePressedUp : kThemeSt atePressedDown; 192 return states & SpinUpControlState ? kThemeStatePressedUp : kThemeSt atePressedDown;
200 return kThemeStatePressed; 193 return kThemeStatePressed;
201 } 194 }
202 return kThemeStateActive; 195 return kThemeStateActive;
203 } 196 }
204 197
205 static IntRect inflateRect(const IntRect& zoomedRect, const IntSize& zoomedSize, const int* margins, float zoomFactor) 198 // static
199 IntRect ThemeMac::inflateRect(const IntRect& zoomedRect, const IntSize& zoomedSi ze, const int* margins, float zoomFactor)
206 { 200 {
207 // Only do the inflation if the available width/height are too small. Other wise try to 201 // Only do the inflation if the available width/height are too small. Other wise try to
208 // fit the glow/check space into the available box's width/height. 202 // fit the glow/check space into the available box's width/height.
209 int widthDelta = zoomedRect.width() - (zoomedSize.width() + margins[leftMarg in] * zoomFactor + margins[rightMargin] * zoomFactor); 203 int widthDelta = zoomedRect.width() - (zoomedSize.width() + margins[LeftMarg in] * zoomFactor + margins[RightMargin] * zoomFactor);
210 int heightDelta = zoomedRect.height() - (zoomedSize.height() + margins[topMa rgin] * zoomFactor + margins[bottomMargin] * zoomFactor); 204 int heightDelta = zoomedRect.height() - (zoomedSize.height() + margins[TopMa rgin] * zoomFactor + margins[BottomMargin] * zoomFactor);
211 IntRect result(zoomedRect); 205 IntRect result(zoomedRect);
212 if (widthDelta < 0) { 206 if (widthDelta < 0) {
213 result.setX(result.x() - margins[leftMargin] * zoomFactor); 207 result.setX(result.x() - margins[LeftMargin] * zoomFactor);
214 result.setWidth(result.width() - widthDelta); 208 result.setWidth(result.width() - widthDelta);
215 } 209 }
216 if (heightDelta < 0) { 210 if (heightDelta < 0) {
217 result.setY(result.y() - margins[topMargin] * zoomFactor); 211 result.setY(result.y() - margins[TopMargin] * zoomFactor);
218 result.setHeight(result.height() - heightDelta); 212 result.setHeight(result.height() - heightDelta);
219 } 213 }
220 return result; 214 return result;
221 } 215 }
222 216
217 // static
218 IntRect ThemeMac::inflateRectForAA(const IntRect& rect) {
219 const int margin = 2;
220 return IntRect(rect.x() - margin, rect.y() - margin, rect.width() + 2 * margin , rect.height() + 2 * margin);
221 }
222
223 // static
224 IntRect ThemeMac::inflateRectForFocusRing(const IntRect& rect) {
225 #if BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING
226 // Just put a margin of 16 units around the rect. The UI elements that use t his don't appropriately
227 // scale their focus rings appropriately (e.g, paint pickers), or switch to non-native widgets when
228 // scaled (e.g, check boxes and radio buttons).
229 const int margin = 16;
230 IntRect result;
231 result.setX(rect.x() - margin);
232 result.setY(rect.y() - margin);
233 result.setWidth(rect.width() + 2 * margin);
234 result.setHeight(rect.height() + 2 * margin);
235 return result;
236 #else
237 return rect;
238 #endif
239 }
240
223 // Checkboxes 241 // Checkboxes
224 242
225 static const IntSize* checkboxSizes() 243 static const IntSize* checkboxSizes()
226 { 244 {
227 static const IntSize sizes[3] = { IntSize(14, 14), IntSize(12, 12), IntSize( 10, 10) }; 245 static const IntSize sizes[3] = { IntSize(14, 14), IntSize(12, 12), IntSize( 10, 10) };
228 return sizes; 246 return sizes;
229 } 247 }
230 248
231 static const int* checkboxMargins(NSControlSize controlSize) 249 static const int* checkboxMargins(NSControlSize controlSize)
232 { 250 {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 BEGIN_BLOCK_OBJC_EXCEPTIONS 293 BEGIN_BLOCK_OBJC_EXCEPTIONS
276 294
277 // Determine the width and height needed for the control and prepare the cel l for painting. 295 // Determine the width and height needed for the control and prepare the cel l for painting.
278 NSButtonCell *checkboxCell = checkbox(states, zoomedRect, zoomFactor); 296 NSButtonCell *checkboxCell = checkbox(states, zoomedRect, zoomFactor);
279 GraphicsContextStateSaver stateSaver(*context); 297 GraphicsContextStateSaver stateSaver(*context);
280 298
281 NSControlSize controlSize = [checkboxCell controlSize]; 299 NSControlSize controlSize = [checkboxCell controlSize];
282 IntSize zoomedSize = checkboxSizes()[controlSize]; 300 IntSize zoomedSize = checkboxSizes()[controlSize];
283 zoomedSize.setWidth(zoomedSize.width() * zoomFactor); 301 zoomedSize.setWidth(zoomedSize.width() * zoomFactor);
284 zoomedSize.setHeight(zoomedSize.height() * zoomFactor); 302 zoomedSize.setHeight(zoomedSize.height() * zoomFactor);
285 IntRect inflatedRect = inflateRect(zoomedRect, zoomedSize, checkboxMargins(c ontrolSize), zoomFactor); 303 IntRect inflatedRect = ThemeMac::inflateRect(zoomedRect, zoomedSize, checkbo xMargins(controlSize), zoomFactor);
286 304
287 if (zoomFactor != 1.0f) { 305 if (zoomFactor != 1.0f) {
288 inflatedRect.setWidth(inflatedRect.width() / zoomFactor); 306 inflatedRect.setWidth(inflatedRect.width() / zoomFactor);
289 inflatedRect.setHeight(inflatedRect.height() / zoomFactor); 307 inflatedRect.setHeight(inflatedRect.height() / zoomFactor);
290 context->translate(inflatedRect.x(), inflatedRect.y()); 308 context->translate(inflatedRect.x(), inflatedRect.y());
291 context->scale(zoomFactor, zoomFactor); 309 context->scale(zoomFactor, zoomFactor);
292 context->translate(-inflatedRect.x(), -inflatedRect.y()); 310 context->translate(-inflatedRect.x(), -inflatedRect.y());
293 } 311 }
294 312
295 LocalCurrentGraphicsContext localContext(context); 313 LocalCurrentGraphicsContext localContext(context, ThemeMac::inflateRectForFo cusRing(inflatedRect));
296 NSView *view = ThemeMac::ensuredView(scrollView); 314 NSView *view = ThemeMac::ensuredView(scrollView);
297 [checkboxCell drawWithFrame:NSRect(inflatedRect) inView:view]; 315 [checkboxCell drawWithFrame:NSRect(inflatedRect) inView:view];
298 #if !BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING 316 #if !BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING
299 if (states & FocusControlState) 317 if (states & FocusControlState)
300 [checkboxCell _web_drawFocusRingWithFrame:NSRect(inflatedRect) inView:vi ew]; 318 [checkboxCell _web_drawFocusRingWithFrame:NSRect(inflatedRect) inView:vi ew];
301 #endif 319 #endif
302 [checkboxCell setControlView:nil]; 320 [checkboxCell setControlView:nil];
303 321
304 END_BLOCK_OBJC_EXCEPTIONS 322 END_BLOCK_OBJC_EXCEPTIONS
305 } 323 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 static void paintRadio(ControlStates states, GraphicsContext* context, const Int Rect& zoomedRect, float zoomFactor, ScrollView* scrollView) 375 static void paintRadio(ControlStates states, GraphicsContext* context, const Int Rect& zoomedRect, float zoomFactor, ScrollView* scrollView)
358 { 376 {
359 // Determine the width and height needed for the control and prepare the cel l for painting. 377 // Determine the width and height needed for the control and prepare the cel l for painting.
360 NSButtonCell *radioCell = radio(states, zoomedRect, zoomFactor); 378 NSButtonCell *radioCell = radio(states, zoomedRect, zoomFactor);
361 GraphicsContextStateSaver stateSaver(*context); 379 GraphicsContextStateSaver stateSaver(*context);
362 380
363 NSControlSize controlSize = [radioCell controlSize]; 381 NSControlSize controlSize = [radioCell controlSize];
364 IntSize zoomedSize = radioSizes()[controlSize]; 382 IntSize zoomedSize = radioSizes()[controlSize];
365 zoomedSize.setWidth(zoomedSize.width() * zoomFactor); 383 zoomedSize.setWidth(zoomedSize.width() * zoomFactor);
366 zoomedSize.setHeight(zoomedSize.height() * zoomFactor); 384 zoomedSize.setHeight(zoomedSize.height() * zoomFactor);
367 IntRect inflatedRect = inflateRect(zoomedRect, zoomedSize, radioMargins(cont rolSize), zoomFactor); 385 IntRect inflatedRect = ThemeMac::inflateRect(zoomedRect, zoomedSize, radioMa rgins(controlSize), zoomFactor);
368 386
369 if (zoomFactor != 1.0f) { 387 if (zoomFactor != 1.0f) {
370 inflatedRect.setWidth(inflatedRect.width() / zoomFactor); 388 inflatedRect.setWidth(inflatedRect.width() / zoomFactor);
371 inflatedRect.setHeight(inflatedRect.height() / zoomFactor); 389 inflatedRect.setHeight(inflatedRect.height() / zoomFactor);
372 context->translate(inflatedRect.x(), inflatedRect.y()); 390 context->translate(inflatedRect.x(), inflatedRect.y());
373 context->scale(zoomFactor, zoomFactor); 391 context->scale(zoomFactor, zoomFactor);
374 context->translate(-inflatedRect.x(), -inflatedRect.y()); 392 context->translate(-inflatedRect.x(), -inflatedRect.y());
375 } 393 }
376 394
377 LocalCurrentGraphicsContext localContext(context); 395 LocalCurrentGraphicsContext localContext(context, ThemeMac::inflateRectForFo cusRing(inflatedRect));
378 BEGIN_BLOCK_OBJC_EXCEPTIONS 396 BEGIN_BLOCK_OBJC_EXCEPTIONS
379 NSView *view = ThemeMac::ensuredView(scrollView); 397 NSView *view = ThemeMac::ensuredView(scrollView);
380 [radioCell drawWithFrame:NSRect(inflatedRect) inView:view]; 398 [radioCell drawWithFrame:NSRect(inflatedRect) inView:view];
381 #if !BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING 399 #if !BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING
382 if (states & FocusControlState) 400 if (states & FocusControlState)
383 [radioCell _web_drawFocusRingWithFrame:NSRect(inflatedRect) inView:view] ; 401 [radioCell _web_drawFocusRingWithFrame:NSRect(inflatedRect) inView:view] ;
384 #endif 402 #endif
385 [radioCell setControlView:nil]; 403 [radioCell setControlView:nil];
386 END_BLOCK_OBJC_EXCEPTIONS 404 END_BLOCK_OBJC_EXCEPTIONS
387 } 405 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 zoomedSize.setHeight(zoomedSize.height() * zoomFactor); 467 zoomedSize.setHeight(zoomedSize.height() * zoomFactor);
450 IntRect inflatedRect = zoomedRect; 468 IntRect inflatedRect = zoomedRect;
451 if ([buttonCell bezelStyle] == NSRoundedBezelStyle) { 469 if ([buttonCell bezelStyle] == NSRoundedBezelStyle) {
452 // Center the button within the available space. 470 // Center the button within the available space.
453 if (inflatedRect.height() > zoomedSize.height()) { 471 if (inflatedRect.height() > zoomedSize.height()) {
454 inflatedRect.setY(inflatedRect.y() + (inflatedRect.height() - zoomed Size.height()) / 2); 472 inflatedRect.setY(inflatedRect.y() + (inflatedRect.height() - zoomed Size.height()) / 2);
455 inflatedRect.setHeight(zoomedSize.height()); 473 inflatedRect.setHeight(zoomedSize.height());
456 } 474 }
457 475
458 // Now inflate it to account for the shadow. 476 // Now inflate it to account for the shadow.
459 inflatedRect = inflateRect(inflatedRect, zoomedSize, buttonMargins(contr olSize), zoomFactor); 477 inflatedRect = ThemeMac::inflateRect(inflatedRect, zoomedSize, buttonMar gins(controlSize), zoomFactor);
460 478
461 if (zoomFactor != 1.0f) { 479 if (zoomFactor != 1.0f) {
462 inflatedRect.setWidth(inflatedRect.width() / zoomFactor); 480 inflatedRect.setWidth(inflatedRect.width() / zoomFactor);
463 inflatedRect.setHeight(inflatedRect.height() / zoomFactor); 481 inflatedRect.setHeight(inflatedRect.height() / zoomFactor);
464 context->translate(inflatedRect.x(), inflatedRect.y()); 482 context->translate(inflatedRect.x(), inflatedRect.y());
465 context->scale(zoomFactor, zoomFactor); 483 context->scale(zoomFactor, zoomFactor);
466 context->translate(-inflatedRect.x(), -inflatedRect.y()); 484 context->translate(-inflatedRect.x(), -inflatedRect.y());
467 } 485 }
468 } 486 }
469 487
470 LocalCurrentGraphicsContext localContext(context); 488 LocalCurrentGraphicsContext localContext(context, ThemeMac::inflateRectForFo cusRing(inflatedRect));
471 NSView *view = ThemeMac::ensuredView(scrollView); 489 NSView *view = ThemeMac::ensuredView(scrollView);
472 490
473 [buttonCell drawWithFrame:NSRect(inflatedRect) inView:view]; 491 [buttonCell drawWithFrame:NSRect(inflatedRect) inView:view];
474 #if !BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING 492 #if !BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING
475 if (states & FocusControlState) 493 if (states & FocusControlState)
476 [buttonCell _web_drawFocusRingWithFrame:NSRect(inflatedRect) inView:view ]; 494 [buttonCell _web_drawFocusRingWithFrame:NSRect(inflatedRect) inView:view ];
477 #endif 495 #endif
478 [buttonCell setControlView:nil]; 496 [buttonCell setControlView:nil];
479 497
480 END_BLOCK_OBJC_EXCEPTIONS 498 END_BLOCK_OBJC_EXCEPTIONS
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 CGRect bounds(rect); 547 CGRect bounds(rect);
530 CGRect backgroundBounds; 548 CGRect backgroundBounds;
531 HIThemeGetButtonBackgroundBounds(&bounds, &drawInfo, &backgroundBounds); 549 HIThemeGetButtonBackgroundBounds(&bounds, &drawInfo, &backgroundBounds);
532 // Center the stepper rectangle in the specified area. 550 // Center the stepper rectangle in the specified area.
533 backgroundBounds.origin.x = bounds.origin.x + (bounds.size.width - backgroun dBounds.size.width) / 2; 551 backgroundBounds.origin.x = bounds.origin.x + (bounds.size.width - backgroun dBounds.size.width) / 2;
534 if (backgroundBounds.size.height < bounds.size.height) { 552 if (backgroundBounds.size.height < bounds.size.height) {
535 int heightDiff = clampToInteger(bounds.size.height - backgroundBounds.si ze.height); 553 int heightDiff = clampToInteger(bounds.size.height - backgroundBounds.si ze.height);
536 backgroundBounds.origin.y = bounds.origin.y + (heightDiff / 2) + 1; 554 backgroundBounds.origin.y = bounds.origin.y + (heightDiff / 2) + 1;
537 } 555 }
538 556
539 LocalCurrentGraphicsContext localContext(context); 557 LocalCurrentGraphicsContext localContext(context, rect);
540 HIThemeDrawButton(&backgroundBounds, &drawInfo, localContext.cgContext(), kH IThemeOrientationNormal, 0); 558 HIThemeDrawButton(&backgroundBounds, &drawInfo, localContext.cgContext(), kH IThemeOrientationNormal, 0);
541 } 559 }
542 560
543 // This will ensure that we always return a valid NSView, even if ScrollView doe sn't have an associated document NSView. 561 // This will ensure that we always return a valid NSView, even if ScrollView doe sn't have an associated document NSView.
544 // If the ScrollView doesn't have an NSView, we will return a fake NSView whose sole purpose is to tell AppKit that it's flipped. 562 // If the ScrollView doesn't have an NSView, we will return a fake NSView whose sole purpose is to tell AppKit that it's flipped.
545 NSView *ThemeMac::ensuredView(ScrollView* scrollView) 563 NSView *ThemeMac::ensuredView(ScrollView* scrollView)
546 { 564 {
547 565
548 // Use a fake flipped view. 566 // Use a fake flipped view.
549 static NSView *flippedView = [[WebCoreFlippedView alloc] init]; 567 static NSView *flippedView = [[WebCoreFlippedView alloc] init];
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 break; 737 break;
720 case InnerSpinButtonPart: 738 case InnerSpinButtonPart:
721 paintStepper(states, context, zoomedRect, zoomFactor, scrollView); 739 paintStepper(states, context, zoomedRect, zoomFactor, scrollView);
722 break; 740 break;
723 default: 741 default:
724 break; 742 break;
725 } 743 }
726 } 744 }
727 745
728 } 746 }
OLDNEW
« no previous file with comments | « Source/platform/mac/ThemeMac.h ('k') | Source/platform/scroll/ScrollbarThemeMacNonOverlayAPI.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698