| OLD | NEW |
| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 if ([[self familyName] hasPrefix:@"."]) | 84 if ([[self familyName] hasPrefix:@"."]) |
| 85 return [self fontName]; | 85 return [self fontName]; |
| 86 | 86 |
| 87 return [self familyName]; | 87 return [self familyName]; |
| 88 } | 88 } |
| 89 | 89 |
| 90 @end | 90 @end |
| 91 | 91 |
| 92 namespace blink { | 92 namespace blink { |
| 93 | 93 |
| 94 enum { | |
| 95 topMargin, | |
| 96 rightMargin, | |
| 97 bottomMargin, | |
| 98 leftMargin | |
| 99 }; | |
| 100 | |
| 101 Theme* platformTheme() | 94 Theme* platformTheme() |
| 102 { | 95 { |
| 103 DEFINE_STATIC_LOCAL(ThemeMac, themeMac, ()); | 96 DEFINE_STATIC_LOCAL(ThemeMac, themeMac, ()); |
| 104 return &themeMac; | 97 return &themeMac; |
| 105 } | 98 } |
| 106 | 99 |
| 107 // Helper functions used by a bunch of different control parts. | 100 // Helper functions used by a bunch of different control parts. |
| 108 | 101 |
| 109 static NSControlSize controlSizeForFont(const FontDescription& fontDescription) | 102 static NSControlSize controlSizeForFont(const FontDescription& fontDescription) |
| 110 { | 103 { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 | 190 |
| 198 // Do not process PressedState if !EnabledControlState or ReadOnlyControlSta
te. | 191 // Do not process PressedState if !EnabledControlState or ReadOnlyControlSta
te. |
| 199 if (states & PressedControlState) { | 192 if (states & PressedControlState) { |
| 200 if (kind == kThemeIncDecButton || kind == kThemeIncDecButtonSmall || kin
d == kThemeIncDecButtonMini) | 193 if (kind == kThemeIncDecButton || kind == kThemeIncDecButtonSmall || kin
d == kThemeIncDecButtonMini) |
| 201 return states & SpinUpControlState ? kThemeStatePressedUp : kThemeSt
atePressedDown; | 194 return states & SpinUpControlState ? kThemeStatePressedUp : kThemeSt
atePressedDown; |
| 202 return kThemeStatePressed; | 195 return kThemeStatePressed; |
| 203 } | 196 } |
| 204 return kThemeStateActive; | 197 return kThemeStateActive; |
| 205 } | 198 } |
| 206 | 199 |
| 207 static IntRect inflateRect(const IntRect& zoomedRect, const IntSize& zoomedSize,
const int* margins, float zoomFactor) | 200 // static |
| 201 IntRect ThemeMac::inflateRect(const IntRect& zoomedRect, const IntSize& zoomedSi
ze, const int* margins, float zoomFactor) |
| 208 { | 202 { |
| 209 // Only do the inflation if the available width/height are too small. Other
wise try to | 203 // Only do the inflation if the available width/height are too small. Other
wise try to |
| 210 // fit the glow/check space into the available box's width/height. | 204 // fit the glow/check space into the available box's width/height. |
| 211 int widthDelta = zoomedRect.width() - (zoomedSize.width() + margins[leftMarg
in] * zoomFactor + margins[rightMargin] * zoomFactor); | 205 int widthDelta = zoomedRect.width() - (zoomedSize.width() + margins[LeftMarg
in] * zoomFactor + margins[RightMargin] * zoomFactor); |
| 212 int heightDelta = zoomedRect.height() - (zoomedSize.height() + margins[topMa
rgin] * zoomFactor + margins[bottomMargin] * zoomFactor); | 206 int heightDelta = zoomedRect.height() - (zoomedSize.height() + margins[TopMa
rgin] * zoomFactor + margins[BottomMargin] * zoomFactor); |
| 213 IntRect result(zoomedRect); | 207 IntRect result(zoomedRect); |
| 214 if (widthDelta < 0) { | 208 if (widthDelta < 0) { |
| 215 result.setX(result.x() - margins[leftMargin] * zoomFactor); | 209 result.setX(result.x() - margins[LeftMargin] * zoomFactor); |
| 216 result.setWidth(result.width() - widthDelta); | 210 result.setWidth(result.width() - widthDelta); |
| 217 } | 211 } |
| 218 if (heightDelta < 0) { | 212 if (heightDelta < 0) { |
| 219 result.setY(result.y() - margins[topMargin] * zoomFactor); | 213 result.setY(result.y() - margins[TopMargin] * zoomFactor); |
| 220 result.setHeight(result.height() - heightDelta); | 214 result.setHeight(result.height() - heightDelta); |
| 221 } | 215 } |
| 222 return result; | 216 return result; |
| 223 } | 217 } |
| 224 | 218 |
| 219 // static |
| 220 IntRect ThemeMac::inflateRectForAA(const IntRect& rect) { |
| 221 const int margin = 2; |
| 222 return IntRect(rect.x() - margin, rect.y() - margin, rect.width() + 2 * margin
, rect.height() + 2 * margin); |
| 223 } |
| 224 |
| 225 // static |
| 226 IntRect ThemeMac::inflateRectForFocusRing(const IntRect& rect) { |
| 227 #if BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING |
| 228 // Just put a margin of 16 units around the rect. The UI elements that use t
his don't appropriately |
| 229 // scale their focus rings appropriately (e.g, paint pickers), or switch to
non-native widgets when |
| 230 // scaled (e.g, check boxes and radio buttons). |
| 231 const int margin = 16; |
| 232 IntRect result; |
| 233 result.setX(rect.x() - margin); |
| 234 result.setY(rect.y() - margin); |
| 235 result.setWidth(rect.width() + 2 * margin); |
| 236 result.setHeight(rect.height() + 2 * margin); |
| 237 return result; |
| 238 #else |
| 239 return rect; |
| 240 #endif |
| 241 } |
| 242 |
| 225 // Checkboxes | 243 // Checkboxes |
| 226 | 244 |
| 227 static const IntSize* checkboxSizes() | 245 static const IntSize* checkboxSizes() |
| 228 { | 246 { |
| 229 static const IntSize sizes[3] = { IntSize(14, 14), IntSize(12, 12), IntSize(
10, 10) }; | 247 static const IntSize sizes[3] = { IntSize(14, 14), IntSize(12, 12), IntSize(
10, 10) }; |
| 230 return sizes; | 248 return sizes; |
| 231 } | 249 } |
| 232 | 250 |
| 233 static const int* checkboxMargins(NSControlSize controlSize) | 251 static const int* checkboxMargins(NSControlSize controlSize) |
| 234 { | 252 { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 BEGIN_BLOCK_OBJC_EXCEPTIONS | 295 BEGIN_BLOCK_OBJC_EXCEPTIONS |
| 278 | 296 |
| 279 // Determine the width and height needed for the control and prepare the cel
l for painting. | 297 // Determine the width and height needed for the control and prepare the cel
l for painting. |
| 280 NSButtonCell *checkboxCell = checkbox(states, zoomedRect, zoomFactor); | 298 NSButtonCell *checkboxCell = checkbox(states, zoomedRect, zoomFactor); |
| 281 GraphicsContextStateSaver stateSaver(*context); | 299 GraphicsContextStateSaver stateSaver(*context); |
| 282 | 300 |
| 283 NSControlSize controlSize = [checkboxCell controlSize]; | 301 NSControlSize controlSize = [checkboxCell controlSize]; |
| 284 IntSize zoomedSize = checkboxSizes()[controlSize]; | 302 IntSize zoomedSize = checkboxSizes()[controlSize]; |
| 285 zoomedSize.setWidth(zoomedSize.width() * zoomFactor); | 303 zoomedSize.setWidth(zoomedSize.width() * zoomFactor); |
| 286 zoomedSize.setHeight(zoomedSize.height() * zoomFactor); | 304 zoomedSize.setHeight(zoomedSize.height() * zoomFactor); |
| 287 IntRect inflatedRect = inflateRect(zoomedRect, zoomedSize, checkboxMargins(c
ontrolSize), zoomFactor); | 305 IntRect inflatedRect = ThemeMac::inflateRect(zoomedRect, zoomedSize, checkbo
xMargins(controlSize), zoomFactor); |
| 288 | 306 |
| 289 if (zoomFactor != 1.0f) { | 307 if (zoomFactor != 1.0f) { |
| 290 inflatedRect.setWidth(inflatedRect.width() / zoomFactor); | 308 inflatedRect.setWidth(inflatedRect.width() / zoomFactor); |
| 291 inflatedRect.setHeight(inflatedRect.height() / zoomFactor); | 309 inflatedRect.setHeight(inflatedRect.height() / zoomFactor); |
| 292 context->translate(inflatedRect.x(), inflatedRect.y()); | 310 context->translate(inflatedRect.x(), inflatedRect.y()); |
| 293 context->scale(zoomFactor, zoomFactor); | 311 context->scale(zoomFactor, zoomFactor); |
| 294 context->translate(-inflatedRect.x(), -inflatedRect.y()); | 312 context->translate(-inflatedRect.x(), -inflatedRect.y()); |
| 295 } | 313 } |
| 296 | 314 |
| 297 LocalCurrentGraphicsContext localContext(context); | 315 LocalCurrentGraphicsContext localContext(context, ThemeMac::inflateRectForFo
cusRing(inflatedRect)); |
| 298 NSView *view = ThemeMac::ensuredView(scrollView); | 316 NSView *view = ThemeMac::ensuredView(scrollView); |
| 299 [checkboxCell drawWithFrame:NSRect(inflatedRect) inView:view]; | 317 [checkboxCell drawWithFrame:NSRect(inflatedRect) inView:view]; |
| 300 #if !BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING | 318 #if !BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING |
| 301 if (states & FocusControlState) | 319 if (states & FocusControlState) |
| 302 [checkboxCell _web_drawFocusRingWithFrame:NSRect(inflatedRect) inView:vi
ew]; | 320 [checkboxCell _web_drawFocusRingWithFrame:NSRect(inflatedRect) inView:vi
ew]; |
| 303 #endif | 321 #endif |
| 304 [checkboxCell setControlView:nil]; | 322 [checkboxCell setControlView:nil]; |
| 305 | 323 |
| 306 END_BLOCK_OBJC_EXCEPTIONS | 324 END_BLOCK_OBJC_EXCEPTIONS |
| 307 } | 325 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 } |
| OLD | NEW |