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_strip_view.h" | 5 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" |
6 | 6 |
7 #include <cmath> // floor | 7 #include <cmath> // floor |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
11 #include "chrome/browser/themes/theme_service.h" | 11 #include "chrome/browser/themes/theme_service.h" |
12 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 12 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
13 #import "chrome/browser/ui/cocoa/new_tab_button.h" | 13 #import "chrome/browser/ui/cocoa/new_tab_button.h" |
14 #import "chrome/browser/ui/cocoa/nsview_additions.h" | 14 #import "chrome/browser/ui/cocoa/nsview_additions.h" |
15 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" | 15 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" |
16 #import "chrome/browser/ui/cocoa/view_id_util.h" | 16 #import "chrome/browser/ui/cocoa/view_id_util.h" |
17 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
18 #include "grit/theme_resources.h" | 18 #include "grit/theme_resources.h" |
19 #include "ui/base/l10n/l10n_util_mac.h" | 19 #include "ui/base/l10n/l10n_util_mac.h" |
20 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 20 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
21 | 21 |
| 22 // When the window doesn't have focus then we want to draw the button with a |
| 23 // slightly lighter color. We do this by just reducing the alpha. |
| 24 const CGFloat kImageNoFocusAlpha = 0.65; |
| 25 |
22 @implementation TabStripView | 26 @implementation TabStripView |
23 | 27 |
24 @synthesize dropArrowShown = dropArrowShown_; | 28 @synthesize dropArrowShown = dropArrowShown_; |
25 @synthesize dropArrowPosition = dropArrowPosition_; | 29 @synthesize dropArrowPosition = dropArrowPosition_; |
26 | 30 |
27 - (id)initWithFrame:(NSRect)frame { | 31 - (id)initWithFrame:(NSRect)frame { |
28 self = [super initWithFrame:frame]; | 32 self = [super initWithFrame:frame]; |
29 if (self) { | 33 if (self) { |
30 newTabButton_.reset([[NewTabButton alloc] initWithFrame: | 34 newTabButton_.reset([[NewTabButton alloc] initWithFrame: |
31 NSMakeRect(295, 0, 40, 27)]); | 35 NSMakeRect(295, 0, 40, 27)]); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 | 72 |
69 // Draw the border bitmap, which is partially transparent. | 73 // Draw the border bitmap, which is partially transparent. |
70 NSImage* image = themeProvider->GetNSImageNamed(IDR_TOOLBAR_SHADE_TOP, true); | 74 NSImage* image = themeProvider->GetNSImageNamed(IDR_TOOLBAR_SHADE_TOP, true); |
71 if (NSMinY(dirtyRect) >= [image size].height) | 75 if (NSMinY(dirtyRect) >= [image size].height) |
72 return; | 76 return; |
73 | 77 |
74 NSRect borderRect = dirtyRect; | 78 NSRect borderRect = dirtyRect; |
75 borderRect.size.height = [image size].height; | 79 borderRect.size.height = [image size].height; |
76 borderRect.origin.y = 0; | 80 borderRect.origin.y = 0; |
77 | 81 |
78 NSDrawThreePartImage(borderRect, nil, image, nil, /*vertical=*/NO, | 82 bool active = [[self window] isKeyWindow] || [[self window] isMainWindow]; |
79 NSCompositeSourceOver, 1.0, /*flipped=*/NO); | 83 NSDrawThreePartImage(borderRect, nil, image, nil, /*vertical=*/ NO, |
| 84 NSCompositeSourceOver, |
| 85 active ? 1.0 : kImageNoFocusAlpha, /*flipped=*/ NO); |
80 } | 86 } |
81 | 87 |
82 - (void)drawRect:(NSRect)rect { | 88 - (void)drawRect:(NSRect)rect { |
83 NSRect boundsRect = [self bounds]; | 89 NSRect boundsRect = [self bounds]; |
84 | 90 |
85 [self drawBorder:boundsRect]; | 91 [self drawBorder:boundsRect]; |
86 | 92 |
87 // Draw drop-indicator arrow (if appropriate). | 93 // Draw drop-indicator arrow (if appropriate). |
88 // TODO(viettrungluu): this is all a stop-gap measure. | 94 // TODO(viettrungluu): this is all a stop-gap measure. |
89 if ([self dropArrowShown]) { | 95 if ([self dropArrowShown]) { |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 | 267 |
262 - (void)setNewTabButton:(NewTabButton*)button { | 268 - (void)setNewTabButton:(NewTabButton*)button { |
263 newTabButton_.reset([button retain]); | 269 newTabButton_.reset([button retain]); |
264 } | 270 } |
265 | 271 |
266 - (void)setController:(TabStripController*)controller { | 272 - (void)setController:(TabStripController*)controller { |
267 controller_ = controller; | 273 controller_ = controller; |
268 } | 274 } |
269 | 275 |
270 @end | 276 @end |
OLD | NEW |