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

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

Issue 2712733003: Remove non-MD code from VirtualKeyboardTray (Closed)
Patch Set: Addressed review comments Created 3 years, 10 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
« no previous file with comments | « no previous file | ash/common/system/tray/tray_constants.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "ash/common/shelf/shelf_constants.h" 10 #include "ash/common/shelf/shelf_constants.h"
12 #include "ash/common/shelf/wm_shelf.h" 11 #include "ash/common/shelf/wm_shelf.h"
13 #include "ash/common/shelf/wm_shelf_util.h"
14 #include "ash/common/system/tray/tray_constants.h" 12 #include "ash/common/system/tray/tray_constants.h"
15 #include "ash/common/system/tray/tray_utils.h"
16 #include "ash/common/wm_shell.h" 13 #include "ash/common/wm_shell.h"
17 #include "ash/common/wm_window.h" 14 #include "ash/common/wm_window.h"
18 #include "ash/resources/grit/ash_resources.h"
19 #include "ash/resources/vector_icons/vector_icons.h" 15 #include "ash/resources/vector_icons/vector_icons.h"
20 #include "grit/ash_strings.h" 16 #include "grit/ash_strings.h"
21 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
22 #include "ui/base/resource/resource_bundle.h"
23 #include "ui/display/display.h" 18 #include "ui/display/display.h"
24 #include "ui/events/event.h" 19 #include "ui/events/event.h"
25 #include "ui/gfx/image/image_skia.h" 20 #include "ui/gfx/image/image_skia.h"
26 #include "ui/gfx/paint_vector_icon.h" 21 #include "ui/gfx/paint_vector_icon.h"
27 #include "ui/keyboard/keyboard_controller.h" 22 #include "ui/keyboard/keyboard_controller.h"
28 #include "ui/views/controls/image_view.h" 23 #include "ui/views/controls/image_view.h"
29 24
30 namespace ash { 25 namespace ash {
31 26
32 VirtualKeyboardTray::VirtualKeyboardTray(WmShelf* wm_shelf) 27 VirtualKeyboardTray::VirtualKeyboardTray(WmShelf* wm_shelf)
33 : TrayBackgroundView(wm_shelf), 28 : TrayBackgroundView(wm_shelf),
34 icon_(new views::ImageView), 29 icon_(new views::ImageView),
35 wm_shelf_(wm_shelf) { 30 wm_shelf_(wm_shelf) {
36 if (MaterialDesignController::IsShelfMaterial()) { 31 SetInkDropMode(InkDropMode::ON);
37 SetInkDropMode(InkDropMode::ON); 32 SetContentsBackground(false);
38 SetContentsBackground(false);
39 gfx::ImageSkia image_md =
40 CreateVectorIcon(kShelfKeyboardIcon, kShelfIconColor);
41 icon_->SetImage(image_md);
42 } else {
43 SetContentsBackground(true);
44 gfx::ImageSkia* image_non_md =
45 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
46 IDR_AURA_UBER_TRAY_VIRTUAL_KEYBOARD);
47 icon_->SetImage(image_non_md);
48 }
49 33
34 icon_->SetImage(gfx::CreateVectorIcon(kShelfKeyboardIcon, kShelfIconColor));
50 SetIconBorderForShelfAlignment(); 35 SetIconBorderForShelfAlignment();
51 tray_container()->AddChildView(icon_); 36 tray_container()->AddChildView(icon_);
37
52 // The Shell may not exist in some unit tests. 38 // The Shell may not exist in some unit tests.
53 if (WmShell::HasInstance()) 39 if (WmShell::HasInstance())
54 WmShell::Get()->keyboard_ui()->AddObserver(this); 40 WmShell::Get()->keyboard_ui()->AddObserver(this);
55 // Try observing keyboard controller, in case it is already constructed. 41 // Try observing keyboard controller, in case it is already constructed.
56 ObserveKeyboardController(); 42 ObserveKeyboardController();
57 } 43 }
58 44
59 VirtualKeyboardTray::~VirtualKeyboardTray() { 45 VirtualKeyboardTray::~VirtualKeyboardTray() {
60 // Try unobserving keyboard controller, in case it still exists. 46 // Try unobserving keyboard controller, in case it still exists.
61 UnobserveKeyboardController(); 47 UnobserveKeyboardController();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 } 94 }
109 95
110 void VirtualKeyboardTray::OnKeyboardBoundsChanging( 96 void VirtualKeyboardTray::OnKeyboardBoundsChanging(
111 const gfx::Rect& new_bounds) { 97 const gfx::Rect& new_bounds) {
112 SetIsActive(!new_bounds.IsEmpty()); 98 SetIsActive(!new_bounds.IsEmpty());
113 } 99 }
114 100
115 void VirtualKeyboardTray::OnKeyboardClosed() {} 101 void VirtualKeyboardTray::OnKeyboardClosed() {}
116 102
117 void VirtualKeyboardTray::SetIconBorderForShelfAlignment() { 103 void VirtualKeyboardTray::SetIconBorderForShelfAlignment() {
118 // Every time shelf alignment is updated, StatusAreaWidgetDelegate resets the
119 // border to a non-null border. So, we need to remove it.
120 if (!ash::MaterialDesignController::IsShelfMaterial())
121 tray_container()->SetBorder(views::NullBorder());
122 const gfx::ImageSkia& image = icon_->GetImage(); 104 const gfx::ImageSkia& image = icon_->GetImage();
123 const int size = GetTrayConstant(VIRTUAL_KEYBOARD_BUTTON_SIZE); 105 const int vertical_padding = (kTrayItemSize - image.height()) / 2;
124 const int vertical_padding = (size - image.height()) / 2; 106 const int horizontal_padding = (kTrayItemSize - image.width()) / 2;
125 int horizontal_padding = (size - image.width()) / 2;
126 if (!ash::MaterialDesignController::IsShelfMaterial() &&
127 IsHorizontalAlignment(shelf_alignment())) {
128 // Square up the padding if horizontally aligned. Avoid extra padding when
129 // vertically aligned as the button would violate the width constraint on
130 // the shelf.
131 horizontal_padding += std::max(0, vertical_padding - horizontal_padding);
132 }
133 icon_->SetBorder(views::CreateEmptyBorder( 107 icon_->SetBorder(views::CreateEmptyBorder(
134 gfx::Insets(vertical_padding, horizontal_padding))); 108 gfx::Insets(vertical_padding, horizontal_padding)));
135 } 109 }
136 110
137 void VirtualKeyboardTray::ObserveKeyboardController() { 111 void VirtualKeyboardTray::ObserveKeyboardController() {
138 keyboard::KeyboardController* keyboard_controller = 112 keyboard::KeyboardController* keyboard_controller =
139 keyboard::KeyboardController::GetInstance(); 113 keyboard::KeyboardController::GetInstance();
140 if (keyboard_controller) 114 if (keyboard_controller)
141 keyboard_controller->AddObserver(this); 115 keyboard_controller->AddObserver(this);
142 } 116 }
143 117
144 void VirtualKeyboardTray::UnobserveKeyboardController() { 118 void VirtualKeyboardTray::UnobserveKeyboardController() {
145 keyboard::KeyboardController* keyboard_controller = 119 keyboard::KeyboardController* keyboard_controller =
146 keyboard::KeyboardController::GetInstance(); 120 keyboard::KeyboardController::GetInstance();
147 if (keyboard_controller) 121 if (keyboard_controller)
148 keyboard_controller->RemoveObserver(this); 122 keyboard_controller->RemoveObserver(this);
149 } 123 }
150 124
151 } // namespace ash 125 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/common/system/tray/tray_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698