diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-14 20:08:20 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-14 20:08:20 +0000 |
commit | 113a42f3a036c484702554d78568ce1bc30d9384 (patch) | |
tree | 676b24db889f6565f3e2242a371d23304e19545c /chrome | |
parent | 5dc21090414efa5635c57c94e9c647f819dccfec (diff) | |
download | chromium_src-113a42f3a036c484702554d78568ce1bc30d9384.zip chromium_src-113a42f3a036c484702554d78568ce1bc30d9384.tar.gz chromium_src-113a42f3a036c484702554d78568ce1bc30d9384.tar.bz2 |
Add download item tooltips on linux/win.
BUG=41195
TEST=manual
Review URL: http://codereview.chromium.org/1528032
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44524 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/gtk/download_item_gtk.cc | 13 | ||||
-rw-r--r-- | chrome/browser/gtk/download_item_gtk.h | 3 | ||||
-rw-r--r-- | chrome/browser/views/download_item_view.cc | 12 | ||||
-rw-r--r-- | chrome/browser/views/download_item_view.h | 5 |
4 files changed, 33 insertions, 0 deletions
diff --git a/chrome/browser/gtk/download_item_gtk.cc b/chrome/browser/gtk/download_item_gtk.cc index b6b84f9..254561d 100644 --- a/chrome/browser/gtk/download_item_gtk.cc +++ b/chrome/browser/gtk/download_item_gtk.cc @@ -49,6 +49,9 @@ const int kDangerousElementPadding = 3; // it will be elided. const int kTextWidth = 140; +// We only cap the size of the tooltip so we don't crash. +const int kTooltipMaxWidth = 1000; + // The minimum width we will ever draw the download item. Used as a lower bound // during animation. This number comes from the width of the images used to // make the download item. @@ -153,6 +156,7 @@ DownloadItemGtk::DownloadItemGtk(DownloadShelfGtk* parent_shelf, body_.Own(gtk_button_new()); gtk_widget_set_app_paintable(body_.get(), TRUE); + UpdateTooltip(); g_signal_connect(body_.get(), "expose-event", G_CALLBACK(OnExpose), this); @@ -332,6 +336,8 @@ void DownloadItemGtk::OnDownloadUpdated(DownloadItem* download) { // downloads. When the download is confirmed, the file is renamed on // another thread, so reload the icon if the download filename changes. LoadIcon(); + + UpdateTooltip(); } switch (download->state()) { @@ -481,6 +487,13 @@ void DownloadItemGtk::LoadIcon() { NewCallback(this, &DownloadItemGtk::OnLoadIconComplete)); } +void DownloadItemGtk::UpdateTooltip() { + std::wstring elided_filename = gfx::ElideFilename( + get_download()->GetFileName(), + gfx::Font(), kTooltipMaxWidth); + gtk_widget_set_tooltip_text(body_.get(), WideToUTF8(elided_filename).c_str()); +} + void DownloadItemGtk::UpdateNameLabel() { // TODO(estade): This is at best an educated guess, since we don't actually // use gfx::Font() to draw the text. This is why we need to add so diff --git a/chrome/browser/gtk/download_item_gtk.h b/chrome/browser/gtk/download_item_gtk.h index e2abcb9..fbe2ec5 100644 --- a/chrome/browser/gtk/download_item_gtk.h +++ b/chrome/browser/gtk/download_item_gtk.h @@ -76,6 +76,9 @@ class DownloadItemGtk : public DownloadItem::Observer, // Ask the icon manager to asynchronously start loading the icon for the file. void LoadIcon(); + // Sets the tooltip on the download button. + void UpdateTooltip(); + // Sets the name label to the correct color. void UpdateNameLabel(); diff --git a/chrome/browser/views/download_item_view.cc b/chrome/browser/views/download_item_view.cc index 3127813..fbb0dd8 100644 --- a/chrome/browser/views/download_item_view.cc +++ b/chrome/browser/views/download_item_view.cc @@ -211,6 +211,7 @@ DownloadItemView::DownloadItemView(DownloadItem* download, dangerous_mode_body_image_set_ = dangerous_mode_body_image_set; LoadIcon(); + tooltip_text_ = download_->GetFileName().value(); font_ = ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont); box_height_ = std::max<int>(2 * kVerticalPadding + font_.height() + @@ -240,6 +241,7 @@ DownloadItemView::DownloadItemView(DownloadItem* download, drop_hover_animation_.reset(new SlideAnimation(this)); if (download->safety_state() == DownloadItem::DANGEROUS) { + tooltip_text_.clear(); body_state_ = DANGEROUS; drop_down_state_ = DANGEROUS; @@ -728,6 +730,7 @@ void DownloadItemView::ClearDangerousMode() { // We need to load the icon now that the download_ has the real path. LoadIcon(); + tooltip_text_ = download_->GetFileName().value(); // Force the shelf to layout again as our size has changed. parent_->Layout(); @@ -924,6 +927,15 @@ void DownloadItemView::LoadIcon() { NewCallback(this, &DownloadItemView::OnExtractIconComplete)); } +bool DownloadItemView::GetTooltipText(const gfx::Point& p, + std::wstring* tooltip) { + if (tooltip_text_.empty()) + return false; + + tooltip->assign(tooltip_text_); + return true; +} + gfx::Size DownloadItemView::GetButtonSize() { DCHECK(save_button_ && discard_button_); gfx::Size size; diff --git a/chrome/browser/views/download_item_view.h b/chrome/browser/views/download_item_view.h index 4c1526c..366dc1c 100644 --- a/chrome/browser/views/download_item_view.h +++ b/chrome/browser/views/download_item_view.h @@ -114,6 +114,8 @@ class DownloadItemView : public views::ButtonListener, void LoadIcon(); + virtual bool GetTooltipText(const gfx::Point& p, std::wstring* tooltip); + // Convenience method to paint the 3 vertical bitmaps (bottom, middle, top) // that form the background. void PaintBitmaps(gfx::Canvas* canvas, @@ -176,6 +178,9 @@ class DownloadItemView : public views::ButtonListener, // The font used to print the file name and status. gfx::Font font_; + // The tooltip. + std::wstring tooltip_text_; + // The current state (normal, hot or pushed) of the body and drop-down. State body_state_; State drop_down_state_; |