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/insecure_content_transient_te
xture.h" | 5 #include "chrome/browser/android/vr_shell/textures/insecure_content_transient_te
xture.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/geometry/rect.h" | 12 #include "ui/gfx/geometry/rect.h" |
12 #include "ui/gfx/geometry/vector2d.h" | 13 #include "ui/gfx/geometry/vector2d.h" |
13 #include "ui/gfx/paint_vector_icon.h" | 14 #include "ui/gfx/paint_vector_icon.h" |
14 #include "ui/gfx/vector_icon_types.h" | 15 #include "ui/gfx/vector_icon_types.h" |
15 #include "ui/vector_icons/vector_icons.h" | 16 #include "ui/vector_icons/vector_icons.h" |
16 | 17 |
17 namespace vr_shell { | 18 namespace vr_shell { |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 const SkColor kBackgroundColor = 0xCC1A1A1A; | 22 const SkColor kBackgroundColor = 0xCC1A1A1A; |
22 const SkColor kForegroundColor = SK_ColorWHITE; | 23 const SkColor kForegroundColor = SK_ColorWHITE; |
| 24 constexpr float kBorderFactor = 0.045; |
| 25 constexpr float kIconSizeFactor = 0.25; |
| 26 constexpr float kFontSizeFactor = 0.045; |
| 27 constexpr float kTextWidthFactor = 1.0 - 3 * kBorderFactor - kIconSizeFactor; |
23 | 28 |
24 } // namespace | 29 } // namespace |
25 | 30 |
26 InsecureContentTransientTexture::InsecureContentTransientTexture( | 31 InsecureContentTransientTexture::InsecureContentTransientTexture( |
27 int texture_handle, | 32 int texture_handle, |
28 int texture_size) | 33 int texture_size) |
29 : UITexture(texture_handle, texture_size) { | 34 : UITexture(texture_handle, texture_size) { |
30 // Ensuring height is half the width. | |
31 DCHECK(texture_size_ % 2 == 0); | |
32 height_ = texture_size_ / 2; | |
33 } | 35 } |
34 | 36 |
35 InsecureContentTransientTexture::~InsecureContentTransientTexture() = default; | 37 InsecureContentTransientTexture::~InsecureContentTransientTexture() = default; |
36 | 38 |
37 void InsecureContentTransientTexture::Draw(gfx::Canvas* canvas) { | 39 void InsecureContentTransientTexture::Draw(gfx::Canvas* canvas) { |
38 cc::PaintFlags flags; | 40 cc::PaintFlags flags; |
39 flags.setColor(kBackgroundColor); | 41 flags.setColor(kBackgroundColor); |
40 canvas->DrawRoundRect(gfx::Rect(texture_size_, height_), height_ * 0.1, | 42 |
41 flags); | 43 int text_flags = gfx::Canvas::TEXT_ALIGN_CENTER | gfx::Canvas::MULTI_LINE; |
| 44 auto text = |
| 45 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INSECURE_WEBVR_CONTENT_TRANSIENT); |
| 46 auto fonts = GetFontList(texture_size_ * kFontSizeFactor, text); |
| 47 |
| 48 int text_width = texture_size_ * kTextWidthFactor; |
| 49 int text_height = 0; // Will be increased during text measurement. |
| 50 gfx::Canvas::SizeStringInt(text, fonts, &text_width, &text_height, 0, |
| 51 text_flags); |
| 52 // Making sure that the icon fits in the box. |
| 53 text_height = std::max( |
| 54 text_height, static_cast<int>(ceil(texture_size_ * kIconSizeFactor))); |
| 55 // Making sure the drawing fits within the texture. |
| 56 text_height = std::min( |
| 57 text_height, static_cast<int>((1.0 - 2 * kBorderFactor) * texture_size_)); |
| 58 height_ = |
| 59 static_cast<int>(ceil(texture_size_ * 2 * kBorderFactor + text_height)); |
| 60 |
| 61 canvas->DrawRoundRect(gfx::Rect(texture_size_, height_), |
| 62 height_ * kBorderFactor, flags); |
| 63 |
42 canvas->Save(); | 64 canvas->Save(); |
43 canvas->Translate({height_ * 0.1, height_ * 0.25}); | 65 canvas->Translate({IsRTL() ? 2 * kBorderFactor * texture_size_ + text_width |
44 PaintVectorIcon(canvas, ui::kInfoOutlineIcon, height_ * 0.5, | 66 : texture_size_ * kBorderFactor, |
| 67 (height_ - kIconSizeFactor * texture_size_) / 2.0}); |
| 68 PaintVectorIcon(canvas, ui::kInfoOutlineIcon, texture_size_ * kIconSizeFactor, |
45 kForegroundColor); | 69 kForegroundColor); |
46 canvas->Restore(); | 70 canvas->Restore(); |
| 71 |
47 canvas->Save(); | 72 canvas->Save(); |
48 canvas->Translate({height_ * 0.7, height_ * 0.1}); | 73 canvas->Translate( |
49 // TODO(acondor): Draw text IDS_PAGE_INFO_INSECURE_WEBVR_CONTENT_TRANSIENT. | 74 {IsRTL() ? kBorderFactor * texture_size_ |
| 75 : texture_size_ * (2 * kBorderFactor + kIconSizeFactor), |
| 76 texture_size_ * kBorderFactor}); |
| 77 canvas->DrawStringRectWithFlags( |
| 78 text, fonts, kForegroundColor, |
| 79 gfx::Rect(kTextWidthFactor * texture_size_, text_height), text_flags); |
50 canvas->Restore(); | 80 canvas->Restore(); |
51 } | 81 } |
52 | 82 |
53 void InsecureContentTransientTexture::SetSize() { | 83 void InsecureContentTransientTexture::SetSize() { |
54 size_.SetSize(texture_size_, height_); | 84 size_.SetSize(texture_size_, height_); |
55 } | 85 } |
56 | 86 |
57 } // namespace vr_shell | 87 } // namespace vr_shell |
OLD | NEW |