Chromium Code Reviews| 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 "chrome/browser/themes/theme_service.h" | 8 #include "chrome/browser/themes/theme_service.h" |
| 9 #import "chrome/browser/ui/cocoa/nsview_additions.h" | 9 #import "chrome/browser/ui/cocoa/nsview_additions.h" |
| 10 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" | 10 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" |
| 11 #import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h" | 11 #import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h" |
| 12 #import "chrome/browser/ui/cocoa/themed_window.h" | 12 #import "chrome/browser/ui/cocoa/themed_window.h" |
| 13 #import "chrome/browser/ui/cocoa/view_id_util.h" | 13 #import "chrome/browser/ui/cocoa/view_id_util.h" |
| 14 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
| 15 #include "grit/theme_resources.h" | 15 #include "grit/theme_resources.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
| 17 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
| 18 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 18 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
| 19 | 19 |
| 20 #if !defined(MAC_OS_X_VERSION_10_7) || \ | 20 #if !defined(MAC_OS_X_VERSION_10_7) || \ |
| 21 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 | 21 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 |
| 22 @interface NSWindow (LionAPI) | 22 @interface NSWindow (LionAPI) |
| 23 - (CGFloat)backingScaleFactor; | 23 - (CGFloat)backingScaleFactor; |
| 24 @end | 24 @end |
| 25 #endif | 25 #endif |
| 26 | 26 |
| 27 namespace { | 27 // When the window doesn't have focus then we want to draw the button with a |
| 28 // slightly lighter color. We do this by just reducing the alpha. | |
| 29 const CGFloat kImageNoFocusAlpha = 0.65; | |
| 28 | 30 |
| 29 const int kMaskHeight = 29; // Height of the mask bitmap. | 31 const int kMaskHeight = 29; // Height of the mask bitmap. |
| 30 const int kFillHeight = 25; // Height of the "mask on" part of the mask bitmap. | 32 const int kFillHeight = 25; // Height of the "mask on" part of the mask bitmap. |
| 31 | 33 |
| 32 | 34 |
| 33 // Constants for inset and control points for tab shape. | 35 // Constants for inset and control points for tab shape. |
| 34 const CGFloat kInsetMultiplier = 2.0/3.0; | 36 const CGFloat kInsetMultiplier = 2.0/3.0; |
| 35 const CGFloat kControlPoint1Multiplier = 1.0/3.0; | 37 const CGFloat kControlPoint1Multiplier = 1.0/3.0; |
| 36 const CGFloat kControlPoint2Multiplier = 3.0/8.0; | 38 const CGFloat kControlPoint2Multiplier = 3.0/8.0; |
| 37 | 39 |
| 38 // The amount of time in seconds during which each type of glow increases, holds | 40 // The amount of time in seconds during which each type of glow increases, holds |
| 39 // steady, and decreases, respectively. | 41 // steady, and decreases, respectively. |
| 40 const NSTimeInterval kHoverShowDuration = 0.2; | 42 const NSTimeInterval kHoverShowDuration = 0.2; |
| 41 const NSTimeInterval kHoverHoldDuration = 0.02; | 43 const NSTimeInterval kHoverHoldDuration = 0.02; |
| 42 const NSTimeInterval kHoverHideDuration = 0.4; | 44 const NSTimeInterval kHoverHideDuration = 0.4; |
| 43 const NSTimeInterval kAlertShowDuration = 0.4; | 45 const NSTimeInterval kAlertShowDuration = 0.4; |
| 44 const NSTimeInterval kAlertHoldDuration = 0.4; | 46 const NSTimeInterval kAlertHoldDuration = 0.4; |
| 45 const NSTimeInterval kAlertHideDuration = 0.4; | 47 const NSTimeInterval kAlertHideDuration = 0.4; |
| 46 | 48 |
| 47 // The default time interval in seconds between glow updates (when | 49 // The default time interval in seconds between glow updates (when |
| 48 // increasing/decreasing). | 50 // increasing/decreasing). |
| 49 const NSTimeInterval kGlowUpdateInterval = 0.025; | 51 const NSTimeInterval kGlowUpdateInterval = 0.025; |
| 50 | 52 |
| 51 // This is used to judge whether the mouse has moved during rapid closure; if it | 53 // This is used to judge whether the mouse has moved during rapid closure; if it |
| 52 // has moved less than the threshold, we want to close the tab. | 54 // has moved less than the threshold, we want to close the tab. |
| 53 const CGFloat kRapidCloseDist = 2.5; | 55 const CGFloat kRapidCloseDist = 2.5; |
| 54 | 56 |
| 55 } // namespace | |
| 56 | |
| 57 @interface TabView(Private) | 57 @interface TabView(Private) |
| 58 | 58 |
| 59 - (void)resetLastGlowUpdateTime; | 59 - (void)resetLastGlowUpdateTime; |
| 60 - (NSTimeInterval)timeElapsedSinceLastGlowUpdate; | 60 - (NSTimeInterval)timeElapsedSinceLastGlowUpdate; |
| 61 - (void)adjustGlowValue; | 61 - (void)adjustGlowValue; |
| 62 - (CGImageRef)tabClippingMask; | 62 - (CGImageRef)tabClippingMask; |
| 63 | 63 |
| 64 @end // TabView(Private) | 64 @end // TabView(Private) |
| 65 | 65 |
| 66 @implementation TabView | 66 @implementation TabView |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 static_cast<ThemeService*>([[self window] themeProvider]); | 320 static_cast<ThemeService*>([[self window] themeProvider]); |
| 321 [context setPatternPhase:[[self window] themePatternPhase]]; | 321 [context setPatternPhase:[[self window] themePatternPhase]]; |
| 322 | 322 |
| 323 | 323 |
| 324 CGImageRef mask([self tabClippingMask]); | 324 CGImageRef mask([self tabClippingMask]); |
| 325 CGRect maskBounds = CGRectMake(0, 0, maskCacheWidth_, kMaskHeight); | 325 CGRect maskBounds = CGRectMake(0, 0, maskCacheWidth_, kMaskHeight); |
| 326 CGContextClipToMask(cgContext, maskBounds, mask); | 326 CGContextClipToMask(cgContext, maskBounds, mask); |
| 327 | 327 |
| 328 bool selected = [self state]; | 328 bool selected = [self state]; |
| 329 | 329 |
| 330 // Background tabs should not paint over the tab strip separator, which is | |
| 331 // two pixels high in both lodpi and hidpi. | |
| 332 if (!selected && dirtyRect.origin.y < 1) | |
| 333 dirtyRect.origin.y = 2 * [self cr_lineWidth]; | |
| 334 | |
| 330 bool usingDefaultTheme = themeProvider && themeProvider->UsingDefaultTheme(); | 335 bool usingDefaultTheme = themeProvider && themeProvider->UsingDefaultTheme(); |
| 331 NSColor* backgroundImageColor = [self backgroundColorForSelected:selected]; | 336 NSColor* backgroundImageColor = [self backgroundColorForSelected:selected]; |
| 332 | 337 |
| 333 // Don't draw the window/tab bar background when selected, since the tab | 338 // Don't draw the window/tab bar background when selected, since the tab |
| 334 // background overlay drawn over it (see below) will be fully opaque. | 339 // background overlay drawn over it (see below) will be fully opaque. |
| 335 if (!selected) { | 340 if (!selected) { |
| 336 [backgroundImageColor set]; | 341 [backgroundImageColor set]; |
| 337 // Themes can have partially transparent images. NSRectFill() is measurably | 342 // Themes can have partially transparent images. NSRectFill() is measurably |
| 338 // faster though, so call it for the known-safe default theme. | 343 // faster though, so call it for the known-safe default theme. |
| 339 if (usingDefaultTheme) | 344 if (usingDefaultTheme) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 options:NSGradientDrawsBeforeStartingLocation]; | 403 options:NSGradientDrawsBeforeStartingLocation]; |
| 399 } | 404 } |
| 400 } | 405 } |
| 401 | 406 |
| 402 CGContextEndTransparencyLayer(cgContext); | 407 CGContextEndTransparencyLayer(cgContext); |
| 403 } | 408 } |
| 404 } | 409 } |
| 405 | 410 |
| 406 // Draws the tab outline. | 411 // Draws the tab outline. |
| 407 - (void)drawStroke:(NSRect)dirtyRect { | 412 - (void)drawStroke:(NSRect)dirtyRect { |
| 413 bool focused = [[self window] isKeyWindow] || [[self window] isMainWindow]; | |
|
Robert Sesek
2013/01/07 22:08:04
BOOL
Nico
2013/01/07 22:20:15
DONE
| |
| 414 CGFloat alpha = focused ? 1.0 : kImageNoFocusAlpha; | |
| 415 | |
| 408 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 416 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 409 float height = | 417 float height = |
| 410 [rb.GetNativeImageNamed(IDR_TAB_ACTIVE_LEFT).ToNSImage() size].height; | 418 [rb.GetNativeImageNamed(IDR_TAB_ACTIVE_LEFT).ToNSImage() size].height; |
| 411 if ([controller_ active]) { | 419 if ([controller_ active]) { |
| 412 NSDrawThreePartImage(NSMakeRect(0, 0, NSWidth([self bounds]), height), | 420 NSDrawThreePartImage(NSMakeRect(0, 0, NSWidth([self bounds]), height), |
| 413 rb.GetNativeImageNamed(IDR_TAB_ACTIVE_LEFT).ToNSImage(), | 421 rb.GetNativeImageNamed(IDR_TAB_ACTIVE_LEFT).ToNSImage(), |
| 414 rb.GetNativeImageNamed(IDR_TAB_ACTIVE_CENTER).ToNSImage(), | 422 rb.GetNativeImageNamed(IDR_TAB_ACTIVE_CENTER).ToNSImage(), |
| 415 rb.GetNativeImageNamed(IDR_TAB_ACTIVE_RIGHT).ToNSImage(), | 423 rb.GetNativeImageNamed(IDR_TAB_ACTIVE_RIGHT).ToNSImage(), |
| 416 /*vertical=*/NO, | 424 /*vertical=*/NO, |
| 417 NSCompositeSourceOver, | 425 NSCompositeSourceOver, |
| 418 1.0, | 426 alpha, |
|
Nico
2013/01/07 21:57:21
(I measured that this doesn't regress throbber per
| |
| 419 /*flipped=*/NO); | 427 /*flipped=*/NO); |
| 420 } else { | 428 } else { |
| 421 NSDrawThreePartImage(NSMakeRect(0, 0, NSWidth([self bounds]), height), | 429 NSDrawThreePartImage(NSMakeRect(0, 0, NSWidth([self bounds]), height), |
| 422 rb.GetNativeImageNamed(IDR_TAB_INACTIVE_LEFT).ToNSImage(), | 430 rb.GetNativeImageNamed(IDR_TAB_INACTIVE_LEFT).ToNSImage(), |
| 423 rb.GetNativeImageNamed(IDR_TAB_INACTIVE_CENTER).ToNSImage(), | 431 rb.GetNativeImageNamed(IDR_TAB_INACTIVE_CENTER).ToNSImage(), |
| 424 rb.GetNativeImageNamed(IDR_TAB_INACTIVE_RIGHT).ToNSImage(), | 432 rb.GetNativeImageNamed(IDR_TAB_INACTIVE_RIGHT).ToNSImage(), |
| 425 /*vertical=*/NO, | 433 /*vertical=*/NO, |
| 426 NSCompositeSourceOver, | 434 NSCompositeSourceOver, |
| 427 1.0, | 435 alpha, |
| 428 /*flipped=*/NO); | 436 /*flipped=*/NO); |
| 429 } | 437 } |
| 430 } | 438 } |
| 431 | 439 |
| 432 - (void)drawRect:(NSRect)dirtyRect { | 440 - (void)drawRect:(NSRect)dirtyRect { |
| 433 // Text, close button, and image are drawn by subviews. | 441 // Text, close button, and image are drawn by subviews. |
| 434 [self drawFill:dirtyRect]; | 442 [self drawFill:dirtyRect]; |
| 435 [self drawStroke:dirtyRect]; | 443 [self drawStroke:dirtyRect]; |
| 436 } | 444 } |
| 437 | 445 |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 692 CGFloat middleWidth = tabWidth - leftWidth - rightWidth; | 700 CGFloat middleWidth = tabWidth - leftWidth - rightWidth; |
| 693 NSRect middleRect = NSMakeRect(leftWidth, 0, middleWidth, kFillHeight); | 701 NSRect middleRect = NSMakeRect(leftWidth, 0, middleWidth, kFillHeight); |
| 694 [[NSColor whiteColor] setFill]; | 702 [[NSColor whiteColor] setFill]; |
| 695 NSRectFill(middleRect); | 703 NSRectFill(middleRect); |
| 696 | 704 |
| 697 maskCache_.reset(CGBitmapContextCreateImage(maskContext)); | 705 maskCache_.reset(CGBitmapContextCreateImage(maskContext)); |
| 698 return maskCache_; | 706 return maskCache_; |
| 699 } | 707 } |
| 700 | 708 |
| 701 @end // @implementation TabView(Private) | 709 @end // @implementation TabView(Private) |
| OLD | NEW |