Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: ash/common/system/chromeos/virtual_keyboard/virtual_keyboard_tray.cc

Issue 2147143002: [Chrome OS MD] Draw a 1px separator between 2 tray items (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/common/system/chromeos/virtual_keyboard/virtual_keyboard_tray.h" 5 #include "ash/common/system/chromeos/virtual_keyboard/virtual_keyboard_tray.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/common/keyboard/keyboard_ui.h" 9 #include "ash/common/keyboard/keyboard_ui.h"
10 #include "ash/common/material_design/material_design_controller.h" 10 #include "ash/common/material_design/material_design_controller.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 UnobserveKeyboardController(); 54 UnobserveKeyboardController();
55 // The Shell may not exist in some unit tests. 55 // The Shell may not exist in some unit tests.
56 if (WmShell::HasInstance()) 56 if (WmShell::HasInstance())
57 WmShell::Get()->keyboard_ui()->RemoveObserver(this); 57 WmShell::Get()->keyboard_ui()->RemoveObserver(this);
58 } 58 }
59 59
60 void VirtualKeyboardTray::SetShelfAlignment(ShelfAlignment alignment) { 60 void VirtualKeyboardTray::SetShelfAlignment(ShelfAlignment alignment) {
61 if (alignment == shelf_alignment()) 61 if (alignment == shelf_alignment())
62 return; 62 return;
63 63
64 if (!ash::MaterialDesignController::IsShelfMaterial() &&
65 IsHorizontalAlignment(alignment)) {
66 // Pad button size to align with other controls in the system tray.
67 const gfx::ImageSkia image = icon_->GetImage();
68 const int size = GetTrayConstant(VIRTUAL_KEYBOARD_BUTTON_SIZE);
69 const int vertical_padding = (size - image.height()) / 2;
70 int horizontal_padding = (size - image.width()) / 2;
71
72 // Square up the padding if horizontally aligned. Avoid extra padding when
73 // vertically aligned as the button would violate the width constraint on
74 // the shelf.
75 horizontal_padding += std::max(0, vertical_padding - horizontal_padding);
James Cook 2016/08/11 20:36:54 horizontal_padding isn't used after this line
yiyix 2016/08/18 00:42:59 Sorry, I had these from merge, I did not check car
76 }
77
64 TrayBackgroundView::SetShelfAlignment(alignment); 78 TrayBackgroundView::SetShelfAlignment(alignment);
65 SetIconBorderForShelfAlignment(); 79 SetIconBorderForShelfAlignment();
66 } 80 }
67 81
68 base::string16 VirtualKeyboardTray::GetAccessibleNameForTray() { 82 base::string16 VirtualKeyboardTray::GetAccessibleNameForTray() {
69 return l10n_util::GetStringUTF16( 83 return l10n_util::GetStringUTF16(
70 IDS_ASH_VIRTUAL_KEYBOARD_TRAY_ACCESSIBLE_NAME); 84 IDS_ASH_VIRTUAL_KEYBOARD_TRAY_ACCESSIBLE_NAME);
71 } 85 }
72 86
73 void VirtualKeyboardTray::HideBubbleWithView( 87 void VirtualKeyboardTray::HideBubbleWithView(
(...skipping 17 matching lines...) Expand all
91 UnobserveKeyboardController(); 105 UnobserveKeyboardController();
92 } 106 }
93 } 107 }
94 108
95 void VirtualKeyboardTray::OnKeyboardBoundsChanging( 109 void VirtualKeyboardTray::OnKeyboardBoundsChanging(
96 const gfx::Rect& new_bounds) { 110 const gfx::Rect& new_bounds) {
97 SetDrawBackgroundAsActive(!new_bounds.IsEmpty()); 111 SetDrawBackgroundAsActive(!new_bounds.IsEmpty());
98 } 112 }
99 113
100 void VirtualKeyboardTray::SetIconBorderForShelfAlignment() { 114 void VirtualKeyboardTray::SetIconBorderForShelfAlignment() {
101 // Every time shelf alignment is updated, StatusAreaWidgetDelegate resets the
102 // border to a non-null border. So, we need to remove it.
103 tray_container()->SetBorder(views::Border::NullBorder());
James Cook 2016/08/11 20:36:54 Q: Are you sure this isn't needed anymore? I thoug
yiyix 2016/08/18 00:42:59 One of the change I made it to initialize the bord
104
105 const gfx::ImageSkia& image = icon_->GetImage(); 115 const gfx::ImageSkia& image = icon_->GetImage();
106 const int size = GetTrayConstant(VIRTUAL_KEYBOARD_BUTTON_SIZE); 116 const int size = GetTrayConstant(VIRTUAL_KEYBOARD_BUTTON_SIZE);
107 const int vertical_padding = (size - image.height()) / 2; 117 const int vertical_padding = (size - image.height()) / 2;
108 int horizontal_padding = (size - image.width()) / 2; 118 int horizontal_padding = (size - image.width()) / 2;
109 if (!ash::MaterialDesignController::IsShelfMaterial() && 119 if (!ash::MaterialDesignController::IsShelfMaterial() &&
110 IsHorizontalAlignment(shelf_alignment())) { 120 IsHorizontalAlignment(shelf_alignment())) {
111 // Square up the padding if horizontally aligned. Avoid extra padding when 121 // Square up the padding if horizontally aligned. Avoid extra padding when
112 // vertically aligned as the button would violate the width constraint on 122 // vertically aligned as the button would violate the width constraint on
113 // the shelf. 123 // the shelf.
114 horizontal_padding += std::max(0, vertical_padding - horizontal_padding); 124 horizontal_padding += std::max(0, vertical_padding - horizontal_padding);
115 } 125 }
James Cook 2016/08/11 20:36:54 There seems to be some duplication between this co
yiyix 2016/08/18 00:43:00 The earlier one means needs to be deleted.
116 icon_->SetBorder(views::Border::CreateEmptyBorder( 126 icon_->SetBorder(views::Border::CreateEmptyBorder(
117 gfx::Insets(vertical_padding, horizontal_padding))); 127 gfx::Insets(vertical_padding, horizontal_padding)));
118 } 128 }
119 129
120 void VirtualKeyboardTray::ObserveKeyboardController() { 130 void VirtualKeyboardTray::ObserveKeyboardController() {
121 keyboard::KeyboardController* keyboard_controller = 131 keyboard::KeyboardController* keyboard_controller =
122 keyboard::KeyboardController::GetInstance(); 132 keyboard::KeyboardController::GetInstance();
123 if (keyboard_controller) 133 if (keyboard_controller)
124 keyboard_controller->AddObserver(this); 134 keyboard_controller->AddObserver(this);
125 } 135 }
126 136
127 void VirtualKeyboardTray::UnobserveKeyboardController() { 137 void VirtualKeyboardTray::UnobserveKeyboardController() {
128 keyboard::KeyboardController* keyboard_controller = 138 keyboard::KeyboardController* keyboard_controller =
129 keyboard::KeyboardController::GetInstance(); 139 keyboard::KeyboardController::GetInstance();
130 if (keyboard_controller) 140 if (keyboard_controller)
131 keyboard_controller->RemoveObserver(this); 141 keyboard_controller->RemoveObserver(this);
132 } 142 }
133 143
134 } // namespace ash 144 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698