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_view_controller.h" | 5 #import "ui/app_list/cocoa/app_list_view_controller.h" |
6 | 6 |
7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_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/app_list/app_list_view_delegate.h" | 10 #include "ui/app_list/app_list_view_delegate.h" |
11 #import "ui/app_list/cocoa/app_list_pager_view.h" | 11 #import "ui/app_list/cocoa/app_list_pager_view.h" |
12 #import "ui/app_list/cocoa/apps_grid_controller.h" | 12 #import "ui/app_list/cocoa/apps_grid_controller.h" |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 // The roundedness of the corners of the bubble. | 16 // The roundedness of the corners of the bubble. |
17 const CGFloat kBubbleCornerRadius = 3; | 17 const CGFloat kBubbleCornerRadius = 3; |
18 | 18 |
19 // Height of the pager. | 19 // Height of the pager. |
20 const CGFloat kPagerPreferredHeight = 57; | 20 const CGFloat kPagerPreferredHeight = 57; |
21 // Padding between the bottom of the grid and the bottom of the view. | |
22 const CGFloat kViewGridOffsetY = 41; | |
23 | 21 |
24 // Padding between the top of the grid and the top of the view. | 22 // Padding between the top of the grid and the top of the view. |
25 // TODO(tapted): Update padding when the search entry control is added. | 23 // TODO(tapted): Update padding when the search entry control is added. |
26 const CGFloat kTopPadding = 16; | 24 const CGFloat kTopPadding = 16; |
27 | 25 |
28 // Height of the search input. TODO(tapted): Make this visible when the search | 26 // Height of the search input. TODO(tapted): Make this visible when the search |
29 // input UI is written. | 27 // input UI is written. |
30 const CGFloat kSearchInputHeight = 0; | 28 const CGFloat kSearchInputHeight = 0; |
31 | 29 |
32 // Minimum margin on either side of the pager. If the pager grows beyond this, | 30 // Minimum margin on either side of the pager. If the pager grows beyond this, |
(...skipping 12 matching lines...) Expand all Loading... | |
45 - (void)drawRect:(NSRect)dirtyRect { | 43 - (void)drawRect:(NSRect)dirtyRect { |
46 [NSGraphicsContext saveGraphicsState]; | 44 [NSGraphicsContext saveGraphicsState]; |
47 [gfx::SkColorToCalibratedNSColor(app_list::kContentsBackgroundColor) set]; | 45 [gfx::SkColorToCalibratedNSColor(app_list::kContentsBackgroundColor) set]; |
48 [[NSBezierPath bezierPathWithRoundedRect:[self bounds] | 46 [[NSBezierPath bezierPathWithRoundedRect:[self bounds] |
49 xRadius:kBubbleCornerRadius | 47 xRadius:kBubbleCornerRadius |
50 yRadius:kBubbleCornerRadius] addClip]; | 48 yRadius:kBubbleCornerRadius] addClip]; |
51 NSRectFill([self bounds]); | 49 NSRectFill([self bounds]); |
52 [NSGraphicsContext restoreGraphicsState]; | 50 [NSGraphicsContext restoreGraphicsState]; |
53 } | 51 } |
54 | 52 |
53 - (BOOL)isFlipped { | |
tapted
2013/05/17 04:24:15
note: this keeps things consistent w.r.t. the drag
| |
54 return YES; | |
55 } | |
56 | |
55 @end | 57 @end |
56 | 58 |
57 @interface AppListViewController () | 59 @interface AppListViewController () |
58 | 60 |
59 - (void)loadAndSetView; | 61 - (void)loadAndSetView; |
60 | 62 |
61 @end | 63 @end |
62 | 64 |
63 @implementation AppListViewController | 65 @implementation AppListViewController |
64 | 66 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 - (void)setDelegate:(scoped_ptr<app_list::AppListViewDelegate>)newDelegate { | 100 - (void)setDelegate:(scoped_ptr<app_list::AppListViewDelegate>)newDelegate { |
99 delegate_.reset(newDelegate.release()); | 101 delegate_.reset(newDelegate.release()); |
100 [appsGridController_ setDelegate:delegate_.get()]; | 102 [appsGridController_ setDelegate:delegate_.get()]; |
101 } | 103 } |
102 | 104 |
103 -(void)loadAndSetView { | 105 -(void)loadAndSetView { |
104 pagerControl_.reset([[AppListPagerView alloc] init]); | 106 pagerControl_.reset([[AppListPagerView alloc] init]); |
105 [pagerControl_ setTarget:appsGridController_]; | 107 [pagerControl_ setTarget:appsGridController_]; |
106 [pagerControl_ setAction:@selector(onPagerClicked:)]; | 108 [pagerControl_ setAction:@selector(onPagerClicked:)]; |
107 | 109 |
108 [[appsGridController_ view] setFrameOrigin:NSMakePoint(0, kViewGridOffsetY)]; | 110 [[appsGridController_ view] setFrameOrigin:NSMakePoint(0, kTopPadding)]; |
109 | 111 |
110 NSRect backgroundRect = [[appsGridController_ view] bounds]; | 112 NSRect backgroundRect = [[appsGridController_ view] bounds]; |
111 backgroundRect.size.height += kViewGridOffsetY + kTopPadding; | 113 backgroundRect.size.height += kPagerPreferredHeight; |
112 scoped_nsobject<BackgroundView> backgroundView( | 114 scoped_nsobject<BackgroundView> backgroundView( |
113 [[BackgroundView alloc] initWithFrame:backgroundRect]); | 115 [[BackgroundView alloc] initWithFrame:backgroundRect]); |
114 | 116 |
115 NSRect searchInputRect = | 117 NSRect searchInputRect = |
116 NSMakeRect(0, NSMaxY(backgroundRect) - kSearchInputHeight, | 118 NSMakeRect(0, 0, backgroundRect.size.width, kSearchInputHeight); |
117 backgroundRect.size.width, kSearchInputHeight); | |
118 scoped_nsobject<NSTextField> searchInput( | 119 scoped_nsobject<NSTextField> searchInput( |
119 [[NSTextField alloc] initWithFrame:searchInputRect]); | 120 [[NSTextField alloc] initWithFrame:searchInputRect]); |
120 [searchInput setDelegate:self]; | 121 [searchInput setDelegate:self]; |
121 | 122 |
122 [backgroundView addSubview:[appsGridController_ view]]; | 123 [backgroundView addSubview:[appsGridController_ view]]; |
123 [backgroundView addSubview:pagerControl_]; | 124 [backgroundView addSubview:pagerControl_]; |
124 [backgroundView addSubview:searchInput]; | 125 [backgroundView addSubview:searchInput]; |
125 [self setView:backgroundView]; | 126 [self setView:backgroundView]; |
126 } | 127 } |
127 | 128 |
(...skipping 10 matching lines...) Expand all Loading... | |
138 [pagerControl_ setWidth:segmentWidth | 139 [pagerControl_ setWidth:segmentWidth |
139 forSegment:i]; | 140 forSegment:i]; |
140 [[pagerControl_ cell] setTag:i | 141 [[pagerControl_ cell] setTag:i |
141 forSegment:i]; | 142 forSegment:i]; |
142 } | 143 } |
143 | 144 |
144 // Center in view. | 145 // Center in view. |
145 [pagerControl_ sizeToFit]; | 146 [pagerControl_ sizeToFit]; |
146 [pagerControl_ setFrame: | 147 [pagerControl_ setFrame: |
147 NSMakeRect(NSMidX(viewFrame) - NSMidX([pagerControl_ bounds]), | 148 NSMakeRect(NSMidX(viewFrame) - NSMidX([pagerControl_ bounds]), |
148 0, | 149 viewFrame.size.height - kPagerPreferredHeight, |
149 [pagerControl_ bounds].size.width, | 150 [pagerControl_ bounds].size.width, |
150 kPagerPreferredHeight)]; | 151 kPagerPreferredHeight)]; |
151 } | 152 } |
152 | 153 |
153 - (void)selectedPageChanged:(int)newSelected { | 154 - (void)selectedPageChanged:(int)newSelected { |
154 [pagerControl_ selectSegmentWithTag:newSelected]; | 155 [pagerControl_ selectSegmentWithTag:newSelected]; |
155 } | 156 } |
156 | 157 |
157 - (void)pageVisibilityChanged { | 158 - (void)pageVisibilityChanged { |
158 [pagerControl_ setNeedsDisplay:YES]; | 159 [pagerControl_ setNeedsDisplay:YES]; |
159 } | 160 } |
160 | 161 |
162 - (NSInteger)pagerSegmentAtLocation:(NSPoint)locationInWindow { | |
163 return [pagerControl_ getSegmentAndHighlight:locationInWindow]; | |
164 } | |
165 | |
161 - (BOOL)control:(NSControl*)control | 166 - (BOOL)control:(NSControl*)control |
162 textView:(NSTextView*)textView | 167 textView:(NSTextView*)textView |
163 doCommandBySelector:(SEL)command { | 168 doCommandBySelector:(SEL)command { |
164 // If anything has been written, let the search view handle it. | 169 // If anything has been written, let the search view handle it. |
165 if ([[control stringValue] length] > 0) | 170 if ([[control stringValue] length] > 0) |
166 return NO; | 171 return NO; |
167 | 172 |
168 // Handle escape. | 173 // Handle escape. |
169 if (command == @selector(complete:) || | 174 if (command == @selector(complete:) || |
170 command == @selector(cancel:) || | 175 command == @selector(cancel:) || |
171 command == @selector(cancelOperation:)) { | 176 command == @selector(cancelOperation:)) { |
172 if (delegate_) | 177 if (delegate_) |
173 delegate_->Dismiss(); | 178 delegate_->Dismiss(); |
174 return YES; | 179 return YES; |
175 } | 180 } |
176 | 181 |
177 // Possibly handle grid navigation. | 182 // Possibly handle grid navigation. |
178 return [appsGridController_ handleCommandBySelector:command]; | 183 return [appsGridController_ handleCommandBySelector:command]; |
179 } | 184 } |
180 | 185 |
181 @end | 186 @end |
OLD | NEW |