Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: ui/views/controls/combobox/combobox.cc

Issue 2944083004: MacViews a11y: Support the "Show menu" action in Textfield and Combobox. (Closed)
Patch Set: base off crrev/2946783003 Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 730 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 // AX_ROLE_COMBO_BOX is for UI elements with a dropdown and an editable text 755 // AX_ROLE_COMBO_BOX is for UI elements with a dropdown and an editable text
755 // field, which views::Combobox does not have. Use AX_ROLE_POP_UP_BUTTON to 756 // field, which views::Combobox does not have. Use AX_ROLE_POP_UP_BUTTON to
756 // match an HTML <select> element. 757 // match an HTML <select> element.
757 node_data->role = ui::AX_ROLE_POP_UP_BUTTON; 758 node_data->role = ui::AX_ROLE_POP_UP_BUTTON;
758 759
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);
765 node_data->AddAction(ui::AX_ACTION_SHOW_CONTEXT_MENU);
764 } 766 }
765 node_data->AddIntAttribute(ui::AX_ATTR_POS_IN_SET, selected_index_); 767 node_data->AddIntAttribute(ui::AX_ATTR_POS_IN_SET, selected_index_);
766 node_data->AddIntAttribute(ui::AX_ATTR_SET_SIZE, model_->GetItemCount()); 768 node_data->AddIntAttribute(ui::AX_ATTR_SET_SIZE, model_->GetItemCount());
767 } 769 }
768 770
771 bool Combobox::HandleAccessibleAction(const ui::AXActionData& action_data) {
772 // The action handling in View would generate a mouse event, but mouse events
773 // for Combobox are handled by |arrow_button_|. Handle the action explicitly.
774 // Also handle AX_SHOW_CONTEXT_MENU so that a "show menu" action is exposed to
775 // native accessibility tools.
776 if (enabled() && (action_data.action == ui::AX_ACTION_DO_DEFAULT ||
777 action_data.action == ui::AX_ACTION_SHOW_CONTEXT_MENU)) {
dmazzoni 2017/06/21 06:09:35 Wait, so the SHOW_CONTEXT_MENU action also drops d
tapted 2017/06/21 06:52:55 Cocoa offers both "press" and "show menu" actions
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698