OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/status/accessibility_menu_button.h" |
| 6 |
| 7 #include "chrome/browser/browser_process.h" |
| 8 #include "chrome/browser/chromeos/accessibility_util.h" |
| 9 #include "chrome/browser/prefs/pref_service.h" |
| 10 #include "chrome/common/chrome_notification_types.h" |
| 11 #include "chrome/common/pref_names.h" |
| 12 #include "grit/generated_resources.h" |
| 13 #include "grit/theme_resources.h" |
| 14 #include "ui/base/l10n/l10n_util.h" |
| 15 #include "ui/base/resource/resource_bundle.h" |
| 16 #include "views/widget/widget.h" |
| 17 #include "views/controls/menu/menu_runner.h" |
| 18 #include "views/controls/menu/menu_item_view.h" |
| 19 |
| 20 namespace { |
| 21 |
| 22 enum MenuItemID { |
| 23 MENU_ITEM_DISABLE_SPOKEN_FEEDBACK, |
| 24 }; |
| 25 |
| 26 } |
| 27 |
| 28 namespace chromeos { |
| 29 |
| 30 //////////////////////////////////////////////////////////////////////////////// |
| 31 // AccessibilityMenuButton |
| 32 |
| 33 AccessibilityMenuButton::AccessibilityMenuButton(StatusAreaHost* host) |
| 34 : StatusAreaButton(host, this) { |
| 35 accessibility_enabled_.Init(prefs::kAccessibilityEnabled, |
| 36 g_browser_process->local_state(), this); |
| 37 SetIcon(*ResourceBundle::GetSharedInstance().GetBitmapNamed( |
| 38 IDR_STATUSBAR_ACCESSIBILITY)); |
| 39 Update(); |
| 40 } |
| 41 |
| 42 AccessibilityMenuButton::~AccessibilityMenuButton() { |
| 43 } |
| 44 |
| 45 //////////////////////////////////////////////////////////////////////////////// |
| 46 // views::ViewMenuDelegate implementation: |
| 47 |
| 48 void AccessibilityMenuButton::RunMenu(views::View* source, |
| 49 const gfx::Point& pt) { |
| 50 PrepareMenu(); |
| 51 |
| 52 gfx::Point screen_location; |
| 53 views::View::ConvertPointToScreen(source, &screen_location); |
| 54 gfx::Rect bounds(screen_location, source->size()); |
| 55 CHECK(menu_runner_->RunMenuAt(source->GetWidget()->GetTopLevelWidget(), |
| 56 this, bounds, views::MenuItemView::TOPRIGHT, |
| 57 0) == |
| 58 views::MenuRunner::NORMAL_EXIT); |
| 59 } |
| 60 |
| 61 //////////////////////////////////////////////////////////////////////////////// |
| 62 // views::MenuDelegate implementation |
| 63 |
| 64 void AccessibilityMenuButton::ExecuteCommand(int id) { |
| 65 switch (id) { |
| 66 case MENU_ITEM_DISABLE_SPOKEN_FEEDBACK: |
| 67 accessibility::EnableAccessibility(false, NULL); |
| 68 break; |
| 69 default: |
| 70 NOTREACHED(); |
| 71 } |
| 72 } |
| 73 |
| 74 //////////////////////////////////////////////////////////////////////////////// |
| 75 // NotificationObserver implementation |
| 76 |
| 77 void AccessibilityMenuButton::Observe(int type, |
| 78 const NotificationSource& source, |
| 79 const NotificationDetails& details) { |
| 80 if (type == chrome::NOTIFICATION_PREF_CHANGED) |
| 81 Update(); |
| 82 } |
| 83 |
| 84 |
| 85 void AccessibilityMenuButton::Update() { |
| 86 // Update tooltip and accessibile name. |
| 87 string16 message = |
| 88 l10n_util::GetStringUTF16(IDS_STATUSBAR_ACCESSIBILITY_ENABLED); |
| 89 SetTooltipText(UTF16ToWide(message)); |
| 90 SetAccessibleName(message); |
| 91 // Update visibility. |
| 92 SetVisible(accessibility_enabled_.GetValue()); |
| 93 } |
| 94 |
| 95 void AccessibilityMenuButton::PrepareMenu() { |
| 96 views::MenuItemView* menu = new views::MenuItemView(this); |
| 97 if (accessibility_enabled_.GetValue()) |
| 98 menu->AppendMenuItemWithLabel(MENU_ITEM_DISABLE_SPOKEN_FEEDBACK, |
| 99 UTF16ToWide(l10n_util::GetStringUTF16( |
| 100 IDS_STATUSBAR_DISABLE_SPOKEN_FEEDBACK))); |
| 101 // |menu_runner_| takes the ownership of |menu| |
| 102 menu_runner_.reset(new views::MenuRunner(menu)); |
| 103 } |
| 104 |
| 105 } // namespace chromeos |
OLD | NEW |