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

Side by Side Diff: chrome/browser/android/vr_shell/textures/system_indicator_texture.cc

Issue 2876403003: VR: text for audio/video input capture notifications (Closed)
Patch Set: removing unnecessary comments 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 unified diff | Download patch
OLDNEW
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/system_indicator_texture.h" 5 #include "chrome/browser/android/vr_shell/textures/system_indicator_texture.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "cc/paint/skia_paint_canvas.h" 8 #include "cc/paint/skia_paint_canvas.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/paint_vector_icon.h" 14 #include "ui/gfx/paint_vector_icon.h"
15 #include "ui/gfx/render_text.h" 15 #include "ui/gfx/render_text.h"
16 #include "ui/gfx/vector_icon_types.h" 16 #include "ui/gfx/vector_icon_types.h"
17 17
18 namespace vr_shell { 18 namespace vr_shell {
19 19
20 namespace { 20 namespace {
21 21
22 const SkColor kBackgroundColor = SK_ColorWHITE; 22 const SkColor kBackgroundColor = SK_ColorWHITE;
23 const SkColor kForegroundColor = 0xFF444444; 23 const SkColor kForegroundColor = 0xFF444444;
24 constexpr int kHeightWidthRatio = 8.0;
24 constexpr float kBorderFactor = 0.1; 25 constexpr float kBorderFactor = 0.1;
25 constexpr float kIconSizeFactor = 0.7; 26 constexpr float kIconSizeFactor = 0.7;
26 constexpr float kFontSizeFactor = 0.40; 27 constexpr float kFontSizeFactor = 0.40;
27 constexpr float kTextHeightFactor = 1.0 - 2 * kBorderFactor; 28 constexpr float kTextHeightFactor = 1.0 - 2 * kBorderFactor;
28 constexpr float kTextWidthFactor = 4.0 - 3 * kBorderFactor - kIconSizeFactor; 29 constexpr float kTextWidthFactor =
30 kHeightWidthRatio - 3 * kBorderFactor - kIconSizeFactor;
29 31
30 } // namespace 32 } // namespace
31 33
32 SystemIndicatorTexture::SystemIndicatorTexture(const gfx::VectorIcon& icon, 34 SystemIndicatorTexture::SystemIndicatorTexture(const gfx::VectorIcon& icon,
33 int message_id) 35 int message_id)
34 : icon_(icon), message_id_(message_id) {} 36 : icon_(icon), message_id_(message_id) {}
35 37
36 SystemIndicatorTexture::~SystemIndicatorTexture() = default; 38 SystemIndicatorTexture::~SystemIndicatorTexture() = default;
37 39
38 void SystemIndicatorTexture::Draw(SkCanvas* sk_canvas, 40 void SystemIndicatorTexture::Draw(SkCanvas* sk_canvas,
39 const gfx::Size& texture_size) { 41 const gfx::Size& texture_size) {
40 cc::SkiaPaintCanvas paint_canvas(sk_canvas); 42 cc::SkiaPaintCanvas paint_canvas(sk_canvas);
41 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f); 43 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f);
42 gfx::Canvas* canvas = &gfx_canvas; 44 gfx::Canvas* canvas = &gfx_canvas;
43 45
44 DCHECK(texture_size.height() * 4 == texture_size.width()); 46 DCHECK(texture_size.height() * kHeightWidthRatio == texture_size.width());
45 size_.set_height(texture_size.height()); 47 size_.set_height(texture_size.height());
46 SkPaint paint; 48 SkPaint paint;
47 paint.setColor(kBackgroundColor); 49 paint.setColor(kBackgroundColor);
48 50
49 base::string16 text; 51 base::string16 text = l10n_util::GetStringUTF16(message_id_);
50
51 // TODO(acondor): Set proper strings in resources files.
52 if (message_id_)
53 text = l10n_util::GetStringUTF16(message_id_);
54 else
55 text = base::UTF8ToUTF16("<message>");
56 52
57 auto fonts = GetFontList(size_.height() * kFontSizeFactor, text); 53 auto fonts = GetFontList(size_.height() * kFontSizeFactor, text);
58 gfx::Rect text_size(0, kTextHeightFactor * size_.height()); 54 gfx::Rect text_size(0, kTextHeightFactor * size_.height());
59 55
60 std::vector<std::unique_ptr<gfx::RenderText>> lines = 56 std::vector<std::unique_ptr<gfx::RenderText>> lines =
61 PrepareDrawStringRect(text, fonts, kForegroundColor, &text_size, 0); 57 PrepareDrawStringRect(text, fonts, kForegroundColor, &text_size, 0);
62 58
63 DCHECK_LE(text_size.width(), kTextWidthFactor * size_.height()); 59 DCHECK_LE(text_size.width(), kTextWidthFactor * size_.height());
64 // Setting background size giving some extra lateral padding to the text. 60 // Setting background size giving some extra lateral padding to the text.
65 size_.set_width((5 * kBorderFactor + kIconSizeFactor) * size_.height() + 61 size_.set_width((kHeightWidthRatio * kBorderFactor + kIconSizeFactor) *
62 size_.height() +
mthiesse 2017/05/15 21:44:11 This spacing looks really weird. Did git cl format
acondor_ 2017/05/16 14:18:36 Yes, that's the output.
66 text_size.width()); 63 text_size.width());
67 float radius = size_.height() * kBorderFactor; 64 float radius = size_.height() * kBorderFactor;
68 sk_canvas->drawRoundRect(SkRect::MakeWH(size_.width(), size_.height()), 65 sk_canvas->drawRoundRect(SkRect::MakeWH(size_.width(), size_.height()),
69 radius, radius, paint); 66 radius, radius, paint);
70 67
71 canvas->Save(); 68 canvas->Save();
72 canvas->Translate(gfx::Vector2d( 69 canvas->Translate(gfx::Vector2d(
73 IsRTL() ? 4 * kBorderFactor * size_.height() + text_size.width() 70 IsRTL() ? 4 * kBorderFactor * size_.height() + text_size.width()
74 : size_.height() * kBorderFactor, 71 : size_.height() * kBorderFactor,
75 size_.height() * (1.0 - kIconSizeFactor) / 2.0)); 72 size_.height() * (1.0 - kIconSizeFactor) / 2.0));
76 PaintVectorIcon(canvas, icon_, size_.height() * kIconSizeFactor, 73 PaintVectorIcon(canvas, icon_, size_.height() * kIconSizeFactor,
77 kForegroundColor); 74 kForegroundColor);
78 canvas->Restore(); 75 canvas->Restore();
79 76
80 canvas->Save(); 77 canvas->Save();
81 canvas->Translate(gfx::Vector2d( 78 canvas->Translate(gfx::Vector2d(
82 size_.height() * 79 size_.height() *
83 (IsRTL() ? 2 * kBorderFactor : 3 * kBorderFactor + kIconSizeFactor), 80 (IsRTL() ? 2 * kBorderFactor : 3 * kBorderFactor + kIconSizeFactor),
84 size_.height() * kBorderFactor)); 81 size_.height() * kBorderFactor));
85 for (auto& render_text : lines) 82 for (auto& render_text : lines)
86 render_text->Draw(canvas); 83 render_text->Draw(canvas);
87 canvas->Restore(); 84 canvas->Restore();
88 } 85 }
89 86
90 gfx::Size SystemIndicatorTexture::GetPreferredTextureSize( 87 gfx::Size SystemIndicatorTexture::GetPreferredTextureSize(
91 int maximum_width) const { 88 int maximum_width) const {
92 // Ensuring height is a quarter of the width. 89 // Ensuring height is a quarter of the width.
93 int height = maximum_width / 4; 90 int height = maximum_width / kHeightWidthRatio;
94 return gfx::Size(height * 4, height); 91 return gfx::Size(height * kHeightWidthRatio, height);
95 } 92 }
96 93
97 gfx::SizeF SystemIndicatorTexture::GetDrawnSize() const { 94 gfx::SizeF SystemIndicatorTexture::GetDrawnSize() const {
98 return size_; 95 return size_;
99 } 96 }
100 97
101 } // namespace vr_shell 98 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | chrome/browser/android/vr_shell/ui_elements/audio_capture_indicator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698