Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(972)

Side by Side Diff: chrome/browser/android/vr_shell/textures/url_bar_texture.cc

Issue 2944923002: VR: Add ellipsis on truncated URLs. (Closed)
Patch Set: Comment some non-trivial logic. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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" 7 #include "base/i18n/rtl.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "cc/paint/skia_paint_canvas.h" 9 #include "cc/paint/skia_paint_canvas.h"
10 #include "chrome/browser/android/vr_shell/color_scheme.h" 10 #include "chrome/browser/android/vr_shell/color_scheme.h"
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 292
293 gfx::FontList font_list; 293 gfx::FontList font_list;
294 if (!GetFontList(pixel_font_height, text, &font_list)) 294 if (!GetFontList(pixel_font_height, text, &font_list))
295 failure_callback_.Run(UiUnsupportedMode::kUnhandledCodePoint); 295 failure_callback_.Run(UiUnsupportedMode::kUnhandledCodePoint);
296 296
297 std::unique_ptr<gfx::RenderText> render_text( 297 std::unique_ptr<gfx::RenderText> render_text(
298 gfx::RenderText::CreateInstance()); 298 gfx::RenderText::CreateInstance());
299 render_text->SetFontList(font_list); 299 render_text->SetFontList(font_list);
300 render_text->SetColor(SK_ColorBLACK); 300 render_text->SetColor(SK_ColorBLACK);
301 render_text->SetHorizontalAlignment(gfx::ALIGN_LEFT); 301 render_text->SetHorizontalAlignment(gfx::ALIGN_LEFT);
302 render_text->SetElideBehavior(gfx::TRUNCATE); 302 render_text->SetElideBehavior(gfx::ELIDE_TAIL);
303 render_text->SetText(text);
304 render_text->SetDisplayRect(bounds);
303 305
306 // Until we can properly elide a URL, we need to bail if the origin portion
307 // cannot be displayed in its entirety.
304 base::string16 mandatory_prefix = text; 308 base::string16 mandatory_prefix = text;
305 int length = parsed.CountCharactersBefore(url::Parsed::PORT, false); 309 int length = parsed.CountCharactersBefore(url::Parsed::PORT, false);
306 if (length > 0) 310 if (length > 0)
307 mandatory_prefix = text.substr(0, length); 311 mandatory_prefix = text.substr(0, length);
308 gfx::Rect expanded_bounds = bounds; 312 // Ellipsis-based eliding replaces the last character in the string with an
309 expanded_bounds.set_width(2 * bounds.width()); 313 // ellipsis, so to reliably check that the origin is intact, check both length
310 render_text->SetDisplayRect(expanded_bounds); 314 // and string equality.
311 render_text->SetText(mandatory_prefix); 315 if (render_text->GetDisplayText().size() < mandatory_prefix.size() ||
312 316 render_text->GetDisplayText().substr(0, mandatory_prefix.size()) !=
313 if (render_text->GetStringSize().width() > bounds.width()) { 317 mandatory_prefix) {
314 failure_callback_.Run(UiUnsupportedMode::kCouldNotElideURL); 318 failure_callback_.Run(UiUnsupportedMode::kCouldNotElideURL);
315 } 319 }
316 320
317 render_text->SetText(text);
318 render_text->SetDisplayRect(bounds);
319 vr_shell::RenderTextWrapper vr_render_text(render_text.get()); 321 vr_shell::RenderTextWrapper vr_render_text(render_text.get());
320 ApplyUrlStyling(text, parsed, security_level_, &vr_render_text, 322 ApplyUrlStyling(text, parsed, security_level_, &vr_render_text,
321 color_scheme()); 323 color_scheme());
322 324
323 url_render_text_ = std::move(render_text); 325 url_render_text_ = std::move(render_text);
324 } 326 }
325 327
326 // This method replicates behavior in OmniboxView::UpdateTextStyle(), and 328 // This method replicates behavior in OmniboxView::UpdateTextStyle(), and
327 // attempts to maintain similar code structure. 329 // attempts to maintain similar code structure.
328 void UrlBarTexture::ApplyUrlStyling( 330 void UrlBarTexture::ApplyUrlStyling(
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 394
393 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const { 395 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const {
394 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth); 396 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth);
395 } 397 }
396 398
397 gfx::SizeF UrlBarTexture::GetDrawnSize() const { 399 gfx::SizeF UrlBarTexture::GetDrawnSize() const {
398 return size_; 400 return size_;
399 } 401 }
400 402
401 } // namespace vr_shell 403 } // namespace vr_shell
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698