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/keyboard/keyboard_ui.h" | 7 #include "ash/common/keyboard/keyboard_ui.h" |
8 #include "ash/common/material_design/material_design_controller.h" | 8 #include "ash/common/material_design/material_design_controller.h" |
9 #include "ash/common/shelf/shelf_constants.h" | 9 #include "ash/common/shelf/shelf_constants.h" |
10 #include "ash/common/shelf/wm_shelf_util.h" | 10 #include "ash/common/shelf/wm_shelf_util.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 Shell::GetInstance()->keyboard_ui()->RemoveObserver(this); | 53 Shell::GetInstance()->keyboard_ui()->RemoveObserver(this); |
54 } | 54 } |
55 | 55 |
56 void VirtualKeyboardTray::SetShelfAlignment(ShelfAlignment alignment) { | 56 void VirtualKeyboardTray::SetShelfAlignment(ShelfAlignment alignment) { |
57 TrayBackgroundView::SetShelfAlignment(alignment); | 57 TrayBackgroundView::SetShelfAlignment(alignment); |
58 tray_container()->SetBorder(views::Border::NullBorder()); | 58 tray_container()->SetBorder(views::Border::NullBorder()); |
59 | 59 |
60 // Pad button size to align with other controls in the system tray. | 60 // Pad button size to align with other controls in the system tray. |
61 const gfx::ImageSkia image = | 61 const gfx::ImageSkia image = |
62 button_->GetImage(views::CustomButton::STATE_NORMAL); | 62 button_->GetImage(views::CustomButton::STATE_NORMAL); |
63 int top_padding = (kTrayBarButtonWidth - image.height()) / 2; | 63 const int size = GetTrayConstant(VIRTUAL_KEYBOARD_BUTTON_SIZE); |
64 int left_padding = (kTrayBarButtonWidth - image.width()) / 2; | 64 const int vertical_padding = (size - image.height()) / 2; |
65 int bottom_padding = kTrayBarButtonWidth - image.height() - top_padding; | 65 int horizontal_padding = (size - image.width()) / 2; |
66 int right_padding = kTrayBarButtonWidth - image.width() - left_padding; | 66 if (!ash::MaterialDesignController::IsShelfMaterial() && |
67 | 67 IsHorizontalAlignment(alignment)) { |
68 // Square up the padding if horizontally aligned. Avoid extra padding when | 68 // Square up the padding if horizontally aligned. Avoid extra padding when |
69 // vertically aligned as the button would violate the width constraint on the | 69 // vertically aligned as the button would violate the width constraint on |
70 // shelf. | 70 // the shelf. |
71 if (IsHorizontalAlignment(alignment)) { | 71 horizontal_padding += std::max(0, vertical_padding - horizontal_padding); |
72 int additional_padding = std::max(0, top_padding - left_padding); | |
73 left_padding += additional_padding; | |
74 right_padding += additional_padding; | |
75 } | 72 } |
76 | 73 |
77 button_->SetBorder(views::Border::CreateEmptyBorder( | 74 button_->SetBorder(views::Border::CreateEmptyBorder( |
78 top_padding, left_padding, bottom_padding, right_padding)); | 75 gfx::Insets(vertical_padding, horizontal_padding))); |
79 } | 76 } |
80 | 77 |
81 base::string16 VirtualKeyboardTray::GetAccessibleNameForTray() { | 78 base::string16 VirtualKeyboardTray::GetAccessibleNameForTray() { |
82 return l10n_util::GetStringUTF16( | 79 return l10n_util::GetStringUTF16( |
83 IDS_ASH_VIRTUAL_KEYBOARD_TRAY_ACCESSIBLE_NAME); | 80 IDS_ASH_VIRTUAL_KEYBOARD_TRAY_ACCESSIBLE_NAME); |
84 } | 81 } |
85 | 82 |
86 void VirtualKeyboardTray::HideBubbleWithView( | 83 void VirtualKeyboardTray::HideBubbleWithView( |
87 const views::TrayBubbleView* bubble_view) {} | 84 const views::TrayBubbleView* bubble_view) {} |
88 | 85 |
89 void VirtualKeyboardTray::ClickedOutsideBubble() {} | 86 void VirtualKeyboardTray::ClickedOutsideBubble() {} |
90 | 87 |
91 bool VirtualKeyboardTray::PerformAction(const ui::Event& event) { | 88 bool VirtualKeyboardTray::PerformAction(const ui::Event& event) { |
92 Shell::GetInstance()->keyboard_ui()->Show(); | 89 Shell::GetInstance()->keyboard_ui()->Show(); |
93 return true; | 90 return true; |
94 } | 91 } |
95 | 92 |
96 void VirtualKeyboardTray::ButtonPressed(views::Button* sender, | 93 void VirtualKeyboardTray::ButtonPressed(views::Button* sender, |
97 const ui::Event& event) { | 94 const ui::Event& event) { |
98 DCHECK_EQ(button_, sender); | 95 DCHECK_EQ(button_, sender); |
99 PerformAction(event); | 96 PerformAction(event); |
100 } | 97 } |
101 | 98 |
102 void VirtualKeyboardTray::OnKeyboardEnabledStateChanged(bool new_value) { | 99 void VirtualKeyboardTray::OnKeyboardEnabledStateChanged(bool new_value) { |
103 SetVisible(Shell::GetInstance()->keyboard_ui()->IsEnabled()); | 100 SetVisible(Shell::GetInstance()->keyboard_ui()->IsEnabled()); |
104 } | 101 } |
105 | 102 |
106 } // namespace ash | 103 } // namespace ash |
OLD | NEW |