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

Unified Diff: chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.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: Removed withView arg from highlightRowAt Created 5 years, 7 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_view_mac.mm
diff --git a/chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.mm b/chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.mm
index 8e403f0622416c3759f9ca9b209afd89a158211c..87badf5eae8e311c177c1d8214e49929f9e5d990 100644
--- a/chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.mm
+++ b/chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.mm
@@ -29,10 +29,6 @@
namespace {
-// How much to adjust the cell sizing up from the default determined
-// by the font.
-const CGFloat kCellHeightAdjust = 6.0;
-
// Padding between matrix and the top and bottom of the popup window.
const CGFloat kPopupPaddingVertical = 5.0;
@@ -83,7 +79,7 @@ void OmniboxPopupViewMac::UpdatePopupAppearance() {
// Break references to |this| because the popup may not be
// deallocated immediately.
- [matrix_ setDelegate:nil];
+ [matrix_ setObserver:NULL];
matrix_.reset();
popup_.reset(nil);
@@ -94,44 +90,9 @@ void OmniboxPopupViewMac::UpdatePopupAppearance() {
}
CreatePopupIfNeeded();
-
- // Calculate the width of the matrix based on backing out the popup's border
- // from the width of the field.
- const CGFloat matrix_width = NSWidth([field_ bounds]);
- DCHECK_GT(matrix_width, 0.0);
-
- // Load the results into the popup's matrix.
- DCHECK_GT(rows, 0U);
- [matrix_ renewRows:rows columns:1];
- CGFloat max_match_contents_width = 0.0f;
- CGFloat contents_offset = -1.0f;
- for (size_t ii = 0; ii < rows; ++ii) {
- OmniboxPopupCell* cell = [matrix_ cellAtRow:ii column:0];
- const AutocompleteMatch& match = GetResult().match_at(ii + start_match);
- [cell setImage:ImageForMatch(match)];
- [cell setMatch:match];
- if (match.type == AutocompleteMatchType::SEARCH_SUGGEST_TAIL) {
- max_match_contents_width = std::max(max_match_contents_width,
- [cell getMatchContentsWidth]);
- if (contents_offset < 0.0f) {
- contents_offset = [OmniboxPopupCell computeContentsOffset:match];
- }
- [cell setContentsOffset:contents_offset];
- }
- }
-
- for (size_t ii = 0; ii < rows; ++ii) {
- OmniboxPopupCell* cell = [matrix_ cellAtRow:ii column:0];
- [cell setMaxMatchContentsWidth:max_match_contents_width];
- }
-
- // Set the cell size to fit a line of text in the cell's font. All
- // cells should use the same font and each should layout in one
- // line, so they should all be about the same height.
- const NSSize cell_size = [[matrix_ cellAtRow:0 column:0] cellSize];
- DCHECK_GT(cell_size.height, 0.0);
- const CGFloat cell_height = cell_size.height + kCellHeightAdjust;
- [matrix_ setCellSize:NSMakeSize(matrix_width, cell_height)];
+ [matrix_ setController:[[OmniboxPopupTableController alloc]
+ initWithMatchResults:result
+ popupView:*this]];
Scott Hess - ex-Googler 2015/05/21 20:40:27 I don't think anyone has the owning reference to O
dschuyler 2015/05/26 18:40:21 Done.
// Update the selection before placing (and displaying) the window.
PaintUpdatesNow();
@@ -140,7 +101,7 @@ void OmniboxPopupViewMac::UpdatePopupAppearance() {
// because actually resizing the matrix messed up the popup size
// animation.
DCHECK_EQ([matrix_ intercellSpacing].height, 0.0);
- PositionPopup(rows * cell_height);
+ PositionPopup(NSHeight([matrix_ frame]));
}
gfx::Rect OmniboxPopupViewMac::GetTargetBounds() {
@@ -155,13 +116,7 @@ gfx::Rect OmniboxPopupViewMac::GetTargetBounds() {
// This is only called by model in SetSelectedLine() after updating
// everything. Popup should already be visible.
void OmniboxPopupViewMac::PaintUpdatesNow() {
- size_t start_match = model_->result().ShouldHideTopMatch() ? 1 : 0;
- if (start_match > model_->selected_line()) {
- [matrix_ deselectAllCells];
- } else {
- [matrix_ selectCellAtRow:model_->selected_line() - start_match column:0];
- }
-
+ [matrix_ selectRowIndex:model_->selected_line()];
}
void OmniboxPopupViewMac::OnMatrixRowSelected(OmniboxPopupMatrix* matrix,
@@ -242,10 +197,6 @@ void OmniboxPopupViewMac::PositionPopup(const CGFloat matrixHeight) {
popup_frame.origin =
[[controller window] convertBaseToScreen:popup_frame.origin];
- // Do nothing if the popup is already animating to the given |frame|.
- if (NSEqualRects(popup_frame, target_popup_frame_))
- return;
Scott Hess - ex-Googler 2015/05/21 20:40:27 Did I already mention that this looks like somethi
dschuyler 2015/05/26 18:40:21 Acknowledged.
-
// Top separator.
NSRect top_separator_frame = NSZeroRect;
top_separator_frame.size.width = NSWidth(popup_frame);
@@ -270,13 +221,18 @@ void OmniboxPopupViewMac::PositionPopup(const CGFloat matrixHeight) {
background_rect.origin.y = NSMaxY(top_separator_frame);
[background_view_ setFrame:background_rect];
+ // Calculate the width of the table based on backing out the popup's border
+ // from the width of the field.
+ const CGFloat tableWidth = NSWidth([field_ bounds]);
+ DCHECK_GT(tableWidth, 0.0);
+
// Matrix.
NSPoint field_origin_base =
[field_ convertPoint:[field_ bounds].origin toView:nil];
NSRect matrix_frame = NSZeroRect;
matrix_frame.origin.x = field_origin_base.x - NSMinX(anchor_rect_base);
matrix_frame.origin.y = kPopupPaddingVertical;
- matrix_frame.size.width = [matrix_ cellSize].width;
+ matrix_frame.size.width = tableWidth;
matrix_frame.size.height = matrixHeight;
[matrix_ setFrame:matrix_frame];
@@ -318,7 +274,8 @@ void OmniboxPopupViewMac::PositionPopup(const CGFloat matrixHeight) {
[[field_ window] addChildWindow:popup_ ordered:NSWindowAbove];
}
-NSImage* OmniboxPopupViewMac::ImageForMatch(const AutocompleteMatch& match) {
+NSImage* OmniboxPopupViewMac::ImageForMatch(
+ const AutocompleteMatch& match) const {
Scott Hess - ex-Googler 2015/05/21 20:40:27 I was wondering earlier if this could just be pull
dschuyler 2015/05/26 18:40:21 I wondered about the same. In the scope of 'this
groby-ooo-7-16 2015/05/26 21:23:22 I think we've heaped on enough change :) Follow-up
dschuyler 2015/05/28 20:34:22 The bug is 492896 Done.
gfx::Image image = model_->GetIconIfExtensionMatch(match);
if (!image.IsEmpty())
return image.AsNSImage();

Powered by Google App Engine
This is Rietveld 408576698