OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "ash/system/chromeos/virtual_keyboard/virtual_keyboard_tray.h" |
| 6 |
| 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" |
| 20 |
| 21 namespace ash { |
| 22 namespace internal { |
| 23 |
| 24 namespace { |
| 25 |
| 26 class VirtualKeyboardButton : public views::ImageButton { |
| 27 public: |
| 28 VirtualKeyboardButton(views::ButtonListener* listener); |
| 29 virtual ~VirtualKeyboardButton(); |
| 30 |
| 31 // Overridden from views::ImageButton: |
| 32 virtual gfx::Size GetPreferredSize() OVERRIDE; |
| 33 |
| 34 private: |
| 35 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardButton); |
| 36 }; |
| 37 |
| 38 VirtualKeyboardButton::VirtualKeyboardButton(views::ButtonListener* listener) |
| 39 : views::ImageButton(listener) { |
| 40 } |
| 41 |
| 42 VirtualKeyboardButton::~VirtualKeyboardButton() { |
| 43 } |
| 44 |
| 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; |
| 52 } |
| 53 |
| 54 } // namespace |
| 55 |
| 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); |
| 65 |
| 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); |
| 73 } |
| 74 } |
| 75 |
| 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); |
| 81 } |
| 82 } |
| 83 |
| 84 void VirtualKeyboardTray::SetShelfAlignment(ShelfAlignment alignment) { |
| 85 TrayBackgroundView::SetShelfAlignment(alignment); |
| 86 tray_container()->SetBorder(views::Border::NullBorder()); |
| 87 } |
| 88 |
| 89 base::string16 VirtualKeyboardTray::GetAccessibleNameForTray() { |
| 90 return l10n_util::GetStringUTF16( |
| 91 IDS_ASH_VIRTUAL_KEYBOARD_TRAY_ACCESSIBLE_NAME); |
| 92 } |
| 93 |
| 94 void VirtualKeyboardTray::HideBubbleWithView( |
| 95 const views::TrayBubbleView* bubble_view) { |
| 96 } |
| 97 |
| 98 bool VirtualKeyboardTray::ClickedOutsideBubble() { |
| 99 return false; |
| 100 } |
| 101 |
| 102 bool VirtualKeyboardTray::PerformAction(const ui::Event& event) { |
| 103 Shell::GetInstance()->keyboard_controller()->ShowAndLockKeyboard(); |
| 104 return true; |
| 105 } |
| 106 |
| 107 void VirtualKeyboardTray::ButtonPressed(views::Button* sender, |
| 108 const ui::Event& event) { |
| 109 DCHECK_EQ(button_, sender); |
| 110 PerformAction(event); |
| 111 } |
| 112 |
| 113 void VirtualKeyboardTray::OnAccessibilityModeChanged( |
| 114 AccessibilityNotificationVisibility notify) { |
| 115 SetVisible(Shell::GetInstance()->accessibility_delegate()-> |
| 116 IsVirtualKeyboardEnabled()); |
| 117 } |
| 118 |
| 119 } // namespace internal |
| 120 } // namespace ash |
OLD | NEW |