OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" | 5 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #import "base/mac/mac_util.h" | 8 #import "base/mac/mac_util.h" |
9 #include "base/mac/scoped_cftyperef.h" | 9 #include "base/mac/scoped_cftyperef.h" |
10 #include "chrome/browser/themes/theme_service.h" | 10 #include "chrome/browser/themes/theme_service.h" |
11 #import "chrome/browser/ui/cocoa/nsview_additions.h" | 11 #import "chrome/browser/ui/cocoa/nsview_additions.h" |
12 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" | 12 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" |
13 #import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h" | 13 #import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h" |
14 #import "chrome/browser/ui/cocoa/themed_window.h" | 14 #import "chrome/browser/ui/cocoa/themed_window.h" |
15 #import "chrome/browser/ui/cocoa/view_id_util.h" | 15 #import "chrome/browser/ui/cocoa/view_id_util.h" |
16 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
17 #include "grit/theme_resources.h" | 17 #include "grit/theme_resources.h" |
18 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
| 19 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 // Constants for inset and control points for tab shape. | 23 // Constants for inset and control points for tab shape. |
23 const CGFloat kInsetMultiplier = 2.0/3.0; | 24 const CGFloat kInsetMultiplier = 2.0/3.0; |
24 const CGFloat kControlPoint1Multiplier = 1.0/3.0; | 25 const CGFloat kControlPoint1Multiplier = 1.0/3.0; |
25 const CGFloat kControlPoint2Multiplier = 3.0/8.0; | 26 const CGFloat kControlPoint2Multiplier = 3.0/8.0; |
26 | 27 |
27 // The amount of time in seconds during which each type of glow increases, holds | 28 // The amount of time in seconds during which each type of glow increases, holds |
28 // steady, and decreases, respectively. | 29 // steady, and decreases, respectively. |
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 // close. | 645 // close. |
645 if ([self hitTest:upLocation]) | 646 if ([self hitTest:upLocation]) |
646 [controller_ closeTab:self]; | 647 [controller_ closeTab:self]; |
647 } | 648 } |
648 } | 649 } |
649 | 650 |
650 - (void)drawRect:(NSRect)dirtyRect { | 651 - (void)drawRect:(NSRect)dirtyRect { |
651 const CGFloat lineWidth = [self cr_lineWidth]; | 652 const CGFloat lineWidth = [self cr_lineWidth]; |
652 | 653 |
653 NSGraphicsContext* context = [NSGraphicsContext currentContext]; | 654 NSGraphicsContext* context = [NSGraphicsContext currentContext]; |
654 [context saveGraphicsState]; | 655 gfx::ScopedNSGraphicsContextSaveGState scopedGState(context); |
655 | 656 |
656 ThemeService* themeProvider = | 657 ThemeService* themeProvider = |
657 static_cast<ThemeService*>([[self window] themeProvider]); | 658 static_cast<ThemeService*>([[self window] themeProvider]); |
658 [context setPatternPhase:[[self window] themePatternPhase]]; | 659 [context setPatternPhase:[[self window] themePatternPhase]]; |
659 | 660 |
660 NSRect rect = [self bounds]; | 661 NSRect rect = [self bounds]; |
661 NSBezierPath* path = [self bezierPathForRect:rect]; | 662 NSBezierPath* path = [self bezierPathForRect:rect]; |
662 | 663 |
663 BOOL selected = [self state]; | 664 BOOL selected = [self state]; |
664 // Don't draw the window/tab bar background when selected, since the tab | 665 // Don't draw the window/tab bar background when selected, since the tab |
(...skipping 28 matching lines...) Expand all Loading... |
693 | 694 |
694 [context saveGraphicsState]; | 695 [context saveGraphicsState]; |
695 [path addClip]; | 696 [path addClip]; |
696 | 697 |
697 // Use the same overlay for the selected state and for hover and alert glows; | 698 // Use the same overlay for the selected state and for hover and alert glows; |
698 // for the selected state, it's fully opaque. | 699 // for the selected state, it's fully opaque. |
699 CGFloat hoverAlpha = [self hoverAlpha]; | 700 CGFloat hoverAlpha = [self hoverAlpha]; |
700 CGFloat alertAlpha = [self alertAlpha]; | 701 CGFloat alertAlpha = [self alertAlpha]; |
701 if (selected || hoverAlpha > 0 || alertAlpha > 0) { | 702 if (selected || hoverAlpha > 0 || alertAlpha > 0) { |
702 // Draw the selected background / glow overlay. | 703 // Draw the selected background / glow overlay. |
703 [context saveGraphicsState]; | 704 gfx::ScopedNSGraphicsContextSaveGState drawHoverState(context); |
704 CGContextRef cgContext = static_cast<CGContextRef>([context graphicsPort]); | 705 CGContextRef cgContext = static_cast<CGContextRef>([context graphicsPort]); |
705 CGContextBeginTransparencyLayer(cgContext, 0); | 706 CGContextBeginTransparencyLayer(cgContext, 0); |
706 if (!selected) { | 707 if (!selected) { |
707 // The alert glow overlay is like the selected state but at most at most | 708 // The alert glow overlay is like the selected state but at most at most |
708 // 80% opaque. The hover glow brings up the overlay's opacity at most 50%. | 709 // 80% opaque. The hover glow brings up the overlay's opacity at most 50%. |
709 CGFloat backgroundAlpha = 0.8 * alertAlpha; | 710 CGFloat backgroundAlpha = 0.8 * alertAlpha; |
710 backgroundAlpha += (1 - backgroundAlpha) * 0.5 * hoverAlpha; | 711 backgroundAlpha += (1 - backgroundAlpha) * 0.5 * hoverAlpha; |
711 CGContextSetAlpha(cgContext, backgroundAlpha); | 712 CGContextSetAlpha(cgContext, backgroundAlpha); |
712 } | 713 } |
713 [path addClip]; | 714 [path addClip]; |
714 [context saveGraphicsState]; | 715 { |
715 [super drawBackground]; | 716 gfx::ScopedNSGraphicsContextSaveGState drawBackgroundState(context); |
716 [context restoreGraphicsState]; | 717 [super drawBackground]; |
| 718 } |
717 | 719 |
718 // Draw a mouse hover gradient for the default themes. | 720 // Draw a mouse hover gradient for the default themes. |
719 if (!selected && hoverAlpha > 0) { | 721 if (!selected && hoverAlpha > 0) { |
720 if (themeProvider && !hasBackgroundImage) { | 722 if (themeProvider && !hasBackgroundImage) { |
721 scoped_nsobject<NSGradient> glow([NSGradient alloc]); | 723 scoped_nsobject<NSGradient> glow([NSGradient alloc]); |
722 [glow initWithStartingColor:[NSColor colorWithCalibratedWhite:1.0 | 724 [glow initWithStartingColor:[NSColor colorWithCalibratedWhite:1.0 |
723 alpha:1.0 * hoverAlpha] | 725 alpha:1.0 * hoverAlpha] |
724 endingColor:[NSColor colorWithCalibratedWhite:1.0 | 726 endingColor:[NSColor colorWithCalibratedWhite:1.0 |
725 alpha:0.0]]; | 727 alpha:0.0]]; |
726 | 728 |
727 NSPoint point = hoverPoint_; | 729 NSPoint point = hoverPoint_; |
728 point.y = NSHeight(rect); | 730 point.y = NSHeight(rect); |
729 [glow drawFromCenter:point | 731 [glow drawFromCenter:point |
730 radius:0.0 | 732 radius:0.0 |
731 toCenter:point | 733 toCenter:point |
732 radius:NSWidth(rect) / 3.0 | 734 radius:NSWidth(rect) / 3.0 |
733 options:NSGradientDrawsBeforeStartingLocation]; | 735 options:NSGradientDrawsBeforeStartingLocation]; |
734 | 736 |
735 [glow drawInBezierPath:path relativeCenterPosition:hoverPoint_]; | 737 [glow drawInBezierPath:path relativeCenterPosition:hoverPoint_]; |
736 } | 738 } |
737 } | 739 } |
738 | 740 |
739 CGContextEndTransparencyLayer(cgContext); | 741 CGContextEndTransparencyLayer(cgContext); |
740 [context restoreGraphicsState]; | |
741 } | 742 } |
742 | 743 |
743 BOOL active = [[self window] isKeyWindow] || [[self window] isMainWindow]; | 744 BOOL active = [[self window] isKeyWindow] || [[self window] isMainWindow]; |
744 CGFloat borderAlpha = selected ? (active ? 0.3 : 0.2) : 0.2; | 745 CGFloat borderAlpha = selected ? (active ? 0.3 : 0.2) : 0.2; |
745 NSColor* borderColor = [NSColor colorWithDeviceWhite:0.0 alpha:borderAlpha]; | 746 NSColor* borderColor = [NSColor colorWithDeviceWhite:0.0 alpha:borderAlpha]; |
746 NSColor* highlightColor = themeProvider ? themeProvider->GetNSColor( | 747 NSColor* highlightColor = themeProvider ? themeProvider->GetNSColor( |
747 themeProvider->UsingDefaultTheme() ? | 748 themeProvider->UsingDefaultTheme() ? |
748 ThemeService::COLOR_TOOLBAR_BEZEL : | 749 ThemeService::COLOR_TOOLBAR_BEZEL : |
749 ThemeService::COLOR_TOOLBAR, true) : nil; | 750 ThemeService::COLOR_TOOLBAR, true) : nil; |
750 | 751 |
751 // Draw the top inner highlight within the currently selected tab if using | 752 // Draw the top inner highlight within the currently selected tab if using |
752 // the default theme. | 753 // the default theme. |
753 if (selected && themeProvider && themeProvider->UsingDefaultTheme()) { | 754 if (selected && themeProvider && themeProvider->UsingDefaultTheme()) { |
754 NSAffineTransform* highlightTransform = [NSAffineTransform transform]; | 755 NSAffineTransform* highlightTransform = [NSAffineTransform transform]; |
755 [highlightTransform translateXBy:lineWidth yBy:-lineWidth]; | 756 [highlightTransform translateXBy:lineWidth yBy:-lineWidth]; |
756 scoped_nsobject<NSBezierPath> highlightPath([path copy]); | 757 scoped_nsobject<NSBezierPath> highlightPath([path copy]); |
757 [highlightPath transformUsingAffineTransform:highlightTransform]; | 758 [highlightPath transformUsingAffineTransform:highlightTransform]; |
758 [highlightColor setStroke]; | 759 [highlightColor setStroke]; |
759 [highlightPath setLineWidth:lineWidth]; | 760 [highlightPath setLineWidth:lineWidth]; |
760 [highlightPath stroke]; | 761 [highlightPath stroke]; |
761 highlightTransform = [NSAffineTransform transform]; | 762 highlightTransform = [NSAffineTransform transform]; |
762 [highlightTransform translateXBy:-2 * lineWidth yBy:0.0]; | 763 [highlightTransform translateXBy:-2 * lineWidth yBy:0.0]; |
763 [highlightPath transformUsingAffineTransform:highlightTransform]; | 764 [highlightPath transformUsingAffineTransform:highlightTransform]; |
764 [highlightPath stroke]; | 765 [highlightPath stroke]; |
765 } | 766 } |
766 | 767 |
767 [context restoreGraphicsState]; | 768 [context restoreGraphicsState]; |
768 | 769 |
769 // Draw the top stroke. | 770 // Draw the top stroke. |
770 [context saveGraphicsState]; | 771 { |
771 [borderColor set]; | 772 gfx::ScopedNSGraphicsContextSaveGState drawBorderState(context); |
772 [path setLineWidth:lineWidth]; | 773 [borderColor set]; |
773 [path stroke]; | 774 [path setLineWidth:lineWidth]; |
774 [context restoreGraphicsState]; | 775 [path stroke]; |
| 776 } |
775 | 777 |
776 // Mimic the tab strip's bottom border, which consists of a dark border | 778 // Mimic the tab strip's bottom border, which consists of a dark border |
777 // and light highlight. | 779 // and light highlight. |
778 if (!selected) { | 780 if (!selected) { |
779 [path addClip]; | 781 [path addClip]; |
780 NSRect borderRect = rect; | 782 NSRect borderRect = rect; |
781 borderRect.origin.y = lineWidth; | 783 borderRect.origin.y = lineWidth; |
782 borderRect.size.height = lineWidth; | 784 borderRect.size.height = lineWidth; |
783 [borderColor set]; | 785 [borderColor set]; |
784 NSRectFillUsingOperation(borderRect, NSCompositeSourceOver); | 786 NSRectFillUsingOperation(borderRect, NSCompositeSourceOver); |
785 | 787 |
786 borderRect.origin.y = 0; | 788 borderRect.origin.y = 0; |
787 [highlightColor set]; | 789 [highlightColor set]; |
788 NSRectFillUsingOperation(borderRect, NSCompositeSourceOver); | 790 NSRectFillUsingOperation(borderRect, NSCompositeSourceOver); |
789 } | 791 } |
790 | |
791 [context restoreGraphicsState]; | |
792 } | 792 } |
793 | 793 |
794 - (void)viewDidMoveToWindow { | 794 - (void)viewDidMoveToWindow { |
795 [super viewDidMoveToWindow]; | 795 [super viewDidMoveToWindow]; |
796 if ([self window]) { | 796 if ([self window]) { |
797 [controller_ updateTitleColor]; | 797 [controller_ updateTitleColor]; |
798 } | 798 } |
799 } | 799 } |
800 | 800 |
801 - (void)setClosing:(BOOL)closing { | 801 - (void)setClosing:(BOOL)closing { |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1060 topRight.y) | 1060 topRight.y) |
1061 controlPoint2:NSMakePoint(bottomRight.x - baseControlPointOutset, | 1061 controlPoint2:NSMakePoint(bottomRight.x - baseControlPointOutset, |
1062 bottomRight.y)]; | 1062 bottomRight.y)]; |
1063 [path lineToPoint:NSMakePoint(bottomRight.x + lineWidth, bottomRight.y)]; | 1063 [path lineToPoint:NSMakePoint(bottomRight.x + lineWidth, bottomRight.y)]; |
1064 [path lineToPoint:NSMakePoint(bottomRight.x + lineWidth, | 1064 [path lineToPoint:NSMakePoint(bottomRight.x + lineWidth, |
1065 bottomRight.y - (2 * lineWidth))]; | 1065 bottomRight.y - (2 * lineWidth))]; |
1066 return path; | 1066 return path; |
1067 } | 1067 } |
1068 | 1068 |
1069 @end // @implementation TabView(Private) | 1069 @end // @implementation TabView(Private) |
OLD | NEW |