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_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 #include "base/mac/sdk_forward_declarations.h" | 8 #include "base/mac/sdk_forward_declarations.h" |
9 #include "chrome/browser/themes/theme_service.h" | 9 #include "chrome/browser/themes/theme_service.h" |
10 #import "chrome/browser/ui/cocoa/nsview_additions.h" | 10 #import "chrome/browser/ui/cocoa/nsview_additions.h" |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 }; | 294 }; |
295 | 295 |
296 // Themes don't have an inactive image so only look for one if there's no | 296 // Themes don't have an inactive image so only look for one if there's no |
297 // theme. | 297 // theme. |
298 bool active = [[self window] isKeyWindow] || [[self window] isMainWindow] || | 298 bool active = [[self window] isKeyWindow] || [[self window] isMainWindow] || |
299 !themeProvider->UsingDefaultTheme(); | 299 !themeProvider->UsingDefaultTheme(); |
300 return themeProvider->GetNSImageColorNamed( | 300 return themeProvider->GetNSImageColorNamed( |
301 bitmapResources[active][selected], true); | 301 bitmapResources[active][selected], true); |
302 } | 302 } |
303 | 303 |
| 304 // Draws the active tab background. |
| 305 - (void)drawFillForActiveTab:(NSRect)dirtyRect { |
| 306 NSColor* backgroundImageColor = [self backgroundColorForSelected:YES]; |
| 307 [backgroundImageColor set]; |
| 308 |
| 309 // Themes can have partially transparent images. NSRectFill() is measurably |
| 310 // faster though, so call it for the known-safe default theme. |
| 311 ThemeService* themeProvider = |
| 312 static_cast<ThemeService*>([[self window] themeProvider]); |
| 313 if (themeProvider && themeProvider->UsingDefaultTheme()) |
| 314 NSRectFill(dirtyRect); |
| 315 else |
| 316 NSRectFillUsingOperation(dirtyRect, NSCompositeSourceOver); |
| 317 } |
| 318 |
304 // Draws the tab background. | 319 // Draws the tab background. |
305 - (void)drawFill:(NSRect)dirtyRect { | 320 - (void)drawFill:(NSRect)dirtyRect { |
306 gfx::ScopedNSGraphicsContextSaveGState scopedGState; | 321 gfx::ScopedNSGraphicsContextSaveGState scopedGState; |
307 NSGraphicsContext* context = [NSGraphicsContext currentContext]; | 322 NSGraphicsContext* context = [NSGraphicsContext currentContext]; |
308 CGContextRef cgContext = static_cast<CGContextRef>([context graphicsPort]); | 323 CGContextRef cgContext = static_cast<CGContextRef>([context graphicsPort]); |
309 | 324 |
310 ThemeService* themeProvider = | 325 ThemeService* themeProvider = |
311 static_cast<ThemeService*>([[self window] themeProvider]); | 326 static_cast<ThemeService*>([[self window] themeProvider]); |
312 [context cr_setPatternPhase:[[self window] themePatternPhase] forView:self]; | 327 NSPoint phase = [[self window] |
313 | 328 themePatternPhaseForAlignment: THEME_PATTERN_ALIGN_WITH_TAB_STRIP]; |
| 329 [context cr_setPatternPhase:phase forView:self]; |
314 | 330 |
315 CGImageRef mask([self tabClippingMask]); | 331 CGImageRef mask([self tabClippingMask]); |
316 CGRect maskBounds = CGRectMake(0, 0, maskCacheWidth_, kMaskHeight); | 332 CGRect maskBounds = CGRectMake(0, 0, maskCacheWidth_, kMaskHeight); |
317 CGContextClipToMask(cgContext, maskBounds, mask); | 333 CGContextClipToMask(cgContext, maskBounds, mask); |
318 | 334 |
319 bool selected = [self state]; | 335 bool selected = [self state]; |
| 336 if (selected) { |
| 337 [self drawFillForActiveTab:dirtyRect]; |
| 338 return; |
| 339 } |
320 | 340 |
321 // Background tabs should not paint over the tab strip separator, which is | 341 // Background tabs should not paint over the tab strip separator, which is |
322 // two pixels high in both lodpi and hidpi. | 342 // two pixels high in both lodpi and hidpi. |
323 if (!selected && dirtyRect.origin.y < 1) | 343 if (dirtyRect.origin.y < 1) |
324 dirtyRect.origin.y = 2 * [self cr_lineWidth]; | 344 dirtyRect.origin.y = 2 * [self cr_lineWidth]; |
325 | 345 |
| 346 // Draw the tab background. |
| 347 NSColor* backgroundImageColor = [self backgroundColorForSelected:NO]; |
| 348 [backgroundImageColor set]; |
| 349 |
| 350 // Themes can have partially transparent images. NSRectFill() is measurably |
| 351 // faster though, so call it for the known-safe default theme. |
326 bool usingDefaultTheme = themeProvider && themeProvider->UsingDefaultTheme(); | 352 bool usingDefaultTheme = themeProvider && themeProvider->UsingDefaultTheme(); |
327 NSColor* backgroundImageColor = [self backgroundColorForSelected:selected]; | 353 if (usingDefaultTheme) |
| 354 NSRectFill(dirtyRect); |
| 355 else |
| 356 NSRectFillUsingOperation(dirtyRect, NSCompositeSourceOver); |
328 | 357 |
329 // Don't draw the window/tab bar background when selected, since the tab | 358 // Draw the glow for hover and the overlay for alerts. |
330 // background overlay drawn over it (see below) will be fully opaque. | |
331 if (!selected) { | |
332 [backgroundImageColor set]; | |
333 // Themes can have partially transparent images. NSRectFill() is measurably | |
334 // faster though, so call it for the known-safe default theme. | |
335 if (usingDefaultTheme) | |
336 NSRectFill(dirtyRect); | |
337 else | |
338 NSRectFillUsingOperation(dirtyRect, NSCompositeSourceOver); | |
339 } | |
340 | |
341 // Use the same overlay for the selected state and for hover and alert | |
342 // glows; for the selected state, it's fully opaque. | |
343 CGFloat hoverAlpha = [self hoverAlpha]; | 359 CGFloat hoverAlpha = [self hoverAlpha]; |
344 CGFloat alertAlpha = [self alertAlpha]; | 360 CGFloat alertAlpha = [self alertAlpha]; |
345 if (selected || hoverAlpha > 0 || alertAlpha > 0) { | 361 if (hoverAlpha > 0 || alertAlpha > 0) { |
346 gfx::ScopedNSGraphicsContextSaveGState contextSave; | 362 gfx::ScopedNSGraphicsContextSaveGState contextSave; |
| 363 CGContextBeginTransparencyLayer(cgContext, 0); |
347 | 364 |
348 // Draw the selected background / glow overlay. | 365 // The alert glow overlay is like the selected state but at most at most 80% |
349 CGContextBeginTransparencyLayer(cgContext, 0); | 366 // opaque. The hover glow brings up the overlay's opacity at most 50%. |
350 if (!selected) { | 367 CGFloat backgroundAlpha = 0.8 * alertAlpha; |
351 // The alert glow overlay is like the selected state but at most at most | 368 backgroundAlpha += (1 - backgroundAlpha) * 0.5 * hoverAlpha; |
352 // 80% opaque. The hover glow brings up the overlay's opacity at most | 369 CGContextSetAlpha(cgContext, backgroundAlpha); |
353 // 50%. | |
354 CGFloat backgroundAlpha = 0.8 * alertAlpha; | |
355 backgroundAlpha += (1 - backgroundAlpha) * 0.5 * hoverAlpha; | |
356 CGContextSetAlpha(cgContext, backgroundAlpha); | |
357 } | |
358 | 370 |
359 // For background tabs, this branch is taken to draw a highlight. The | 371 [self drawFillForActiveTab:dirtyRect]; |
360 // highlight is drawn using the foreground tab bitmap. | |
361 if (!selected && themeProvider) | |
362 backgroundImageColor = [self backgroundColorForSelected:YES]; | |
363 | |
364 [backgroundImageColor set]; | |
365 // Themes can have partially transparent images. NSRectFill() is measurably | |
366 // faster though, so call it for the known-safe default theme. | |
367 if (usingDefaultTheme) | |
368 NSRectFill(dirtyRect); | |
369 else | |
370 NSRectFillUsingOperation(dirtyRect, NSCompositeSourceOver); | |
371 | 372 |
372 // ui::ThemeProvider::HasCustomImage is true only if the theme provides the | 373 // ui::ThemeProvider::HasCustomImage is true only if the theme provides the |
373 // image. However, even if the theme doesn't provide a tab background, the | 374 // image. However, even if the theme doesn't provide a tab background, the |
374 // theme machinery will make one if given a frame image. See | 375 // theme machinery will make one if given a frame image. See |
375 // BrowserThemePack::GenerateTabBackgroundImages for details. | 376 // BrowserThemePack::GenerateTabBackgroundImages for details. |
376 BOOL hasCustomTheme = themeProvider && | 377 BOOL hasCustomTheme = themeProvider && |
377 (themeProvider->HasCustomImage(IDR_THEME_TAB_BACKGROUND) || | 378 (themeProvider->HasCustomImage(IDR_THEME_TAB_BACKGROUND) || |
378 themeProvider->HasCustomImage(IDR_THEME_FRAME)); | 379 themeProvider->HasCustomImage(IDR_THEME_FRAME)); |
379 // Draw a mouse hover gradient for the default themes. | 380 // Draw a mouse hover gradient for the default themes. |
380 if (!selected && hoverAlpha > 0) { | 381 if (hoverAlpha > 0) { |
381 if (themeProvider && !hasCustomTheme) { | 382 if (themeProvider && !hasCustomTheme) { |
382 base::scoped_nsobject<NSGradient> glow([NSGradient alloc]); | 383 base::scoped_nsobject<NSGradient> glow([NSGradient alloc]); |
383 [glow initWithStartingColor:[NSColor colorWithCalibratedWhite:1.0 | 384 [glow initWithStartingColor:[NSColor colorWithCalibratedWhite:1.0 |
384 alpha:1.0 * hoverAlpha] | 385 alpha:1.0 * hoverAlpha] |
385 endingColor:[NSColor colorWithCalibratedWhite:1.0 | 386 endingColor:[NSColor colorWithCalibratedWhite:1.0 |
386 alpha:0.0]]; | 387 alpha:0.0]]; |
387 NSRect rect = [self bounds]; | 388 NSRect rect = [self bounds]; |
388 NSPoint point = hoverPoint_; | 389 NSPoint point = hoverPoint_; |
389 point.y = NSHeight(rect); | 390 point.y = NSHeight(rect); |
390 [glow drawFromCenter:point | 391 [glow drawFromCenter:point |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 CGFloat middleWidth = tabWidth - leftWidth - rightWidth; | 706 CGFloat middleWidth = tabWidth - leftWidth - rightWidth; |
706 NSRect middleRect = NSMakeRect(leftWidth, 0, middleWidth, kFillHeight); | 707 NSRect middleRect = NSMakeRect(leftWidth, 0, middleWidth, kFillHeight); |
707 [[NSColor whiteColor] setFill]; | 708 [[NSColor whiteColor] setFill]; |
708 NSRectFill(middleRect); | 709 NSRectFill(middleRect); |
709 | 710 |
710 maskCache_.reset(CGBitmapContextCreateImage(maskContext)); | 711 maskCache_.reset(CGBitmapContextCreateImage(maskContext)); |
711 return maskCache_; | 712 return maskCache_; |
712 } | 713 } |
713 | 714 |
714 @end // @implementation TabView(Private) | 715 @end // @implementation TabView(Private) |
OLD | NEW |