Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/android/vr_shell/textures/exclusive_screen_toast_textur e.h" | 5 #include "chrome/browser/android/vr_shell/textures/exclusive_screen_toast_textur e.h" |
| 6 | 6 |
| 7 #include "cc/paint/skia_paint_canvas.h" | 7 #include "cc/paint/skia_paint_canvas.h" |
| 8 #include "chrome/grit/generated_resources.h" | 8 #include "chrome/grit/generated_resources.h" |
| 9 #include "ui/base/l10n/l10n_util.h" | 9 #include "ui/base/l10n/l10n_util.h" |
| 10 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
| 11 #include "ui/gfx/font_list.h" | 11 #include "ui/gfx/font_list.h" |
| 12 #include "ui/gfx/geometry/rect.h" | 12 #include "ui/gfx/geometry/rect.h" |
| 13 #include "ui/gfx/geometry/vector2d.h" | 13 #include "ui/gfx/geometry/vector2d.h" |
| 14 #include "ui/gfx/render_text.h" | 14 #include "ui/gfx/render_text.h" |
| 15 | 15 |
| 16 namespace vr_shell { | 16 namespace vr_shell { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 constexpr float kBorderFactor = 0.045; | 20 constexpr float kHeight = 0.064; |
| 21 constexpr float kFontSizeFactor = 0.048; | 21 constexpr float kWidthHeightRatio = 16.0; |
| 22 constexpr float kTextWidthFactor = 1.0 - 3 * kBorderFactor; | 22 constexpr float kFontHeight = 0.024; |
| 23 constexpr float kWidthPadding = 0.02; | |
| 24 constexpr float kRadius = 0.004; | |
|
cjgrant
2017/06/28 13:55:34
Possibly kCornerRadius for clarity?
bshe
2017/06/28 20:01:58
Done.
| |
| 23 | 25 |
| 24 } // namespace | 26 } // namespace |
| 25 | 27 |
| 26 ExclusiveScreenToastTexture::ExclusiveScreenToastTexture() = default; | 28 ExclusiveScreenToastTexture::ExclusiveScreenToastTexture() = default; |
| 27 | 29 |
| 28 ExclusiveScreenToastTexture::~ExclusiveScreenToastTexture() = default; | 30 ExclusiveScreenToastTexture::~ExclusiveScreenToastTexture() = default; |
| 29 | 31 |
| 30 void ExclusiveScreenToastTexture::Draw(SkCanvas* sk_canvas, | 32 void ExclusiveScreenToastTexture::Draw(SkCanvas* sk_canvas, |
| 31 const gfx::Size& texture_size) { | 33 const gfx::Size& texture_size) { |
| 32 cc::SkiaPaintCanvas paint_canvas(sk_canvas); | 34 cc::SkiaPaintCanvas paint_canvas(sk_canvas); |
| 33 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f); | 35 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f); |
| 34 gfx::Canvas* canvas = &gfx_canvas; | 36 gfx::Canvas* canvas = &gfx_canvas; |
| 35 | 37 |
| 36 size_.set_width(texture_size.width()); | 38 size_.set_height(texture_size.height()); |
| 37 SkPaint paint; | 39 SkPaint paint; |
| 40 float meter_to_pixel_ratio = texture_size.height() / kHeight; | |
| 38 | 41 |
| 39 paint.setColor(color_scheme().exclusive_screen_toast_background); | 42 paint.setColor(color_scheme().exclusive_screen_toast_background); |
| 40 auto text = l10n_util::GetStringUTF16(IDS_PRESS_APP_TO_EXIT); | 43 auto text = l10n_util::GetStringUTF16(IDS_PRESS_APP_TO_EXIT); |
| 41 gfx::FontList fonts; | 44 gfx::FontList fonts; |
| 42 GetFontList(size_.width() * kFontSizeFactor, text, &fonts); | 45 int pixel_font_size = meter_to_pixel_ratio * kFontHeight; |
| 43 gfx::Rect text_size(size_.width() * kTextWidthFactor, 0); | 46 GetFontList(pixel_font_size, text, &fonts); |
| 47 gfx::Rect text_size(0, pixel_font_size); | |
| 44 | 48 |
| 45 std::vector<std::unique_ptr<gfx::RenderText>> lines = PrepareDrawStringRect( | 49 std::vector<std::unique_ptr<gfx::RenderText>> lines = PrepareDrawStringRect( |
| 46 text, fonts, color_scheme().exclusive_screen_toast_foreground, &text_size, | 50 text, fonts, color_scheme().exclusive_screen_toast_foreground, &text_size, |
| 47 kTextAlignmentCenter, kWrappingBehaviorWrap); | 51 kTextAlignmentNone, kWrappingBehaviorNoWrap); |
| 48 | 52 |
| 49 DCHECK_LE(text_size.height(), | 53 int pixel_padding = meter_to_pixel_ratio * kWidthPadding; |
| 50 static_cast<int>((1.0 - 2 * kBorderFactor) * size_.width())); | 54 size_.set_width(2 * pixel_padding + text_size.width()); |
| 51 size_.set_height(size_.width() * 2 * kBorderFactor + text_size.height()); | 55 DCHECK_LE(size_.width(), texture_size.width()); |
| 52 float radius = size_.width() * kBorderFactor; | 56 int radius = meter_to_pixel_ratio * kRadius; |
| 53 sk_canvas->drawRoundRect(SkRect::MakeWH(size_.width(), size_.height()), | 57 sk_canvas->drawRoundRect(SkRect::MakeWH(size_.width(), size_.height()), |
| 54 radius, radius, paint); | 58 radius, radius, paint); |
| 55 | 59 |
| 56 canvas->Save(); | 60 canvas->Save(); |
| 57 canvas->Translate(gfx::Vector2d(size_.width() * kBorderFactor, | 61 canvas->Translate( |
| 58 size_.width() * kBorderFactor)); | 62 gfx::Vector2d(meter_to_pixel_ratio * kWidthPadding, |
| 63 (kHeight - kFontHeight) / 2 * meter_to_pixel_ratio)); | |
| 59 for (auto& render_text : lines) | 64 for (auto& render_text : lines) |
| 60 render_text->Draw(canvas); | 65 render_text->Draw(canvas); |
| 61 canvas->Restore(); | 66 canvas->Restore(); |
| 62 } | 67 } |
| 63 | 68 |
| 64 gfx::Size ExclusiveScreenToastTexture::GetPreferredTextureSize( | 69 gfx::Size ExclusiveScreenToastTexture::GetPreferredTextureSize( |
| 65 int maximum_width) const { | 70 int maximum_width) const { |
| 66 return gfx::Size(maximum_width, maximum_width); | 71 return gfx::Size(maximum_width, maximum_width / kWidthHeightRatio); |
| 67 } | 72 } |
| 68 | 73 |
| 69 gfx::SizeF ExclusiveScreenToastTexture::GetDrawnSize() const { | 74 gfx::SizeF ExclusiveScreenToastTexture::GetDrawnSize() const { |
| 70 return size_; | 75 return size_; |
| 71 } | 76 } |
| 72 | 77 |
| 73 } // namespace vr_shell | 78 } // namespace vr_shell |
| OLD | NEW |