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

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

Issue 14413014: Remove -webkit-appearance:default-button. This was only used in Safari. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 7 years, 8 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
« no previous file with comments | « Source/core/platform/ThemeTypes.h ('k') | Source/core/platform/mac/WebCoreSystemInterface.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 12 matching lines...) Expand all
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 "ThemeMac.h" 27 #import "ThemeMac.h"
28 28
29 #import <Carbon/Carbon.h> 29 #import <Carbon/Carbon.h>
30 #import "BlockExceptions.h" 30 #import "BlockExceptions.h"
31 #import "LocalCurrentGraphicsContext.h" 31 #import "LocalCurrentGraphicsContext.h"
32 #import "WebCoreNSCellExtras.h" 32 #import "WebCoreNSCellExtras.h"
33 #import "WebCoreSystemInterface.h"
34 #import "core/platform/ScrollView.h" 33 #import "core/platform/ScrollView.h"
35 #import "core/platform/graphics/GraphicsContext.h" 34 #import "core/platform/graphics/GraphicsContext.h"
36 #include <wtf/StdLibExtras.h> 35 #include <wtf/StdLibExtras.h>
37 36
38 using namespace std; 37 using namespace std;
39 38
40 NSRect focusRingClipRect; 39 NSRect focusRingClipRect;
41 40
42 // This is a view whose sole purpose is to tell AppKit that it's flipped. 41 // This is a view whose sole purpose is to tell AppKit that it's flipped.
43 @interface WebCoreFlippedView : NSControl 42 @interface WebCoreFlippedView : NSControl
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 - (NSString*)webCoreFamilyName 82 - (NSString*)webCoreFamilyName
84 { 83 {
85 if ([[self familyName] hasPrefix:@"."]) 84 if ([[self familyName] hasPrefix:@"."])
86 return [self fontName]; 85 return [self fontName];
87 86
88 return [self familyName]; 87 return [self familyName];
89 } 88 }
90 89
91 @end 90 @end
92 91
93 // FIXME: Default buttons really should be more like push buttons and not like b uttons.
94
95 namespace WebCore { 92 namespace WebCore {
96 93
97 enum { 94 enum {
98 topMargin, 95 topMargin,
99 rightMargin, 96 rightMargin,
100 bottomMargin, 97 bottomMargin,
101 leftMargin 98 leftMargin
102 }; 99 };
103 100
104 Theme* platformTheme() 101 Theme* platformTheme()
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 { 399 {
403 static const int margins[3][4] = 400 static const int margins[3][4] =
404 { 401 {
405 { 4, 6, 7, 6 }, 402 { 4, 6, 7, 6 },
406 { 4, 5, 6, 5 }, 403 { 4, 5, 6, 5 },
407 { 0, 1, 1, 1 }, 404 { 0, 1, 1, 1 },
408 }; 405 };
409 return margins[controlSize]; 406 return margins[controlSize];
410 } 407 }
411 408
412 enum ButtonCellType { NormalButtonCell, DefaultButtonCell };
413
414 static NSButtonCell *leakButtonCell(ButtonCellType type)
415 {
416 NSButtonCell *cell = [[NSButtonCell alloc] init];
417 [cell setTitle:nil];
418 [cell setButtonType:NSMomentaryPushInButton];
419 if (type == DefaultButtonCell)
420 [cell setKeyEquivalent:@"\r"];
421 return cell;
422 }
423
424 static void setUpButtonCell(NSButtonCell *cell, ControlPart part, ControlStates states, const IntRect& zoomedRect, float zoomFactor) 409 static void setUpButtonCell(NSButtonCell *cell, ControlPart part, ControlStates states, const IntRect& zoomedRect, float zoomFactor)
425 { 410 {
426 // Set the control size based off the rectangle we're painting into. 411 // Set the control size based off the rectangle we're painting into.
427 const IntSize* sizes = buttonSizes(); 412 const IntSize* sizes = buttonSizes();
428 if (part == SquareButtonPart || zoomedRect.height() > buttonSizes()[NSRegula rControlSize].height() * zoomFactor) { 413 if (part == SquareButtonPart || zoomedRect.height() > buttonSizes()[NSRegula rControlSize].height() * zoomFactor) {
429 // Use the square button 414 // Use the square button
430 if ([cell bezelStyle] != NSShadowlessSquareBezelStyle) 415 if ([cell bezelStyle] != NSShadowlessSquareBezelStyle)
431 [cell setBezelStyle:NSShadowlessSquareBezelStyle]; 416 [cell setBezelStyle:NSShadowlessSquareBezelStyle];
432 } else if ([cell bezelStyle] != NSRoundedBezelStyle) 417 } else if ([cell bezelStyle] != NSRoundedBezelStyle)
433 [cell setBezelStyle:NSRoundedBezelStyle]; 418 [cell setBezelStyle:NSRoundedBezelStyle];
434 419
435 setControlSize(cell, sizes, zoomedRect.size(), zoomFactor); 420 setControlSize(cell, sizes, zoomedRect.size(), zoomFactor);
436 421
437 // Update the various states we respond to. 422 // Update the various states we respond to.
438 updateStates(cell, states); 423 updateStates(cell, states);
439 } 424 }
440 425
441 static NSButtonCell *button(ControlPart part, ControlStates states, const IntRec t& zoomedRect, float zoomFactor) 426 static NSButtonCell *button(ControlPart part, ControlStates states, const IntRec t& zoomedRect, float zoomFactor)
442 { 427 {
443 NSButtonCell *cell; 428 static NSButtonCell *cell = nil;
444 if (states & DefaultState) { 429 if (!cell) {
445 static NSButtonCell *defaultCell = leakButtonCell(DefaultButtonCell); 430 cell = [[NSButtonCell alloc] init];
446 cell = defaultCell; 431 [cell setTitle:nil];
447 } else { 432 [cell setButtonType:NSMomentaryPushInButton];
448 static NSButtonCell *normalCell = leakButtonCell(NormalButtonCell);
449 cell = normalCell;
450 } 433 }
451 setUpButtonCell(cell, part, states, zoomedRect, zoomFactor); 434 setUpButtonCell(cell, part, states, zoomedRect, zoomFactor);
452 return cell; 435 return cell;
453 } 436 }
454 437
455 static void paintButton(ControlPart part, ControlStates states, GraphicsContext* context, const IntRect& zoomedRect, float zoomFactor, ScrollView* scrollView) 438 static void paintButton(ControlPart part, ControlStates states, GraphicsContext* context, const IntRect& zoomedRect, float zoomFactor, ScrollView* scrollView)
456 { 439 {
457 BEGIN_BLOCK_OBJC_EXCEPTIONS 440 BEGIN_BLOCK_OBJC_EXCEPTIONS
458 441
459 // Determine the width and height needed for the control and prepare the cel l for painting. 442 // Determine the width and height needed for the control and prepare the cel l for painting.
460 NSButtonCell *buttonCell = button(part, states, zoomedRect, zoomFactor); 443 NSButtonCell *buttonCell = button(part, states, zoomedRect, zoomFactor);
461 GraphicsContextStateSaver stateSaver(*context); 444 GraphicsContextStateSaver stateSaver(*context);
(...skipping 18 matching lines...) Expand all
480 inflatedRect.setHeight(inflatedRect.height() / zoomFactor); 463 inflatedRect.setHeight(inflatedRect.height() / zoomFactor);
481 context->translate(inflatedRect.x(), inflatedRect.y()); 464 context->translate(inflatedRect.x(), inflatedRect.y());
482 context->scale(FloatSize(zoomFactor, zoomFactor)); 465 context->scale(FloatSize(zoomFactor, zoomFactor));
483 context->translate(-inflatedRect.x(), -inflatedRect.y()); 466 context->translate(-inflatedRect.x(), -inflatedRect.y());
484 } 467 }
485 } 468 }
486 469
487 LocalCurrentGraphicsContext localContext(context); 470 LocalCurrentGraphicsContext localContext(context);
488 NSView *view = ThemeMac::ensuredView(scrollView); 471 NSView *view = ThemeMac::ensuredView(scrollView);
489 NSWindow *window = [view window]; 472 NSWindow *window = [view window];
490 NSButtonCell *previousDefaultButtonCell = [window defaultButtonCell];
491
492 if (states & DefaultState) {
493 [window setDefaultButtonCell:buttonCell];
494 WKAdvanceDefaultButtonPulseAnimation(buttonCell);
495 } else if ([previousDefaultButtonCell isEqual:buttonCell])
496 [window setDefaultButtonCell:nil];
497 473
498 [buttonCell drawWithFrame:NSRect(inflatedRect) inView:view]; 474 [buttonCell drawWithFrame:NSRect(inflatedRect) inView:view];
499 #if !BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING 475 #if !BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING
500 if (states & FocusState) 476 if (states & FocusState)
501 [buttonCell _web_drawFocusRingWithFrame:NSRect(inflatedRect) inView:view ]; 477 [buttonCell _web_drawFocusRingWithFrame:NSRect(inflatedRect) inView:view ];
502 #endif 478 #endif
503 [buttonCell setControlView:nil]; 479 [buttonCell setControlView:nil];
504 480
505 if (![previousDefaultButtonCell isEqual:buttonCell])
506 [window setDefaultButtonCell:previousDefaultButtonCell];
507
508 END_BLOCK_OBJC_EXCEPTIONS 481 END_BLOCK_OBJC_EXCEPTIONS
509 } 482 }
510 483
511 // Stepper 484 // Stepper
512 485
513 static const IntSize* stepperSizes() 486 static const IntSize* stepperSizes()
514 { 487 {
515 static const IntSize sizes[3] = { IntSize(19, 27), IntSize(15, 22), IntSize( 13, 15) }; 488 static const IntSize sizes[3] = { IntSize(19, 27), IntSize(15, 22), IntSize( 13, 15) };
516 return sizes; 489 return sizes;
517 } 490 }
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 return sizeFromNSControlSize(stepperControlSizeForFont(font), zoomed Size, zoomFactor, stepperSizes()); 602 return sizeFromNSControlSize(stepperControlSizeForFont(font), zoomed Size, zoomFactor, stepperSizes());
630 default: 603 default:
631 return zoomedSize; 604 return zoomedSize;
632 } 605 }
633 } 606 }
634 607
635 LengthSize ThemeMac::minimumControlSize(ControlPart part, const Font& font, floa t zoomFactor) const 608 LengthSize ThemeMac::minimumControlSize(ControlPart part, const Font& font, floa t zoomFactor) const
636 { 609 {
637 switch (part) { 610 switch (part) {
638 case SquareButtonPart: 611 case SquareButtonPart:
639 case DefaultButtonPart:
640 case ButtonPart: 612 case ButtonPart:
641 return LengthSize(Length(0, Fixed), Length(static_cast<int>(15 * zoo mFactor), Fixed)); 613 return LengthSize(Length(0, Fixed), Length(static_cast<int>(15 * zoo mFactor), Fixed));
642 case InnerSpinButtonPart:{ 614 case InnerSpinButtonPart:{
643 IntSize base = stepperSizes()[NSMiniControlSize]; 615 IntSize base = stepperSizes()[NSMiniControlSize];
644 return LengthSize(Length(static_cast<int>(base.width() * zoomFactor) , Fixed), 616 return LengthSize(Length(static_cast<int>(base.width() * zoomFactor) , Fixed),
645 Length(static_cast<int>(base.height() * zoomFactor ), Fixed)); 617 Length(static_cast<int>(base.height() * zoomFactor ), Fixed));
646 } 618 }
647 default: 619 default:
648 return Theme::minimumControlSize(part, font, zoomFactor); 620 return Theme::minimumControlSize(part, font, zoomFactor);
649 } 621 }
650 } 622 }
651 623
652 LengthBox ThemeMac::controlBorder(ControlPart part, const Font& font, const Leng thBox& zoomedBox, float zoomFactor) const 624 LengthBox ThemeMac::controlBorder(ControlPart part, const Font& font, const Leng thBox& zoomedBox, float zoomFactor) const
653 { 625 {
654 switch (part) { 626 switch (part) {
655 case SquareButtonPart: 627 case SquareButtonPart:
656 case DefaultButtonPart:
657 case ButtonPart: 628 case ButtonPart:
658 return LengthBox(0, zoomedBox.right().value(), 0, zoomedBox.left().v alue()); 629 return LengthBox(0, zoomedBox.right().value(), 0, zoomedBox.left().v alue());
659 default: 630 default:
660 return Theme::controlBorder(part, font, zoomedBox, zoomFactor); 631 return Theme::controlBorder(part, font, zoomedBox, zoomFactor);
661 } 632 }
662 } 633 }
663 634
664 LengthBox ThemeMac::controlPadding(ControlPart part, const Font& font, const Len gthBox& zoomedBox, float zoomFactor) const 635 LengthBox ThemeMac::controlPadding(ControlPart part, const Font& font, const Len gthBox& zoomedBox, float zoomFactor) const
665 { 636 {
666 switch (part) { 637 switch (part) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 // shadow". We don't consider this part of the bounds of the contro l in WebKit. 669 // shadow". We don't consider this part of the bounds of the contro l in WebKit.
699 NSCell *cell = radio(states, zoomedRect, zoomFactor); 670 NSCell *cell = radio(states, zoomedRect, zoomFactor);
700 NSControlSize controlSize = [cell controlSize]; 671 NSControlSize controlSize = [cell controlSize];
701 IntSize zoomedSize = radioSizes()[controlSize]; 672 IntSize zoomedSize = radioSizes()[controlSize];
702 zoomedSize.setHeight(zoomedSize.height() * zoomFactor); 673 zoomedSize.setHeight(zoomedSize.height() * zoomFactor);
703 zoomedSize.setWidth(zoomedSize.width() * zoomFactor); 674 zoomedSize.setWidth(zoomedSize.width() * zoomFactor);
704 zoomedRect = inflateRect(zoomedRect, zoomedSize, radioMargins(contro lSize), zoomFactor); 675 zoomedRect = inflateRect(zoomedRect, zoomedSize, radioMargins(contro lSize), zoomFactor);
705 break; 676 break;
706 } 677 }
707 case PushButtonPart: 678 case PushButtonPart:
708 case DefaultButtonPart:
709 case ButtonPart: { 679 case ButtonPart: {
710 NSButtonCell *cell = button(part, states, zoomedRect, zoomFactor); 680 NSButtonCell *cell = button(part, states, zoomedRect, zoomFactor);
711 NSControlSize controlSize = [cell controlSize]; 681 NSControlSize controlSize = [cell controlSize];
712 682
713 // We inflate the rect as needed to account for the Aqua button's sh adow. 683 // We inflate the rect as needed to account for the Aqua button's sh adow.
714 if ([cell bezelStyle] == NSRoundedBezelStyle) { 684 if ([cell bezelStyle] == NSRoundedBezelStyle) {
715 IntSize zoomedSize = buttonSizes()[controlSize]; 685 IntSize zoomedSize = buttonSizes()[controlSize];
716 zoomedSize.setHeight(zoomedSize.height() * zoomFactor); 686 zoomedSize.setHeight(zoomedSize.height() * zoomFactor);
717 zoomedSize.setWidth(zoomedRect.width()); // Buttons don't ever c onstrain width, so the zoomed width can just be honored. 687 zoomedSize.setWidth(zoomedRect.width()); // Buttons don't ever c onstrain width, so the zoomed width can just be honored.
718 zoomedRect = inflateRect(zoomedRect, zoomedSize, buttonMargins(c ontrolSize), zoomFactor); 688 zoomedRect = inflateRect(zoomedRect, zoomedSize, buttonMargins(c ontrolSize), zoomFactor);
(...skipping 18 matching lines...) Expand all
737 void ThemeMac::paint(ControlPart part, ControlStates states, GraphicsContext* co ntext, const IntRect& zoomedRect, float zoomFactor, ScrollView* scrollView) cons t 707 void ThemeMac::paint(ControlPart part, ControlStates states, GraphicsContext* co ntext, const IntRect& zoomedRect, float zoomFactor, ScrollView* scrollView) cons t
738 { 708 {
739 switch (part) { 709 switch (part) {
740 case CheckboxPart: 710 case CheckboxPart:
741 paintCheckbox(states, context, zoomedRect, zoomFactor, scrollView); 711 paintCheckbox(states, context, zoomedRect, zoomFactor, scrollView);
742 break; 712 break;
743 case RadioPart: 713 case RadioPart:
744 paintRadio(states, context, zoomedRect, zoomFactor, scrollView); 714 paintRadio(states, context, zoomedRect, zoomFactor, scrollView);
745 break; 715 break;
746 case PushButtonPart: 716 case PushButtonPart:
747 case DefaultButtonPart:
748 case ButtonPart: 717 case ButtonPart:
749 case SquareButtonPart: 718 case SquareButtonPart:
750 paintButton(part, states, context, zoomedRect, zoomFactor, scrollVie w); 719 paintButton(part, states, context, zoomedRect, zoomFactor, scrollVie w);
751 break; 720 break;
752 case InnerSpinButtonPart: 721 case InnerSpinButtonPart:
753 paintStepper(states, context, zoomedRect, zoomFactor, scrollView); 722 paintStepper(states, context, zoomedRect, zoomFactor, scrollView);
754 break; 723 break;
755 default: 724 default:
756 break; 725 break;
757 } 726 }
758 } 727 }
759 728
760 } 729 }
OLDNEW
« no previous file with comments | « Source/core/platform/ThemeTypes.h ('k') | Source/core/platform/mac/WebCoreSystemInterface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698