| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "views/controls/button/button_dropdown.h" | 5 #include "views/controls/button/button_dropdown.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "grit/ui_strings.h" | 10 #include "grit/ui_strings.h" |
| 11 #include "ui/base/accessibility/accessible_view_state.h" | 11 #include "ui/base/accessibility/accessible_view_state.h" |
| 12 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
| 13 #include "ui/base/models/menu_model.h" | 13 #include "ui/base/models/menu_model.h" |
| 14 #include "views/controls/menu/menu_item_view.h" | 14 #include "views/controls/menu/menu_item_view.h" |
| 15 #include "views/controls/menu/menu_model_adapter.h" | 15 #include "views/controls/menu/menu_model_adapter.h" |
| 16 #include "views/controls/menu/menu_runner.h" |
| 16 #include "views/widget/widget.h" | 17 #include "views/widget/widget.h" |
| 17 | 18 |
| 18 namespace views { | 19 namespace views { |
| 19 | 20 |
| 20 // static | 21 // static |
| 21 const char ButtonDropDown::kViewClassName[] = | 22 const char ButtonDropDown::kViewClassName[] = |
| 22 "views/controls/button/ButtonDropDown"; | 23 "views/controls/button/ButtonDropDown"; |
| 23 | 24 |
| 24 // How long to wait before showing the menu | 25 // How long to wait before showing the menu |
| 25 static const int kMenuTimerDelay = 500; | 26 static const int kMenuTimerDelay = 500; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 if (menu_position.x() < left_bound) | 149 if (menu_position.x() < left_bound) |
| 149 menu_position.set_x(left_bound); | 150 menu_position.set_x(left_bound); |
| 150 | 151 |
| 151 // Make the button look depressed while the menu is open. | 152 // Make the button look depressed while the menu is open. |
| 152 SetState(BS_PUSHED); | 153 SetState(BS_PUSHED); |
| 153 | 154 |
| 154 // Create and run menu. Display an empty menu if model is NULL. | 155 // Create and run menu. Display an empty menu if model is NULL. |
| 155 if (model_) { | 156 if (model_) { |
| 156 MenuModelAdapter menu_delegate(model_); | 157 MenuModelAdapter menu_delegate(model_); |
| 157 menu_delegate.set_triggerable_event_flags(triggerable_event_flags()); | 158 menu_delegate.set_triggerable_event_flags(triggerable_event_flags()); |
| 158 MenuItemView menu(&menu_delegate); | 159 MenuRunner runner(menu_delegate.CreateMenu()); |
| 159 menu_delegate.BuildMenu(&menu); | 160 if (runner.RunMenuAt(GetWidget(), NULL, |
| 160 | 161 gfx::Rect(menu_position, gfx::Size(0, 0)), |
| 161 menu.RunMenuAt(GetWidget(), NULL, | 162 MenuItemView::TOPLEFT, |
| 162 gfx::Rect(menu_position, gfx::Size(0, 0)), | 163 MenuRunner::HAS_MNEMONICS) == MenuRunner::MENU_DELETED) |
| 163 views::MenuItemView::TOPLEFT, | 164 return; |
| 164 true); | |
| 165 } else { | 165 } else { |
| 166 MenuDelegate menu_delegate; | 166 MenuDelegate menu_delegate; |
| 167 MenuItemView menu(&menu_delegate); | 167 MenuItemView* menu = new MenuItemView(&menu_delegate); |
| 168 menu.RunMenuAt(GetWidget(), NULL, | 168 MenuRunner runner(menu); |
| 169 gfx::Rect(menu_position, gfx::Size(0, 0)), | 169 if (runner.RunMenuAt(GetWidget(), NULL, |
| 170 views::MenuItemView::TOPLEFT, | 170 gfx::Rect(menu_position, gfx::Size(0, 0)), |
| 171 true); | 171 views::MenuItemView::TOPLEFT, |
| 172 MenuRunner::HAS_MNEMONICS) == MenuRunner::MENU_DELETED) |
| 173 return; |
| 172 } | 174 } |
| 173 | 175 |
| 174 // Need to explicitly clear mouse handler so that events get sent | 176 // Need to explicitly clear mouse handler so that events get sent |
| 175 // properly after the menu finishes running. If we don't do this, then | 177 // properly after the menu finishes running. If we don't do this, then |
| 176 // the first click to other parts of the UI is eaten. | 178 // the first click to other parts of the UI is eaten. |
| 177 SetMouseHandler(NULL); | 179 SetMouseHandler(NULL); |
| 178 | 180 |
| 179 // Set the state back to normal after the drop down menu is closed. | 181 // Set the state back to normal after the drop down menu is closed. |
| 180 if (state_ != BS_DISABLED) | 182 if (state_ != BS_DISABLED) |
| 181 SetState(BS_NORMAL); | 183 SetState(BS_NORMAL); |
| 182 } | 184 } |
| 183 | 185 |
| 184 //////////////////////////////////////////////////////////////////////////////// | 186 //////////////////////////////////////////////////////////////////////////////// |
| 185 // | 187 // |
| 186 // ButtonDropDown - Accessibility | 188 // ButtonDropDown - Accessibility |
| 187 // | 189 // |
| 188 //////////////////////////////////////////////////////////////////////////////// | 190 //////////////////////////////////////////////////////////////////////////////// |
| 189 | 191 |
| 190 } // namespace views | 192 } // namespace views |
| OLD | NEW |