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/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 canvas->SizeStringInt(text, fonts, &text_width, &text_height, 0, text_flags); | |
|
mthiesse
2017/04/21 00:12:24
Canvas::SizeStringInt is a static function
| |
| 51 // Making sure that the icon fits in the box. | |
| 52 text_height = std::max( | |
| 53 text_height, static_cast<int>(ceil(texture_size_ * kIconSizeFactor))); | |
| 54 // Making sure the drawing fits within the texture. | |
| 55 text_height = std::min( | |
| 56 text_height, static_cast<int>((1.0 - 2 * kBorderFactor) * texture_size_)); | |
| 57 height_ = | |
| 58 static_cast<int>(ceil(texture_size_ * 2 * kBorderFactor + text_height)); | |
| 59 | |
| 60 canvas->DrawRoundRect(gfx::Rect(texture_size_, height_), | |
| 61 height_ * kBorderFactor, flags); | |
| 62 | |
| 42 canvas->Save(); | 63 canvas->Save(); |
| 43 canvas->Translate({height_ * 0.1, height_ * 0.25}); | 64 canvas->Translate({IsRTL() ? 2 * kBorderFactor * texture_size_ + text_width |
| 44 PaintVectorIcon(canvas, ui::kInfoOutlineIcon, height_ * 0.5, | 65 : texture_size_ * kBorderFactor, |
| 66 (height_ - kIconSizeFactor * texture_size_) / 2.0}); | |
| 67 PaintVectorIcon(canvas, ui::kInfoOutlineIcon, texture_size_ * kIconSizeFactor, | |
| 45 kForegroundColor); | 68 kForegroundColor); |
| 46 canvas->Restore(); | 69 canvas->Restore(); |
| 70 | |
| 47 canvas->Save(); | 71 canvas->Save(); |
| 48 canvas->Translate({height_ * 0.7, height_ * 0.1}); | 72 canvas->Translate( |
| 49 // TODO(acondor): Draw text IDS_PAGE_INFO_INSECURE_WEBVR_CONTENT_TRANSIENT. | 73 {IsRTL() ? kBorderFactor * texture_size_ |
| 74 : texture_size_ * (2 * kBorderFactor + kIconSizeFactor), | |
| 75 texture_size_ * kBorderFactor}); | |
| 76 canvas->DrawStringRectWithFlags( | |
| 77 text, fonts, kForegroundColor, | |
| 78 gfx::Rect(kTextWidthFactor * texture_size_, text_height), text_flags); | |
| 50 canvas->Restore(); | 79 canvas->Restore(); |
| 51 } | 80 } |
| 52 | 81 |
| 53 void InsecureContentTransientTexture::SetSize() { | 82 void InsecureContentTransientTexture::SetSize() { |
| 54 size_.SetSize(texture_size_, height_); | 83 size_.SetSize(texture_size_, height_); |
| 55 } | 84 } |
| 56 | 85 |
| 57 } // namespace vr_shell | 86 } // namespace vr_shell |
| OLD | NEW |