Commit a6bf420a authored by Christopher Grant's avatar Christopher Grant Committed by Commit Bot

VR: Add initial UI sound support

This change wires up button hover and click sounds, and adds them to the
asset structure.

BUG=812026
R=tiborg

Cq-Include-Trybots: master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_vr;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: Iccf113e74663201c62aa220c7e134990369fd755
Reviewed-on: https://chromium-review.googlesource.com/953962
Commit-Queue: Christopher Grant <cjgrant@chromium.org>
Reviewed-by: default avatarTibor Goldschwendt <tiborg@chromium.org>
Reviewed-by: default avatarIan Vollick <vollick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542109}
parent addfa4e6
......@@ -17,6 +17,7 @@
#include "chrome/browser/vr/model/assets.h"
#include "chrome/browser/vr/model/omnibox_suggestions.h"
#include "chrome/browser/vr/model/toolbar_state.h"
#include "chrome/browser/vr/sounds_manager_audio_delegate.h"
#include "chrome/browser/vr/ui.h"
#include "chrome/common/chrome_features.h"
#include "third_party/skia/include/core/SkBitmap.h"
......@@ -66,8 +67,12 @@ void VrGLThread::Init() {
!keyboard_delegate_ ? nullptr : keyboard_delegate_.get();
if (!keyboard_delegate)
ui_initial_state_.needs_keyboard_update = true;
audio_delegate_ = std::make_unique<SoundsManagerAudioDelegate>();
auto ui = std::make_unique<Ui>(this, this, keyboard_delegate,
text_input_delegate_.get(), ui_initial_state_);
text_input_delegate_.get(),
audio_delegate_.get(), ui_initial_state_);
if (keyboard_enabled) {
text_input_delegate_->SetRequestFocusCallback(
base::BindRepeating(&Ui::RequestFocus, base::Unretained(ui.get())));
......@@ -91,6 +96,7 @@ void VrGLThread::Init() {
}
void VrGLThread::CleanUp() {
audio_delegate_.reset();
vr_shell_gl_.reset();
}
......
......@@ -16,6 +16,7 @@
#include "chrome/browser/vr/browser_ui_interface.h"
#include "chrome/browser/vr/content_input_delegate.h"
#include "chrome/browser/vr/model/omnibox_suggestions.h"
#include "chrome/browser/vr/model/sound_id.h"
#include "chrome/browser/vr/text_input_delegate.h"
#include "chrome/browser/vr/ui.h"
#include "chrome/browser/vr/ui_browser_interface.h"
......@@ -27,6 +28,7 @@ class Version;
namespace vr {
class AudioDelegate;
class VrInputConnection;
class VrShell;
class VrShellGl;
......@@ -131,6 +133,7 @@ class VrGLThread : public base::android::JavaHandlerThread,
std::unique_ptr<VrShellGl> vr_shell_gl_;
std::unique_ptr<GvrKeyboardDelegate> keyboard_delegate_;
std::unique_ptr<TextInputDelegate> text_input_delegate_;
std::unique_ptr<AudioDelegate> audio_delegate_;
base::WeakPtr<VrShell> weak_vr_shell_;
base::WeakPtr<BrowserUiInterface> weak_browser_ui_;
......
......@@ -183,6 +183,8 @@ static_library("vr_common") {
"service/vr_service_impl.h",
"sliding_average.cc",
"sliding_average.h",
"sounds_manager_audio_delegate.cc",
"sounds_manager_audio_delegate.h",
"speech_recognizer.cc",
"speech_recognizer.h",
"target_property.cc",
......
......@@ -22,6 +22,9 @@ namespace vr {
namespace {
constexpr char kMinVersionWithGradients[] = "1.1";
constexpr char kMinVersionWithSounds[] = "2.0";
static const base::FilePath::CharType kBackgroundBaseFilename[] =
FILE_PATH_LITERAL("background");
static const base::FilePath::CharType kNormalGradientBaseFilename[] =
......@@ -35,7 +38,12 @@ static const base::FilePath::CharType kPngExtension[] =
static const base::FilePath::CharType kJpegExtension[] =
FILE_PATH_LITERAL("jpeg");
constexpr char kMinVersionWithGradients[] = "1.1";
static const base::FilePath::CharType kButtonHoverSoundFilename[] =
FILE_PATH_LITERAL("button_hover.wav");
static const base::FilePath::CharType kButtonClickSoundFilename[] =
FILE_PATH_LITERAL("button_click.wav");
static const base::FilePath::CharType kBackButtonClickSoundFilename[] =
FILE_PATH_LITERAL("back_button_click.wav");
} // namespace
......@@ -147,6 +155,23 @@ AssetsLoadStatus LoadImage(const base::FilePath& component_install_dir,
return AssetsLoadStatus::kSuccess;
}
AssetsLoadStatus LoadSound(const base::FilePath& component_install_dir,
const base::FilePath::CharType* file_name,
std::unique_ptr<std::string>* out_buffer) {
base::FilePath file_path = component_install_dir.Append(file_name);
if (!base::PathExists(file_path)) {
return AssetsLoadStatus::kNotFound;
}
auto buffer = std::make_unique<std::string>();
if (!base::ReadFileToString(file_path, buffer.get())) {
return AssetsLoadStatus::kParseFailure;
}
*out_buffer = std::move(buffer);
return AssetsLoadStatus::kSuccess;
}
// static
void AssetsLoader::LoadAssetsTask(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
......@@ -174,6 +199,22 @@ void AssetsLoader::LoadAssetsTask(
}
}
if (status == AssetsLoadStatus::kSuccess &&
component_version >= base::Version(kMinVersionWithSounds)) {
std::vector<std::pair<const base::FilePath::CharType*,
std::unique_ptr<std::string>*>>
sounds = {
{kButtonHoverSoundFilename, &assets->button_hover_sound},
{kButtonClickSoundFilename, &assets->button_click_sound},
{kBackButtonClickSoundFilename, &assets->back_button_click_sound},
};
for (auto& sound : sounds) {
status = LoadSound(component_install_dir, sound.first, sound.second);
if (status != AssetsLoadStatus::kSuccess)
break;
}
}
if (status != AssetsLoadStatus::kSuccess) {
assets.reset();
}
......
......@@ -22,7 +22,7 @@ class Version;
namespace vr {
constexpr uint32_t kCompatibleMajorVrAssetsComponentVersion = 1;
constexpr uint32_t kCompatibleMajorVrAssetsComponentVersion = 2;
class MetricsHelper;
struct AssetsLoaderSingletonTrait;
......
// 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_AUDIO_DELEGATE_H_
#define CHROME_BROWSER_VR_AUDIO_DELEGATE_H_
#include <memory>
#include <string>
#include "chrome/browser/vr/model/sound_id.h"
namespace vr {
// This delegate interface describes an audio implementation supplied to the UI.
class AudioDelegate {
public:
virtual ~AudioDelegate() {}
// Clears all registered sounds. This must be done before re-registering a
// particular sound.
virtual void ResetSounds();
// The delegate must assume ownership of the audio data. A sound may only be
// registered once. To change the sound later, call ResetSounds and
// re-register all sounds.
virtual bool RegisterSound(SoundId id, std::unique_ptr<std::string> data) = 0;
virtual void PlaySound(SoundId id) = 0;
};
} // namespace vr
#endif // CHROME_BROWSER_VR_AUDIO_DELEGATE_H_
......@@ -21,7 +21,8 @@ constexpr float kIconScaleFactor = 0.5f;
} // namespace
DiscButton::DiscButton(base::RepeatingCallback<void()> click_handler,
const gfx::VectorIcon& icon)
const gfx::VectorIcon& icon,
AudioDelegate* audio_delegate)
: Button(click_handler) {
auto vector_icon = std::make_unique<VectorIcon>(512);
vector_icon->SetType(kTypeButtonForeground);
......@@ -35,6 +36,8 @@ DiscButton::DiscButton(base::RepeatingCallback<void()> click_handler,
auto target = RemoveChild(hit_plane());
vector_icon->AddChild(std::move(target));
AddChild(std::move(vector_icon));
SetSounds(kSoundButtonHover, kSoundBackButtonClick, audio_delegate);
}
DiscButton::~DiscButton() = default;
......
......@@ -22,7 +22,8 @@ class VectorIcon;
class DiscButton : public Button {
public:
DiscButton(base::RepeatingCallback<void()> click_handler,
const gfx::VectorIcon& icon);
const gfx::VectorIcon& icon,
AudioDelegate* audio_delegate);
~DiscButton() override;
VectorIcon* foreground() const { return foreground_; }
......
......@@ -18,7 +18,8 @@
namespace vr {
TEST(DiscButton, HoverTest) {
DiscButton button(base::RepeatingCallback<void()>(), vector_icons::kMicIcon);
DiscButton button(base::RepeatingCallback<void()>(), vector_icons::kMicIcon,
nullptr);
button.SetSize(1.0f, 1.0f);
button.set_hover_offset(0.5f);
......@@ -45,7 +46,8 @@ TEST(DiscButton, HoverTest) {
}
TEST(DiscButton, SizePropagatesToSubElements) {
DiscButton button(base::RepeatingCallback<void()>(), vector_icons::kMicIcon);
DiscButton button(base::RepeatingCallback<void()>(), vector_icons::kMicIcon,
nullptr);
gfx::SizeF size(1000.0f, 1000.0f);
gfx::SizeF icon_size = size;
icon_size.Scale(0.5f);
......@@ -69,7 +71,8 @@ TEST(DiscButton, SizePropagatesToSubElements) {
}
TEST(DiscButton, DrawPhasePropagatesToSubElements) {
DiscButton button(base::RepeatingCallback<void()>(), vector_icons::kMicIcon);
DiscButton button(base::RepeatingCallback<void()>(), vector_icons::kMicIcon,
nullptr);
button.SetDrawPhase(kPhaseOverlayForeground);
for (auto& child : button.children()) {
......@@ -78,7 +81,8 @@ TEST(DiscButton, DrawPhasePropagatesToSubElements) {
}
TEST(DiscButton, NamePropagatesToSubElements) {
DiscButton button(base::RepeatingCallback<void()>(), vector_icons::kMicIcon);
DiscButton button(base::RepeatingCallback<void()>(), vector_icons::kMicIcon,
nullptr);
button.SetName(kCloseButton);
for (auto& child : button.children()) {
......
......@@ -13,6 +13,7 @@
#include "base/strings/stringprintf.h"
#include "base/time/time.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/skia/include/core/SkRRect.h"
#include "third_party/skia/include/core/SkRect.h"
......@@ -139,6 +140,9 @@ void UiElement::Render(UiElementRenderer* renderer,
void UiElement::Initialize(SkiaSurfaceProvider* provider) {}
void UiElement::OnHoverEnter(const gfx::PointF& position) {
if (hover_sound_id_ != kSoundNone && audio_delegate_) {
audio_delegate_->PlaySound(hover_sound_id_);
}
if (event_handlers_.hover_enter) {
event_handlers_.hover_enter.Run();
} else if (parent() && bubble_events()) {
......@@ -163,6 +167,9 @@ void UiElement::OnMove(const gfx::PointF& position) {
}
void UiElement::OnButtonDown(const gfx::PointF& position) {
if (hover_sound_id_ != kSoundNone && audio_delegate_) {
audio_delegate_->PlaySound(click_sound_id_);
}
if (event_handlers_.button_down) {
event_handlers_.button_down.Run();
} else if (parent() && bubble_events()) {
......@@ -527,6 +534,14 @@ void UiElement::DumpGeometry(std::ostringstream* os) const {
}
#endif
void UiElement::SetSounds(SoundId hover,
SoundId click,
AudioDelegate* delegate) {
hover_sound_id_ = hover;
click_sound_id_ = click;
audio_delegate_ = delegate;
}
void UiElement::OnUpdatedWorldSpaceTransform() {}
gfx::SizeF UiElement::stale_size() const {
......
......@@ -15,6 +15,7 @@
#include "cc/animation/animation_target.h"
#include "cc/animation/transform_operations.h"
#include "chrome/browser/vr/animation.h"
#include "chrome/browser/vr/audio_delegate.h"
#include "chrome/browser/vr/databinding/binding_base.h"
#include "chrome/browser/vr/elements/corner_radii.h"
#include "chrome/browser/vr/elements/draw_phase.h"
......@@ -57,11 +58,11 @@ enum LayoutAlignment {
struct EventHandlers {
EventHandlers();
~EventHandlers();
base::Callback<void()> hover_enter;
base::Callback<void()> hover_leave;
base::Callback<void(const gfx::PointF&)> hover_move;
base::Callback<void()> button_down;
base::Callback<void()> button_up;
base::RepeatingCallback<void()> hover_enter;
base::RepeatingCallback<void()> hover_leave;
base::RepeatingCallback<void(const gfx::PointF&)> hover_move;
base::RepeatingCallback<void()> button_down;
base::RepeatingCallback<void()> button_up;
base::RepeatingCallback<void(bool)> focus_change;
};
......@@ -443,6 +444,10 @@ class UiElement : public cc::AnimationTarget {
// change your size based on your old size).
gfx::SizeF stale_size() const;
// Set the sounds that play when an applicable handler is executed. Elements
// that override element hover and click methods must manage their own sounds.
void SetSounds(SoundId hover, SoundId click, AudioDelegate* delegate);
protected:
Animation& animation() { return animation_; }
......@@ -568,6 +573,10 @@ class UiElement : public cc::AnimationTarget {
UpdatePhase phase_ = kClean;
AudioDelegate* audio_delegate_ = nullptr;
SoundId hover_sound_id_ = kSoundNone;
SoundId click_sound_id_ = kSoundNone;
DISALLOW_COPY_AND_ASSIGN(UiElement);
};
......
......@@ -29,6 +29,10 @@ struct Assets {
std::unique_ptr<SkBitmap> incognito_gradient;
std::unique_ptr<SkBitmap> fullscreen_gradient;
std::unique_ptr<std::string> button_hover_sound;
std::unique_ptr<std::string> button_click_sound;
std::unique_ptr<std::string> back_button_click_sound;
base::Version version;
};
......
// 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_SOUND_ID_H_
#define CHROME_BROWSER_VR_MODEL_SOUND_ID_H_
namespace vr {
enum SoundId {
kSoundNone,
kSoundButtonHover,
kSoundButtonClick,
kSoundBackButtonClick,
};
} // namespace vr
#endif // CHROME_BROWSER_VR_MODEL_SOUND_ID_H_
// 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.
#include "chrome/browser/vr/sounds_manager_audio_delegate.h"
#include "media/audio/sounds/sounds_manager.h"
namespace vr {
SoundsManagerAudioDelegate::SoundsManagerAudioDelegate() {}
SoundsManagerAudioDelegate::~SoundsManagerAudioDelegate() {
ResetSounds();
}
void SoundsManagerAudioDelegate::ResetSounds() {
// Because SoundsManager cannot replace a registered sound, start fresh
// with a new manager if needed.
if (!sounds_.empty()) {
media::SoundsManager::Shutdown();
sounds_.clear();
}
}
bool SoundsManagerAudioDelegate::RegisterSound(
SoundId id,
std::unique_ptr<std::string> data) {
DCHECK_NE(id, kSoundNone);
DCHECK(sounds_.find(id) == sounds_.end());
if (sounds_.empty())
media::SoundsManager::Create();
sounds_[id] = std::move(data);
return media::SoundsManager::Get()->Initialize(id, *sounds_[id]);
}
void SoundsManagerAudioDelegate::PlaySound(SoundId id) {
if (sounds_.find(id) != sounds_.end())
media::SoundsManager::Get()->Play(id);
}
} // namespace vr
// 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_SOUNDS_MANAGER_AUDIO_DELEGATE_H_
#define CHROME_BROWSER_VR_SOUNDS_MANAGER_AUDIO_DELEGATE_H_
#include <unordered_map>
#include "base/macros.h"
#include "chrome/browser/vr/audio_delegate.h"
namespace vr {
class SoundsManagerAudioDelegate : public AudioDelegate {
public:
SoundsManagerAudioDelegate();
~SoundsManagerAudioDelegate() override;
// AudioDelegate implementation.
void ResetSounds() override;
bool RegisterSound(SoundId, std::unique_ptr<std::string> data) override;
void PlaySound(SoundId id) override;
private:
std::unordered_map<SoundId, std::unique_ptr<std::string>> sounds_;
DISALLOW_COPY_AND_ASSIGN(SoundsManagerAudioDelegate);
};
} // namespace vr
#endif // CHROME_BROWSER_VR_SOUNDS_MANAGER_AUDIO_DELEGATE_H_
......@@ -57,7 +57,7 @@ void UiPixelTest::TearDown() {
void UiPixelTest::MakeUi(const UiInitialState& ui_initial_state,
const ToolbarState& toolbar_state) {
ui_ = std::make_unique<Ui>(browser_.get(), nullptr, nullptr, nullptr,
ui_ = std::make_unique<Ui>(browser_.get(), nullptr, nullptr, nullptr, nullptr,
ui_initial_state);
ui_->OnGlInitialized(content_texture_,
vr::UiElementRenderer::kTextureLocationLocal,
......
......@@ -76,7 +76,7 @@ void UiTest::CreateSceneInternal(
content_input_delegate_ = content_input_delegate.get();
ui_ = std::make_unique<Ui>(std::move(browser_.get()),
std::move(content_input_delegate), nullptr,
nullptr, state);
nullptr, nullptr, state);
scene_ = ui_->scene();
model_ = ui_->model_for_test();
model_->controller.transform.Translate3d(kStartControllerPosition);
......
......@@ -90,7 +90,8 @@ VrTestContext::VrTestContext() : view_scale_factor_(kDefaultViewScaleFactor) {
UiInitialState ui_initial_state;
ui_ = std::make_unique<Ui>(this, nullptr, keyboard_delegate_.get(),
text_input_delegate_.get(), ui_initial_state);
text_input_delegate_.get(), nullptr,
ui_initial_state);
LoadAssets();
text_input_delegate_->SetRequestFocusCallback(
......
......@@ -18,6 +18,7 @@
#include "chrome/browser/vr/model/assets.h"
#include "chrome/browser/vr/model/model.h"
#include "chrome/browser/vr/model/omnibox_suggestions.h"
#include "chrome/browser/vr/model/sound_id.h"
#include "chrome/browser/vr/speech_recognizer.h"
#include "chrome/browser/vr/ui_browser_interface.h"
#include "chrome/browser/vr/ui_element_renderer.h"
......@@ -32,25 +33,29 @@ namespace vr {
Ui::Ui(UiBrowserInterface* browser,
ContentInputForwarder* content_input_forwarder,
vr::KeyboardDelegate* keyboard_delegate,
vr::TextInputDelegate* text_input_delegate,
KeyboardDelegate* keyboard_delegate,
TextInputDelegate* text_input_delegate,
AudioDelegate* audio_delegate,
const UiInitialState& ui_initial_state)
: Ui(browser,
std::make_unique<ContentInputDelegate>(content_input_forwarder),
keyboard_delegate,
text_input_delegate,
audio_delegate,
ui_initial_state) {}
Ui::Ui(UiBrowserInterface* browser,
std::unique_ptr<ContentInputDelegate> content_input_delegate,
vr::KeyboardDelegate* keyboard_delegate,
vr::TextInputDelegate* text_input_delegate,
KeyboardDelegate* keyboard_delegate,
TextInputDelegate* text_input_delegate,
AudioDelegate* audio_delegate,
const UiInitialState& ui_initial_state)
: browser_(browser),
scene_(std::make_unique<UiScene>()),
model_(std::make_unique<Model>()),
content_input_delegate_(std::move(content_input_delegate)),
input_manager_(std::make_unique<UiInputManager>(scene_.get())),
audio_delegate_(audio_delegate),
weak_ptr_factory_(this) {
UiInitialState state = ui_initial_state;
if (keyboard_delegate != nullptr)
......@@ -58,7 +63,8 @@ Ui::Ui(UiBrowserInterface* browser,
InitializeModel(state);
UiSceneCreator(browser, scene_.get(), this, content_input_delegate_.get(),
keyboard_delegate, text_input_delegate, model_.get())
keyboard_delegate, text_input_delegate, audio_delegate,
model_.get())
.CreateScene();
}
......@@ -404,6 +410,19 @@ void Ui::OnAssetsLoaded(AssetsLoadStatus status,
ColorScheme::UpdateForComponent(component_version);
model_->background_loaded = true;
if (audio_delegate_) {
std::vector<std::pair<SoundId, std::unique_ptr<std::string>&>> sounds = {
{kSoundButtonHover, assets->button_hover_sound},
{kSoundButtonClick, assets->button_click_sound},
{kSoundBackButtonClick, assets->back_button_click_sound},
};
audio_delegate_->ResetSounds();
for (auto& sound : sounds) {
if (sound.second)
audio_delegate_->RegisterSound(sound.first, std::move(sound.second));
}
}
}
void Ui::OnAssetsUnavailable() {
......
......@@ -17,6 +17,7 @@
#include "chrome/browser/vr/ui_element_renderer.h"
namespace vr {
class AudioDelegate;
class BrowserUiInterface;
class ContentInputDelegate;
class ContentInputForwarder;
......@@ -51,14 +52,16 @@ class Ui : public BrowserUiInterface, public KeyboardUiInterface {
public:
Ui(UiBrowserInterface* browser,
ContentInputForwarder* content_input_forwarder,
vr::KeyboardDelegate* keyboard_delegate,
vr::TextInputDelegate* text_input_delegate,
KeyboardDelegate* keyboard_delegate,
TextInputDelegate* text_input_delegate,
AudioDelegate* audio_delegate,
const UiInitialState& ui_initial_state);
Ui(UiBrowserInterface* browser,
std::unique_ptr<ContentInputDelegate> content_input_delegate,
vr::KeyboardDelegate* keyboard_delegate,
vr::TextInputDelegate* text_input_delegate,
KeyboardDelegate* keyboard_delegate,
TextInputDelegate* text_input_delegate,
AudioDelegate* audio_delegate,
const UiInitialState& ui_initial_state);
~Ui() override;
......@@ -71,7 +74,7 @@ class Ui : public BrowserUiInterface, public KeyboardUiInterface {
UiRenderer* ui_renderer() { return ui_renderer_.get(); }
UiInputManager* input_manager() { return input_manager_.get(); }
base::WeakPtr<vr::BrowserUiInterface> GetBrowserUiWeakPtr();
base::WeakPtr<BrowserUiInterface> GetBrowserUiWeakPtr();
// BrowserUiInterface
void SetWebVrMode(bool enabled, bool show_toast) override;
......@@ -165,14 +168,16 @@ class Ui : public BrowserUiInterface, public KeyboardUiInterface {
UiBrowserInterface* browser_;
// This state may be further abstracted into a SkiaUi object.
std::unique_ptr<vr::UiScene> scene_;
std::unique_ptr<vr::Model> model_;
std::unique_ptr<vr::ContentInputDelegate> content_input_delegate_;
std::unique_ptr<vr::UiElementRenderer> ui_element_renderer_;
std::unique_ptr<vr::UiInputManager> input_manager_;
std::unique_ptr<vr::UiRenderer> ui_renderer_;
std::unique_ptr<UiScene> scene_;
std::unique_ptr<Model> model_;
std::unique_ptr<ContentInputDelegate> content_input_delegate_;
std::unique_ptr<UiElementRenderer> ui_element_renderer_;
std::unique_ptr<UiInputManager> input_manager_;
std::unique_ptr<UiRenderer> ui_renderer_;
std::unique_ptr<SkiaSurfaceProvider> provider_;
AudioDelegate* audio_delegate_ = nullptr;
base::WeakPtrFactory<Ui> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(Ui);
......
......@@ -132,6 +132,7 @@ void OnSuggestionModelAdded(UiScene* scene,
UiBrowserInterface* browser,
Ui* ui,
Model* model,
AudioDelegate* audio_delegate,
SuggestionBinding* element_binding) {
auto icon = std::make_unique<VectorIcon>(100);
icon->SetDrawPhase(kPhaseForeground);
......@@ -197,6 +198,7 @@ void OnSuggestionModelAdded(UiScene* scene,
background->set_bubble_events(true);
background->set_bounds_contain_children(true);
background->set_hover_offset(0.0);
background->SetSounds(kSoundButtonHover, kSoundButtonClick, audio_delegate);
VR_BIND_BUTTON_COLORS(model, background.get(),
&ColorScheme::suggestion_button_colors,
&Button::SetButtonColors);
......@@ -592,6 +594,7 @@ UiSceneCreator::UiSceneCreator(UiBrowserInterface* browser,
ContentInputDelegate* content_input_delegate,
KeyboardDelegate* keyboard_delegate,
TextInputDelegate* text_input_delegate,
AudioDelegate* audio_delegate,
Model* model)
: browser_(browser),
scene_(scene),
......@@ -599,6 +602,7 @@ UiSceneCreator::UiSceneCreator(UiBrowserInterface* browser,
content_input_delegate_(content_input_delegate),
keyboard_delegate_(keyboard_delegate),
text_input_delegate_(text_input_delegate),
audio_delegate_(audio_delegate),
model_(model) {}
UiSceneCreator::~UiSceneCreator() {}
......@@ -1130,7 +1134,7 @@ void UiSceneCreator::CreateWebVrTimeoutScreen() {
Create<DiscButton>(kWebVrTimeoutMessageButton, kPhaseForeground,
base::BindRepeating(&UiBrowserInterface::ExitPresent,
base::Unretained(browser_)),
vector_icons::kClose16Icon);
vector_icons::kClose16Icon, audio_delegate_);
button->SetVisible(false);
button->SetTranslate(0, -kTimeoutMessageTextWidthDMM, 0);
button->SetRotate(1, 0, 0, kTimeoutButtonRotationRad);
......@@ -1403,7 +1407,7 @@ void UiSceneCreator::CreateVoiceSearchUiGroup() {
kSpeechRecognitionListeningCloseButton, kPhaseForeground,
base::BindRepeating(&UiBrowserInterface::SetVoiceSearchActive,
base::Unretained(browser_), false),
vector_icons::kClose16Icon);
vector_icons::kClose16Icon, audio_delegate_);
close_button->SetSize(kVoiceSearchCloseButtonDiameter,
kVoiceSearchCloseButtonDiameter);
close_button->set_hover_offset(kButtonZOffsetHoverDMM * kContentDistance);
......@@ -1448,7 +1452,7 @@ void UiSceneCreator::CreateContentRepositioningAffordance() {
base::BindRepeating(
[](Model* model) { model->push_mode(kModeRepositionWindow); },
base::Unretained(model_)),
kRepositionIcon);
kRepositionIcon, audio_delegate_);
reposition_button->SetSize(kRepositionButtonDiameter,
kRepositionButtonDiameter);
reposition_button->set_y_anchoring(BOTTOM);
......@@ -1463,6 +1467,7 @@ void UiSceneCreator::CreateContentRepositioningAffordance() {
reposition_button->background()->SetTransitionedProperties(
{BACKGROUND_COLOR, TRANSFORM});
reposition_button->SetOpacity(kRepositionButtonMinOpacity);
reposition_button->SetSounds(kSoundNone, kSoundNone, nullptr);
reposition_button->AddBinding(std::make_unique<Binding<float>>(
VR_BIND_LAMBDA(
[](Model* model, Button* button) {
......@@ -1681,6 +1686,7 @@ void UiSceneCreator::CreateUrlBar() {
back_button->SetCornerRadii(
{kUrlBarHeightDMM / 2, 0, kUrlBarHeightDMM / 2, 0});
back_button->set_hover_offset(0.0f);
back_button->SetSounds(kSoundButtonHover, kSoundButtonClick, audio_delegate_);
back_button->AddBinding(VR_BIND_FUNC(bool, Model, model_,
model->can_navigate_back, Button,
back_button.get(), set_enabled));
......@@ -2043,6 +2049,8 @@ void UiSceneCreator::CreateOmnibox() {
mic_icon_box->SetSize(kOmniboxTextFieldIconButtonSizeDMM,
kOmniboxTextFieldIconButtonSizeDMM);
mic_icon_box->set_corner_radius(kOmniboxTextFieldIconButtonRadiusDMM);
mic_icon_box->SetSounds(kSoundButtonHover, kSoundButtonClick,
audio_delegate_);
VR_BIND_VISIBILITY(mic_icon_box,
model->speech.has_or_can_request_audio_permission &&
!model->incognito &&
......@@ -2072,10 +2080,10 @@ void UiSceneCreator::CreateOmnibox() {
text_field_layout->AddChild(std::move(right_spacer));
// Set up the vector binding to manage suggestions dynamically.
SuggestionSetBinding::ModelAddedCallback added_callback =
base::BindRepeating(&OnSuggestionModelAdded, base::Unretained(scene_),
base::Unretained(browser_), base::Unretained(ui_),
base::Unretained(model_));
SuggestionSetBinding::ModelAddedCallback added_callback = base::BindRepeating(
&OnSuggestionModelAdded, base::Unretained(scene_),
base::Unretained(browser_), base::Unretained(ui_),
base::Unretained(model_), base::Unretained(audio_delegate_));
SuggestionSetBinding::ModelRemovedCallback removed_callback =
base::BindRepeating(&OnSuggestionModelRemoved, base::Unretained(scene_));
......@@ -2097,7 +2105,7 @@ void UiSceneCreator::CreateOmnibox() {
base::BindRepeating(
[](Model* model) { model->pop_mode(kModeEditingOmnibox); },
base::Unretained(model_)),
vector_icons::kBackArrowIcon);
vector_icons::kBackArrowIcon, audio_delegate_);
close_button->SetSize(kOmniboxCloseButtonDiameterDMM,
kOmniboxCloseButtonDiameterDMM);
close_button->SetTranslate(0, kOmniboxCloseButtonVerticalOffsetDMM, 0);
......@@ -2148,7 +2156,7 @@ void UiSceneCreator::CreateCloseButton() {
base::Unretained(model_), base::Unretained(browser_));
std::unique_ptr<DiscButton> element =
Create<DiscButton>(kCloseButton, kPhaseForeground, click_handler,
vector_icons::kClose16Icon);
vector_icons::kClose16Icon, audio_delegate_);
element->SetSize(kCloseButtonDiameter, kCloseButtonDiameter);
element->set_hover_offset(kButtonZOffsetHoverDMM * kCloseButtonDistance);
element->SetTranslate(0, kCloseButtonVerticalOffset, -kCloseButtonDistance);
......
......@@ -29,6 +29,7 @@ class UiSceneCreator {
ContentInputDelegate* content_input_delegate,
KeyboardDelegate* keyboard_delegate,
TextInputDelegate* text_input_delegate,
AudioDelegate* audio_delegate,
Model* model);
~UiSceneCreator();
......@@ -66,6 +67,7 @@ class UiSceneCreator {
ContentInputDelegate* content_input_delegate_;
KeyboardDelegate* keyboard_delegate_;
TextInputDelegate* text_input_delegate_;
AudioDelegate* audio_delegate_;
Model* model_;
DISALLOW_COPY_AND_ASSIGN(UiSceneCreator);
......
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