Add a11y virtual keyboard icon when a11y VK is enabled
[chromium-blink-merge.git] / ash / system / chromeos / virtual_keyboard / virtual_keyboard_tray.cc
blobf1a9c5c823ef5d3620a76c097c3230ff49dbfb57
1 // Copyright 2014 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.
5 #include "ash/system/chromeos/virtual_keyboard/virtual_keyboard_tray.h"
7 #include "ash/shell.h"
8 #include "ash/system/status_area_widget.h"
9 #include "ash/system/tray/system_tray_notifier.h"
10 #include "ash/system/tray/tray_constants.h"
11 #include "ash/system/tray/tray_utils.h"
12 #include "grit/ash_resources.h"
13 #include "grit/ash_strings.h"
14 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/events/event.h"
17 #include "ui/gfx/image/image_skia.h"
18 #include "ui/keyboard/keyboard_controller.h"
19 #include "ui/views/controls/button/image_button.h"
21 namespace ash {
22 namespace internal {
24 namespace {
26 class VirtualKeyboardButton : public views::ImageButton {
27 public:
28 VirtualKeyboardButton(views::ButtonListener* listener);
29 virtual ~VirtualKeyboardButton();
31 // Overridden from views::ImageButton:
32 virtual gfx::Size GetPreferredSize() OVERRIDE;
34 private:
35 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardButton);
38 VirtualKeyboardButton::VirtualKeyboardButton(views::ButtonListener* listener)
39 : views::ImageButton(listener) {
42 VirtualKeyboardButton::~VirtualKeyboardButton() {
45 gfx::Size VirtualKeyboardButton::GetPreferredSize() {
46 const int virtual_keyboard_button_height = GetShelfItemHeight();
47 gfx::Size size = ImageButton::GetPreferredSize();
48 int padding = virtual_keyboard_button_height - size.height();
49 size.set_height(virtual_keyboard_button_height);
50 size.set_width(size.width() + padding);
51 return size;
54 } // namespace
56 VirtualKeyboardTray::VirtualKeyboardTray(StatusAreaWidget* status_area_widget)
57 : TrayBackgroundView(status_area_widget),
58 button_(NULL) {
59 button_ = new VirtualKeyboardButton(this);
60 button_->SetImage(views::CustomButton::STATE_NORMAL,
61 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
62 IDR_AURA_UBER_TRAY_VIRTUAL_KEYBOARD));
63 button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER,
64 views::ImageButton::ALIGN_MIDDLE);
66 tray_container()->AddChildView(button_);
67 SetContentsBackground();
68 SetVisible(false);
69 // The Shell may not exist in some unit tests.
70 if (Shell::HasInstance()) {
71 Shell::GetInstance()->system_tray_notifier()->
72 AddAccessibilityObserver(this);
76 VirtualKeyboardTray::~VirtualKeyboardTray() {
77 // The Shell may not exist in some unit tests.
78 if (Shell::HasInstance()) {
79 Shell::GetInstance()->system_tray_notifier()->
80 RemoveAccessibilityObserver(this);
84 void VirtualKeyboardTray::SetShelfAlignment(ShelfAlignment alignment) {
85 TrayBackgroundView::SetShelfAlignment(alignment);
86 tray_container()->SetBorder(views::Border::NullBorder());
89 base::string16 VirtualKeyboardTray::GetAccessibleNameForTray() {
90 return l10n_util::GetStringUTF16(
91 IDS_ASH_VIRTUAL_KEYBOARD_TRAY_ACCESSIBLE_NAME);
94 void VirtualKeyboardTray::HideBubbleWithView(
95 const views::TrayBubbleView* bubble_view) {
98 bool VirtualKeyboardTray::ClickedOutsideBubble() {
99 return false;
102 bool VirtualKeyboardTray::PerformAction(const ui::Event& event) {
103 Shell::GetInstance()->keyboard_controller()->ShowAndLockKeyboard();
104 return true;
107 void VirtualKeyboardTray::ButtonPressed(views::Button* sender,
108 const ui::Event& event) {
109 DCHECK_EQ(button_, sender);
110 PerformAction(event);
113 void VirtualKeyboardTray::OnAccessibilityModeChanged(
114 AccessibilityNotificationVisibility notify) {
115 SetVisible(Shell::GetInstance()->accessibility_delegate()->
116 IsVirtualKeyboardEnabled());
119 } // namespace internal
120 } // namespace ash