| 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 bool pressed = states & PressedControlState; | 134 bool pressed = states & PressedControlState; |
| 135 if (pressed != oldPressed) | 135 if (pressed != oldPressed) |
| 136 [cell setHighlighted:pressed]; | 136 [cell setHighlighted:pressed]; |
| 137 | 137 |
| 138 // Enabled state | 138 // Enabled state |
| 139 bool oldEnabled = [cell isEnabled]; | 139 bool oldEnabled = [cell isEnabled]; |
| 140 bool enabled = states & EnabledControlState; | 140 bool enabled = states & EnabledControlState; |
| 141 if (enabled != oldEnabled) | 141 if (enabled != oldEnabled) |
| 142 [cell setEnabled:enabled]; | 142 [cell setEnabled:enabled]; |
| 143 | 143 |
| 144 #if BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING | 144 if (ThemeMac::drawWithFrameDrawsFocusRing()) { |
| 145 // Focused state | 145 // Focused state |
| 146 bool oldFocused = [cell showsFirstResponder]; | 146 bool oldFocused = [cell showsFirstResponder]; |
| 147 bool focused = states & FocusControlState; | 147 bool focused = states & FocusControlState; |
| 148 if (focused != oldFocused) | 148 if (focused != oldFocused) |
| 149 [cell setShowsFirstResponder:focused]; | 149 [cell setShowsFirstResponder:focused]; |
| 150 #endif | 150 } |
| 151 | 151 |
| 152 // Checked and Indeterminate | 152 // Checked and Indeterminate |
| 153 bool oldIndeterminate = [cell state] == NSMixedState; | 153 bool oldIndeterminate = [cell state] == NSMixedState; |
| 154 bool indeterminate = (states & IndeterminateControlState); | 154 bool indeterminate = (states & IndeterminateControlState); |
| 155 bool checked = states & CheckedControlState; | 155 bool checked = states & CheckedControlState; |
| 156 bool oldChecked = [cell state] == NSOnState; | 156 bool oldChecked = [cell state] == NSOnState; |
| 157 if (oldIndeterminate != indeterminate || checked != oldChecked) | 157 if (oldIndeterminate != indeterminate || checked != oldChecked) |
| 158 [cell setState:indeterminate ? NSMixedState : (checked ? NSOnState : NSO
ffState)]; | 158 [cell setState:indeterminate ? NSMixedState : (checked ? NSOnState : NSO
ffState)]; |
| 159 | 159 |
| 160 // Window inactive state does not need to be checked explicitly, since we pa
int parented to | 160 // Window inactive state does not need to be checked explicitly, since we pa
int parented to |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 } | 207 } |
| 208 | 208 |
| 209 // static | 209 // static |
| 210 IntRect ThemeMac::inflateRectForAA(const IntRect& rect) { | 210 IntRect ThemeMac::inflateRectForAA(const IntRect& rect) { |
| 211 const int margin = 2; | 211 const int margin = 2; |
| 212 return IntRect(rect.x() - margin, rect.y() - margin, rect.width() + 2 * margin
, rect.height() + 2 * margin); | 212 return IntRect(rect.x() - margin, rect.y() - margin, rect.width() + 2 * margin
, rect.height() + 2 * margin); |
| 213 } | 213 } |
| 214 | 214 |
| 215 // static | 215 // static |
| 216 IntRect ThemeMac::inflateRectForFocusRing(const IntRect& rect) { | 216 IntRect ThemeMac::inflateRectForFocusRing(const IntRect& rect) { |
| 217 #if BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING | 217 if (ThemeMac::drawWithFrameDrawsFocusRing()) { |
| 218 // Just put a margin of 16 units around the rect. The UI elements that use t
his don't appropriately | 218 // Just put a margin of 16 units around the rect. The UI elements that u
se this don't appropriately |
| 219 // scale their focus rings appropriately (e.g, paint pickers), or switch to
non-native widgets when | 219 // scale their focus rings appropriately (e.g, paint pickers), or switch
to non-native widgets when |
| 220 // scaled (e.g, check boxes and radio buttons). | 220 // scaled (e.g, check boxes and radio buttons). |
| 221 const int margin = 16; | 221 const int margin = 16; |
| 222 IntRect result; | 222 IntRect result; |
| 223 result.setX(rect.x() - margin); | 223 result.setX(rect.x() - margin); |
| 224 result.setY(rect.y() - margin); | 224 result.setY(rect.y() - margin); |
| 225 result.setWidth(rect.width() + 2 * margin); | 225 result.setWidth(rect.width() + 2 * margin); |
| 226 result.setHeight(rect.height() + 2 * margin); | 226 result.setHeight(rect.height() + 2 * margin); |
| 227 return result; | 227 return result; |
| 228 #else | 228 } else { |
| 229 return rect; | 229 return rect; |
| 230 #endif | 230 } |
| 231 } | 231 } |
| 232 | 232 |
| 233 // Checkboxes | 233 // Checkboxes |
| 234 | 234 |
| 235 static const IntSize* checkboxSizes() | 235 static const IntSize* checkboxSizes() |
| 236 { | 236 { |
| 237 static const IntSize sizes[3] = { IntSize(14, 14), IntSize(12, 12), IntSize(
10, 10) }; | 237 static const IntSize sizes[3] = { IntSize(14, 14), IntSize(12, 12), IntSize(
10, 10) }; |
| 238 return sizes; | 238 return sizes; |
| 239 } | 239 } |
| 240 | 240 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 inflatedRect.setWidth(inflatedRect.width() / zoomFactor); | 298 inflatedRect.setWidth(inflatedRect.width() / zoomFactor); |
| 299 inflatedRect.setHeight(inflatedRect.height() / zoomFactor); | 299 inflatedRect.setHeight(inflatedRect.height() / zoomFactor); |
| 300 context->translate(inflatedRect.x(), inflatedRect.y()); | 300 context->translate(inflatedRect.x(), inflatedRect.y()); |
| 301 context->scale(zoomFactor, zoomFactor); | 301 context->scale(zoomFactor, zoomFactor); |
| 302 context->translate(-inflatedRect.x(), -inflatedRect.y()); | 302 context->translate(-inflatedRect.x(), -inflatedRect.y()); |
| 303 } | 303 } |
| 304 | 304 |
| 305 LocalCurrentGraphicsContext localContext(context, ThemeMac::inflateRectForFo
cusRing(inflatedRect)); | 305 LocalCurrentGraphicsContext localContext(context, ThemeMac::inflateRectForFo
cusRing(inflatedRect)); |
| 306 NSView* view = ensuredView(scrollableArea); | 306 NSView* view = ensuredView(scrollableArea); |
| 307 [checkboxCell drawWithFrame:NSRect(inflatedRect) inView:view]; | 307 [checkboxCell drawWithFrame:NSRect(inflatedRect) inView:view]; |
| 308 #if !BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING | 308 if (!ThemeMac::drawWithFrameDrawsFocusRing() && states & FocusControlState) |
| 309 if (states & FocusControlState) | 309 [checkboxCell cr_drawFocusRingWithFrame:NSRect(inflatedRect) inView:view
]; |
| 310 [checkboxCell _web_drawFocusRingWithFrame:NSRect(inflatedRect) inView:vi
ew]; | |
| 311 #endif | |
| 312 [checkboxCell setControlView:nil]; | 310 [checkboxCell setControlView:nil]; |
| 313 | 311 |
| 314 END_BLOCK_OBJC_EXCEPTIONS | 312 END_BLOCK_OBJC_EXCEPTIONS |
| 315 } | 313 } |
| 316 | 314 |
| 317 // Radio Buttons | 315 // Radio Buttons |
| 318 | 316 |
| 319 static const IntSize* radioSizes() | 317 static const IntSize* radioSizes() |
| 320 { | 318 { |
| 321 static const IntSize sizes[3] = { IntSize(14, 15), IntSize(12, 13), IntSize(
10, 10) }; | 319 static const IntSize sizes[3] = { IntSize(14, 15), IntSize(12, 13), IntSize(
10, 10) }; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 inflatedRect.setHeight(inflatedRect.height() / zoomFactor); | 379 inflatedRect.setHeight(inflatedRect.height() / zoomFactor); |
| 382 context->translate(inflatedRect.x(), inflatedRect.y()); | 380 context->translate(inflatedRect.x(), inflatedRect.y()); |
| 383 context->scale(zoomFactor, zoomFactor); | 381 context->scale(zoomFactor, zoomFactor); |
| 384 context->translate(-inflatedRect.x(), -inflatedRect.y()); | 382 context->translate(-inflatedRect.x(), -inflatedRect.y()); |
| 385 } | 383 } |
| 386 | 384 |
| 387 LocalCurrentGraphicsContext localContext(context, ThemeMac::inflateRectForFo
cusRing(inflatedRect)); | 385 LocalCurrentGraphicsContext localContext(context, ThemeMac::inflateRectForFo
cusRing(inflatedRect)); |
| 388 BEGIN_BLOCK_OBJC_EXCEPTIONS | 386 BEGIN_BLOCK_OBJC_EXCEPTIONS |
| 389 NSView* view = ensuredView(scrollableArea); | 387 NSView* view = ensuredView(scrollableArea); |
| 390 [radioCell drawWithFrame:NSRect(inflatedRect) inView:view]; | 388 [radioCell drawWithFrame:NSRect(inflatedRect) inView:view]; |
| 391 #if !BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING | 389 if (!ThemeMac::drawWithFrameDrawsFocusRing() && states & FocusControlState) |
| 392 if (states & FocusControlState) | 390 [radioCell cr_drawFocusRingWithFrame:NSRect(inflatedRect) inView:view]; |
| 393 [radioCell _web_drawFocusRingWithFrame:NSRect(inflatedRect) inView:view]
; | |
| 394 #endif | |
| 395 [radioCell setControlView:nil]; | 391 [radioCell setControlView:nil]; |
| 396 END_BLOCK_OBJC_EXCEPTIONS | 392 END_BLOCK_OBJC_EXCEPTIONS |
| 397 } | 393 } |
| 398 | 394 |
| 399 // Buttons | 395 // Buttons |
| 400 | 396 |
| 401 // Buttons really only constrain height. They respect width. | 397 // Buttons really only constrain height. They respect width. |
| 402 static const IntSize* buttonSizes() | 398 static const IntSize* buttonSizes() |
| 403 { | 399 { |
| 404 static const IntSize sizes[3] = { IntSize(0, 21), IntSize(0, 18), IntSize(0,
15) }; | 400 static const IntSize sizes[3] = { IntSize(0, 21), IntSize(0, 18), IntSize(0,
15) }; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 context->translate(inflatedRect.x(), inflatedRect.y()); | 470 context->translate(inflatedRect.x(), inflatedRect.y()); |
| 475 context->scale(zoomFactor, zoomFactor); | 471 context->scale(zoomFactor, zoomFactor); |
| 476 context->translate(-inflatedRect.x(), -inflatedRect.y()); | 472 context->translate(-inflatedRect.x(), -inflatedRect.y()); |
| 477 } | 473 } |
| 478 } | 474 } |
| 479 | 475 |
| 480 LocalCurrentGraphicsContext localContext(context, ThemeMac::inflateRectForFo
cusRing(inflatedRect)); | 476 LocalCurrentGraphicsContext localContext(context, ThemeMac::inflateRectForFo
cusRing(inflatedRect)); |
| 481 NSView* view = ensuredView(scrollableArea); | 477 NSView* view = ensuredView(scrollableArea); |
| 482 | 478 |
| 483 [buttonCell drawWithFrame:NSRect(inflatedRect) inView:view]; | 479 [buttonCell drawWithFrame:NSRect(inflatedRect) inView:view]; |
| 484 #if !BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING | 480 if (!ThemeMac::drawWithFrameDrawsFocusRing() && states & FocusControlState) |
| 485 if (states & FocusControlState) | 481 [buttonCell cr_drawFocusRingWithFrame:NSRect(inflatedRect) inView:view]; |
| 486 [buttonCell _web_drawFocusRingWithFrame:NSRect(inflatedRect) inView:view
]; | |
| 487 #endif | |
| 488 [buttonCell setControlView:nil]; | 482 [buttonCell setControlView:nil]; |
| 489 | 483 |
| 490 END_BLOCK_OBJC_EXCEPTIONS | 484 END_BLOCK_OBJC_EXCEPTIONS |
| 491 } | 485 } |
| 492 | 486 |
| 493 // Stepper | 487 // Stepper |
| 494 | 488 |
| 495 static const IntSize* stepperSizes() | 489 static const IntSize* stepperSizes() |
| 496 { | 490 { |
| 497 static const IntSize sizes[3] = { IntSize(19, 27), IntSize(15, 22), IntSize(
13, 15) }; | 491 static const IntSize sizes[3] = { IntSize(19, 27), IntSize(15, 22), IntSize(
13, 15) }; |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 paintButton(part, states, context, zoomedRect, zoomFactor, scrollabl
eArea); | 705 paintButton(part, states, context, zoomedRect, zoomFactor, scrollabl
eArea); |
| 712 break; | 706 break; |
| 713 case InnerSpinButtonPart: | 707 case InnerSpinButtonPart: |
| 714 paintStepper(states, context, zoomedRect, zoomFactor, scrollableArea
); | 708 paintStepper(states, context, zoomedRect, zoomFactor, scrollableArea
); |
| 715 break; | 709 break; |
| 716 default: | 710 default: |
| 717 break; | 711 break; |
| 718 } | 712 } |
| 719 } | 713 } |
| 720 | 714 |
| 715 #ifndef NSAppKitVersionNumber10_9 |
| 716 #define NSAppKitVersionNumber10_9 1265 |
| 717 #endif |
| 718 |
| 719 bool ThemeMac::drawWithFrameDrawsFocusRing() |
| 720 { |
| 721 // drawWithFrame has changed in 10.10 Yosemite and it does not draw the focu
s ring. |
| 722 return floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_9; |
| 721 } | 723 } |
| 724 |
| 725 } |
| OLD | NEW |