Commit f3b4fb30 authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

[VK] Clean up timing code.

Bug: 845780
Change-Id: I07e73631ec2ebb363f4ab96d1b6489006692054b
Reviewed-on: https://chromium-review.googlesource.com/c/1432412
Commit-Queue: Yuichiro Hanada <yhanada@chromium.org>
Auto-Submit: Darren Shen <shend@chromium.org>
Reviewed-by: default avatarYuichiro Hanada <yhanada@chromium.org>
Cr-Commit-Position: refs/heads/master@{#625445}
parent 0c3e3062
...@@ -54,18 +54,22 @@ namespace { ...@@ -54,18 +54,22 @@ namespace {
// Owned by ash::Shell. // Owned by ash::Shell.
KeyboardController* g_keyboard_controller = nullptr; KeyboardController* g_keyboard_controller = nullptr;
constexpr int kHideKeyboardDelayMs = 100; // How long the keyboard stays in WILL_HIDE state before moving to HIDDEN.
constexpr base::TimeDelta kHideKeyboardDelay =
base::TimeDelta::FromMilliseconds(100);
// Reports an error histogram if the keyboard state is lingering in an // Reports an error histogram if the keyboard state is lingering in an
// intermediate state for more than 5 seconds. // intermediate state for more than 5 seconds.
constexpr int kReportLingeringStateDelayMs = 5000; constexpr base::TimeDelta kReportLingeringStateDelay =
base::TimeDelta::FromMilliseconds(5000);
// Delay threshold after the keyboard enters the WILL_HIDE state. If text focus // Delay threshold after the keyboard enters the WILL_HIDE state. If text focus
// is regained during this threshold, the keyboard will show again, even if it // is regained during this threshold, the keyboard will show again, even if it
// is an asynchronous event. This is for the benefit of things like login flow // is an asynchronous event. This is for the benefit of things like login flow
// where the password field may get text focus after an animation that plays // where the password field may get text focus after an animation that plays
// after the user enters their username. // after the user enters their username.
constexpr int kTransientBlurThresholdMs = 3500; constexpr base::TimeDelta kTransientBlurThreshold =
base::TimeDelta::FromMilliseconds(3500);
// State transition diagram (document linked from crbug.com/719905) // State transition diagram (document linked from crbug.com/719905)
bool IsAllowedStateTransition(KeyboardControllerState from, bool IsAllowedStateTransition(KeyboardControllerState from,
...@@ -630,7 +634,7 @@ void KeyboardController::HideKeyboardImplicitlyBySystem() { ...@@ -630,7 +634,7 @@ void KeyboardController::HideKeyboardImplicitlyBySystem() {
base::BindOnce(&KeyboardController::HideKeyboard, base::BindOnce(&KeyboardController::HideKeyboard,
weak_factory_will_hide_.GetWeakPtr(), weak_factory_will_hide_.GetWeakPtr(),
HIDE_REASON_SYSTEM_IMPLICIT), HIDE_REASON_SYSTEM_IMPLICIT),
base::TimeDelta::FromMilliseconds(kHideKeyboardDelayMs)); kHideKeyboardDelay);
} }
// private // private
...@@ -818,12 +822,7 @@ void KeyboardController::OnTextInputStateChanged( ...@@ -818,12 +822,7 @@ void KeyboardController::OnTextInputStateChanged(
} }
void KeyboardController::ShowKeyboardIfWithinTransientBlurThreshold() { void KeyboardController::ShowKeyboardIfWithinTransientBlurThreshold() {
static const base::TimeDelta kTransientBlurThreshold = if (base::Time::Now() - time_of_last_blur_ < kTransientBlurThreshold)
base::TimeDelta::FromMilliseconds(kTransientBlurThresholdMs);
const base::Time now = base::Time::Now();
const base::TimeDelta time_since_last_blur = now - time_of_last_blur_;
if (time_since_last_blur < kTransientBlurThreshold)
ShowKeyboard(false); ShowKeyboard(false);
} }
...@@ -982,7 +981,7 @@ void KeyboardController::ChangeState(KeyboardControllerState state) { ...@@ -982,7 +981,7 @@ void KeyboardController::ChangeState(KeyboardControllerState state) {
FROM_HERE, FROM_HERE,
base::BindOnce(&KeyboardController::ReportLingeringState, base::BindOnce(&KeyboardController::ReportLingeringState,
weak_factory_report_lingering_state_.GetWeakPtr()), weak_factory_report_lingering_state_.GetWeakPtr()),
base::TimeDelta::FromMilliseconds(kReportLingeringStateDelayMs)); kReportLingeringStateDelay);
break; break;
default: default:
// Do nothing // Do nothing
......
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