| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ui/app_list/cocoa/app_list_pager_view.h" | 5 #import "ui/app_list/cocoa/app_list_pager_view.h" |
| 6 | 6 |
| 7 #include "base/mac/mac_util.h" | 7 #include "base/mac/mac_util.h" |
| 8 #include "skia/ext/skia_utils_mac.h" | 8 #include "skia/ext/skia_utils_mac.h" |
| 9 #include "ui/app_list/app_list_constants.h" | 9 #include "ui/app_list/app_list_constants.h" |
| 10 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 10 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 const CGFloat kButtonHeight = 6; | 14 const CGFloat kButtonHeight = 6; |
| 15 const CGFloat kButtonCornerRadius = 2; | 15 const CGFloat kButtonCornerRadius = 2; |
| 16 const CGFloat kButtonStripPadding = 20; | 16 const CGFloat kButtonStripPadding = 20; |
| 17 | 17 |
| 18 } // namespace | 18 } // namespace |
| 19 | 19 |
| 20 @interface AppListPagerView () | 20 @interface AppListPagerView () |
| 21 | 21 |
| 22 @property(assign, nonatomic) NSInteger hoveredSegment; | 22 @property(assign, nonatomic) NSInteger hoveredSegment; |
| 23 | 23 |
| 24 - (NSInteger)segmentUnderEvent:(NSEvent*)theEvent; | 24 - (NSInteger)segmentUnderLocation:(NSPoint)locationInWindow; |
| 25 | 25 |
| 26 @end | 26 @end |
| 27 | 27 |
| 28 @interface AppListPagerCell : NSSegmentedCell; | 28 @interface AppListPagerCell : NSSegmentedCell; |
| 29 @end | 29 @end |
| 30 | 30 |
| 31 @implementation AppListPagerView | 31 @implementation AppListPagerView |
| 32 | 32 |
| 33 @synthesize hoveredSegment = hoveredSegment_; | 33 @synthesize hoveredSegment = hoveredSegment_; |
| 34 | 34 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 45 NSTrackingMouseMoved | | 45 NSTrackingMouseMoved | |
| 46 NSTrackingActiveInKeyWindow | 46 NSTrackingActiveInKeyWindow |
| 47 owner:self | 47 owner:self |
| 48 userInfo:nil]); | 48 userInfo:nil]); |
| 49 [self addTrackingArea:trackingArea_.get()]; | 49 [self addTrackingArea:trackingArea_.get()]; |
| 50 hoveredSegment_ = -1; | 50 hoveredSegment_ = -1; |
| 51 } | 51 } |
| 52 return self; | 52 return self; |
| 53 } | 53 } |
| 54 | 54 |
| 55 - (NSInteger)findAndHighlightSegmentAtLocation:(NSPoint)locationInWindow { |
| 56 NSInteger segment = [self segmentUnderLocation:locationInWindow]; |
| 57 [self setHoveredSegment:segment]; |
| 58 return segment; |
| 59 } |
| 60 |
| 55 - (void)setHoveredSegment:(NSInteger)segment { | 61 - (void)setHoveredSegment:(NSInteger)segment { |
| 56 if (segment == hoveredSegment_) | 62 if (segment == hoveredSegment_) |
| 57 return; | 63 return; |
| 58 | 64 |
| 59 hoveredSegment_ = segment; | 65 hoveredSegment_ = segment; |
| 60 [self setNeedsDisplay:YES]; | 66 [self setNeedsDisplay:YES]; |
| 61 return; | 67 return; |
| 62 } | 68 } |
| 63 | 69 |
| 64 - (NSInteger)segmentUnderEvent:(NSEvent*)theEvent { | 70 - (NSInteger)segmentUnderLocation:(NSPoint)locationInWindow { |
| 65 if ([self segmentCount] == 0) | 71 if ([self segmentCount] == 0) |
| 66 return -1; | 72 return -1; |
| 67 | 73 |
| 68 NSPoint pointInView = [self convertPoint:[theEvent locationInWindow] | 74 NSPoint pointInView = [self convertPoint:locationInWindow |
| 69 fromView:nil]; | 75 fromView:nil]; |
| 70 if (![self mouse:pointInView inRect:[self bounds]]) | 76 if (![self mouse:pointInView inRect:[self bounds]]) |
| 71 return -1; | 77 return -1; |
| 72 | 78 |
| 73 CGFloat segmentWidth = [self bounds].size.width / [self segmentCount]; | 79 CGFloat segmentWidth = [self bounds].size.width / [self segmentCount]; |
| 74 return pointInView.x / segmentWidth; | 80 return pointInView.x / segmentWidth; |
| 75 } | 81 } |
| 76 | 82 |
| 77 - (BOOL)isHoveredForSegment:(NSInteger)segment { | 83 - (BOOL)isHoveredForSegment:(NSInteger)segment { |
| 78 return segment == hoveredSegment_; | 84 return segment == hoveredSegment_; |
| 79 } | 85 } |
| 80 | 86 |
| 81 - (void)mouseExited:(NSEvent*)theEvent { | 87 - (void)mouseExited:(NSEvent*)theEvent { |
| 82 [self setHoveredSegment:-1]; | 88 [self setHoveredSegment:-1]; |
| 83 } | 89 } |
| 84 | 90 |
| 85 - (void)mouseMoved:(NSEvent*)theEvent { | 91 - (void)mouseMoved:(NSEvent*)theEvent { |
| 86 [self setHoveredSegment:[self segmentUnderEvent:theEvent]]; | 92 [self findAndHighlightSegmentAtLocation:[theEvent locationInWindow]]; |
| 87 } | 93 } |
| 88 | 94 |
| 89 - (void)mouseDown:(NSEvent*)theEvent { | 95 - (void)mouseDown:(NSEvent*)theEvent { |
| 90 // Temporarily clear the highlight to give feedback. | 96 // Temporarily clear the highlight to give feedback. |
| 91 [self setHoveredSegment:-1]; | 97 [self setHoveredSegment:-1]; |
| 92 } | 98 } |
| 93 | 99 |
| 94 // The stock NSSegmentedControl ignores any clicks outside the non-default | 100 // The stock NSSegmentedControl ignores any clicks outside the non-default |
| 95 // control height, so process all clicks here. | 101 // control height, so process all clicks here. |
| 96 - (void)mouseUp:(NSEvent*)theEvent { | 102 - (void)mouseUp:(NSEvent*)theEvent { |
| 97 [self setHoveredSegment:[self segmentUnderEvent:theEvent]]; | 103 [self findAndHighlightSegmentAtLocation:[theEvent locationInWindow]]; |
| 98 if (hoveredSegment_ < 0) | 104 if (hoveredSegment_ < 0) |
| 99 return; | 105 return; |
| 100 | 106 |
| 101 [self setSelectedSegment:hoveredSegment_]; | 107 [self setSelectedSegment:hoveredSegment_]; |
| 102 [[self target] performSelector:[self action] | 108 [[self target] performSelector:[self action] |
| 103 withObject:self]; | 109 withObject:self]; |
| 104 } | 110 } |
| 105 | 111 |
| 106 @end | 112 @end |
| 107 | 113 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 return; | 158 return; |
| 153 | 159 |
| 154 [gfx::SkColorToCalibratedNSColor(app_list::kPagerSelectedColor) set]; | 160 [gfx::SkColorToCalibratedNSColor(app_list::kPagerSelectedColor) set]; |
| 155 if (selectedRatio < 0) | 161 if (selectedRatio < 0) |
| 156 frame.origin.x += frame.size.width + frame.size.width * selectedRatio; | 162 frame.origin.x += frame.size.width + frame.size.width * selectedRatio; |
| 157 frame.size.width *= fabs(selectedRatio); | 163 frame.size.width *= fabs(selectedRatio); |
| 158 NSRectFill(frame); | 164 NSRectFill(frame); |
| 159 } | 165 } |
| 160 | 166 |
| 161 @end | 167 @end |
| OLD | NEW |