Skip to content

Commit

Permalink
VR: Prompt user to update their keyboard version if needed
Browse files Browse the repository at this point in the history
This CL renames AudioPermissionPrompt and its corresponding texture to
Prompt and uses the same texture for the exit prompt.

Bug: 799584
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: If435488f3e10a2f704d7e4df2177756e4d7aaa15
Reviewed-on: https://chromium-review.googlesource.com/945110
Commit-Queue: Yash Malik <ymalik@chromium.org>
Reviewed-by: Christopher Grant <cjgrant@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#540573}(cherry picked from commit dd8e1f5)
Reviewed-on: https://chromium-review.googlesource.com/952745
Reviewed-by: Yash Malik <ymalik@chromium.org>
Cr-Commit-Position: refs/branch-heads/3359@{#53}
Cr-Branched-From: 66afc5e-refs/heads/master@{#540276}
  • Loading branch information
Yash Malik authored and Yash Malik committed Mar 7, 2018
1 parent 869f88f commit af670aa
Show file tree
Hide file tree
Showing 21 changed files with 340 additions and 236 deletions.
8 changes: 4 additions & 4 deletions chrome/browser/vr/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ static_library("vr_common") {
"databinding/binding_base.h",
"databinding/vector_binding.h",
"databinding/vector_element_binding.h",
"elements/audio_permission_prompt.cc",
"elements/audio_permission_prompt.h",
"elements/audio_permission_prompt_texture.cc",
"elements/audio_permission_prompt_texture.h",
"elements/button.cc",
"elements/button.h",
"elements/content_element.cc",
Expand Down Expand Up @@ -69,6 +65,10 @@ static_library("vr_common") {
"elements/omnibox_formatting.h",
"elements/omnibox_text_field.cc",
"elements/omnibox_text_field.h",
"elements/prompt.cc",
"elements/prompt.h",
"elements/prompt_texture.cc",
"elements/prompt_texture.h",
"elements/rect.cc",
"elements/rect.h",
"elements/render_text_wrapper.cc",
Expand Down
26 changes: 0 additions & 26 deletions chrome/browser/vr/elements/audio_permission_prompt.cc

This file was deleted.

32 changes: 0 additions & 32 deletions chrome/browser/vr/elements/audio_permission_prompt.h

This file was deleted.

34 changes: 0 additions & 34 deletions chrome/browser/vr/elements/audio_permission_prompt_texture.h

This file was deleted.

4 changes: 2 additions & 2 deletions chrome/browser/vr/elements/exit_prompt_texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ class ExitPromptTexture : public UiTexture {
ButtonColors primary_button_colors_;
ButtonColors secondary_button_colors_;

int content_message_id_ = -1;

private:
void Draw(SkCanvas* sk_canvas, const gfx::Size& texture_size) override;

int content_message_id_ = -1;

DISALLOW_COPY_AND_ASSIGN(ExitPromptTexture);
};

Expand Down
32 changes: 32 additions & 0 deletions chrome/browser/vr/elements/prompt.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2017 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/elements/prompt.h"

#include "chrome/browser/vr/elements/prompt_texture.h"

namespace vr {

Prompt::Prompt(int preferred_width,
int content_message_id,
const gfx::VectorIcon& icon,
int primary_button_message_id,
int secondary_button_message_id,
const ExitPromptCallback& result_callback)
: ExitPrompt(preferred_width,
result_callback,
std::make_unique<PromptTexture>(content_message_id,
icon,
primary_button_message_id,
secondary_button_message_id)) {
set_reason(UiUnsupportedMode::kVoiceSearchNeedsRecordAudioOsPermission);
}

Prompt::~Prompt() = default;

void Prompt::SetIconColor(SkColor color) {
static_cast<PromptTexture*>(GetTexture())->SetIconColor(color);
}

} // namespace vr
37 changes: 37 additions & 0 deletions chrome/browser/vr/elements/prompt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2017 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_ELEMENTS_PROMPT_H_
#define CHROME_BROWSER_VR_ELEMENTS_PROMPT_H_

#include <memory>

#include "base/callback.h"
#include "base/macros.h"
#include "chrome/browser/vr/elements/exit_prompt.h"
#include "ui/gfx/vector_icon_types.h"

namespace vr {

class Prompt : public ExitPrompt {
public:
Prompt(int preferred_width,
int content_message_id,
const gfx::VectorIcon& icon,
int primary_button_message_id,
int secondary_button_message_id,
const ExitPromptCallback& result_callback);
~Prompt() override;

void SetIconColor(SkColor color);

private:
void OnStateUpdated(const gfx::PointF& position);

DISALLOW_COPY_AND_ASSIGN(Prompt);
};

} // namespace vr

#endif // CHROME_BROWSER_VR_ELEMENTS_PROMPT_H_
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/vr/elements/audio_permission_prompt_texture.h"
#include "chrome/browser/vr/elements/prompt_texture.h"

#include "base/i18n/case_conversion.h"
#include "cc/paint/skia_paint_canvas.h"
Expand Down Expand Up @@ -41,12 +41,19 @@ constexpr char kPreferredFontNameForButtons[] = "sans-serif-medium";

} // namespace

AudioPermissionPromptTexture::AudioPermissionPromptTexture() = default;
PromptTexture::PromptTexture(int content_message_id,
const gfx::VectorIcon& icon,
int primary_button_message_id,
int secondary_button_message_id)
: icon_(icon),
primary_button_message_id_(primary_button_message_id),
secondary_button_message_id_(secondary_button_message_id) {
SetContentMessageId(content_message_id);
}

AudioPermissionPromptTexture::~AudioPermissionPromptTexture() = default;
PromptTexture::~PromptTexture() = default;

void AudioPermissionPromptTexture::Draw(SkCanvas* sk_canvas,
const gfx::Size& texture_size) {
void PromptTexture::Draw(SkCanvas* sk_canvas, const gfx::Size& texture_size) {
size_.set_width(texture_size.width());
size_.set_height(texture_size.height());

Expand All @@ -63,12 +70,11 @@ void AudioPermissionPromptTexture::Draw(SkCanvas* sk_canvas,

// Icon
gfx::PointF icon_location(ToPixels(kPadding), ToPixels(kPadding));
VectorIcon::DrawVectorIcon(canvas, vector_icons::kMicIcon,
ToPixels(kIconSize), icon_location, icon_color_);
VectorIcon::DrawVectorIcon(canvas, icon_, ToPixels(kIconSize), icon_location,
icon_color_);

// Prompt description.
auto text = l10n_util::GetStringUTF16(
IDS_VR_SHELL_AUDIO_PERMISSION_PROMPT_DESCRIPTION);
auto text = l10n_util::GetStringUTF16(content_message_id_);
gfx::FontList fonts;
GetDefaultFontList(ToPixels(kFontSizePromptText), text, &fonts);
gfx::Rect prompt_text_size(
Expand All @@ -91,8 +97,8 @@ void AudioPermissionPromptTexture::Draw(SkCanvas* sk_canvas,

// Secondary button area.
// TODO(https://crbug.com/787654): Uppercasing should be conditional.
text = base::i18n::ToUpper(l10n_util::GetStringUTF16(
IDS_VR_SHELL_AUDIO_PERMISSION_PROMPT_ABORT_BUTTON));
text = base::i18n::ToUpper(
l10n_util::GetStringUTF16(secondary_button_message_id_));
GetFontList(kPreferredFontNameForButtons, ToPixels(kFontSizePromptButtonText),
text, &fonts);
lines = PrepareDrawStringRect(
Expand All @@ -118,8 +124,8 @@ void AudioPermissionPromptTexture::Draw(SkCanvas* sk_canvas,

// Primary button area.
// TODO(https://crbug.com/787654): Uppercasing should be conditional.
text = base::i18n::ToUpper(l10n_util::GetStringUTF16(
IDS_VR_SHELL_AUDIO_PERMISSION_PROMPT_CONTINUE_BUTTON));
text = base::i18n::ToUpper(
l10n_util::GetStringUTF16(primary_button_message_id_));
GetFontList(kPreferredFontNameForButtons, ToPixels(kFontSizePromptButtonText),
text, &fonts);
button_text_size.set_size(gfx::Size(ToPixels(kButtonWidth), 0));
Expand All @@ -144,17 +150,12 @@ void AudioPermissionPromptTexture::Draw(SkCanvas* sk_canvas,
canvas->Restore();
}

void AudioPermissionPromptTexture::SetIconColor(SkColor color) {
void PromptTexture::SetIconColor(SkColor color) {
SetAndDirty(&icon_color_, color);
}

gfx::Size AudioPermissionPromptTexture::GetPreferredTextureSize(
int maximum_width) const {
gfx::Size PromptTexture::GetPreferredTextureSize(int maximum_width) const {
return gfx::Size(maximum_width, maximum_width * kHeight / kWidth);
}

void AudioPermissionPromptTexture::SetContentMessageId(int message_id) {
NOTREACHED();
}

} // namespace vr
40 changes: 40 additions & 0 deletions chrome/browser/vr/elements/prompt_texture.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2017 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_ELEMENTS_PROMPT_TEXTURE_H_
#define CHROME_BROWSER_VR_ELEMENTS_PROMPT_TEXTURE_H_

#include "base/macros.h"
#include "chrome/browser/vr/elements/exit_prompt_texture.h"
#include "chrome/browser/vr/model/color_scheme.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/vector_icon_types.h"

namespace vr {

class PromptTexture : public ExitPromptTexture {
public:
PromptTexture(int content_message_id,
const gfx::VectorIcon& icon,
int primary_button_message_id,
int secondary_button_message_id);
~PromptTexture() override;
gfx::Size GetPreferredTextureSize(int width) const override;

void SetIconColor(SkColor color);

private:
void Draw(SkCanvas* sk_canvas, const gfx::Size& texture_size) override;

SkColor icon_color_ = SK_ColorBLACK;
const gfx::VectorIcon& icon_;
int primary_button_message_id_ = -1;
int secondary_button_message_id_ = -1;

DISALLOW_COPY_AND_ASSIGN(PromptTexture);
};

} // namespace vr

#endif // CHROME_BROWSER_VR_ELEMENTS_PROMPT_TEXTURE_H_
2 changes: 2 additions & 0 deletions chrome/browser/vr/elements/ui_element_name.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ static const char* g_ui_element_name_strings[] = {
"kCeiling",
"kFloor",
"kStars",
"kUpdateKeyboardPrompt",
"kUrlBarDmmRoot",
"kUrlBar",
"kUrlBarLayout",
Expand Down Expand Up @@ -67,6 +68,7 @@ static const char* g_ui_element_name_strings[] = {
"k2dBrowsingVisibiltyControlForSiteInfoPrompt",
"k2dBrowsingOpacityControlForAudioPermissionPrompt",
"k2dBrowsingOpacityControlForNativeDialogPrompt",
"k2dBrowsingOpacityControlForUpdateKeyboardPrompt",
"kIndicatorLayout",
"kAudioCaptureIndicator",
"kVideoCaptureIndicator",
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/vr/elements/ui_element_name.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ enum UiElementName {
kCeiling,
kFloor,
kStars,
kUpdateKeyboardPrompt,
kUrlBarDmmRoot,
kUrlBar,
kUrlBarLayout,
Expand Down Expand Up @@ -66,6 +67,7 @@ enum UiElementName {
k2dBrowsingVisibiltyControlForSiteInfoPrompt,
k2dBrowsingOpacityControlForAudioPermissionPrompt,
k2dBrowsingOpacityControlForNativeDialogPrompt,
k2dBrowsingOpacityControlForUpdateKeyboardPrompt,
kIndicatorLayout,
kAudioCaptureIndicator,
kVideoCaptureIndicator,
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/vr/elements/ui_element_type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ static const char* g_ui_element_type_strings[] = {
"kTypeOmniboxSuggestionIcon",
"kTypeOmniboxSuggestionContentText",
"kTypeOmniboxSuggestionDescriptionText",
"kTypePromptBackplane",
"kTypePromptShadow",
"kTypeSpacer",
"kTypeTextInputHint",
"kTypeTextInputText",
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/vr/elements/ui_element_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ enum UiElementType {
kTypeOmniboxSuggestionIcon,
kTypeOmniboxSuggestionContentText,
kTypeOmniboxSuggestionDescriptionText,
kTypePromptBackplane,
kTypePromptShadow,
kTypeSpacer,
kTypeTextInputHint,
kTypeTextInputText,
Expand Down
Loading

0 comments on commit af670aa

Please sign in to comment.