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 12 matching lines...) Expand all Loading... | |
23 #include "chrome/browser/devtools/devtools_window.h" | 23 #include "chrome/browser/devtools/devtools_window.h" |
24 #include "chrome/browser/extensions/tab_helper.h" | 24 #include "chrome/browser/extensions/tab_helper.h" |
25 #include "chrome/browser/favicon/favicon_tab_helper.h" | 25 #include "chrome/browser/favicon/favicon_tab_helper.h" |
26 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
27 #include "chrome/browser/profiles/profile_manager.h" | 27 #include "chrome/browser/profiles/profile_manager.h" |
28 #include "chrome/browser/themes/theme_service.h" | 28 #include "chrome/browser/themes/theme_service.h" |
29 #include "chrome/browser/ui/browser.h" | 29 #include "chrome/browser/ui/browser.h" |
30 #include "chrome/browser/ui/browser_navigator.h" | 30 #include "chrome/browser/ui/browser_navigator.h" |
31 #include "chrome/browser/ui/browser_tabstrip.h" | 31 #include "chrome/browser/ui/browser_tabstrip.h" |
32 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 32 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
33 #import "chrome/browser/ui/cocoa/browser_window_utils.h" | |
33 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con troller.h" | 34 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con troller.h" |
34 #include "chrome/browser/ui/cocoa/drag_util.h" | 35 #include "chrome/browser/ui/cocoa/drag_util.h" |
35 #import "chrome/browser/ui/cocoa/image_button_cell.h" | 36 #import "chrome/browser/ui/cocoa/image_button_cell.h" |
36 #import "chrome/browser/ui/cocoa/new_tab_button.h" | 37 #import "chrome/browser/ui/cocoa/new_tab_button.h" |
37 #import "chrome/browser/ui/cocoa/tab_contents/favicon_util_mac.h" | 38 #import "chrome/browser/ui/cocoa/tab_contents/favicon_util_mac.h" |
38 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" | 39 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" |
39 #import "chrome/browser/ui/cocoa/tabs/tab_audio_indicator_view_mac.h" | 40 #import "chrome/browser/ui/cocoa/tabs/tab_audio_indicator_view_mac.h" |
40 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" | 41 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" |
41 #import "chrome/browser/ui/cocoa/tabs/tab_projecting_image_view.h" | 42 #import "chrome/browser/ui/cocoa/tabs/tab_projecting_image_view.h" |
42 #import "chrome/browser/ui/cocoa/tabs/tab_strip_drag_controller.h" | 43 #import "chrome/browser/ui/cocoa/tabs/tab_strip_drag_controller.h" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 [result addRepresentation:bmpImageRep]; | 185 [result addRepresentation:bmpImageRep]; |
185 } | 186 } |
186 [NSGraphicsContext restoreGraphicsState]; | 187 [NSGraphicsContext restoreGraphicsState]; |
187 | 188 |
188 return result.release(); | 189 return result.release(); |
189 } | 190 } |
190 | 191 |
191 // Takes a normal bitmap and a mask image and returns an image the size of the | 192 // Takes a normal bitmap and a mask image and returns an image the size of the |
192 // mask that has pixels from |image| but alpha information from |mask|. | 193 // mask that has pixels from |image| but alpha information from |mask|. |
193 NSImage* ApplyMask(NSImage* image, NSImage* mask) { | 194 NSImage* ApplyMask(NSImage* image, NSImage* mask) { |
195 DCHECK_EQ([image size].width, [mask size].width); | |
196 DCHECK_EQ([image size].height, [mask size].height); | |
197 | |
194 return [CreateImageWithSize([mask size], ^(NSSize size) { | 198 return [CreateImageWithSize([mask size], ^(NSSize size) { |
195 // Skip a few pixels from the top of the tab background gradient, because | 199 [image drawAtPoint:NSZeroPoint |
196 // the new tab button is not drawn at the very top of the browser window. | 200 fromRect:NSMakeRect(0, 0, size.width, size.height) |
197 const int kYOffset = 10; | 201 operation:NSCompositeCopy |
198 CGFloat width = size.width; | 202 fraction:1.0]; |
199 CGFloat height = size.height; | |
200 | |
201 // In some themes, the tab background image is narrower than the | |
202 // new tab button, so tile the background image. | |
203 CGFloat x = 0; | |
204 // The floor() is to make sure images with odd widths don't draw to the | |
205 // same pixel twice on retina displays. (Using NSDrawThreePartImage() | |
206 // caused a startup perf regression, so that cannot be used.) | |
207 CGFloat tileWidth = floor(std::min(width, [image size].width)); | |
208 while (x < width) { | |
209 [image drawAtPoint:NSMakePoint(x, 0) | |
210 fromRect:NSMakeRect(0, | |
211 [image size].height - height - kYOffset, | |
212 tileWidth, | |
213 height) | |
214 operation:NSCompositeCopy | |
215 fraction:1.0]; | |
216 x += tileWidth; | |
217 } | |
218 | |
219 [mask drawAtPoint:NSZeroPoint | 203 [mask drawAtPoint:NSZeroPoint |
220 fromRect:NSMakeRect(0, 0, width, height) | 204 fromRect:NSMakeRect(0, 0, size.width, size.height) |
221 operation:NSCompositeDestinationIn | 205 operation:NSCompositeDestinationIn |
222 fraction:1.0]; | 206 fraction:1.0]; |
223 }) autorelease]; | 207 }) autorelease]; |
224 } | 208 } |
225 | 209 |
226 // Creates a modified favicon used for the recording case. The mask is used for | 210 // Creates a modified favicon used for the recording case. The mask is used for |
227 // making part of the favicon transparent. (The part where the recording dot | 211 // making part of the favicon transparent. (The part where the recording dot |
228 // later is drawn.) | 212 // later is drawn.) |
229 NSImage* CreateMaskedFaviconForRecording(NSImage* image, | 213 NSImage* CreateMaskedFaviconForRecording(NSImage* image, |
230 NSImage* mask, | 214 NSImage* mask, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
268 fromRect:NSMakeRect(0, 0, width, height) | 252 fromRect:NSMakeRect(0, 0, width, height) |
269 operation:NSCompositeCopy | 253 operation:NSCompositeCopy |
270 fraction:1.0]; | 254 fraction:1.0]; |
271 [overlay drawAtPoint:NSZeroPoint | 255 [overlay drawAtPoint:NSZeroPoint |
272 fromRect:NSMakeRect(0, 0, width, height) | 256 fromRect:NSMakeRect(0, 0, width, height) |
273 operation:NSCompositeSourceOver | 257 operation:NSCompositeSourceOver |
274 fraction:alpha]; | 258 fraction:alpha]; |
275 }) autorelease]; | 259 }) autorelease]; |
276 } | 260 } |
277 | 261 |
262 // Tiles |image| horizontally into a new NSImage of |size|. |yInset| refers | |
263 // to the position from the bottom of the returned image at which the top of | |
264 // |image| should be painted. | |
265 NSImage* TileHorizontally(NSImage* image, CGFloat yInset, NSSize size) { | |
sail
2013/08/22 18:23:01
Could use better variable names. For example:
s
| |
266 return [CreateImageWithSize(size, ^(NSSize size) { | |
sail
2013/08/22 18:23:01
shouldn't use the same variable name as the outer
| |
267 CGFloat width = size.width; | |
sail
2013/08/22 18:23:01
Same problem with variable names. Maybe remove all
| |
268 CGFloat height = size.height; | |
269 | |
270 CGFloat x = 0; | |
271 // The floor() is to make sure images with odd widths and height don't | |
272 // draw to the same pixel twice on retina displays. (Using | |
273 // NSDrawThreePartImage() caused a startup perf regression, so that | |
274 // cannot be used.) | |
275 CGFloat tileWidth = floor(std::min(width, [image size].width)); | |
276 while (x < width) { | |
277 [image drawAtPoint:NSMakePoint(x, 0) | |
278 fromRect:NSMakeRect(0, | |
279 [image size].height - yInset, | |
280 tileWidth, | |
281 height) | |
282 operation:NSCompositeCopy | |
283 fraction:1.0]; | |
284 x += tileWidth; | |
285 } | |
286 }) autorelease]; | |
287 } | |
288 | |
289 // Computes the y position that the top of a theme image with |alignment| | |
290 // should be painted at. The returned y position is in the coordinates of an | |
291 // NSImage of |dst_height| which is centered on the new tab button. This method | |
292 // is a helper for [TabStripController setNewTabImages]. | |
293 int NewTabButtonThemeBackgroundYPosition(TabStripView* tabstrip, | |
294 ThemeImageAlignment alignment, | |
295 CGFloat dstHeight) { | |
296 CGFloat yPositionInTabstrip = | |
sail
2013/08/22 18:23:01
use c style variable names? more above and below
| |
297 [BrowserWindowUtils themeImagePositionInTabStripCoords:tabstrip | |
298 alignment:alignment].y; | |
299 // The image is centered in the new tab button. | |
300 NSView* newTabButton = [tabstrip getNewTabButton]; | |
301 return yPositionInTabstrip - | |
302 roundf((NSHeight([newTabButton bounds]) - dstHeight) / 2.0); | |
303 } | |
304 | |
278 } // namespace | 305 } // namespace |
279 | 306 |
280 @interface TabStripController (Private) | 307 @interface TabStripController (Private) |
281 - (void)addSubviewToPermanentList:(NSView*)aView; | 308 - (void)addSubviewToPermanentList:(NSView*)aView; |
282 - (void)regenerateSubviewList; | 309 - (void)regenerateSubviewList; |
283 - (NSInteger)indexForContentsView:(NSView*)view; | 310 - (NSInteger)indexForContentsView:(NSView*)view; |
284 - (NSImageView*)iconImageViewForContents:(content::WebContents*)contents; | 311 - (NSImageView*)iconImageViewForContents:(content::WebContents*)contents; |
285 - (void)updateFaviconForContents:(content::WebContents*)contents | 312 - (void)updateFaviconForContents:(content::WebContents*)contents |
286 atIndex:(NSInteger)modelIndex; | 313 atIndex:(NSInteger)modelIndex; |
287 - (void)layoutTabsWithAnimation:(BOOL)animate | 314 - (void)layoutTabsWithAnimation:(BOOL)animate |
(...skipping 1973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2261 ThemeService *theme = | 2288 ThemeService *theme = |
2262 static_cast<ThemeService*>([[tabStripView_ window] themeProvider]); | 2289 static_cast<ThemeService*>([[tabStripView_ window] themeProvider]); |
2263 if (!theme) | 2290 if (!theme) |
2264 return; | 2291 return; |
2265 | 2292 |
2266 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 2293 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
2267 NSImage* mask = rb.GetNativeImageNamed(IDR_NEWTAB_BUTTON_MASK).ToNSImage(); | 2294 NSImage* mask = rb.GetNativeImageNamed(IDR_NEWTAB_BUTTON_MASK).ToNSImage(); |
2268 NSImage* normal = rb.GetNativeImageNamed(IDR_NEWTAB_BUTTON).ToNSImage(); | 2295 NSImage* normal = rb.GetNativeImageNamed(IDR_NEWTAB_BUTTON).ToNSImage(); |
2269 NSImage* hover = rb.GetNativeImageNamed(IDR_NEWTAB_BUTTON_H).ToNSImage(); | 2296 NSImage* hover = rb.GetNativeImageNamed(IDR_NEWTAB_BUTTON_H).ToNSImage(); |
2270 NSImage* pressed = rb.GetNativeImageNamed(IDR_NEWTAB_BUTTON_P).ToNSImage(); | 2297 NSImage* pressed = rb.GetNativeImageNamed(IDR_NEWTAB_BUTTON_P).ToNSImage(); |
2298 NSImage* bgActive = theme->GetNSImageNamed(IDR_THEME_TAB_BACKGROUND); | |
2299 NSImage* bgActiveOverlay = nil; | |
2300 if (theme->HasCustomImage(IDR_THEME_TAB_BACKGROUND_OVERLAY)) { | |
2301 bgActiveOverlay = theme->GetNSImageNamed( | |
2302 IDR_THEME_TAB_BACKGROUND_OVERLAY); | |
2303 } | |
2271 | 2304 |
2272 NSImage* foreground = ApplyMask( | 2305 int yPositionAlignWithFrame = NewTabButtonThemeBackgroundYPosition( |
2273 theme->GetNSImageNamed(IDR_THEME_TAB_BACKGROUND), mask); | 2306 tabStripView_, THEME_IMAGE_ALIGN_WITH_FRAME, [mask size].height); |
2307 int yPositionAlignWithTabStrip = NewTabButtonThemeBackgroundYPosition( | |
2308 tabStripView_, THEME_IMAGE_ALIGN_WITH_TAB_STRIP, [mask size].height); | |
2309 | |
2310 // Create the foreground image by combining the tinted frame image | |
2311 // (IDR_THEME_TAB_BACKGROUND) and the custom theme provided overlay | |
2312 // (IDR_THEME_TAB_BACKGROUND_OVERLAY). Tile the images because the images | |
2313 // can be narrower than the new tab button for some themes. | |
2314 NSImage* unmaskedForeground = TileHorizontally(bgActive, | |
2315 yPositionAlignWithFrame, [mask size]); | |
2316 if (bgActiveOverlay) { | |
2317 NSImage* tiledOverlay = TileHorizontally(bgActiveOverlay, | |
2318 yPositionAlignWithTabStrip, [mask size]); | |
2319 unmaskedForeground = Overlay(unmaskedForeground, tiledOverlay, 1.0); | |
2320 } | |
2321 NSImage* foreground = ApplyMask(unmaskedForeground, mask); | |
2274 | 2322 |
2275 [[newTabButton_ cell] setImage:Overlay(foreground, normal, 1.0) | 2323 [[newTabButton_ cell] setImage:Overlay(foreground, normal, 1.0) |
2276 forButtonState:image_button_cell::kDefaultState]; | 2324 forButtonState:image_button_cell::kDefaultState]; |
2277 [[newTabButton_ cell] setImage:Overlay(foreground, hover, 1.0) | 2325 [[newTabButton_ cell] setImage:Overlay(foreground, hover, 1.0) |
2278 forButtonState:image_button_cell::kHoverState]; | 2326 forButtonState:image_button_cell::kHoverState]; |
2279 [[newTabButton_ cell] setImage:Overlay(foreground, pressed, 1.0) | 2327 [[newTabButton_ cell] setImage:Overlay(foreground, pressed, 1.0) |
2280 forButtonState:image_button_cell::kPressedState]; | 2328 forButtonState:image_button_cell::kPressedState]; |
2281 | 2329 |
2282 // IDR_THEME_TAB_BACKGROUND_INACTIVE is only used with the default theme. | 2330 // IDR_THEME_TAB_BACKGROUND_INACTIVE is only used with the default theme. |
2283 if (theme->UsingDefaultTheme()) { | 2331 if (theme->UsingDefaultTheme()) { |
2284 const CGFloat alpha = tabs::kImageNoFocusAlpha; | 2332 const CGFloat alpha = tabs::kImageNoFocusAlpha; |
2285 NSImage* background = ApplyMask( | 2333 NSImage* unmasked_background = TileHorizontally( |
sail
2013/08/22 18:23:01
camel case?
| |
2286 theme->GetNSImageNamed(IDR_THEME_TAB_BACKGROUND_INACTIVE), mask); | 2334 rb.GetNativeImageNamed(IDR_THEME_TAB_BACKGROUND_INACTIVE).ToNSImage(), |
sail
2013/08/22 18:23:01
Why get this from the resource bungle but IDR_THEM
pkotwicz
2013/10/25 05:15:34
IDR_THEME_TAB_BACKGROUND_INACTIVE is not a themeab
| |
2335 yPositionAlignWithTabStrip, | |
2336 [mask size]); | |
2337 NSImage* background = ApplyMask(unmasked_background, mask); | |
2287 [[newTabButton_ cell] setImage:Overlay(background, normal, alpha) | 2338 [[newTabButton_ cell] setImage:Overlay(background, normal, alpha) |
2288 forButtonState:image_button_cell::kDefaultStateBackground]; | 2339 forButtonState:image_button_cell::kDefaultStateBackground]; |
2289 [[newTabButton_ cell] setImage:Overlay(background, hover, alpha) | 2340 [[newTabButton_ cell] setImage:Overlay(background, hover, alpha) |
2290 forButtonState:image_button_cell::kHoverStateBackground]; | 2341 forButtonState:image_button_cell::kHoverStateBackground]; |
2291 } else { | 2342 } else { |
2292 [[newTabButton_ cell] setImage:nil | 2343 [[newTabButton_ cell] setImage:nil |
2293 forButtonState:image_button_cell::kDefaultStateBackground]; | 2344 forButtonState:image_button_cell::kDefaultStateBackground]; |
2294 [[newTabButton_ cell] setImage:nil | 2345 [[newTabButton_ cell] setImage:nil |
2295 forButtonState:image_button_cell::kHoverStateBackground]; | 2346 forButtonState:image_button_cell::kHoverStateBackground]; |
2296 } | 2347 } |
2297 } | 2348 } |
2298 | 2349 |
2299 @end | 2350 @end |
2300 | 2351 |
2301 NSView* GetSheetParentViewForWebContents(WebContents* web_contents) { | 2352 NSView* GetSheetParentViewForWebContents(WebContents* web_contents) { |
2302 // View hierarchy of the contents view: | 2353 // View hierarchy of the contents view: |
2303 // NSView -- switchView, same for all tabs | 2354 // NSView -- switchView, same for all tabs |
2304 // +- NSView -- TabContentsController's view | 2355 // +- NSView -- TabContentsController's view |
2305 // +- TabContentsViewCocoa | 2356 // +- TabContentsViewCocoa |
2306 // | 2357 // |
2307 // Changing it? Do not forget to modify | 2358 // Changing it? Do not forget to modify |
2308 // -[TabStripController swapInTabAtIndex:] too. | 2359 // -[TabStripController swapInTabAtIndex:] too. |
2309 return [web_contents->GetView()->GetNativeView() superview]; | 2360 return [web_contents->GetView()->GetNativeView() superview]; |
2310 } | 2361 } |
OLD | NEW |