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 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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, ScrollableArea* scrollView) | 291 static void paintCheckbox(ControlStates states, GraphicsContext* context, const
IntRect& zoomedRect, float zoomFactor, ScrollableArea* scrollableArea) |
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(scrollableArea); |
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 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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, ScrollableArea* scrollView) | 375 static void paintRadio(ControlStates states, GraphicsContext* context, const Int
Rect& zoomedRect, float zoomFactor, ScrollableArea* scrollableArea) |
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 |
397 NSView *view = ThemeMac::ensuredView(scrollView); | 397 NSView *view = ThemeMac::ensuredView(scrollableArea); |
398 [radioCell drawWithFrame:NSRect(inflatedRect) inView:view]; | 398 [radioCell drawWithFrame:NSRect(inflatedRect) inView:view]; |
399 #if !BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING | 399 #if !BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING |
400 if (states & FocusControlState) | 400 if (states & FocusControlState) |
401 [radioCell _web_drawFocusRingWithFrame:NSRect(inflatedRect) inView:view]
; | 401 [radioCell _web_drawFocusRingWithFrame:NSRect(inflatedRect) inView:view]
; |
402 #endif | 402 #endif |
403 [radioCell setControlView:nil]; | 403 [radioCell setControlView:nil]; |
404 END_BLOCK_OBJC_EXCEPTIONS | 404 END_BLOCK_OBJC_EXCEPTIONS |
405 } | 405 } |
406 | 406 |
407 // Buttons | 407 // Buttons |
(...skipping 38 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, ScrollableArea* scrollVie
w) | 456 static void paintButton(ControlPart part, ControlStates states, GraphicsContext*
context, const IntRect& zoomedRect, float zoomFactor, ScrollableArea* scrollabl
eArea) |
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. |
(...skipping 12 matching lines...) Expand all Loading... |
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(scrollableArea); |
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]; |
497 | 497 |
498 END_BLOCK_OBJC_EXCEPTIONS | 498 END_BLOCK_OBJC_EXCEPTIONS |
499 } | 499 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 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; |
552 if (backgroundBounds.size.height < bounds.size.height) { | 552 if (backgroundBounds.size.height < bounds.size.height) { |
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 FrameView does
n'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 FrameView doesn't have an NSView, we will return a fake NSView whose s
ole purpose is to tell AppKit that it's flipped. |
563 NSView *ThemeMac::ensuredView(ScrollableArea* scrollView) | 563 NSView *ThemeMac::ensuredView(ScrollableArea* frameView) |
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(frameView->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) |
574 { | 574 { |
575 focusRingClipRect = rect; | 575 focusRingClipRect = rect; |
576 } | 576 } |
577 | 577 |
578 // Theme overrides | 578 // Theme overrides |
(...skipping 135 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, ScrollableArea* scrollView)
const | 724 void ThemeMac::paint(ControlPart part, ControlStates states, GraphicsContext* co
ntext, const IntRect& zoomedRect, float zoomFactor, ScrollableArea* scrollableAr
ea) 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, scrollableAre
a); |
729 break; | 729 break; |
730 case RadioPart: | 730 case RadioPart: |
731 paintRadio(states, context, zoomedRect, zoomFactor, scrollView); | 731 paintRadio(states, context, zoomedRect, zoomFactor, scrollableArea); |
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, scrollabl
eArea); |
737 break; | 737 break; |
738 case InnerSpinButtonPart: | 738 case InnerSpinButtonPart: |
739 paintStepper(states, context, zoomedRect, zoomFactor, scrollView); | 739 paintStepper(states, context, zoomedRect, zoomFactor, scrollableArea
); |
740 break; | 740 break; |
741 default: | 741 default: |
742 break; | 742 break; |
743 } | 743 } |
744 } | 744 } |
745 | 745 |
746 } | 746 } |
OLD | NEW |