| 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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 &parsed, nullptr, nullptr); | 245 &parsed, nullptr, nullptr); |
| 246 | 246 |
| 247 int pixel_font_height = texture_size.height() * kFontHeight / kHeight; | 247 int pixel_font_height = texture_size.height() * kFontHeight / kHeight; |
| 248 | 248 |
| 249 gfx::FontList font_list; | 249 gfx::FontList font_list; |
| 250 if (!GetFontList(pixel_font_height, text, &font_list)) | 250 if (!GetFontList(pixel_font_height, text, &font_list)) |
| 251 failure_callback_.Run(UiUnsupportedMode::kUnhandledCodePoint); | 251 failure_callback_.Run(UiUnsupportedMode::kUnhandledCodePoint); |
| 252 | 252 |
| 253 std::unique_ptr<gfx::RenderText> render_text( | 253 std::unique_ptr<gfx::RenderText> render_text( |
| 254 gfx::RenderText::CreateInstance()); | 254 gfx::RenderText::CreateInstance()); |
| 255 render_text->SetText(text); | |
| 256 render_text->SetFontList(font_list); | 255 render_text->SetFontList(font_list); |
| 257 render_text->SetColor(SK_ColorBLACK); | 256 render_text->SetColor(SK_ColorBLACK); |
| 258 render_text->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 257 render_text->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 259 render_text->SetDisplayRect(bounds); | |
| 260 render_text->SetElideBehavior(gfx::TRUNCATE); | 258 render_text->SetElideBehavior(gfx::TRUNCATE); |
| 261 | 259 |
| 260 base::string16 mandatory_prefix = text; |
| 261 int length = parsed.CountCharactersBefore(url::Parsed::PORT, false); |
| 262 if (length > 0) |
| 263 mandatory_prefix = text.substr(0, length); |
| 264 gfx::Rect expanded_bounds = bounds; |
| 265 expanded_bounds.set_width(2 * bounds.width()); |
| 266 render_text->SetDisplayRect(expanded_bounds); |
| 267 render_text->SetText(mandatory_prefix); |
| 268 |
| 269 if (render_text->GetStringSize().width() > bounds.width()) { |
| 270 failure_callback_.Run(UiUnsupportedMode::kCouldNotElideURL); |
| 271 } |
| 272 |
| 273 render_text->SetText(text); |
| 274 render_text->SetDisplayRect(bounds); |
| 262 vr_shell::RenderTextWrapper vr_render_text(render_text.get()); | 275 vr_shell::RenderTextWrapper vr_render_text(render_text.get()); |
| 263 ApplyUrlStyling(text, parsed, security_level_, &vr_render_text); | 276 ApplyUrlStyling(text, parsed, security_level_, &vr_render_text); |
| 264 | 277 |
| 265 url_render_text_ = std::move(render_text); | 278 url_render_text_ = std::move(render_text); |
| 266 } | 279 } |
| 267 | 280 |
| 268 // This method replicates behavior in OmniboxView::UpdateTextStyle(), and | 281 // This method replicates behavior in OmniboxView::UpdateTextStyle(), and |
| 269 // attempts to maintain similar code structure. | 282 // attempts to maintain similar code structure. |
| 270 void UrlBarTexture::ApplyUrlStyling( | 283 void UrlBarTexture::ApplyUrlStyling( |
| 271 const base::string16& formatted_url, | 284 const base::string16& formatted_url, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 | 344 |
| 332 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const { | 345 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const { |
| 333 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth); | 346 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth); |
| 334 } | 347 } |
| 335 | 348 |
| 336 gfx::SizeF UrlBarTexture::GetDrawnSize() const { | 349 gfx::SizeF UrlBarTexture::GetDrawnSize() const { |
| 337 return size_; | 350 return size_; |
| 338 } | 351 } |
| 339 | 352 |
| 340 } // namespace vr_shell | 353 } // namespace vr_shell |
| OLD | NEW |