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

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

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