OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/system/chromeos/virtual_keyboard/virtual_keyboard_tray.h" | 5 #include "ash/system/chromeos/virtual_keyboard/virtual_keyboard_tray.h" |
6 | 6 |
7 #include "ash/shelf/shelf.h" | |
7 #include "ash/shelf/shelf_constants.h" | 8 #include "ash/shelf/shelf_constants.h" |
8 #include "ash/shell.h" | 9 #include "ash/shell.h" |
9 #include "ash/system/status_area_widget.h" | 10 #include "ash/system/status_area_widget.h" |
10 #include "ash/system/tray/system_tray_notifier.h" | 11 #include "ash/system/tray/system_tray_notifier.h" |
11 #include "ash/system/tray/tray_constants.h" | 12 #include "ash/system/tray/tray_constants.h" |
12 #include "ash/system/tray/tray_utils.h" | 13 #include "ash/system/tray/tray_utils.h" |
13 #include "grit/ash_resources.h" | 14 #include "grit/ash_resources.h" |
14 #include "grit/ash_strings.h" | 15 #include "grit/ash_strings.h" |
15 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
16 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
17 #include "ui/events/event.h" | 18 #include "ui/events/event.h" |
18 #include "ui/gfx/image/image_skia.h" | 19 #include "ui/gfx/image/image_skia.h" |
19 #include "ui/keyboard/keyboard_controller.h" | 20 #include "ui/keyboard/keyboard_controller.h" |
20 #include "ui/views/controls/button/image_button.h" | 21 #include "ui/views/controls/button/image_button.h" |
21 | 22 |
22 namespace ash { | 23 namespace ash { |
23 namespace { | |
24 | |
25 class VirtualKeyboardButton : public views::ImageButton { | |
26 public: | |
27 VirtualKeyboardButton(views::ButtonListener* listener); | |
28 virtual ~VirtualKeyboardButton(); | |
29 | |
30 // Overridden from views::ImageButton: | |
31 virtual gfx::Size GetPreferredSize() const OVERRIDE; | |
32 | |
33 private: | |
34 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardButton); | |
35 }; | |
36 | |
37 VirtualKeyboardButton::VirtualKeyboardButton(views::ButtonListener* listener) | |
38 : views::ImageButton(listener) { | |
39 } | |
40 | |
41 VirtualKeyboardButton::~VirtualKeyboardButton() { | |
42 } | |
43 | |
44 gfx::Size VirtualKeyboardButton::GetPreferredSize() const { | |
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; | |
51 } | |
52 | |
53 } // namespace | |
54 | 24 |
55 VirtualKeyboardTray::VirtualKeyboardTray(StatusAreaWidget* status_area_widget) | 25 VirtualKeyboardTray::VirtualKeyboardTray(StatusAreaWidget* status_area_widget) |
56 : TrayBackgroundView(status_area_widget), | 26 : TrayBackgroundView(status_area_widget), |
57 button_(NULL) { | 27 button_(NULL) { |
58 button_ = new VirtualKeyboardButton(this); | 28 button_ = new views::ImageButton(this); |
59 button_->SetImage(views::CustomButton::STATE_NORMAL, | 29 button_->SetImage(views::CustomButton::STATE_NORMAL, |
60 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 30 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
61 IDR_AURA_UBER_TRAY_VIRTUAL_KEYBOARD)); | 31 IDR_AURA_UBER_TRAY_VIRTUAL_KEYBOARD)); |
62 button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, | 32 button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, |
63 views::ImageButton::ALIGN_MIDDLE); | 33 views::ImageButton::ALIGN_MIDDLE); |
64 | 34 |
65 tray_container()->AddChildView(button_); | 35 tray_container()->AddChildView(button_); |
66 SetContentsBackground(); | 36 SetContentsBackground(); |
67 // The Shell may not exist in some unit tests. | 37 // The Shell may not exist in some unit tests. |
68 if (Shell::HasInstance()) { | 38 if (Shell::HasInstance()) { |
69 Shell::GetInstance()->system_tray_notifier()-> | 39 Shell::GetInstance()->system_tray_notifier()-> |
70 AddAccessibilityObserver(this); | 40 AddAccessibilityObserver(this); |
71 } | 41 } |
72 } | 42 } |
73 | 43 |
74 VirtualKeyboardTray::~VirtualKeyboardTray() { | 44 VirtualKeyboardTray::~VirtualKeyboardTray() { |
75 // The Shell may not exist in some unit tests. | 45 // The Shell may not exist in some unit tests. |
76 if (Shell::HasInstance()) { | 46 if (Shell::HasInstance()) { |
77 Shell::GetInstance()->system_tray_notifier()-> | 47 Shell::GetInstance()->system_tray_notifier()-> |
78 RemoveAccessibilityObserver(this); | 48 RemoveAccessibilityObserver(this); |
79 } | 49 } |
80 } | 50 } |
81 | 51 |
82 void VirtualKeyboardTray::SetShelfAlignment(ShelfAlignment alignment) { | 52 void VirtualKeyboardTray::SetShelfAlignment(ShelfAlignment alignment) { |
83 TrayBackgroundView::SetShelfAlignment(alignment); | 53 TrayBackgroundView::SetShelfAlignment(alignment); |
84 tray_container()->SetBorder(views::Border::NullBorder()); | 54 tray_container()->SetBorder(views::Border::NullBorder()); |
55 | |
56 // Pad button size to align with other controls in the system tray. | |
57 const gfx::ImageSkia image = button_->GetImage( | |
58 views::CustomButton::STATE_NORMAL); | |
59 int top_padding = (kTrayBarButtonWidth - image.height()) / 2; | |
60 int left_padding = (kTrayBarButtonWidth - image.width()) / 2; | |
61 int bottom_padding = kTrayBarButtonWidth - image.height() - top_padding; | |
62 int right_padding = kTrayBarButtonWidth - image.width() - left_padding; | |
63 | |
64 // Square up the padding if horizontally aligned. Avoid extra padding when | |
65 // vertically aligned as the button would violate the width constraint on the | |
66 // shelf. | |
67 if (alignment == SHELF_ALIGNMENT_BOTTOM || alignment == SHELF_ALIGNMENT_TOP) { | |
68 gfx::Insets insets = button_->GetInsets(); | |
69 int additional_padding = std::max(0, top_padding - left_padding); | |
70 left_padding += additional_padding; | |
71 right_padding += additional_padding; | |
72 } | |
73 | |
74 button_->SetBorder(views::Border::CreateEmptyBorder( | |
75 top_padding, | |
76 left_padding, | |
77 bottom_padding, | |
78 right_padding)); | |
sadrul
2014/08/05 14:53:30
I assume SetShelfAlignment() is called immediately
| |
85 } | 79 } |
86 | 80 |
87 base::string16 VirtualKeyboardTray::GetAccessibleNameForTray() { | 81 base::string16 VirtualKeyboardTray::GetAccessibleNameForTray() { |
88 return l10n_util::GetStringUTF16( | 82 return l10n_util::GetStringUTF16( |
89 IDS_ASH_VIRTUAL_KEYBOARD_TRAY_ACCESSIBLE_NAME); | 83 IDS_ASH_VIRTUAL_KEYBOARD_TRAY_ACCESSIBLE_NAME); |
90 } | 84 } |
91 | 85 |
92 void VirtualKeyboardTray::HideBubbleWithView( | 86 void VirtualKeyboardTray::HideBubbleWithView( |
93 const views::TrayBubbleView* bubble_view) { | 87 const views::TrayBubbleView* bubble_view) { |
94 } | 88 } |
(...skipping 13 matching lines...) Expand all Loading... | |
108 PerformAction(event); | 102 PerformAction(event); |
109 } | 103 } |
110 | 104 |
111 void VirtualKeyboardTray::OnAccessibilityModeChanged( | 105 void VirtualKeyboardTray::OnAccessibilityModeChanged( |
112 AccessibilityNotificationVisibility notify) { | 106 AccessibilityNotificationVisibility notify) { |
113 SetVisible(Shell::GetInstance()->accessibility_delegate()-> | 107 SetVisible(Shell::GetInstance()->accessibility_delegate()-> |
114 IsVirtualKeyboardEnabled()); | 108 IsVirtualKeyboardEnabled()); |
115 } | 109 } |
116 | 110 |
117 } // namespace ash | 111 } // namespace ash |
OLD | NEW |