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

Side by Side Diff: chrome/browser/android/vr_shell/textures/exit_warning_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/exit_warning_texture.h" 5 #include "chrome/browser/android/vr_shell/textures/exit_warning_texture.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 ExitWarningTexture::ExitWarningTexture() = default; 29 ExitWarningTexture::ExitWarningTexture() = default;
32 30
33 ExitWarningTexture::~ExitWarningTexture() = default; 31 ExitWarningTexture::~ExitWarningTexture() = default;
34 32
35 void ExitWarningTexture::Draw(SkCanvas* sk_canvas, 33 void ExitWarningTexture::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
42 paint.setColor(color_scheme().exit_warning_background);
44 auto text = 43 auto text =
45 l10n_util::GetStringUTF16(IDS_PAGE_INFO_VR_BROWSER_UNSUPPORTED_MODE); 44 l10n_util::GetStringUTF16(IDS_PAGE_INFO_VR_BROWSER_UNSUPPORTED_MODE);
46 gfx::FontList fonts; 45 gfx::FontList fonts;
47 GetFontList(size_.width() * kFontSizeFactor, text, &fonts); 46 GetFontList(size_.width() * kFontSizeFactor, text, &fonts);
48 gfx::Rect text_size(size_.width() * kTextWidthFactor, 0); 47 gfx::Rect text_size(size_.width() * kTextWidthFactor, 0);
49 48
50 std::vector<std::unique_ptr<gfx::RenderText>> lines = 49 std::vector<std::unique_ptr<gfx::RenderText>> lines = PrepareDrawStringRect(
51 PrepareDrawStringRect(text, fonts, kForegroundColor, &text_size, 50 text, fonts, color_scheme().exit_warning_foreground, &text_size,
52 kTextAlignmentCenter, kWrappingBehaviorWrap); 51 kTextAlignmentCenter, kWrappingBehaviorWrap);
53 52
54 DCHECK_LE(text_size.height(), 53 DCHECK_LE(text_size.height(),
55 static_cast<int>((1.0 - 2 * kBorderFactor) * size_.width())); 54 static_cast<int>((1.0 - 2 * kBorderFactor) * size_.width()));
56 size_.set_height(size_.width() * 2 * kBorderFactor + text_size.height()); 55 size_.set_height(size_.width() * 2 * kBorderFactor + text_size.height());
57 float radius = size_.height() * kBorderFactor; 56 float radius = size_.height() * kBorderFactor;
58 sk_canvas->drawRoundRect(SkRect::MakeWH(size_.width(), size_.height()), 57 sk_canvas->drawRoundRect(SkRect::MakeWH(size_.width(), size_.height()),
59 radius, radius, paint); 58 radius, radius, paint);
60 59
61 canvas->Save(); 60 canvas->Save();
62 canvas->Translate(gfx::Vector2d(size_.width() * kBorderFactor, 61 canvas->Translate(gfx::Vector2d(size_.width() * kBorderFactor,
63 size_.width() * kBorderFactor)); 62 size_.width() * kBorderFactor));
64 for (auto& render_text : lines) 63 for (auto& render_text : lines)
65 render_text->Draw(canvas); 64 render_text->Draw(canvas);
66 canvas->Restore(); 65 canvas->Restore();
67 } 66 }
68 67
69 gfx::Size ExitWarningTexture::GetPreferredTextureSize(int maximum_width) const { 68 gfx::Size ExitWarningTexture::GetPreferredTextureSize(int maximum_width) const {
70 return gfx::Size(maximum_width, maximum_width); 69 return gfx::Size(maximum_width, maximum_width);
71 } 70 }
72 71
73 gfx::SizeF ExitWarningTexture::GetDrawnSize() const { 72 gfx::SizeF ExitWarningTexture::GetDrawnSize() const {
74 return size_; 73 return size_;
75 } 74 }
76 75
77 } // namespace vr_shell 76 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698