1// Copyright 2014 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4// 5// This file defines utility functions for eliding URLs. 6 7#ifndef CHROME_BROWSER_UI_ELIDE_URL_H_ 8#define CHROME_BROWSER_UI_ELIDE_URL_H_ 9 10#include <string> 11 12#include "base/strings/string16.h" 13 14class GURL; 15 16namespace gfx { 17class FontList; 18} 19 20// This function takes a GURL object and elides it. It returns a string 21// which composed of parts from subdomain, domain, path, filename and query. 22// A "..." is added automatically at the end if the elided string is bigger 23// than the |available_pixel_width|. For |available_pixel_width| == 0, a 24// formatted, but un-elided, string is returned. |languages| is a comma 25// separated list of ISO 639 language codes and is used to determine what 26// characters are understood by a user. It should come from 27// |prefs::kAcceptLanguages|. 28// 29// Note: in RTL locales, if the URL returned by this function is going to be 30// displayed in the UI, then it is likely that the string needs to be marked 31// as an LTR string (using base::i18n::WrapStringWithLTRFormatting()) so that it 32// is displayed properly in an RTL context. Please refer to 33// http://crbug.com/6487 for more information. 34base::string16 ElideUrl(const GURL& url, 35 const gfx::FontList& font_list, 36 float available_pixel_width, 37 const std::string& languages); 38 39// This function takes a GURL object and elides the host to fit within 40// the given width. The function will never elide past the TLD+1 point, 41// but after that, will leading-elide the domain name to fit the width. 42// Example: http://sub.domain.com ---> "...domain.com", or "...b.domain.com" 43// depending on the width. 44base::string16 ElideHost(const GURL& host_url, 45 const gfx::FontList& font_list, 46 float available_pixel_width); 47 48#endif // CHROME_BROWSER_UI_ELIDE_URL_H_ 49