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

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

Issue 2902043005: [vr] Add incognito coloring (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/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/browser/android/vr_shell/color_scheme.h"
9 #include "chrome/browser/android/vr_shell/textures/render_text_wrapper.h" 10 #include "chrome/browser/android/vr_shell/textures/render_text_wrapper.h"
10 #include "components/url_formatter/url_formatter.h" 11 #include "components/url_formatter/url_formatter.h"
11 #include "ui/gfx/canvas.h" 12 #include "ui/gfx/canvas.h"
12 #include "ui/gfx/color_palette.h"
13 #include "ui/gfx/font.h" 13 #include "ui/gfx/font.h"
14 #include "ui/gfx/font_list.h" 14 #include "ui/gfx/font_list.h"
15 #include "ui/gfx/geometry/point_f.h" 15 #include "ui/gfx/geometry/point_f.h"
16 #include "ui/gfx/geometry/rect.h" 16 #include "ui/gfx/geometry/rect.h"
17 #include "ui/gfx/geometry/rect_f.h" 17 #include "ui/gfx/geometry/rect_f.h"
18 #include "ui/gfx/paint_vector_icon.h" 18 #include "ui/gfx/paint_vector_icon.h"
19 #include "ui/gfx/render_text.h" 19 #include "ui/gfx/render_text.h"
20 #include "ui/gfx/vector_icon_types.h" 20 #include "ui/gfx/vector_icon_types.h"
21 #include "ui/vector_icons/vector_icons.h" 21 #include "ui/vector_icons/vector_icons.h"
22 22
23 namespace vr_shell { 23 namespace vr_shell {
24 24
25 namespace { 25 namespace {
26 26
27 static constexpr SkColor kBackground = 0x66EBEBEB;
28 static constexpr SkColor kBackgroundHover = 0xFFEAEAEA;
29 static constexpr SkColor kBackgroundDown = 0xFFFAFAFA;
30 static constexpr SkColor kForeground = 0xFF333333;
31 static constexpr SkColor kSeparatorColor = 0x33000000;
32
33 static constexpr SkColor kUrlTextColor = 0xFF000000;
34 static constexpr SkColor kUrlDeemphasizedTextColor = 0xFF5A5A5A;
35 static const SkColor kSecureColor = gfx::kGoogleGreen700;
36 static const SkColor kWarningColor = gfx::kGoogleRed700;
37
38 static constexpr float kWidth = 0.672; 27 static constexpr float kWidth = 0.672;
39 static constexpr float kHeight = 0.088; 28 static constexpr float kHeight = 0.088;
40 static constexpr float kFontHeight = 0.027; 29 static constexpr float kFontHeight = 0.027;
41 static constexpr float kBackButtonWidth = kHeight; 30 static constexpr float kBackButtonWidth = kHeight;
42 static constexpr float kBackIconHeight = 0.0375; 31 static constexpr float kBackIconHeight = 0.0375;
43 static constexpr float kBackIconOffset = 0.005; 32 static constexpr float kBackIconOffset = 0.005;
44 static constexpr float kSecurityFieldWidth = 0.06; 33 static constexpr float kSecurityFieldWidth = 0.06;
45 static constexpr float kSecurityIconHeight = 0.03; 34 static constexpr float kSecurityIconHeight = 0.03;
46 static constexpr float kUrlRightMargin = 0.02; 35 static constexpr float kUrlRightMargin = 0.02;
47 static constexpr float kSeparatorWidth = 0.002; 36 static constexpr float kSeparatorWidth = 0.002;
(...skipping 12 matching lines...) Expand all
60 case SecurityLevel::DANGEROUS: 49 case SecurityLevel::DANGEROUS:
61 return ui::kWarningIcon; 50 return ui::kWarningIcon;
62 case SecurityLevel::SECURE_WITH_POLICY_INSTALLED_CERT: // ChromeOS only. 51 case SecurityLevel::SECURE_WITH_POLICY_INSTALLED_CERT: // ChromeOS only.
63 default: 52 default:
64 NOTREACHED(); 53 NOTREACHED();
65 return ui::kWarningIcon; 54 return ui::kWarningIcon;
66 } 55 }
67 } 56 }
68 57
69 // See LocationBarView::GetSecureTextColor(). 58 // See LocationBarView::GetSecureTextColor().
70 SkColor getSchemeColor(SecurityLevel level) { 59 SkColor getSchemeColor(SecurityLevel level, const ColorScheme& color_scheme) {
71 switch (level) { 60 switch (level) {
72 case SecurityLevel::NONE: 61 case SecurityLevel::NONE:
73 case SecurityLevel::HTTP_SHOW_WARNING: 62 case SecurityLevel::HTTP_SHOW_WARNING:
74 case SecurityLevel::SECURITY_WARNING: 63 case SecurityLevel::SECURITY_WARNING:
75 return kUrlDeemphasizedTextColor; 64 return color_scheme.deemphasized;
76 case SecurityLevel::SECURE: 65 case SecurityLevel::SECURE:
77 case SecurityLevel::EV_SECURE: 66 case SecurityLevel::EV_SECURE:
78 return kSecureColor; 67 return color_scheme.secure;
79 case SecurityLevel::DANGEROUS: 68 case SecurityLevel::DANGEROUS:
80 return kWarningColor; 69 return color_scheme.insecure;
81 case SecurityLevel::SECURE_WITH_POLICY_INSTALLED_CERT: // ChromeOS only. 70 case SecurityLevel::SECURE_WITH_POLICY_INSTALLED_CERT: // ChromeOS only.
82 default: 71 default:
83 NOTREACHED(); 72 NOTREACHED();
84 return kWarningColor; 73 return color_scheme.warning;
85 } 74 }
86 } 75 }
87 76
88 void setEmphasis(vr_shell::RenderTextWrapper* render_text, 77 void setEmphasis(vr_shell::RenderTextWrapper* render_text,
89 bool emphasis, 78 bool emphasis,
90 const gfx::Range& range) { 79 const gfx::Range& range,
91 SkColor color = emphasis ? kUrlTextColor : kUrlDeemphasizedTextColor; 80 const ColorScheme& color_scheme) {
81 SkColor color =
82 emphasis ? color_scheme.emphasized : color_scheme.deemphasized;
92 if (range.IsValid()) { 83 if (range.IsValid()) {
93 render_text->ApplyColor(color, range); 84 render_text->ApplyColor(color, range);
94 } else { 85 } else {
95 render_text->SetColor(color); 86 render_text->SetColor(color);
96 } 87 }
97 } 88 }
98 89
99 gfx::PointF percentToMeters(const gfx::PointF& percent) { 90 gfx::PointF percentToMeters(const gfx::PointF& percent) {
100 return gfx::PointF(percent.x() * kWidth, percent.y() * kHeight); 91 return gfx::PointF(percent.x() * kWidth, percent.y() * kHeight);
101 } 92 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 set_dirty(); 142 set_dirty();
152 hovered_ = hovered; 143 hovered_ = hovered;
153 } 144 }
154 145
155 void UrlBarTexture::SetPressed(bool pressed) { 146 void UrlBarTexture::SetPressed(bool pressed) {
156 if (pressed_ != pressed) 147 if (pressed_ != pressed)
157 set_dirty(); 148 set_dirty();
158 pressed_ = pressed; 149 pressed_ = pressed;
159 } 150 }
160 151
152 void UrlBarTexture::OnSetMode() {
153 set_dirty();
154 }
155
156 const ColorScheme& UrlBarTexture::color_scheme() const {
157 return ColorScheme::GetColorScheme(mode());
158 }
159
161 void UrlBarTexture::Draw(SkCanvas* canvas, const gfx::Size& texture_size) { 160 void UrlBarTexture::Draw(SkCanvas* canvas, const gfx::Size& texture_size) {
162 size_.set_height(texture_size.height()); 161 size_.set_height(texture_size.height());
163 size_.set_width(texture_size.width()); 162 size_.set_width(texture_size.width());
164 163
165 canvas->save(); 164 canvas->save();
166 canvas->scale(size_.width() / kWidth, size_.width() / kWidth); 165 canvas->scale(size_.width() / kWidth, size_.width() / kWidth);
167 166
168 // Make a gfx canvas to support utility drawing methods. 167 // Make a gfx canvas to support utility drawing methods.
169 cc::SkiaPaintCanvas paint_canvas(canvas); 168 cc::SkiaPaintCanvas paint_canvas(canvas);
170 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f); 169 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f);
171 170
172 // Back button area. 171 // Back button area.
173 SkRRect round_rect; 172 SkRRect round_rect;
174 SkVector rounded_corner = {kHeight / 2, kHeight / 2}; 173 SkVector rounded_corner = {kHeight / 2, kHeight / 2};
175 SkVector left_corners[4] = {rounded_corner, {0, 0}, {0, 0}, rounded_corner}; 174 SkVector left_corners[4] = {rounded_corner, {0, 0}, {0, 0}, rounded_corner};
176 round_rect.setRectRadii({0, 0, kHeight, kHeight}, left_corners); 175 round_rect.setRectRadii({0, 0, kHeight, kHeight}, left_corners);
177 SkColor color = hovered_ ? kBackgroundHover : kBackground; 176 SkColor color =
178 color = pressed_ ? kBackgroundDown : color; 177 hovered_ ? color_scheme().background_hover : color_scheme().background;
178 color = pressed_ ? color_scheme().background_down : color;
179 SkPaint paint; 179 SkPaint paint;
180 paint.setColor(color); 180 paint.setColor(color);
181 canvas->drawRRect(round_rect, paint); 181 canvas->drawRRect(round_rect, paint);
182 182
183 // URL area. 183 // URL area.
184 paint.setColor(kBackground); 184 paint.setColor(color_scheme().background);
185 SkVector right_corners[4] = {{0, 0}, rounded_corner, rounded_corner, {0, 0}}; 185 SkVector right_corners[4] = {{0, 0}, rounded_corner, rounded_corner, {0, 0}};
186 round_rect.setRectRadii({kHeight, 0, kWidth, kHeight}, right_corners); 186 round_rect.setRectRadii({kHeight, 0, kWidth, kHeight}, right_corners);
187 canvas->drawRRect(round_rect, paint); 187 canvas->drawRRect(round_rect, paint);
188 188
189 // Back button / URL separator vertical line. 189 // Back button / URL separator vertical line.
190 paint.setColor(kSeparatorColor); 190 paint.setColor(color_scheme().separator);
191 canvas->drawRect(SkRect::MakeXYWH(kHeight, 0, kSeparatorWidth, kHeight), 191 canvas->drawRect(SkRect::MakeXYWH(kHeight, 0, kSeparatorWidth, kHeight),
192 paint); 192 paint);
193 193
194 // Back button icon. 194 // Back button icon.
195 canvas->save(); 195 canvas->save();
196 canvas->translate(kHeight / 2 + kBackIconOffset, kHeight / 2); 196 canvas->translate(kHeight / 2 + kBackIconOffset, kHeight / 2);
197 canvas->translate(-kBackIconHeight / 2, -kBackIconHeight / 2); 197 canvas->translate(-kBackIconHeight / 2, -kBackIconHeight / 2);
198 int icon_default_height = GetDefaultSizeOfVectorIcon(ui::kBackArrowIcon); 198 int icon_default_height = GetDefaultSizeOfVectorIcon(ui::kBackArrowIcon);
199 float icon_scale = kBackIconHeight / icon_default_height; 199 float icon_scale = kBackIconHeight / icon_default_height;
200 canvas->scale(icon_scale, icon_scale); 200 canvas->scale(icon_scale, icon_scale);
201 PaintVectorIcon(&gfx_canvas, ui::kBackArrowIcon, kForeground); 201 PaintVectorIcon(&gfx_canvas, ui::kBackArrowIcon, color_scheme().foreground);
202 canvas->restore(); 202 canvas->restore();
203 203
204 // Site security state icon. 204 // Site security state icon.
205 if (!gurl_.is_empty()) { 205 if (!gurl_.is_empty()) {
206 canvas->save(); 206 canvas->save();
207 canvas->translate( 207 canvas->translate(
208 kBackButtonWidth + kSeparatorWidth + kSecurityFieldWidth / 2, 208 kBackButtonWidth + kSeparatorWidth + kSecurityFieldWidth / 2,
209 kHeight / 2); 209 kHeight / 2);
210 canvas->translate(-kSecurityIconHeight / 2, -kSecurityIconHeight / 2); 210 canvas->translate(-kSecurityIconHeight / 2, -kSecurityIconHeight / 2);
211 const gfx::VectorIcon& icon = getSecurityIcon(security_level_); 211 const gfx::VectorIcon& icon = getSecurityIcon(security_level_);
212 icon_default_height = GetDefaultSizeOfVectorIcon(icon); 212 icon_default_height = GetDefaultSizeOfVectorIcon(icon);
213 icon_scale = kSecurityIconHeight / icon_default_height; 213 icon_scale = kSecurityIconHeight / icon_default_height;
214 SkColor icon_color = getSchemeColor(security_level_); 214 SkColor icon_color = getSchemeColor(security_level_, color_scheme());
215 canvas->scale(icon_scale, icon_scale); 215 canvas->scale(icon_scale, icon_scale);
216 PaintVectorIcon(&gfx_canvas, icon, icon_color); 216 PaintVectorIcon(&gfx_canvas, icon, icon_color);
217 canvas->restore(); 217 canvas->restore();
218 } 218 }
219 219
220 canvas->restore(); 220 canvas->restore();
221 221
222 if (!gurl_.is_empty()) { 222 if (!gurl_.is_empty()) {
223 if (last_drawn_gurl_ != gurl_ || 223 if (last_drawn_gurl_ != gurl_ ||
224 last_drawn_security_level_ != security_level_) { 224 last_drawn_security_level_ != security_level_) {
(...skipping 22 matching lines...) Expand all
247 std::unique_ptr<gfx::RenderText> render_text( 247 std::unique_ptr<gfx::RenderText> render_text(
248 gfx::RenderText::CreateInstance()); 248 gfx::RenderText::CreateInstance());
249 render_text->SetText(text); 249 render_text->SetText(text);
250 render_text->SetFontList(font_list); 250 render_text->SetFontList(font_list);
251 render_text->SetColor(SK_ColorBLACK); 251 render_text->SetColor(SK_ColorBLACK);
252 render_text->SetHorizontalAlignment(gfx::ALIGN_LEFT); 252 render_text->SetHorizontalAlignment(gfx::ALIGN_LEFT);
253 render_text->SetDisplayRect(bounds); 253 render_text->SetDisplayRect(bounds);
254 render_text->SetElideBehavior(gfx::TRUNCATE); 254 render_text->SetElideBehavior(gfx::TRUNCATE);
255 255
256 vr_shell::RenderTextWrapper vr_render_text(render_text.get()); 256 vr_shell::RenderTextWrapper vr_render_text(render_text.get());
257 ApplyUrlStyling(text, parsed, security_level_, &vr_render_text); 257 ApplyUrlStyling(text, parsed, security_level_, &vr_render_text,
258 color_scheme());
258 259
259 url_render_text_ = std::move(render_text); 260 url_render_text_ = std::move(render_text);
260 } 261 }
261 262
262 // This method replicates behavior in OmniboxView::UpdateTextStyle(), and 263 // This method replicates behavior in OmniboxView::UpdateTextStyle(), and
263 // attempts to maintain similar code structure. 264 // attempts to maintain similar code structure.
264 void UrlBarTexture::ApplyUrlStyling( 265 void UrlBarTexture::ApplyUrlStyling(
265 const base::string16& formatted_url, 266 const base::string16& formatted_url,
266 const url::Parsed& parsed, 267 const url::Parsed& parsed,
267 const security_state::SecurityLevel security_level, 268 const security_state::SecurityLevel security_level,
268 vr_shell::RenderTextWrapper* render_text) { 269 vr_shell::RenderTextWrapper* render_text,
270 const ColorScheme& color_scheme) {
269 const url::Component& scheme = parsed.scheme; 271 const url::Component& scheme = parsed.scheme;
270 const url::Component& host = parsed.host; 272 const url::Component& host = parsed.host;
271 273
272 enum DeemphasizeComponents { 274 enum DeemphasizeComponents {
273 EVERYTHING, 275 EVERYTHING,
274 ALL_BUT_SCHEME, 276 ALL_BUT_SCHEME,
275 ALL_BUT_HOST, 277 ALL_BUT_HOST,
276 NOTHING, 278 NOTHING,
277 } deemphasize = NOTHING; 279 } deemphasize = NOTHING;
278 280
279 const base::string16 url_scheme = 281 const base::string16 url_scheme =
280 formatted_url.substr(scheme.begin, scheme.len); 282 formatted_url.substr(scheme.begin, scheme.len);
281 283
282 // Data URLs are rarely human-readable and can be used for spoofing, so draw 284 // Data URLs are rarely human-readable and can be used for spoofing, so draw
283 // attention to the scheme to emphasize "this is just a bunch of data". For 285 // attention to the scheme to emphasize "this is just a bunch of data". For
284 // normal URLs, the host is the best proxy for "identity". 286 // normal URLs, the host is the best proxy for "identity".
285 // TODO(cjgrant): Handle extensions, if required, for desktop. 287 // TODO(cjgrant): Handle extensions, if required, for desktop.
286 if (url_scheme == base::UTF8ToUTF16(url::kDataScheme)) 288 if (url_scheme == base::UTF8ToUTF16(url::kDataScheme))
287 deemphasize = ALL_BUT_SCHEME; 289 deemphasize = ALL_BUT_SCHEME;
288 else if (host.is_nonempty()) 290 else if (host.is_nonempty())
289 deemphasize = ALL_BUT_HOST; 291 deemphasize = ALL_BUT_HOST;
290 292
291 gfx::Range scheme_range = scheme.is_nonempty() 293 gfx::Range scheme_range = scheme.is_nonempty()
292 ? gfx::Range(scheme.begin, scheme.end()) 294 ? gfx::Range(scheme.begin, scheme.end())
293 : gfx::Range::InvalidRange(); 295 : gfx::Range::InvalidRange();
294 switch (deemphasize) { 296 switch (deemphasize) {
295 case EVERYTHING: 297 case EVERYTHING:
296 setEmphasis(render_text, false, gfx::Range::InvalidRange()); 298 setEmphasis(render_text, false, gfx::Range::InvalidRange(), color_scheme);
297 break; 299 break;
298 case NOTHING: 300 case NOTHING:
299 setEmphasis(render_text, true, gfx::Range::InvalidRange()); 301 setEmphasis(render_text, true, gfx::Range::InvalidRange(), color_scheme);
300 break; 302 break;
301 case ALL_BUT_SCHEME: 303 case ALL_BUT_SCHEME:
302 DCHECK(scheme_range.IsValid()); 304 DCHECK(scheme_range.IsValid());
303 setEmphasis(render_text, false, gfx::Range::InvalidRange()); 305 setEmphasis(render_text, false, gfx::Range::InvalidRange(), color_scheme);
304 setEmphasis(render_text, true, scheme_range); 306 setEmphasis(render_text, true, scheme_range, color_scheme);
305 break; 307 break;
306 case ALL_BUT_HOST: 308 case ALL_BUT_HOST:
307 setEmphasis(render_text, false, gfx::Range::InvalidRange()); 309 setEmphasis(render_text, false, gfx::Range::InvalidRange(), color_scheme);
308 setEmphasis(render_text, true, gfx::Range(host.begin, host.end())); 310 setEmphasis(render_text, true, gfx::Range(host.begin, host.end()),
311 color_scheme);
309 break; 312 break;
310 } 313 }
311 314
312 // Only SECURE and DANGEROUS levels (pages served over HTTPS or flagged by 315 // Only SECURE and DANGEROUS levels (pages served over HTTPS or flagged by
313 // SafeBrowsing) get a special scheme color treatment. If the security level 316 // SafeBrowsing) get a special scheme color treatment. If the security level
314 // is NONE or HTTP_SHOW_WARNING, we do not override the text style previously 317 // is NONE or HTTP_SHOW_WARNING, we do not override the text style previously
315 // applied to the scheme text range by setEmphasis(). 318 // applied to the scheme text range by setEmphasis().
316 if (scheme_range.IsValid() && security_level != security_state::NONE && 319 if (scheme_range.IsValid() && security_level != security_state::NONE &&
317 security_level != security_state::HTTP_SHOW_WARNING) { 320 security_level != security_state::HTTP_SHOW_WARNING) {
318 render_text->ApplyColor(getSchemeColor(security_level), scheme_range); 321 render_text->ApplyColor(getSchemeColor(security_level, color_scheme),
322 scheme_range);
319 if (security_level == SecurityLevel::DANGEROUS) { 323 if (security_level == SecurityLevel::DANGEROUS) {
320 render_text->ApplyStyle(gfx::TextStyle::DIAGONAL_STRIKE, true, 324 render_text->ApplyStyle(gfx::TextStyle::DIAGONAL_STRIKE, true,
321 scheme_range); 325 scheme_range);
322 } 326 }
323 } 327 }
324 } 328 }
325 329
326 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const { 330 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const {
327 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth); 331 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth);
328 } 332 }
329 333
330 gfx::SizeF UrlBarTexture::GetDrawnSize() const { 334 gfx::SizeF UrlBarTexture::GetDrawnSize() const {
331 return size_; 335 return size_;
332 } 336 }
333 337
334 } // namespace vr_shell 338 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698