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/menu/menu_item_view.h" | 5 #include "views/controls/menu/menu_item_view.h" |
6 | 6 |
7 #include "base/i18n/case_conversion.h" | 7 #include "base/i18n/case_conversion.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.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" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 const MenuDelegate* delegate = GetDelegate(); | 132 const MenuDelegate* delegate = GetDelegate(); |
133 CHECK(delegate); | 133 CHECK(delegate); |
134 gfx::Point location(p); | 134 gfx::Point location(p); |
135 ConvertPointToScreen(this, &location); | 135 ConvertPointToScreen(this, &location); |
136 *tooltip = delegate->GetTooltipText(command_, location); | 136 *tooltip = delegate->GetTooltipText(command_, location); |
137 return !tooltip->empty(); | 137 return !tooltip->empty(); |
138 } | 138 } |
139 | 139 |
140 void MenuItemView::GetAccessibleState(ui::AccessibleViewState* state) { | 140 void MenuItemView::GetAccessibleState(ui::AccessibleViewState* state) { |
141 state->role = ui::AccessibilityTypes::ROLE_MENUITEM; | 141 state->role = ui::AccessibilityTypes::ROLE_MENUITEM; |
142 state->name = accessible_name_; | 142 |
143 string16 item_text; | |
dmazzoni
2011/11/09 14:43:20
If we do this, add a comment like "One case to dea
| |
144 if (child_count() == 1 && title_.empty()) { | |
sky
2011/11/09 15:11:37
This seems weird. Why do we want the accessible ti
dmazzoni
2011/11/09 15:50:21
The motivating example is the status bar menus on
hashimoto
2011/11/10 05:22:51
I don't know examples other than ChromeOS status a
| |
145 View* child = child_at(0); | |
146 ui::AccessibleViewState state; | |
147 child->GetAccessibleState(&state); | |
148 item_text = state.name; | |
149 } else { | |
150 item_text = title_; | |
151 } | |
152 state->name = GetAccessibleNameForMenuItem(item_text, GetAcceleratorText()); | |
153 | |
143 switch (GetType()) { | 154 switch (GetType()) { |
144 case SUBMENU: | 155 case SUBMENU: |
145 state->state |= ui::AccessibilityTypes::STATE_HASPOPUP; | 156 state->state |= ui::AccessibilityTypes::STATE_HASPOPUP; |
146 break; | 157 break; |
147 case CHECKBOX: | 158 case CHECKBOX: |
148 case RADIO: | 159 case RADIO: |
149 state->state |= GetDelegate()->IsItemChecked(GetCommand()) ? | 160 state->state |= GetDelegate()->IsItemChecked(GetCommand()) ? |
150 ui::AccessibilityTypes::STATE_CHECKED : 0; | 161 ui::AccessibilityTypes::STATE_CHECKED : 0; |
151 break; | 162 break; |
152 case NORMAL: | 163 case NORMAL: |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
323 bool MenuItemView::HasSubmenu() const { | 334 bool MenuItemView::HasSubmenu() const { |
324 return (submenu_ != NULL); | 335 return (submenu_ != NULL); |
325 } | 336 } |
326 | 337 |
327 SubmenuView* MenuItemView::GetSubmenu() const { | 338 SubmenuView* MenuItemView::GetSubmenu() const { |
328 return submenu_; | 339 return submenu_; |
329 } | 340 } |
330 | 341 |
331 void MenuItemView::SetTitle(const string16& title) { | 342 void MenuItemView::SetTitle(const string16& title) { |
332 title_ = title; | 343 title_ = title; |
333 accessible_name_ = GetAccessibleNameForMenuItem(title_, GetAcceleratorText()); | |
334 pref_size_.SetSize(0, 0); // Triggers preferred size recalculation. | 344 pref_size_.SetSize(0, 0); // Triggers preferred size recalculation. |
335 } | 345 } |
336 | 346 |
337 void MenuItemView::SetSelected(bool selected) { | 347 void MenuItemView::SetSelected(bool selected) { |
338 selected_ = selected; | 348 selected_ = selected; |
339 SchedulePaint(); | 349 SchedulePaint(); |
340 } | 350 } |
341 | 351 |
342 void MenuItemView::SetTooltip(const string16& tooltip, int item_id) { | 352 void MenuItemView::SetTooltip(const string16& tooltip, int item_id) { |
343 MenuItemView* item = GetMenuItemByID(item_id); | 353 MenuItemView* item = GetMenuItemByID(item_id); |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
761 if(!MenuConfig::instance().show_accelerators) | 771 if(!MenuConfig::instance().show_accelerators) |
762 return string16(); | 772 return string16(); |
763 | 773 |
764 Accelerator accelerator; | 774 Accelerator accelerator; |
765 return (GetDelegate() && | 775 return (GetDelegate() && |
766 GetDelegate()->GetAccelerator(GetCommand(), &accelerator)) ? | 776 GetDelegate()->GetAccelerator(GetCommand(), &accelerator)) ? |
767 accelerator.GetShortcutText() : string16(); | 777 accelerator.GetShortcutText() : string16(); |
768 } | 778 } |
769 | 779 |
770 } // namespace views | 780 } // namespace views |
OLD | NEW |