Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: chrome/browser/ui/cocoa/tabs/tab_view.mm

Issue 19576007: Refactor themePatternPhase and tab_view in preparation for fixing crbug.com/176857 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 bool usingDefaultTheme = themeProvider && themeProvider->UsingDefaultTheme();
Nico 2013/07/18 19:58:30 Why did this move up? It's not used until before w
313 328 NSPoint phase = [[self window]
329 themePatternPhaseForAlignment: THEME_PATTERN_ALIGN_WITH_TAB_STRIP];
330 [context cr_setPatternPhase:phase forView:self];
314 331
315 CGImageRef mask([self tabClippingMask]); 332 CGImageRef mask([self tabClippingMask]);
316 CGRect maskBounds = CGRectMake(0, 0, maskCacheWidth_, kMaskHeight); 333 CGRect maskBounds = CGRectMake(0, 0, maskCacheWidth_, kMaskHeight);
317 CGContextClipToMask(cgContext, maskBounds, mask); 334 CGContextClipToMask(cgContext, maskBounds, mask);
318 335
319 bool selected = [self state]; 336 if ([self state]) {
Nico 2013/07/18 19:58:30 nit: Keeping the bool is imo better for readabilit
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
326 bool usingDefaultTheme = themeProvider && themeProvider->UsingDefaultTheme(); 346 // Draw the tab background.
327 NSColor* backgroundImageColor = [self backgroundColorForSelected:selected]; 347 NSColor* backgroundImageColor = [self backgroundColorForSelected:NO];
348 [backgroundImageColor set];
349 // Themes can have partially transparent images. NSRectFill() is measurably
350 // faster though, so call it for the known-safe default theme.
351 if (usingDefaultTheme)
352 NSRectFill(dirtyRect);
353 else
354 NSRectFillUsingOperation(dirtyRect, NSCompositeSourceOver);
328 355
329 // Don't draw the window/tab bar background when selected, since the tab 356 // 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]; 357 CGFloat hoverAlpha = [self hoverAlpha];
344 CGFloat alertAlpha = [self alertAlpha]; 358 CGFloat alertAlpha = [self alertAlpha];
345 if (selected || hoverAlpha > 0 || alertAlpha > 0) { 359 if (hoverAlpha > 0 || alertAlpha > 0) {
346 gfx::ScopedNSGraphicsContextSaveGState contextSave; 360 gfx::ScopedNSGraphicsContextSaveGState contextSave;
361 CGContextBeginTransparencyLayer(cgContext, 0);
347 362
348 // Draw the selected background / glow overlay. 363 // The alert glow overlay is like the selected state but at most at most 80%
349 CGContextBeginTransparencyLayer(cgContext, 0); 364 // opaque. The hover glow brings up the overlay's opacity at most 50%.
350 if (!selected) { 365 CGFloat backgroundAlpha = 0.8 * alertAlpha;
351 // The alert glow overlay is like the selected state but at most at most 366 backgroundAlpha += (1 - backgroundAlpha) * 0.5 * hoverAlpha;
352 // 80% opaque. The hover glow brings up the overlay's opacity at most 367 CGContextSetAlpha(cgContext, backgroundAlpha);
353 // 50%.
354 CGFloat backgroundAlpha = 0.8 * alertAlpha;
355 backgroundAlpha += (1 - backgroundAlpha) * 0.5 * hoverAlpha;
356 CGContextSetAlpha(cgContext, backgroundAlpha);
357 }
358 368
359 // For background tabs, this branch is taken to draw a highlight. The 369 [self drawFillForActiveTab:dirtyRect];
360 // highlight is drawn using the foreground tab bitmap.
pkotwicz 2013/07/17 21:24:01 [self drawFillForActiveTab:dirtyRect] is used to d
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 370
372 // ui::ThemeProvider::HasCustomImage is true only if the theme provides the 371 // 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 372 // 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 373 // theme machinery will make one if given a frame image. See
375 // BrowserThemePack::GenerateTabBackgroundImages for details. 374 // BrowserThemePack::GenerateTabBackgroundImages for details.
376 BOOL hasCustomTheme = themeProvider && 375 BOOL hasCustomTheme = themeProvider &&
377 (themeProvider->HasCustomImage(IDR_THEME_TAB_BACKGROUND) || 376 (themeProvider->HasCustomImage(IDR_THEME_TAB_BACKGROUND) ||
378 themeProvider->HasCustomImage(IDR_THEME_FRAME)); 377 themeProvider->HasCustomImage(IDR_THEME_FRAME));
379 // Draw a mouse hover gradient for the default themes. 378 // Draw a mouse hover gradient for the default themes.
380 if (!selected && hoverAlpha > 0) { 379 if (hoverAlpha > 0) {
381 if (themeProvider && !hasCustomTheme) { 380 if (themeProvider && !hasCustomTheme) {
382 base::scoped_nsobject<NSGradient> glow([NSGradient alloc]); 381 base::scoped_nsobject<NSGradient> glow([NSGradient alloc]);
383 [glow initWithStartingColor:[NSColor colorWithCalibratedWhite:1.0 382 [glow initWithStartingColor:[NSColor colorWithCalibratedWhite:1.0
384 alpha:1.0 * hoverAlpha] 383 alpha:1.0 * hoverAlpha]
385 endingColor:[NSColor colorWithCalibratedWhite:1.0 384 endingColor:[NSColor colorWithCalibratedWhite:1.0
386 alpha:0.0]]; 385 alpha:0.0]];
387 NSRect rect = [self bounds]; 386 NSRect rect = [self bounds];
388 NSPoint point = hoverPoint_; 387 NSPoint point = hoverPoint_;
389 point.y = NSHeight(rect); 388 point.y = NSHeight(rect);
390 [glow drawFromCenter:point 389 [glow drawFromCenter:point
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 CGFloat middleWidth = tabWidth - leftWidth - rightWidth; 704 CGFloat middleWidth = tabWidth - leftWidth - rightWidth;
706 NSRect middleRect = NSMakeRect(leftWidth, 0, middleWidth, kFillHeight); 705 NSRect middleRect = NSMakeRect(leftWidth, 0, middleWidth, kFillHeight);
707 [[NSColor whiteColor] setFill]; 706 [[NSColor whiteColor] setFill];
708 NSRectFill(middleRect); 707 NSRectFill(middleRect);
709 708
710 maskCache_.reset(CGBitmapContextCreateImage(maskContext)); 709 maskCache_.reset(CGBitmapContextCreateImage(maskContext));
711 return maskCache_; 710 return maskCache_;
712 } 711 }
713 712
714 @end // @implementation TabView(Private) 713 @end // @implementation TabView(Private)
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/tabs/tab_strip_view.mm ('k') | chrome/browser/ui/cocoa/tabs/tab_window_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698