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

Side by Side Diff: chrome/browser/android/vr_shell/textures/insecure_content_transient_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_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 "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 = 0xCC1A1A1A;
24 const SkColor kForegroundColor = SK_ColorWHITE;
25 constexpr float kBorderFactor = 0.045; 23 constexpr float kBorderFactor = 0.045;
26 constexpr float kFontSizeFactor = 0.048; 24 constexpr float kFontSizeFactor = 0.048;
27 constexpr float kTextWidthFactor = 1.0 - 3 * kBorderFactor; 25 constexpr float kTextWidthFactor = 1.0 - 3 * kBorderFactor;
28 26
29 } // namespace 27 } // namespace
30 28
31 InsecureContentTransientTexture::InsecureContentTransientTexture() = default; 29 InsecureContentTransientTexture::InsecureContentTransientTexture() = default;
32 30
33 InsecureContentTransientTexture::~InsecureContentTransientTexture() = default; 31 InsecureContentTransientTexture::~InsecureContentTransientTexture() = default;
34 32
35 void InsecureContentTransientTexture::Draw(SkCanvas* sk_canvas, 33 void InsecureContentTransientTexture::Draw(SkCanvas* sk_canvas,
36 const gfx::Size& texture_size) { 34 const gfx::Size& texture_size) {
37 cc::SkiaPaintCanvas paint_canvas(sk_canvas); 35 cc::SkiaPaintCanvas paint_canvas(sk_canvas);
38 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f); 36 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f);
39 gfx::Canvas* canvas = &gfx_canvas; 37 gfx::Canvas* canvas = &gfx_canvas;
40 38
41 size_.set_width(texture_size.width()); 39 size_.set_width(texture_size.width());
42 SkPaint paint; 40 SkPaint paint;
43 paint.setColor(kBackgroundColor); 41 paint.setColor(color_scheme().transient_warning_background);
44 auto text = 42 auto text =
45 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INSECURE_WEBVR_CONTENT_TRANSIENT); 43 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INSECURE_WEBVR_CONTENT_TRANSIENT);
46 gfx::FontList fonts; 44 gfx::FontList fonts;
47 GetFontList(size_.width() * kFontSizeFactor, text, &fonts); 45 GetFontList(size_.width() * kFontSizeFactor, text, &fonts);
48 gfx::Rect text_size(size_.width() * kTextWidthFactor, 0); 46 gfx::Rect text_size(size_.width() * kTextWidthFactor, 0);
49 47
50 std::vector<std::unique_ptr<gfx::RenderText>> lines = 48 std::vector<std::unique_ptr<gfx::RenderText>> lines = PrepareDrawStringRect(
51 PrepareDrawStringRect(text, fonts, kForegroundColor, &text_size, 49 text, fonts, color_scheme().transient_warning_foreground, &text_size,
52 kTextAlignmentCenter, kWrappingBehaviorWrap); 50 kTextAlignmentCenter, kWrappingBehaviorWrap);
53 51
54 DCHECK_LE(text_size.height(), 52 DCHECK_LE(text_size.height(),
55 static_cast<int>((1.0 - 2 * kBorderFactor) * size_.width())); 53 static_cast<int>((1.0 - 2 * kBorderFactor) * size_.width()));
56 size_.set_height(size_.width() * 2 * kBorderFactor + text_size.height()); 54 size_.set_height(size_.width() * 2 * kBorderFactor + text_size.height());
57 float radius = size_.height() * kBorderFactor; 55 float radius = size_.height() * kBorderFactor;
58 sk_canvas->drawRoundRect(SkRect::MakeWH(size_.width(), size_.height()), 56 sk_canvas->drawRoundRect(SkRect::MakeWH(size_.width(), size_.height()),
59 radius, radius, paint); 57 radius, radius, paint);
60 58
61 canvas->Save(); 59 canvas->Save();
62 canvas->Translate(gfx::Vector2d(size_.width() * kBorderFactor, 60 canvas->Translate(gfx::Vector2d(size_.width() * kBorderFactor,
63 size_.width() * kBorderFactor)); 61 size_.width() * kBorderFactor));
64 for (auto& render_text : lines) 62 for (auto& render_text : lines)
65 render_text->Draw(canvas); 63 render_text->Draw(canvas);
66 canvas->Restore(); 64 canvas->Restore();
67 } 65 }
68 66
69 gfx::Size InsecureContentTransientTexture::GetPreferredTextureSize( 67 gfx::Size InsecureContentTransientTexture::GetPreferredTextureSize(
70 int maximum_width) const { 68 int maximum_width) const {
71 return gfx::Size(maximum_width, maximum_width); 69 return gfx::Size(maximum_width, maximum_width);
72 } 70 }
73 71
74 gfx::SizeF InsecureContentTransientTexture::GetDrawnSize() const { 72 gfx::SizeF InsecureContentTransientTexture::GetDrawnSize() const {
75 return size_; 73 return size_;
76 } 74 }
77 75
78 } // namespace vr_shell 76 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698