| 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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 &parsed, nullptr, nullptr); | 257 &parsed, nullptr, nullptr); |
| 258 | 258 |
| 259 int pixel_font_height = texture_size.height() * kFontHeight / kHeight; | 259 int pixel_font_height = texture_size.height() * kFontHeight / kHeight; |
| 260 | 260 |
| 261 gfx::FontList font_list; | 261 gfx::FontList font_list; |
| 262 if (!GetFontList(pixel_font_height, text, &font_list)) | 262 if (!GetFontList(pixel_font_height, text, &font_list)) |
| 263 failure_callback_.Run(UiUnsupportedMode::kUnhandledCodePoint); | 263 failure_callback_.Run(UiUnsupportedMode::kUnhandledCodePoint); |
| 264 | 264 |
| 265 std::unique_ptr<gfx::RenderText> render_text( | 265 std::unique_ptr<gfx::RenderText> render_text( |
| 266 gfx::RenderText::CreateInstance()); | 266 gfx::RenderText::CreateInstance()); |
| 267 render_text->SetText(text); | |
| 268 render_text->SetFontList(font_list); | 267 render_text->SetFontList(font_list); |
| 269 render_text->SetColor(SK_ColorBLACK); | 268 render_text->SetColor(SK_ColorBLACK); |
| 270 render_text->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 269 render_text->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 271 render_text->SetDisplayRect(bounds); | |
| 272 render_text->SetElideBehavior(gfx::TRUNCATE); | 270 render_text->SetElideBehavior(gfx::TRUNCATE); |
| 273 | 271 |
| 272 base::string16 mandatory_prefix = text; |
| 273 int length = parsed.CountCharactersBefore(url::Parsed::PORT, false); |
| 274 if (length > 0) |
| 275 mandatory_prefix = text.substr(0, length); |
| 276 gfx::Rect expanded_bounds = bounds; |
| 277 expanded_bounds.set_width(2 * bounds.width()); |
| 278 render_text->SetDisplayRect(expanded_bounds); |
| 279 render_text->SetText(mandatory_prefix); |
| 280 |
| 281 if (render_text->GetStringSize().width() > bounds.width()) { |
| 282 failure_callback_.Run(UiUnsupportedMode::kCouldNotElideURL); |
| 283 } |
| 284 |
| 285 render_text->SetText(text); |
| 286 render_text->SetDisplayRect(bounds); |
| 274 vr_shell::RenderTextWrapper vr_render_text(render_text.get()); | 287 vr_shell::RenderTextWrapper vr_render_text(render_text.get()); |
| 275 ApplyUrlStyling(text, parsed, security_level_, &vr_render_text, | 288 ApplyUrlStyling(text, parsed, security_level_, &vr_render_text, |
| 276 color_scheme()); | 289 color_scheme()); |
| 277 | 290 |
| 278 url_render_text_ = std::move(render_text); | 291 url_render_text_ = std::move(render_text); |
| 279 } | 292 } |
| 280 | 293 |
| 281 // This method replicates behavior in OmniboxView::UpdateTextStyle(), and | 294 // This method replicates behavior in OmniboxView::UpdateTextStyle(), and |
| 282 // attempts to maintain similar code structure. | 295 // attempts to maintain similar code structure. |
| 283 void UrlBarTexture::ApplyUrlStyling( | 296 void UrlBarTexture::ApplyUrlStyling( |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 | 360 |
| 348 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const { | 361 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const { |
| 349 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth); | 362 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth); |
| 350 } | 363 } |
| 351 | 364 |
| 352 gfx::SizeF UrlBarTexture::GetDrawnSize() const { | 365 gfx::SizeF UrlBarTexture::GetDrawnSize() const { |
| 353 return size_; | 366 return size_; |
| 354 } | 367 } |
| 355 | 368 |
| 356 } // namespace vr_shell | 369 } // namespace vr_shell |
| OLD | NEW |