Commit fc132218 authored by Tetsui Ohkubo's avatar Tetsui Ohkubo Committed by Commit Bot

Add RotationLock feature pod button.

This CL adds a feature pod button that can toggle RotationLock state.
The button is only visible when tablet mode is enabled.

Screenshot: http://screen/iPZnUeRwsRd

UnifiedSystemTray design doc: go/cros-qs-restyling

TEST=RotationLockFeaturePodControllerTest
TEST=out/Release/chrome --enable-features=SystemTrayUnified --force-tablet-mode=touch_view
BUG=813499

Change-Id: Ia8aff60ea3e0a704024e1402bd6bb52e4f3783c4
Reviewed-on: https://chromium-review.googlesource.com/948223Reviewed-by: default avatarYoshiki Iguchi <yoshiki@chromium.org>
Commit-Queue: Tetsui Ohkubo <tetsui@chromium.org>
Cr-Commit-Position: refs/heads/master@{#541046}
parent bc3ea16c
...@@ -638,6 +638,8 @@ component("ash") { ...@@ -638,6 +638,8 @@ component("ash") {
"system/power/tray_power.h", "system/power/tray_power.h",
"system/power/video_activity_notifier.cc", "system/power/video_activity_notifier.cc",
"system/power/video_activity_notifier.h", "system/power/video_activity_notifier.h",
"system/rotation/rotation_lock_feature_pod_controller.cc",
"system/rotation/rotation_lock_feature_pod_controller.h",
"system/rotation/tray_rotation_lock.cc", "system/rotation/tray_rotation_lock.cc",
"system/rotation/tray_rotation_lock.h", "system/rotation/tray_rotation_lock.h",
"system/screen_layout_observer.cc", "system/screen_layout_observer.cc",
...@@ -1543,6 +1545,7 @@ test("ash_unittests") { ...@@ -1543,6 +1545,7 @@ test("ash_unittests") {
"system/power/power_status_view_unittest.cc", "system/power/power_status_view_unittest.cc",
"system/power/tray_power_unittest.cc", "system/power/tray_power_unittest.cc",
"system/power/video_activity_notifier_unittest.cc", "system/power/video_activity_notifier_unittest.cc",
"system/rotation/rotation_lock_feature_pod_controller_unittest.cc",
"system/rotation/tray_rotation_lock_unittest.cc", "system/rotation/tray_rotation_lock_unittest.cc",
"system/screen_layout_observer_unittest.cc", "system/screen_layout_observer_unittest.cc",
"system/screen_security/screen_tray_item_unittest.cc", "system/screen_security/screen_tray_item_unittest.cc",
......
...@@ -878,6 +878,9 @@ This file contains the strings for ash. ...@@ -878,6 +878,9 @@ This file contains the strings for ash.
<message name="IDS_ASH_STATUS_TRAY_NOTIFICATION_SESSION_LENGTH_LIMIT_MESSAGE" desc="The message of the notification shown to inform the user that the session length is limited."> <message name="IDS_ASH_STATUS_TRAY_NOTIFICATION_SESSION_LENGTH_LIMIT_MESSAGE" desc="The message of the notification shown to inform the user that the session length is limited.">
You will automatically be signed out. You will automatically be signed out.
</message> </message>
<message name="IDS_ASH_STATUS_TRAY_ROTATION_LOCK" desc="The text shown in the tray menu button that the user can enable the rotation lock by tapping.">
Orientation
</message>
<message name="IDS_ASH_STATUS_TRAY_ROTATION_LOCK_AUTO" desc="The text shown in the tray menu when rotation is set to auto and the user can enable the rotation lock by tapping."> <message name="IDS_ASH_STATUS_TRAY_ROTATION_LOCK_AUTO" desc="The text shown in the tray menu when rotation is set to auto and the user can enable the rotation lock by tapping.">
Auto rotate Auto rotate
</message> </message>
......
// 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/rotation/rotation_lock_feature_pod_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/wm/tablet_mode/tablet_mode_controller.h"
#include "ui/base/l10n/l10n_util.h"
namespace ash {
RotationLockFeaturePodController::RotationLockFeaturePodController() {
DCHECK(Shell::Get());
Shell::Get()->tablet_mode_controller()->AddObserver(this);
Shell::Get()->screen_orientation_controller()->AddObserver(this);
}
RotationLockFeaturePodController::~RotationLockFeaturePodController() {
if (Shell::Get()->screen_orientation_controller())
Shell::Get()->screen_orientation_controller()->RemoveObserver(this);
if (Shell::Get()->tablet_mode_controller())
Shell::Get()->tablet_mode_controller()->RemoveObserver(this);
}
FeaturePodButton* RotationLockFeaturePodController::CreateButton() {
DCHECK(!button_);
button_ = new FeaturePodButton(this);
button_->SetLabel(
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ROTATION_LOCK));
UpdateButton();
return button_;
}
void RotationLockFeaturePodController::OnPressed() {
Shell::Get()->screen_orientation_controller()->ToggleUserRotationLock();
}
void RotationLockFeaturePodController::OnTabletModeStarted() {
UpdateButton();
}
void RotationLockFeaturePodController::OnTabletModeEnded() {
UpdateButton();
}
void RotationLockFeaturePodController::OnUserRotationLockChanged() {
UpdateButton();
}
void RotationLockFeaturePodController::UpdateButton() {
bool tablet_enabled = Shell::Get()
->tablet_mode_controller()
->IsTabletModeWindowManagerEnabled();
button_->SetVisible(tablet_enabled);
if (!tablet_enabled)
return;
bool rotation_locked =
Shell::Get()->screen_orientation_controller()->user_rotation_locked();
bool is_portrait = Shell::Get()
->screen_orientation_controller()
->IsUserLockedOrientationPortrait();
button_->SetToggled(rotation_locked);
if (rotation_locked && is_portrait) {
button_->SetVectorIcon(kSystemMenuRotationLockPortraitIcon);
button_->SetSubLabel(
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ROTATION_LOCK_PORTRAIT));
} else if (rotation_locked && !is_portrait) {
button_->SetVectorIcon(kSystemMenuRotationLockLandscapeIcon);
button_->SetSubLabel(
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ROTATION_LOCK_LANDSCAPE));
} else {
button_->SetVectorIcon(kSystemMenuRotationLockAutoIcon);
button_->SetSubLabel(
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ROTATION_LOCK_AUTO));
}
}
} // 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_ROTATION_ROTATION_LOCK_FEATURE_POD_CONTROLLER_H_
#define ASH_SYSTEM_ROTATION_ROTATION_LOCK_FEATURE_POD_CONTROLLER_H_
#include "ash/ash_export.h"
#include "ash/display/screen_orientation_controller_chromeos.h"
#include "ash/system/unified/feature_pod_controller_base.h"
#include "ash/wm/tablet_mode/tablet_mode_observer.h"
#include "base/macros.h"
namespace ash {
// Controller of a feature pod button that toggles rotation lock mode.
class ASH_EXPORT RotationLockFeaturePodController
: public FeaturePodControllerBase,
public TabletModeObserver,
public ScreenOrientationController::Observer {
public:
RotationLockFeaturePodController();
~RotationLockFeaturePodController() override;
// FeaturePodControllerBase:
FeaturePodButton* CreateButton() override;
void OnPressed() override;
// TabletModeObserver:
void OnTabletModeStarted() override;
void OnTabletModeEnded() override;
// ScreenOrientationController::Observer:
void OnUserRotationLockChanged() override;
private:
void UpdateButton();
FeaturePodButton* button_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(RotationLockFeaturePodController);
};
} // namespace ash
#endif // ASH_SYSTEM_ROTATION_ROTATION_LOCK_FEATURE_POD_CONTROLLER_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/rotation/rotation_lock_feature_pod_controller.h"
#include "ash/shell.h"
#include "ash/system/unified/feature_pod_button.h"
#include "ash/test/ash_test_base.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "base/command_line.h"
#include "ui/display/display_switches.h"
namespace ash {
class RotationLockFeaturePodControllerTest : public AshTestBase {
public:
RotationLockFeaturePodControllerTest() = default;
~RotationLockFeaturePodControllerTest() override = default;
// AshTestBase:
void SetUp() override;
void TearDown() override;
protected:
void SetUpController();
RotationLockFeaturePodController* controller() const {
return controller_.get();
}
FeaturePodButton* button_view() const { return button_view_.get(); }
private:
std::unique_ptr<RotationLockFeaturePodController> controller_;
std::unique_ptr<FeaturePodButton> button_view_;
DISALLOW_COPY_AND_ASSIGN(RotationLockFeaturePodControllerTest);
};
void RotationLockFeaturePodControllerTest::SetUp() {
// The Display used for testing is not an internal display. This flag
// allows for DisplayManager to treat it as one.
base::CommandLine::ForCurrentProcess()->AppendSwitch(
::switches::kUseFirstDisplayAsInternal);
AshTestBase::SetUp();
}
void RotationLockFeaturePodControllerTest::TearDown() {
controller_.reset();
button_view_.reset();
AshTestBase::TearDown();
}
void RotationLockFeaturePodControllerTest::SetUpController() {
controller_ = std::make_unique<RotationLockFeaturePodController>();
button_view_.reset(controller_->CreateButton());
}
// Tests that when the button is initially created, that it is created
// not visible.
TEST_F(RotationLockFeaturePodControllerTest, CreateButton) {
SetUpController();
EXPECT_FALSE(button_view()->visible());
}
// Tests that when the button is created, while TabletMode is active,
// that it is visible.
TEST_F(RotationLockFeaturePodControllerTest, CreateButtonDuringTabletMode) {
Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(true);
SetUpController();
EXPECT_TRUE(button_view()->visible());
Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(false);
EXPECT_FALSE(button_view()->visible());
}
// Tests that the enabling of TabletMode affects a previously created default
// view, changing the visibility.
TEST_F(RotationLockFeaturePodControllerTest,
ButtonVisibilityChangesDuringTabletMode) {
SetUpController();
Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(true);
EXPECT_TRUE(button_view()->visible());
Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(false);
EXPECT_FALSE(button_view()->visible());
}
TEST_F(RotationLockFeaturePodControllerTest, OnPressed) {
SetUpController();
TabletModeController* tablet_mode_controller =
Shell::Get()->tablet_mode_controller();
ScreenOrientationController* screen_orientation_controller =
Shell::Get()->screen_orientation_controller();
ASSERT_FALSE(screen_orientation_controller->rotation_locked());
tablet_mode_controller->EnableTabletModeWindowManager(true);
ASSERT_TRUE(button_view()->visible());
EXPECT_FALSE(button_view()->IsToggled());
controller()->OnPressed();
EXPECT_TRUE(screen_orientation_controller->rotation_locked());
EXPECT_TRUE(button_view()->visible());
EXPECT_TRUE(button_view()->IsToggled());
controller()->OnPressed();
EXPECT_FALSE(screen_orientation_controller->rotation_locked());
EXPECT_TRUE(button_view()->visible());
EXPECT_FALSE(button_view()->IsToggled());
tablet_mode_controller->EnableTabletModeWindowManager(false);
}
} // namespace ash
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "ui/views/animation/ink_drop_highlight.h" #include "ui/views/animation/ink_drop_highlight.h"
#include "ui/views/animation/ink_drop_impl.h" #include "ui/views/animation/ink_drop_impl.h"
#include "ui/views/animation/ink_drop_mask.h" #include "ui/views/animation/ink_drop_mask.h"
#include "ui/views/border.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
...@@ -83,17 +84,18 @@ std::unique_ptr<views::InkDropMask> FeaturePodIconButton::CreateInkDropMask() ...@@ -83,17 +84,18 @@ std::unique_ptr<views::InkDropMask> FeaturePodIconButton::CreateInkDropMask()
} }
FeaturePodButton::FeaturePodButton(FeaturePodControllerBase* controller) FeaturePodButton::FeaturePodButton(FeaturePodControllerBase* controller)
: controller_(controller) { : controller_(controller),
auto layout = std::make_unique<views::BoxLayout>( icon_button_(new FeaturePodIconButton(this)),
views::BoxLayout::kVertical, gfx::Insets(), kUnifiedTopShortcutSpacing); label_(new views::Label()) {
auto layout = std::make_unique<views::BoxLayout>(views::BoxLayout::kVertical);
layout->set_cross_axis_alignment( layout->set_cross_axis_alignment(
views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER);
SetLayoutManager(std::move(layout)); SetLayoutManager(std::move(layout));
icon_button_ = new FeaturePodIconButton(this);
AddChildView(icon_button_); AddChildView(icon_button_);
label_ = new views::Label(); label_->SetBorder(
views::CreateEmptyBorder(kUnifiedTopShortcutSpacing, 0, 0, 0));
label_->SetVisible(false); label_->SetVisible(false);
ConfigureFeaturePodLabel(label_); ConfigureFeaturePodLabel(label_);
AddChildView(label_); AddChildView(label_);
...@@ -109,6 +111,8 @@ void FeaturePodButton::SetVectorIcon(const gfx::VectorIcon& icon) { ...@@ -109,6 +111,8 @@ void FeaturePodButton::SetVectorIcon(const gfx::VectorIcon& icon) {
void FeaturePodButton::SetLabel(const base::string16& label) { void FeaturePodButton::SetLabel(const base::string16& label) {
label_->SetVisible(true); label_->SetVisible(true);
label_->SetText(label); label_->SetText(label);
Layout();
SchedulePaint();
} }
void FeaturePodButton::SetSubLabel(const base::string16& sub_label) { void FeaturePodButton::SetSubLabel(const base::string16& sub_label) {
...@@ -120,6 +124,8 @@ void FeaturePodButton::SetSubLabel(const base::string16& sub_label) { ...@@ -120,6 +124,8 @@ void FeaturePodButton::SetSubLabel(const base::string16& sub_label) {
} }
sub_label_->SetText(sub_label); sub_label_->SetText(sub_label);
Layout();
SchedulePaint();
} }
void FeaturePodButton::SetToggled(bool toggled) { void FeaturePodButton::SetToggled(bool toggled) {
......
...@@ -34,6 +34,8 @@ class FeaturePodIconButton : public views::ImageButton { ...@@ -34,6 +34,8 @@ class FeaturePodIconButton : public views::ImageButton {
const override; const override;
std::unique_ptr<views::InkDropMask> CreateInkDropMask() const override; std::unique_ptr<views::InkDropMask> CreateInkDropMask() const override;
bool toggled() const { return toggled_; }
private: private:
// Ture if the button is currently toggled. // Ture if the button is currently toggled.
bool toggled_ = false; bool toggled_ = false;
...@@ -67,13 +69,15 @@ class FeaturePodButton : public views::View, public views::ButtonListener { ...@@ -67,13 +69,15 @@ class FeaturePodButton : public views::View, public views::ButtonListener {
// views::ButtonListener: // views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override; void ButtonPressed(views::Button* sender, const ui::Event& event) override;
bool IsToggled() const { return icon_button_->toggled(); }
private: private:
// Unowned. // Unowned.
FeaturePodControllerBase* controller_; FeaturePodControllerBase* const controller_;
// Owned by views hierarchy. // Owned by views hierarchy.
FeaturePodIconButton* icon_button_ = nullptr; FeaturePodIconButton* const icon_button_;
views::Label* label_ = nullptr; views::Label* const label_;
views::Label* sub_label_ = nullptr; views::Label* sub_label_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(FeaturePodButton); DISALLOW_COPY_AND_ASSIGN(FeaturePodButton);
......
...@@ -17,7 +17,9 @@ class FeaturePodControllerBase { ...@@ -17,7 +17,9 @@ class FeaturePodControllerBase {
virtual ~FeaturePodControllerBase() {} virtual ~FeaturePodControllerBase() {}
// Create the view. Subclasses instantiate FeaturePodButton. // Create the view. Subclasses instantiate FeaturePodButton.
// The view will be onwed by views hierarchy. // The view will be onwed by views hierarchy. The view will be always deleted
// after the controller is destructed (UnifiedSystemTrayBubble guarantees
// this).
virtual FeaturePodButton* CreateButton() = 0; virtual FeaturePodButton* CreateButton() = 0;
// Called when the feature pod button is clicked. // Called when the feature pod button is clicked.
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "ash/metrics/user_metrics_recorder.h" #include "ash/metrics/user_metrics_recorder.h"
#include "ash/session/session_controller.h" #include "ash/session/session_controller.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/system/rotation/rotation_lock_feature_pod_controller.h"
#include "ash/system/tray/system_tray_controller.h" #include "ash/system/tray/system_tray_controller.h"
#include "ash/system/unified/feature_pod_controller_base.h" #include "ash/system/unified/feature_pod_controller_base.h"
#include "ash/system/unified/quiet_mode_feature_pod_controller.h" #include "ash/system/unified/quiet_mode_feature_pod_controller.h"
...@@ -58,6 +59,7 @@ void UnifiedSystemTrayController::ToggleExpanded() { ...@@ -58,6 +59,7 @@ void UnifiedSystemTrayController::ToggleExpanded() {
void UnifiedSystemTrayController::InitFeaturePods() { void UnifiedSystemTrayController::InitFeaturePods() {
AddFeaturePodItem(std::make_unique<QuietModeFeaturePodController>()); AddFeaturePodItem(std::make_unique<QuietModeFeaturePodController>());
AddFeaturePodItem(std::make_unique<RotationLockFeaturePodController>());
// If you want to add a new feature pod item, add here. // If you want to add a new feature pod item, add here.
......
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