diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-19 08:20:56 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-19 08:20:56 +0000 |
commit | 6145198177d58f79e7ed1b44fee883ea074fc5fa (patch) | |
tree | 306253d68fa38b61d49da733316a31b6d377a7ca /app/text_elider.h | |
parent | eb776a32dcb148e37c7d5990161c6fff9f2f534a (diff) | |
download | chromium_src-6145198177d58f79e7ed1b44fee883ea074fc5fa.zip chromium_src-6145198177d58f79e7ed1b44fee883ea074fc5fa.tar.gz chromium_src-6145198177d58f79e7ed1b44fee883ea074fc5fa.tar.bz2 |
Move text_elider from app/gfx to app/
TBR=darin
BUG=none
TEST=none
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42090 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/text_elider.h')
-rw-r--r-- | app/text_elider.h | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/app/text_elider.h b/app/text_elider.h new file mode 100644 index 0000000..aa33c29 --- /dev/null +++ b/app/text_elider.h @@ -0,0 +1,87 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef APP_GFX_TEXT_ELIDER_H_ +#define APP_GFX_TEXT_ELIDER_H_ + +#include <unicode/coll.h> +#include <unicode/uchar.h> + +#include "app/gfx/font.h" +#include "base/basictypes.h" +#include "base/string16.h" + +class FilePath; +class GURL; + +// TODO(port): this file should deal in string16s rather than wstrings. +namespace gfx { + +// This function takes a GURL object and elides it. It returns a string +// which composed of parts from subdomain, domain, path, filename and query. +// A "..." is added automatically at the end if the elided string is bigger +// than the available pixel width. For available pixel width = 0, empty +// string is returned. |languages| is a comma separted list of ISO 639 +// language codes and is used to determine what characters are understood +// by a user. It should come from |prefs::kAcceptLanguages|. +// +// Note: in RTL locales, if the URL returned by this function is going to be +// displayed in the UI, then it is likely that the string needs to be marked +// as an LTR string (using l10n_util::WrapStringWithLTRFormatting()) so that it +// is displayed properly in an RTL context. Please refer to +// http://crbug.com/6487 for more information. +std::wstring ElideUrl(const GURL& url, + const gfx::Font& font, + int available_pixel_width, + const std::wstring& languages); + +std::wstring ElideText(const std::wstring& text, + const gfx::Font& font, + int available_pixel_width); + +// Elide a filename to fit a given pixel width, with an emphasis on not hiding +// the extension unless we have to. If filename contains a path, the path will +// be removed if filename doesn't fit into available_pixel_width. The elided +// filename is forced to have LTR directionality, which means that in RTL UI +// the elided filename is wrapped with LRE (Left-To-Right Embedding) mark and +// PDF (Pop Directional Formatting) mark. +std::wstring ElideFilename(const FilePath& filename, + const gfx::Font& font, + int available_pixel_width); + +// SortedDisplayURL maintains a string from a URL suitable for display to the +// use. SortedDisplayURL also provides a function used for comparing two +// SortedDisplayURLs for use in visually ordering the SortedDisplayURLs. +// +// SortedDisplayURL is relatively cheap and supports value semantics. +class SortedDisplayURL { + public: + SortedDisplayURL(const GURL& url, const std::wstring& languages); + SortedDisplayURL() {} + + // Compares this SortedDisplayURL to |url| using |collator|. Returns a value + // < 0, = 1 or > 0 as to whether this url is less then, equal to or greater + // than the supplied url. + int Compare(const SortedDisplayURL& other, icu::Collator* collator) const; + + // Returns the display string for the URL. + const string16& display_url() const { return display_url_; } + + private: + // Returns everything after the host. This is used by Compare if the hosts + // match. + string16 AfterHost() const; + + // Host name minus 'www.'. Used by Compare. + string16 sort_host_; + + // End of the prefix (spec and separator) in display_url_. + size_t prefix_end_; + + string16 display_url_; +}; + +} // namespace gfx. + +#endif // APP_GFX_TEXT_ELIDER_H_ |