| 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" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 const SkColor kBackgroundColor = 0xCC1A1A1A; | 22 const SkColor kBackgroundColor = 0xCC1A1A1A; |
| 23 const SkColor kForegroundColor = SK_ColorWHITE; | 23 const SkColor kForegroundColor = SK_ColorWHITE; |
| 24 constexpr float kBorderFactor = 0.045; | 24 constexpr float kBorderFactor = 0.045; |
| 25 constexpr float kIconSizeFactor = 0.25; | 25 constexpr float kIconSizeFactor = 0.25; |
| 26 constexpr float kFontSizeFactor = 0.045; | 26 constexpr float kFontSizeFactor = 0.045; |
| 27 constexpr float kTextWidthFactor = 1.0 - 3 * kBorderFactor - kIconSizeFactor; | 27 constexpr float kTextWidthFactor = 1.0 - 3 * kBorderFactor - kIconSizeFactor; |
| 28 | 28 |
| 29 } // namespace | 29 } // namespace |
| 30 | 30 |
| 31 InsecureContentTransientTexture::InsecureContentTransientTexture( | 31 InsecureContentTransientTexture::InsecureContentTransientTexture() = default; |
| 32 int texture_handle, | |
| 33 int texture_size) | |
| 34 : UITexture(texture_handle, texture_size) { | |
| 35 } | |
| 36 | 32 |
| 37 InsecureContentTransientTexture::~InsecureContentTransientTexture() = default; | 33 InsecureContentTransientTexture::~InsecureContentTransientTexture() = default; |
| 38 | 34 |
| 39 void InsecureContentTransientTexture::Draw(gfx::Canvas* canvas) { | 35 void InsecureContentTransientTexture::Draw(gfx::Canvas* canvas, |
| 36 const gfx::Size& texture_size) { |
| 37 size_.set_width(texture_size.width()); |
| 38 int max_height = texture_size.height(); |
| 40 cc::PaintFlags flags; | 39 cc::PaintFlags flags; |
| 41 flags.setColor(kBackgroundColor); | 40 flags.setColor(kBackgroundColor); |
| 42 | 41 |
| 43 int text_flags = gfx::Canvas::TEXT_ALIGN_CENTER | gfx::Canvas::MULTI_LINE; | 42 int text_flags = gfx::Canvas::TEXT_ALIGN_CENTER | gfx::Canvas::MULTI_LINE; |
| 44 auto text = | 43 auto text = |
| 45 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INSECURE_WEBVR_CONTENT_TRANSIENT); | 44 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INSECURE_WEBVR_CONTENT_TRANSIENT); |
| 46 auto fonts = GetFontList(texture_size_ * kFontSizeFactor, text); | 45 auto fonts = GetFontList(size_.width() * kFontSizeFactor, text); |
| 47 | 46 int text_width = size_.width() * kTextWidthFactor; |
| 48 int text_width = texture_size_ * kTextWidthFactor; | |
| 49 int text_height = 0; // Will be increased during text measurement. | 47 int text_height = 0; // Will be increased during text measurement. |
| 50 gfx::Canvas::SizeStringInt(text, fonts, &text_width, &text_height, 0, | 48 gfx::Canvas::SizeStringInt(text, fonts, &text_width, &text_height, 0, |
| 51 text_flags); | 49 text_flags); |
| 52 // Making sure that the icon fits in the box. | 50 // Making sure that the icon fits in the box. |
| 53 text_height = std::max( | 51 text_height = std::max( |
| 54 text_height, static_cast<int>(ceil(texture_size_ * kIconSizeFactor))); | 52 text_height, static_cast<int>(ceil(size_.width() * kIconSizeFactor))); |
| 55 // Making sure the drawing fits within the texture. | 53 // Making sure the drawing fits within the texture. |
| 56 text_height = std::min( | 54 text_height = std::min( |
| 57 text_height, static_cast<int>((1.0 - 2 * kBorderFactor) * texture_size_)); | 55 text_height, static_cast<int>((1.0 - 2 * kBorderFactor) * size_.width())); |
| 58 height_ = | 56 size_.set_height(size_.width() * 2 * kBorderFactor + text_height); |
| 59 static_cast<int>(ceil(texture_size_ * 2 * kBorderFactor + text_height)); | 57 DCHECK_LE(size_.height(), max_height); |
| 60 | 58 canvas->DrawRoundRect(gfx::Rect(size_.width(), size_.height()), |
| 61 canvas->DrawRoundRect(gfx::Rect(texture_size_, height_), | 59 size_.height() * kBorderFactor, flags); |
| 62 height_ * kBorderFactor, flags); | |
| 63 | 60 |
| 64 canvas->Save(); | 61 canvas->Save(); |
| 65 canvas->Translate({IsRTL() ? 2 * kBorderFactor * texture_size_ + text_width | 62 canvas->Translate( |
| 66 : texture_size_ * kBorderFactor, | 63 gfx::Vector2d(IsRTL() ? 2 * kBorderFactor * size_.width() + text_width |
| 67 (height_ - kIconSizeFactor * texture_size_) / 2.0}); | 64 : size_.width() * kBorderFactor, |
| 68 PaintVectorIcon(canvas, ui::kInfoOutlineIcon, texture_size_ * kIconSizeFactor, | 65 (size_.height() - kIconSizeFactor * size_.width()) / 2.0)); |
| 66 PaintVectorIcon(canvas, ui::kInfoOutlineIcon, size_.width() * kIconSizeFactor, |
| 69 kForegroundColor); | 67 kForegroundColor); |
| 70 canvas->Restore(); | 68 canvas->Restore(); |
| 71 | 69 |
| 72 canvas->Save(); | 70 canvas->Save(); |
| 73 canvas->Translate( | 71 canvas->Translate(gfx::Vector2d( |
| 74 {IsRTL() ? kBorderFactor * texture_size_ | 72 IsRTL() ? kBorderFactor * size_.width() |
| 75 : texture_size_ * (2 * kBorderFactor + kIconSizeFactor), | 73 : size_.width() * (2 * kBorderFactor + kIconSizeFactor), |
| 76 texture_size_ * kBorderFactor}); | 74 size_.width() * kBorderFactor)); |
| 77 canvas->DrawStringRectWithFlags( | 75 canvas->DrawStringRectWithFlags( |
| 78 text, fonts, kForegroundColor, | 76 text, fonts, kForegroundColor, |
| 79 gfx::Rect(kTextWidthFactor * texture_size_, text_height), text_flags); | 77 gfx::Rect(kTextWidthFactor * size_.width(), text_height), text_flags); |
| 80 canvas->Restore(); | 78 canvas->Restore(); |
| 81 } | 79 } |
| 82 | 80 |
| 83 void InsecureContentTransientTexture::SetSize() { | 81 gfx::Size InsecureContentTransientTexture::GetPreferredTextureSize( |
| 84 size_.SetSize(texture_size_, height_); | 82 int maximum_width) const { |
| 83 return gfx::Size(maximum_width, maximum_width); |
| 84 } |
| 85 |
| 86 gfx::SizeF InsecureContentTransientTexture::GetDrawnSize() const { |
| 87 return size_; |
| 85 } | 88 } |
| 86 | 89 |
| 87 } // namespace vr_shell | 90 } // namespace vr_shell |
| OLD | NEW |