Chromium Code Reviews| 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)); |
| 32 | |
| 33 gfx::Size size = button_->GetPreferredSize(); | |
| 34 int top_padding = (kTrayBarButtonWidth - size.height()) / 2; | |
| 35 int left_padding = (kTrayBarButtonWidth - size.width()) / 2; | |
| 36 int bottom_padding = kTrayBarButtonWidth - size.height() - top_padding; | |
| 37 int right_padding = kTrayBarButtonWidth - size.width() - left_padding; | |
| 38 button_->SetBorder(views::Border::CreateEmptyBorder( | |
| 39 top_padding, | |
| 40 left_padding, | |
| 41 bottom_padding, | |
| 42 right_padding)); | |
| 43 | |
| 62 button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, | 44 button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, |
| 63 views::ImageButton::ALIGN_MIDDLE); | 45 views::ImageButton::ALIGN_MIDDLE); |
| 64 | 46 |
| 65 tray_container()->AddChildView(button_); | 47 tray_container()->AddChildView(button_); |
| 66 SetContentsBackground(); | 48 SetContentsBackground(); |
| 67 // The Shell may not exist in some unit tests. | 49 // The Shell may not exist in some unit tests. |
| 68 if (Shell::HasInstance()) { | 50 if (Shell::HasInstance()) { |
| 69 Shell::GetInstance()->system_tray_notifier()-> | 51 Shell::GetInstance()->system_tray_notifier()-> |
| 70 AddAccessibilityObserver(this); | 52 AddAccessibilityObserver(this); |
| 71 } | 53 } |
| 72 } | 54 } |
| 73 | 55 |
| 74 VirtualKeyboardTray::~VirtualKeyboardTray() { | 56 VirtualKeyboardTray::~VirtualKeyboardTray() { |
| 75 // The Shell may not exist in some unit tests. | 57 // The Shell may not exist in some unit tests. |
| 76 if (Shell::HasInstance()) { | 58 if (Shell::HasInstance()) { |
| 77 Shell::GetInstance()->system_tray_notifier()-> | 59 Shell::GetInstance()->system_tray_notifier()-> |
| 78 RemoveAccessibilityObserver(this); | 60 RemoveAccessibilityObserver(this); |
| 79 } | 61 } |
| 80 } | 62 } |
| 81 | 63 |
| 82 void VirtualKeyboardTray::SetShelfAlignment(ShelfAlignment alignment) { | 64 void VirtualKeyboardTray::SetShelfAlignment(ShelfAlignment alignment) { |
| 83 TrayBackgroundView::SetShelfAlignment(alignment); | 65 TrayBackgroundView::SetShelfAlignment(alignment); |
| 84 tray_container()->SetBorder(views::Border::NullBorder()); | 66 int horizontal_padding = 0; |
| 67 // Square up the padding if horizontally aligned. Cannot afford extra padding | |
| 68 // when vertically aligned as the button would violate the width constraint on | |
| 69 // the shelf. | |
| 70 if (alignment == SHELF_ALIGNMENT_BOTTOM || alignment == SHELF_ALIGNMENT_TOP) { | |
| 71 gfx::Insets insets = button_->GetInsets(); | |
| 72 horizontal_padding = std::max(0, insets.top() - insets.left()); | |
| 73 } | |
| 74 tray_container()->SetBorder(views::Border::CreateEmptyBorder(0, | |
|
sadrul
2014/08/01 19:49:49
I think you want to SetBorder on button_, and not
kevers
2014/08/05 14:47:18
Done.
| |
| 75 horizontal_padding, 0, horizontal_padding)); | |
| 85 } | 76 } |
| 86 | 77 |
| 87 base::string16 VirtualKeyboardTray::GetAccessibleNameForTray() { | 78 base::string16 VirtualKeyboardTray::GetAccessibleNameForTray() { |
| 88 return l10n_util::GetStringUTF16( | 79 return l10n_util::GetStringUTF16( |
| 89 IDS_ASH_VIRTUAL_KEYBOARD_TRAY_ACCESSIBLE_NAME); | 80 IDS_ASH_VIRTUAL_KEYBOARD_TRAY_ACCESSIBLE_NAME); |
| 90 } | 81 } |
| 91 | 82 |
| 92 void VirtualKeyboardTray::HideBubbleWithView( | 83 void VirtualKeyboardTray::HideBubbleWithView( |
| 93 const views::TrayBubbleView* bubble_view) { | 84 const views::TrayBubbleView* bubble_view) { |
| 94 } | 85 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 108 PerformAction(event); | 99 PerformAction(event); |
| 109 } | 100 } |
| 110 | 101 |
| 111 void VirtualKeyboardTray::OnAccessibilityModeChanged( | 102 void VirtualKeyboardTray::OnAccessibilityModeChanged( |
| 112 AccessibilityNotificationVisibility notify) { | 103 AccessibilityNotificationVisibility notify) { |
| 113 SetVisible(Shell::GetInstance()->accessibility_delegate()-> | 104 SetVisible(Shell::GetInstance()->accessibility_delegate()-> |
| 114 IsVirtualKeyboardEnabled()); | 105 IsVirtualKeyboardEnabled()); |
| 115 } | 106 } |
| 116 | 107 |
| 117 } // namespace ash | 108 } // namespace ash |
| OLD | NEW |