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