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

Unified Diff: chrome/browser/ui/cocoa/omnibox/omnibox_popup_matrix.mm

Issue 1099403005: [AiS] changing mac omnibox suggestions form NSMatrix to NSTableView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review changes Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/omnibox/omnibox_popup_matrix.mm
diff --git a/chrome/browser/ui/cocoa/omnibox/omnibox_popup_matrix.mm b/chrome/browser/ui/cocoa/omnibox/omnibox_popup_matrix.mm
index 9000941c26cea3536cdcc0166a58e9597d9a4aa9..ef97f09abe37e4b54dc43ff24d5eede131ce1699 100644
--- a/chrome/browser/ui/cocoa/omnibox/omnibox_popup_matrix.mm
+++ b/chrome/browser/ui/cocoa/omnibox/omnibox_popup_matrix.mm
@@ -14,41 +14,97 @@ const NSInteger kMiddleButtonNumber = 2;
} // namespace
-@interface OmniboxPopupMatrix()
+@implementation OmniboxPopupTableController
+
+- (id)init {
+ if ((self = [super init])) {
+ array_ = [[NSMutableArray alloc] init];
+ }
+ return self;
+}
+
+- (NSInteger)numberOfRowsInTableView:(NSTableView*)tableView {
+ return [array_ count];
+}
+
+- (id)tableView:(NSTableView*)aTableView
+ objectValueForTableColumn:(NSTableColumn*)aTableColumn
+ row:(NSInteger)rowIndex {
+ // Returning the cell allows selection highlighting to work properly.
+ return [array_ objectAtIndex:rowIndex];
+}
+
+- (NSCell*)tableView:(NSTableView*)tableView
+ dataCellForTableColumn:(NSTableColumn*)tableColumn
+ row:(NSInteger)row {
+ // Returning the cell populates data in the table.
+ return [array_ objectAtIndex:row];
+}
+
+- (void)setCellCount:(NSUInteger)count {
+ // Add more.
+ while (count >= [array_ count]) {
Scott Hess - ex-Googler 2015/04/25 06:04:27 Suggest while ([array_ count] < count)... Might b
dschuyler 2015/05/01 21:50:54 I'm sure that in previous test I've done, it was b
+ [array_ addObject:[[[OmniboxPopupCell alloc] init] autorelease]];
+ }
+ // Remove excess.
+ if (count < [array_ count])
+ [array_ removeObjectsInRange:NSMakeRange(count, [array_ count] - count)];
Scott Hess - ex-Googler 2015/04/25 06:04:27 This is documented as using -removeObjectsAtIndex:
dschuyler 2015/05/01 21:50:54 Previously in this CL, it was calling removeLastOb
Scott Hess - ex-Googler 2015/05/04 19:40:20 I'm mixed. Rachel suggested that change, and I ca
+ DCHECK_EQ(count, [array_ count]);
+ // Set selection to be the first cell.
+ if (count)
+ [[array_ objectAtIndex:0] setState:NSOnState];
Scott Hess - ex-Googler 2015/04/25 06:04:27 Since you may have re-used existing cells in array
dschuyler 2015/05/01 21:50:54 Good catch. Done.
+}
+
+- (NSArray*)getCellArray {
+ return array_;
Scott Hess - ex-Googler 2015/04/25 06:04:27 You document this as an immutable copy, but it can
groby-ooo-7-16 2015/04/25 19:01:12 Technically, if the controller managed highlight/r
dschuyler 2015/05/01 21:50:53 Done.
dschuyler 2015/05/01 21:50:54 That comment was odd - the array itself would not
+}
+
+- (CGFloat)tableView:(NSTableView*)tableView heightOfRow:(NSInteger)row {
+ return [[array_ objectAtIndex:row] cellSize].height;
+}
+
+@end
+
+@interface OmniboxPopupTableView ()
- (void)resetTrackingArea;
- (void)highlightRowAt:(NSInteger)rowIndex;
- (void)highlightRowUnder:(NSEvent*)theEvent;
- (BOOL)selectCellForEvent:(NSEvent*)theEvent;
@end
-@implementation OmniboxPopupMatrix
+@implementation OmniboxPopupTableView
-- (id)initWithDelegate:(OmniboxPopupMatrixDelegate*)delegate {
+- (id)initWithDelegate:(OmniboxPopupTableDelegate*)delegate {
if ((self = [super initWithFrame:NSZeroRect])) {
delegate_ = delegate;
- [self setCellClass:[OmniboxPopupCell class]];
+ controller_ = [[OmniboxPopupTableController alloc] init];
+
+ NSTableColumn* column =
Scott Hess - ex-Googler 2015/04/25 06:04:27 scoped_nsobject<>.
dschuyler 2015/05/01 21:50:54 Could I have done autorelease here instead of the
Scott Hess - ex-Googler 2015/05/04 19:40:20 scoped_nsobject<> means "Add a reference here, dro
+ [[NSTableColumn alloc] initWithIdentifier:@"MainCell"];
+ [self addTableColumn:column];
+
+ [self setDelegate:controller_];
+ [self setDataSource:controller_];
// Cells pack with no spacing.
[self setIntercellSpacing:NSMakeSize(0.0, 0.0)];
- [self setDrawsBackground:YES];
[self setBackgroundColor:[NSColor controlBackgroundColor]];
- [self renewRows:0 columns:1];
[self setAllowsEmptySelection:YES];
- [self setMode:NSRadioModeMatrix];
- [self deselectAllCells];
+ [self deselectAll:self];
+ [self setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleNone];
[self resetTrackingArea];
}
return self;
}
-- (void)setDelegate:(OmniboxPopupMatrixDelegate*)delegate {
+- (void)setCppDelegate:(OmniboxPopupTableDelegate*)delegate {
delegate_ = delegate;
}
- (NSInteger)highlightedRow {
- NSArray* cells = [self cells];
+ NSArray* cells = [controller_ getCellArray];
const NSUInteger count = [cells count];
for(NSUInteger i = 0; i < count; ++i) {
if ([[cells objectAtIndex:i] isHighlighted]) {
@@ -106,7 +162,7 @@ const NSInteger kMiddleButtonNumber = 2;
const NSInteger highlightedRow = [self highlightedRow];
if (highlightedRow != -1) {
DCHECK(delegate_);
- delegate_->OnMatrixRowMiddleClicked(self, highlightedRow);
+ delegate_->OnTableRowMiddleClicked(self, highlightedRow);
}
}
@@ -141,10 +197,21 @@ const NSInteger kMiddleButtonNumber = 2;
}
DCHECK(delegate_);
- delegate_->OnMatrixRowClicked(self, selectedRow);
+ delegate_->OnTableRowClicked(self, selectedRow);
}
}
+- (void)setCellCount:(NSUInteger)count {
+ return [controller_ setCellCount:count];
+}
+
+- (OmniboxPopupCell*)cellAtRow:(NSUInteger)row {
+ NSArray* array = [controller_ getCellArray];
+ if (row >= [array count])
+ return nil;
+ return [array objectAtIndex:row];
+}
+
- (void)resetTrackingArea {
if (trackingArea_.get())
[self removeTrackingArea:trackingArea_.get()];
@@ -163,32 +230,30 @@ const NSInteger kMiddleButtonNumber = 2;
- (void)highlightRowAt:(NSInteger)rowIndex {
// highlightCell will be nil if rowIndex is out of range, so no cell will be
// highlighted.
Scott Hess - ex-Googler 2015/04/25 06:04:27 I think the out-of-range at this point is if the m
dschuyler 2015/05/01 21:50:53 This code has been reworked in the new patch.
- NSCell* highlightCell = [self cellAtRow:rowIndex column:0];
+ OmniboxPopupCell* highlightCell = [self cellAtRow:rowIndex];
+ if ([highlightCell isHighlighted])
+ return;
- for (NSCell* cell in [self cells]) {
- [cell setHighlighted:(cell == highlightCell)];
+ for (OmniboxPopupCell* cell in controller_.getCellArray) {
Scott Hess - ex-Googler 2015/04/25 06:04:27 I have no particular preference WRT controller_.ge
+ if ([cell isHighlighted] || cell == highlightCell) {
+ [cell highlight:(cell == highlightCell) withFrame:_bounds inView:self];
+ }
Scott Hess - ex-Googler 2015/04/25 06:04:27 I'm not really sure what this is saying. The prev
groby-ooo-7-16 2015/04/25 19:01:12 I'll re-ask the question I asked in my last commen
dschuyler 2015/05/01 21:50:54 Done.
dschuyler 2015/05/01 21:50:54 This code has been reworked in the new patch. It
}
}
- (void)highlightRowUnder:(NSEvent*)theEvent {
NSPoint point = [self convertPoint:[theEvent locationInWindow] fromView:nil];
- NSInteger row, column;
- if ([self getRow:&row column:&column forPoint:point]) {
- [self highlightRowAt:row];
- } else {
- [self highlightRowAt:-1];
- }
+ [self highlightRowAt:[self rowAtPoint:point]];
}
// Select cell under |theEvent|, returning YES if a selection is made.
- (BOOL)selectCellForEvent:(NSEvent*)theEvent {
NSPoint point = [self convertPoint:[theEvent locationInWindow] fromView:nil];
- NSInteger row, column;
- if ([self getRow:&row column:&column forPoint:point]) {
- DCHECK_EQ(column, 0);
+ NSInteger row = [self rowAtPoint:point];
+ if (row != -1) {
DCHECK(delegate_);
- delegate_->OnMatrixRowSelected(self, row);
+ delegate_->OnTableRowSelected(self, row);
return YES;
}
return NO;

Powered by Google App Engine
This is Rietveld 408576698