Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.h" | 5 #include "chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSAnimation+Duration.h " | 22 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSAnimation+Duration.h " |
| 23 #import "ui/base/cocoa/cocoa_base_utils.h" | 23 #import "ui/base/cocoa/cocoa_base_utils.h" |
| 24 #import "ui/base/cocoa/flipped_view.h" | 24 #import "ui/base/cocoa/flipped_view.h" |
| 25 #include "ui/base/cocoa/window_size_constants.h" | 25 #include "ui/base/cocoa/window_size_constants.h" |
| 26 #include "ui/gfx/geometry/rect.h" | 26 #include "ui/gfx/geometry/rect.h" |
| 27 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 27 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
| 28 #include "ui/gfx/text_elider.h" | 28 #include "ui/gfx/text_elider.h" |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 // How much to adjust the cell sizing up from the default determined | 32 // Padding between table and the top and bottom of the popup window. |
| 33 // by the font. | |
| 34 const CGFloat kCellHeightAdjust = 6.0; | |
|
dschuyler
2015/04/24 18:43:09
This moved to another file in this CL.
| |
| 35 | |
| 36 // Padding between matrix and the top and bottom of the popup window. | |
| 37 const CGFloat kPopupPaddingVertical = 5.0; | 33 const CGFloat kPopupPaddingVertical = 5.0; |
| 38 | 34 |
| 39 // Animation duration when animating the popup window smaller. | 35 // Animation duration when animating the popup window smaller. |
| 40 const NSTimeInterval kShrinkAnimationDuration = 0.1; | 36 const NSTimeInterval kShrinkAnimationDuration = 0.1; |
| 41 | 37 |
| 42 // Background colors for different states of the popup elements. | 38 // Background colors for different states of the popup elements. |
| 43 NSColor* BackgroundColor() { | 39 NSColor* BackgroundColor() { |
| 44 return [NSColor controlBackgroundColor]; | 40 return [NSColor controlBackgroundColor]; |
| 45 } | 41 } |
| 46 | 42 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 58 DCHECK(edit_model); | 54 DCHECK(edit_model); |
| 59 } | 55 } |
| 60 | 56 |
| 61 OmniboxPopupViewMac::~OmniboxPopupViewMac() { | 57 OmniboxPopupViewMac::~OmniboxPopupViewMac() { |
| 62 // Destroy the popup model before this object is destroyed, because | 58 // Destroy the popup model before this object is destroyed, because |
| 63 // it can call back to us in the destructor. | 59 // it can call back to us in the destructor. |
| 64 model_.reset(); | 60 model_.reset(); |
| 65 | 61 |
| 66 // Break references to |this| because the popup may not be | 62 // Break references to |this| because the popup may not be |
| 67 // deallocated immediately. | 63 // deallocated immediately. |
| 68 [matrix_ setDelegate:NULL]; | 64 [table_view_ setCppDelegate:NULL]; |
| 69 } | 65 } |
| 70 | 66 |
| 71 bool OmniboxPopupViewMac::IsOpen() const { | 67 bool OmniboxPopupViewMac::IsOpen() const { |
| 72 return popup_ != nil; | 68 return popup_ != nil; |
| 73 } | 69 } |
| 74 | 70 |
| 71 void OmniboxPopupViewMac::InvalidateLine(size_t line) { | |
| 72 // Update the selection state so that it's drawn properly later. | |
| 73 [[table_view_ cellAtRow:line] | |
| 74 setState:(line == model_->selected_line() ? NSOnState : NSOffState)]; | |
| 75 } | |
| 76 | |
| 75 void OmniboxPopupViewMac::UpdatePopupAppearance() { | 77 void OmniboxPopupViewMac::UpdatePopupAppearance() { |
| 76 DCHECK([NSThread isMainThread]); | 78 DCHECK([NSThread isMainThread]); |
| 77 const AutocompleteResult& result = GetResult(); | 79 const AutocompleteResult& result = GetResult(); |
| 78 const size_t start_match = result.ShouldHideTopMatch() ? 1 : 0; | 80 const size_t start_match = result.ShouldHideTopMatch() ? 1 : 0; |
| 79 const size_t rows = result.size() - start_match; | 81 const size_t rows = result.size() - start_match; |
| 80 if (rows == 0) { | 82 if (rows == 0) { |
| 81 [[popup_ parentWindow] removeChildWindow:popup_]; | 83 [[popup_ parentWindow] removeChildWindow:popup_]; |
| 82 [popup_ orderOut:nil]; | 84 [popup_ orderOut:nil]; |
| 83 | 85 |
| 84 // Break references to |this| because the popup may not be | 86 // Break references to |this| because the popup may not be |
| 85 // deallocated immediately. | 87 // deallocated immediately. |
| 86 [matrix_ setDelegate:nil]; | 88 [table_view_ setCppDelegate:NULL]; |
| 87 matrix_.reset(); | 89 table_view_.reset(); |
| 88 | 90 |
| 89 popup_.reset(nil); | 91 popup_.reset(nil); |
| 90 | 92 |
| 91 target_popup_frame_ = NSZeroRect; | 93 target_popup_frame_ = NSZeroRect; |
| 92 | 94 |
| 93 return; | 95 return; |
| 94 } | 96 } |
| 95 | 97 |
| 96 CreatePopupIfNeeded(); | 98 CreatePopupIfNeeded(); |
| 97 | 99 |
| 98 // Calculate the width of the matrix based on backing out the popup's border | 100 [table_view_ setCellCount:rows]; |
| 99 // from the width of the field. | |
| 100 const CGFloat matrix_width = NSWidth([field_ bounds]); | |
| 101 DCHECK_GT(matrix_width, 0.0); | |
|
dschuyler
2015/04/24 18:43:09
This is moved elsewhere in this file in this CL.
| |
| 102 | 101 |
| 103 // Load the results into the popup's matrix. | 102 // Load the results into the popup's table. |
| 104 DCHECK_GT(rows, 0U); | 103 DCHECK_GT(rows, 0U); |
| 105 [matrix_ renewRows:rows columns:1]; | |
| 106 CGFloat max_match_contents_width = 0.0f; | 104 CGFloat max_match_contents_width = 0.0f; |
| 107 CGFloat contents_offset = -1.0f; | 105 CGFloat contents_offset = -1.0f; |
| 108 for (size_t ii = 0; ii < rows; ++ii) { | 106 for (size_t ii = 0; ii < rows; ++ii) { |
| 109 OmniboxPopupCell* cell = [matrix_ cellAtRow:ii column:0]; | 107 OmniboxPopupCell* cell = [table_view_ cellAtRow:ii]; |
| 110 const AutocompleteMatch& match = GetResult().match_at(ii + start_match); | 108 const AutocompleteMatch& match = GetResult().match_at(ii + start_match); |
| 111 [cell setImage:ImageForMatch(match)]; | 109 [cell setImage:ImageForMatch(match)]; |
| 112 [cell setMatch:match]; | 110 [cell setMatch:match]; |
| 113 if (match.type == AutocompleteMatchType::SEARCH_SUGGEST_TAIL) { | 111 if (match.type == AutocompleteMatchType::SEARCH_SUGGEST_TAIL) { |
| 114 max_match_contents_width = std::max(max_match_contents_width, | 112 max_match_contents_width = std::max(max_match_contents_width, |
| 115 [cell getMatchContentsWidth]); | 113 [cell getMatchContentsWidth]); |
| 116 if (contents_offset < 0.0f) { | 114 if (contents_offset < 0.0f) { |
| 117 contents_offset = [OmniboxPopupCell computeContentsOffset:match]; | 115 contents_offset = [OmniboxPopupCell computeContentsOffset:match]; |
| 118 } | 116 } |
| 119 [cell setContentsOffset:contents_offset]; | 117 [cell setContentsOffset:contents_offset]; |
| 120 } | 118 } |
| 121 } | 119 } |
| 120 [table_view_ noteNumberOfRowsChanged]; | |
| 122 | 121 |
| 122 NSInteger popupHeight = 0; | |
| 123 for (size_t ii = 0; ii < rows; ++ii) { | 123 for (size_t ii = 0; ii < rows; ++ii) { |
| 124 OmniboxPopupCell* cell = [matrix_ cellAtRow:ii column:0]; | 124 OmniboxPopupCell* cell = [table_view_ cellAtRow:ii]; |
| 125 [cell setMaxMatchContentsWidth:max_match_contents_width]; | 125 [cell setMaxMatchContentsWidth:max_match_contents_width]; |
| 126 popupHeight += [cell cellSize].height; | |
| 126 } | 127 } |
| 127 | 128 if (rows) { |
| 128 // Set the cell size to fit a line of text in the cell's font. All | 129 popupHeight += [table_view_ intercellSpacing].height * (rows - 1); |
|
dschuyler
2015/04/24 18:43:09
This isn't strictly necessary. Right now the spac
| |
| 129 // cells should use the same font and each should layout in one | 130 } |
| 130 // line, so they should all be about the same height. | |
| 131 const NSSize cell_size = [[matrix_ cellAtRow:0 column:0] cellSize]; | |
| 132 DCHECK_GT(cell_size.height, 0.0); | |
| 133 const CGFloat cell_height = cell_size.height + kCellHeightAdjust; | |
| 134 [matrix_ setCellSize:NSMakeSize(matrix_width, cell_height)]; | |
| 135 | 131 |
| 136 // Update the selection before placing (and displaying) the window. | 132 // Update the selection before placing (and displaying) the window. |
| 137 PaintUpdatesNow(); | 133 PaintUpdatesNow(); |
| 138 | 134 |
| 139 // Calculate the matrix size manually rather than using -sizeToCells | 135 // Calculate the table size manually rather than using -sizeToCells |
| 140 // because actually resizing the matrix messed up the popup size | 136 // because actually resizing the table messed up the popup size |
| 141 // animation. | 137 // animation. |
| 142 DCHECK_EQ([matrix_ intercellSpacing].height, 0.0); | 138 DCHECK_EQ([table_view_ intercellSpacing].height, 0.0); |
| 143 PositionPopup(rows * cell_height); | 139 PositionPopup(popupHeight); |
| 144 } | 140 } |
| 145 | 141 |
| 146 gfx::Rect OmniboxPopupViewMac::GetTargetBounds() { | 142 gfx::Rect OmniboxPopupViewMac::GetTargetBounds() { |
| 147 // Flip the coordinate system before returning. | 143 // Flip the coordinate system before returning. |
| 148 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; | 144 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; |
| 149 NSRect monitor_frame = [screen frame]; | 145 NSRect monitor_frame = [screen frame]; |
| 150 gfx::Rect bounds(NSRectToCGRect(target_popup_frame_)); | 146 gfx::Rect bounds(NSRectToCGRect(target_popup_frame_)); |
| 151 bounds.set_y(monitor_frame.size.height - bounds.y() - bounds.height()); | 147 bounds.set_y(monitor_frame.size.height - bounds.y() - bounds.height()); |
| 152 return bounds; | 148 return bounds; |
| 153 } | 149 } |
| 154 | 150 |
| 155 // This is only called by model in SetSelectedLine() after updating | 151 // This is only called by model in SetSelectedLine() after updating |
| 156 // everything. Popup should already be visible. | 152 // everything. Popup should already be visible. |
| 157 void OmniboxPopupViewMac::PaintUpdatesNow() { | 153 void OmniboxPopupViewMac::PaintUpdatesNow() { |
| 158 size_t start_match = model_->result().ShouldHideTopMatch() ? 1 : 0; | 154 size_t start_match = model_->result().ShouldHideTopMatch() ? 1 : 0; |
| 159 if (start_match > model_->selected_line()) { | 155 NSIndexSet* indexSet = [NSIndexSet indexSet]; |
| 160 [matrix_ deselectAllCells]; | 156 if (start_match <= model_->selected_line()) { |
| 161 } else { | 157 indexSet = |
| 162 [matrix_ selectCellAtRow:model_->selected_line() - start_match column:0]; | 158 [NSIndexSet indexSetWithIndex:model_->selected_line() - start_match]; |
| 163 } | 159 } |
| 164 | 160 [table_view_ selectRowIndexes:indexSet byExtendingSelection:NO]; |
| 165 } | 161 } |
| 166 | 162 |
| 167 void OmniboxPopupViewMac::OnMatrixRowSelected(OmniboxPopupMatrix* matrix, | 163 void OmniboxPopupViewMac::OnTableRowSelected(OmniboxPopupTableView* table_view, |
| 168 size_t row) { | 164 size_t row) { |
| 169 size_t start_match = model_->result().ShouldHideTopMatch() ? 1 : 0; | 165 size_t start_match = model_->result().ShouldHideTopMatch() ? 1 : 0; |
| 170 model_->SetSelectedLine(row + start_match, false, false); | 166 model_->SetSelectedLine(row + start_match, false, false); |
| 171 } | 167 } |
| 172 | 168 |
| 173 void OmniboxPopupViewMac::OnMatrixRowClicked(OmniboxPopupMatrix* matrix, | 169 void OmniboxPopupViewMac::OnTableRowClicked(OmniboxPopupTableView* table_view, |
| 174 size_t row) { | 170 size_t row) { |
| 175 OpenURLForRow(row, | 171 OpenURLForRow(row, |
| 176 ui::WindowOpenDispositionFromNSEvent([NSApp currentEvent])); | 172 ui::WindowOpenDispositionFromNSEvent([NSApp currentEvent])); |
| 177 } | 173 } |
| 178 | 174 |
| 179 void OmniboxPopupViewMac::OnMatrixRowMiddleClicked(OmniboxPopupMatrix* matrix, | 175 void OmniboxPopupViewMac::OnTableRowMiddleClicked( |
| 180 size_t row) { | 176 OmniboxPopupTableView* table_view, |
| 177 size_t row) { | |
| 181 OpenURLForRow(row, NEW_BACKGROUND_TAB); | 178 OpenURLForRow(row, NEW_BACKGROUND_TAB); |
| 182 } | 179 } |
| 183 | 180 |
| 184 const AutocompleteResult& OmniboxPopupViewMac::GetResult() const { | 181 const AutocompleteResult& OmniboxPopupViewMac::GetResult() const { |
| 185 return model_->result(); | 182 return model_->result(); |
| 186 } | 183 } |
| 187 | 184 |
| 188 void OmniboxPopupViewMac::CreatePopupIfNeeded() { | 185 void OmniboxPopupViewMac::CreatePopupIfNeeded() { |
| 189 if (!popup_) { | 186 if (!popup_) { |
| 190 popup_.reset( | 187 popup_.reset( |
| 191 [[NSWindow alloc] initWithContentRect:ui::kWindowSizeDeterminedLater | 188 [[NSWindow alloc] initWithContentRect:ui::kWindowSizeDeterminedLater |
| 192 styleMask:NSBorderlessWindowMask | 189 styleMask:NSBorderlessWindowMask |
| 193 backing:NSBackingStoreBuffered | 190 backing:NSBackingStoreBuffered |
| 194 defer:YES]); | 191 defer:YES]); |
| 195 [popup_ setBackgroundColor:[NSColor clearColor]]; | 192 [popup_ setBackgroundColor:[NSColor clearColor]]; |
| 196 [popup_ setOpaque:NO]; | 193 [popup_ setOpaque:NO]; |
| 197 | 194 |
| 198 // Use a flipped view to pin the matrix top the top left. This is needed | 195 // Use a flipped view to pin the table view top the top left. This is needed |
| 199 // for animated resize. | 196 // for animated resize. |
| 200 base::scoped_nsobject<FlippedView> contentView( | 197 base::scoped_nsobject<FlippedView> contentView( |
| 201 [[FlippedView alloc] initWithFrame:NSZeroRect]); | 198 [[FlippedView alloc] initWithFrame:NSZeroRect]); |
| 202 [popup_ setContentView:contentView]; | 199 [popup_ setContentView:contentView]; |
| 203 | 200 |
| 204 // View to draw a background beneath the matrix. | 201 // View to draw a background beneath the table. |
| 205 background_view_.reset([[NSBox alloc] initWithFrame:NSZeroRect]); | 202 background_view_.reset([[NSBox alloc] initWithFrame:NSZeroRect]); |
| 206 [background_view_ setBoxType:NSBoxCustom]; | 203 [background_view_ setBoxType:NSBoxCustom]; |
| 207 [background_view_ setBorderType:NSNoBorder]; | 204 [background_view_ setBorderType:NSNoBorder]; |
| 208 [background_view_ setFillColor:BackgroundColor()]; | 205 [background_view_ setFillColor:BackgroundColor()]; |
| 209 [background_view_ setContentViewMargins:NSZeroSize]; | 206 [background_view_ setContentViewMargins:NSZeroSize]; |
| 210 [contentView addSubview:background_view_]; | 207 [contentView addSubview:background_view_]; |
| 211 | 208 |
| 212 matrix_.reset([[OmniboxPopupMatrix alloc] initWithDelegate:this]); | 209 table_view_.reset([[OmniboxPopupTableView alloc] initWithDelegate:this]); |
| 213 [background_view_ addSubview:matrix_]; | 210 [background_view_ addSubview:table_view_]; |
| 214 | 211 |
| 215 top_separator_view_.reset( | 212 top_separator_view_.reset( |
| 216 [[OmniboxPopupTopSeparatorView alloc] initWithFrame:NSZeroRect]); | 213 [[OmniboxPopupTopSeparatorView alloc] initWithFrame:NSZeroRect]); |
| 217 [contentView addSubview:top_separator_view_]; | 214 [contentView addSubview:top_separator_view_]; |
| 218 | 215 |
| 219 bottom_separator_view_.reset( | 216 bottom_separator_view_.reset( |
| 220 [[OmniboxPopupBottomSeparatorView alloc] initWithFrame:NSZeroRect]); | 217 [[OmniboxPopupBottomSeparatorView alloc] initWithFrame:NSZeroRect]); |
| 221 [contentView addSubview:bottom_separator_view_]; | 218 [contentView addSubview:bottom_separator_view_]; |
| 222 | 219 |
| 223 // TODO(dtseng): Ignore until we provide NSAccessibility support. | 220 // TODO(dtseng): Ignore until we provide NSAccessibility support. |
| 224 [popup_ accessibilitySetOverrideValue:NSAccessibilityUnknownRole | 221 [popup_ accessibilitySetOverrideValue:NSAccessibilityUnknownRole |
| 225 forAttribute:NSAccessibilityRoleAttribute]; | 222 forAttribute:NSAccessibilityRoleAttribute]; |
| 226 } | 223 } |
| 227 } | 224 } |
| 228 | 225 |
| 229 void OmniboxPopupViewMac::PositionPopup(const CGFloat matrixHeight) { | 226 void OmniboxPopupViewMac::PositionPopup(const CGFloat tableHeight) { |
| 230 BrowserWindowController* controller = | 227 BrowserWindowController* controller = |
| 231 [BrowserWindowController browserWindowControllerForView:field_]; | 228 [BrowserWindowController browserWindowControllerForView:field_]; |
| 232 NSRect anchor_rect_base = [controller omniboxPopupAnchorRect]; | 229 NSRect anchor_rect_base = [controller omniboxPopupAnchorRect]; |
| 233 | 230 |
| 234 // Calculate the popup's position on the screen. | 231 // Calculate the popup's position on the screen. |
| 235 NSRect popup_frame = anchor_rect_base; | 232 NSRect popup_frame = anchor_rect_base; |
| 236 // Size to fit the matrix and shift down by the size. | 233 // Size to fit the table view and shift down by the size. |
| 237 popup_frame.size.height = matrixHeight + kPopupPaddingVertical * 2.0; | 234 popup_frame.size.height = tableHeight + kPopupPaddingVertical * 2.0; |
| 238 popup_frame.size.height += [OmniboxPopupTopSeparatorView preferredHeight]; | 235 popup_frame.size.height += [OmniboxPopupTopSeparatorView preferredHeight]; |
| 239 popup_frame.size.height += [OmniboxPopupBottomSeparatorView preferredHeight]; | 236 popup_frame.size.height += [OmniboxPopupBottomSeparatorView preferredHeight]; |
| 240 popup_frame.origin.y -= NSHeight(popup_frame); | 237 popup_frame.origin.y -= NSHeight(popup_frame); |
| 241 // Shift to screen coordinates. | 238 // Shift to screen coordinates. |
| 242 popup_frame.origin = | 239 popup_frame.origin = |
| 243 [[controller window] convertBaseToScreen:popup_frame.origin]; | 240 [[controller window] convertBaseToScreen:popup_frame.origin]; |
| 244 | 241 |
| 245 // Do nothing if the popup is already animating to the given |frame|. | 242 // Do nothing if the popup is already animating to the given |frame|. |
| 246 if (NSEqualRects(popup_frame, target_popup_frame_)) | 243 // if (NSEqualRects(popup_frame, target_popup_frame_)) |
| 247 return; | 244 // return; |
|
dschuyler
2015/04/24 18:43:09
This short circuit causes a problem with the highl
groby-ooo-7-16
2015/04/24 20:11:17
I'm not sure what exactly this does, or why removi
| |
| 248 | 245 |
| 249 // Top separator. | 246 // Top separator. |
| 250 NSRect top_separator_frame = NSZeroRect; | 247 NSRect top_separator_frame = NSZeroRect; |
| 251 top_separator_frame.size.width = NSWidth(popup_frame); | 248 top_separator_frame.size.width = NSWidth(popup_frame); |
| 252 top_separator_frame.size.height = | 249 top_separator_frame.size.height = |
| 253 [OmniboxPopupTopSeparatorView preferredHeight]; | 250 [OmniboxPopupTopSeparatorView preferredHeight]; |
| 254 [top_separator_view_ setFrame:top_separator_frame]; | 251 [top_separator_view_ setFrame:top_separator_frame]; |
| 255 | 252 |
| 256 // Bottom separator. | 253 // Bottom separator. |
| 257 NSRect bottom_separator_frame = NSZeroRect; | 254 NSRect bottom_separator_frame = NSZeroRect; |
| 258 bottom_separator_frame.size.width = NSWidth(popup_frame); | 255 bottom_separator_frame.size.width = NSWidth(popup_frame); |
| 259 bottom_separator_frame.size.height = | 256 bottom_separator_frame.size.height = |
| 260 [OmniboxPopupBottomSeparatorView preferredHeight]; | 257 [OmniboxPopupBottomSeparatorView preferredHeight]; |
| 261 bottom_separator_frame.origin.y = | 258 bottom_separator_frame.origin.y = |
| 262 NSHeight(popup_frame) - NSHeight(bottom_separator_frame); | 259 NSHeight(popup_frame) - NSHeight(bottom_separator_frame); |
| 263 [bottom_separator_view_ setFrame:bottom_separator_frame]; | 260 [bottom_separator_view_ setFrame:bottom_separator_frame]; |
| 264 | 261 |
| 265 // Background view. | 262 // Background view. |
| 266 NSRect background_rect = NSZeroRect; | 263 NSRect background_rect = NSZeroRect; |
| 267 background_rect.size.width = NSWidth(popup_frame); | 264 background_rect.size.width = NSWidth(popup_frame); |
| 268 background_rect.size.height = NSHeight(popup_frame) - | 265 background_rect.size.height = NSHeight(popup_frame) - |
| 269 NSHeight(top_separator_frame) - NSHeight(bottom_separator_frame); | 266 NSHeight(top_separator_frame) - NSHeight(bottom_separator_frame); |
| 270 background_rect.origin.y = NSMaxY(top_separator_frame); | 267 background_rect.origin.y = NSMaxY(top_separator_frame); |
| 271 [background_view_ setFrame:background_rect]; | 268 [background_view_ setFrame:background_rect]; |
| 272 | 269 |
| 273 // Matrix. | 270 // Calculate the width of the table based on backing out the popup's border |
| 271 // from the width of the field. | |
| 272 const CGFloat tableWidth = NSWidth([field_ bounds]); | |
| 273 DCHECK_GT(tableWidth, 0.0); | |
|
dschuyler
2015/04/24 18:43:08
This is moved here from elsewhere in the code, in
| |
| 274 | |
| 274 NSPoint field_origin_base = | 275 NSPoint field_origin_base = |
| 275 [field_ convertPoint:[field_ bounds].origin toView:nil]; | 276 [field_ convertPoint:[field_ bounds].origin toView:nil]; |
| 276 NSRect matrix_frame = NSZeroRect; | 277 NSRect table_frame = NSZeroRect; |
| 277 matrix_frame.origin.x = field_origin_base.x - NSMinX(anchor_rect_base); | 278 table_frame.origin.x = field_origin_base.x - NSMinX(anchor_rect_base); |
| 278 matrix_frame.origin.y = kPopupPaddingVertical; | 279 table_frame.origin.y = kPopupPaddingVertical; |
| 279 matrix_frame.size.width = [matrix_ cellSize].width; | 280 table_frame.size.width = tableWidth; |
| 280 matrix_frame.size.height = matrixHeight; | 281 table_frame.size.height = tableHeight; |
| 281 [matrix_ setFrame:matrix_frame]; | 282 [table_view_ setFrame:table_frame]; |
| 282 | 283 |
| 283 NSRect current_poup_frame = [popup_ frame]; | 284 NSRect current_poup_frame = [popup_ frame]; |
| 284 target_popup_frame_ = popup_frame; | 285 target_popup_frame_ = popup_frame; |
| 285 | 286 |
| 286 // Animate the frame change if the only change is that the height got smaller. | 287 // Animate the frame change if the only change is that the height got smaller. |
| 287 // Otherwise, resize immediately. | 288 // Otherwise, resize immediately. |
| 288 bool animate = (NSHeight(popup_frame) < NSHeight(current_poup_frame) && | 289 bool animate = (NSHeight(popup_frame) < NSHeight(current_poup_frame) && |
| 289 NSWidth(popup_frame) == NSWidth(current_poup_frame)); | 290 NSWidth(popup_frame) == NSWidth(current_poup_frame)); |
| 290 | 291 |
| 291 base::scoped_nsobject<NSDictionary> savedAnimations; | 292 base::scoped_nsobject<NSDictionary> savedAnimations; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 329 } | 330 } |
| 330 | 331 |
| 331 void OmniboxPopupViewMac::OpenURLForRow(size_t row, | 332 void OmniboxPopupViewMac::OpenURLForRow(size_t row, |
| 332 WindowOpenDisposition disposition) { | 333 WindowOpenDisposition disposition) { |
| 333 size_t start_match = model_->result().ShouldHideTopMatch() ? 1 : 0; | 334 size_t start_match = model_->result().ShouldHideTopMatch() ? 1 : 0; |
| 334 row += start_match; | 335 row += start_match; |
| 335 DCHECK_LT(row, GetResult().size()); | 336 DCHECK_LT(row, GetResult().size()); |
| 336 omnibox_view_->OpenMatch(GetResult().match_at(row), disposition, GURL(), | 337 omnibox_view_->OpenMatch(GetResult().match_at(row), disposition, GURL(), |
| 337 base::string16(), row); | 338 base::string16(), row); |
| 338 } | 339 } |
| OLD | NEW |