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

Side by Side Diff: ui/views/controls/combobox/native_combobox_views.cc

Issue 10829176: Update drop down menu look & feel (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: moved offset code Created 8 years, 4 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 (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 "ui/views/controls/combobox/native_combobox_views.h" 5 #include "ui/views/controls/combobox/native_combobox_views.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "grit/ui_resources.h" 9 #include "grit/ui_resources.h"
10 #include "ui/base/keycodes/keyboard_codes.h" 10 #include "ui/base/keycodes/keyboard_codes.h"
(...skipping 13 matching lines...) Expand all
24 #include "ui/views/widget/widget.h" 24 #include "ui/views/widget/widget.h"
25 25
26 namespace { 26 namespace {
27 27
28 // Define the size of the insets. 28 // Define the size of the insets.
29 const int kTopInsetSize = 4; 29 const int kTopInsetSize = 4;
30 const int kLeftInsetSize = 4; 30 const int kLeftInsetSize = 4;
31 const int kBottomInsetSize = 4; 31 const int kBottomInsetSize = 4;
32 const int kRightInsetSize = 4; 32 const int kRightInsetSize = 4;
33 33
34 // Menu border widths
35 const int kMenuBorderWidthLeft = 1;
36 const int kMenuBorderWidthTop = 2;
37 const int kMenuBorderWidthRight = 1;
38 const int kMenuBorderWidthBottom = 2;
39
34 // Limit how small a combobox can be. 40 // Limit how small a combobox can be.
35 const int kMinComboboxWidth = 148; 41 const int kMinComboboxWidth = 148;
36 42
37 // Size of the combobox arrow margins 43 // Size of the combobox arrow margins
38 const int kDisclosureArrowLeftPadding = 7; 44 const int kDisclosureArrowLeftPadding = 7;
39 const int kDisclosureArrowRightPadding = 7; 45 const int kDisclosureArrowRightPadding = 7;
40 46
41 // Color settings for text and border. 47 // Color settings for text and border.
42 // These are tentative, and should be derived from theme, system 48 // These are tentative, and should be derived from theme, system
43 // settings and current settings. 49 // settings and current settings.
44 const SkColor kTextColor = SK_ColorBLACK; 50 const SkColor kTextColor = SK_ColorBLACK;
45 51
46 // Define the id of the first item in the menu (since it needs to be > 0) 52 // Define the id of the first item in the menu (since it needs to be > 0)
47 const int kFirstMenuItemId = 1000; 53 const int kFirstMenuItemId = 1000;
48 54
49 } // namespace 55 } // namespace
50 56
51 namespace views { 57 namespace views {
52 58
53 const char NativeComboboxViews::kViewClassName[] = 59 const char NativeComboboxViews::kViewClassName[] =
54 "views/NativeComboboxViews"; 60 "views/NativeComboboxViews";
55 61
56 NativeComboboxViews::NativeComboboxViews(Combobox* combobox) 62 NativeComboboxViews::NativeComboboxViews(Combobox* combobox)
57 : combobox_(combobox), 63 : combobox_(combobox),
58 text_border_(new FocusableBorder()), 64 text_border_(new FocusableBorder()),
59 disclosure_arrow_(ui::ResourceBundle::GetSharedInstance().GetImageNamed( 65 disclosure_arrow_(ui::ResourceBundle::GetSharedInstance().GetImageNamed(
60 IDR_DISCLOSURE_ARROW).ToImageSkia()), 66 IDR_MENU_DROPARROW).ToImageSkia()),
61 dropdown_open_(false), 67 dropdown_open_(false),
62 selected_index_(-1), 68 selected_index_(-1),
63 content_width_(0), 69 content_width_(0),
64 content_height_(0) { 70 content_height_(0) {
65 set_border(text_border_); 71 set_border(text_border_);
66 } 72 }
67 73
68 NativeComboboxViews::~NativeComboboxViews() { 74 NativeComboboxViews::~NativeComboboxViews() {
69 } 75 }
70 76
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 } 323 }
318 324
319 void NativeComboboxViews::ShowDropDownMenu() { 325 void NativeComboboxViews::ShowDropDownMenu() {
320 326
321 if (!dropdown_list_menu_runner_.get()) 327 if (!dropdown_list_menu_runner_.get())
322 UpdateFromModel(); 328 UpdateFromModel();
323 329
324 // Extend the menu to the width of the combobox. 330 // Extend the menu to the width of the combobox.
325 MenuItemView* menu = dropdown_list_menu_runner_->GetMenu(); 331 MenuItemView* menu = dropdown_list_menu_runner_->GetMenu();
326 SubmenuView* submenu = menu->CreateSubmenu(); 332 SubmenuView* submenu = menu->CreateSubmenu();
327 submenu->set_minimum_preferred_width(size().width()); 333 submenu->set_minimum_preferred_width(size().width() -
328 334 (kMenuBorderWidthLeft + kMenuBorderWidthRight));
329 #if defined(USE_AURA)
330 // Aura style is to have the menu over the bounds. Below bounds is default.
331 menu->set_menu_position(views::MenuItemView::POSITION_OVER_BOUNDS);
332 #endif
333 335
334 gfx::Rect lb = GetLocalBounds(); 336 gfx::Rect lb = GetLocalBounds();
335 gfx::Point menu_position(lb.origin()); 337 gfx::Point menu_position(lb.origin());
338
339 // Inset the menu's requested position so the border of the menu lines up
340 // with the border of the combobox.
341 menu_position.set_x(menu_position.x() + kMenuBorderWidthLeft);
342 menu_position.set_y(menu_position.y() + kMenuBorderWidthTop);
343 lb.set_width(lb.width() - (kMenuBorderWidthLeft + kMenuBorderWidthRight));
344
336 View::ConvertPointToScreen(this, &menu_position); 345 View::ConvertPointToScreen(this, &menu_position);
337 if (menu_position.x() < 0) 346 if (menu_position.x() < 0)
338 menu_position.set_x(0); 347 menu_position.set_x(0);
339 348
340 gfx::Rect bounds(menu_position, lb.size()); 349 gfx::Rect bounds(menu_position, lb.size());
341 350
342 dropdown_open_ = true; 351 dropdown_open_ = true;
343 if (dropdown_list_menu_runner_->RunMenuAt( 352 if (dropdown_list_menu_runner_->RunMenuAt(
344 GetWidget(), NULL, bounds, MenuItemView::TOPLEFT, 353 GetWidget(), NULL, bounds, MenuItemView::TOPLEFT,
345 MenuRunner::HAS_MNEMONICS) == MenuRunner::MENU_DELETED) 354 MenuRunner::HAS_MNEMONICS) == MenuRunner::MENU_DELETED)
(...skipping 11 matching lines...) Expand all
357 366
358 #if defined(USE_AURA) 367 #if defined(USE_AURA)
359 // static 368 // static
360 NativeComboboxWrapper* NativeComboboxWrapper::CreateWrapper( 369 NativeComboboxWrapper* NativeComboboxWrapper::CreateWrapper(
361 Combobox* combobox) { 370 Combobox* combobox) {
362 return new NativeComboboxViews(combobox); 371 return new NativeComboboxViews(combobox);
363 } 372 }
364 #endif 373 #endif
365 374
366 } // namespace views 375 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698