| 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/button/button_dropdown.h" | 5 #include "ui/views/controls/button/button_dropdown.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 } | 125 } |
| 126 | 126 |
| 127 void ButtonDropDown::GetAccessibleState(ui::AccessibleViewState* state) { | 127 void ButtonDropDown::GetAccessibleState(ui::AccessibleViewState* state) { |
| 128 CustomButton::GetAccessibleState(state); | 128 CustomButton::GetAccessibleState(state); |
| 129 state->role = ui::AccessibilityTypes::ROLE_BUTTONDROPDOWN; | 129 state->role = ui::AccessibilityTypes::ROLE_BUTTONDROPDOWN; |
| 130 state->default_action = l10n_util::GetStringUTF16(IDS_APP_ACCACTION_PRESS); | 130 state->default_action = l10n_util::GetStringUTF16(IDS_APP_ACCACTION_PRESS); |
| 131 state->state = ui::AccessibilityTypes::STATE_HASPOPUP; | 131 state->state = ui::AccessibilityTypes::STATE_HASPOPUP; |
| 132 } | 132 } |
| 133 | 133 |
| 134 void ButtonDropDown::ShowContextMenuForView(View* source, | 134 void ButtonDropDown::ShowContextMenuForView(View* source, |
| 135 const gfx::Point& point) { | 135 const gfx::Point& point, |
| 136 ui::MenuSourceType source_type) { |
| 136 if (!enabled()) | 137 if (!enabled()) |
| 137 return; | 138 return; |
| 138 | 139 |
| 139 show_menu_factory_.InvalidateWeakPtrs(); | 140 show_menu_factory_.InvalidateWeakPtrs(); |
| 140 ShowDropDownMenu(); | 141 ShowDropDownMenu(); |
| 141 } | 142 } |
| 142 | 143 |
| 143 bool ButtonDropDown::ShouldEnterPushedState(const ui::Event& event) { | 144 bool ButtonDropDown::ShouldEnterPushedState(const ui::Event& event) { |
| 144 // Enter PUSHED state on press with Left or Right mouse button or on taps. | 145 // Enter PUSHED state on press with Left or Right mouse button or on taps. |
| 145 // Remain in this state while the context menu is open. | 146 // Remain in this state while the context menu is open. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 185 |
| 185 // Create and run menu. Display an empty menu if model is NULL. | 186 // Create and run menu. Display an empty menu if model is NULL. |
| 186 if (model_.get()) { | 187 if (model_.get()) { |
| 187 MenuModelAdapter menu_delegate(model_.get()); | 188 MenuModelAdapter menu_delegate(model_.get()); |
| 188 menu_delegate.set_triggerable_event_flags(triggerable_event_flags()); | 189 menu_delegate.set_triggerable_event_flags(triggerable_event_flags()); |
| 189 menu_runner_.reset(new MenuRunner(menu_delegate.CreateMenu())); | 190 menu_runner_.reset(new MenuRunner(menu_delegate.CreateMenu())); |
| 190 MenuRunner::RunResult result = | 191 MenuRunner::RunResult result = |
| 191 menu_runner_->RunMenuAt(GetWidget(), NULL, | 192 menu_runner_->RunMenuAt(GetWidget(), NULL, |
| 192 gfx::Rect(menu_position, gfx::Size(0, 0)), | 193 gfx::Rect(menu_position, gfx::Size(0, 0)), |
| 193 MenuItemView::TOPLEFT, | 194 MenuItemView::TOPLEFT, |
| 195 ui::MENU_SOURCE_NONE, |
| 194 MenuRunner::HAS_MNEMONICS); | 196 MenuRunner::HAS_MNEMONICS); |
| 195 if (result == MenuRunner::MENU_DELETED) | 197 if (result == MenuRunner::MENU_DELETED) |
| 196 return; | 198 return; |
| 197 } else { | 199 } else { |
| 198 MenuDelegate menu_delegate; | 200 MenuDelegate menu_delegate; |
| 199 MenuItemView* menu = new MenuItemView(&menu_delegate); | 201 MenuItemView* menu = new MenuItemView(&menu_delegate); |
| 200 menu_runner_.reset(new MenuRunner(menu)); | 202 menu_runner_.reset(new MenuRunner(menu)); |
| 201 MenuRunner::RunResult result = | 203 MenuRunner::RunResult result = |
| 202 menu_runner_->RunMenuAt(GetWidget(), NULL, | 204 menu_runner_->RunMenuAt(GetWidget(), NULL, |
| 203 gfx::Rect(menu_position, gfx::Size(0, 0)), | 205 gfx::Rect(menu_position, gfx::Size(0, 0)), |
| 204 MenuItemView::TOPLEFT, | 206 MenuItemView::TOPLEFT, |
| 207 ui::MENU_SOURCE_NONE, |
| 205 MenuRunner::HAS_MNEMONICS); | 208 MenuRunner::HAS_MNEMONICS); |
| 206 if (result == MenuRunner::MENU_DELETED) | 209 if (result == MenuRunner::MENU_DELETED) |
| 207 return; | 210 return; |
| 208 } | 211 } |
| 209 | 212 |
| 210 menu_showing_ = false; | 213 menu_showing_ = false; |
| 211 | 214 |
| 212 // Need to explicitly clear mouse handler so that events get sent | 215 // Need to explicitly clear mouse handler so that events get sent |
| 213 // properly after the menu finishes running. If we don't do this, then | 216 // properly after the menu finishes running. If we don't do this, then |
| 214 // the first click to other parts of the UI is eaten. | 217 // the first click to other parts of the UI is eaten. |
| 215 SetMouseHandler(NULL); | 218 SetMouseHandler(NULL); |
| 216 | 219 |
| 217 // Set the state back to normal after the drop down menu is closed. | 220 // Set the state back to normal after the drop down menu is closed. |
| 218 if (state_ != STATE_DISABLED) | 221 if (state_ != STATE_DISABLED) |
| 219 SetState(STATE_NORMAL); | 222 SetState(STATE_NORMAL); |
| 220 } | 223 } |
| 221 | 224 |
| 222 //////////////////////////////////////////////////////////////////////////////// | 225 //////////////////////////////////////////////////////////////////////////////// |
| 223 // | 226 // |
| 224 // ButtonDropDown - Accessibility | 227 // ButtonDropDown - Accessibility |
| 225 // | 228 // |
| 226 //////////////////////////////////////////////////////////////////////////////// | 229 //////////////////////////////////////////////////////////////////////////////// |
| 227 | 230 |
| 228 } // namespace views | 231 } // namespace views |
| OLD | NEW |