Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Side by Side Diff: ui/app_list/cocoa/apps_search_results_controller.mm

Issue 17593006: mac: Update clients of scoped_nsobject.h. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: iwyu, scoped_nsprotocol Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/apps_search_results_controller.h" 5 #import "ui/app_list/cocoa/apps_search_results_controller.h"
6 6
7 #include "base/mac/foundation_util.h" 7 #include "base/mac/foundation_util.h"
8 #include "base/strings/sys_string_conversions.h" 8 #include "base/strings/sys_string_conversions.h"
9 #include "skia/ext/skia_utils_mac.h" 9 #include "skia/ext/skia_utils_mac.h"
10 #include "ui/app_list/app_list_constants.h" 10 #include "ui/app_list/app_list_constants.h"
(...skipping 28 matching lines...) Expand all
39 - (BOOL)moveSelectionByDelta:(NSInteger)delta; 39 - (BOOL)moveSelectionByDelta:(NSInteger)delta;
40 40
41 @end 41 @end
42 42
43 @interface AppsSearchResultsCell : NSTextFieldCell 43 @interface AppsSearchResultsCell : NSTextFieldCell
44 @end 44 @end
45 45
46 // Immutable class representing a search result in the NSTableView. 46 // Immutable class representing a search result in the NSTableView.
47 @interface AppsSearchResultRep : NSObject<NSCopying> { 47 @interface AppsSearchResultRep : NSObject<NSCopying> {
48 @private 48 @private
49 scoped_nsobject<NSAttributedString> attributedStringValue_; 49 base::scoped_nsobject<NSAttributedString> attributedStringValue_;
50 scoped_nsobject<NSImage> resultIcon_; 50 base::scoped_nsobject<NSImage> resultIcon_;
51 } 51 }
52 52
53 @property(readonly, nonatomic) NSAttributedString* attributedStringValue; 53 @property(readonly, nonatomic) NSAttributedString* attributedStringValue;
54 @property(readonly, nonatomic) NSImage* resultIcon; 54 @property(readonly, nonatomic) NSImage* resultIcon;
55 55
56 - (id)initWithSearchResult:(app_list::SearchResult*)result; 56 - (id)initWithSearchResult:(app_list::SearchResult*)result;
57 57
58 - (NSMutableAttributedString*)createRenderText:(const base::string16&)content 58 - (NSMutableAttributedString*)createRenderText:(const base::string16&)content
59 tags:(const app_list::SearchResult::Tags&)tags; 59 tags:(const app_list::SearchResult::Tags&)tags;
60 60
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 trackingArea_.reset( 133 trackingArea_.reset(
134 [[CrTrackingArea alloc] initWithRect:NSZeroRect 134 [[CrTrackingArea alloc] initWithRect:NSZeroRect
135 options:NSTrackingInVisibleRect | 135 options:NSTrackingInVisibleRect |
136 NSTrackingMouseEnteredAndExited | 136 NSTrackingMouseEnteredAndExited |
137 NSTrackingMouseMoved | 137 NSTrackingMouseMoved |
138 NSTrackingActiveInKeyWindow 138 NSTrackingActiveInKeyWindow
139 owner:self 139 owner:self
140 userInfo:nil]); 140 userInfo:nil]);
141 [tableView_ addTrackingArea:trackingArea_.get()]; 141 [tableView_ addTrackingArea:trackingArea_.get()];
142 142
143 scoped_nsobject<NSTableColumn> resultsColumn( 143 base::scoped_nsobject<NSTableColumn> resultsColumn(
144 [[NSTableColumn alloc] initWithIdentifier:@""]); 144 [[NSTableColumn alloc] initWithIdentifier:@""]);
145 scoped_nsobject<NSCell> resultsDataCell( 145 base::scoped_nsobject<NSCell> resultsDataCell(
146 [[AppsSearchResultsCell alloc] initTextCell:@""]); 146 [[AppsSearchResultsCell alloc] initTextCell:@""]);
147 [resultsColumn setDataCell:resultsDataCell]; 147 [resultsColumn setDataCell:resultsDataCell];
148 [resultsColumn setWidth:size.width]; 148 [resultsColumn setWidth:size.width];
149 [tableView_ addTableColumn:resultsColumn]; 149 [tableView_ addTableColumn:resultsColumn];
150 150
151 // An NSTableView is normally put in a NSScrollView, but scrolling is not 151 // An NSTableView is normally put in a NSScrollView, but scrolling is not
152 // used for the app list. Instead, place it in a container with the desired 152 // used for the app list. Instead, place it in a container with the desired
153 // size; flipped so the table is anchored to the top-left. 153 // size; flipped so the table is anchored to the top-left.
154 scoped_nsobject<FlippedView> containerView([[FlippedView alloc] initWithFrame: 154 base::scoped_nsobject<FlippedView> containerView([[FlippedView alloc]
155 NSMakeRect(0, 0, size.width, size.height)]); 155 initWithFrame:NSMakeRect(0, 0, size.width, size.height)]);
156 156
157 // The container is then anchored in an un-flipped view, initially hidden, 157 // The container is then anchored in an un-flipped view, initially hidden,
158 // so that |containerView| slides in from the top when showing results. 158 // so that |containerView| slides in from the top when showing results.
159 scoped_nsobject<NSView> clipView([[NSView alloc] initWithFrame: 159 base::scoped_nsobject<NSView> clipView(
160 NSMakeRect(0, 0, size.width, 0)]); 160 [[NSView alloc] initWithFrame:NSMakeRect(0, 0, size.width, 0)]);
161 161
162 [containerView addSubview:tableView_]; 162 [containerView addSubview:tableView_];
163 [clipView addSubview:containerView]; 163 [clipView addSubview:containerView];
164 [self setView:clipView]; 164 [self setView:clipView];
165 } 165 }
166 166
167 - (void)mouseDown:(NSEvent*)theEvent { 167 - (void)mouseDown:(NSEvent*)theEvent {
168 lastMouseDownInView_ = [tableView_ convertPoint:[theEvent locationInWindow] 168 lastMouseDownInView_ = [tableView_ convertPoint:[theEvent locationInWindow]
169 fromView:nil]; 169 fromView:nil];
170 } 170 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 - (id)tableView:(NSTableView*)aTableView 229 - (id)tableView:(NSTableView*)aTableView
230 objectValueForTableColumn:(NSTableColumn*)aTableColumn 230 objectValueForTableColumn:(NSTableColumn*)aTableColumn
231 row:(NSInteger)rowIndex { 231 row:(NSInteger)rowIndex {
232 // When the results were previously cleared, nothing will be selected. For 232 // When the results were previously cleared, nothing will be selected. For
233 // that case, select the first row when it appears. 233 // that case, select the first row when it appears.
234 if (rowIndex == 0 && [tableView_ selectedRow] == -1) { 234 if (rowIndex == 0 && [tableView_ selectedRow] == -1) {
235 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:0] 235 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:0]
236 byExtendingSelection:NO]; 236 byExtendingSelection:NO];
237 } 237 }
238 238
239 scoped_nsobject<AppsSearchResultRep> resultRep([[AppsSearchResultRep alloc] 239 base::scoped_nsobject<AppsSearchResultRep> resultRep(
240 initWithSearchResult:[self searchResults]->GetItemAt(rowIndex)]); 240 [[AppsSearchResultRep alloc]
241 initWithSearchResult:[self searchResults]->GetItemAt(rowIndex)]);
241 return resultRep.autorelease(); 242 return resultRep.autorelease();
242 } 243 }
243 244
244 - (void)tableView:(NSTableView*)tableView 245 - (void)tableView:(NSTableView*)tableView
245 willDisplayCell:(id)cell 246 willDisplayCell:(id)cell
246 forTableColumn:(NSTableColumn*)tableColumn 247 forTableColumn:(NSTableColumn*)tableColumn
247 row:(NSInteger)rowIndex { 248 row:(NSInteger)rowIndex {
248 if (rowIndex == [tableView selectedRow]) 249 if (rowIndex == [tableView selectedRow])
249 [cell setBackgroundStyle:kBackgroundSelected]; 250 [cell setBackgroundStyle:kBackgroundSelected];
250 else if (rowIndex == hoveredRowIndex_) 251 else if (rowIndex == hoveredRowIndex_)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 [[self createResultsAttributedStringWithModel:result] retain]); 294 [[self createResultsAttributedStringWithModel:result] retain]);
294 if (!result->icon().isNull()) 295 if (!result->icon().isNull())
295 resultIcon_.reset([gfx::NSImageFromImageSkia(result->icon()) retain]); 296 resultIcon_.reset([gfx::NSImageFromImageSkia(result->icon()) retain]);
296 } 297 }
297 return self; 298 return self;
298 } 299 }
299 300
300 - (NSMutableAttributedString*)createRenderText:(const base::string16&)content 301 - (NSMutableAttributedString*)createRenderText:(const base::string16&)content
301 tags:(const app_list::SearchResult::Tags&)tags { 302 tags:(const app_list::SearchResult::Tags&)tags {
302 NSFont* boldFont = nil; 303 NSFont* boldFont = nil;
303 scoped_nsobject<NSMutableParagraphStyle> paragraphStyle( 304 base::scoped_nsobject<NSMutableParagraphStyle> paragraphStyle(
304 [[NSMutableParagraphStyle alloc] init]); 305 [[NSMutableParagraphStyle alloc] init]);
305 [paragraphStyle setLineBreakMode:NSLineBreakByTruncatingTail]; 306 [paragraphStyle setLineBreakMode:NSLineBreakByTruncatingTail];
306 NSDictionary* defaultAttributes = @{ 307 NSDictionary* defaultAttributes = @{
307 NSForegroundColorAttributeName: 308 NSForegroundColorAttributeName:
308 gfx::SkColorToCalibratedNSColor(app_list::kResultDefaultTextColor), 309 gfx::SkColorToCalibratedNSColor(app_list::kResultDefaultTextColor),
309 NSParagraphStyleAttributeName: paragraphStyle 310 NSParagraphStyleAttributeName: paragraphStyle
310 }; 311 };
311 312
312 scoped_nsobject<NSMutableAttributedString> text( 313 base::scoped_nsobject<NSMutableAttributedString> text(
313 [[NSMutableAttributedString alloc] 314 [[NSMutableAttributedString alloc]
314 initWithString:base::SysUTF16ToNSString(content) 315 initWithString:base::SysUTF16ToNSString(content)
315 attributes:defaultAttributes]); 316 attributes:defaultAttributes]);
316 317
317 for (app_list::SearchResult::Tags::const_iterator it = tags.begin(); 318 for (app_list::SearchResult::Tags::const_iterator it = tags.begin();
318 it != tags.end(); ++it) { 319 it != tags.end(); ++it) {
319 if (it->styles == app_list::SearchResult::Tag::NONE) 320 if (it->styles == app_list::SearchResult::Tag::NONE)
320 continue; 321 continue;
321 322
322 if (it->styles & app_list::SearchResult::Tag::MATCH) { 323 if (it->styles & app_list::SearchResult::Tag::MATCH) {
(...skipping 27 matching lines...) Expand all
350 351
351 - (NSAttributedString*)createResultsAttributedStringWithModel 352 - (NSAttributedString*)createResultsAttributedStringWithModel
352 :(app_list::SearchResult*)result { 353 :(app_list::SearchResult*)result {
353 NSMutableAttributedString* titleText = 354 NSMutableAttributedString* titleText =
354 [self createRenderText:result->title() 355 [self createRenderText:result->title()
355 tags:result->title_tags()]; 356 tags:result->title_tags()];
356 if (!result->details().empty()) { 357 if (!result->details().empty()) {
357 NSMutableAttributedString* detailText = 358 NSMutableAttributedString* detailText =
358 [self createRenderText:result->details() 359 [self createRenderText:result->details()
359 tags:result->details_tags()]; 360 tags:result->details_tags()];
360 scoped_nsobject<NSAttributedString> lineBreak( 361 base::scoped_nsobject<NSAttributedString> lineBreak(
361 [[NSAttributedString alloc] initWithString:@"\n"]); 362 [[NSAttributedString alloc] initWithString:@"\n"]);
362 [titleText appendAttributedString:lineBreak]; 363 [titleText appendAttributedString:lineBreak];
363 [titleText appendAttributedString:detailText]; 364 [titleText appendAttributedString:detailText];
364 } 365 }
365 return titleText; 366 return titleText;
366 } 367 }
367 368
368 - (id)copyWithZone:(NSZone*)zone { 369 - (id)copyWithZone:(NSZone*)zone {
369 return [self retain]; 370 return [self retain];
370 } 371 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 std::min(iconSize.height, kIconDimension)); 422 std::min(iconSize.height, kIconDimension));
422 [resultIcon drawInRect:iconRect 423 [resultIcon drawInRect:iconRect
423 fromRect:NSZeroRect 424 fromRect:NSZeroRect
424 operation:NSCompositeSourceOver 425 operation:NSCompositeSourceOver
425 fraction:1.0 426 fraction:1.0
426 respectFlipped:YES 427 respectFlipped:YES
427 hints:nil]; 428 hints:nil];
428 } 429 }
429 430
430 @end 431 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698