| 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" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 const SkColor kBackgroundColor = SK_ColorWHITE; | 22 const SkColor kBackgroundColor = SK_ColorWHITE; |
| 23 const SkColor kForegroundColor = 0xFF444444; | 23 const SkColor kForegroundColor = 0xFF444444; |
| 24 constexpr float kBorderFactor = 0.1; | 24 constexpr float kBorderFactor = 0.1; |
| 25 constexpr float kIconSizeFactor = 0.7; | 25 constexpr float kIconSizeFactor = 0.7; |
| 26 constexpr float kFontSizeFactor = 0.45; | 26 constexpr float kFontSizeFactor = 0.45; |
| 27 constexpr float kTextHeightFactor = 1.0 - 2 * kBorderFactor; | 27 constexpr float kTextHeightFactor = 1.0 - 2 * kBorderFactor; |
| 28 constexpr float kTextWidthFactor = 4.0 - 3 * kBorderFactor - kIconSizeFactor; | 28 constexpr float kTextWidthFactor = 4.0 - 3 * kBorderFactor - kIconSizeFactor; |
| 29 | 29 |
| 30 } // namespace | 30 } // namespace |
| 31 | 31 |
| 32 InsecureContentPermanentTexture::InsecureContentPermanentTexture( | 32 InsecureContentPermanentTexture::InsecureContentPermanentTexture() = default; |
| 33 int texture_handle, | |
| 34 int texture_size) | |
| 35 : UITexture(texture_handle, texture_size) { | |
| 36 // Ensuring height is a quarter of the width. | |
| 37 DCHECK(texture_size_ % 4 == 0); | |
| 38 height_ = texture_size_ / 4; | |
| 39 } | |
| 40 | 33 |
| 41 InsecureContentPermanentTexture::~InsecureContentPermanentTexture() = default; | 34 InsecureContentPermanentTexture::~InsecureContentPermanentTexture() = default; |
| 42 | 35 |
| 43 void InsecureContentPermanentTexture::Draw(gfx::Canvas* canvas) { | 36 void InsecureContentPermanentTexture::Draw(gfx::Canvas* canvas, |
| 37 const gfx::Size& texture_size) { |
| 38 DCHECK(texture_size.height() * 4 == texture_size.width()); |
| 39 size_.set_height(texture_size.height()); |
| 40 int max_width = texture_size.width(); |
| 44 cc::PaintFlags flags; | 41 cc::PaintFlags flags; |
| 45 flags.setColor(kBackgroundColor); | 42 flags.setColor(kBackgroundColor); |
| 46 | 43 |
| 47 int text_flags = gfx::Canvas::TEXT_ALIGN_CENTER | gfx::Canvas::NO_ELLIPSIS; | 44 int text_flags = gfx::Canvas::TEXT_ALIGN_CENTER | gfx::Canvas::NO_ELLIPSIS; |
| 48 auto text = | 45 auto text = |
| 49 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INSECURE_WEBVR_CONTENT_PERMANENT); | 46 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INSECURE_WEBVR_CONTENT_PERMANENT); |
| 50 auto fonts = GetFontList(height_ * kFontSizeFactor, text); | 47 auto fonts = GetFontList(size_.height() * kFontSizeFactor, text); |
| 51 int text_height = kTextHeightFactor * height_; | 48 int text_height = kTextHeightFactor * size_.height(); |
| 52 int text_width = kTextWidthFactor * height_; | 49 int text_width = kTextWidthFactor * size_.height(); |
| 53 canvas->SizeStringInt(text, fonts, &text_width, &text_height, 0, text_flags); | 50 canvas->SizeStringInt(text, fonts, &text_width, &text_height, 0, text_flags); |
| 54 // Giving some extra width without reaching the texture limit. | 51 // Giving some extra width without reaching the texture limit. |
| 55 text_width = static_cast<int>(std::min( | 52 text_width = |
| 56 text_width + 2 * kBorderFactor * height_, kTextWidthFactor * height_)); | 53 static_cast<int>(std::min(text_width + 2 * kBorderFactor * size_.height(), |
| 57 width_ = static_cast<int>( | 54 kTextWidthFactor * size_.height())); |
| 58 ceil((3 * kBorderFactor + kIconSizeFactor) * height_ + text_width)); | 55 size_.set_width((3 * kBorderFactor + kIconSizeFactor) * size_.height() + |
| 59 | 56 text_width); |
| 60 canvas->DrawRoundRect(gfx::Rect(width_, height_), height_ * kBorderFactor, | 57 DCHECK(size_.width() <= max_width); |
| 61 flags); | 58 canvas->DrawRoundRect(gfx::Rect(size_.width(), size_.height()), |
| 59 size_.height() * kBorderFactor, flags); |
| 62 | 60 |
| 63 canvas->Save(); | 61 canvas->Save(); |
| 64 canvas->Translate({IsRTL() ? 2 * kBorderFactor * height_ + text_width | 62 canvas->Translate( |
| 65 : height_ * kBorderFactor, | 63 gfx::Vector2d(IsRTL() ? 2 * kBorderFactor * size_.height() + text_width |
| 66 height_ * (1.0 - kIconSizeFactor) / 2.0}); | 64 : size_.height() * kBorderFactor, |
| 67 PaintVectorIcon(canvas, ui::kInfoOutlineIcon, height_ * kIconSizeFactor, | 65 size_.height() * (1.0 - kIconSizeFactor) / 2.0)); |
| 68 kForegroundColor); | 66 PaintVectorIcon(canvas, ui::kInfoOutlineIcon, |
| 67 size_.height() * kIconSizeFactor, kForegroundColor); |
| 69 canvas->Restore(); | 68 canvas->Restore(); |
| 70 | 69 |
| 71 canvas->Save(); | 70 canvas->Save(); |
| 72 canvas->Translate({height_ * (IsRTL() ? kBorderFactor | 71 canvas->Translate(gfx::Vector2d( |
| 73 : 2 * kBorderFactor + kIconSizeFactor), | 72 size_.height() * |
| 74 height_ * kBorderFactor}); | 73 (IsRTL() ? kBorderFactor : 2 * kBorderFactor + kIconSizeFactor), |
| 74 size_.height() * kBorderFactor)); |
| 75 canvas->DrawStringRectWithFlags( | 75 canvas->DrawStringRectWithFlags( |
| 76 text, GetFontList(height_ * kFontSizeFactor, text), kForegroundColor, | 76 text, fonts, kForegroundColor, |
| 77 gfx::Rect(text_width, kTextHeightFactor * height_), text_flags); | 77 gfx::Rect(text_width, kTextHeightFactor * size_.height()), text_flags); |
| 78 canvas->Restore(); | 78 canvas->Restore(); |
| 79 } | 79 } |
| 80 | 80 |
| 81 void InsecureContentPermanentTexture::SetSize() { | 81 gfx::Size InsecureContentPermanentTexture::GetPreferredTextureSize( |
| 82 size_.SetSize(width_, height_); | 82 int width) const { |
| 83 // Ensuring height is a quarter of the width. |
| 84 int height = width / 4; |
| 85 return gfx::Size(height * 4, height); |
| 86 } |
| 87 |
| 88 gfx::SizeF InsecureContentPermanentTexture::GetActualSize() const { |
| 89 return size_; |
| 83 } | 90 } |
| 84 | 91 |
| 85 } // namespace vr_shell | 92 } // namespace vr_shell |
| OLD | NEW |