Commit a8952d32 authored by Ian Vollick's avatar Ian Vollick Committed by Commit Bot

[vr] Move mic button on hover

With this change, I've added a hover offset to the mic button. I've also
generalized some button code so that it can be reused by the mic button.
(Specifically, you can now set the corner radius of the disc button, and
we may want to rename this class eventually).

Bug: 818008
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: I0884b90ae19d34952c639653850ede4754e16fc8
Reviewed-on: https://chromium-review.googlesource.com/958221Reviewed-by: default avatarBiao She <bshe@chromium.org>
Commit-Queue: Ian Vollick <vollick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542536}
parent 6ec63231
......@@ -64,6 +64,11 @@ void DiscButton::OnSetName() {
foreground_->set_owner_name_for_test(name());
}
void DiscButton::OnSetCornerRadii(const CornerRadii& radii) {
Button::OnSetCornerRadii(radii);
foreground_->SetCornerRadii(radii);
}
void DiscButton::NotifyClientSizeAnimated(const gfx::SizeF& size,
int target_property_id,
cc::KeyframeModel* animation) {
......
......@@ -32,6 +32,7 @@ class DiscButton : public Button {
void OnStateUpdated() override;
void OnSetDrawPhase() override;
void OnSetName() override;
void OnSetCornerRadii(const CornerRadii& radii) override;
void NotifyClientSizeAnimated(const gfx::SizeF& size,
int target_property_id,
cc::KeyframeModel* keyframe_model) override;
......
......@@ -81,7 +81,6 @@ static const char* g_ui_element_name_strings[] = {
"kLoadingIndicator",
"kLoadingIndicatorForeground",
"kCloseButton",
"kVoiceSearchButton",
"kScreenDimmer",
"kExitWarningText",
"kExitWarningBackground",
......
......@@ -80,7 +80,6 @@ enum UiElementName {
kLoadingIndicator,
kLoadingIndicatorForeground,
kCloseButton,
kVoiceSearchButton,
kScreenDimmer,
kExitWarningText,
kExitWarningBackground,
......
......@@ -220,7 +220,7 @@ static constexpr int kOmniboxTransitionMs = 300;
static constexpr float kOmniboxTextFieldIconSizeDMM = 0.05f;
static constexpr float kOmniboxTextFieldIconButtonSizeDMM = 0.064f;
static constexpr float kOmniboxTextFieldIconButtonRadiusDMM = 0.006f;
static constexpr float kOmniboxTextFieldIconButtonHoverOffsetDMM = 0.0f;
static constexpr float kOmniboxTextFieldIconButtonHoverOffsetDMM = 0.012f;
static constexpr float kOmniboxTextFieldRightMargin =
((kOmniboxHeightDMM - kOmniboxTextFieldIconButtonSizeDMM) / 2);
......
......@@ -2073,33 +2073,26 @@ void UiSceneCreator::CreateOmnibox() {
},
base::Unretained(omnibox_text_field.get()))));
auto mic_icon =
Create<VectorIcon>(kOmniboxVoiceSearchButton, kPhaseForeground, 100);
mic_icon->SetIcon(vector_icons::kMicIcon);
mic_icon->SetSize(kOmniboxTextFieldIconSizeDMM, kOmniboxTextFieldIconSizeDMM);
VR_BIND_COLOR(model_, mic_icon.get(), &ColorScheme::omnibox_text,
&VectorIcon::SetColor);
auto mic_icon_box = Create<Button>(
kVoiceSearchButton, kPhaseForeground,
auto mic_button = Create<DiscButton>(
kOmniboxVoiceSearchButton, kPhaseForeground,
base::BindRepeating(
[](UiBrowserInterface* b, Ui* ui) { b->SetVoiceSearchActive(true); },
base::Unretained(browser_), base::Unretained(ui_)));
mic_icon_box->set_hover_offset(kOmniboxTextFieldIconButtonHoverOffsetDMM);
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,
base::Unretained(browser_), base::Unretained(ui_)),
vector_icons::kMicIcon, audio_delegate_);
mic_button->SetSize(kOmniboxTextFieldIconButtonSizeDMM,
kOmniboxTextFieldIconButtonSizeDMM);
mic_button->set_hover_offset(kOmniboxTextFieldIconButtonHoverOffsetDMM);
mic_button->set_corner_radius(kOmniboxTextFieldIconButtonRadiusDMM);
mic_button->SetSounds(kSoundButtonHover, kSoundButtonClick, audio_delegate_);
VR_BIND_VISIBILITY(mic_button,
model->speech.has_or_can_request_audio_permission &&
!model->incognito &&
!model->capturing_state.audio_capture_enabled);
VR_BIND_BUTTON_COLORS(model_, mic_icon_box.get(),
VR_BIND_BUTTON_COLORS(model_, mic_button.get(),
&ColorScheme::omnibox_voice_search_button_colors,
&Button::SetButtonColors);
mic_icon_box->AddChild(std::move(mic_icon));
auto left_spacer = Create<Rect>(kNone, kPhaseNone);
left_spacer->SetSize(kOmniboxTextMarginDMM, kOmniboxTextHeightDMM);
......@@ -2116,7 +2109,7 @@ void UiSceneCreator::CreateOmnibox() {
text_field_layout->AddChild(std::move(left_spacer));
text_field_layout->AddChild(std::move(omnibox_text_field));
text_field_layout->AddChild(std::move(middle_spacer));
text_field_layout->AddChild(std::move(mic_icon_box));
text_field_layout->AddChild(std::move(mic_button));
text_field_layout->AddChild(std::move(right_spacer));
// Set up the vector binding to manage suggestions dynamically.
......
......@@ -254,11 +254,11 @@ TEST_F(UiTest, VoiceSearchHiddenInIncognito) {
model_->push_mode(kModeEditingOmnibox);
EXPECT_TRUE(OnBeginFrame());
EXPECT_TRUE(IsVisible(kVoiceSearchButton));
EXPECT_TRUE(IsVisible(kOmniboxVoiceSearchButton));
model_->incognito = true;
EXPECT_TRUE(OnBeginFrame());
EXPECT_FALSE(IsVisible(kVoiceSearchButton));
EXPECT_FALSE(IsVisible(kOmniboxVoiceSearchButton));
}
TEST_F(UiTest, VoiceSearchHiddenWhenCantAskForPermission) {
......@@ -267,11 +267,11 @@ TEST_F(UiTest, VoiceSearchHiddenWhenCantAskForPermission) {
model_->push_mode(kModeEditingOmnibox);
model_->speech.has_or_can_request_audio_permission = true;
EXPECT_TRUE(OnBeginFrame());
EXPECT_TRUE(IsVisible(kVoiceSearchButton));
EXPECT_TRUE(IsVisible(kOmniboxVoiceSearchButton));
model_->speech.has_or_can_request_audio_permission = false;
EXPECT_TRUE(OnBeginFrame());
EXPECT_FALSE(IsVisible(kVoiceSearchButton));
EXPECT_FALSE(IsVisible(kOmniboxVoiceSearchButton));
}
TEST_F(UiTest, VoiceSearchHiddenWhenContentCapturingAudio) {
......@@ -281,11 +281,11 @@ TEST_F(UiTest, VoiceSearchHiddenWhenContentCapturingAudio) {
model_->speech.has_or_can_request_audio_permission = true;
model_->capturing_state.audio_capture_enabled = false;
EXPECT_TRUE(OnBeginFrame());
EXPECT_TRUE(IsVisible(kVoiceSearchButton));
EXPECT_TRUE(IsVisible(kOmniboxVoiceSearchButton));
model_->capturing_state.audio_capture_enabled = true;
EXPECT_TRUE(OnBeginFrame());
EXPECT_FALSE(IsVisible(kVoiceSearchButton));
EXPECT_FALSE(IsVisible(kOmniboxVoiceSearchButton));
}
TEST_F(UiTest, UiModeWebVr) {
......
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