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/tabs/tab_strip_controller.h" | 5 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" |
6 | 6 |
7 #import <QuartzCore/QuartzCore.h> | 7 #import <QuartzCore/QuartzCore.h> |
8 | 8 |
9 #include <cmath> | 9 #include <cmath> |
10 #include <limits> | 10 #include <limits> |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 | 189 |
190 // Takes a normal bitmap and a mask image and returns an image the size of the | 190 // Takes a normal bitmap and a mask image and returns an image the size of the |
191 // mask that has pixels from |image| but alpha information from |mask|. | 191 // mask that has pixels from |image| but alpha information from |mask|. |
192 NSImage* ApplyMask(NSImage* image, NSImage* mask) { | 192 NSImage* ApplyMask(NSImage* image, NSImage* mask) { |
193 return [CreateImageWithSize([mask size], ^(NSSize size) { | 193 return [CreateImageWithSize([mask size], ^(NSSize size) { |
194 // Skip a few pixels from the top of the tab background gradient, because | 194 // Skip a few pixels from the top of the tab background gradient, because |
195 // the new tab button is not drawn at the very top of the browser window. | 195 // the new tab button is not drawn at the very top of the browser window. |
196 const int kYOffset = 10; | 196 const int kYOffset = 10; |
197 CGFloat width = size.width; | 197 CGFloat width = size.width; |
198 CGFloat height = size.height; | 198 CGFloat height = size.height; |
| 199 |
199 // In some themes, the tab background image is narrower than the | 200 // In some themes, the tab background image is narrower than the |
200 // new tab button, so tile the background image. | 201 // new tab button, so tile the background image. |
201 NSDrawThreePartImage( | 202 CGFloat x = 0; |
202 NSMakeRect(0, -([image size].height - height - kYOffset), | 203 // The floor() is to make sure images with odd widths don't draw to the |
203 width, [image size].height), | 204 // same pixel twice on retina displays. (Using NSDrawThreePartImage() |
204 nil, image, nil, /*vertical=*/NO, NSCompositeCopy, | 205 // caused a startup perf regression, so that cannot be used.) |
205 1.0, /*flipped=*/NO); | 206 CGFloat tileWidth = floor(std::min(width, [image size].width)); |
| 207 while (x < width) { |
| 208 [image drawAtPoint:NSMakePoint(x, 0) |
| 209 fromRect:NSMakeRect(0, |
| 210 [image size].height - height - kYOffset, |
| 211 tileWidth, |
| 212 height) |
| 213 operation:NSCompositeCopy |
| 214 fraction:1.0]; |
| 215 x += tileWidth; |
| 216 } |
| 217 |
206 [mask drawAtPoint:NSZeroPoint | 218 [mask drawAtPoint:NSZeroPoint |
207 fromRect:NSMakeRect(0, 0, width, height) | 219 fromRect:NSMakeRect(0, 0, width, height) |
208 operation:NSCompositeDestinationIn | 220 operation:NSCompositeDestinationIn |
209 fraction:1.0]; | 221 fraction:1.0]; |
210 }) autorelease]; | 222 }) autorelease]; |
211 } | 223 } |
212 | 224 |
213 // Paints |overlay| on top of |ground|. | 225 // Paints |overlay| on top of |ground|. |
214 NSImage* Overlay(NSImage* ground, NSImage* overlay, CGFloat alpha) { | 226 NSImage* Overlay(NSImage* ground, NSImage* overlay, CGFloat alpha) { |
215 DCHECK_EQ([ground size].width, [overlay size].width); | 227 DCHECK_EQ([ground size].width, [overlay size].width); |
(...skipping 2003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2219 NSView* GetSheetParentViewForWebContents(WebContents* web_contents) { | 2231 NSView* GetSheetParentViewForWebContents(WebContents* web_contents) { |
2220 // View hierarchy of the contents view: | 2232 // View hierarchy of the contents view: |
2221 // NSView -- switchView, same for all tabs | 2233 // NSView -- switchView, same for all tabs |
2222 // +- NSView -- TabContentsController's view | 2234 // +- NSView -- TabContentsController's view |
2223 // +- TabContentsViewCocoa | 2235 // +- TabContentsViewCocoa |
2224 // | 2236 // |
2225 // Changing it? Do not forget to modify | 2237 // Changing it? Do not forget to modify |
2226 // -[TabStripController swapInTabAtIndex:] too. | 2238 // -[TabStripController swapInTabAtIndex:] too. |
2227 return [web_contents->GetNativeView() superview]; | 2239 return [web_contents->GetNativeView() superview]; |
2228 } | 2240 } |
OLD | NEW |