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

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

Issue 2926643003: [VrShell] Centralize color handling and enable close button on fullscreen (Closed)
Patch Set: Created 3 years, 6 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;
23 const SkColor kForegroundColor = 0xFF444444;
24 constexpr int kHeightWidthRatio = 8.0; 22 constexpr int kHeightWidthRatio = 8.0;
25 constexpr float kBorderFactor = 0.1; 23 constexpr float kBorderFactor = 0.1;
26 constexpr float kIconSizeFactor = 0.7; 24 constexpr float kIconSizeFactor = 0.7;
27 constexpr float kFontSizeFactor = 0.40; 25 constexpr float kFontSizeFactor = 0.40;
28 constexpr float kTextHeightFactor = 1.0 - 2 * kBorderFactor; 26 constexpr float kTextHeightFactor = 1.0 - 2 * kBorderFactor;
29 constexpr float kTextWidthFactor = 27 constexpr float kTextWidthFactor =
30 kHeightWidthRatio - 3 * kBorderFactor - kIconSizeFactor; 28 kHeightWidthRatio - 3 * kBorderFactor - kIconSizeFactor;
31 29
32 } // namespace 30 } // namespace
33 31
34 SystemIndicatorTexture::SystemIndicatorTexture(const gfx::VectorIcon& icon, 32 SystemIndicatorTexture::SystemIndicatorTexture(const gfx::VectorIcon& icon,
35 int message_id) 33 int message_id)
36 : icon_(icon), message_id_(message_id) {} 34 : icon_(icon), message_id_(message_id) {}
37 35
38 SystemIndicatorTexture::~SystemIndicatorTexture() = default; 36 SystemIndicatorTexture::~SystemIndicatorTexture() = default;
39 37
40 void SystemIndicatorTexture::Draw(SkCanvas* sk_canvas, 38 void SystemIndicatorTexture::Draw(SkCanvas* sk_canvas,
41 const gfx::Size& texture_size) { 39 const gfx::Size& texture_size) {
42 cc::SkiaPaintCanvas paint_canvas(sk_canvas); 40 cc::SkiaPaintCanvas paint_canvas(sk_canvas);
43 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f); 41 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f);
44 gfx::Canvas* canvas = &gfx_canvas; 42 gfx::Canvas* canvas = &gfx_canvas;
45 43
46 DCHECK(texture_size.height() * kHeightWidthRatio == texture_size.width()); 44 DCHECK(texture_size.height() * kHeightWidthRatio == texture_size.width());
47 size_.set_height(texture_size.height()); 45 size_.set_height(texture_size.height());
48 SkPaint paint; 46 SkPaint paint;
49 paint.setColor(kBackgroundColor); 47 paint.setColor(color_scheme().system_indicator_background);
50 48
51 base::string16 text = l10n_util::GetStringUTF16(message_id_); 49 base::string16 text = l10n_util::GetStringUTF16(message_id_);
52 50
53 gfx::FontList fonts; 51 gfx::FontList fonts;
54 GetFontList(size_.height() * kFontSizeFactor, text, &fonts); 52 GetFontList(size_.height() * kFontSizeFactor, text, &fonts);
55 gfx::Rect text_size(0, kTextHeightFactor * size_.height()); 53 gfx::Rect text_size(0, kTextHeightFactor * size_.height());
56 54
57 std::vector<std::unique_ptr<gfx::RenderText>> lines = 55 std::vector<std::unique_ptr<gfx::RenderText>> lines = PrepareDrawStringRect(
58 PrepareDrawStringRect(text, fonts, kForegroundColor, &text_size, 56 text, fonts, color_scheme().system_indicator_foreground, &text_size,
59 kTextAlignmentNone, kWrappingBehaviorNoWrap); 57 kTextAlignmentNone, kWrappingBehaviorNoWrap);
60 58
61 DCHECK_LE(text_size.width(), kTextWidthFactor * size_.height()); 59 DCHECK_LE(text_size.width(), kTextWidthFactor * size_.height());
62 // Setting background size giving some extra lateral padding to the text. 60 // Setting background size giving some extra lateral padding to the text.
63 size_.set_width((kHeightWidthRatio * kBorderFactor + kIconSizeFactor) * 61 size_.set_width((kHeightWidthRatio * kBorderFactor + kIconSizeFactor) *
64 size_.height() + 62 size_.height() +
65 text_size.width()); 63 text_size.width());
66 float radius = size_.height() * kBorderFactor; 64 float radius = size_.height() * kBorderFactor;
67 sk_canvas->drawRoundRect(SkRect::MakeWH(size_.width(), size_.height()), 65 sk_canvas->drawRoundRect(SkRect::MakeWH(size_.width(), size_.height()),
68 radius, radius, paint); 66 radius, radius, paint);
69 67
70 canvas->Save(); 68 canvas->Save();
71 canvas->Translate(gfx::Vector2d( 69 canvas->Translate(gfx::Vector2d(
72 IsRTL() ? 4 * kBorderFactor * size_.height() + text_size.width() 70 IsRTL() ? 4 * kBorderFactor * size_.height() + text_size.width()
73 : size_.height() * kBorderFactor, 71 : size_.height() * kBorderFactor,
74 size_.height() * (1.0 - kIconSizeFactor) / 2.0)); 72 size_.height() * (1.0 - kIconSizeFactor) / 2.0));
75 PaintVectorIcon(canvas, icon_, size_.height() * kIconSizeFactor, 73 PaintVectorIcon(canvas, icon_, size_.height() * kIconSizeFactor,
76 kForegroundColor); 74 color_scheme().system_indicator_foreground);
77 canvas->Restore(); 75 canvas->Restore();
78 76
79 canvas->Save(); 77 canvas->Save();
80 canvas->Translate(gfx::Vector2d( 78 canvas->Translate(gfx::Vector2d(
81 size_.height() * 79 size_.height() *
82 (IsRTL() ? 2 * kBorderFactor : 3 * kBorderFactor + kIconSizeFactor), 80 (IsRTL() ? 2 * kBorderFactor : 3 * kBorderFactor + kIconSizeFactor),
83 size_.height() * kBorderFactor)); 81 size_.height() * kBorderFactor));
84 for (auto& render_text : lines) 82 for (auto& render_text : lines)
85 render_text->Draw(canvas); 83 render_text->Draw(canvas);
86 canvas->Restore(); 84 canvas->Restore();
87 } 85 }
88 86
89 gfx::Size SystemIndicatorTexture::GetPreferredTextureSize( 87 gfx::Size SystemIndicatorTexture::GetPreferredTextureSize(
90 int maximum_width) const { 88 int maximum_width) const {
91 // Ensuring height is a quarter of the width. 89 // Ensuring height is a quarter of the width.
92 int height = maximum_width / kHeightWidthRatio; 90 int height = maximum_width / kHeightWidthRatio;
93 return gfx::Size(height * kHeightWidthRatio, height); 91 return gfx::Size(height * kHeightWidthRatio, height);
94 } 92 }
95 93
96 gfx::SizeF SystemIndicatorTexture::GetDrawnSize() const { 94 gfx::SizeF SystemIndicatorTexture::GetDrawnSize() const {
97 return size_; 95 return size_;
98 } 96 }
99 97
100 } // namespace vr_shell 98 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698