| 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/menu_button.h" | 5 #include "ui/views/controls/button/menu_button.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "ui/accessibility/ax_view_state.h" | 8 #include "ui/accessibility/ax_node_data.h" |
| 9 #include "ui/base/dragdrop/drag_drop_types.h" | 9 #include "ui/base/dragdrop/drag_drop_types.h" |
| 10 #include "ui/base/l10n/l10n_util.h" | 10 #include "ui/base/l10n/l10n_util.h" |
| 11 #include "ui/base/resource/resource_bundle.h" | 11 #include "ui/base/resource/resource_bundle.h" |
| 12 #include "ui/display/screen.h" | 12 #include "ui/display/screen.h" |
| 13 #include "ui/events/event.h" | 13 #include "ui/events/event.h" |
| 14 #include "ui/events/event_constants.h" | 14 #include "ui/events/event_constants.h" |
| 15 #include "ui/events/event_utils.h" | 15 #include "ui/events/event_utils.h" |
| 16 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
| 17 #include "ui/gfx/image/image.h" | 17 #include "ui/gfx/image/image.h" |
| 18 #include "ui/gfx/text_constants.h" | 18 #include "ui/gfx/text_constants.h" |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 return false; | 290 return false; |
| 291 } | 291 } |
| 292 | 292 |
| 293 bool MenuButton::OnKeyReleased(const ui::KeyEvent& event) { | 293 bool MenuButton::OnKeyReleased(const ui::KeyEvent& event) { |
| 294 // Override CustomButton's implementation, which presses the button when | 294 // Override CustomButton's implementation, which presses the button when |
| 295 // you press space and clicks it when you release space. For a MenuButton | 295 // you press space and clicks it when you release space. For a MenuButton |
| 296 // we always activate the menu on key press. | 296 // we always activate the menu on key press. |
| 297 return false; | 297 return false; |
| 298 } | 298 } |
| 299 | 299 |
| 300 void MenuButton::GetAccessibleState(ui::AXViewState* state) { | 300 void MenuButton::GetAccessibleNodeData(ui::AXNodeData* node_data) { |
| 301 CustomButton::GetAccessibleState(state); | 301 CustomButton::GetAccessibleNodeData(node_data); |
| 302 state->role = ui::AX_ROLE_POP_UP_BUTTON; | 302 node_data->role = ui::AX_ROLE_POP_UP_BUTTON; |
| 303 state->default_action = l10n_util::GetStringUTF16(IDS_APP_ACCACTION_PRESS); | 303 node_data->AddStringAttribute( |
| 304 state->AddStateFlag(ui::AX_STATE_HASPOPUP); | 304 ui::AX_ATTR_ACTION, l10n_util::GetStringUTF8(IDS_APP_ACCACTION_PRESS)); |
| 305 node_data->AddStateFlag(ui::AX_STATE_HASPOPUP); |
| 305 } | 306 } |
| 306 | 307 |
| 307 void MenuButton::PaintMenuMarker(gfx::Canvas* canvas) { | 308 void MenuButton::PaintMenuMarker(gfx::Canvas* canvas) { |
| 308 gfx::Insets insets = GetInsets(); | 309 gfx::Insets insets = GetInsets(); |
| 309 | 310 |
| 310 // Using the Views mirroring infrastructure incorrectly flips icon content. | 311 // Using the Views mirroring infrastructure incorrectly flips icon content. |
| 311 // Instead, manually mirror the position of the down arrow. | 312 // Instead, manually mirror the position of the down arrow. |
| 312 gfx::Rect arrow_bounds(width() - insets.right() - | 313 gfx::Rect arrow_bounds(width() - insets.right() - |
| 313 menu_marker_->width() - kMenuMarkerPaddingRight, | 314 menu_marker_->width() - kMenuMarkerPaddingRight, |
| 314 height() / 2 - menu_marker_->height() / 2, | 315 height() / 2 - menu_marker_->height() / 2, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 if (!GetWidget()) { | 406 if (!GetWidget()) { |
| 406 NOTREACHED(); | 407 NOTREACHED(); |
| 407 return 0; | 408 return 0; |
| 408 } | 409 } |
| 409 | 410 |
| 410 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen(); | 411 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen(); |
| 411 return monitor_bounds.right() - 1; | 412 return monitor_bounds.right() - 1; |
| 412 } | 413 } |
| 413 | 414 |
| 414 } // namespace views | 415 } // namespace views |
| OLD | NEW |