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/combobox.h" | 5 #include "ui/views/controls/combobox/combobox.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "ui/accessibility/ax_action_data.h" |
14 #include "ui/accessibility/ax_node_data.h" | 15 #include "ui/accessibility/ax_node_data.h" |
15 #include "ui/base/default_style.h" | 16 #include "ui/base/default_style.h" |
16 #include "ui/base/ime/input_method.h" | 17 #include "ui/base/ime/input_method.h" |
17 #include "ui/base/material_design/material_design_controller.h" | 18 #include "ui/base/material_design/material_design_controller.h" |
18 #include "ui/base/models/combobox_model_observer.h" | 19 #include "ui/base/models/combobox_model_observer.h" |
19 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
20 #include "ui/events/event.h" | 21 #include "ui/events/event.h" |
21 #include "ui/gfx/animation/throb_animation.h" | 22 #include "ui/gfx/animation/throb_animation.h" |
22 #include "ui/gfx/canvas.h" | 23 #include "ui/gfx/canvas.h" |
23 #include "ui/gfx/color_palette.h" | 24 #include "ui/gfx/color_palette.h" |
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 node_data->SetName(accessible_name_); | 760 node_data->SetName(accessible_name_); |
760 node_data->SetValue(model_->GetItemAt(selected_index_)); | 761 node_data->SetValue(model_->GetItemAt(selected_index_)); |
761 if (enabled()) { | 762 if (enabled()) { |
762 node_data->AddIntAttribute(ui::AX_ATTR_DEFAULT_ACTION_VERB, | 763 node_data->AddIntAttribute(ui::AX_ATTR_DEFAULT_ACTION_VERB, |
763 ui::AX_DEFAULT_ACTION_VERB_OPEN); | 764 ui::AX_DEFAULT_ACTION_VERB_OPEN); |
764 } | 765 } |
765 node_data->AddIntAttribute(ui::AX_ATTR_POS_IN_SET, selected_index_); | 766 node_data->AddIntAttribute(ui::AX_ATTR_POS_IN_SET, selected_index_); |
766 node_data->AddIntAttribute(ui::AX_ATTR_SET_SIZE, model_->GetItemCount()); | 767 node_data->AddIntAttribute(ui::AX_ATTR_SET_SIZE, model_->GetItemCount()); |
767 } | 768 } |
768 | 769 |
| 770 bool Combobox::HandleAccessibleAction(const ui::AXActionData& action_data) { |
| 771 // The action handling in View would generate a mouse event and send it to |
| 772 // |this|. However, mouse events for Combobox are handled by |arrow_button_|, |
| 773 // which is hidden from the a11y tree (so can't expose actions). Rather than |
| 774 // forwarding AX_ACTION_DO_DEFAULT to View and then forwarding the mouse event |
| 775 // it generates to |arrow_button_| to have it forward back to |this| (as its |
| 776 // ButtonListener), just handle the action explicitly here and bypass View. |
| 777 if (enabled() && action_data.action == ui::AX_ACTION_DO_DEFAULT) { |
| 778 ShowDropDownMenu(ui::MENU_SOURCE_KEYBOARD); |
| 779 return true; |
| 780 } |
| 781 return View::HandleAccessibleAction(action_data); |
| 782 } |
| 783 |
769 void Combobox::ButtonPressed(Button* sender, const ui::Event& event) { | 784 void Combobox::ButtonPressed(Button* sender, const ui::Event& event) { |
770 if (!enabled()) | 785 if (!enabled()) |
771 return; | 786 return; |
772 | 787 |
773 if (!UseMd()) | 788 if (!UseMd()) |
774 RequestFocus(); | 789 RequestFocus(); |
775 | 790 |
776 if (sender == text_button_) { | 791 if (sender == text_button_) { |
777 OnPerformAction(); | 792 OnPerformAction(); |
778 } else { | 793 } else { |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1014 constexpr int kMdPaddingWidth = 8; | 1029 constexpr int kMdPaddingWidth = 8; |
1015 constexpr int kNormalPaddingWidth = 7; | 1030 constexpr int kNormalPaddingWidth = 7; |
1016 int arrow_pad = UseMd() ? kMdPaddingWidth : kNormalPaddingWidth; | 1031 int arrow_pad = UseMd() ? kMdPaddingWidth : kNormalPaddingWidth; |
1017 int padding = style_ == STYLE_NORMAL | 1032 int padding = style_ == STYLE_NORMAL |
1018 ? arrow_pad * 2 | 1033 ? arrow_pad * 2 |
1019 : kActionLeftPadding + kActionRightPadding; | 1034 : kActionLeftPadding + kActionRightPadding; |
1020 return ArrowSize().width() + padding; | 1035 return ArrowSize().width() + padding; |
1021 } | 1036 } |
1022 | 1037 |
1023 } // namespace views | 1038 } // namespace views |
OLD | NEW |