Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / ash / system / chromeos / virtual_keyboard / virtual_keyboard_tray.cc
blob2875d9ed9d7e399874e94778049efc8a96a8bc51
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/shelf/shelf_constants.h"
8 #include "ash/shell.h"
9 #include "ash/system/status_area_widget.h"
10 #include "ash/system/tray/system_tray_notifier.h"
11 #include "ash/system/tray/tray_constants.h"
12 #include "ash/system/tray/tray_utils.h"
13 #include "grit/ash_resources.h"
14 #include "grit/ash_strings.h"
15 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/events/event.h"
18 #include "ui/gfx/image/image_skia.h"
19 #include "ui/keyboard/keyboard_controller.h"
20 #include "ui/views/controls/button/image_button.h"
22 namespace ash {
23 namespace {
25 class VirtualKeyboardButton : public views::ImageButton {
26 public:
27 VirtualKeyboardButton(views::ButtonListener* listener);
28 virtual ~VirtualKeyboardButton();
30 // Overridden from views::ImageButton:
31 virtual gfx::Size GetPreferredSize() OVERRIDE;
33 private:
34 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardButton);
37 VirtualKeyboardButton::VirtualKeyboardButton(views::ButtonListener* listener)
38 : views::ImageButton(listener) {
41 VirtualKeyboardButton::~VirtualKeyboardButton() {
44 gfx::Size VirtualKeyboardButton::GetPreferredSize() {
45 const int virtual_keyboard_button_height = kShelfSize;
46 gfx::Size size = ImageButton::GetPreferredSize();
47 int padding = virtual_keyboard_button_height - size.height();
48 size.set_height(virtual_keyboard_button_height);
49 size.set_width(size.width() + padding);
50 return size;
53 } // namespace
55 VirtualKeyboardTray::VirtualKeyboardTray(StatusAreaWidget* status_area_widget)
56 : TrayBackgroundView(status_area_widget),
57 button_(NULL) {
58 button_ = new VirtualKeyboardButton(this);
59 button_->SetImage(views::CustomButton::STATE_NORMAL,
60 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
61 IDR_AURA_UBER_TRAY_VIRTUAL_KEYBOARD));
62 button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER,
63 views::ImageButton::ALIGN_MIDDLE);
65 tray_container()->AddChildView(button_);
66 SetContentsBackground();
67 SetVisible(false);
68 // The Shell may not exist in some unit tests.
69 if (Shell::HasInstance()) {
70 Shell::GetInstance()->system_tray_notifier()->
71 AddAccessibilityObserver(this);
75 VirtualKeyboardTray::~VirtualKeyboardTray() {
76 // The Shell may not exist in some unit tests.
77 if (Shell::HasInstance()) {
78 Shell::GetInstance()->system_tray_notifier()->
79 RemoveAccessibilityObserver(this);
83 void VirtualKeyboardTray::SetShelfAlignment(ShelfAlignment alignment) {
84 TrayBackgroundView::SetShelfAlignment(alignment);
85 tray_container()->SetBorder(views::Border::NullBorder());
88 base::string16 VirtualKeyboardTray::GetAccessibleNameForTray() {
89 return l10n_util::GetStringUTF16(
90 IDS_ASH_VIRTUAL_KEYBOARD_TRAY_ACCESSIBLE_NAME);
93 void VirtualKeyboardTray::HideBubbleWithView(
94 const views::TrayBubbleView* bubble_view) {
97 bool VirtualKeyboardTray::ClickedOutsideBubble() {
98 return false;
101 bool VirtualKeyboardTray::PerformAction(const ui::Event& event) {
102 keyboard::KeyboardController::GetInstance()->ShowKeyboard(true);
103 return true;
106 void VirtualKeyboardTray::ButtonPressed(views::Button* sender,
107 const ui::Event& event) {
108 DCHECK_EQ(button_, sender);
109 PerformAction(event);
112 void VirtualKeyboardTray::OnAccessibilityModeChanged(
113 AccessibilityNotificationVisibility notify) {
114 SetVisible(Shell::GetInstance()->accessibility_delegate()->
115 IsVirtualKeyboardEnabled());
118 } // namespace ash