Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: chrome/browser/android/vr_shell/textures/insecure_content_permanent_texture.cc

Issue 2926643003: [VrShell] Centralize color handling and enable close button on fullscreen (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/strings/grit/components_strings.h" 8 #include "components/strings/grit/components_strings.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/render_text.h" 15 #include "ui/gfx/render_text.h"
16 #include "ui/gfx/vector_icon_types.h" 16 #include "ui/gfx/vector_icon_types.h"
17 #include "ui/vector_icons/vector_icons.h" 17 #include "ui/vector_icons/vector_icons.h"
18 18
19 namespace vr_shell { 19 namespace vr_shell {
20 20
21 namespace { 21 namespace {
22 22
23 const SkColor kBackgroundColor = SK_ColorWHITE;
24 const SkColor kForegroundColor = 0xFF444444;
25 constexpr float kBorderFactor = 0.1; 23 constexpr float kBorderFactor = 0.1;
26 constexpr float kIconSizeFactor = 0.7; 24 constexpr float kIconSizeFactor = 0.7;
27 constexpr float kFontSizeFactor = 0.40; 25 constexpr float kFontSizeFactor = 0.40;
28 constexpr float kTextHeightFactor = 1.0 - 2 * kBorderFactor; 26 constexpr float kTextHeightFactor = 1.0 - 2 * kBorderFactor;
29 constexpr float kTextWidthFactor = 4.0 - 3 * kBorderFactor - kIconSizeFactor; 27 constexpr float kTextWidthFactor = 4.0 - 3 * kBorderFactor - kIconSizeFactor;
30 28
31 } // namespace 29 } // namespace
32 30
33 InsecureContentPermanentTexture::InsecureContentPermanentTexture() = default; 31 InsecureContentPermanentTexture::InsecureContentPermanentTexture() = default;
34 32
35 InsecureContentPermanentTexture::~InsecureContentPermanentTexture() = default; 33 InsecureContentPermanentTexture::~InsecureContentPermanentTexture() = default;
36 34
37 void InsecureContentPermanentTexture::Draw(SkCanvas* sk_canvas, 35 void InsecureContentPermanentTexture::Draw(SkCanvas* sk_canvas,
38 const gfx::Size& texture_size) { 36 const gfx::Size& texture_size) {
39 cc::SkiaPaintCanvas paint_canvas(sk_canvas); 37 cc::SkiaPaintCanvas paint_canvas(sk_canvas);
40 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f); 38 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f);
41 gfx::Canvas* canvas = &gfx_canvas; 39 gfx::Canvas* canvas = &gfx_canvas;
42 40
43 DCHECK(texture_size.height() * 4 == texture_size.width()); 41 DCHECK(texture_size.height() * 4 == texture_size.width());
44 size_.set_height(texture_size.height()); 42 size_.set_height(texture_size.height());
45 SkPaint paint; 43 SkPaint paint;
46 paint.setColor(kBackgroundColor); 44 paint.setColor(color_scheme().permanent_warning_background);
47 auto text = 45 auto text =
48 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INSECURE_WEBVR_CONTENT_PERMANENT); 46 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INSECURE_WEBVR_CONTENT_PERMANENT);
49 gfx::FontList fonts; 47 gfx::FontList fonts;
50 GetFontList(size_.height() * kFontSizeFactor, text, &fonts); 48 GetFontList(size_.height() * kFontSizeFactor, text, &fonts);
51 gfx::Rect text_size(0, kTextHeightFactor * size_.height()); 49 gfx::Rect text_size(0, kTextHeightFactor * size_.height());
52 50
53 std::vector<std::unique_ptr<gfx::RenderText>> lines = 51 std::vector<std::unique_ptr<gfx::RenderText>> lines = PrepareDrawStringRect(
54 PrepareDrawStringRect(text, fonts, kForegroundColor, &text_size, 52 text, fonts, color_scheme().permanent_warning_foreground, &text_size,
55 kTextAlignmentNone, kWrappingBehaviorNoWrap); 53 kTextAlignmentNone, kWrappingBehaviorNoWrap);
56 54
57 DCHECK_LE(text_size.width(), kTextWidthFactor * size_.height()); 55 DCHECK_LE(text_size.width(), kTextWidthFactor * size_.height());
58 // Setting background size giving some extra lateral padding to the text. 56 // Setting background size giving some extra lateral padding to the text.
59 size_.set_width((5 * kBorderFactor + kIconSizeFactor) * size_.height() + 57 size_.set_width((5 * kBorderFactor + kIconSizeFactor) * size_.height() +
60 text_size.width()); 58 text_size.width());
61 float radius = size_.height() * kBorderFactor; 59 float radius = size_.height() * kBorderFactor;
62 sk_canvas->drawRoundRect(SkRect::MakeWH(size_.width(), size_.height()), 60 sk_canvas->drawRoundRect(SkRect::MakeWH(size_.width(), size_.height()),
63 radius, radius, paint); 61 radius, radius, paint);
64 62
65 canvas->Save(); 63 canvas->Save();
66 canvas->Translate(gfx::Vector2d( 64 canvas->Translate(gfx::Vector2d(
67 IsRTL() ? 4 * kBorderFactor * size_.height() + text_size.width() 65 IsRTL() ? 4 * kBorderFactor * size_.height() + text_size.width()
68 : size_.height() * kBorderFactor, 66 : size_.height() * kBorderFactor,
69 size_.height() * (1.0 - kIconSizeFactor) / 2.0)); 67 size_.height() * (1.0 - kIconSizeFactor) / 2.0));
70 PaintVectorIcon(canvas, ui::kInfoOutlineIcon, 68 PaintVectorIcon(canvas, ui::kInfoOutlineIcon,
71 size_.height() * kIconSizeFactor, kForegroundColor); 69 size_.height() * kIconSizeFactor,
70 color_scheme().permanent_warning_foreground);
72 canvas->Restore(); 71 canvas->Restore();
73 72
74 canvas->Save(); 73 canvas->Save();
75 canvas->Translate(gfx::Vector2d( 74 canvas->Translate(gfx::Vector2d(
76 size_.height() * 75 size_.height() *
77 (IsRTL() ? 2 * kBorderFactor : 3 * kBorderFactor + kIconSizeFactor), 76 (IsRTL() ? 2 * kBorderFactor : 3 * kBorderFactor + kIconSizeFactor),
78 size_.height() * kBorderFactor)); 77 size_.height() * kBorderFactor));
79 for (auto& render_text : lines) 78 for (auto& render_text : lines)
80 render_text->Draw(canvas); 79 render_text->Draw(canvas);
81 canvas->Restore(); 80 canvas->Restore();
82 } 81 }
83 82
84 gfx::Size InsecureContentPermanentTexture::GetPreferredTextureSize( 83 gfx::Size InsecureContentPermanentTexture::GetPreferredTextureSize(
85 int maximum_width) const { 84 int maximum_width) const {
86 // Ensuring height is a quarter of the width. 85 // Ensuring height is a quarter of the width.
87 int height = maximum_width / 4; 86 int height = maximum_width / 4;
88 return gfx::Size(height * 4, height); 87 return gfx::Size(height * 4, height);
89 } 88 }
90 89
91 gfx::SizeF InsecureContentPermanentTexture::GetDrawnSize() const { 90 gfx::SizeF InsecureContentPermanentTexture::GetDrawnSize() const {
92 return size_; 91 return size_;
93 } 92 }
94 93
95 } // namespace vr_shell 94 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698