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

Side by Side Diff: chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.mm

Issue 2916413002: Omnibox UI Experiments: Suggestions Dropdown width experiment on Cocoa (Closed)
Patch Set: merge Created 3 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/feature_list.h"
9 #include "base/mac/mac_util.h" 10 #include "base/mac/mac_util.h"
10 #import "base/mac/sdk_forward_declarations.h" 11 #import "base/mac/sdk_forward_declarations.h"
11 #include "base/stl_util.h" 12 #include "base/stl_util.h"
12 #include "base/strings/sys_string_conversions.h" 13 #include "base/strings/sys_string_conversions.h"
13 #include "chrome/browser/search/search.h" 14 #include "chrome/browser/search/search.h"
14 #include "chrome/browser/ui/cocoa/browser_window_controller.h" 15 #include "chrome/browser/ui/cocoa/browser_window_controller.h"
15 #import "chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.h" 16 #import "chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.h"
16 #import "chrome/browser/ui/cocoa/omnibox/omnibox_popup_separator_view.h" 17 #import "chrome/browser/ui/cocoa/omnibox/omnibox_popup_separator_view.h"
17 #include "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" 18 #include "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h"
18 #include "components/omnibox/browser/autocomplete_match.h" 19 #include "components/omnibox/browser/autocomplete_match.h"
19 #include "components/omnibox/browser/autocomplete_match_type.h" 20 #include "components/omnibox/browser/autocomplete_match_type.h"
20 #include "components/omnibox/browser/omnibox_edit_model.h" 21 #include "components/omnibox/browser/omnibox_edit_model.h"
22 #include "components/omnibox/browser/omnibox_field_trial.h"
21 #include "components/omnibox/browser/omnibox_popup_model.h" 23 #include "components/omnibox/browser/omnibox_popup_model.h"
22 #include "components/toolbar/vector_icons.h" 24 #include "components/toolbar/vector_icons.h"
23 #include "skia/ext/skia_utils_mac.h" 25 #include "skia/ext/skia_utils_mac.h"
24 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSAnimation+Duration.h " 26 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSAnimation+Duration.h "
25 #import "ui/base/cocoa/cocoa_base_utils.h" 27 #import "ui/base/cocoa/cocoa_base_utils.h"
26 #import "ui/base/cocoa/flipped_view.h" 28 #import "ui/base/cocoa/flipped_view.h"
27 #include "ui/base/cocoa/window_size_constants.h" 29 #include "ui/base/cocoa/window_size_constants.h"
28 #include "ui/base/material_design/material_design_controller.h" 30 #include "ui/base/material_design/material_design_controller.h"
29 #include "ui/gfx/color_palette.h" 31 #include "ui/gfx/color_palette.h"
30 #include "ui/gfx/geometry/rect.h" 32 #include "ui/gfx/geometry/rect.h"
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 } 211 }
210 } 212 }
211 213
212 void OmniboxPopupViewMac::PositionPopup(const CGFloat matrixHeight) { 214 void OmniboxPopupViewMac::PositionPopup(const CGFloat matrixHeight) {
213 BrowserWindowController* controller = 215 BrowserWindowController* controller =
214 [BrowserWindowController browserWindowControllerForView:field_]; 216 [BrowserWindowController browserWindowControllerForView:field_];
215 NSRect anchor_rect_base = [controller omniboxPopupAnchorRect]; 217 NSRect anchor_rect_base = [controller omniboxPopupAnchorRect];
216 218
217 // Calculate the popup's position on the screen. 219 // Calculate the popup's position on the screen.
218 NSRect popup_frame = anchor_rect_base; 220 NSRect popup_frame = anchor_rect_base;
221
222 bool match_omnibox_width =
223 base::FeatureList::IsEnabled(omnibox::kUIExperimentNarrowDropdown);
224
225 CGFloat table_width = match_omnibox_width
226 ? NSWidth([field_ bounds])
227 : NSWidth([[[field_ window] contentView] bounds]);
228 DCHECK_GT(table_width, 0.0);
229
230 NSPoint field_origin_base =
231 [field_ convertPoint:[field_ bounds].origin toView:nil];
232
219 // Size to fit the matrix and shift down by the size. 233 // Size to fit the matrix and shift down by the size.
220 popup_frame.size.height = matrixHeight + PopupPaddingVertical() * 2.0; 234 popup_frame.size.height = matrixHeight + PopupPaddingVertical() * 2.0;
221 popup_frame.size.height += [OmniboxPopupTopSeparatorView preferredHeight]; 235 popup_frame.size.height += [OmniboxPopupTopSeparatorView preferredHeight];
222 popup_frame.size.height += [OmniboxPopupBottomSeparatorView preferredHeight]; 236 popup_frame.size.height += [OmniboxPopupBottomSeparatorView preferredHeight];
237 popup_frame.origin.x = match_omnibox_width ? field_origin_base.x : 0;
223 popup_frame.origin.y -= NSHeight(popup_frame); 238 popup_frame.origin.y -= NSHeight(popup_frame);
224 239
240 if (match_omnibox_width)
241 popup_frame.size.width = table_width;
242
225 // Shift to screen coordinates. 243 // Shift to screen coordinates.
226 if ([controller window]) { 244 if ([controller window]) {
227 popup_frame = [[controller window] convertRectToScreen:popup_frame]; 245 popup_frame = [[controller window] convertRectToScreen:popup_frame];
228 } 246 }
229 247
230 // Top separator. 248 // Top separator.
231 NSRect top_separator_frame = NSZeroRect; 249 NSRect top_separator_frame = NSZeroRect;
232 top_separator_frame.size.width = NSWidth(popup_frame); 250 top_separator_frame.size.width = NSWidth(popup_frame);
233 top_separator_frame.size.height = 251 top_separator_frame.size.height =
234 [OmniboxPopupTopSeparatorView preferredHeight]; 252 [OmniboxPopupTopSeparatorView preferredHeight];
235 [top_separator_view_ setFrame:top_separator_frame]; 253 [top_separator_view_ setFrame:top_separator_frame];
236 254
237 // Bottom separator. 255 // Bottom separator.
238 NSRect bottom_separator_frame = NSZeroRect; 256 NSRect bottom_separator_frame = NSZeroRect;
239 bottom_separator_frame.size.width = NSWidth(popup_frame); 257 bottom_separator_frame.size.width = NSWidth(popup_frame);
240 bottom_separator_frame.size.height = 258 bottom_separator_frame.size.height =
241 [OmniboxPopupBottomSeparatorView preferredHeight]; 259 [OmniboxPopupBottomSeparatorView preferredHeight];
242 bottom_separator_frame.origin.y = 260 bottom_separator_frame.origin.y =
243 NSHeight(popup_frame) - NSHeight(bottom_separator_frame); 261 NSHeight(popup_frame) - NSHeight(bottom_separator_frame);
244 [bottom_separator_view_ setFrame:bottom_separator_frame]; 262 [bottom_separator_view_ setFrame:bottom_separator_frame];
245 263
246 // Background view. 264 // Background view.
247 NSRect background_rect = NSZeroRect; 265 NSRect background_rect = NSZeroRect;
248 background_rect.size.width = NSWidth(popup_frame); 266 background_rect.size.width = NSWidth(popup_frame);
249 background_rect.size.height = NSHeight(popup_frame) - 267 background_rect.size.height = NSHeight(popup_frame) -
250 NSHeight(top_separator_frame) - NSHeight(bottom_separator_frame); 268 NSHeight(top_separator_frame) - NSHeight(bottom_separator_frame);
251 background_rect.origin.y = NSMaxY(top_separator_frame); 269 background_rect.origin.y = NSMaxY(top_separator_frame);
252 [background_view_ setFrame:background_rect]; 270 [background_view_ setFrame:background_rect];
253 271
254 // In Material Design, the table is the width of the window. In non-MD,
255 // calculate the width of the table based on backing out the popup's border
256 // from the width of the field.
257 CGFloat table_width = NSWidth([[[field_ window] contentView] bounds]);
258 DCHECK_GT(table_width, 0.0);
259
260 // Matrix. 272 // Matrix.
261 NSPoint field_origin_base =
262 [field_ convertPoint:[field_ bounds].origin toView:nil];
263 NSRect matrix_frame = NSZeroRect; 273 NSRect matrix_frame = NSZeroRect;
264 matrix_frame.origin.x = 0; 274 matrix_frame.origin.x = 0;
265 [matrix_ setContentLeftPadding:field_origin_base.x]; 275 [matrix_ setContentLeftPadding:match_omnibox_width ? 0 : field_origin_base.x];
266 matrix_frame.origin.y = PopupPaddingVertical(); 276 matrix_frame.origin.y = PopupPaddingVertical();
267 matrix_frame.size.width = table_width; 277 matrix_frame.size.width = table_width;
268 matrix_frame.size.height = matrixHeight; 278 matrix_frame.size.height = matrixHeight;
269 [matrix_ setFrame:matrix_frame]; 279 [matrix_ setFrame:matrix_frame];
270 [[[matrix_ tableColumns] objectAtIndex:0] setWidth:table_width]; 280 [[[matrix_ tableColumns] objectAtIndex:0] setWidth:table_width];
271 281
272 // Don't play animation games on first display. 282 // Don't play animation games on first display.
273 target_popup_frame_ = popup_frame; 283 target_popup_frame_ = popup_frame;
274 if (![popup_ parentWindow]) { 284 if (![popup_ parentWindow]) {
275 DCHECK(![popup_ isVisible]); 285 DCHECK(![popup_ isVisible]);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 return NSImageFromImageSkia( 349 return NSImageFromImageSkia(
340 gfx::CreateVectorIcon(vector_icon, kIconSize, icon_color)); 350 gfx::CreateVectorIcon(vector_icon, kIconSize, icon_color));
341 } 351 }
342 352
343 void OmniboxPopupViewMac::OpenURLForRow(size_t row, 353 void OmniboxPopupViewMac::OpenURLForRow(size_t row,
344 WindowOpenDisposition disposition) { 354 WindowOpenDisposition disposition) {
345 DCHECK_LT(row, GetResult().size()); 355 DCHECK_LT(row, GetResult().size());
346 omnibox_view_->OpenMatch(GetResult().match_at(row), disposition, GURL(), 356 omnibox_view_->OpenMatch(GetResult().match_at(row), disposition, GURL(),
347 base::string16(), row); 357 base::string16(), row);
348 } 358 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698