Commit 2ff761db authored by Tetsui Ohkubo's avatar Tetsui Ohkubo Committed by Commit Bot

Add ime feature pod button.

This CL adds a feature pod button for IME. By clicking on the button,
it will show IME detailed view of the existing SystemTray. This behavior
is described as Development Stage 1 in the design doc:
go/cros-qs-restyling

Screenshot: http://screen/scc32RkykN2

TEST=manual
BUG=821671

Change-Id: I156db2af966d13082079e639e2c46805b0453995
Reviewed-on: https://chromium-review.googlesource.com/961748
Commit-Queue: Tetsui Ohkubo <tetsui@chromium.org>
Reviewed-by: default avatarYoshiki Iguchi <yoshiki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543640}
parent 1214a911
......@@ -531,6 +531,8 @@ component("ash") {
"system/enterprise/tray_enterprise.h",
"system/flag_warning/flag_warning_tray.cc",
"system/flag_warning/flag_warning_tray.h",
"system/ime/ime_feature_pod_controller.cc",
"system/ime/ime_feature_pod_controller.h",
"system/ime/ime_observer.h",
"system/ime/tray_ime_chromeos.cc",
"system/ime/tray_ime_chromeos.h",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/ime/ime_feature_pod_controller.h"
#include "ash/ime/ime_controller.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/unified/feature_pod_button.h"
#include "ash/system/unified/unified_system_tray_controller.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/keyboard/keyboard_util.h"
namespace ash {
namespace {
bool IsButtonVisible() {
DCHECK(Shell::Get());
ImeController* ime_controller = Shell::Get()->ime_controller();
size_t ime_count = ime_controller->available_imes().size();
return ime_count > 1;
}
base::string16 GetLabelString() {
DCHECK(Shell::Get());
ImeController* ime_controller = Shell::Get()->ime_controller();
size_t ime_count = ime_controller->available_imes().size();
if (ime_count > 1) {
return ime_controller->current_ime().name;
} else {
return l10n_util::GetStringUTF16(
keyboard::IsKeyboardEnabled() ? IDS_ASH_STATUS_TRAY_KEYBOARD_ENABLED
: IDS_ASH_STATUS_TRAY_KEYBOARD_DISABLED);
}
}
} // namespace
IMEFeaturePodController::IMEFeaturePodController(
UnifiedSystemTrayController* tray_controller)
: tray_controller_(tray_controller) {}
IMEFeaturePodController::~IMEFeaturePodController() = default;
FeaturePodButton* IMEFeaturePodController::CreateButton() {
button_ = new FeaturePodButton(this);
button_->SetVectorIcon(kSystemMenuKeyboardIcon);
Update();
return button_;
}
void IMEFeaturePodController::OnPressed() {
tray_controller_->ShowIMEDetailedView();
}
void IMEFeaturePodController::Update() {
button_->SetLabel(GetLabelString());
button_->SetVisible(IsButtonVisible());
}
} // namespace ash
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SYSTEM_IME_IME_FEATURE_POD_CONTROLLER_H_
#define ASH_SYSTEM_IME_IME_FEATURE_POD_CONTROLLER_H_
#include "ash/ash_export.h"
#include "ash/system/unified/feature_pod_controller_base.h"
#include "base/macros.h"
namespace ash {
class UnifiedSystemTrayController;
// Controller of IME feature pod button.
class ASH_EXPORT IMEFeaturePodController : public FeaturePodControllerBase {
public:
IMEFeaturePodController(UnifiedSystemTrayController* tray_controller);
~IMEFeaturePodController() override;
// FeaturePodControllerBase:
FeaturePodButton* CreateButton() override;
void OnPressed() override;
private:
void Update();
// Unowned.
UnifiedSystemTrayController* const tray_controller_;
FeaturePodButton* button_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(IMEFeaturePodController);
};
} // namespace ash
#endif // ASH_SYSTEM_IME_IME_FEATURE_POD_CONTROLLER_H_
......@@ -260,7 +260,8 @@ void SystemTray::CreateItems() {
AddTrayItem(base::WrapUnique(tray_enterprise_));
tray_supervised_user_ = new TraySupervisedUser(this);
AddTrayItem(base::WrapUnique(tray_supervised_user_));
AddTrayItem(std::make_unique<TrayIME>(this));
tray_ime_ = new TrayIME(this);
AddTrayItem(base::WrapUnique(tray_ime_));
tray_accessibility_ = new TrayAccessibility(this);
AddTrayItem(base::WrapUnique(tray_accessibility_));
tray_tracing_ = new TrayTracing(this);
......@@ -414,6 +415,10 @@ TrayAccessibility* SystemTray::GetTrayAccessibility() const {
return tray_accessibility_;
}
TrayIME* SystemTray::GetTrayIME() const {
return tray_ime_;
}
void SystemTray::CanSwitchAwayFromActiveUser(
base::OnceCallback<void(bool)> callback) {
// If neither screen sharing nor capturing is going on we can immediately
......
......@@ -30,6 +30,7 @@ class TrayBluetooth;
class TrayCapsLock;
class TrayCast;
class TrayEnterprise;
class TrayIME;
class TrayNetwork;
class TrayNightLight;
class TrayScale;
......@@ -126,6 +127,8 @@ class ASH_EXPORT SystemTray : public TrayBackgroundView {
TrayBluetooth* GetTrayBluetooth() const;
// Returns TrayAccessibility object if present or null otherwise.
TrayAccessibility* GetTrayAccessibility() const;
// Returns TrayIME object if present or null otherwise.
TrayIME* GetTrayIME() const;
// Determines if it's ok to switch away from the currently active user. Screen
// casting may block this (or at least throw up a confirmation dialog). Calls
......@@ -225,6 +228,7 @@ class ASH_EXPORT SystemTray : public TrayBackgroundView {
TrayCapsLock* tray_caps_lock_ = nullptr;
TrayCast* tray_cast_ = nullptr;
TrayEnterprise* tray_enterprise_ = nullptr;
TrayIME* tray_ime_ = nullptr;
TrayNetwork* tray_network_ = nullptr;
TrayTiles* tray_tiles_ = nullptr;
TrayScale* tray_scale_ = nullptr;
......
......@@ -12,6 +12,8 @@
#include "ash/system/bluetooth/bluetooth_feature_pod_controller.h"
#include "ash/system/bluetooth/tray_bluetooth.h"
#include "ash/system/brightness/unified_brightness_slider_controller.h"
#include "ash/system/ime/ime_feature_pod_controller.h"
#include "ash/system/ime/tray_ime_chromeos.h"
#include "ash/system/network/network_feature_pod_controller.h"
#include "ash/system/network/tray_network.h"
#include "ash/system/night_light/night_light_feature_pod_controller.h"
......@@ -83,7 +85,8 @@ void UnifiedSystemTrayController::ShowNetworkDetailedView() {
// Initially create default view to set |default_bubble_height_|.
system_tray_->ShowDefaultView(BubbleCreationType::BUBBLE_CREATE_NEW,
true /* show_by_click */);
system_tray_->ShowDetailedView(system_tray_->GetTrayNetwork(), 0,
system_tray_->ShowDetailedView(system_tray_->GetTrayNetwork(),
0 /* close_delay_in_seconds */,
BubbleCreationType::BUBBLE_USE_EXISTING);
}
......@@ -93,7 +96,8 @@ void UnifiedSystemTrayController::ShowBluetoothDetailedView() {
// Initially create default view to set |default_bubble_height_|.
system_tray_->ShowDefaultView(BubbleCreationType::BUBBLE_CREATE_NEW,
true /* show_by_click */);
system_tray_->ShowDetailedView(system_tray_->GetTrayBluetooth(), 0,
system_tray_->ShowDetailedView(system_tray_->GetTrayBluetooth(),
0 /* close_delay_in_seconds */,
BubbleCreationType::BUBBLE_USE_EXISTING);
}
......@@ -103,7 +107,18 @@ void UnifiedSystemTrayController::ShowAccessibilityDetailedView() {
// Initially create default view to set |default_bubble_height_|.
system_tray_->ShowDefaultView(BubbleCreationType::BUBBLE_CREATE_NEW,
true /* show_by_click */);
system_tray_->ShowDetailedView(system_tray_->GetTrayAccessibility(), 0,
system_tray_->ShowDetailedView(system_tray_->GetTrayAccessibility(),
0 /* close_delay_in_seconds */,
BubbleCreationType::BUBBLE_USE_EXISTING);
}
void UnifiedSystemTrayController::ShowIMEDetailedView() {
// TODO(tetsui): Implement UnifiedSystemTray's IME detailed view.
// Initially create default view to set |default_bubble_height_|.
system_tray_->ShowDefaultView(BubbleCreationType::BUBBLE_CREATE_NEW,
true /* show_by_click */);
system_tray_->ShowDetailedView(system_tray_->GetTrayIME(),
0 /* close_delay_in_seconds */,
BubbleCreationType::BUBBLE_USE_EXISTING);
}
......@@ -114,6 +129,7 @@ void UnifiedSystemTrayController::InitFeaturePods() {
AddFeaturePodItem(std::make_unique<RotationLockFeaturePodController>());
AddFeaturePodItem(std::make_unique<NightLightFeaturePodController>());
AddFeaturePodItem(std::make_unique<AccessibilityFeaturePodController>(this));
AddFeaturePodItem(std::make_unique<IMEFeaturePodController>(this));
// If you want to add a new feature pod item, add here.
// TODO(tetsui): Add more feature pod items in spec.
......
......@@ -47,6 +47,8 @@ class ASH_EXPORT UnifiedSystemTrayController {
void ShowBluetoothDetailedView();
// Show the detailed view of accessibility. Called from the view.
void ShowAccessibilityDetailedView();
// Show the detailed view of IME. Called from the view.
void ShowIMEDetailedView();
private:
// Initialize feature pod controllers and their views.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment