Commit a7478254 authored by James Cook's avatar James Cook Committed by Commit Bot

cros: Eliminate //ui/chromeos/accelerometer_util

We're trying to eliminate //ui/chromeos, since all high-level chromeos
UI lives in //ash. This file only exists because of a DEPS-ban on
//ui in //chromeos. Allowing one gfx::Vector3dF dependency in
//chromeos/accelerometer allows this file to be eliminated and all
functionality consolidated in AccelerometerUpdate.

TBR=danakj@chromium.org

Bug: none
Test: ash_unittests, chromeos_unittests
Change-Id: Iff03d52073920c9ed6dfbed3c550e98dc02ed335
Reviewed-on: https://chromium-review.googlesource.com/933082
Commit-Queue: James Cook <jamescook@chromium.org>
Reviewed-by: default avatarDan Erat <derat@chromium.org>
Cr-Commit-Position: refs/heads/master@{#538936}
parent c44b18fd
......@@ -15,7 +15,6 @@
#include "chromeos/accelerometer/accelerometer_reader.h"
#include "chromeos/accelerometer/accelerometer_types.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/chromeos/accelerometer/accelerometer_util.h"
#include "ui/display/display.h"
#include "ui/display/manager/display_manager.h"
#include "ui/display/manager/managed_display_info.h"
......@@ -289,10 +288,8 @@ void ScreenOrientationController::OnAccelerometerUpdated(
return;
// Ignore the reading if it appears unstable. The reading is considered
// unstable if it deviates too much from gravity
if (ui::IsAccelerometerReadingStable(*update,
chromeos::ACCELEROMETER_SOURCE_SCREEN)) {
if (update->IsReadingStable(chromeos::ACCELEROMETER_SOURCE_SCREEN))
HandleScreenRotation(update->get(chromeos::ACCELEROMETER_SOURCE_SCREEN));
}
}
void ScreenOrientationController::OnDisplayConfigurationChanged() {
......
......@@ -21,7 +21,6 @@
#include "base/time/tick_clock.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/chromeos/accelerometer/accelerometer_util.h"
#include "ui/display/display.h"
#include "ui/display/manager/display_manager.h"
#include "ui/events/event.h"
......@@ -78,11 +77,9 @@ const float kNoisyMagnitudeDeviation = 1.0f;
bool IsAngleBetweenAccelerometerReadingsStable(
const chromeos::AccelerometerUpdate& update) {
return std::abs(
ui::ConvertAccelerometerReadingToVector3dF(
update.get(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD))
update.GetVector(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD)
.Length() -
ui::ConvertAccelerometerReadingToVector3dF(
update.get(chromeos::ACCELEROMETER_SOURCE_SCREEN))
update.GetVector(chromeos::ACCELEROMETER_SOURCE_SCREEN)
.Length()) <= kNoisyMagnitudeDeviation;
}
......@@ -249,10 +246,9 @@ void TabletModeController::OnAccelerometerUpdated(
// Whether or not we enter tablet mode affects whether we handle screen
// rotation, so determine whether to enter tablet mode first.
if (ui::IsAccelerometerReadingStable(*update,
chromeos::ACCELEROMETER_SOURCE_SCREEN) &&
ui::IsAccelerometerReadingStable(
*update, chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD) &&
if (update->IsReadingStable(chromeos::ACCELEROMETER_SOURCE_SCREEN) &&
update->IsReadingStable(
chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD) &&
IsAngleBetweenAccelerometerReadingsStable(*update)) {
// update.has(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD)
// Ignore the reading if it appears unstable. The reading is considered
......@@ -313,10 +309,10 @@ void TabletModeController::SuspendDone(const base::TimeDelta& sleep_duration) {
void TabletModeController::HandleHingeRotation(
scoped_refptr<const chromeos::AccelerometerUpdate> update) {
static const gfx::Vector3dF hinge_vector(1.0f, 0.0f, 0.0f);
gfx::Vector3dF base_reading(ui::ConvertAccelerometerReadingToVector3dF(
update->get(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD)));
gfx::Vector3dF lid_reading(ui::ConvertAccelerometerReadingToVector3dF(
update->get(chromeos::ACCELEROMETER_SOURCE_SCREEN)));
gfx::Vector3dF base_reading =
update->GetVector(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD);
gfx::Vector3dF lid_reading =
update->GetVector(chromeos::ACCELEROMETER_SOURCE_SCREEN);
// As the hinge approaches a vertical angle, the base and lid accelerometers
// approach the same values making any angle calculations highly inaccurate.
......
......@@ -48,6 +48,7 @@ component("chromeos") {
"//skia", # For components/user_manager
"//third_party/icu",
"//third_party/protobuf:protobuf_lite",
"//ui/gfx/geometry", # For accelerometer.
"//url",
]
data_deps = [
......
include_rules = [
"+ui/gfx/geometry/vector3d_f.h",
]
......@@ -4,7 +4,19 @@
#include "chromeos/accelerometer/accelerometer_types.h"
#include "ui/gfx/geometry/vector3d_f.h"
namespace chromeos {
namespace {
// The maximum deviation from the acceleration expected due to gravity for which
// the device will be considered stable: 1g.
constexpr float kDeviationFromGravityThreshold = 1.0f;
// The mean acceleration due to gravity on Earth in m/s^2.
constexpr float kMeanGravity = 9.80665f;
} // namespace
AccelerometerReading::AccelerometerReading() : present(false) {
}
......@@ -15,4 +27,18 @@ AccelerometerUpdate::AccelerometerUpdate() = default;
AccelerometerUpdate::~AccelerometerUpdate() = default;
gfx::Vector3dF AccelerometerUpdate::GetVector(
AccelerometerSource source) const {
const AccelerometerReading& reading = data_[source];
return gfx::Vector3dF(reading.x, reading.y, reading.z);
}
bool AccelerometerUpdate::IsReadingStable(AccelerometerSource source) const {
if (!has(source))
return false;
return std::abs(GetVector(source).Length() - kMeanGravity) <=
kDeviationFromGravityThreshold;
}
} // namespace chromeos
......@@ -9,6 +9,10 @@
#include "base/memory/ref_counted.h"
#include "chromeos/chromeos_export.h"
namespace gfx {
class Vector3dF;
}
namespace chromeos {
enum AccelerometerSource {
......@@ -58,6 +62,9 @@ class CHROMEOS_EXPORT AccelerometerUpdate
return data_[source];
}
// Returns the last known value for |source| as a vector.
gfx::Vector3dF GetVector(AccelerometerSource source) const;
void Set(AccelerometerSource source, float x, float y, float z) {
data_[source].present = true;
data_[source].x = x;
......@@ -65,6 +72,11 @@ class CHROMEOS_EXPORT AccelerometerUpdate
data_[source].z = z;
}
// A reading is considered stable if its deviation from gravity is small. This
// returns false if the deviation is too high, or if |source| is not present
// in the update.
bool IsReadingStable(AccelerometerSource source) const;
protected:
AccelerometerReading data_[ACCELEROMETER_SOURCE_COUNT];
......
......@@ -9,8 +9,6 @@ assert(is_chromeos)
component("chromeos") {
output_name = "ui_chromeos"
sources = [
"accelerometer/accelerometer_util.cc",
"accelerometer/accelerometer_util.h",
"devicetype_utils.cc",
"devicetype_utils.h",
"ime/candidate_view.cc",
......
// Copyright 2015 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 "ui/chromeos/accelerometer/accelerometer_util.h"
#include <cmath>
#include "chromeos/accelerometer/accelerometer_types.h"
#include "ui/gfx/geometry/vector3d_f.h"
namespace {
// The maximum deviation from the acceleration expected due to gravity for which
// the device will be considered stable: 1g.
const float kDeviationFromGravityThreshold = 1.0f;
// The mean acceleration due to gravity on Earth in m/s^2.
const float kMeanGravity = 9.80665f;
} // namespace
namespace ui {
const gfx::Vector3dF ConvertAccelerometerReadingToVector3dF(
const chromeos::AccelerometerReading& reading) {
return gfx::Vector3dF(reading.x, reading.y, reading.z);
}
bool IsAccelerometerReadingStable(const chromeos::AccelerometerUpdate& update,
chromeos::AccelerometerSource source) {
return update.has(source) &&
std::abs(ConvertAccelerometerReadingToVector3dF(update.get(source))
.Length() -
kMeanGravity) <= kDeviationFromGravityThreshold;
}
} // namespace ui
// Copyright 2015 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 UI_CHROMEOS_ACCELEROMETER_ACCELEROMETER_UTIL_H_
#define UI_CHROMEOS_ACCELEROMETER_ACCELEROMETER_UTIL_H_
#include "chromeos/accelerometer/accelerometer_types.h"
#include "ui/chromeos/ui_chromeos_export.h"
#include "ui/gfx/geometry/vector3d_f.h"
namespace ui {
// Converts the acceleration data in |reading| into a gfx::Vector3dF.
UI_CHROMEOS_EXPORT const gfx::Vector3dF ConvertAccelerometerReadingToVector3dF(
const chromeos::AccelerometerReading& reading);
// A reading is considered stable if its deviation from gravity is small. This
// returns false if the deviation is too high, or if |source| is not present
// in the update.
UI_CHROMEOS_EXPORT bool IsAccelerometerReadingStable(
const chromeos::AccelerometerUpdate& update,
chromeos::AccelerometerSource source);
} // namespace ui
#endif // UI_CHROMEOS_ACCELEROMETER_ACCELEROMETER_UTIL_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