| 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/i18n/rtl.h" | |
| 8 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 9 #include "cc/paint/skia_paint_canvas.h" | 8 #include "cc/paint/skia_paint_canvas.h" |
| 10 #include "chrome/browser/android/vr_shell/color_scheme.h" | 9 #include "chrome/browser/android/vr_shell/color_scheme.h" |
| 11 #include "chrome/browser/android/vr_shell/textures/render_text_wrapper.h" | 10 #include "chrome/browser/android/vr_shell/textures/render_text_wrapper.h" |
| 12 #include "components/strings/grit/components_strings.h" | 11 #include "components/strings/grit/components_strings.h" |
| 13 #include "components/toolbar/vector_icons.h" | 12 #include "components/toolbar/vector_icons.h" |
| 14 #include "components/url_formatter/url_formatter.h" | 13 #include "components/url_formatter/url_formatter.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
| 16 #include "ui/gfx/canvas.h" | 15 #include "ui/gfx/canvas.h" |
| 17 #include "ui/gfx/font.h" | 16 #include "ui/gfx/font.h" |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 } | 345 } |
| 347 } | 346 } |
| 348 | 347 |
| 349 void UrlBarTexture::RenderUrl(const gfx::Size& texture_size, | 348 void UrlBarTexture::RenderUrl(const gfx::Size& texture_size, |
| 350 const gfx::Rect& bounds) { | 349 const gfx::Rect& bounds) { |
| 351 url::Parsed parsed; | 350 url::Parsed parsed; |
| 352 const base::string16 text = url_formatter::FormatUrl( | 351 const base::string16 text = url_formatter::FormatUrl( |
| 353 gurl_, url_formatter::kFormatUrlOmitAll, net::UnescapeRule::NORMAL, | 352 gurl_, url_formatter::kFormatUrlOmitAll, net::UnescapeRule::NORMAL, |
| 354 &parsed, nullptr, nullptr); | 353 &parsed, nullptr, nullptr); |
| 355 | 354 |
| 356 if (base::i18n::StringContainsStrongRTLChars(text)) | |
| 357 failure_callback_.Run(UiUnsupportedMode::kURLWithStrongRTLChars); | |
| 358 | |
| 359 int pixel_font_height = texture_size.height() * kFontHeight / kHeight; | 355 int pixel_font_height = texture_size.height() * kFontHeight / kHeight; |
| 360 | 356 |
| 361 gfx::FontList font_list; | 357 gfx::FontList font_list; |
| 362 if (!GetFontList(pixel_font_height, text, &font_list)) | 358 if (!GetFontList(pixel_font_height, text, &font_list)) |
| 363 failure_callback_.Run(UiUnsupportedMode::kUnhandledCodePoint); | 359 failure_callback_.Run(UiUnsupportedMode::kUnhandledCodePoint); |
| 364 | 360 |
| 365 std::unique_ptr<gfx::RenderText> render_text( | 361 std::unique_ptr<gfx::RenderText> render_text( |
| 366 gfx::RenderText::CreateInstance()); | 362 gfx::RenderText::CreateInstance()); |
| 367 render_text->SetFontList(font_list); | 363 render_text->SetFontList(font_list); |
| 368 render_text->SetColor(SK_ColorBLACK); | 364 render_text->SetColor(SK_ColorBLACK); |
| 369 render_text->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 365 render_text->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 370 render_text->SetElideBehavior(gfx::ELIDE_TAIL); | 366 render_text->SetElideBehavior(gfx::ELIDE_TAIL); |
| 367 render_text->SetDirectionalityMode(gfx::DIRECTIONALITY_FORCE_LTR); |
| 371 render_text->SetText(text); | 368 render_text->SetText(text); |
| 372 render_text->SetDisplayRect(bounds); | 369 render_text->SetDisplayRect(bounds); |
| 373 | 370 |
| 374 // Until we can properly elide a URL, we need to bail if the origin portion | 371 // Until we can properly elide a URL, we need to bail if the origin portion |
| 375 // cannot be displayed in its entirety. | 372 // cannot be displayed in its entirety. |
| 376 base::string16 mandatory_prefix = text; | 373 base::string16 mandatory_prefix = text; |
| 377 int length = parsed.CountCharactersBefore(url::Parsed::PORT, false); | 374 int length = parsed.CountCharactersBefore(url::Parsed::PORT, false); |
| 378 if (length > 0) | 375 if (length > 0) |
| 379 mandatory_prefix = text.substr(0, length); | 376 mandatory_prefix = text.substr(0, length); |
| 380 // Ellipsis-based eliding replaces the last character in the string with an | 377 // Ellipsis-based eliding replaces the last character in the string with an |
| 381 // ellipsis, so to reliably check that the origin is intact, check both length | 378 // ellipsis, so to reliably check that the origin is intact, check both length |
| 382 // and string equality. | 379 // and string equality. |
| 383 if (render_text->GetDisplayText().size() < mandatory_prefix.size() || | 380 if (render_text->GetDisplayText().size() < mandatory_prefix.size() || |
| 384 render_text->GetDisplayText().substr(0, mandatory_prefix.size()) != | 381 render_text->GetDisplayText().substr(0, mandatory_prefix.size()) != |
| 385 mandatory_prefix) { | 382 mandatory_prefix) { |
| 386 failure_callback_.Run(UiUnsupportedMode::kCouldNotElideURL); | 383 failure_callback_.Run(UiUnsupportedMode::kCouldNotElideURL); |
| 387 } | 384 } |
| 388 | 385 |
| 389 vr_shell::RenderTextWrapper vr_render_text(render_text.get()); | 386 vr_shell::RenderTextWrapper vr_render_text(render_text.get()); |
| 390 ApplyUrlStyling(text, parsed, security_level_, &vr_render_text, | 387 ApplyUrlStyling(text, parsed, security_level_, &vr_render_text, |
| 391 color_scheme()); | 388 color_scheme()); |
| 392 | 389 |
| 393 url_render_text_ = std::move(render_text); | 390 url_render_text_ = std::move(render_text); |
| 391 url_text_ = text; |
| 394 } | 392 } |
| 395 | 393 |
| 396 // This method replicates behavior in OmniboxView::UpdateTextStyle(), and | 394 // This method replicates behavior in OmniboxView::UpdateTextStyle(), and |
| 397 // attempts to maintain similar code structure. | 395 // attempts to maintain similar code structure. |
| 398 void UrlBarTexture::ApplyUrlStyling( | 396 void UrlBarTexture::ApplyUrlStyling( |
| 399 const base::string16& formatted_url, | 397 const base::string16& formatted_url, |
| 400 const url::Parsed& parsed, | 398 const url::Parsed& parsed, |
| 401 const security_state::SecurityLevel security_level, | 399 const security_state::SecurityLevel security_level, |
| 402 vr_shell::RenderTextWrapper* render_text, | 400 vr_shell::RenderTextWrapper* render_text, |
| 403 const ColorScheme& color_scheme) { | 401 const ColorScheme& color_scheme) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 | 459 |
| 462 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const { | 460 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const { |
| 463 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth); | 461 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth); |
| 464 } | 462 } |
| 465 | 463 |
| 466 gfx::SizeF UrlBarTexture::GetDrawnSize() const { | 464 gfx::SizeF UrlBarTexture::GetDrawnSize() const { |
| 467 return size_; | 465 return size_; |
| 468 } | 466 } |
| 469 | 467 |
| 470 } // namespace vr_shell | 468 } // namespace vr_shell |
| OLD | NEW |