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/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" |
(...skipping 26 matching lines...) Expand all Loading... |
37 : icon_(icon), has_text_(false) {} | 37 : icon_(icon), has_text_(false) {} |
38 | 38 |
39 SystemIndicatorTexture::~SystemIndicatorTexture() = default; | 39 SystemIndicatorTexture::~SystemIndicatorTexture() = default; |
40 | 40 |
41 void SystemIndicatorTexture::Draw(SkCanvas* sk_canvas, | 41 void SystemIndicatorTexture::Draw(SkCanvas* sk_canvas, |
42 const gfx::Size& texture_size) { | 42 const gfx::Size& texture_size) { |
43 cc::SkiaPaintCanvas paint_canvas(sk_canvas); | 43 cc::SkiaPaintCanvas paint_canvas(sk_canvas); |
44 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f); | 44 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f); |
45 gfx::Canvas* canvas = &gfx_canvas; | 45 gfx::Canvas* canvas = &gfx_canvas; |
46 | 46 |
47 DCHECK(texture_size.height() * kHeightWidthRatio == texture_size.width()); | |
48 size_.set_height(texture_size.height()); | 47 size_.set_height(texture_size.height()); |
| 48 |
49 SkPaint paint; | 49 SkPaint paint; |
50 paint.setColor(color_scheme().system_indicator_background); | 50 paint.setColor(color_scheme().system_indicator_background); |
51 | 51 |
52 gfx::Rect text_size(0, 0); | 52 gfx::Rect text_size(0, 0); |
53 std::vector<std::unique_ptr<gfx::RenderText>> lines; | 53 std::vector<std::unique_ptr<gfx::RenderText>> lines; |
54 | 54 |
55 if (has_text_) { | 55 if (has_text_) { |
56 base::string16 text = l10n_util::GetStringUTF16(message_id_); | 56 base::string16 text = l10n_util::GetStringUTF16(message_id_); |
57 | 57 |
58 gfx::FontList fonts; | 58 gfx::FontList fonts; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 size_.height() * | 92 size_.height() * |
93 (IsRTL() ? 2 * kBorderFactor : 3 * kBorderFactor + kIconSizeFactor), | 93 (IsRTL() ? 2 * kBorderFactor : 3 * kBorderFactor + kIconSizeFactor), |
94 size_.height() * kBorderFactor)); | 94 size_.height() * kBorderFactor)); |
95 for (auto& render_text : lines) | 95 for (auto& render_text : lines) |
96 render_text->Draw(canvas); | 96 render_text->Draw(canvas); |
97 canvas->Restore(); | 97 canvas->Restore(); |
98 } | 98 } |
99 | 99 |
100 gfx::Size SystemIndicatorTexture::GetPreferredTextureSize( | 100 gfx::Size SystemIndicatorTexture::GetPreferredTextureSize( |
101 int maximum_width) const { | 101 int maximum_width) const { |
102 // Ensuring height is a quarter of the width. | 102 // All indicators need to be the same height, so compute height, and then |
| 103 // re-compute with based on whether the indicator has text or not. |
103 int height = maximum_width / kHeightWidthRatio; | 104 int height = maximum_width / kHeightWidthRatio; |
104 return gfx::Size(height * kHeightWidthRatio, height); | 105 return gfx::Size(has_text_ ? maximum_width : height, height); |
105 } | 106 } |
106 | 107 |
107 gfx::SizeF SystemIndicatorTexture::GetDrawnSize() const { | 108 gfx::SizeF SystemIndicatorTexture::GetDrawnSize() const { |
108 return size_; | 109 return size_; |
109 } | 110 } |
110 | 111 |
111 } // namespace vr_shell | 112 } // namespace vr_shell |
OLD | NEW |