| 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 |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #import "config.h" | 26 #import "config.h" |
| 27 #import "platform/mac/ThemeMac.h" | 27 #import "platform/mac/ThemeMac.h" |
| 28 | 28 |
| 29 #import <Carbon/Carbon.h> | 29 #import <Carbon/Carbon.h> |
| 30 #import "platform/graphics/GraphicsContextStateSaver.h" | 30 #import "platform/graphics/GraphicsContextStateSaver.h" |
| 31 #import "platform/mac/BlockExceptions.h" | 31 #import "platform/mac/BlockExceptions.h" |
| 32 #import "platform/mac/LocalCurrentGraphicsContext.h" | 32 #import "platform/mac/LocalCurrentGraphicsContext.h" |
| 33 #import "platform/mac/WebCoreNSCellExtras.h" | 33 #import "platform/mac/WebCoreNSCellExtras.h" |
| 34 #import "platform/scroll/ScrollView.h" | 34 #import "platform/scroll/ScrollableArea.h" |
| 35 #include "wtf/StdLibExtras.h" | 35 #include "wtf/StdLibExtras.h" |
| 36 | 36 |
| 37 NSRect focusRingClipRect; | 37 NSRect focusRingClipRect; |
| 38 | 38 |
| 39 // This is a view whose sole purpose is to tell AppKit that it's flipped. | 39 // This is a view whose sole purpose is to tell AppKit that it's flipped. |
| 40 @interface WebCoreFlippedView : NSControl | 40 @interface WebCoreFlippedView : NSControl |
| 41 @end | 41 @end |
| 42 | 42 |
| 43 @implementation WebCoreFlippedView | 43 @implementation WebCoreFlippedView |
| 44 | 44 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 static void setControlSize(NSCell* cell, const IntSize* sizes, const IntSize& mi
nZoomedSize, float zoomFactor) | 139 static void setControlSize(NSCell* cell, const IntSize* sizes, const IntSize& mi
nZoomedSize, float zoomFactor) |
| 140 { | 140 { |
| 141 ControlSize size = controlSizeFromPixelSize(sizes, minZoomedSize, zoomFactor
); | 141 ControlSize size = controlSizeFromPixelSize(sizes, minZoomedSize, zoomFactor
); |
| 142 if (size != [cell controlSize]) // Only update if we have to, since AppKit d
oes work even if the size is the same. | 142 if (size != [cell controlSize]) // Only update if we have to, since AppKit d
oes work even if the size is the same. |
| 143 [cell setControlSize:(NSControlSize)size]; | 143 [cell setControlSize:(NSControlSize)size]; |
| 144 } | 144 } |
| 145 | 145 |
| 146 static void updateStates(NSCell* cell, ControlStates states) | 146 static void updateStates(NSCell* cell, ControlStates states) |
| 147 { | 147 { |
| 148 // Hover state is not supported by Aqua. | 148 // Hover state is not supported by Aqua. |
| 149 | 149 |
| 150 // Pressed state | 150 // Pressed state |
| 151 bool oldPressed = [cell isHighlighted]; | 151 bool oldPressed = [cell isHighlighted]; |
| 152 bool pressed = states & PressedControlState; | 152 bool pressed = states & PressedControlState; |
| 153 if (pressed != oldPressed) | 153 if (pressed != oldPressed) |
| 154 [cell setHighlighted:pressed]; | 154 [cell setHighlighted:pressed]; |
| 155 | 155 |
| 156 // Enabled state | 156 // Enabled state |
| 157 bool oldEnabled = [cell isEnabled]; | 157 bool oldEnabled = [cell isEnabled]; |
| 158 bool enabled = states & EnabledControlState; | 158 bool enabled = states & EnabledControlState; |
| 159 if (enabled != oldEnabled) | 159 if (enabled != oldEnabled) |
| 160 [cell setEnabled:enabled]; | 160 [cell setEnabled:enabled]; |
| 161 | 161 |
| 162 #if BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING | 162 #if BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING |
| 163 // Focused state | 163 // Focused state |
| 164 bool oldFocused = [cell showsFirstResponder]; | 164 bool oldFocused = [cell showsFirstResponder]; |
| 165 bool focused = states & FocusControlState; | 165 bool focused = states & FocusControlState; |
| 166 if (focused != oldFocused) | 166 if (focused != oldFocused) |
| 167 [cell setShowsFirstResponder:focused]; | 167 [cell setShowsFirstResponder:focused]; |
| 168 #endif | 168 #endif |
| 169 | 169 |
| 170 // Checked and Indeterminate | 170 // Checked and Indeterminate |
| 171 bool oldIndeterminate = [cell state] == NSMixedState; | 171 bool oldIndeterminate = [cell state] == NSMixedState; |
| 172 bool indeterminate = (states & IndeterminateControlState); | 172 bool indeterminate = (states & IndeterminateControlState); |
| 173 bool checked = states & CheckedControlState; | 173 bool checked = states & CheckedControlState; |
| 174 bool oldChecked = [cell state] == NSOnState; | 174 bool oldChecked = [cell state] == NSOnState; |
| 175 if (oldIndeterminate != indeterminate || checked != oldChecked) | 175 if (oldIndeterminate != indeterminate || checked != oldChecked) |
| 176 [cell setState:indeterminate ? NSMixedState : (checked ? NSOnState : NSO
ffState)]; | 176 [cell setState:indeterminate ? NSMixedState : (checked ? NSOnState : NSO
ffState)]; |
| 177 | 177 |
| 178 // Window inactive state does not need to be checked explicitly, since we pa
int parented to | 178 // Window inactive state does not need to be checked explicitly, since we pa
int parented to |
| 179 // a view in a window whose key state can be detected. | 179 // a view in a window whose key state can be detected. |
| 180 } | 180 } |
| 181 | 181 |
| 182 static ThemeDrawState convertControlStatesToThemeDrawState(ThemeButtonKind kind,
ControlStates states) | 182 static ThemeDrawState convertControlStatesToThemeDrawState(ThemeButtonKind kind,
ControlStates states) |
| 183 { | 183 { |
| 184 if (states & ReadOnlyControlState) | 184 if (states & ReadOnlyControlState) |
| 185 return kThemeStateUnavailableInactive; | 185 return kThemeStateUnavailableInactive; |
| 186 if (!(states & EnabledControlState)) | 186 if (!(states & EnabledControlState)) |
| 187 return kThemeStateUnavailableInactive; | 187 return kThemeStateUnavailableInactive; |
| 188 | 188 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 static NSButtonCell *checkbox(ControlStates states, const IntRect& zoomedRect, f
loat zoomFactor) | 270 static NSButtonCell *checkbox(ControlStates states, const IntRect& zoomedRect, f
loat zoomFactor) |
| 271 { | 271 { |
| 272 static NSButtonCell *checkboxCell; | 272 static NSButtonCell *checkboxCell; |
| 273 if (!checkboxCell) { | 273 if (!checkboxCell) { |
| 274 checkboxCell = [[NSButtonCell alloc] init]; | 274 checkboxCell = [[NSButtonCell alloc] init]; |
| 275 [checkboxCell setButtonType:NSSwitchButton]; | 275 [checkboxCell setButtonType:NSSwitchButton]; |
| 276 [checkboxCell setTitle:nil]; | 276 [checkboxCell setTitle:nil]; |
| 277 [checkboxCell setAllowsMixedState:YES]; | 277 [checkboxCell setAllowsMixedState:YES]; |
| 278 [checkboxCell setFocusRingType:NSFocusRingTypeExterior]; | 278 [checkboxCell setFocusRingType:NSFocusRingTypeExterior]; |
| 279 } | 279 } |
| 280 | 280 |
| 281 // Set the control size based off the rectangle we're painting into. | 281 // Set the control size based off the rectangle we're painting into. |
| 282 setControlSize(checkboxCell, checkboxSizes(), zoomedRect.size(), zoomFactor)
; | 282 setControlSize(checkboxCell, checkboxSizes(), zoomedRect.size(), zoomFactor)
; |
| 283 | 283 |
| 284 // Update the various states we respond to. | 284 // Update the various states we respond to. |
| 285 updateStates(checkboxCell, states); | 285 updateStates(checkboxCell, states); |
| 286 | 286 |
| 287 return checkboxCell; | 287 return checkboxCell; |
| 288 } | 288 } |
| 289 | 289 |
| 290 // FIXME: Share more code with radio buttons. | 290 // FIXME: Share more code with radio buttons. |
| 291 static void paintCheckbox(ControlStates states, GraphicsContext* context, const
IntRect& zoomedRect, float zoomFactor, ScrollView* scrollView) | 291 static void paintCheckbox(ControlStates states, GraphicsContext* context, const
IntRect& zoomedRect, float zoomFactor, ScrollableArea* scrollView) |
| 292 { | 292 { |
| 293 BEGIN_BLOCK_OBJC_EXCEPTIONS | 293 BEGIN_BLOCK_OBJC_EXCEPTIONS |
| 294 | 294 |
| 295 // 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. |
| 296 NSButtonCell *checkboxCell = checkbox(states, zoomedRect, zoomFactor); | 296 NSButtonCell *checkboxCell = checkbox(states, zoomedRect, zoomFactor); |
| 297 GraphicsContextStateSaver stateSaver(*context); | 297 GraphicsContextStateSaver stateSaver(*context); |
| 298 | 298 |
| 299 NSControlSize controlSize = [checkboxCell controlSize]; | 299 NSControlSize controlSize = [checkboxCell controlSize]; |
| 300 IntSize zoomedSize = checkboxSizes()[controlSize]; | 300 IntSize zoomedSize = checkboxSizes()[controlSize]; |
| 301 zoomedSize.setWidth(zoomedSize.width() * zoomFactor); | 301 zoomedSize.setWidth(zoomedSize.width() * zoomFactor); |
| 302 zoomedSize.setHeight(zoomedSize.height() * zoomFactor); | 302 zoomedSize.setHeight(zoomedSize.height() * zoomFactor); |
| 303 IntRect inflatedRect = ThemeMac::inflateRect(zoomedRect, zoomedSize, checkbo
xMargins(controlSize), zoomFactor); | 303 IntRect inflatedRect = ThemeMac::inflateRect(zoomedRect, zoomedSize, checkbo
xMargins(controlSize), zoomFactor); |
| 304 | 304 |
| 305 if (zoomFactor != 1.0f) { | 305 if (zoomFactor != 1.0f) { |
| 306 inflatedRect.setWidth(inflatedRect.width() / zoomFactor); | 306 inflatedRect.setWidth(inflatedRect.width() / zoomFactor); |
| 307 inflatedRect.setHeight(inflatedRect.height() / zoomFactor); | 307 inflatedRect.setHeight(inflatedRect.height() / zoomFactor); |
| 308 context->translate(inflatedRect.x(), inflatedRect.y()); | 308 context->translate(inflatedRect.x(), inflatedRect.y()); |
| 309 context->scale(zoomFactor, zoomFactor); | 309 context->scale(zoomFactor, zoomFactor); |
| 310 context->translate(-inflatedRect.x(), -inflatedRect.y()); | 310 context->translate(-inflatedRect.x(), -inflatedRect.y()); |
| 311 } | 311 } |
| 312 | 312 |
| 313 LocalCurrentGraphicsContext localContext(context, ThemeMac::inflateRectForFo
cusRing(inflatedRect)); | 313 LocalCurrentGraphicsContext localContext(context, ThemeMac::inflateRectForFo
cusRing(inflatedRect)); |
| 314 NSView *view = ThemeMac::ensuredView(scrollView); | 314 NSView *view = ThemeMac::ensuredView(scrollView); |
| 315 [checkboxCell drawWithFrame:NSRect(inflatedRect) inView:view]; | 315 [checkboxCell drawWithFrame:NSRect(inflatedRect) inView:view]; |
| 316 #if !BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING | 316 #if !BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING |
| 317 if (states & FocusControlState) | 317 if (states & FocusControlState) |
| 318 [checkboxCell _web_drawFocusRingWithFrame:NSRect(inflatedRect) inView:vi
ew]; | 318 [checkboxCell _web_drawFocusRingWithFrame:NSRect(inflatedRect) inView:vi
ew]; |
| 319 #endif | 319 #endif |
| 320 [checkboxCell setControlView:nil]; | 320 [checkboxCell setControlView:nil]; |
| 321 | 321 |
| 322 END_BLOCK_OBJC_EXCEPTIONS | 322 END_BLOCK_OBJC_EXCEPTIONS |
| 323 } | 323 } |
| 324 | 324 |
| 325 // Radio Buttons | 325 // Radio Buttons |
| 326 | 326 |
| 327 static const IntSize* radioSizes() | 327 static const IntSize* radioSizes() |
| 328 { | 328 { |
| 329 static const IntSize sizes[3] = { IntSize(14, 15), IntSize(12, 13), IntSize(
10, 10) }; | 329 static const IntSize sizes[3] = { IntSize(14, 15), IntSize(12, 13), IntSize(
10, 10) }; |
| 330 return sizes; | 330 return sizes; |
| 331 } | 331 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 353 | 353 |
| 354 static NSButtonCell *radio(ControlStates states, const IntRect& zoomedRect, floa
t zoomFactor) | 354 static NSButtonCell *radio(ControlStates states, const IntRect& zoomedRect, floa
t zoomFactor) |
| 355 { | 355 { |
| 356 static NSButtonCell *radioCell; | 356 static NSButtonCell *radioCell; |
| 357 if (!radioCell) { | 357 if (!radioCell) { |
| 358 radioCell = [[NSButtonCell alloc] init]; | 358 radioCell = [[NSButtonCell alloc] init]; |
| 359 [radioCell setButtonType:NSRadioButton]; | 359 [radioCell setButtonType:NSRadioButton]; |
| 360 [radioCell setTitle:nil]; | 360 [radioCell setTitle:nil]; |
| 361 [radioCell setFocusRingType:NSFocusRingTypeExterior]; | 361 [radioCell setFocusRingType:NSFocusRingTypeExterior]; |
| 362 } | 362 } |
| 363 | 363 |
| 364 // Set the control size based off the rectangle we're painting into. | 364 // Set the control size based off the rectangle we're painting into. |
| 365 setControlSize(radioCell, radioSizes(), zoomedRect.size(), zoomFactor); | 365 setControlSize(radioCell, radioSizes(), zoomedRect.size(), zoomFactor); |
| 366 | 366 |
| 367 // Update the various states we respond to. | 367 // Update the various states we respond to. |
| 368 // Cocoa draws NSMixedState NSRadioButton as NSOnState so we don't want that
. | 368 // Cocoa draws NSMixedState NSRadioButton as NSOnState so we don't want that
. |
| 369 states &= ~IndeterminateControlState; | 369 states &= ~IndeterminateControlState; |
| 370 updateStates(radioCell, states); | 370 updateStates(radioCell, states); |
| 371 | 371 |
| 372 return radioCell; | 372 return radioCell; |
| 373 } | 373 } |
| 374 | 374 |
| 375 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, ScrollableArea* scrollView) |
| 376 { | 376 { |
| 377 // 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. |
| 378 NSButtonCell *radioCell = radio(states, zoomedRect, zoomFactor); | 378 NSButtonCell *radioCell = radio(states, zoomedRect, zoomFactor); |
| 379 GraphicsContextStateSaver stateSaver(*context); | 379 GraphicsContextStateSaver stateSaver(*context); |
| 380 | 380 |
| 381 NSControlSize controlSize = [radioCell controlSize]; | 381 NSControlSize controlSize = [radioCell controlSize]; |
| 382 IntSize zoomedSize = radioSizes()[controlSize]; | 382 IntSize zoomedSize = radioSizes()[controlSize]; |
| 383 zoomedSize.setWidth(zoomedSize.width() * zoomFactor); | 383 zoomedSize.setWidth(zoomedSize.width() * zoomFactor); |
| 384 zoomedSize.setHeight(zoomedSize.height() * zoomFactor); | 384 zoomedSize.setHeight(zoomedSize.height() * zoomFactor); |
| 385 IntRect inflatedRect = ThemeMac::inflateRect(zoomedRect, zoomedSize, radioMa
rgins(controlSize), zoomFactor); | 385 IntRect inflatedRect = ThemeMac::inflateRect(zoomedRect, zoomedSize, radioMa
rgins(controlSize), zoomFactor); |
| 386 | 386 |
| 387 if (zoomFactor != 1.0f) { | 387 if (zoomFactor != 1.0f) { |
| 388 inflatedRect.setWidth(inflatedRect.width() / zoomFactor); | 388 inflatedRect.setWidth(inflatedRect.width() / zoomFactor); |
| 389 inflatedRect.setHeight(inflatedRect.height() / zoomFactor); | 389 inflatedRect.setHeight(inflatedRect.height() / zoomFactor); |
| 390 context->translate(inflatedRect.x(), inflatedRect.y()); | 390 context->translate(inflatedRect.x(), inflatedRect.y()); |
| 391 context->scale(zoomFactor, zoomFactor); | 391 context->scale(zoomFactor, zoomFactor); |
| 392 context->translate(-inflatedRect.x(), -inflatedRect.y()); | 392 context->translate(-inflatedRect.x(), -inflatedRect.y()); |
| 393 } | 393 } |
| 394 | 394 |
| 395 LocalCurrentGraphicsContext localContext(context, ThemeMac::inflateRectForFo
cusRing(inflatedRect)); | 395 LocalCurrentGraphicsContext localContext(context, ThemeMac::inflateRectForFo
cusRing(inflatedRect)); |
| 396 BEGIN_BLOCK_OBJC_EXCEPTIONS | 396 BEGIN_BLOCK_OBJC_EXCEPTIONS |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 static NSButtonCell *cell = nil; | 446 static NSButtonCell *cell = nil; |
| 447 if (!cell) { | 447 if (!cell) { |
| 448 cell = [[NSButtonCell alloc] init]; | 448 cell = [[NSButtonCell alloc] init]; |
| 449 [cell setTitle:nil]; | 449 [cell setTitle:nil]; |
| 450 [cell setButtonType:NSMomentaryPushInButton]; | 450 [cell setButtonType:NSMomentaryPushInButton]; |
| 451 } | 451 } |
| 452 setUpButtonCell(cell, part, states, zoomedRect, zoomFactor); | 452 setUpButtonCell(cell, part, states, zoomedRect, zoomFactor); |
| 453 return cell; | 453 return cell; |
| 454 } | 454 } |
| 455 | 455 |
| 456 static void paintButton(ControlPart part, ControlStates states, GraphicsContext*
context, const IntRect& zoomedRect, float zoomFactor, ScrollView* scrollView) | 456 static void paintButton(ControlPart part, ControlStates states, GraphicsContext*
context, const IntRect& zoomedRect, float zoomFactor, ScrollableArea* scrollVie
w) |
| 457 { | 457 { |
| 458 BEGIN_BLOCK_OBJC_EXCEPTIONS | 458 BEGIN_BLOCK_OBJC_EXCEPTIONS |
| 459 | 459 |
| 460 // Determine the width and height needed for the control and prepare the cel
l for painting. | 460 // Determine the width and height needed for the control and prepare the cel
l for painting. |
| 461 NSButtonCell *buttonCell = button(part, states, zoomedRect, zoomFactor); | 461 NSButtonCell *buttonCell = button(part, states, zoomedRect, zoomFactor); |
| 462 GraphicsContextStateSaver stateSaver(*context); | 462 GraphicsContextStateSaver stateSaver(*context); |
| 463 | 463 |
| 464 NSControlSize controlSize = [buttonCell controlSize]; | 464 NSControlSize controlSize = [buttonCell controlSize]; |
| 465 IntSize zoomedSize = buttonSizes()[controlSize]; | 465 IntSize zoomedSize = buttonSizes()[controlSize]; |
| 466 zoomedSize.setWidth(zoomedRect.width()); // Buttons don't ever constrain wid
th, so the zoomed width can just be honored. | 466 zoomedSize.setWidth(zoomedRect.width()); // Buttons don't ever constrain wid
th, so the zoomed width can just be honored. |
| 467 zoomedSize.setHeight(zoomedSize.height() * zoomFactor); | 467 zoomedSize.setHeight(zoomedSize.height() * zoomFactor); |
| 468 IntRect inflatedRect = zoomedRect; | 468 IntRect inflatedRect = zoomedRect; |
| 469 if ([buttonCell bezelStyle] == NSRoundedBezelStyle) { | 469 if ([buttonCell bezelStyle] == NSRoundedBezelStyle) { |
| 470 // Center the button within the available space. | 470 // Center the button within the available space. |
| 471 if (inflatedRect.height() > zoomedSize.height()) { | 471 if (inflatedRect.height() > zoomedSize.height()) { |
| 472 inflatedRect.setY(inflatedRect.y() + (inflatedRect.height() - zoomed
Size.height()) / 2); | 472 inflatedRect.setY(inflatedRect.y() + (inflatedRect.height() - zoomed
Size.height()) / 2); |
| 473 inflatedRect.setHeight(zoomedSize.height()); | 473 inflatedRect.setHeight(zoomedSize.height()); |
| 474 } | 474 } |
| 475 | 475 |
| 476 // Now inflate it to account for the shadow. | 476 // Now inflate it to account for the shadow. |
| 477 inflatedRect = ThemeMac::inflateRect(inflatedRect, zoomedSize, buttonMar
gins(controlSize), zoomFactor); | 477 inflatedRect = ThemeMac::inflateRect(inflatedRect, zoomedSize, buttonMar
gins(controlSize), zoomFactor); |
| 478 | 478 |
| 479 if (zoomFactor != 1.0f) { | 479 if (zoomFactor != 1.0f) { |
| 480 inflatedRect.setWidth(inflatedRect.width() / zoomFactor); | 480 inflatedRect.setWidth(inflatedRect.width() / zoomFactor); |
| 481 inflatedRect.setHeight(inflatedRect.height() / zoomFactor); | 481 inflatedRect.setHeight(inflatedRect.height() / zoomFactor); |
| 482 context->translate(inflatedRect.x(), inflatedRect.y()); | 482 context->translate(inflatedRect.x(), inflatedRect.y()); |
| 483 context->scale(zoomFactor, zoomFactor); | 483 context->scale(zoomFactor, zoomFactor); |
| 484 context->translate(-inflatedRect.x(), -inflatedRect.y()); | 484 context->translate(-inflatedRect.x(), -inflatedRect.y()); |
| 485 } | 485 } |
| 486 } | 486 } |
| 487 | 487 |
| 488 LocalCurrentGraphicsContext localContext(context, ThemeMac::inflateRectForFo
cusRing(inflatedRect)); | 488 LocalCurrentGraphicsContext localContext(context, ThemeMac::inflateRectForFo
cusRing(inflatedRect)); |
| 489 NSView *view = ThemeMac::ensuredView(scrollView); | 489 NSView *view = ThemeMac::ensuredView(scrollView); |
| 490 | 490 |
| 491 [buttonCell drawWithFrame:NSRect(inflatedRect) inView:view]; | 491 [buttonCell drawWithFrame:NSRect(inflatedRect) inView:view]; |
| 492 #if !BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING | 492 #if !BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING |
| 493 if (states & FocusControlState) | 493 if (states & FocusControlState) |
| 494 [buttonCell _web_drawFocusRingWithFrame:NSRect(inflatedRect) inView:view
]; | 494 [buttonCell _web_drawFocusRingWithFrame:NSRect(inflatedRect) inView:view
]; |
| 495 #endif | 495 #endif |
| 496 [buttonCell setControlView:nil]; | 496 [buttonCell setControlView:nil]; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 511 static NSControlSize stepperControlSizeForFont(const FontDescription& fontDescri
ption) | 511 static NSControlSize stepperControlSizeForFont(const FontDescription& fontDescri
ption) |
| 512 { | 512 { |
| 513 int fontSize = fontDescription.computedPixelSize(); | 513 int fontSize = fontDescription.computedPixelSize(); |
| 514 if (fontSize >= 27) | 514 if (fontSize >= 27) |
| 515 return NSRegularControlSize; | 515 return NSRegularControlSize; |
| 516 if (fontSize >= 22) | 516 if (fontSize >= 22) |
| 517 return NSSmallControlSize; | 517 return NSSmallControlSize; |
| 518 return NSMiniControlSize; | 518 return NSMiniControlSize; |
| 519 } | 519 } |
| 520 | 520 |
| 521 static void paintStepper(ControlStates states, GraphicsContext* context, const I
ntRect& zoomedRect, float zoomFactor, ScrollView*) | 521 static void paintStepper(ControlStates states, GraphicsContext* context, const I
ntRect& zoomedRect, float zoomFactor, ScrollableArea*) |
| 522 { | 522 { |
| 523 // We don't use NSStepperCell because there are no ways to draw an | 523 // We don't use NSStepperCell because there are no ways to draw an |
| 524 // NSStepperCell with the up button highlighted. | 524 // NSStepperCell with the up button highlighted. |
| 525 | 525 |
| 526 HIThemeButtonDrawInfo drawInfo; | 526 HIThemeButtonDrawInfo drawInfo; |
| 527 drawInfo.version = 0; | 527 drawInfo.version = 0; |
| 528 drawInfo.state = convertControlStatesToThemeDrawState(kThemeIncDecButton, st
ates); | 528 drawInfo.state = convertControlStatesToThemeDrawState(kThemeIncDecButton, st
ates); |
| 529 drawInfo.adornment = kThemeAdornmentDefault; | 529 drawInfo.adornment = kThemeAdornmentDefault; |
| 530 ControlSize controlSize = controlSizeFromPixelSize(stepperSizes(), zoomedRec
t.size(), zoomFactor); | 530 ControlSize controlSize = controlSizeFromPixelSize(stepperSizes(), zoomedRec
t.size(), zoomFactor); |
| 531 if (controlSize == NSSmallControlSize) | 531 if (controlSize == NSSmallControlSize) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 553 int heightDiff = clampToInteger(bounds.size.height - backgroundBounds.si
ze.height); | 553 int heightDiff = clampToInteger(bounds.size.height - backgroundBounds.si
ze.height); |
| 554 backgroundBounds.origin.y = bounds.origin.y + (heightDiff / 2) + 1; | 554 backgroundBounds.origin.y = bounds.origin.y + (heightDiff / 2) + 1; |
| 555 } | 555 } |
| 556 | 556 |
| 557 LocalCurrentGraphicsContext localContext(context, rect); | 557 LocalCurrentGraphicsContext localContext(context, rect); |
| 558 HIThemeDrawButton(&backgroundBounds, &drawInfo, localContext.cgContext(), kH
IThemeOrientationNormal, 0); | 558 HIThemeDrawButton(&backgroundBounds, &drawInfo, localContext.cgContext(), kH
IThemeOrientationNormal, 0); |
| 559 } | 559 } |
| 560 | 560 |
| 561 // 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. |
| 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. | 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. |
| 563 NSView *ThemeMac::ensuredView(ScrollView* scrollView) | 563 NSView *ThemeMac::ensuredView(ScrollableArea* scrollView) |
| 564 { | 564 { |
| 565 | 565 |
| 566 // Use a fake flipped view. | 566 // Use a fake flipped view. |
| 567 static NSView *flippedView = [[WebCoreFlippedView alloc] init]; | 567 static NSView *flippedView = [[WebCoreFlippedView alloc] init]; |
| 568 [flippedView setFrameSize:NSSizeFromCGSize(scrollView->contentsSize())]; | 568 [flippedView setFrameSize:NSSizeFromCGSize(scrollView->contentsSize())]; |
| 569 | 569 |
| 570 return flippedView; | 570 return flippedView; |
| 571 } | 571 } |
| 572 | 572 |
| 573 void ThemeMac::setFocusRingClipRect(const FloatRect& rect) | 573 void ThemeMac::setFocusRingClipRect(const FloatRect& rect) |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 zoomedSize.setWidth(zoomedSize.width() * zoomFactor); | 714 zoomedSize.setWidth(zoomedSize.width() * zoomFactor); |
| 715 zoomedRect = inflateRect(zoomedRect, zoomedSize, stepperMargin, zoom
Factor); | 715 zoomedRect = inflateRect(zoomedRect, zoomedSize, stepperMargin, zoom
Factor); |
| 716 break; | 716 break; |
| 717 } | 717 } |
| 718 default: | 718 default: |
| 719 break; | 719 break; |
| 720 } | 720 } |
| 721 END_BLOCK_OBJC_EXCEPTIONS | 721 END_BLOCK_OBJC_EXCEPTIONS |
| 722 } | 722 } |
| 723 | 723 |
| 724 void ThemeMac::paint(ControlPart part, ControlStates states, GraphicsContext* co
ntext, const IntRect& zoomedRect, float zoomFactor, ScrollView* scrollView) cons
t | 724 void ThemeMac::paint(ControlPart part, ControlStates states, GraphicsContext* co
ntext, const IntRect& zoomedRect, float zoomFactor, ScrollableArea* scrollView)
const |
| 725 { | 725 { |
| 726 switch (part) { | 726 switch (part) { |
| 727 case CheckboxPart: | 727 case CheckboxPart: |
| 728 paintCheckbox(states, context, zoomedRect, zoomFactor, scrollView); | 728 paintCheckbox(states, context, zoomedRect, zoomFactor, scrollView); |
| 729 break; | 729 break; |
| 730 case RadioPart: | 730 case RadioPart: |
| 731 paintRadio(states, context, zoomedRect, zoomFactor, scrollView); | 731 paintRadio(states, context, zoomedRect, zoomFactor, scrollView); |
| 732 break; | 732 break; |
| 733 case PushButtonPart: | 733 case PushButtonPart: |
| 734 case ButtonPart: | 734 case ButtonPart: |
| 735 case SquareButtonPart: | 735 case SquareButtonPart: |
| 736 paintButton(part, states, context, zoomedRect, zoomFactor, scrollVie
w); | 736 paintButton(part, states, context, zoomedRect, zoomFactor, scrollVie
w); |
| 737 break; | 737 break; |
| 738 case InnerSpinButtonPart: | 738 case InnerSpinButtonPart: |
| 739 paintStepper(states, context, zoomedRect, zoomFactor, scrollView); | 739 paintStepper(states, context, zoomedRect, zoomFactor, scrollView); |
| 740 break; | 740 break; |
| 741 default: | 741 default: |
| 742 break; | 742 break; |
| 743 } | 743 } |
| 744 } | 744 } |
| 745 | 745 |
| 746 } | 746 } |
| OLD | NEW |