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

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: merge 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"
11 #include "ash/common/shelf/shelf_constants.h" 11 #include "ash/common/shelf/shelf_constants.h"
12 #include "ash/common/shelf/wm_shelf.h"
13 #include "ash/common/shelf/wm_shelf_observer.h"
12 #include "ash/common/shelf/wm_shelf_util.h" 14 #include "ash/common/shelf/wm_shelf_util.h"
15 #include "ash/common/system/chromeos/session/logout_button_tray.h"
13 #include "ash/common/system/tray/tray_constants.h" 16 #include "ash/common/system/tray/tray_constants.h"
14 #include "ash/common/system/tray/tray_utils.h" 17 #include "ash/common/system/tray/tray_utils.h"
15 #include "ash/common/wm_shell.h" 18 #include "ash/common/wm_shell.h"
16 #include "grit/ash_resources.h" 19 #include "grit/ash_resources.h"
17 #include "grit/ash_strings.h" 20 #include "grit/ash_strings.h"
18 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/base/resource/resource_bundle.h" 22 #include "ui/base/resource/resource_bundle.h"
20 #include "ui/events/event.h" 23 #include "ui/events/event.h"
21 #include "ui/gfx/image/image_skia.h" 24 #include "ui/gfx/image/image_skia.h"
22 #include "ui/gfx/paint_vector_icon.h" 25 #include "ui/gfx/paint_vector_icon.h"
23 #include "ui/gfx/vector_icons_public.h" 26 #include "ui/gfx/vector_icons_public.h"
24 #include "ui/keyboard/keyboard_controller.h" 27 #include "ui/keyboard/keyboard_controller.h"
25 #include "ui/views/controls/image_view.h" 28 #include "ui/views/controls/image_view.h"
26 29
27 namespace ash { 30 namespace ash {
28 31
29 VirtualKeyboardTray::VirtualKeyboardTray(WmShelf* wm_shelf) 32 VirtualKeyboardTray::VirtualKeyboardTray(WmShelf* wm_shelf,
30 : TrayBackgroundView(wm_shelf), icon_(new views::ImageView) { 33 WmShelfObserver* wm_shelf_observer)
34 : TrayBackgroundView(wm_shelf, wm_shelf_observer),
35 icon_(new views::ImageView) {
31 if (MaterialDesignController::IsShelfMaterial()) { 36 if (MaterialDesignController::IsShelfMaterial()) {
32 gfx::ImageSkia image_md = 37 gfx::ImageSkia image_md =
33 CreateVectorIcon(gfx::VectorIconId::SHELF_KEYBOARD, kShelfIconColor); 38 CreateVectorIcon(gfx::VectorIconId::SHELF_KEYBOARD, kShelfIconColor);
34 icon_->SetImage(image_md); 39 icon_->SetImage(image_md);
35 } else { 40 } else {
36 gfx::ImageSkia* image_non_md = 41 gfx::ImageSkia* image_non_md =
37 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 42 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
38 IDR_AURA_UBER_TRAY_VIRTUAL_KEYBOARD); 43 IDR_AURA_UBER_TRAY_VIRTUAL_KEYBOARD);
39 icon_->SetImage(image_non_md); 44 icon_->SetImage(image_non_md);
40 } 45 }
(...skipping 13 matching lines...) Expand all
54 UnobserveKeyboardController(); 59 UnobserveKeyboardController();
55 // The Shell may not exist in some unit tests. 60 // The Shell may not exist in some unit tests.
56 if (WmShell::HasInstance()) 61 if (WmShell::HasInstance())
57 WmShell::Get()->keyboard_ui()->RemoveObserver(this); 62 WmShell::Get()->keyboard_ui()->RemoveObserver(this);
58 } 63 }
59 64
60 void VirtualKeyboardTray::SetShelfAlignment(ShelfAlignment alignment) { 65 void VirtualKeyboardTray::SetShelfAlignment(ShelfAlignment alignment) {
61 if (alignment == shelf_alignment()) 66 if (alignment == shelf_alignment())
62 return; 67 return;
63 68
69 // Pad button size to align with other controls in the system tray.
70 const gfx::ImageSkia image = icon_->GetImage();
71 const int size = GetTrayConstant(VIRTUAL_KEYBOARD_BUTTON_SIZE);
72 const int vertical_padding = (size - image.height()) / 2;
73 int horizontal_padding = (size - image.width()) / 2;
74 if (!ash::MaterialDesignController::IsShelfMaterial() &&
75 IsHorizontalAlignment(alignment)) {
76 // Square up the padding if horizontally aligned. Avoid extra padding when
77 // vertically aligned as the button would violate the width constraint on
78 // the shelf.
79 horizontal_padding += std::max(0, vertical_padding - horizontal_padding);
80 }
81
64 TrayBackgroundView::SetShelfAlignment(alignment); 82 TrayBackgroundView::SetShelfAlignment(alignment);
65 SetIconBorderForShelfAlignment(); 83 SetIconBorderForShelfAlignment();
66 } 84 }
67 85
68 base::string16 VirtualKeyboardTray::GetAccessibleNameForTray() { 86 base::string16 VirtualKeyboardTray::GetAccessibleNameForTray() {
69 return l10n_util::GetStringUTF16( 87 return l10n_util::GetStringUTF16(
70 IDS_ASH_VIRTUAL_KEYBOARD_TRAY_ACCESSIBLE_NAME); 88 IDS_ASH_VIRTUAL_KEYBOARD_TRAY_ACCESSIBLE_NAME);
71 } 89 }
72 90
73 void VirtualKeyboardTray::HideBubbleWithView( 91 void VirtualKeyboardTray::HideBubbleWithView(
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 } 139 }
122 140
123 void VirtualKeyboardTray::UnobserveKeyboardController() { 141 void VirtualKeyboardTray::UnobserveKeyboardController() {
124 keyboard::KeyboardController* keyboard_controller = 142 keyboard::KeyboardController* keyboard_controller =
125 keyboard::KeyboardController::GetInstance(); 143 keyboard::KeyboardController::GetInstance();
126 if (keyboard_controller) 144 if (keyboard_controller)
127 keyboard_controller->RemoveObserver(this); 145 keyboard_controller->RemoveObserver(this);
128 } 146 }
129 147
130 } // namespace ash 148 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698