| 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 { | |
| 28 | |
| 29 const int kMaskHeight = 29; // Height of the mask bitmap. | 27 const int kMaskHeight = 29; // Height of the mask bitmap. |
| 30 const int kFillHeight = 25; // Height of the "mask on" part of the mask bitmap. | 28 const int kFillHeight = 25; // Height of the "mask on" part of the mask bitmap. |
| 31 | 29 |
| 32 | 30 |
| 33 // Constants for inset and control points for tab shape. | 31 // Constants for inset and control points for tab shape. |
| 34 const CGFloat kInsetMultiplier = 2.0/3.0; | 32 const CGFloat kInsetMultiplier = 2.0/3.0; |
| 35 const CGFloat kControlPoint1Multiplier = 1.0/3.0; | 33 const CGFloat kControlPoint1Multiplier = 1.0/3.0; |
| 36 const CGFloat kControlPoint2Multiplier = 3.0/8.0; | 34 const CGFloat kControlPoint2Multiplier = 3.0/8.0; |
| 37 | 35 |
| 38 // The amount of time in seconds during which each type of glow increases, holds | 36 // The amount of time in seconds during which each type of glow increases, holds |
| 39 // steady, and decreases, respectively. | 37 // steady, and decreases, respectively. |
| 40 const NSTimeInterval kHoverShowDuration = 0.2; | 38 const NSTimeInterval kHoverShowDuration = 0.2; |
| 41 const NSTimeInterval kHoverHoldDuration = 0.02; | 39 const NSTimeInterval kHoverHoldDuration = 0.02; |
| 42 const NSTimeInterval kHoverHideDuration = 0.4; | 40 const NSTimeInterval kHoverHideDuration = 0.4; |
| 43 const NSTimeInterval kAlertShowDuration = 0.4; | 41 const NSTimeInterval kAlertShowDuration = 0.4; |
| 44 const NSTimeInterval kAlertHoldDuration = 0.4; | 42 const NSTimeInterval kAlertHoldDuration = 0.4; |
| 45 const NSTimeInterval kAlertHideDuration = 0.4; | 43 const NSTimeInterval kAlertHideDuration = 0.4; |
| 46 | 44 |
| 47 // The default time interval in seconds between glow updates (when | 45 // The default time interval in seconds between glow updates (when |
| 48 // increasing/decreasing). | 46 // increasing/decreasing). |
| 49 const NSTimeInterval kGlowUpdateInterval = 0.025; | 47 const NSTimeInterval kGlowUpdateInterval = 0.025; |
| 50 | 48 |
| 51 // This is used to judge whether the mouse has moved during rapid closure; if it | 49 // 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. | 50 // has moved less than the threshold, we want to close the tab. |
| 53 const CGFloat kRapidCloseDist = 2.5; | 51 const CGFloat kRapidCloseDist = 2.5; |
| 54 | 52 |
| 55 } // namespace | |
| 56 | |
| 57 @interface TabView(Private) | 53 @interface TabView(Private) |
| 58 | 54 |
| 59 - (void)resetLastGlowUpdateTime; | 55 - (void)resetLastGlowUpdateTime; |
| 60 - (NSTimeInterval)timeElapsedSinceLastGlowUpdate; | 56 - (NSTimeInterval)timeElapsedSinceLastGlowUpdate; |
| 61 - (void)adjustGlowValue; | 57 - (void)adjustGlowValue; |
| 62 - (CGImageRef)tabClippingMask; | 58 - (CGImageRef)tabClippingMask; |
| 63 | 59 |
| 64 @end // TabView(Private) | 60 @end // TabView(Private) |
| 65 | 61 |
| 66 @implementation TabView | 62 @implementation TabView |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 static_cast<ThemeService*>([[self window] themeProvider]); | 316 static_cast<ThemeService*>([[self window] themeProvider]); |
| 321 [context setPatternPhase:[[self window] themePatternPhase]]; | 317 [context setPatternPhase:[[self window] themePatternPhase]]; |
| 322 | 318 |
| 323 | 319 |
| 324 CGImageRef mask([self tabClippingMask]); | 320 CGImageRef mask([self tabClippingMask]); |
| 325 CGRect maskBounds = CGRectMake(0, 0, maskCacheWidth_, kMaskHeight); | 321 CGRect maskBounds = CGRectMake(0, 0, maskCacheWidth_, kMaskHeight); |
| 326 CGContextClipToMask(cgContext, maskBounds, mask); | 322 CGContextClipToMask(cgContext, maskBounds, mask); |
| 327 | 323 |
| 328 bool selected = [self state]; | 324 bool selected = [self state]; |
| 329 | 325 |
| 326 // Background tabs should not paint over the tab strip separator, which is |
| 327 // two pixels high in both lodpi and hidpi. |
| 328 if (!selected && dirtyRect.origin.y < 1) |
| 329 dirtyRect.origin.y = 2 * [self cr_lineWidth]; |
| 330 |
| 330 bool usingDefaultTheme = themeProvider && themeProvider->UsingDefaultTheme(); | 331 bool usingDefaultTheme = themeProvider && themeProvider->UsingDefaultTheme(); |
| 331 NSColor* backgroundImageColor = [self backgroundColorForSelected:selected]; | 332 NSColor* backgroundImageColor = [self backgroundColorForSelected:selected]; |
| 332 | 333 |
| 333 // Don't draw the window/tab bar background when selected, since the tab | 334 // 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. | 335 // background overlay drawn over it (see below) will be fully opaque. |
| 335 if (!selected) { | 336 if (!selected) { |
| 336 [backgroundImageColor set]; | 337 [backgroundImageColor set]; |
| 337 // Themes can have partially transparent images. NSRectFill() is measurably | 338 // Themes can have partially transparent images. NSRectFill() is measurably |
| 338 // faster though, so call it for the known-safe default theme. | 339 // faster though, so call it for the known-safe default theme. |
| 339 if (usingDefaultTheme) | 340 if (usingDefaultTheme) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 options:NSGradientDrawsBeforeStartingLocation]; | 399 options:NSGradientDrawsBeforeStartingLocation]; |
| 399 } | 400 } |
| 400 } | 401 } |
| 401 | 402 |
| 402 CGContextEndTransparencyLayer(cgContext); | 403 CGContextEndTransparencyLayer(cgContext); |
| 403 } | 404 } |
| 404 } | 405 } |
| 405 | 406 |
| 406 // Draws the tab outline. | 407 // Draws the tab outline. |
| 407 - (void)drawStroke:(NSRect)dirtyRect { | 408 - (void)drawStroke:(NSRect)dirtyRect { |
| 409 BOOL focused = [[self window] isKeyWindow] || [[self window] isMainWindow]; |
| 410 CGFloat alpha = focused ? 1.0 : tabs::kImageNoFocusAlpha; |
| 411 |
| 408 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 412 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 409 float height = | 413 float height = |
| 410 [rb.GetNativeImageNamed(IDR_TAB_ACTIVE_LEFT).ToNSImage() size].height; | 414 [rb.GetNativeImageNamed(IDR_TAB_ACTIVE_LEFT).ToNSImage() size].height; |
| 411 if ([controller_ active]) { | 415 if ([controller_ active]) { |
| 412 NSDrawThreePartImage(NSMakeRect(0, 0, NSWidth([self bounds]), height), | 416 NSDrawThreePartImage(NSMakeRect(0, 0, NSWidth([self bounds]), height), |
| 413 rb.GetNativeImageNamed(IDR_TAB_ACTIVE_LEFT).ToNSImage(), | 417 rb.GetNativeImageNamed(IDR_TAB_ACTIVE_LEFT).ToNSImage(), |
| 414 rb.GetNativeImageNamed(IDR_TAB_ACTIVE_CENTER).ToNSImage(), | 418 rb.GetNativeImageNamed(IDR_TAB_ACTIVE_CENTER).ToNSImage(), |
| 415 rb.GetNativeImageNamed(IDR_TAB_ACTIVE_RIGHT).ToNSImage(), | 419 rb.GetNativeImageNamed(IDR_TAB_ACTIVE_RIGHT).ToNSImage(), |
| 416 /*vertical=*/NO, | 420 /*vertical=*/NO, |
| 417 NSCompositeSourceOver, | 421 NSCompositeSourceOver, |
| 418 1.0, | 422 alpha, |
| 419 /*flipped=*/NO); | 423 /*flipped=*/NO); |
| 420 } else { | 424 } else { |
| 421 NSDrawThreePartImage(NSMakeRect(0, 0, NSWidth([self bounds]), height), | 425 NSDrawThreePartImage(NSMakeRect(0, 0, NSWidth([self bounds]), height), |
| 422 rb.GetNativeImageNamed(IDR_TAB_INACTIVE_LEFT).ToNSImage(), | 426 rb.GetNativeImageNamed(IDR_TAB_INACTIVE_LEFT).ToNSImage(), |
| 423 rb.GetNativeImageNamed(IDR_TAB_INACTIVE_CENTER).ToNSImage(), | 427 rb.GetNativeImageNamed(IDR_TAB_INACTIVE_CENTER).ToNSImage(), |
| 424 rb.GetNativeImageNamed(IDR_TAB_INACTIVE_RIGHT).ToNSImage(), | 428 rb.GetNativeImageNamed(IDR_TAB_INACTIVE_RIGHT).ToNSImage(), |
| 425 /*vertical=*/NO, | 429 /*vertical=*/NO, |
| 426 NSCompositeSourceOver, | 430 NSCompositeSourceOver, |
| 427 1.0, | 431 alpha, |
| 428 /*flipped=*/NO); | 432 /*flipped=*/NO); |
| 429 } | 433 } |
| 430 } | 434 } |
| 431 | 435 |
| 432 - (void)drawRect:(NSRect)dirtyRect { | 436 - (void)drawRect:(NSRect)dirtyRect { |
| 433 // Text, close button, and image are drawn by subviews. | 437 // Text, close button, and image are drawn by subviews. |
| 434 [self drawFill:dirtyRect]; | 438 [self drawFill:dirtyRect]; |
| 435 [self drawStroke:dirtyRect]; | 439 [self drawStroke:dirtyRect]; |
| 436 } | 440 } |
| 437 | 441 |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 CGFloat middleWidth = tabWidth - leftWidth - rightWidth; | 696 CGFloat middleWidth = tabWidth - leftWidth - rightWidth; |
| 693 NSRect middleRect = NSMakeRect(leftWidth, 0, middleWidth, kFillHeight); | 697 NSRect middleRect = NSMakeRect(leftWidth, 0, middleWidth, kFillHeight); |
| 694 [[NSColor whiteColor] setFill]; | 698 [[NSColor whiteColor] setFill]; |
| 695 NSRectFill(middleRect); | 699 NSRectFill(middleRect); |
| 696 | 700 |
| 697 maskCache_.reset(CGBitmapContextCreateImage(maskContext)); | 701 maskCache_.reset(CGBitmapContextCreateImage(maskContext)); |
| 698 return maskCache_; | 702 return maskCache_; |
| 699 } | 703 } |
| 700 | 704 |
| 701 @end // @implementation TabView(Private) | 705 @end // @implementation TabView(Private) |
| OLD | NEW |