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

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

Issue 2968143003: Toolbar: Report offline state through icon and verbose text. (Closed)
Patch Set: . Created 3 years, 5 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/color_scheme.h"
10 #include "chrome/browser/android/vr_shell/textures/render_text_wrapper.h" 10 #include "chrome/browser/android/vr_shell/textures/render_text_wrapper.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 case SecurityLevel::SECURE_WITH_POLICY_INSTALLED_CERT: // ChromeOS only. 50 case SecurityLevel::SECURE_WITH_POLICY_INSTALLED_CERT: // ChromeOS only.
51 return color_scheme.insecure; 51 return color_scheme.insecure;
52 case SecurityLevel::DANGEROUS: 52 case SecurityLevel::DANGEROUS:
53 return color_scheme.insecure; 53 return color_scheme.insecure;
54 default: 54 default:
55 NOTREACHED(); 55 NOTREACHED();
56 return color_scheme.insecure; 56 return color_scheme.insecure;
57 } 57 }
58 } 58 }
59 59
60 SkColor GetSecurityChipColor(SecurityLevel level,
61 bool offline_page,
62 const ColorScheme& color_scheme) {
63 if (offline_page)
64 return color_scheme.url_emphasized;
fgorski 2017/07/06 20:01:33 per our discussion I am concerned about putting th
cjgrant 2017/07/06 20:13:00 Noted. I'll follow up with Josh Carpenter (our UX
65 return GetSchemeColor(level, color_scheme);
66 }
67
60 void setEmphasis(vr_shell::RenderTextWrapper* render_text, 68 void setEmphasis(vr_shell::RenderTextWrapper* render_text,
61 bool emphasis, 69 bool emphasis,
62 const gfx::Range& range, 70 const gfx::Range& range,
63 const ColorScheme& color_scheme) { 71 const ColorScheme& color_scheme) {
64 SkColor color = 72 SkColor color =
65 emphasis ? color_scheme.url_emphasized : color_scheme.url_deemphasized; 73 emphasis ? color_scheme.url_emphasized : color_scheme.url_deemphasized;
66 if (range.IsValid()) { 74 if (range.IsValid()) {
67 render_text->ApplyColor(color, range); 75 render_text->ApplyColor(color, range);
68 } else { 76 } else {
69 render_text->SetColor(color); 77 render_text->SetColor(color);
70 } 78 }
71 } 79 }
72 80
73 gfx::PointF percentToMeters(const gfx::PointF& percent) { 81 gfx::PointF percentToMeters(const gfx::PointF& percent) {
74 return gfx::PointF(percent.x() * kWidth, percent.y() * kHeight); 82 return gfx::PointF(percent.x() * kWidth, percent.y() * kHeight);
75 } 83 }
76 84
77 } // namespace 85 } // namespace
78 86
79 UrlBarTexture::UrlBarTexture( 87 UrlBarTexture::UrlBarTexture(
80 bool web_vr, 88 bool web_vr,
81 const base::Callback<void(UiUnsupportedMode)>& failure_callback) 89 const base::Callback<void(UiUnsupportedMode)>& failure_callback)
82 : has_back_button_(!web_vr), 90 : has_back_button_(!web_vr),
83 has_security_chip_(false),
84 failure_callback_(failure_callback) {} 91 failure_callback_(failure_callback) {}
85 92
86 UrlBarTexture::~UrlBarTexture() = default; 93 UrlBarTexture::~UrlBarTexture() = default;
87 94
88 void UrlBarTexture::SetToolbarState(const ToolbarState& state) { 95 void UrlBarTexture::SetToolbarState(const ToolbarState& state) {
89 if (state_ == state) 96 if (state_ == state)
90 return; 97 return;
91 state_ = state; 98 state_ = state;
92 set_dirty(); 99 set_dirty();
93 } 100 }
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 : color_scheme().disabled); 219 : color_scheme().disabled);
213 canvas->restore(); 220 canvas->restore();
214 221
215 back_button_hit_region_.SetRect(left_edge, 0, left_edge + kBackButtonWidth, 222 back_button_hit_region_.SetRect(left_edge, 0, left_edge + kBackButtonWidth,
216 kHeight); 223 kHeight);
217 left_edge += kBackButtonWidth + kSeparatorWidth; 224 left_edge += kBackButtonWidth + kSeparatorWidth;
218 } 225 }
219 226
220 // Site security state icon. 227 // Site security state icon.
221 left_edge += kFieldSpacing; 228 left_edge += kFieldSpacing;
222 if (state_.security_level != security_state::NONE && 229 if ((state_.security_level != security_state::NONE || state_.offline_page) &&
223 state_.vector_icon != nullptr) { 230 state_.vector_icon != nullptr && state_.should_display_url) {
224 gfx::RectF icon_region(left_edge, kHeight / 2 - kSecurityIconSize / 2, 231 gfx::RectF icon_region(left_edge, kHeight / 2 - kSecurityIconSize / 2,
225 kSecurityIconSize, kSecurityIconSize); 232 kSecurityIconSize, kSecurityIconSize);
226 canvas->save(); 233 canvas->save();
227 canvas->translate(icon_region.x(), icon_region.y()); 234 canvas->translate(icon_region.x(), icon_region.y());
228 const gfx::VectorIcon& icon = *state_.vector_icon; 235 const gfx::VectorIcon& icon = *state_.vector_icon;
229 float icon_scale = kSecurityIconSize / GetDefaultSizeOfVectorIcon(icon); 236 float icon_scale = kSecurityIconSize / GetDefaultSizeOfVectorIcon(icon);
230 canvas->scale(icon_scale, icon_scale); 237 canvas->scale(icon_scale, icon_scale);
231 PaintVectorIcon(&gfx_canvas, icon, 238 PaintVectorIcon(&gfx_canvas, icon,
232 GetSchemeColor(state_.security_level, color_scheme())); 239 GetSecurityChipColor(state_.security_level,
240 state_.offline_page, color_scheme()));
233 canvas->restore(); 241 canvas->restore();
234 242
235 security_hit_region_ = icon_region; 243 security_hit_region_ = icon_region;
236 left_edge += kSecurityIconSize + kFieldSpacing; 244 left_edge += kSecurityIconSize + kFieldSpacing;
237 } 245 }
238 246
239 canvas->restore(); 247 canvas->restore();
240 248
241 // Draw security chip text (eg. "Not secure") next to the security icon. 249 // Draw security chip text (eg. "Not secure") next to the security icon.
242 if (has_security_chip_ && state_.should_display_url) { 250 if (state_.offline_page && state_.should_display_url) {
fgorski 2017/07/06 20:01:34 this will only kick in for offline pages if you &&
cjgrant 2017/07/06 20:13:00 Yes. We added chip support for "Secure" and "Not
243 float chip_max_width = kWidth - left_edge - kUrlRightMargin; 251 float chip_max_width = kWidth - left_edge - kUrlRightMargin;
244 gfx::Rect text_bounds(ToPixels(left_edge), 0, ToPixels(chip_max_width), 252 gfx::Rect text_bounds(ToPixels(left_edge), 0, ToPixels(chip_max_width),
245 ToPixels(kHeight)); 253 ToPixels(kHeight));
246 254
247 int pixel_font_height = texture_size.height() * kFontHeight / kHeight; 255 int pixel_font_height = texture_size.height() * kFontHeight / kHeight;
248 SkColor chip_color = GetSchemeColor(state_.security_level, color_scheme()); 256 SkColor chip_color = GetSecurityChipColor(
257 state_.security_level, state_.offline_page, color_scheme());
249 const base::string16& chip_text = state_.secure_verbose_text; 258 const base::string16& chip_text = state_.secure_verbose_text;
250 DCHECK(!chip_text.empty()); 259 DCHECK(!chip_text.empty());
251 260
252 gfx::FontList font_list; 261 gfx::FontList font_list;
253 if (!GetFontList(pixel_font_height, chip_text, &font_list)) 262 if (!GetFontList(pixel_font_height, chip_text, &font_list))
254 failure_callback_.Run(UiUnsupportedMode::kUnhandledCodePoint); 263 failure_callback_.Run(UiUnsupportedMode::kUnhandledCodePoint);
255 264
256 std::unique_ptr<gfx::RenderText> render_text( 265 std::unique_ptr<gfx::RenderText> render_text(
257 gfx::RenderText::CreateInstance()); 266 gfx::RenderText::CreateInstance());
258 render_text->SetFontList(font_list); 267 render_text->SetFontList(font_list);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 last_drawn_gurl_ = state_.gurl; 301 last_drawn_gurl_ = state_.gurl;
293 last_drawn_security_level_ = state_.security_level; 302 last_drawn_security_level_ = state_.security_level;
294 } 303 }
295 url_render_text_->Draw(&gfx_canvas); 304 url_render_text_->Draw(&gfx_canvas);
296 } 305 }
297 } 306 }
298 307
299 void UrlBarTexture::RenderUrl(const gfx::Size& texture_size, 308 void UrlBarTexture::RenderUrl(const gfx::Size& texture_size,
300 const gfx::Rect& bounds) { 309 const gfx::Rect& bounds) {
301 url::Parsed parsed; 310 url::Parsed parsed;
311
312 url_formatter::FormatUrlTypes format_types = url_formatter::kFormatUrlOmitAll;
313 if (state_.offline_page)
314 format_types |= url_formatter::kFormatUrlExperimentalOmitHTTPS;
315
302 const base::string16 text = url_formatter::FormatUrl( 316 const base::string16 text = url_formatter::FormatUrl(
303 state_.gurl, url_formatter::kFormatUrlOmitAll, net::UnescapeRule::NORMAL, 317 state_.gurl, format_types, net::UnescapeRule::NORMAL, &parsed, nullptr,
304 &parsed, nullptr, nullptr); 318 nullptr);
305 319
306 int pixel_font_height = texture_size.height() * kFontHeight / kHeight; 320 int pixel_font_height = texture_size.height() * kFontHeight / kHeight;
307 321
308 gfx::FontList font_list; 322 gfx::FontList font_list;
309 if (!GetFontList(pixel_font_height, text, &font_list)) 323 if (!GetFontList(pixel_font_height, text, &font_list))
310 failure_callback_.Run(UiUnsupportedMode::kUnhandledCodePoint); 324 failure_callback_.Run(UiUnsupportedMode::kUnhandledCodePoint);
311 325
312 std::unique_ptr<gfx::RenderText> render_text( 326 std::unique_ptr<gfx::RenderText> render_text(
313 gfx::RenderText::CreateInstance()); 327 gfx::RenderText::CreateInstance());
314 render_text->SetFontList(font_list); 328 render_text->SetFontList(font_list);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 424
411 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const { 425 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const {
412 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth); 426 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth);
413 } 427 }
414 428
415 gfx::SizeF UrlBarTexture::GetDrawnSize() const { 429 gfx::SizeF UrlBarTexture::GetDrawnSize() const {
416 return size_; 430 return size_;
417 } 431 }
418 432
419 } // namespace vr_shell 433 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698