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

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

Issue 18486007: Fix the misalignment on CrOS of the tab background images (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(bitmapResources[active][selected]); 300 return themeProvider->GetNSImageColorNamed(bitmapResources[active][selected]);
301 } 301 }
302 302
303 // Draws the active tab background. 303 // Draws the active tab background.
304 - (void)drawFillForActiveTab:(NSRect)dirtyRect { 304 - (void)drawFillForActiveTab:(NSRect)dirtyRect {
305 gfx::ScopedNSGraphicsContextSaveGState scopedGState;
306 NSGraphicsContext* context = [NSGraphicsContext currentContext];
307 NSPoint position = [[self window]
308 themeImagePositionForAlignment: THEME_IMAGE_ALIGN_WITH_TAB_STRIP];
sail 2013/08/22 18:23:01 no space after colon
309 [context cr_setPatternPhase:position forView:self];
310
305 NSColor* backgroundImageColor = [self backgroundColorForSelected:YES]; 311 NSColor* backgroundImageColor = [self backgroundColorForSelected:YES];
306 [backgroundImageColor set]; 312 [backgroundImageColor set];
307 313
308 // Themes can have partially transparent images. NSRectFill() is measurably 314 // Themes can have partially transparent images. NSRectFill() is measurably
309 // faster though, so call it for the known-safe default theme. 315 // faster though, so call it for the known-safe default theme.
310 ThemeService* themeProvider = 316 ThemeService* themeProvider =
311 static_cast<ThemeService*>([[self window] themeProvider]); 317 static_cast<ThemeService*>([[self window] themeProvider]);
312 if (themeProvider && themeProvider->UsingDefaultTheme()) 318 if (themeProvider && themeProvider->UsingDefaultTheme())
313 NSRectFill(dirtyRect); 319 NSRectFill(dirtyRect);
314 else 320 else
315 NSRectFillUsingOperation(dirtyRect, NSCompositeSourceOver); 321 NSRectFillUsingOperation(dirtyRect, NSCompositeSourceOver);
316 } 322 }
317 323
318 // Draws the tab background. 324 // Draws the tab background.
319 - (void)drawFill:(NSRect)dirtyRect { 325 - (void)drawFill:(NSRect)dirtyRect {
320 gfx::ScopedNSGraphicsContextSaveGState scopedGState; 326 gfx::ScopedNSGraphicsContextSaveGState scopedGState;
321 NSGraphicsContext* context = [NSGraphicsContext currentContext]; 327 NSGraphicsContext* context = [NSGraphicsContext currentContext];
322 CGContextRef cgContext = static_cast<CGContextRef>([context graphicsPort]); 328 CGContextRef cgContext = static_cast<CGContextRef>([context graphicsPort]);
323 329
324 ThemeService* themeProvider = 330 ThemeService* themeProvider =
325 static_cast<ThemeService*>([[self window] themeProvider]); 331 static_cast<ThemeService*>([[self window] themeProvider]);
326 NSPoint position = [[self window]
327 themeImagePositionForAlignment: THEME_IMAGE_ALIGN_WITH_TAB_STRIP];
328 [context cr_setPatternPhase:position forView:self];
329 332
330 CGImageRef mask([self tabClippingMask]); 333 CGImageRef mask([self tabClippingMask]);
331 CGRect maskBounds = CGRectMake(0, 0, maskCacheWidth_, kMaskHeight); 334 CGRect maskBounds = CGRectMake(0, 0, maskCacheWidth_, kMaskHeight);
332 CGContextClipToMask(cgContext, maskBounds, mask); 335 CGContextClipToMask(cgContext, maskBounds, mask);
333 336
334 bool selected = [self state]; 337 bool selected = [self state];
335 if (selected) { 338 if (selected) {
336 [self drawFillForActiveTab:dirtyRect]; 339 [self drawFillForActiveTab:dirtyRect];
337 return; 340 return;
338 } 341 }
339 342
340 // Background tabs should not paint over the tab strip separator, which is 343 // Background tabs should not paint over the tab strip separator, which is
341 // two pixels high in both lodpi and hidpi. 344 // two pixels high in both lodpi and hidpi.
342 if (dirtyRect.origin.y < 1) 345 if (dirtyRect.origin.y < 1)
343 dirtyRect.origin.y = 2 * [self cr_lineWidth]; 346 dirtyRect.origin.y = 2 * [self cr_lineWidth];
344 347
345 // Draw the tab background. 348 // Draw the tinted frame image.
349 NSPoint position = [[self window]
350 themeImagePositionForAlignment: THEME_IMAGE_ALIGN_WITH_FRAME];
sail 2013/08/22 18:23:01 no space after colon
351 [context cr_setPatternPhase:position forView:self];
346 NSColor* backgroundImageColor = [self backgroundColorForSelected:NO]; 352 NSColor* backgroundImageColor = [self backgroundColorForSelected:NO];
347 [backgroundImageColor set]; 353 [backgroundImageColor set];
348 354
349 // Themes can have partially transparent images. NSRectFill() is measurably 355 // Themes can have partially transparent images. NSRectFill() is measurably
350 // faster though, so call it for the known-safe default theme. 356 // faster though, so call it for the known-safe default theme.
351 bool usingDefaultTheme = themeProvider && themeProvider->UsingDefaultTheme(); 357 bool usingDefaultTheme = themeProvider && themeProvider->UsingDefaultTheme();
352 if (usingDefaultTheme) 358 if (usingDefaultTheme)
353 NSRectFill(dirtyRect); 359 NSRectFill(dirtyRect);
354 else 360 else
355 NSRectFillUsingOperation(dirtyRect, NSCompositeSourceOver); 361 NSRectFillUsingOperation(dirtyRect, NSCompositeSourceOver);
356 362
363 // If the theme is not the default theme, it may provide a custom overlay
364 // image. The overlay image is aligned with the top of the tab.
365 NSColor* overlayImageColor = nil;
366 if (themeProvider &&
367 themeProvider->HasCustomImage(IDR_THEME_TAB_BACKGROUND_OVERLAY)) {
368 overlayImageColor = themeProvider->GetNSImageColorNamed(
369 IDR_THEME_TAB_BACKGROUND_OVERLAY);
370 }
371 if (overlayImageColor) {
372 position = [[self window]
373 themeImagePositionForAlignment: THEME_IMAGE_ALIGN_WITH_TAB_STRIP];
sail 2013/08/22 18:23:01 no space after colon
374 [context cr_setPatternPhase:position forView:self];
375 [overlayImageColor set];
376 NSRectFillUsingOperation(dirtyRect, NSCompositeSourceOver);
377 }
378
357 // Draw the glow for hover and the overlay for alerts. 379 // Draw the glow for hover and the overlay for alerts.
358 CGFloat hoverAlpha = [self hoverAlpha]; 380 CGFloat hoverAlpha = [self hoverAlpha];
359 CGFloat alertAlpha = [self alertAlpha]; 381 CGFloat alertAlpha = [self alertAlpha];
360 if (hoverAlpha > 0 || alertAlpha > 0) { 382 if (hoverAlpha > 0 || alertAlpha > 0) {
361 gfx::ScopedNSGraphicsContextSaveGState contextSave; 383 gfx::ScopedNSGraphicsContextSaveGState contextSave;
362 CGContextBeginTransparencyLayer(cgContext, 0); 384 CGContextBeginTransparencyLayer(cgContext, 0);
363 385
364 // The alert glow overlay is like the selected state but at most at most 80% 386 // The alert glow overlay is like the selected state but at most at most 80%
365 // opaque. The hover glow brings up the overlay's opacity at most 50%. 387 // opaque. The hover glow brings up the overlay's opacity at most 50%.
366 CGFloat backgroundAlpha = 0.8 * alertAlpha; 388 CGFloat backgroundAlpha = 0.8 * alertAlpha;
367 backgroundAlpha += (1 - backgroundAlpha) * 0.5 * hoverAlpha; 389 backgroundAlpha += (1 - backgroundAlpha) * 0.5 * hoverAlpha;
368 CGContextSetAlpha(cgContext, backgroundAlpha); 390 CGContextSetAlpha(cgContext, backgroundAlpha);
369 391
370 [self drawFillForActiveTab:dirtyRect]; 392 [self drawFillForActiveTab:dirtyRect];
371 393
372 // ui::ThemeProvider::HasCustomImage is true only if the theme provides the 394 // 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 395 // 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 396 // theme machinery will make one if given a frame image. See
375 // BrowserThemePack::GenerateTabBackgroundImages for details. 397 // BrowserThemePack::GenerateTabBackgroundImages for details.
376 BOOL hasCustomTheme = themeProvider && 398 BOOL hasCustomTheme = themeProvider &&
377 (themeProvider->HasCustomImage(IDR_THEME_TAB_BACKGROUND) || 399 (themeProvider->HasCustomImage(IDR_THEME_TAB_BACKGROUND_OVERLAY) ||
378 themeProvider->HasCustomImage(IDR_THEME_FRAME)); 400 themeProvider->HasCustomImage(IDR_THEME_FRAME));
379 // Draw a mouse hover gradient for the default themes. 401 // Draw a mouse hover gradient for the default themes.
380 if (hoverAlpha > 0) { 402 if (hoverAlpha > 0) {
381 if (themeProvider && !hasCustomTheme) { 403 if (themeProvider && !hasCustomTheme) {
382 base::scoped_nsobject<NSGradient> glow([NSGradient alloc]); 404 base::scoped_nsobject<NSGradient> glow([NSGradient alloc]);
383 [glow initWithStartingColor:[NSColor colorWithCalibratedWhite:1.0 405 [glow initWithStartingColor:[NSColor colorWithCalibratedWhite:1.0
384 alpha:1.0 * hoverAlpha] 406 alpha:1.0 * hoverAlpha]
385 endingColor:[NSColor colorWithCalibratedWhite:1.0 407 endingColor:[NSColor colorWithCalibratedWhite:1.0
386 alpha:0.0]]; 408 alpha:0.0]];
387 NSRect rect = [self bounds]; 409 NSRect rect = [self bounds];
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 CGFloat middleWidth = tabWidth - leftWidth - rightWidth; 727 CGFloat middleWidth = tabWidth - leftWidth - rightWidth;
706 NSRect middleRect = NSMakeRect(leftWidth, 0, middleWidth, kFillHeight); 728 NSRect middleRect = NSMakeRect(leftWidth, 0, middleWidth, kFillHeight);
707 [[NSColor whiteColor] setFill]; 729 [[NSColor whiteColor] setFill];
708 NSRectFill(middleRect); 730 NSRectFill(middleRect);
709 731
710 maskCache_.reset(CGBitmapContextCreateImage(maskContext)); 732 maskCache_.reset(CGBitmapContextCreateImage(maskContext));
711 return maskCache_; 733 return maskCache_;
712 } 734 }
713 735
714 @end // @implementation TabView(Private) 736 @end // @implementation TabView(Private)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698