Commit 9fed56c6 authored by Antonio Gomes's avatar Antonio Gomes Committed by Commit Bot

Introduce chromeos::TabletState

chromeos::TabletState is the singleton that actually holds the
information about the current TabletMode state. The state getter
method is public, but its setter is not. The idea is that only a
handful of classes can actually set the state, eg
ash::TabletModeController.

In the future, Lacros will also be able to create a
chromeos::TabletState instance and set the tablet mode state
via the (upcoming) use of `zcr_remote_shell` Exo protocol extension.

BUG=1113900
R=jamescook@chromium.org

Change-Id: I2ec77e7f038095b7e4f9c776683993f6b30c409e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2443219
Commit-Queue: Antonio Gomes (GMT-4) <tonikitoo@igalia.com>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#813394}
parent ea5d856a
...@@ -87,8 +87,7 @@ include_rules = [ ...@@ -87,8 +87,7 @@ include_rules = [
"+chromeos/strings", "+chromeos/strings",
"+chromeos/system", "+chromeos/system",
# Do not eliminate this. # Do not eliminate this.
"+chromeos/ui/vector_icons", "+chromeos/ui",
"+chromeos/ui/chromeos_ui_constants.h",
# ui/base/idle depends on SessionManagerClient so disallow it. # ui/base/idle depends on SessionManagerClient so disallow it.
"-ui/base/idle" "-ui/base/idle"
......
...@@ -491,8 +491,8 @@ bool TabletModeController::TriggerRecordLidAngleTimerForTesting() { ...@@ -491,8 +491,8 @@ bool TabletModeController::TriggerRecordLidAngleTimerForTesting() {
void TabletModeController::MaybeObserveBoundsAnimation(aura::Window* window) { void TabletModeController::MaybeObserveBoundsAnimation(aura::Window* window) {
StopObservingAnimation(/*record_stats=*/false, /*delete_screenshot=*/false); StopObservingAnimation(/*record_stats=*/false, /*delete_screenshot=*/false);
if (state_ != State::kEnteringTabletMode && if (tablet_state_.state() != chromeos::TabletState::kEnteringTabletMode &&
state_ != State::kExitingTabletMode) { tablet_state_.state() != chromeos::TabletState::kExitingTabletMode) {
return; return;
} }
...@@ -545,7 +545,7 @@ void TabletModeController::RemoveObserver(TabletModeObserver* observer) { ...@@ -545,7 +545,7 @@ void TabletModeController::RemoveObserver(TabletModeObserver* observer) {
} }
bool TabletModeController::InTabletMode() const { bool TabletModeController::InTabletMode() const {
return state_ == State::kInTabletMode || state_ == State::kEnteringTabletMode; return tablet_state_.InTabletMode();
} }
void TabletModeController::ForceUiTabletModeState( void TabletModeController::ForceUiTabletModeState(
...@@ -789,7 +789,8 @@ void TabletModeController::OnLayerAnimationScheduled( ...@@ -789,7 +789,8 @@ void TabletModeController::OnLayerAnimationScheduled(
transition_tracker_ = transition_tracker_ =
animating_layer_->GetCompositor()->RequestNewThroughputTracker(); animating_layer_->GetCompositor()->RequestNewThroughputTracker();
transition_tracker_->Start(metrics_util::ForSmoothness(base::BindRepeating( transition_tracker_->Start(metrics_util::ForSmoothness(base::BindRepeating(
&ReportTrasitionSmoothness, state_ == State::kEnteringTabletMode))); &ReportTrasitionSmoothness,
tablet_state_.state() == chromeos::TabletState::kEnteringTabletMode)));
return; return;
} }
...@@ -835,7 +836,7 @@ void TabletModeController::SetTabletModeEnabledInternal(bool should_enable) { ...@@ -835,7 +836,7 @@ void TabletModeController::SetTabletModeEnabledInternal(bool should_enable) {
DeleteScreenshot(); DeleteScreenshot();
if (should_enable) { if (should_enable) {
state_ = State::kEnteringTabletMode; tablet_state_.SetState(chromeos::TabletState::kEnteringTabletMode);
// Take a screenshot if there is a top window that will get animated. // Take a screenshot if there is a top window that will get animated.
// TODO(sammiequon): Handle the case where the top window is not on the // TODO(sammiequon): Handle the case where the top window is not on the
...@@ -865,7 +866,7 @@ void TabletModeController::SetTabletModeEnabledInternal(bool should_enable) { ...@@ -865,7 +866,7 @@ void TabletModeController::SetTabletModeEnabledInternal(bool should_enable) {
FinishInitTabletMode(); FinishInitTabletMode();
} }
} else { } else {
state_ = State::kExitingTabletMode; tablet_state_.SetState(chromeos::TabletState::kExitingTabletMode);
// We may have entered tablet mode, then tried to exit before the screenshot // We may have entered tablet mode, then tried to exit before the screenshot
// was taken. In this case |tablet_mode_window_manager_| will be null. // was taken. In this case |tablet_mode_window_manager_| will be null.
...@@ -881,7 +882,7 @@ void TabletModeController::SetTabletModeEnabledInternal(bool should_enable) { ...@@ -881,7 +882,7 @@ void TabletModeController::SetTabletModeEnabledInternal(bool should_enable) {
base::RecordAction(base::UserMetricsAction("Touchview_Disabled")); base::RecordAction(base::UserMetricsAction("Touchview_Disabled"));
RecordTabletModeUsageInterval(TABLET_MODE_INTERVAL_ACTIVE); RecordTabletModeUsageInterval(TABLET_MODE_INTERVAL_ACTIVE);
state_ = State::kInClamshellMode; tablet_state_.SetState(chromeos::TabletState::kInClamshellMode);
for (auto& observer : tablet_mode_observers_) for (auto& observer : tablet_mode_observers_)
observer.OnTabletModeEnded(); observer.OnTabletModeEnded();
VLOG(1) << "Exit tablet mode."; VLOG(1) << "Exit tablet mode.";
...@@ -1124,7 +1125,7 @@ void TabletModeController::ResetPauser() { ...@@ -1124,7 +1125,7 @@ void TabletModeController::ResetPauser() {
} }
void TabletModeController::FinishInitTabletMode() { void TabletModeController::FinishInitTabletMode() {
DCHECK_EQ(State::kEnteringTabletMode, state_); DCHECK_EQ(chromeos::TabletState::kEnteringTabletMode, tablet_state_.state());
for (auto& observer : tablet_mode_observers_) for (auto& observer : tablet_mode_observers_)
observer.OnTabletModeStarting(); observer.OnTabletModeStarting();
...@@ -1133,7 +1134,7 @@ void TabletModeController::FinishInitTabletMode() { ...@@ -1133,7 +1134,7 @@ void TabletModeController::FinishInitTabletMode() {
base::RecordAction(base::UserMetricsAction("Touchview_Enabled")); base::RecordAction(base::UserMetricsAction("Touchview_Enabled"));
RecordTabletModeUsageInterval(TABLET_MODE_INTERVAL_INACTIVE); RecordTabletModeUsageInterval(TABLET_MODE_INTERVAL_INACTIVE);
state_ = State::kInTabletMode; tablet_state_.SetState(chromeos::TabletState::kInTabletMode);
for (auto& observer : tablet_mode_observers_) for (auto& observer : tablet_mode_observers_)
observer.OnTabletModeStarted(); observer.OnTabletModeStarted();
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "base/time/time.h" #include "base/time/time.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "chromeos/dbus/power/power_manager_client.h" #include "chromeos/dbus/power/power_manager_client.h"
#include "chromeos/ui/tablet_state.h"
#include "ui/aura/window_occlusion_tracker.h" #include "ui/aura/window_occlusion_tracker.h"
#include "ui/compositor/layer_animation_element.h" #include "ui/compositor/layer_animation_element.h"
#include "ui/compositor/layer_animation_observer.h" #include "ui/compositor/layer_animation_observer.h"
...@@ -430,7 +431,7 @@ class ASH_EXPORT TabletModeController ...@@ -430,7 +431,7 @@ class ASH_EXPORT TabletModeController
gfx::Vector3dF base_smoothed_; gfx::Vector3dF base_smoothed_;
gfx::Vector3dF lid_smoothed_; gfx::Vector3dF lid_smoothed_;
State state_ = State::kInClamshellMode; chromeos::TabletState tablet_state_;
// Calls RecordLidAngle() periodically. // Calls RecordLidAngle() periodically.
base::RepeatingTimer record_lid_angle_timer_; base::RepeatingTimer record_lid_angle_timer_;
......
...@@ -7,9 +7,18 @@ assert(is_chromeos || chromeos_is_browser_only, ...@@ -7,9 +7,18 @@ assert(is_chromeos || chromeos_is_browser_only,
# C++ headers and sources that can be used by both ash and lacros builds. # C++ headers and sources that can be used by both ash and lacros builds.
component("ui") { component("ui") {
sources = [ "chromeos_ui_constants.h" ] defines = [ "IS_CHROMEOS_UI_IMPL" ]
sources = [
"chromeos_ui_constants.h",
"tablet_state.cc",
"tablet_state.h",
]
output_name = "chromeos_ui" output_name = "chromeos_ui"
deps = [ "//skia" ] deps = [
"//base",
"//skia",
]
} }
// Copyright 2020 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 "chromeos/ui/tablet_state.h"
#include "base/check_op.h"
namespace chromeos {
namespace {
TabletState* g_instance = nullptr;
}
TabletState* TabletState::Get() {
return g_instance;
}
TabletState::TabletState() {
DCHECK_EQ(nullptr, g_instance);
g_instance = this;
}
TabletState::~TabletState() {
DCHECK_EQ(this, g_instance);
g_instance = nullptr;
}
bool TabletState::InTabletMode() const {
return state_ == TabletState::kInTabletMode ||
state_ == TabletState::kEnteringTabletMode;
}
} // namespace chromeos
// Copyright 2020 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 CHROMEOS_UI_TABLET_STATE_H_
#define CHROMEOS_UI_TABLET_STATE_H_
#include "base/component_export.h"
namespace ash {
class TabletModeController;
}
namespace chromeos {
// Class is a singleton and holds the tablet mode state.
//
// The idea is that only the creator of this class in Ash or Lacros/Ozone code
// is able to set the state.
class COMPONENT_EXPORT(CHROMEOS_UI) TabletState {
public:
// Returns the singleton instance.
static TabletState* Get();
// Tracks whether we are in the process of entering or exiting tablet mode.
// Used for logging histogram metrics.
enum State {
kInClamshellMode,
kEnteringTabletMode,
kInTabletMode,
kExitingTabletMode,
};
TabletState();
TabletState(const TabletState&) = delete;
TabletState& operator=(const TabletState&) = delete;
~TabletState();
// TODO(http://crbug.com/1113900): Introduce Add|RemoveObserver support.
// Returns true if the system is in tablet mode.
bool InTabletMode() const;
State state() const { return state_; }
private:
// The friend class declaration here is used to control classes that can set
// the tablet state.
friend class ash::TabletModeController;
void SetState(State state) { state_ = state; }
State state_ = State::kInClamshellMode;
};
} // namespace chromeos
#endif // CHROMEOS_UI_TABLET_STATE_H_
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