| 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/textures/render_text_wrapper.h" | 9 #include "chrome/browser/android/vr_shell/textures/render_text_wrapper.h" |
| 10 #include "components/url_formatter/url_formatter.h" | 10 #include "components/url_formatter/url_formatter.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 render_text->SetColor(color); | 95 render_text->SetColor(color); |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 | 98 |
| 99 gfx::PointF percentToMeters(const gfx::PointF& percent) { | 99 gfx::PointF percentToMeters(const gfx::PointF& percent) { |
| 100 return gfx::PointF(percent.x() * kWidth, percent.y() * kHeight); | 100 return gfx::PointF(percent.x() * kWidth, percent.y() * kHeight); |
| 101 } | 101 } |
| 102 | 102 |
| 103 } // namespace | 103 } // namespace |
| 104 | 104 |
| 105 UrlBarTexture::UrlBarTexture() : security_level_(SecurityLevel::DANGEROUS) {} | 105 UrlBarTexture::UrlBarTexture( |
| 106 const base::Callback<void(UiUnsupportedMode)>& failure_callback) |
| 107 : security_level_(SecurityLevel::DANGEROUS), |
| 108 failure_callback_(failure_callback) {} |
| 106 | 109 |
| 107 UrlBarTexture::~UrlBarTexture() = default; | 110 UrlBarTexture::~UrlBarTexture() = default; |
| 108 | 111 |
| 109 void UrlBarTexture::SetURL(const GURL& gurl) { | 112 void UrlBarTexture::SetURL(const GURL& gurl) { |
| 110 if (gurl_ != gurl) | 113 if (gurl_ != gurl) |
| 111 set_dirty(); | 114 set_dirty(); |
| 112 gurl_ = gurl; | 115 gurl_ = gurl; |
| 113 } | 116 } |
| 114 | 117 |
| 115 void UrlBarTexture::SetSecurityLevel(SecurityLevel level) { | 118 void UrlBarTexture::SetSecurityLevel(SecurityLevel level) { |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 } | 238 } |
| 236 | 239 |
| 237 void UrlBarTexture::RenderUrl(const gfx::Size& texture_size, | 240 void UrlBarTexture::RenderUrl(const gfx::Size& texture_size, |
| 238 const gfx::Rect& bounds) { | 241 const gfx::Rect& bounds) { |
| 239 url::Parsed parsed; | 242 url::Parsed parsed; |
| 240 const base::string16 text = url_formatter::FormatUrl( | 243 const base::string16 text = url_formatter::FormatUrl( |
| 241 gurl_, url_formatter::kFormatUrlOmitAll, net::UnescapeRule::NORMAL, | 244 gurl_, url_formatter::kFormatUrlOmitAll, net::UnescapeRule::NORMAL, |
| 242 &parsed, nullptr, nullptr); | 245 &parsed, nullptr, nullptr); |
| 243 | 246 |
| 244 int pixel_font_height = texture_size.height() * kFontHeight / kHeight; | 247 int pixel_font_height = texture_size.height() * kFontHeight / kHeight; |
| 245 auto font_list = GetFontList(pixel_font_height, text); | 248 |
| 249 gfx::FontList font_list; |
| 250 if (!GetFontList(pixel_font_height, text, &font_list)) |
| 251 failure_callback_.Run(UiUnsupportedMode::kUnhandledCodePoint); |
| 246 | 252 |
| 247 std::unique_ptr<gfx::RenderText> render_text( | 253 std::unique_ptr<gfx::RenderText> render_text( |
| 248 gfx::RenderText::CreateInstance()); | 254 gfx::RenderText::CreateInstance()); |
| 249 render_text->SetText(text); | 255 render_text->SetText(text); |
| 250 render_text->SetFontList(font_list); | 256 render_text->SetFontList(font_list); |
| 251 render_text->SetColor(SK_ColorBLACK); | 257 render_text->SetColor(SK_ColorBLACK); |
| 252 render_text->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 258 render_text->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 253 render_text->SetDisplayRect(bounds); | 259 render_text->SetDisplayRect(bounds); |
| 254 render_text->SetElideBehavior(gfx::TRUNCATE); | 260 render_text->SetElideBehavior(gfx::TRUNCATE); |
| 255 | 261 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 | 331 |
| 326 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const { | 332 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const { |
| 327 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth); | 333 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth); |
| 328 } | 334 } |
| 329 | 335 |
| 330 gfx::SizeF UrlBarTexture::GetDrawnSize() const { | 336 gfx::SizeF UrlBarTexture::GetDrawnSize() const { |
| 331 return size_; | 337 return size_; |
| 332 } | 338 } |
| 333 | 339 |
| 334 } // namespace vr_shell | 340 } // namespace vr_shell |
| OLD | NEW |