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