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_permanent_te xture.h" | 5 #include "chrome/browser/android/vr_shell/textures/insecure_content_permanent_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 = SK_ColorWHITE; | 22 const SkColor kBackgroundColor = SK_ColorWHITE; |
| 22 const SkColor kForegroundColor = 0xFF444444; | 23 const SkColor kForegroundColor = 0xFF444444; |
| 24 constexpr float kBorderFactor = 0.1; | |
| 25 constexpr float kIconSizeFactor = 0.7; | |
| 26 constexpr float kFontSizeFactor = 0.45; | |
| 27 constexpr float kTextHeightFactor = 1.0 - 2 * kBorderFactor; | |
| 28 constexpr float kTextWidthFactor = 4.0 - 3 * kBorderFactor - kIconSizeFactor; | |
| 23 | 29 |
| 24 } // namespace | 30 } // namespace |
| 25 | 31 |
| 26 InsecureContentPermanentTexture::InsecureContentPermanentTexture( | 32 InsecureContentPermanentTexture::InsecureContentPermanentTexture( |
| 27 int texture_handle, | 33 int texture_handle, |
| 28 int texture_size) | 34 int texture_size) |
| 29 : UITexture(texture_handle, texture_size) { | 35 : UITexture(texture_handle, texture_size) { |
| 30 // Ensuring height is a quarter of the width. | 36 // Ensuring height is a quarter of the width. |
| 31 DCHECK(texture_size_ % 4 == 0); | 37 DCHECK(texture_size_ % 4 == 0); |
| 32 height_ = texture_size_ / 4; | 38 height_ = texture_size_ / 4; |
| 33 } | 39 } |
| 34 | 40 |
| 35 InsecureContentPermanentTexture::~InsecureContentPermanentTexture() = default; | 41 InsecureContentPermanentTexture::~InsecureContentPermanentTexture() = default; |
| 36 | 42 |
| 37 void InsecureContentPermanentTexture::Draw(gfx::Canvas* canvas) { | 43 void InsecureContentPermanentTexture::Draw(gfx::Canvas* canvas) { |
| 38 cc::PaintFlags flags; | 44 cc::PaintFlags flags; |
| 39 flags.setColor(kBackgroundColor); | 45 flags.setColor(kBackgroundColor); |
| 40 canvas->DrawRoundRect(gfx::Rect(texture_size_, height_), height_ * 0.1, | 46 |
| 47 int text_flags = gfx::Canvas::TEXT_ALIGN_CENTER | gfx::Canvas::NO_ELLIPSIS; | |
| 48 auto text = | |
| 49 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INSECURE_WEBVR_CONTENT_PERMANENT); | |
| 50 auto fonts = GetFontList(height_ * kFontSizeFactor, text); | |
| 51 int text_height = kTextHeightFactor * height_; | |
| 52 int text_width = kTextWidthFactor * height_; | |
| 53 canvas->SizeStringInt(text, fonts, &text_width, &text_height, 0, text_flags); | |
|
mthiesse
2017/04/21 00:12:24
Canvas::SizeStringInt is a static function
| |
| 54 // Giving some extra width without reaching the texture limit. | |
| 55 text_width = static_cast<int>(std::min( | |
| 56 text_width + 2 * kBorderFactor * height_, kTextWidthFactor * height_)); | |
| 57 width_ = static_cast<int>( | |
| 58 ceil((3 * kBorderFactor + kIconSizeFactor) * height_ + text_width)); | |
| 59 | |
| 60 canvas->DrawRoundRect(gfx::Rect(width_, height_), height_ * kBorderFactor, | |
| 41 flags); | 61 flags); |
| 62 | |
| 42 canvas->Save(); | 63 canvas->Save(); |
| 43 canvas->Translate({height_ * 0.1, height_ * 0.1}); | 64 canvas->Translate({IsRTL() ? 2 * kBorderFactor * height_ + text_width |
| 44 PaintVectorIcon(canvas, ui::kInfoOutlineIcon, height_ * 0.8, | 65 : height_ * kBorderFactor, |
| 66 height_ * (1.0 - kIconSizeFactor) / 2.0}); | |
| 67 PaintVectorIcon(canvas, ui::kInfoOutlineIcon, height_ * kIconSizeFactor, | |
| 45 kForegroundColor); | 68 kForegroundColor); |
| 46 canvas->Restore(); | 69 canvas->Restore(); |
| 70 | |
| 47 canvas->Save(); | 71 canvas->Save(); |
| 48 canvas->Translate({height_, height_ * 0.1}); | 72 canvas->Translate({height_ * (IsRTL() ? kBorderFactor |
| 49 // TODO(acondor): Draw text IDS_PAGE_INFO_INSECURE_WEBVR_CONTENT_PERMANENT. | 73 : 2 * kBorderFactor + kIconSizeFactor), |
| 74 height_ * kBorderFactor}); | |
| 75 canvas->DrawStringRectWithFlags( | |
| 76 text, GetFontList(height_ * kFontSizeFactor, text), kForegroundColor, | |
|
mthiesse
2017/04/21 00:03:11
reuse |fonts|
| |
| 77 gfx::Rect(text_width, kTextHeightFactor * height_), text_flags); | |
| 50 canvas->Restore(); | 78 canvas->Restore(); |
| 51 } | 79 } |
| 52 | 80 |
| 53 void InsecureContentPermanentTexture::SetSize() { | 81 void InsecureContentPermanentTexture::SetSize() { |
| 54 size_.SetSize(texture_size_, height_); | 82 size_.SetSize(width_, height_); |
| 55 } | 83 } |
| 56 | 84 |
| 57 } // namespace vr_shell | 85 } // namespace vr_shell |
| OLD | NEW |