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/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/mac/sdk_forward_declarations.h" | 9 #include "base/mac/sdk_forward_declarations.h" |
10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 // The default time interval in seconds between glow updates (when | 39 // The default time interval in seconds between glow updates (when |
40 // increasing/decreasing). | 40 // increasing/decreasing). |
41 const NSTimeInterval kGlowUpdateInterval = 0.025; | 41 const NSTimeInterval kGlowUpdateInterval = 0.025; |
42 | 42 |
43 // This is used to judge whether the mouse has moved during rapid closure; if it | 43 // This is used to judge whether the mouse has moved during rapid closure; if it |
44 // has moved less than the threshold, we want to close the tab. | 44 // has moved less than the threshold, we want to close the tab. |
45 const CGFloat kRapidCloseDist = 2.5; | 45 const CGFloat kRapidCloseDist = 2.5; |
46 | 46 |
47 namespace { | 47 namespace { |
48 | 48 |
49 ui::ThreePartImage* GetMaskImage() { | 49 ui::ThreePartImage& GetMaskImage() { |
50 static ui::ThreePartImage* mask = | 50 CR_DEFINE_STATIC_LOCAL(ui::ThreePartImage, mask, |
51 new ui::ThreePartImage(IDR_TAB_ALPHA_LEFT, 0, IDR_TAB_ALPHA_RIGHT); | 51 (IDR_TAB_ALPHA_LEFT, 0, IDR_TAB_ALPHA_RIGHT)); |
52 return mask; | 52 return mask; |
53 } | 53 } |
54 | 54 |
55 ui::ThreePartImage* GetStrokeImage(bool active) { | 55 ui::ThreePartImage& GetStrokeImage(bool active) { |
56 static ui::ThreePartImage* activeStroke = new ui::ThreePartImage( | 56 CR_DEFINE_STATIC_LOCAL( |
57 IDR_TAB_ACTIVE_LEFT, IDR_TAB_ACTIVE_CENTER, IDR_TAB_ACTIVE_RIGHT); | 57 ui::ThreePartImage, activeStroke, |
58 static ui::ThreePartImage* inactiveStroke = new ui::ThreePartImage( | 58 (IDR_TAB_ACTIVE_LEFT, IDR_TAB_ACTIVE_CENTER, IDR_TAB_ACTIVE_RIGHT)); |
59 IDR_TAB_INACTIVE_LEFT, IDR_TAB_INACTIVE_CENTER, IDR_TAB_INACTIVE_RIGHT); | 59 CR_DEFINE_STATIC_LOCAL( |
| 60 ui::ThreePartImage, inactiveStroke, |
| 61 (IDR_TAB_INACTIVE_LEFT, IDR_TAB_INACTIVE_CENTER, IDR_TAB_INACTIVE_RIGHT)); |
60 | 62 |
61 return active ? activeStroke : inactiveStroke; | 63 return active ? activeStroke : inactiveStroke; |
62 } | 64 } |
63 | 65 |
64 } // namespace | 66 } // namespace |
65 | 67 |
66 @interface TabView(Private) | 68 @interface TabView(Private) |
67 | 69 |
68 - (void)resetLastGlowUpdateTime; | 70 - (void)resetLastGlowUpdateTime; |
69 - (NSTimeInterval)timeElapsedSinceLastGlowUpdate; | 71 - (NSTimeInterval)timeElapsedSinceLastGlowUpdate; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 // Determines which view a click in our frame actually hit. It's either this | 174 // Determines which view a click in our frame actually hit. It's either this |
173 // view or one of the child buttons. | 175 // view or one of the child buttons. |
174 - (NSView*)hitTest:(NSPoint)aPoint { | 176 - (NSView*)hitTest:(NSPoint)aPoint { |
175 NSView* const defaultHitTestResult = [super hitTest:aPoint]; | 177 NSView* const defaultHitTestResult = [super hitTest:aPoint]; |
176 if ([defaultHitTestResult isKindOfClass:[NSButton class]]) | 178 if ([defaultHitTestResult isKindOfClass:[NSButton class]]) |
177 return defaultHitTestResult; | 179 return defaultHitTestResult; |
178 | 180 |
179 NSPoint viewPoint = [self convertPoint:aPoint fromView:[self superview]]; | 181 NSPoint viewPoint = [self convertPoint:aPoint fromView:[self superview]]; |
180 NSRect maskRect = [self bounds]; | 182 NSRect maskRect = [self bounds]; |
181 maskRect.size.height = kFillHeight; | 183 maskRect.size.height = kFillHeight; |
182 return GetMaskImage()->HitTest(viewPoint, maskRect) ? self : nil; | 184 return GetMaskImage().HitTest(viewPoint, maskRect) ? self : nil; |
183 } | 185 } |
184 | 186 |
185 // Returns |YES| if this tab can be torn away into a new window. | 187 // Returns |YES| if this tab can be torn away into a new window. |
186 - (BOOL)canBeDragged { | 188 - (BOOL)canBeDragged { |
187 return [controller_ tabCanBeDragged:controller_]; | 189 return [controller_ tabCanBeDragged:controller_]; |
188 } | 190 } |
189 | 191 |
190 // Handle clicks and drags in this button. We get here because we have | 192 // Handle clicks and drags in this button. We get here because we have |
191 // overridden acceptsFirstMouse: and the click is within our bounds. | 193 // overridden acceptsFirstMouse: and the click is within our bounds. |
192 - (void)mouseDown:(NSEvent*)theEvent { | 194 - (void)mouseDown:(NSEvent*)theEvent { |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 | 330 |
329 [[self backgroundColorForSelected:(state_ != NSOffState)] set]; | 331 [[self backgroundColorForSelected:(state_ != NSOffState)] set]; |
330 NSRectFill(dirtyRect); | 332 NSRectFill(dirtyRect); |
331 | 333 |
332 if (state_ == NSOffState) | 334 if (state_ == NSOffState) |
333 [self drawGlow:dirtyRect]; | 335 [self drawGlow:dirtyRect]; |
334 | 336 |
335 // If we filled outside the middle rect, we need to erase what we filled | 337 // If we filled outside the middle rect, we need to erase what we filled |
336 // outside the tab's shape. | 338 // outside the tab's shape. |
337 // This only works if we are drawing to our own backing layer. | 339 // This only works if we are drawing to our own backing layer. |
338 if (!NSContainsRect(GetMaskImage()->GetMiddleRect(bounds), dirtyRect)) { | 340 if (!NSContainsRect(GetMaskImage().GetMiddleRect(bounds), dirtyRect)) { |
339 DCHECK([self layer]); | 341 DCHECK([self layer]); |
340 GetMaskImage()->DrawInRect(bounds, NSCompositeDestinationIn, 1.0); | 342 GetMaskImage().DrawInRect(bounds, NSCompositeDestinationIn, 1.0); |
341 } | 343 } |
342 } | 344 } |
343 | 345 |
344 // Draw the glow for hover and the overlay for alerts. | 346 // Draw the glow for hover and the overlay for alerts. |
345 - (void)drawGlow:(NSRect)dirtyRect { | 347 - (void)drawGlow:(NSRect)dirtyRect { |
346 NSGraphicsContext* context = [NSGraphicsContext currentContext]; | 348 NSGraphicsContext* context = [NSGraphicsContext currentContext]; |
347 CGContextRef cgContext = static_cast<CGContextRef>([context graphicsPort]); | 349 CGContextRef cgContext = static_cast<CGContextRef>([context graphicsPort]); |
348 | 350 |
349 CGFloat hoverAlpha = [self hoverAlpha]; | 351 CGFloat hoverAlpha = [self hoverAlpha]; |
350 CGFloat alertAlpha = [self alertAlpha]; | 352 CGFloat alertAlpha = [self alertAlpha]; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 } | 390 } |
389 | 391 |
390 CGContextEndTransparencyLayer(cgContext); | 392 CGContextEndTransparencyLayer(cgContext); |
391 } | 393 } |
392 } | 394 } |
393 | 395 |
394 // Draws the tab outline. | 396 // Draws the tab outline. |
395 - (void)drawStroke:(NSRect)dirtyRect { | 397 - (void)drawStroke:(NSRect)dirtyRect { |
396 CGFloat alpha = [[self window] isMainWindow] ? 1.0 : tabs::kImageNoFocusAlpha; | 398 CGFloat alpha = [[self window] isMainWindow] ? 1.0 : tabs::kImageNoFocusAlpha; |
397 GetStrokeImage(state_ == NSOnState) | 399 GetStrokeImage(state_ == NSOnState) |
398 ->DrawInRect([self bounds], NSCompositeSourceOver, alpha); | 400 .DrawInRect([self bounds], NSCompositeSourceOver, alpha); |
399 } | 401 } |
400 | 402 |
401 - (void)drawRect:(NSRect)dirtyRect { | 403 - (void)drawRect:(NSRect)dirtyRect { |
402 [self drawFill:dirtyRect]; | 404 [self drawFill:dirtyRect]; |
403 [self drawStroke:dirtyRect]; | 405 [self drawStroke:dirtyRect]; |
404 | 406 |
405 // We draw the title string directly instead of using a NSTextField subview. | 407 // We draw the title string directly instead of using a NSTextField subview. |
406 // This is so that we can get font smoothing to work on earlier OS, and even | 408 // This is so that we can get font smoothing to work on earlier OS, and even |
407 // when the tab background is a pattern image (when using themes). | 409 // when the tab background is a pattern image (when using themes). |
408 if (![titleView_ isHidden]) { | 410 if (![titleView_ isHidden]) { |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 } | 693 } |
692 | 694 |
693 if (nextUpdate < kNoUpdate) | 695 if (nextUpdate < kNoUpdate) |
694 [self performSelector:_cmd withObject:nil afterDelay:nextUpdate]; | 696 [self performSelector:_cmd withObject:nil afterDelay:nextUpdate]; |
695 | 697 |
696 [self resetLastGlowUpdateTime]; | 698 [self resetLastGlowUpdateTime]; |
697 [self setNeedsDisplay:YES]; | 699 [self setNeedsDisplay:YES]; |
698 } | 700 } |
699 | 701 |
700 @end // @implementation TabView(Private) | 702 @end // @implementation TabView(Private) |
OLD | NEW |