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

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

Issue 2872773002: VR: Render the current URL and security level on the URL bar. (Closed)
Patch Set: Created 3 years, 7 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/url_bar_texture.h" 5 #include "chrome/browser/android/vr_shell/textures/url_bar_texture.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "cc/paint/skia_paint_canvas.h" 8 #include "cc/paint/skia_paint_canvas.h"
9 #include "chrome/app/vector_icons/vector_icons.h"
10 #include "components/security_state/core/security_state.h"
9 #include "ui/gfx/canvas.h" 11 #include "ui/gfx/canvas.h"
10 #include "ui/gfx/font.h" 12 #include "ui/gfx/font.h"
11 #include "ui/gfx/font_list.h" 13 #include "ui/gfx/font_list.h"
12 #include "ui/gfx/geometry/rect.h" 14 #include "ui/gfx/geometry/rect.h"
13 #include "ui/gfx/paint_vector_icon.h" 15 #include "ui/gfx/paint_vector_icon.h"
14 #include "ui/gfx/vector_icon_types.h" 16 #include "ui/gfx/vector_icon_types.h"
15 #include "ui/vector_icons/vector_icons.h" 17 #include "ui/vector_icons/vector_icons.h"
16 18
17 namespace vr_shell { 19 namespace vr_shell {
18 20
(...skipping 10 matching lines...) Expand all
29 static constexpr float kHeight = 0.088; 31 static constexpr float kHeight = 0.088;
30 static constexpr float kFontHeight = 0.027; 32 static constexpr float kFontHeight = 0.027;
31 static constexpr float kBackButtonWidth = kHeight; 33 static constexpr float kBackButtonWidth = kHeight;
32 static constexpr float kBackIconHeight = 0.05; 34 static constexpr float kBackIconHeight = 0.05;
33 static constexpr float kBackIconOffset = 0.005; 35 static constexpr float kBackIconOffset = 0.005;
34 static constexpr float kSecurityFieldWidth = 0.06; 36 static constexpr float kSecurityFieldWidth = 0.06;
35 static constexpr float kSecurityIconHeight = 0.03; 37 static constexpr float kSecurityIconHeight = 0.03;
36 static constexpr float kUrlRightMargin = 0.02; 38 static constexpr float kUrlRightMargin = 0.02;
37 static constexpr float kSeparatorWidth = 0.002; 39 static constexpr float kSeparatorWidth = 0.002;
38 40
41 using security_state::SecurityLevel;
42
43 const struct gfx::VectorIcon& getSecurityIcon(int level) {
44 switch (level) {
45 case SecurityLevel::NONE:
46 case SecurityLevel::HTTP_SHOW_WARNING:
47 case SecurityLevel::SECURITY_WARNING:
48 return ui::kInfoOutlineIcon;
49 case SecurityLevel::SECURE:
50 case SecurityLevel::EV_SECURE:
51 return kLockIcon;
52 case SecurityLevel::SECURE_WITH_POLICY_INSTALLED_CERT:
53 case SecurityLevel::DANGEROUS:
54 default:
55 return ui::kWarningIcon;
56 }
57 }
58
39 } // namespace 59 } // namespace
40 60
41 UrlBarTexture::UrlBarTexture() = default; 61 UrlBarTexture::UrlBarTexture() : security_level_(SecurityLevel::DANGEROUS) {}
42 62
43 UrlBarTexture::~UrlBarTexture() = default; 63 UrlBarTexture::~UrlBarTexture() = default;
44 64
45 void UrlBarTexture::SetHover(bool hover) { 65 void UrlBarTexture::SetHover(bool hover) {
46 hover_ = hover; 66 hover_ = hover;
47 } 67 }
48 68
49 void UrlBarTexture::SetURL(const GURL& gurl) { 69 void UrlBarTexture::SetURL(const GURL& gurl) {
50 gurl_ = gurl; 70 gurl_ = gurl;
51 } 71 }
52 72
73 void UrlBarTexture::SetSecurityLevel(int level) {
74 security_level_ = level;
75 }
76
53 float UrlBarTexture::ToPixels(float meters) const { 77 float UrlBarTexture::ToPixels(float meters) const {
54 return meters * size_.width() / kWidth; 78 return meters * size_.width() / kWidth;
55 } 79 }
56 80
57 void UrlBarTexture::Draw(SkCanvas* canvas, const gfx::Size& texture_size) { 81 void UrlBarTexture::Draw(SkCanvas* canvas, const gfx::Size& texture_size) {
58 size_.set_height(texture_size.height()); 82 size_.set_height(texture_size.height());
59 size_.set_width(texture_size.width()); 83 size_.set_width(texture_size.width());
60 84
61 canvas->save(); 85 canvas->save();
62 canvas->scale(size_.width() / kWidth, size_.width() / kWidth); 86 canvas->scale(size_.width() / kWidth, size_.width() / kWidth);
(...skipping 28 matching lines...) Expand all
91 canvas->save(); 115 canvas->save();
92 canvas->translate(kHeight / 2 + kBackIconOffset, kHeight / 2); 116 canvas->translate(kHeight / 2 + kBackIconOffset, kHeight / 2);
93 canvas->translate(-kBackIconHeight / 2, -kBackIconHeight / 2); 117 canvas->translate(-kBackIconHeight / 2, -kBackIconHeight / 2);
94 int icon_default_height = GetDefaultSizeOfVectorIcon(ui::kBackArrowIcon); 118 int icon_default_height = GetDefaultSizeOfVectorIcon(ui::kBackArrowIcon);
95 float icon_scale = kBackIconHeight / icon_default_height; 119 float icon_scale = kBackIconHeight / icon_default_height;
96 canvas->scale(icon_scale, icon_scale); 120 canvas->scale(icon_scale, icon_scale);
97 PaintVectorIcon(&gfx_canvas, ui::kBackArrowIcon, kForeground); 121 PaintVectorIcon(&gfx_canvas, ui::kBackArrowIcon, kForeground);
98 canvas->restore(); 122 canvas->restore();
99 123
100 // Site security state icon. 124 // Site security state icon.
101 // TODO(cjgrant): Plug in the correct icons based on security level. 125 // TODO(cjgrant): Plug in the correct icons based on security level.
tiborg 2017/05/09 15:00:35 Can this TODO go away now?
102 canvas->save(); 126 if (!gurl_.spec().empty()) {
103 canvas->translate( 127 canvas->save();
104 kBackButtonWidth + kSeparatorWidth + kSecurityFieldWidth / 2, 128 canvas->translate(
105 kHeight / 2); 129 kBackButtonWidth + kSeparatorWidth + kSecurityFieldWidth / 2,
106 canvas->translate(-kSecurityIconHeight / 2, -kSecurityIconHeight / 2); 130 kHeight / 2);
107 icon_default_height = GetDefaultSizeOfVectorIcon(ui::kBackArrowIcon); 131 canvas->translate(-kSecurityIconHeight / 2, -kSecurityIconHeight / 2);
108 icon_scale = kSecurityIconHeight / icon_default_height; 132 const gfx::VectorIcon& security_icon = getSecurityIcon(security_level_);
109 canvas->scale(icon_scale, icon_scale); 133 icon_default_height = GetDefaultSizeOfVectorIcon(security_icon);
110 PaintVectorIcon(&gfx_canvas, ui::kBackArrowIcon, kForeground); 134 icon_scale = kSecurityIconHeight / icon_default_height;
111 canvas->restore(); 135 canvas->scale(icon_scale, icon_scale);
136 PaintVectorIcon(&gfx_canvas, security_icon, kForeground);
mthiesse 2017/05/08 21:39:30 Why not just use the 4-arg variant like our other
cjgrant 2017/05/09 00:57:42 Reason: Since the UX spec gives all dimensions in
137 canvas->restore();
138 }
112 139
113 canvas->restore(); 140 canvas->restore();
114 141
115 // Draw text based on pixel sizes rather than meters, for correct font sizing. 142 // Draw text based on pixel sizes rather than meters, for correct font sizing.
116 int pixel_font_height = texture_size.height() * kFontHeight / kHeight; 143 int pixel_font_height = texture_size.height() * kFontHeight / kHeight;
117 int text_flags = gfx::Canvas::TEXT_ALIGN_LEFT; 144 int text_flags = gfx::Canvas::TEXT_ALIGN_LEFT;
118 float url_x = kBackButtonWidth + kSeparatorWidth + kSecurityFieldWidth; 145 float url_x = kBackButtonWidth + kSeparatorWidth + kSecurityFieldWidth;
119 float url_width = kWidth - url_x - kUrlRightMargin; 146 float url_width = kWidth - url_x - kUrlRightMargin;
120 gfx_canvas.DrawStringRectWithFlags( 147 gfx_canvas.DrawStringRectWithFlags(
121 base::UTF8ToUTF16(gurl_.spec()), GetDefaultFontList(pixel_font_height), 148 base::UTF8ToUTF16(gurl_.spec()), GetDefaultFontList(pixel_font_height),
122 SK_ColorBLACK, 149 SK_ColorBLACK,
123 gfx::Rect(ToPixels(url_x), 0, ToPixels(url_width), ToPixels(kHeight)), 150 gfx::Rect(ToPixels(url_x), 0, ToPixels(url_width), ToPixels(kHeight)),
124 text_flags); 151 text_flags);
125 } 152 }
126 153
127 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const { 154 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const {
128 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth); 155 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth);
129 } 156 }
130 157
131 gfx::SizeF UrlBarTexture::GetDrawnSize() const { 158 gfx::SizeF UrlBarTexture::GetDrawnSize() const {
132 return size_; 159 return size_;
133 } 160 }
134 161
135 } // namespace vr_shell 162 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698