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

Side by Side Diff: chrome/browser/chromeos/status/accessibility_menu_button.cc

Issue 10056001: chromeos: Remove old status-area related code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 8 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/status/accessibility_menu_button.h"
6
7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/chromeos/accessibility/accessibility_util.h"
10 #include "chrome/browser/chromeos/status/status_area_bubble.h"
11 #include "chrome/browser/chromeos/status/status_area_view_chromeos.h"
12 #include "chrome/browser/chromeos/view_ids.h"
13 #include "chrome/browser/prefs/pref_service.h"
14 #include "chrome/common/chrome_notification_types.h"
15 #include "chrome/common/pref_names.h"
16 #include "content/public/browser/notification_details.h"
17 #include "grit/generated_resources.h"
18 #include "grit/theme_resources.h"
19 #include "ui/base/l10n/l10n_util.h"
20 #include "ui/base/resource/resource_bundle.h"
21 #include "ui/gfx/image/image.h"
22 #include "ui/views/controls/image_view.h"
23 #include "ui/views/controls/menu/menu_item_view.h"
24 #include "ui/views/controls/menu/menu_runner.h"
25 #include "ui/views/widget/widget.h"
26
27 namespace {
28
29 enum MenuItemID {
30 MENU_ITEM_DISABLE_SPOKEN_FEEDBACK,
31 };
32
33 } // namespace
34
35 namespace chromeos {
36
37 ////////////////////////////////////////////////////////////////////////////////
38 // AccessibilityMenuButton
39
40 AccessibilityMenuButton::AccessibilityMenuButton(
41 StatusAreaButton::Delegate* delegate)
42 : StatusAreaButton(delegate, this) {
43 set_id(VIEW_ID_STATUS_BUTTON_ACCESSIBILITY);
44 accessibility_enabled_.Init(prefs::kSpokenFeedbackEnabled,
45 g_browser_process->local_state(), this);
46 SetIcon(*ResourceBundle::GetSharedInstance().GetBitmapNamed(
47 IDR_STATUSBAR_ACCESSIBILITY));
48 Update();
49 }
50
51 AccessibilityMenuButton::~AccessibilityMenuButton() {
52 }
53
54 ////////////////////////////////////////////////////////////////////////////////
55 // views::MenuButtonListener implementation:
56
57 void AccessibilityMenuButton::OnMenuButtonClicked(views::View* source,
58 const gfx::Point& point) {
59 PrepareMenu();
60
61 gfx::Point screen_location;
62 views::View::ConvertPointToScreen(source, &screen_location);
63 gfx::Rect bounds(screen_location, source->size());
64 CHECK(menu_runner_->RunMenuAt(source->GetWidget()->GetTopLevelWidget(),
65 this, bounds, views::MenuItemView::TOPRIGHT,
66 0) == views::MenuRunner::NORMAL_EXIT);
67 }
68
69 ////////////////////////////////////////////////////////////////////////////////
70 // views::MenuDelegate implementation
71
72 void AccessibilityMenuButton::ExecuteCommand(int id) {
73 switch (id) {
74 case MENU_ITEM_DISABLE_SPOKEN_FEEDBACK:
75 accessibility::EnableSpokenFeedback(false, NULL);
76 break;
77 default:
78 NOTREACHED();
79 }
80 }
81
82 ////////////////////////////////////////////////////////////////////////////////
83 // content::NotificationObserver implementation
84
85 void AccessibilityMenuButton::Observe(
86 int type,
87 const content::NotificationSource& source,
88 const content::NotificationDetails& details) {
89 if (type == chrome::NOTIFICATION_PREF_CHANGED) {
90 Update();
91 const std::string path =
92 *static_cast<content::Details<std::string> >(details).ptr();
93 // Show a bubble when accessibility is turned on at the login screen.
94 if (path == prefs::kSpokenFeedbackEnabled) {
95 if (accessibility_enabled_.GetValue() &&
96 StatusAreaViewChromeos::IsLoginMode()) {
97 views::ImageView* icon_view = new views::ImageView;
98 const gfx::Image& image = ResourceBundle::GetSharedInstance().
99 GetImageNamed(IDR_ACCESSIBILITY_ICON);
100 icon_view->SetImage(image.ToSkBitmap());
101 bubble_controller_.reset(
102 StatusAreaBubbleController::ShowBubbleUnderViewForAWhile(
103 this,
104 new StatusAreaBubbleContentView(
105 icon_view,
106 l10n_util::GetStringUTF16(
107 IDS_STATUSBAR_ACCESSIBILITY_TURNED_ON_BUBBLE))));
108 } else {
109 bubble_controller_.reset();
110 }
111 }
112 }
113 }
114
115
116 void AccessibilityMenuButton::Update() {
117 // Update tooltip and accessibile name.
118 string16 message =
119 l10n_util::GetStringUTF16(IDS_STATUSBAR_ACCESSIBILITY_ENABLED);
120 SetTooltipText(message);
121 SetAccessibleName(message);
122 // Update visibility.
123 SetVisible(accessibility_enabled_.GetValue());
124 }
125
126 void AccessibilityMenuButton::PrepareMenu() {
127 views::MenuItemView* menu = new views::MenuItemView(this);
128 if (accessibility_enabled_.GetValue())
129 menu->AppendMenuItemWithLabel(
130 MENU_ITEM_DISABLE_SPOKEN_FEEDBACK,
131 l10n_util::GetStringUTF16(IDS_STATUSBAR_DISABLE_SPOKEN_FEEDBACK));
132 // |menu_runner_| takes the ownership of |menu|
133 menu_runner_.reset(new views::MenuRunner(menu));
134 }
135
136 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/status/accessibility_menu_button.h ('k') | chrome/browser/chromeos/status/caps_lock_menu_button.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698