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

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

Issue 2103053004: mash: Convert virtual keyboard system tray item to wm common types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 5 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ash/system/chromeos/virtual_keyboard/virtual_keyboard_tray.h"
6
7 #include "ash/common/keyboard/keyboard_ui.h"
8 #include "ash/common/material_design/material_design_controller.h"
9 #include "ash/common/shelf/shelf_constants.h"
10 #include "ash/common/shelf/wm_shelf_util.h"
11 #include "ash/common/system/tray/tray_constants.h"
12 #include "ash/common/system/tray/tray_utils.h"
13 #include "ash/shell.h"
14 #include "grit/ash_resources.h"
15 #include "grit/ash_strings.h"
16 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/events/event.h"
19 #include "ui/gfx/image/image_skia.h"
20 #include "ui/gfx/paint_vector_icon.h"
21 #include "ui/gfx/vector_icons_public.h"
22 #include "ui/views/controls/button/image_button.h"
23
24 namespace ash {
25
26 VirtualKeyboardTray::VirtualKeyboardTray(WmShelf* wm_shelf)
27 : TrayBackgroundView(wm_shelf), button_(nullptr) {
28 button_ = new views::ImageButton(this);
29 if (MaterialDesignController::IsShelfMaterial()) {
30 gfx::ImageSkia image_md =
31 CreateVectorIcon(gfx::VectorIconId::SHELF_KEYBOARD, kShelfIconColor);
32 button_->SetImage(views::CustomButton::STATE_NORMAL, &image_md);
33 } else {
34 gfx::ImageSkia* image_non_md =
35 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
36 IDR_AURA_UBER_TRAY_VIRTUAL_KEYBOARD);
37 button_->SetImage(views::CustomButton::STATE_NORMAL, image_non_md);
38 }
39 button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER,
40 views::ImageButton::ALIGN_MIDDLE);
41
42 tray_container()->AddChildView(button_);
43 button_->SetFocusBehavior(FocusBehavior::NEVER);
44 SetContentsBackground();
45 // The Shell may not exist in some unit tests.
46 if (Shell::HasInstance())
47 Shell::GetInstance()->keyboard_ui()->AddObserver(this);
48 }
49
50 VirtualKeyboardTray::~VirtualKeyboardTray() {
51 // The Shell may not exist in some unit tests.
52 if (Shell::HasInstance())
53 Shell::GetInstance()->keyboard_ui()->RemoveObserver(this);
54 }
55
56 void VirtualKeyboardTray::SetShelfAlignment(ShelfAlignment alignment) {
57 TrayBackgroundView::SetShelfAlignment(alignment);
58 tray_container()->SetBorder(views::Border::NullBorder());
59
60 // Pad button size to align with other controls in the system tray.
61 const gfx::ImageSkia image =
62 button_->GetImage(views::CustomButton::STATE_NORMAL);
63 const int size = GetTrayConstant(VIRTUAL_KEYBOARD_BUTTON_SIZE);
64 const int vertical_padding = (size - image.height()) / 2;
65 int horizontal_padding = (size - image.width()) / 2;
66 if (!ash::MaterialDesignController::IsShelfMaterial() &&
67 IsHorizontalAlignment(alignment)) {
68 // Square up the padding if horizontally aligned. Avoid extra padding when
69 // vertically aligned as the button would violate the width constraint on
70 // the shelf.
71 horizontal_padding += std::max(0, vertical_padding - horizontal_padding);
72 }
73
74 button_->SetBorder(views::Border::CreateEmptyBorder(
75 gfx::Insets(vertical_padding, horizontal_padding)));
76 }
77
78 base::string16 VirtualKeyboardTray::GetAccessibleNameForTray() {
79 return l10n_util::GetStringUTF16(
80 IDS_ASH_VIRTUAL_KEYBOARD_TRAY_ACCESSIBLE_NAME);
81 }
82
83 void VirtualKeyboardTray::HideBubbleWithView(
84 const views::TrayBubbleView* bubble_view) {}
85
86 void VirtualKeyboardTray::ClickedOutsideBubble() {}
87
88 bool VirtualKeyboardTray::PerformAction(const ui::Event& event) {
89 Shell::GetInstance()->keyboard_ui()->Show();
90 return true;
91 }
92
93 void VirtualKeyboardTray::ButtonPressed(views::Button* sender,
94 const ui::Event& event) {
95 DCHECK_EQ(button_, sender);
96 PerformAction(event);
97 }
98
99 void VirtualKeyboardTray::OnKeyboardEnabledStateChanged(bool new_value) {
100 SetVisible(Shell::GetInstance()->keyboard_ui()->IsEnabled());
101 }
102
103 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/chromeos/virtual_keyboard/virtual_keyboard_tray.h ('k') | ash/system/status_area_widget.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698