OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/tabpose_window.h" | 5 #import "chrome/browser/ui/cocoa/tabpose_window.h" |
6 | 6 |
7 #import <QuartzCore/QuartzCore.h> | 7 #import <QuartzCore/QuartzCore.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 @implementation GrayGradientLayer | 82 @implementation GrayGradientLayer |
83 - (id)initWithStartGray:(CGFloat)startGray endGray:(CGFloat)endGray { | 83 - (id)initWithStartGray:(CGFloat)startGray endGray:(CGFloat)endGray { |
84 if ((self = [super init])) { | 84 if ((self = [super init])) { |
85 startGray_ = startGray; | 85 startGray_ = startGray; |
86 endGray_ = endGray; | 86 endGray_ = endGray; |
87 } | 87 } |
88 return self; | 88 return self; |
89 } | 89 } |
90 | 90 |
91 - (void)drawInContext:(CGContextRef)context { | 91 - (void)drawInContext:(CGContextRef)context { |
92 base::mac::ScopedCFTypeRef<CGColorSpaceRef> grayColorSpace( | 92 base::ScopedCFTypeRef<CGColorSpaceRef> grayColorSpace( |
93 CGColorSpaceCreateWithName(kCGColorSpaceGenericGray)); | 93 CGColorSpaceCreateWithName(kCGColorSpaceGenericGray)); |
94 CGFloat grays[] = { startGray_, 1.0, endGray_, 1.0 }; | 94 CGFloat grays[] = { startGray_, 1.0, endGray_, 1.0 }; |
95 CGFloat locations[] = { 0, 1 }; | 95 CGFloat locations[] = { 0, 1 }; |
96 base::mac::ScopedCFTypeRef<CGGradientRef> gradient( | 96 base::ScopedCFTypeRef<CGGradientRef> gradient( |
97 CGGradientCreateWithColorComponents( | 97 CGGradientCreateWithColorComponents( |
98 grayColorSpace.get(), grays, locations, arraysize(locations))); | 98 grayColorSpace.get(), grays, locations, arraysize(locations))); |
99 CGPoint topLeft = CGPointMake(0.0, self.bounds.size.height); | 99 CGPoint topLeft = CGPointMake(0.0, self.bounds.size.height); |
100 CGContextDrawLinearGradient(context, gradient.get(), topLeft, CGPointZero, 0); | 100 CGContextDrawLinearGradient(context, gradient.get(), topLeft, CGPointZero, 0); |
101 } | 101 } |
102 @end | 102 @end |
103 | 103 |
104 namespace tabpose { | 104 namespace tabpose { |
105 class ThumbnailLoader; | 105 class ThumbnailLoader; |
106 } | 106 } |
107 | 107 |
108 // A CALayer that draws a thumbnail for a WebContents object. The layer | 108 // A CALayer that draws a thumbnail for a WebContents object. The layer |
109 // tries to draw the WebContents's backing store directly if possible, and | 109 // tries to draw the WebContents's backing store directly if possible, and |
110 // requests a thumbnail bitmap from the WebContents's renderer process if not. | 110 // requests a thumbnail bitmap from the WebContents's renderer process if not. |
111 @interface ThumbnailLayer : CALayer { | 111 @interface ThumbnailLayer : CALayer { |
112 // The WebContents the thumbnail is for. | 112 // The WebContents the thumbnail is for. |
113 content::WebContents* contents_; // weak | 113 content::WebContents* contents_; // weak |
114 | 114 |
115 // The size the thumbnail is drawn at when zoomed in. | 115 // The size the thumbnail is drawn at when zoomed in. |
116 NSSize fullSize_; | 116 NSSize fullSize_; |
117 | 117 |
118 // Used to load a thumbnail, if required. | 118 // Used to load a thumbnail, if required. |
119 scoped_refptr<tabpose::ThumbnailLoader> loader_; | 119 scoped_refptr<tabpose::ThumbnailLoader> loader_; |
120 | 120 |
121 // If the backing store couldn't be used and a thumbnail was returned from a | 121 // If the backing store couldn't be used and a thumbnail was returned from a |
122 // renderer process, it's stored in |thumbnail_|. | 122 // renderer process, it's stored in |thumbnail_|. |
123 base::mac::ScopedCFTypeRef<CGImageRef> thumbnail_; | 123 base::ScopedCFTypeRef<CGImageRef> thumbnail_; |
124 | 124 |
125 // True if the layer already sent a thumbnail request to a renderer. | 125 // True if the layer already sent a thumbnail request to a renderer. |
126 BOOL didSendLoad_; | 126 BOOL didSendLoad_; |
127 } | 127 } |
128 - (id)initWithWebContents:(content::WebContents*)contents | 128 - (id)initWithWebContents:(content::WebContents*)contents |
129 fullSize:(NSSize)fullSize; | 129 fullSize:(NSSize)fullSize; |
130 - (void)drawInContext:(CGContextRef)context; | 130 - (void)drawInContext:(CGContextRef)context; |
131 - (void)setThumbnail:(const SkBitmap&)bitmap; | 131 - (void)setThumbnail:(const SkBitmap&)bitmap; |
132 @end | 132 @end |
133 | 133 |
(...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1024 layer.get().layoutManager = [CAConstraintLayoutManager layoutManager]; | 1024 layer.get().layoutManager = [CAConstraintLayoutManager layoutManager]; |
1025 [layer.get() addSublayer:closeLayer]; | 1025 [layer.get() addSublayer:closeLayer]; |
1026 | 1026 |
1027 [bgLayer_ addSublayer:layer]; | 1027 [bgLayer_ addSublayer:layer]; |
1028 [allThumbnailLayers_ addObject:layer]; | 1028 [allThumbnailLayers_ addObject:layer]; |
1029 | 1029 |
1030 // Favicon and title. | 1030 // Favicon and title. |
1031 NSFont* font = [NSFont systemFontOfSize:tile.title_font_size()]; | 1031 NSFont* font = [NSFont systemFontOfSize:tile.title_font_size()]; |
1032 tile.set_font_metrics([font ascender], -[font descender]); | 1032 tile.set_font_metrics([font ascender], -[font descender]); |
1033 | 1033 |
1034 base::mac::ScopedCFTypeRef<CGImageRef> favicon( | 1034 base::ScopedCFTypeRef<CGImageRef> favicon( |
1035 base::mac::CopyNSImageToCGImage(tile.favicon())); | 1035 base::mac::CopyNSImageToCGImage(tile.favicon())); |
1036 | 1036 |
1037 CALayer* faviconLayer = [CALayer layer]; | 1037 CALayer* faviconLayer = [CALayer layer]; |
1038 if (showZoom) { | 1038 if (showZoom) { |
1039 AnimateCALayerFrameFromTo( | 1039 AnimateCALayerFrameFromTo( |
1040 faviconLayer, | 1040 faviconLayer, |
1041 tile.GetFaviconStartRectRelativeTo(tileSet_->selected_tile()), | 1041 tile.GetFaviconStartRectRelativeTo(tileSet_->selected_tile()), |
1042 tile.favicon_rect(), | 1042 tile.favicon_rect(), |
1043 interval, | 1043 interval, |
1044 nil); | 1044 nil); |
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1661 tile.set_tab_contents(contents); | 1661 tile.set_tab_contents(contents); |
1662 ThumbnailLayer* thumbLayer = [allThumbnailLayers_ objectAtIndex:index]; | 1662 ThumbnailLayer* thumbLayer = [allThumbnailLayers_ objectAtIndex:index]; |
1663 [thumbLayer setWebContents:contents]; | 1663 [thumbLayer setWebContents:contents]; |
1664 } | 1664 } |
1665 | 1665 |
1666 - (void)tabStripModelDeleted { | 1666 - (void)tabStripModelDeleted { |
1667 [self close]; | 1667 [self close]; |
1668 } | 1668 } |
1669 | 1669 |
1670 @end | 1670 @end |
OLD | NEW |