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 "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" |
11 #include "ui/base/models/combobox_model.h" | 11 #include "ui/base/models/combobox_model.h" |
12 #include "ui/base/resource/resource_bundle.h" | 12 #include "ui/base/resource/resource_bundle.h" |
13 #include "ui/gfx/canvas.h" | 13 #include "ui/gfx/canvas.h" |
14 #include "ui/gfx/font.h" | 14 #include "ui/gfx/font.h" |
15 #include "ui/gfx/image/image.h" | 15 #include "ui/gfx/image/image.h" |
16 #include "ui/gfx/path.h" | 16 #include "ui/gfx/path.h" |
17 #include "ui/views/background.h" | 17 #include "ui/views/background.h" |
18 #include "ui/views/border.h" | 18 #include "ui/views/border.h" |
19 #include "ui/views/controls/combobox/combobox.h" | 19 #include "ui/views/controls/combobox/combobox.h" |
20 #include "ui/views/controls/focusable_border.h" | 20 #include "ui/views/controls/focusable_border.h" |
21 #include "ui/views/controls/menu/menu_config.h" | |
21 #include "ui/views/controls/menu/menu_runner.h" | 22 #include "ui/views/controls/menu/menu_runner.h" |
22 #include "ui/views/controls/menu/submenu_view.h" | 23 #include "ui/views/controls/menu/submenu_view.h" |
23 #include "ui/views/widget/root_view.h" | 24 #include "ui/views/widget/root_view.h" |
24 #include "ui/views/widget/widget.h" | 25 #include "ui/views/widget/widget.h" |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
28 // Define the size of the insets. | 29 // Define the size of the insets. |
29 const int kTopInsetSize = 4; | 30 const int kTopInsetSize = 4; |
30 const int kLeftInsetSize = 4; | 31 const int kLeftInsetSize = 4; |
(...skipping 19 matching lines...) Expand all Loading... | |
50 | 51 |
51 namespace views { | 52 namespace views { |
52 | 53 |
53 const char NativeComboboxViews::kViewClassName[] = | 54 const char NativeComboboxViews::kViewClassName[] = |
54 "views/NativeComboboxViews"; | 55 "views/NativeComboboxViews"; |
55 | 56 |
56 NativeComboboxViews::NativeComboboxViews(Combobox* combobox) | 57 NativeComboboxViews::NativeComboboxViews(Combobox* combobox) |
57 : combobox_(combobox), | 58 : combobox_(combobox), |
58 text_border_(new FocusableBorder()), | 59 text_border_(new FocusableBorder()), |
59 disclosure_arrow_(ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 60 disclosure_arrow_(ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
60 IDR_DISCLOSURE_ARROW).ToImageSkia()), | 61 IDR_MENU_DROPARROW).ToImageSkia()), |
61 dropdown_open_(false), | 62 dropdown_open_(false), |
62 selected_index_(-1), | 63 selected_index_(-1), |
63 content_width_(0), | 64 content_width_(0), |
64 content_height_(0) { | 65 content_height_(0) { |
65 set_border(text_border_); | 66 set_border(text_border_); |
66 } | 67 } |
67 | 68 |
68 NativeComboboxViews::~NativeComboboxViews() { | 69 NativeComboboxViews::~NativeComboboxViews() { |
69 } | 70 } |
70 | 71 |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
319 void NativeComboboxViews::ShowDropDownMenu() { | 320 void NativeComboboxViews::ShowDropDownMenu() { |
320 | 321 |
321 if (!dropdown_list_menu_runner_.get()) | 322 if (!dropdown_list_menu_runner_.get()) |
322 UpdateFromModel(); | 323 UpdateFromModel(); |
323 | 324 |
324 // Extend the menu to the width of the combobox. | 325 // Extend the menu to the width of the combobox. |
325 MenuItemView* menu = dropdown_list_menu_runner_->GetMenu(); | 326 MenuItemView* menu = dropdown_list_menu_runner_->GetMenu(); |
326 SubmenuView* submenu = menu->CreateSubmenu(); | 327 SubmenuView* submenu = menu->CreateSubmenu(); |
327 submenu->set_minimum_preferred_width(size().width()); | 328 submenu->set_minimum_preferred_width(size().width()); |
328 | 329 |
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 | |
334 gfx::Rect lb = GetLocalBounds(); | 330 gfx::Rect lb = GetLocalBounds(); |
335 gfx::Point menu_position(lb.origin()); | 331 gfx::Point menu_position(lb.origin()); |
332 | |
333 // Inset the menu's requested position so the border of the menu lines up | |
334 // with the border of the combobox. | |
335 menu_position.set_x(menu_position.x() + | |
336 MenuConfig::instance().menu_border_width_left); | |
sky
2012/08/07 20:50:01
Now that this code is entirely here it doesn't mak
Harry McCleave
2012/08/07 22:08:08
Done.
| |
337 menu_position.set_y(menu_position.y() + | |
338 MenuConfig::instance().menu_border_width_top); | |
339 lb.set_width(lb.width() - (MenuConfig::instance().menu_border_width_left + | |
340 MenuConfig::instance().menu_border_width_right)); | |
341 | |
336 View::ConvertPointToScreen(this, &menu_position); | 342 View::ConvertPointToScreen(this, &menu_position); |
337 if (menu_position.x() < 0) | 343 if (menu_position.x() < 0) |
338 menu_position.set_x(0); | 344 menu_position.set_x(0); |
339 | 345 |
340 gfx::Rect bounds(menu_position, lb.size()); | 346 gfx::Rect bounds(menu_position, lb.size()); |
341 | 347 |
342 dropdown_open_ = true; | 348 dropdown_open_ = true; |
343 if (dropdown_list_menu_runner_->RunMenuAt( | 349 if (dropdown_list_menu_runner_->RunMenuAt( |
344 GetWidget(), NULL, bounds, MenuItemView::TOPLEFT, | 350 GetWidget(), NULL, bounds, MenuItemView::TOPLEFT, |
345 MenuRunner::HAS_MNEMONICS) == MenuRunner::MENU_DELETED) | 351 MenuRunner::HAS_MNEMONICS) == MenuRunner::MENU_DELETED) |
(...skipping 11 matching lines...) Expand all Loading... | |
357 | 363 |
358 #if defined(USE_AURA) | 364 #if defined(USE_AURA) |
359 // static | 365 // static |
360 NativeComboboxWrapper* NativeComboboxWrapper::CreateWrapper( | 366 NativeComboboxWrapper* NativeComboboxWrapper::CreateWrapper( |
361 Combobox* combobox) { | 367 Combobox* combobox) { |
362 return new NativeComboboxViews(combobox); | 368 return new NativeComboboxViews(combobox); |
363 } | 369 } |
364 #endif | 370 #endif |
365 | 371 |
366 } // namespace views | 372 } // namespace views |
OLD | NEW |