| 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 "components/security_state/core/security_state.h" | 9 #include "components/security_state/core/security_state.h" | 
| 10 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" | 
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 77       return kWarningIconColor; | 77       return kWarningIconColor; | 
| 78   } | 78   } | 
| 79 } | 79 } | 
| 80 | 80 | 
| 81 gfx::PointF percentToMeters(const gfx::PointF& percent) { | 81 gfx::PointF percentToMeters(const gfx::PointF& percent) { | 
| 82   return gfx::PointF(percent.x() * kWidth, percent.y() * kHeight); | 82   return gfx::PointF(percent.x() * kWidth, percent.y() * kHeight); | 
| 83 } | 83 } | 
| 84 | 84 | 
| 85 }  // namespace | 85 }  // namespace | 
| 86 | 86 | 
| 87 UrlBarTexture::UrlBarTexture() : security_level_(SecurityLevel::DANGEROUS) {} | 87 UrlBarTexture::UrlBarTexture(const base::Callback<void()>& failure_callback) | 
|  | 88     : security_level_(SecurityLevel::DANGEROUS), | 
|  | 89       failure_callback_(failure_callback) {} | 
| 88 | 90 | 
| 89 UrlBarTexture::~UrlBarTexture() = default; | 91 UrlBarTexture::~UrlBarTexture() = default; | 
| 90 | 92 | 
| 91 void UrlBarTexture::SetURL(const GURL& gurl) { | 93 void UrlBarTexture::SetURL(const GURL& gurl) { | 
| 92   if (gurl_ != gurl) | 94   if (gurl_ != gurl) | 
| 93     set_dirty(); | 95     set_dirty(); | 
| 94   gurl_ = gurl; | 96   gurl_ = gurl; | 
| 95 } | 97 } | 
| 96 | 98 | 
| 97 void UrlBarTexture::SetSecurityLevel(int level) { | 99 void UrlBarTexture::SetSecurityLevel(int level) { | 
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 203 | 205 | 
| 204   if (!gurl_.is_empty()) { | 206   if (!gurl_.is_empty()) { | 
| 205     if (last_drawn_gurl_ != gurl_) { | 207     if (last_drawn_gurl_ != gurl_) { | 
| 206       // Draw text based on pixel sizes rather than meters, for correct font | 208       // Draw text based on pixel sizes rather than meters, for correct font | 
| 207       // sizing. | 209       // sizing. | 
| 208       int pixel_font_height = texture_size.height() * kFontHeight / kHeight; | 210       int pixel_font_height = texture_size.height() * kFontHeight / kHeight; | 
| 209       float url_x = kBackButtonWidth + kSeparatorWidth + kSecurityFieldWidth; | 211       float url_x = kBackButtonWidth + kSeparatorWidth + kSecurityFieldWidth; | 
| 210       float url_width = kWidth - url_x - kUrlRightMargin; | 212       float url_width = kWidth - url_x - kUrlRightMargin; | 
| 211       gfx::Rect text_bounds(ToPixels(url_x), 0, ToPixels(url_width), | 213       gfx::Rect text_bounds(ToPixels(url_x), 0, ToPixels(url_width), | 
| 212                             ToPixels(kHeight)); | 214                             ToPixels(kHeight)); | 
|  | 215       base::string16 text = base::UTF8ToUTF16(gurl_.spec()); | 
|  | 216       if (!CheckFontList(pixel_font_height, text)) | 
|  | 217         failure_callback_.Run(); | 
| 213       gurl_render_texts_ = PrepareDrawStringRect( | 218       gurl_render_texts_ = PrepareDrawStringRect( | 
| 214           base::UTF8ToUTF16(gurl_.spec()), | 219           text, GetDefaultFontList(pixel_font_height), SK_ColorBLACK, | 
| 215           GetDefaultFontList(pixel_font_height), SK_ColorBLACK, &text_bounds, | 220           &text_bounds, kTextAlignmentLeft, kWrappingBehaviorNoWrap); | 
| 216           kTextAlignmentLeft, kWrappingBehaviorNoWrap); |  | 
| 217       last_drawn_gurl_ = gurl_; | 221       last_drawn_gurl_ = gurl_; | 
| 218     } | 222     } | 
| 219     for (auto& render_text : gurl_render_texts_) | 223     for (auto& render_text : gurl_render_texts_) | 
| 220       render_text->Draw(&gfx_canvas); | 224       render_text->Draw(&gfx_canvas); | 
| 221   } | 225   } | 
| 222 } | 226 } | 
| 223 | 227 | 
| 224 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const { | 228 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const { | 
| 225   return gfx::Size(maximum_width, maximum_width * kHeight / kWidth); | 229   return gfx::Size(maximum_width, maximum_width * kHeight / kWidth); | 
| 226 } | 230 } | 
| 227 | 231 | 
| 228 gfx::SizeF UrlBarTexture::GetDrawnSize() const { | 232 gfx::SizeF UrlBarTexture::GetDrawnSize() const { | 
| 229   return size_; | 233   return size_; | 
| 230 } | 234 } | 
| 231 | 235 | 
| 232 }  // namespace vr_shell | 236 }  // namespace vr_shell | 
| OLD | NEW | 
|---|