Commit 0b5cc4e2 authored by Yash Malik's avatar Yash Malik Committed by Commit Bot

VR: Focus should be lost on button up

Before this CL, we would hide the keyboard before releasing the button, which is
incorrect behavior. This CL also makes the background unfocusable so clicking on
it doesn't steal focus from text fields and hide the keyboard.

Bug: 
Cq-Include-Trybots: master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: I0a74c7f3d036e8bff6fc4daa2ce6b47f33f2a2e3
Reviewed-on: https://chromium-review.googlesource.com/828120Reviewed-by: default avatarIan Vollick <vollick@chromium.org>
Commit-Queue: Yash Malik <ymalik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524380}
parent f583e2ff
...@@ -147,7 +147,7 @@ void UiInputManager::HandleInput(base::TimeTicks current_time, ...@@ -147,7 +147,7 @@ void UiInputManager::HandleInput(base::TimeTicks current_time,
} }
SendButtonDown(target_element, reticle_model->target_local_point, SendButtonDown(target_element, reticle_model->target_local_point,
controller_model.touchpad_button_state); controller_model.touchpad_button_state);
if (SendButtonUp(target_element, reticle_model->target_local_point, if (SendButtonUp(reticle_model->target_local_point,
controller_model.touchpad_button_state)) { controller_model.touchpad_button_state)) {
target_element = scene_->GetUiElementById(reticle_model->target_element_id); target_element = scene_->GetUiElementById(reticle_model->target_element_id);
SendHoverLeave(target_element); SendHoverLeave(target_element);
...@@ -323,19 +323,12 @@ void UiInputManager::SendButtonDown(UiElement* target, ...@@ -323,19 +323,12 @@ void UiInputManager::SendButtonDown(UiElement* target,
if (target) { if (target) {
target->OnButtonDown(target_point); target->OnButtonDown(target_point);
input_locked_element_id_ = target->id(); input_locked_element_id_ = target->id();
// Clicking outside of the focused element causes it to lose focus.
// TODO(ymalik): We will lose focus if we hit an element inside the focused
// element, which is incorrect behavior.
if (target->id() != focused_element_id_ && target->focusable()) {
UnfocusFocusedElement();
}
} else { } else {
input_locked_element_id_ = 0; input_locked_element_id_ = 0;
} }
} }
bool UiInputManager::SendButtonUp(UiElement* target, bool UiInputManager::SendButtonUp(const gfx::PointF& target_point,
const gfx::PointF& target_point,
ButtonState button_state) { ButtonState button_state) {
if (!in_click_) { if (!in_click_) {
return false; return false;
...@@ -351,8 +344,13 @@ bool UiInputManager::SendButtonUp(UiElement* target, ...@@ -351,8 +344,13 @@ bool UiInputManager::SendButtonUp(UiElement* target,
} }
UiElement* element = scene_->GetUiElementById(input_locked_element_id_); UiElement* element = scene_->GetUiElementById(input_locked_element_id_);
if (element) { if (element) {
target->OnButtonUp(target_point); element->OnButtonUp(target_point);
// Clicking outside of the focused element causes it to lose focus.
if (element->id() != focused_element_id_ && element->focusable()) {
UnfocusFocusedElement();
}
} }
input_locked_element_id_ = 0; input_locked_element_id_ = 0;
return true; return true;
} }
......
...@@ -86,9 +86,7 @@ class UiInputManager { ...@@ -86,9 +86,7 @@ class UiInputManager {
void SendButtonDown(UiElement* target, void SendButtonDown(UiElement* target,
const gfx::PointF& target_point, const gfx::PointF& target_point,
ButtonState button_state); ButtonState button_state);
bool SendButtonUp(UiElement* target, bool SendButtonUp(const gfx::PointF& target_point, ButtonState button_state);
const gfx::PointF& target_point,
ButtonState button_state);
void GetVisualTargetElement(const ControllerModel& controller_model, void GetVisualTargetElement(const ControllerModel& controller_model,
ReticleModel* reticle_model) const; ReticleModel* reticle_model) const;
void UpdateQuiescenceState(base::TimeTicks current_time, void UpdateQuiescenceState(base::TimeTicks current_time,
......
...@@ -177,8 +177,11 @@ TEST_F(UiInputManagerTest, FocusableChildStealsFocus) { ...@@ -177,8 +177,11 @@ TEST_F(UiInputManagerTest, FocusableChildStealsFocus) {
// Focus child. // Focus child.
EXPECT_CALL(*p_child, OnHoverEnter(_)).InSequence(s); EXPECT_CALL(*p_child, OnHoverEnter(_)).InSequence(s);
EXPECT_CALL(*p_child, OnButtonDown(_)).InSequence(s); EXPECT_CALL(*p_child, OnButtonDown(_)).InSequence(s);
EXPECT_CALL(*p_element, OnFocusChanged(false)).InSequence(s);
HandleInput(kForwardVector, kDown); HandleInput(kForwardVector, kDown);
EXPECT_CALL(*p_child, OnMove(_)).InSequence(s);
EXPECT_CALL(*p_child, OnButtonUp(_)).InSequence(s);
EXPECT_CALL(*p_element, OnFocusChanged(false)).InSequence(s);
HandleInput(kForwardVector, kUp);
} }
// Verify that a non-focusable child does not clear focus off its parent. // Verify that a non-focusable child does not clear focus off its parent.
......
...@@ -705,6 +705,7 @@ void UiSceneCreator::CreateBackground() { ...@@ -705,6 +705,7 @@ void UiSceneCreator::CreateBackground() {
floor->SetTranslate(0.0, -kSceneHeight / 2, 0.0); floor->SetTranslate(0.0, -kSceneHeight / 2, 0.0);
floor->SetRotate(1, 0, 0, -base::kPiFloat / 2); floor->SetRotate(1, 0, 0, -base::kPiFloat / 2);
floor->set_gridline_count(kFloorGridlineCount); floor->set_gridline_count(kFloorGridlineCount);
floor->set_focusable(false);
BindColor(model_, floor.get(), &ColorScheme::floor, &Grid::SetCenterColor); BindColor(model_, floor.get(), &ColorScheme::floor, &Grid::SetCenterColor);
BindColor(model_, floor.get(), &ColorScheme::world_background, BindColor(model_, floor.get(), &ColorScheme::world_background,
&Grid::SetEdgeColor); &Grid::SetEdgeColor);
...@@ -713,6 +714,7 @@ void UiSceneCreator::CreateBackground() { ...@@ -713,6 +714,7 @@ void UiSceneCreator::CreateBackground() {
// Ceiling. // Ceiling.
auto ceiling = base::MakeUnique<Rect>(); auto ceiling = base::MakeUnique<Rect>();
ceiling->set_focusable(false);
ceiling->SetName(kCeiling); ceiling->SetName(kCeiling);
ceiling->SetDrawPhase(kPhaseFloorCeiling); ceiling->SetDrawPhase(kPhaseFloorCeiling);
ceiling->SetSize(kSceneSize, kSceneSize); ceiling->SetSize(kSceneSize, kSceneSize);
......
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