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

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: tweak 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 int top_padding = (kTrayBarButtonWidth - image.height()) / 2;
64 int left_padding = (kTrayBarButtonWidth - image.width()) / 2;
65 int bottom_padding = kTrayBarButtonWidth - image.height() - top_padding;
66 int right_padding = kTrayBarButtonWidth - image.width() - left_padding;
67
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
70 // shelf.
71 if (IsHorizontalAlignment(alignment)) {
72 int additional_padding = std::max(0, top_padding - left_padding);
73 left_padding += additional_padding;
74 right_padding += additional_padding;
75 }
76
77 button_->SetBorder(views::Border::CreateEmptyBorder(
78 top_padding, left_padding, bottom_padding, right_padding));
79 }
80
81 base::string16 VirtualKeyboardTray::GetAccessibleNameForTray() {
82 return l10n_util::GetStringUTF16(
83 IDS_ASH_VIRTUAL_KEYBOARD_TRAY_ACCESSIBLE_NAME);
84 }
85
86 void VirtualKeyboardTray::HideBubbleWithView(
87 const views::TrayBubbleView* bubble_view) {}
88
89 void VirtualKeyboardTray::ClickedOutsideBubble() {}
90
91 bool VirtualKeyboardTray::PerformAction(const ui::Event& event) {
92 Shell::GetInstance()->keyboard_ui()->Show();
93 return true;
94 }
95
96 void VirtualKeyboardTray::ButtonPressed(views::Button* sender,
97 const ui::Event& event) {
98 DCHECK_EQ(button_, sender);
99 PerformAction(event);
100 }
101
102 void VirtualKeyboardTray::OnKeyboardEnabledStateChanged(bool new_value) {
103 SetVisible(Shell::GetInstance()->keyboard_ui()->IsEnabled());
104 }
105
106 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698