Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" | |
| 12 #include "ash/common/shelf/wm_shelf_util.h" | 13 #include "ash/common/shelf/wm_shelf_util.h" |
| 14 #include "ash/common/system/chromeos/session/logout_button_tray.h" | |
| 13 #include "ash/common/system/tray/tray_constants.h" | 15 #include "ash/common/system/tray/tray_constants.h" |
| 14 #include "ash/common/system/tray/tray_utils.h" | 16 #include "ash/common/system/tray/tray_utils.h" |
| 15 #include "ash/common/wm_shell.h" | 17 #include "ash/common/wm_shell.h" |
| 16 #include "grit/ash_resources.h" | 18 #include "grit/ash_resources.h" |
| 17 #include "grit/ash_strings.h" | 19 #include "grit/ash_strings.h" |
| 18 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 19 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
| 20 #include "ui/events/event.h" | 22 #include "ui/events/event.h" |
| 21 #include "ui/gfx/image/image_skia.h" | 23 #include "ui/gfx/image/image_skia.h" |
| 22 #include "ui/gfx/paint_vector_icon.h" | 24 #include "ui/gfx/paint_vector_icon.h" |
| 23 #include "ui/gfx/vector_icons_public.h" | 25 #include "ui/gfx/vector_icons_public.h" |
| 24 #include "ui/views/controls/button/image_button.h" | 26 #include "ui/views/controls/button/image_button.h" |
| 25 | 27 |
| 26 namespace ash { | 28 namespace ash { |
| 27 | 29 |
| 28 VirtualKeyboardTray::VirtualKeyboardTray(WmShelf* wm_shelf) | 30 VirtualKeyboardTray::VirtualKeyboardTray(WmShelf* wm_shelf) |
| 29 : TrayBackgroundView(wm_shelf), button_(nullptr) { | 31 : TrayBackgroundView(wm_shelf), |
| 32 button_(nullptr), | |
| 33 logout_button_tray_(nullptr) { | |
| 30 button_ = new views::ImageButton(this); | 34 button_ = new views::ImageButton(this); |
| 31 if (MaterialDesignController::IsShelfMaterial()) { | 35 if (MaterialDesignController::IsShelfMaterial()) { |
| 32 gfx::ImageSkia image_md = | 36 gfx::ImageSkia image_md = |
| 33 CreateVectorIcon(gfx::VectorIconId::SHELF_KEYBOARD, kShelfIconColor); | 37 CreateVectorIcon(gfx::VectorIconId::SHELF_KEYBOARD, kShelfIconColor); |
| 34 button_->SetImage(views::CustomButton::STATE_NORMAL, &image_md); | 38 button_->SetImage(views::CustomButton::STATE_NORMAL, &image_md); |
| 35 } else { | 39 } else { |
| 36 gfx::ImageSkia* image_non_md = | 40 gfx::ImageSkia* image_non_md = |
| 37 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 41 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 38 IDR_AURA_UBER_TRAY_VIRTUAL_KEYBOARD); | 42 IDR_AURA_UBER_TRAY_VIRTUAL_KEYBOARD); |
| 39 button_->SetImage(views::CustomButton::STATE_NORMAL, image_non_md); | 43 button_->SetImage(views::CustomButton::STATE_NORMAL, image_non_md); |
| 40 } | 44 } |
| 41 button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, | 45 button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, |
| 42 views::ImageButton::ALIGN_MIDDLE); | 46 views::ImageButton::ALIGN_MIDDLE); |
| 43 | 47 |
| 44 tray_container()->AddChildView(button_); | 48 tray_container()->AddChildView(button_); |
| 45 button_->SetFocusBehavior(FocusBehavior::NEVER); | 49 button_->SetFocusBehavior(FocusBehavior::NEVER); |
| 46 SetContentsBackground(); | 50 SetContentsBackground(); |
| 47 // The Shell may not exist in some unit tests. | 51 // The Shell may not exist in some unit tests. |
| 48 if (WmShell::HasInstance()) | 52 if (WmShell::HasInstance()) |
| 49 WmShell::Get()->keyboard_ui()->AddObserver(this); | 53 WmShell::Get()->keyboard_ui()->AddObserver(this); |
| 50 } | 54 } |
| 51 | 55 |
| 52 VirtualKeyboardTray::~VirtualKeyboardTray() { | 56 VirtualKeyboardTray::~VirtualKeyboardTray() { |
| 53 // The Shell may not exist in some unit tests. | 57 // The Shell may not exist in some unit tests. |
| 54 if (WmShell::HasInstance()) | 58 if (WmShell::HasInstance()) |
| 55 WmShell::Get()->keyboard_ui()->RemoveObserver(this); | 59 WmShell::Get()->keyboard_ui()->RemoveObserver(this); |
| 56 } | 60 } |
| 57 | 61 |
| 62 void VirtualKeyboardTray::Shutdown() { | |
| 63 DCHECK(logout_button_tray_); | |
| 64 logout_button_tray_ = nullptr; | |
| 65 } | |
| 66 | |
| 67 void VirtualKeyboardTray::InitializeTrayItems( | |
| 68 LogoutButtonTray* logout_button_tray) { | |
| 69 logout_button_tray_ = logout_button_tray; | |
| 70 TrayBackgroundView::Initialize(); | |
| 71 } | |
| 72 | |
| 58 void VirtualKeyboardTray::SetShelfAlignment(ShelfAlignment alignment) { | 73 void VirtualKeyboardTray::SetShelfAlignment(ShelfAlignment alignment) { |
| 59 TrayBackgroundView::SetShelfAlignment(alignment); | 74 TrayBackgroundView::SetShelfAlignment(alignment); |
| 60 tray_container()->SetBorder(views::Border::NullBorder()); | |
| 61 | 75 |
| 62 // Pad button size to align with other controls in the system tray. | 76 // Pad button size to align with other controls in the system tray. |
| 63 const gfx::ImageSkia image = | 77 const gfx::ImageSkia image = |
| 64 button_->GetImage(views::CustomButton::STATE_NORMAL); | 78 button_->GetImage(views::CustomButton::STATE_NORMAL); |
| 65 const int size = GetTrayConstant(VIRTUAL_KEYBOARD_BUTTON_SIZE); | 79 const int size = GetTrayConstant(VIRTUAL_KEYBOARD_BUTTON_SIZE); |
| 66 const int vertical_padding = (size - image.height()) / 2; | 80 const int vertical_padding = (size - image.height()) / 2; |
| 67 int horizontal_padding = (size - image.width()) / 2; | 81 int horizontal_padding = (size - image.width()) / 2; |
| 68 if (!ash::MaterialDesignController::IsShelfMaterial() && | 82 if (!ash::MaterialDesignController::IsShelfMaterial() && |
| 69 IsHorizontalAlignment(alignment)) { | 83 IsHorizontalAlignment(alignment)) { |
| 70 // Square up the padding if horizontally aligned. Avoid extra padding when | 84 // Square up the padding if horizontally aligned. Avoid extra padding when |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 95 void VirtualKeyboardTray::ButtonPressed(views::Button* sender, | 109 void VirtualKeyboardTray::ButtonPressed(views::Button* sender, |
| 96 const ui::Event& event) { | 110 const ui::Event& event) { |
| 97 DCHECK_EQ(button_, sender); | 111 DCHECK_EQ(button_, sender); |
| 98 PerformAction(event); | 112 PerformAction(event); |
| 99 } | 113 } |
| 100 | 114 |
| 101 void VirtualKeyboardTray::OnKeyboardEnabledStateChanged(bool new_value) { | 115 void VirtualKeyboardTray::OnKeyboardEnabledStateChanged(bool new_value) { |
| 102 SetVisible(WmShell::Get()->keyboard_ui()->IsEnabled()); | 116 SetVisible(WmShell::Get()->keyboard_ui()->IsEnabled()); |
| 103 } | 117 } |
| 104 | 118 |
| 119 void VirtualKeyboardTray::OnPaint(gfx::Canvas* canvas) { | |
| 120 // Paints a 1px separator to separate with the tray to the right. No separator | |
| 121 // requires in front of Logout Button because it is red and appealing by | |
|
varkha
2016/07/14 21:34:46
How about:
Paints a line to separate from the subs
yiyix
2016/07/26 20:27:30
No need to emphasize that the separator is 1px? I
| |
| 122 // itself. | |
| 123 if (!logout_button_tray_->visible()) | |
| 124 DrawSeparator(canvas); | |
| 125 } | |
| 126 | |
| 105 } // namespace ash | 127 } // namespace ash |
| OLD | NEW |