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/common/wm/shelf/wm_shelf_util.h" | 7 #include "ash/common/shelf/shelf_constants.h" |
| 8 #include "ash/common/shelf/wm_shelf_util.h" |
8 #include "ash/keyboard/keyboard_ui.h" | 9 #include "ash/keyboard/keyboard_ui.h" |
9 #include "ash/shelf/shelf.h" | 10 #include "ash/shelf/shelf.h" |
10 #include "ash/shelf/shelf_constants.h" | |
11 #include "ash/shelf/shelf_util.h" | 11 #include "ash/shelf/shelf_util.h" |
12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
13 #include "ash/system/status_area_widget.h" | 13 #include "ash/system/status_area_widget.h" |
14 #include "ash/system/tray/system_tray_notifier.h" | 14 #include "ash/system/tray/system_tray_notifier.h" |
15 #include "ash/system/tray/tray_constants.h" | 15 #include "ash/system/tray/tray_constants.h" |
16 #include "ash/system/tray/tray_utils.h" | 16 #include "ash/system/tray/tray_utils.h" |
17 #include "grit/ash_resources.h" | 17 #include "grit/ash_resources.h" |
18 #include "grit/ash_strings.h" | 18 #include "grit/ash_strings.h" |
19 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
20 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
(...skipping 19 matching lines...) Expand all Loading... |
40 if (Shell::HasInstance()) | 40 if (Shell::HasInstance()) |
41 Shell::GetInstance()->keyboard_ui()->AddObserver(this); | 41 Shell::GetInstance()->keyboard_ui()->AddObserver(this); |
42 } | 42 } |
43 | 43 |
44 VirtualKeyboardTray::~VirtualKeyboardTray() { | 44 VirtualKeyboardTray::~VirtualKeyboardTray() { |
45 // The Shell may not exist in some unit tests. | 45 // The Shell may not exist in some unit tests. |
46 if (Shell::HasInstance()) | 46 if (Shell::HasInstance()) |
47 Shell::GetInstance()->keyboard_ui()->RemoveObserver(this); | 47 Shell::GetInstance()->keyboard_ui()->RemoveObserver(this); |
48 } | 48 } |
49 | 49 |
50 void VirtualKeyboardTray::SetShelfAlignment(wm::ShelfAlignment alignment) { | 50 void VirtualKeyboardTray::SetShelfAlignment(ShelfAlignment alignment) { |
51 TrayBackgroundView::SetShelfAlignment(alignment); | 51 TrayBackgroundView::SetShelfAlignment(alignment); |
52 tray_container()->SetBorder(views::Border::NullBorder()); | 52 tray_container()->SetBorder(views::Border::NullBorder()); |
53 | 53 |
54 // Pad button size to align with other controls in the system tray. | 54 // Pad button size to align with other controls in the system tray. |
55 const gfx::ImageSkia image = button_->GetImage( | 55 const gfx::ImageSkia image = button_->GetImage( |
56 views::CustomButton::STATE_NORMAL); | 56 views::CustomButton::STATE_NORMAL); |
57 int top_padding = (kTrayBarButtonWidth - image.height()) / 2; | 57 int top_padding = (kTrayBarButtonWidth - image.height()) / 2; |
58 int left_padding = (kTrayBarButtonWidth - image.width()) / 2; | 58 int left_padding = (kTrayBarButtonWidth - image.width()) / 2; |
59 int bottom_padding = kTrayBarButtonWidth - image.height() - top_padding; | 59 int bottom_padding = kTrayBarButtonWidth - image.height() - top_padding; |
60 int right_padding = kTrayBarButtonWidth - image.width() - left_padding; | 60 int right_padding = kTrayBarButtonWidth - image.width() - left_padding; |
61 | 61 |
62 // Square up the padding if horizontally aligned. Avoid extra padding when | 62 // Square up the padding if horizontally aligned. Avoid extra padding when |
63 // vertically aligned as the button would violate the width constraint on the | 63 // vertically aligned as the button would violate the width constraint on the |
64 // shelf. | 64 // shelf. |
65 if (wm::IsHorizontalAlignment(alignment)) { | 65 if (IsHorizontalAlignment(alignment)) { |
66 gfx::Insets insets = button_->GetInsets(); | 66 gfx::Insets insets = button_->GetInsets(); |
67 int additional_padding = std::max(0, top_padding - left_padding); | 67 int additional_padding = std::max(0, top_padding - left_padding); |
68 left_padding += additional_padding; | 68 left_padding += additional_padding; |
69 right_padding += additional_padding; | 69 right_padding += additional_padding; |
70 } | 70 } |
71 | 71 |
72 button_->SetBorder(views::Border::CreateEmptyBorder( | 72 button_->SetBorder(views::Border::CreateEmptyBorder( |
73 top_padding, | 73 top_padding, |
74 left_padding, | 74 left_padding, |
75 bottom_padding, | 75 bottom_padding, |
(...skipping 20 matching lines...) Expand all Loading... |
96 const ui::Event& event) { | 96 const ui::Event& event) { |
97 DCHECK_EQ(button_, sender); | 97 DCHECK_EQ(button_, sender); |
98 PerformAction(event); | 98 PerformAction(event); |
99 } | 99 } |
100 | 100 |
101 void VirtualKeyboardTray::OnKeyboardEnabledStateChanged(bool new_value) { | 101 void VirtualKeyboardTray::OnKeyboardEnabledStateChanged(bool new_value) { |
102 SetVisible(Shell::GetInstance()->keyboard_ui()->IsEnabled()); | 102 SetVisible(Shell::GetInstance()->keyboard_ui()->IsEnabled()); |
103 } | 103 } |
104 | 104 |
105 } // namespace ash | 105 } // namespace ash |
OLD | NEW |