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" |
| (...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 canvas->SizeStringInt(text, fonts, &text_width, &text_height, 0, text_flags); | 48 canvas->SizeStringInt(text, fonts, &text_width, &text_height, 0, text_flags); |
| 51 // Making sure that the icon fits in the box. | 49 // Making sure that the icon fits in the box. |
| 52 text_height = std::max( | 50 text_height = std::max( |
| 53 text_height, static_cast<int>(ceil(texture_size_ * kIconSizeFactor))); | 51 text_height, static_cast<int>(ceil(size_.width() * kIconSizeFactor))); |
| 54 // Making sure the drawing fits within the texture. | 52 // Making sure the drawing fits within the texture. |
| 55 text_height = std::min( | 53 text_height = std::min( |
| 56 text_height, static_cast<int>((1.0 - 2 * kBorderFactor) * texture_size_)); | 54 text_height, static_cast<int>((1.0 - 2 * kBorderFactor) * size_.width())); |
| 57 height_ = | 55 size_.set_height(size_.width() * 2 * kBorderFactor + text_height); |
| 58 static_cast<int>(ceil(texture_size_ * 2 * kBorderFactor + text_height)); | 56 DCHECK(size_.height() <= max_height); |
|
cjgrant
2017/04/21 14:30:13
DCHECK_LE()
mthiesse
2017/04/21 15:05:12
Done.
| |
| 59 | 57 canvas->DrawRoundRect(gfx::Rect(size_.width(), size_.height()), |
| 60 canvas->DrawRoundRect(gfx::Rect(texture_size_, height_), | 58 size_.height() * kBorderFactor, flags); |
| 61 height_ * kBorderFactor, flags); | |
| 62 | 59 |
| 63 canvas->Save(); | 60 canvas->Save(); |
| 64 canvas->Translate({IsRTL() ? 2 * kBorderFactor * texture_size_ + text_width | 61 canvas->Translate( |
| 65 : texture_size_ * kBorderFactor, | 62 gfx::Vector2d(IsRTL() ? 2 * kBorderFactor * size_.width() + text_width |
| 66 (height_ - kIconSizeFactor * texture_size_) / 2.0}); | 63 : size_.width() * kBorderFactor, |
| 67 PaintVectorIcon(canvas, ui::kInfoOutlineIcon, texture_size_ * kIconSizeFactor, | 64 (size_.height() - kIconSizeFactor * size_.width()) / 2.0)); |
| 65 PaintVectorIcon(canvas, ui::kInfoOutlineIcon, size_.width() * kIconSizeFactor, | |
| 68 kForegroundColor); | 66 kForegroundColor); |
| 69 canvas->Restore(); | 67 canvas->Restore(); |
| 70 | 68 |
| 71 canvas->Save(); | 69 canvas->Save(); |
| 72 canvas->Translate( | 70 canvas->Translate(gfx::Vector2d( |
| 73 {IsRTL() ? kBorderFactor * texture_size_ | 71 IsRTL() ? kBorderFactor * size_.width() |
| 74 : texture_size_ * (2 * kBorderFactor + kIconSizeFactor), | 72 : size_.width() * (2 * kBorderFactor + kIconSizeFactor), |
| 75 texture_size_ * kBorderFactor}); | 73 size_.width() * kBorderFactor)); |
| 76 canvas->DrawStringRectWithFlags( | 74 canvas->DrawStringRectWithFlags( |
| 77 text, fonts, kForegroundColor, | 75 text, fonts, kForegroundColor, |
| 78 gfx::Rect(kTextWidthFactor * texture_size_, text_height), text_flags); | 76 gfx::Rect(kTextWidthFactor * size_.width(), text_height), text_flags); |
| 79 canvas->Restore(); | 77 canvas->Restore(); |
| 80 } | 78 } |
| 81 | 79 |
| 82 void InsecureContentTransientTexture::SetSize() { | 80 gfx::Size InsecureContentTransientTexture::GetPreferredTextureSize( |
| 83 size_.SetSize(texture_size_, height_); | 81 int width) const { |
| 82 return gfx::Size(width, width); | |
| 83 } | |
| 84 | |
| 85 gfx::SizeF InsecureContentTransientTexture::GetActualSize() const { | |
| 86 return size_; | |
| 84 } | 87 } |
| 85 | 88 |
| 86 } // namespace vr_shell | 89 } // namespace vr_shell |
| OLD | NEW |