Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Unified Diff: chrome/browser/android/vr_shell/textures/exit_prompt_texture.cc

Issue 2913633002: [vr] Clicking on the security icon should prompt the user to bail out of VR (Closed)
Patch Set: . Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/vr_shell/textures/exit_prompt_texture.cc
diff --git a/chrome/browser/android/vr_shell/textures/exit_prompt_texture.cc b/chrome/browser/android/vr_shell/textures/exit_prompt_texture.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2f78072571c4daba29d0537a0d4f3ec237c18ac9
--- /dev/null
+++ b/chrome/browser/android/vr_shell/textures/exit_prompt_texture.cc
@@ -0,0 +1,169 @@
+// 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/android/vr_shell/textures/exit_prompt_texture.h"
+
+#include "cc/paint/skia_paint_canvas.h"
+#include "chrome/browser/android/vr_shell/color_scheme.h"
+#include "chrome/grit/generated_resources.h"
+#include "components/strings/grit/components_strings.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/gfx/canvas.h"
+#include "ui/gfx/font_list.h"
+#include "ui/gfx/geometry/rect.h"
+#include "ui/gfx/geometry/vector2d.h"
+#include "ui/gfx/paint_vector_icon.h"
+#include "ui/gfx/render_text.h"
+#include "ui/gfx/vector_icon_types.h"
+#include "ui/vector_icons/vector_icons.h"
+
+#include "ui/gfx/color_palette.h"
+
+namespace vr_shell {
+
+namespace {
+
+constexpr float kWidth = 0.672;
cjgrant 2017/06/02 04:16:35 Hmm, I'm used to these being static, but the codeb
ymalik 2017/06/02 21:14:31 There's no difference because things in anonymous
+constexpr float kHeight = 0.2;
+constexpr float kButtonWidth = 0.162;
+constexpr float kButtonHeight = 0.066;
+constexpr float kPromptTextButtonSeperatorHeight = 0.04;
+constexpr float kButtonsSeperatorWidth = 0.01;
+constexpr float kButtonRadiusFactor = 0.006;
+constexpr float kFontSizeFactor = 0.048;
+
+} // namespace
+
+ExitPromptTexture::ExitPromptTexture() = default;
+
+ExitPromptTexture::~ExitPromptTexture() = default;
+
+const ColorScheme& ExitPromptTexture::color_scheme() const {
+ return ColorScheme::GetColorScheme(mode());
+}
+
+void ExitPromptTexture::Draw(SkCanvas* sk_canvas,
+ const gfx::Size& texture_size) {
+ size_.set_width(texture_size.width());
+ size_.set_height(texture_size.height());
+
+ cc::SkiaPaintCanvas paint_canvas(sk_canvas);
+ gfx::Canvas gfx_canvas(&paint_canvas, 1.0f);
+ gfx::Canvas* canvas = &gfx_canvas;
+
+ // Prompt text area
cjgrant 2017/06/02 04:16:35 nit: Periods on comments. :)
ymalik 2017/06/02 21:14:31 Done.
+ auto text = l10n_util::GetStringUTF16(IDS_VR_SHELL_EXIT_PROMPT_DESCRIPTION);
+ gfx::FontList fonts;
+ GetFontList(size_.width() * kFontSizeFactor, text, &fonts);
+ gfx::Rect prompt_text_size(size_.width(), 0);
+ std::vector<std::unique_ptr<gfx::RenderText>> lines = PrepareDrawStringRect(
+ text, fonts, color_scheme().prompt_text, &prompt_text_size,
+ kTextAlignmentCenter, kWrappingBehaviorWrap);
+ for (auto& render_text : lines)
+ render_text->Draw(canvas);
+
+ SkPaint paint;
+ gfx::Rect button_text_size(ToPixels(kButtonWidth), 0);
+ float radius = size_.width() * kButtonRadiusFactor;
+
+ // Secondary button area
+ text = l10n_util::GetStringUTF16(IDS_VR_SHELL_EXIT_PROMPT_EXIT_VR_BUTTON);
+ lines = PrepareDrawStringRect(
+ text, fonts, color_scheme().secondary_button_text, &button_text_size,
+ kTextAlignmentCenter, kWrappingBehaviorWrap);
+ secondary_button_rect_.SetRect(
+ ToPixels(kWidth) / 2 - ToPixels(kButtonsSeperatorWidth) -
cjgrant 2017/06/02 04:16:36 Why 3 ToPixels calls instead of one, on the result
ymalik 2017/06/02 21:14:31 I was being silly :)
+ ToPixels(kButtonWidth),
+ prompt_text_size.height() + ToPixels(kPromptTextButtonSeperatorHeight),
+ ToPixels(kButtonWidth), ToPixels(kButtonHeight));
+ paint.setColor(secondary_hovered_
+ ? color_scheme().button_background_hover
+ : color_scheme().secondary_button_background);
+ canvas->Save();
+ canvas->Translate(
+ gfx::Vector2d(secondary_button_rect_.x(), secondary_button_rect_.y()));
+ sk_canvas->drawRoundRect(
+ SkRect::MakeXYWH(0, 0, ToPixels(kButtonWidth), ToPixels(kButtonHeight)),
+ radius, radius, paint);
+ canvas->Translate(gfx::Vector2d(
+ 0, ToPixels(kButtonHeight) / 2 - button_text_size.height() / 2));
+ for (auto& render_text : lines)
+ render_text->Draw(canvas);
+ canvas->Restore();
+
+ // Primary button area
+ text = l10n_util::GetStringUTF16(IDS_OK);
cjgrant 2017/06/02 04:16:36 This block is really similar to the one above. Do
ymalik 2017/06/02 21:14:31 We could, but we would either have to pass a lot o
+ button_text_size.set_size(ToPixels(kButtonWidth), 0);
+ lines = PrepareDrawStringRect(text, fonts, color_scheme().primary_button_text,
+ &button_text_size, kTextAlignmentCenter,
+ kWrappingBehaviorWrap);
+ primary_button_rect_.SetRect(
+ ToPixels(kWidth) / 2 + ToPixels(kButtonsSeperatorWidth),
+ prompt_text_size.height() + ToPixels(kPromptTextButtonSeperatorHeight),
+ ToPixels(kButtonWidth), ToPixels(kButtonHeight));
+ paint.setColor(primary_hovered_ ? color_scheme().button_background_hover
+ : color_scheme().primary_button_background);
+ canvas->Save();
+ canvas->Translate(
+ gfx::Vector2d(primary_button_rect_.x(), primary_button_rect_.y()));
+ sk_canvas->drawRoundRect(
+ SkRect::MakeXYWH(0, 0, ToPixels(kButtonWidth), ToPixels(kButtonHeight)),
+ radius, radius, paint);
+ canvas->Translate(gfx::Vector2d(
+ 0, ToPixels(kButtonHeight) / 2 - button_text_size.height() / 2));
+ for (auto& render_text : lines)
+ render_text->Draw(canvas);
+ canvas->Restore();
+}
+
+float ExitPromptTexture::ToPixels(float meters) const {
+ return meters * size_.width() / kWidth;
+}
+
+gfx::PointF ExitPromptTexture::percentToPixels(
+ const gfx::PointF& percent) const {
+ return gfx::PointF(percent.x() * size_.width(), percent.y() * size_.height());
+}
+
+bool ExitPromptTexture::HitsSecondaryButton(const gfx::PointF& position) const {
+ return secondary_button_rect_.Contains(percentToPixels(position));
+}
+
+void ExitPromptTexture::SetPrimaryHovered(bool hovered) {
+ if (primary_hovered_ != hovered)
+ set_dirty();
+ primary_hovered_ = hovered;
+}
+
+void ExitPromptTexture::SetPrimaryPressed(bool pressed) {
+ if (primary_pressed_ != pressed)
+ set_dirty();
+ primary_pressed_ = pressed;
+}
+
+void ExitPromptTexture::SetSecondaryHovered(bool hovered) {
+ if (secondary_hovered_ != hovered)
+ set_dirty();
+ secondary_hovered_ = hovered;
+}
+
+void ExitPromptTexture::SetSecondaryPressed(bool pressed) {
+ if (secondary_pressed_ != pressed)
+ set_dirty();
+ secondary_pressed_ = pressed;
+}
+
+bool ExitPromptTexture::HitsPrimaryButton(const gfx::PointF& position) const {
cjgrant 2017/06/02 04:16:36 nit: Should probably move this up with the other H
ymalik 2017/06/02 21:14:31 Done.
+ return primary_button_rect_.Contains(percentToPixels(position));
+}
+
+gfx::Size ExitPromptTexture::GetPreferredTextureSize(int maximum_width) const {
+ return gfx::Size(maximum_width, maximum_width * kHeight / kWidth);
+}
+
+gfx::SizeF ExitPromptTexture::GetDrawnSize() const {
+ return size_;
+}
+
+} // namespace vr_shell

Powered by Google App Engine
This is Rietveld 408576698