OLD | NEW |
---|---|
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 case SecurityLevel::SECURE_WITH_POLICY_INSTALLED_CERT: // ChromeOS only. | 51 case SecurityLevel::SECURE_WITH_POLICY_INSTALLED_CERT: // ChromeOS only. |
52 return color_scheme.insecure; | 52 return color_scheme.insecure; |
53 case SecurityLevel::DANGEROUS: | 53 case SecurityLevel::DANGEROUS: |
54 return color_scheme.insecure; | 54 return color_scheme.insecure; |
55 default: | 55 default: |
56 NOTREACHED(); | 56 NOTREACHED(); |
57 return color_scheme.insecure; | 57 return color_scheme.insecure; |
58 } | 58 } |
59 } | 59 } |
60 | 60 |
61 SkColor GetSecurityChipColor(SecurityLevel level, | |
62 bool offline_page, | |
63 const ColorScheme& color_scheme) { | |
64 return offline_page ? color_scheme.url_emphasized | |
65 : GetSchemeColor(level, color_scheme); | |
66 } | |
67 | |
61 void setEmphasis(vr_shell::RenderTextWrapper* render_text, | 68 void setEmphasis(vr_shell::RenderTextWrapper* render_text, |
62 bool emphasis, | 69 bool emphasis, |
63 const gfx::Range& range, | 70 const gfx::Range& range, |
64 const ColorScheme& color_scheme) { | 71 const ColorScheme& color_scheme) { |
65 SkColor color = | 72 SkColor color = |
66 emphasis ? color_scheme.url_emphasized : color_scheme.url_deemphasized; | 73 emphasis ? color_scheme.url_emphasized : color_scheme.url_deemphasized; |
67 if (range.IsValid()) { | 74 if (range.IsValid()) { |
68 render_text->ApplyColor(color, range); | 75 render_text->ApplyColor(color, range); |
69 } else { | 76 } else { |
70 render_text->SetColor(color); | 77 render_text->SetColor(color); |
71 } | 78 } |
72 } | 79 } |
73 | 80 |
74 gfx::PointF percentToMeters(const gfx::PointF& percent) { | 81 gfx::PointF percentToMeters(const gfx::PointF& percent) { |
75 return gfx::PointF(percent.x() * kWidth, percent.y() * kHeight); | 82 return gfx::PointF(percent.x() * kWidth, percent.y() * kHeight); |
76 } | 83 } |
77 | 84 |
78 } // namespace | 85 } // namespace |
79 | 86 |
80 UrlBarTexture::UrlBarTexture( | 87 UrlBarTexture::UrlBarTexture( |
81 bool web_vr, | 88 bool web_vr, |
82 const base::Callback<void(UiUnsupportedMode)>& failure_callback) | 89 const base::Callback<void(UiUnsupportedMode)>& failure_callback) |
83 : has_back_button_(!web_vr), | 90 : has_back_button_(!web_vr), |
84 has_security_chip_(false), | |
85 failure_callback_(failure_callback) {} | 91 failure_callback_(failure_callback) {} |
86 | 92 |
87 UrlBarTexture::~UrlBarTexture() = default; | 93 UrlBarTexture::~UrlBarTexture() = default; |
88 | 94 |
89 void UrlBarTexture::SetToolbarState(const ToolbarState& state) { | 95 void UrlBarTexture::SetToolbarState(const ToolbarState& state) { |
90 if (state_ == state) | 96 if (state_ == state) |
91 return; | 97 return; |
92 state_ = state; | 98 state_ = state; |
93 set_dirty(); | 99 set_dirty(); |
94 } | 100 } |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 : color_scheme().disabled); | 219 : color_scheme().disabled); |
214 canvas->restore(); | 220 canvas->restore(); |
215 | 221 |
216 back_button_hit_region_.SetRect(left_edge, 0, left_edge + kBackButtonWidth, | 222 back_button_hit_region_.SetRect(left_edge, 0, left_edge + kBackButtonWidth, |
217 kHeight); | 223 kHeight); |
218 left_edge += kBackButtonWidth + kSeparatorWidth; | 224 left_edge += kBackButtonWidth + kSeparatorWidth; |
219 } | 225 } |
220 | 226 |
221 // Site security state icon. | 227 // Site security state icon. |
222 left_edge += kFieldSpacing; | 228 left_edge += kFieldSpacing; |
223 if (state_.security_level != security_state::NONE && | 229 if ((state_.security_level != security_state::NONE || state_.offline_page) && |
224 state_.vector_icon != nullptr) { | 230 state_.vector_icon != nullptr && state_.should_display_url) { |
225 gfx::RectF icon_region(left_edge, kHeight / 2 - kSecurityIconSize / 2, | 231 gfx::RectF icon_region(left_edge, kHeight / 2 - kSecurityIconSize / 2, |
226 kSecurityIconSize, kSecurityIconSize); | 232 kSecurityIconSize, kSecurityIconSize); |
227 canvas->save(); | 233 canvas->save(); |
228 canvas->translate(icon_region.x(), icon_region.y()); | 234 canvas->translate(icon_region.x(), icon_region.y()); |
229 const gfx::VectorIcon& icon = *state_.vector_icon; | 235 const gfx::VectorIcon& icon = *state_.vector_icon; |
230 float icon_scale = kSecurityIconSize / GetDefaultSizeOfVectorIcon(icon); | 236 float icon_scale = kSecurityIconSize / GetDefaultSizeOfVectorIcon(icon); |
231 canvas->scale(icon_scale, icon_scale); | 237 canvas->scale(icon_scale, icon_scale); |
232 PaintVectorIcon(&gfx_canvas, icon, | 238 PaintVectorIcon(&gfx_canvas, icon, |
233 GetSchemeColor(state_.security_level, color_scheme())); | 239 GetSecurityChipColor(state_.security_level, |
240 state_.offline_page, color_scheme())); | |
234 canvas->restore(); | 241 canvas->restore(); |
235 | 242 |
236 security_hit_region_ = icon_region; | 243 security_hit_region_ = icon_region; |
237 left_edge += kSecurityIconSize + kFieldSpacing; | 244 left_edge += kSecurityIconSize + kFieldSpacing; |
238 } | 245 } |
239 | 246 |
240 canvas->restore(); | 247 canvas->restore(); |
241 | 248 |
242 // Draw security chip text (eg. "Not secure") next to the security icon. | 249 // The security chip text consumes a significant percentage of URL bar text |
243 if (has_security_chip_ && state_.should_display_url) { | 250 // space, so they are currently disabled (see crbug.com/734206). The offline |
Peter Kasting
2017/07/10 20:22:00
Nit: they are -> it is
| |
251 // chip is an exception, and must be shown (see crbug.com/735770). | |
Peter Kasting
2017/07/10 20:22:00
Nit: chip -> state
| |
252 bool draw_security_chip = state_.offline_page; | |
253 | |
254 // Possibly draw security chip text (eg. "Not secure") next to the security | |
255 // icon. | |
256 if (draw_security_chip && state_.should_display_url) { | |
244 float chip_max_width = kWidth - left_edge - kUrlRightMargin; | 257 float chip_max_width = kWidth - left_edge - kUrlRightMargin; |
245 gfx::Rect text_bounds(ToPixels(left_edge), 0, ToPixels(chip_max_width), | 258 gfx::Rect text_bounds(ToPixels(left_edge), 0, ToPixels(chip_max_width), |
246 ToPixels(kHeight)); | 259 ToPixels(kHeight)); |
247 | 260 |
248 int pixel_font_height = texture_size.height() * kFontHeight / kHeight; | 261 int pixel_font_height = texture_size.height() * kFontHeight / kHeight; |
249 SkColor chip_color = GetSchemeColor(state_.security_level, color_scheme()); | 262 SkColor chip_color = GetSecurityChipColor( |
263 state_.security_level, state_.offline_page, color_scheme()); | |
250 const base::string16& chip_text = state_.secure_verbose_text; | 264 const base::string16& chip_text = state_.secure_verbose_text; |
251 DCHECK(!chip_text.empty()); | 265 DCHECK(!chip_text.empty()); |
252 | 266 |
253 gfx::FontList font_list; | 267 gfx::FontList font_list; |
254 if (!GetFontList(pixel_font_height, chip_text, &font_list)) | 268 if (!GetFontList(pixel_font_height, chip_text, &font_list)) |
255 failure_callback_.Run(UiUnsupportedMode::kUnhandledCodePoint); | 269 failure_callback_.Run(UiUnsupportedMode::kUnhandledCodePoint); |
256 | 270 |
257 std::unique_ptr<gfx::RenderText> render_text( | 271 std::unique_ptr<gfx::RenderText> render_text( |
258 gfx::RenderText::CreateInstance()); | 272 gfx::RenderText::CreateInstance()); |
259 render_text->SetFontList(font_list); | 273 render_text->SetFontList(font_list); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
293 last_drawn_gurl_ = state_.gurl; | 307 last_drawn_gurl_ = state_.gurl; |
294 last_drawn_security_level_ = state_.security_level; | 308 last_drawn_security_level_ = state_.security_level; |
295 } | 309 } |
296 url_render_text_->Draw(&gfx_canvas); | 310 url_render_text_->Draw(&gfx_canvas); |
297 } | 311 } |
298 } | 312 } |
299 | 313 |
300 void UrlBarTexture::RenderUrl(const gfx::Size& texture_size, | 314 void UrlBarTexture::RenderUrl(const gfx::Size& texture_size, |
301 const gfx::Rect& bounds) { | 315 const gfx::Rect& bounds) { |
302 url::Parsed parsed; | 316 url::Parsed parsed; |
317 | |
Peter Kasting
2017/07/10 20:22:00
Nit: Probably wouldn't add this blank line
| |
303 const base::string16 text = url_formatter::FormatUrl( | 318 const base::string16 text = url_formatter::FormatUrl( |
304 state_.gurl, url_formatter::kFormatUrlOmitAll, net::UnescapeRule::NORMAL, | 319 state_.gurl, url_formatter::kFormatUrlOmitAll, net::UnescapeRule::NORMAL, |
305 &parsed, nullptr, nullptr); | 320 &parsed, nullptr, nullptr); |
306 | 321 |
307 int pixel_font_height = texture_size.height() * kFontHeight / kHeight; | 322 int pixel_font_height = texture_size.height() * kFontHeight / kHeight; |
308 | 323 |
309 gfx::FontList font_list; | 324 gfx::FontList font_list; |
310 if (!GetFontList(pixel_font_height, text, &font_list)) | 325 if (!GetFontList(pixel_font_height, text, &font_list)) |
311 failure_callback_.Run(UiUnsupportedMode::kUnhandledCodePoint); | 326 failure_callback_.Run(UiUnsupportedMode::kUnhandledCodePoint); |
312 | 327 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
412 | 427 |
413 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const { | 428 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const { |
414 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth); | 429 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth); |
415 } | 430 } |
416 | 431 |
417 gfx::SizeF UrlBarTexture::GetDrawnSize() const { | 432 gfx::SizeF UrlBarTexture::GetDrawnSize() const { |
418 return size_; | 433 return size_; |
419 } | 434 } |
420 | 435 |
421 } // namespace vr_shell | 436 } // namespace vr_shell |
OLD | NEW |