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 } // namespace | |
39 | |
40 VirtualKeyboardButton::VirtualKeyboardButton(views::ButtonListener* listener) | |
sadrul
2014/03/04 07:00:32
Shouldn't these be inside the anonymous namespace
bshe
2014/03/04 16:11:54
doh. Sorry.
On 2014/03/04 07:00:32, sadrul wrote:
| |
41 : views::ImageButton(listener) { | |
42 } | |
43 | |
44 VirtualKeyboardButton::~VirtualKeyboardButton() { | |
45 } | |
46 | |
47 gfx::Size VirtualKeyboardButton::GetPreferredSize() { | |
48 const int virtual_keyboard_button_size = GetShelfItemHeight(); | |
49 return gfx::Size(virtual_keyboard_button_size, virtual_keyboard_button_size); | |
50 } | |
51 | |
52 VirtualKeyboardTray::VirtualKeyboardTray(StatusAreaWidget* status_area_widget) | |
53 : TrayBackgroundView(status_area_widget), | |
54 button_(NULL) { | |
55 button_ = new VirtualKeyboardButton(this); | |
56 button_->SetImage(views::CustomButton::STATE_NORMAL, | |
57 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
58 IDR_AURA_UBER_TRAY_VIRTUAL_KEYBOARD)); | |
59 button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, | |
60 views::ImageButton::ALIGN_MIDDLE); | |
61 | |
62 tray_container()->AddChildView(button_); | |
63 SetContentsBackground(); | |
64 SetVisible(false); | |
65 // The Shell may not exist in some unit tests. | |
66 if (Shell::HasInstance()) { | |
67 Shell::GetInstance()->system_tray_notifier()-> | |
68 AddAccessibilityObserver(this); | |
69 } | |
70 } | |
71 | |
72 VirtualKeyboardTray::~VirtualKeyboardTray() { | |
73 // The Shell may not exist in some unit tests. | |
74 if (Shell::HasInstance()) { | |
75 Shell::GetInstance()->system_tray_notifier()-> | |
76 RemoveAccessibilityObserver(this); | |
77 } | |
78 } | |
79 | |
80 void VirtualKeyboardTray::SetShelfAlignment(ShelfAlignment alignment) { | |
81 TrayBackgroundView::SetShelfAlignment(alignment); | |
82 tray_container()->SetBorder(views::Border::NullBorder()); | |
83 } | |
84 | |
85 base::string16 VirtualKeyboardTray::GetAccessibleNameForTray() { | |
86 return l10n_util::GetStringUTF16( | |
87 IDS_ASH_VIRTUAL_KEYBOARD_TRAY_ACCESSIBLE_NAME); | |
88 } | |
89 | |
90 void VirtualKeyboardTray::HideBubbleWithView( | |
91 const views::TrayBubbleView* bubble_view) { | |
92 } | |
93 | |
94 bool VirtualKeyboardTray::ClickedOutsideBubble() { | |
95 return false; | |
96 } | |
97 | |
98 bool VirtualKeyboardTray::PerformAction(const ui::Event& event) { | |
99 Shell::GetInstance()->keyboard_controller()->ShowAndLockKeyboard(); | |
100 return true; | |
101 } | |
102 | |
103 void VirtualKeyboardTray::ButtonPressed(views::Button* sender, | |
104 const ui::Event& event) { | |
105 DCHECK_EQ(button_, sender); | |
106 PerformAction(event); | |
107 } | |
108 | |
109 void VirtualKeyboardTray::OnAccessibilityModeChanged( | |
110 AccessibilityNotificationVisibility notify) { | |
111 SetVisible(Shell::GetInstance()->accessibility_delegate()-> | |
112 IsVirtualKeyboardEnabled()); | |
113 } | |
114 | |
115 } // namespace internal | |
116 } // namespace ash | |
OLD | NEW |