Commit 7e81ef70 authored by Ian Vollick's avatar Ian Vollick Committed by Commit Bot

[vr] Repositioning tweaks

This changes the direction you need to scroll to increase the size of
the content window to match the spec.

It also adds sounds for repositioning (and introduces a struct ot hang
onto a bunch of sounds).

Bug: 799270
Cq-Include-Trybots: luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_vr;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: Ifa538a70575e8c508db07d9d12d588e3ecbabc6e
Reviewed-on: https://chromium-review.googlesource.com/973263
Commit-Queue: Ian Vollick <vollick@chromium.org>
Reviewed-by: default avatarChristopher Grant <cjgrant@chromium.org>
Cr-Commit-Position: refs/heads/master@{#544719}
parent 3d42a133
...@@ -37,7 +37,10 @@ DiscButton::DiscButton(base::RepeatingCallback<void()> click_handler, ...@@ -37,7 +37,10 @@ DiscButton::DiscButton(base::RepeatingCallback<void()> click_handler,
vector_icon->AddChild(std::move(target)); vector_icon->AddChild(std::move(target));
AddChild(std::move(vector_icon)); AddChild(std::move(vector_icon));
SetSounds(kSoundButtonHover, kSoundBackButtonClick, audio_delegate); Sounds sounds;
sounds.hover_enter = kSoundButtonHover;
sounds.button_down = kSoundBackButtonClick;
SetSounds(sounds, audio_delegate);
} }
DiscButton::~DiscButton() = default; DiscButton::~DiscButton() = default;
......
...@@ -61,7 +61,7 @@ void Resizer::Reset() { ...@@ -61,7 +61,7 @@ void Resizer::Reset() {
void Resizer::UpdateTransform(const gfx::Transform& head_pose) { void Resizer::UpdateTransform(const gfx::Transform& head_pose) {
float delta = touchpad_position_.y() - initial_touchpad_position_.y(); float delta = touchpad_position_.y() - initial_touchpad_position_.y();
t_ = base::ClampToRange(initial_t_ - delta, 0.0f, 1.0f); t_ = base::ClampToRange(initial_t_ + delta, 0.0f, 1.0f);
float scale = float scale =
gfx::Tween::FloatValueBetween(t_, kMinResizerScale, kMaxResizerScale); gfx::Tween::FloatValueBetween(t_, kMinResizerScale, kMaxResizerScale);
transform_.MakeIdentity(); transform_.MakeIdentity();
......
...@@ -62,21 +62,21 @@ TEST_F(ResizerTest, HorizontalMove) { ...@@ -62,21 +62,21 @@ TEST_F(ResizerTest, HorizontalMove) {
} }
TEST_F(ResizerTest, UpwardMove) { TEST_F(ResizerTest, UpwardMove) {
Move({0.5f, 0.5f}, {0.5f, 1.0f}); Move({0.5f, 0.5f}, {0.5f, 0.0f});
CheckScale(kMinResizerScale); CheckScale(kMinResizerScale);
} }
TEST_F(ResizerTest, DownwardMove) { TEST_F(ResizerTest, DownwardMove) {
Move({0.5f, 0.5f}, {0.5f, 0.0f}); Move({0.5f, 0.5f}, {0.5f, 1.0f});
CheckScale(kMaxResizerScale); CheckScale(kMaxResizerScale);
} }
TEST_F(ResizerTest, AccumulatedMove) { TEST_F(ResizerTest, AccumulatedMove) {
Move({0.5f, 0.5f}, {0.5f, 0.25f}); Move({0.5f, 0.5f}, {0.5f, 0.75f});
float scale = ComputeScale(); float scale = ComputeScale();
EXPECT_LT(1.0f, scale); EXPECT_LT(1.0f, scale);
EXPECT_GT(kMaxResizerScale, scale); EXPECT_GT(kMaxResizerScale, scale);
Move({0.5f, 0.5f}, {0.5f, 0.25f}); Move({0.5f, 0.5f}, {0.5f, 0.75f});
CheckScale(kMaxResizerScale); CheckScale(kMaxResizerScale);
} }
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/vr/model/camera_model.h" #include "chrome/browser/vr/model/camera_model.h"
#include "chrome/browser/vr/model/sound_id.h"
#include "third_party/WebKit/public/platform/WebGestureEvent.h" #include "third_party/WebKit/public/platform/WebGestureEvent.h"
#include "third_party/skia/include/core/SkRRect.h" #include "third_party/skia/include/core/SkRRect.h"
#include "third_party/skia/include/core/SkRect.h" #include "third_party/skia/include/core/SkRect.h"
...@@ -141,8 +140,8 @@ void UiElement::Render(UiElementRenderer* renderer, ...@@ -141,8 +140,8 @@ void UiElement::Render(UiElementRenderer* renderer,
void UiElement::Initialize(SkiaSurfaceProvider* provider) {} void UiElement::Initialize(SkiaSurfaceProvider* provider) {}
void UiElement::OnHoverEnter(const gfx::PointF& position) { void UiElement::OnHoverEnter(const gfx::PointF& position) {
if (hover_sound_id_ != kSoundNone && audio_delegate_) { if (sounds_.hover_enter != kSoundNone && audio_delegate_) {
audio_delegate_->PlaySound(hover_sound_id_); audio_delegate_->PlaySound(sounds_.hover_enter);
} }
if (event_handlers_.hover_enter) { if (event_handlers_.hover_enter) {
event_handlers_.hover_enter.Run(); event_handlers_.hover_enter.Run();
...@@ -152,6 +151,9 @@ void UiElement::OnHoverEnter(const gfx::PointF& position) { ...@@ -152,6 +151,9 @@ void UiElement::OnHoverEnter(const gfx::PointF& position) {
} }
void UiElement::OnHoverLeave() { void UiElement::OnHoverLeave() {
if (sounds_.hover_leave != kSoundNone && audio_delegate_) {
audio_delegate_->PlaySound(sounds_.hover_leave);
}
if (event_handlers_.hover_leave) { if (event_handlers_.hover_leave) {
event_handlers_.hover_leave.Run(); event_handlers_.hover_leave.Run();
} else if (parent() && bubble_events()) { } else if (parent() && bubble_events()) {
...@@ -160,6 +162,9 @@ void UiElement::OnHoverLeave() { ...@@ -160,6 +162,9 @@ void UiElement::OnHoverLeave() {
} }
void UiElement::OnMove(const gfx::PointF& position) { void UiElement::OnMove(const gfx::PointF& position) {
if (sounds_.move != kSoundNone && audio_delegate_) {
audio_delegate_->PlaySound(sounds_.move);
}
if (event_handlers_.hover_move) { if (event_handlers_.hover_move) {
event_handlers_.hover_move.Run(position); event_handlers_.hover_move.Run(position);
} else if (parent() && bubble_events()) { } else if (parent() && bubble_events()) {
...@@ -168,8 +173,8 @@ void UiElement::OnMove(const gfx::PointF& position) { ...@@ -168,8 +173,8 @@ void UiElement::OnMove(const gfx::PointF& position) {
} }
void UiElement::OnButtonDown(const gfx::PointF& position) { void UiElement::OnButtonDown(const gfx::PointF& position) {
if (hover_sound_id_ != kSoundNone && audio_delegate_) { if (sounds_.button_down != kSoundNone && audio_delegate_) {
audio_delegate_->PlaySound(click_sound_id_); audio_delegate_->PlaySound(sounds_.button_down);
} }
if (event_handlers_.button_down) { if (event_handlers_.button_down) {
event_handlers_.button_down.Run(); event_handlers_.button_down.Run();
...@@ -179,6 +184,9 @@ void UiElement::OnButtonDown(const gfx::PointF& position) { ...@@ -179,6 +184,9 @@ void UiElement::OnButtonDown(const gfx::PointF& position) {
} }
void UiElement::OnButtonUp(const gfx::PointF& position) { void UiElement::OnButtonUp(const gfx::PointF& position) {
if (sounds_.button_up != kSoundNone && audio_delegate_) {
audio_delegate_->PlaySound(sounds_.button_up);
}
if (event_handlers_.button_up) { if (event_handlers_.button_up) {
event_handlers_.button_up.Run(); event_handlers_.button_up.Run();
} else if (parent() && bubble_events()) { } else if (parent() && bubble_events()) {
...@@ -535,11 +543,8 @@ void UiElement::DumpGeometry(std::ostringstream* os) const { ...@@ -535,11 +543,8 @@ void UiElement::DumpGeometry(std::ostringstream* os) const {
} }
#endif #endif
void UiElement::SetSounds(SoundId hover, void UiElement::SetSounds(Sounds sounds, AudioDelegate* delegate) {
SoundId click, sounds_ = sounds;
AudioDelegate* delegate) {
hover_sound_id_ = hover;
click_sound_id_ = click;
audio_delegate_ = delegate; audio_delegate_ = delegate;
} }
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "chrome/browser/vr/elements/ui_element_type.h" #include "chrome/browser/vr/elements/ui_element_type.h"
#include "chrome/browser/vr/model/camera_model.h" #include "chrome/browser/vr/model/camera_model.h"
#include "chrome/browser/vr/model/reticle_model.h" #include "chrome/browser/vr/model/reticle_model.h"
#include "chrome/browser/vr/model/sounds.h"
#include "chrome/browser/vr/target_property.h" #include "chrome/browser/vr/target_property.h"
#include "ui/gfx/geometry/point3_f.h" #include "ui/gfx/geometry/point3_f.h"
#include "ui/gfx/geometry/quaternion.h" #include "ui/gfx/geometry/quaternion.h"
...@@ -472,7 +473,7 @@ class UiElement : public cc::AnimationTarget { ...@@ -472,7 +473,7 @@ class UiElement : public cc::AnimationTarget {
// Set the sounds that play when an applicable handler is executed. Elements // Set the sounds that play when an applicable handler is executed. Elements
// that override element hover and click methods must manage their own sounds. // that override element hover and click methods must manage their own sounds.
void SetSounds(SoundId hover, SoundId click, AudioDelegate* delegate); void SetSounds(Sounds sounds, AudioDelegate* delegate);
bool resizable_by_layout() { return resizable_by_layout_; } bool resizable_by_layout() { return resizable_by_layout_; }
void set_resizable_by_layout(bool resizable) { void set_resizable_by_layout(bool resizable) {
...@@ -608,8 +609,7 @@ class UiElement : public cc::AnimationTarget { ...@@ -608,8 +609,7 @@ class UiElement : public cc::AnimationTarget {
UpdatePhase phase_ = kClean; UpdatePhase phase_ = kClean;
AudioDelegate* audio_delegate_ = nullptr; AudioDelegate* audio_delegate_ = nullptr;
SoundId hover_sound_id_ = kSoundNone; Sounds sounds_;
SoundId click_sound_id_ = kSoundNone;
// Indicates that this element may be resized by parent layout elements. // Indicates that this element may be resized by parent layout elements.
bool resizable_by_layout_ = false; bool resizable_by_layout_ = false;
......
// 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 CHROME_BROWSER_VR_MODEL_SOUNDS_H_
#define CHROME_BROWSER_VR_MODEL_SOUNDS_H_
#include "chrome/browser/vr/model/sound_id.h"
namespace vr {
struct Sounds {
SoundId hover_enter = kSoundNone;
SoundId hover_leave = kSoundNone;
SoundId button_down = kSoundNone;
SoundId button_up = kSoundNone;
SoundId move = kSoundNone;
};
} // namespace vr
#endif // CHROME_BROWSER_VR_MODEL_SOUNDS_H_
...@@ -126,6 +126,13 @@ std::unique_ptr<T> Create(UiElementName name, DrawPhase phase, Args&&... args) { ...@@ -126,6 +126,13 @@ std::unique_ptr<T> Create(UiElementName name, DrawPhase phase, Args&&... args) {
return element; return element;
} }
Sounds CreateButtonSounds() {
Sounds sounds;
sounds.hover_enter = kSoundButtonHover;
sounds.button_down = kSoundButtonClick;
return sounds;
}
typedef VectorBinding<OmniboxSuggestion, Button> SuggestionSetBinding; typedef VectorBinding<OmniboxSuggestion, Button> SuggestionSetBinding;
typedef typename SuggestionSetBinding::ElementBinding SuggestionBinding; typedef typename SuggestionSetBinding::ElementBinding SuggestionBinding;
...@@ -200,7 +207,7 @@ void OnSuggestionModelAdded(UiScene* scene, ...@@ -200,7 +207,7 @@ void OnSuggestionModelAdded(UiScene* scene,
background->set_bubble_events(true); background->set_bubble_events(true);
background->set_bounds_contain_children(true); background->set_bounds_contain_children(true);
background->set_hover_offset(0.0); background->set_hover_offset(0.0);
background->SetSounds(kSoundButtonHover, kSoundButtonClick, audio_delegate); background->SetSounds(CreateButtonSounds(), audio_delegate);
VR_BIND_BUTTON_COLORS(model, background.get(), VR_BIND_BUTTON_COLORS(model, background.get(),
&ColorScheme::suggestion_button_colors, &ColorScheme::suggestion_button_colors,
&Button::SetButtonColors); &Button::SetButtonColors);
...@@ -1080,6 +1087,9 @@ void UiSceneCreator::CreateContentQuad() { ...@@ -1080,6 +1087,9 @@ void UiSceneCreator::CreateContentQuad() {
plane->set_bounds_contain_padding(false); plane->set_bounds_contain_padding(false);
plane->set_corner_radius(kContentCornerRadius); plane->set_corner_radius(kContentCornerRadius);
plane->set_cursor_type(kCursorReposition); plane->set_cursor_type(kCursorReposition);
Sounds sounds;
sounds.button_up = kSoundButtonClick;
plane->SetSounds(sounds, audio_delegate_);
plane->set_padding(0, kRepositionFrameHitPlaneTopPadding, 0, 0); plane->set_padding(0, kRepositionFrameHitPlaneTopPadding, 0, 0);
plane->set_event_handlers(CreateRepositioningHandlers(model_, scene_)); plane->set_event_handlers(CreateRepositioningHandlers(model_, scene_));
...@@ -1566,6 +1576,9 @@ void UiSceneCreator::CreateContentRepositioningAffordance() { ...@@ -1566,6 +1576,9 @@ void UiSceneCreator::CreateContentRepositioningAffordance() {
hit_plane->SetSize(kSceneSize, kSceneSize); hit_plane->SetSize(kSceneSize, kSceneSize);
hit_plane->SetTranslate(0.0f, 0.0f, -kContentDistance); hit_plane->SetTranslate(0.0f, 0.0f, -kContentDistance);
hit_plane->set_cursor_type(kCursorReposition); hit_plane->set_cursor_type(kCursorReposition);
Sounds sounds;
sounds.button_up = kSoundButtonClick;
hit_plane->SetSounds(sounds, audio_delegate_);
EventHandlers event_handlers; EventHandlers event_handlers;
event_handlers.button_up = base::BindRepeating( event_handlers.button_up = base::BindRepeating(
[](Model* m) { [](Model* m) {
...@@ -1758,7 +1771,7 @@ void UiSceneCreator::CreateUrlBar() { ...@@ -1758,7 +1771,7 @@ void UiSceneCreator::CreateUrlBar() {
back_button->SetCornerRadii( back_button->SetCornerRadii(
{kUrlBarHeightDMM / 2, 0, kUrlBarHeightDMM / 2, 0}); {kUrlBarHeightDMM / 2, 0, kUrlBarHeightDMM / 2, 0});
back_button->set_hover_offset(0.0f); back_button->set_hover_offset(0.0f);
back_button->SetSounds(kSoundButtonHover, kSoundButtonClick, audio_delegate_); back_button->SetSounds(CreateButtonSounds(), audio_delegate_);
back_button->AddBinding(VR_BIND_FUNC(bool, Model, model_, back_button->AddBinding(VR_BIND_FUNC(bool, Model, model_,
model->can_navigate_back, Button, model->can_navigate_back, Button,
back_button.get(), set_enabled)); back_button.get(), set_enabled));
...@@ -1862,8 +1875,7 @@ void UiSceneCreator::CreateUrlBar() { ...@@ -1862,8 +1875,7 @@ void UiSceneCreator::CreateUrlBar() {
overflow_button->SetCornerRadii( overflow_button->SetCornerRadii(
{0, kUrlBarHeightDMM / 2, 0, kUrlBarHeightDMM / 2}); {0, kUrlBarHeightDMM / 2, 0, kUrlBarHeightDMM / 2});
overflow_button->set_hover_offset(0.0f); overflow_button->set_hover_offset(0.0f);
overflow_button->SetSounds(kSoundButtonHover, kSoundButtonClick, overflow_button->SetSounds(CreateButtonSounds(), audio_delegate_);
audio_delegate_);
VR_BIND_BUTTON_COLORS(model_, overflow_button.get(), VR_BIND_BUTTON_COLORS(model_, overflow_button.get(),
&ColorScheme::back_button, &Button::SetButtonColors); &ColorScheme::back_button, &Button::SetButtonColors);
scene_->AddUiElement(kUrlBarLayout, std::move(overflow_button)); scene_->AddUiElement(kUrlBarLayout, std::move(overflow_button));
...@@ -2276,7 +2288,7 @@ void UiSceneCreator::CreateOmnibox() { ...@@ -2276,7 +2288,7 @@ void UiSceneCreator::CreateOmnibox() {
kOmniboxTextFieldIconButtonSizeDMM); kOmniboxTextFieldIconButtonSizeDMM);
mic_button->set_hover_offset(kOmniboxTextFieldIconButtonHoverOffsetDMM); mic_button->set_hover_offset(kOmniboxTextFieldIconButtonHoverOffsetDMM);
mic_button->set_corner_radius(kUrlBarItemCornerRadiusDMM); mic_button->set_corner_radius(kUrlBarItemCornerRadiusDMM);
mic_button->SetSounds(kSoundButtonHover, kSoundButtonClick, audio_delegate_); mic_button->SetSounds(CreateButtonSounds(), audio_delegate_);
VR_BIND_VISIBILITY(mic_button, VR_BIND_VISIBILITY(mic_button,
model->speech.has_or_can_request_audio_permission && model->speech.has_or_can_request_audio_permission &&
......
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