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/font_list.h" |
| 12 #include "ui/gfx/geometry/rect.h" | 12 #include "ui/gfx/geometry/rect.h" |
| 13 #include "ui/gfx/geometry/vector2d.h" | 13 #include "ui/gfx/geometry/vector2d.h" |
| 14 #include "ui/gfx/paint_vector_icon.h" | 14 #include "ui/gfx/paint_vector_icon.h" |
| 15 #include "ui/gfx/vector_icon_types.h" | 15 #include "ui/gfx/vector_icon_types.h" |
| 16 #include "ui/vector_icons/vector_icons.h" | 16 #include "ui/vector_icons/vector_icons.h" |
| 17 | 17 |
| 18 namespace vr_shell { | 18 namespace vr_shell { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 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 kFontSizeFactor = 0.048; |
| 26 constexpr float kFontSizeFactor = 0.045; | 26 constexpr float kTextWidthFactor = 1.0 - 3 * kBorderFactor; |
| 27 constexpr float kTextWidthFactor = 1.0 - 3 * kBorderFactor - kIconSizeFactor; | |
| 28 | 27 |
| 29 } // namespace | 28 } // namespace |
| 30 | 29 |
| 31 InsecureContentTransientTexture::InsecureContentTransientTexture() = default; | 30 InsecureContentTransientTexture::InsecureContentTransientTexture() = default; |
| 32 | 31 |
| 33 InsecureContentTransientTexture::~InsecureContentTransientTexture() = default; | 32 InsecureContentTransientTexture::~InsecureContentTransientTexture() = default; |
| 34 | 33 |
| 35 void InsecureContentTransientTexture::Draw(gfx::Canvas* canvas, | 34 void InsecureContentTransientTexture::Draw(gfx::Canvas* canvas, |
| 36 const gfx::Size& texture_size) { | 35 const gfx::Size& texture_size) { |
| 37 size_.set_width(texture_size.width()); | 36 size_.set_width(texture_size.width()); |
| 38 int max_height = texture_size.height(); | 37 int max_height = texture_size.height(); |
| 39 cc::PaintFlags flags; | 38 cc::PaintFlags flags; |
| 40 flags.setColor(kBackgroundColor); | 39 flags.setColor(kBackgroundColor); |
| 41 | 40 |
| 42 int text_flags = gfx::Canvas::TEXT_ALIGN_CENTER | gfx::Canvas::MULTI_LINE; | 41 int text_flags = gfx::Canvas::TEXT_ALIGN_CENTER | gfx::Canvas::MULTI_LINE; |
| 43 auto text = | 42 auto text = |
| 44 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INSECURE_WEBVR_CONTENT_TRANSIENT); | 43 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INSECURE_WEBVR_CONTENT_TRANSIENT); |
| 45 auto fonts = GetFontList(size_.width() * kFontSizeFactor, text); | 44 auto fonts = GetFontList(size_.width() * kFontSizeFactor, text); |
| 46 int text_width = size_.width() * kTextWidthFactor; | 45 int text_width = size_.width() * kTextWidthFactor; |
| 47 int text_height = 0; // Will be increased during text measurement. | 46 int text_height = 0; // Will be increased during text measurement. |
| 48 gfx::Canvas::SizeStringInt(text, fonts, &text_width, &text_height, 0, | 47 gfx::Canvas::SizeStringInt(text, fonts, &text_width, &text_height, 0, |
| 49 text_flags); | 48 text_flags); |
| 50 // Making sure that the icon fits in the box. | 49 |
| 51 text_height = std::max( | |
| 52 text_height, static_cast<int>(ceil(size_.width() * kIconSizeFactor))); | |
| 53 // Making sure the drawing fits within the texture. | 50 // Making sure the drawing fits within the texture. |
| 54 text_height = std::min( | 51 text_height = std::min( |
| 55 text_height, static_cast<int>((1.0 - 2 * kBorderFactor) * size_.width())); | 52 text_height, static_cast<int>((1.0 - 2 * kBorderFactor) * size_.width())); |
| 56 size_.set_height(size_.width() * 2 * kBorderFactor + text_height); | 53 size_.set_height(size_.width() * 2 * kBorderFactor + text_height); |
| 57 DCHECK_LE(size_.height(), max_height); | 54 DCHECK_LE(size_.height(), max_height); |
| 58 canvas->DrawRoundRect(gfx::Rect(size_.width(), size_.height()), | 55 canvas->DrawRoundRect(gfx::Rect(size_.width(), size_.height()), |
| 59 size_.height() * kBorderFactor, flags); | 56 size_.height() * kBorderFactor, flags); |
| 60 | 57 |
| 61 canvas->Save(); | 58 canvas->Save(); |
| 62 canvas->Translate( | 59 canvas->Translate(gfx::Vector2d(IsRTL() ? kBorderFactor * size_.width() |
|
acondor_
2017/04/27 16:09:50
There's no need to distinguish between RTL and LTR
mthiesse
2017/04/27 16:58:07
Done.
| |
| 63 gfx::Vector2d(IsRTL() ? 2 * kBorderFactor * size_.width() + text_width | 60 : size_.width() * (2 * kBorderFactor), |
| 64 : size_.width() * kBorderFactor, | 61 size_.width() * kBorderFactor)); |
| 65 (size_.height() - kIconSizeFactor * size_.width()) / 2.0)); | |
| 66 PaintVectorIcon(canvas, ui::kInfoOutlineIcon, size_.width() * kIconSizeFactor, | |
| 67 kForegroundColor); | |
| 68 canvas->Restore(); | |
| 69 | |
| 70 canvas->Save(); | |
| 71 canvas->Translate(gfx::Vector2d( | |
| 72 IsRTL() ? kBorderFactor * size_.width() | |
| 73 : size_.width() * (2 * kBorderFactor + kIconSizeFactor), | |
| 74 size_.width() * kBorderFactor)); | |
| 75 canvas->DrawStringRectWithFlags( | 62 canvas->DrawStringRectWithFlags( |
| 76 text, fonts, kForegroundColor, | 63 text, fonts, kForegroundColor, |
| 77 gfx::Rect(kTextWidthFactor * size_.width(), text_height), text_flags); | 64 gfx::Rect(kTextWidthFactor * size_.width(), text_height), text_flags); |
| 78 canvas->Restore(); | 65 canvas->Restore(); |
| 79 } | 66 } |
| 80 | 67 |
| 81 gfx::Size InsecureContentTransientTexture::GetPreferredTextureSize( | 68 gfx::Size InsecureContentTransientTexture::GetPreferredTextureSize( |
| 82 int maximum_width) const { | 69 int maximum_width) const { |
| 83 return gfx::Size(maximum_width, maximum_width); | 70 return gfx::Size(maximum_width, maximum_width); |
|
acondor_
2017/04/27 16:09:50
It might be possible to fit everything in half the
mthiesse
2017/04/27 16:58:07
I'd rather be on the safe side and ensure we have
| |
| 84 } | 71 } |
| 85 | 72 |
| 86 gfx::SizeF InsecureContentTransientTexture::GetDrawnSize() const { | 73 gfx::SizeF InsecureContentTransientTexture::GetDrawnSize() const { |
| 87 return size_; | 74 return size_; |
| 88 } | 75 } |
| 89 | 76 |
| 90 } // namespace vr_shell | 77 } // namespace vr_shell |
| OLD | NEW |