summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authortc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-18 18:56:08 +0000
committertc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-18 18:56:08 +0000
commit77148a8429579009f0eb74f5b57af5c42a8374cf (patch)
tree2deb7b97967cd28938f098074d8e3fb077e61a5a /chrome/browser
parent167803ef100566b560c5df76ff4d952087401f37 (diff)
downloadchromium_src-77148a8429579009f0eb74f5b57af5c42a8374cf.zip
chromium_src-77148a8429579009f0eb74f5b57af5c42a8374cf.tar.gz
chromium_src-77148a8429579009f0eb74f5b57af5c42a8374cf.tar.bz2
Elide the URL in the status bubble.
I copied the logic about whether to show the loading status or URL from the Views code. Review URL: http://codereview.chromium.org/125267 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18730 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/gtk/status_bubble_gtk.cc43
-rw-r--r--chrome/browser/gtk/status_bubble_gtk.h13
2 files changed, 47 insertions, 9 deletions
diff --git a/chrome/browser/gtk/status_bubble_gtk.cc b/chrome/browser/gtk/status_bubble_gtk.cc
index 7b377b1..6bceeb2 100644
--- a/chrome/browser/gtk/status_bubble_gtk.cc
+++ b/chrome/browser/gtk/status_bubble_gtk.cc
@@ -6,6 +6,7 @@
#include <gtk/gtk.h>
+#include "app/gfx/text_elider.h"
#include "base/gfx/gtk_util.h"
#include "base/message_loop.h"
#include "base/string_util.h"
@@ -41,14 +42,15 @@ StatusBubbleGtk::~StatusBubbleGtk() {
}
void StatusBubbleGtk::SetStatus(const std::string& status) {
- if (status.empty()) {
- HideInASecond();
+ if (status_text_ == status)
return;
- }
-
- gtk_label_set_text(GTK_LABEL(label_), status.c_str());
- Show();
+ status_text_ = status;
+ if (!status_text_.empty()) {
+ UpdateWidgetText(status_text_);
+ } else {
+ UpdateWidgetText(url_text_);
+ }
}
void StatusBubbleGtk::SetStatus(const std::wstring& status) {
@@ -56,7 +58,34 @@ void StatusBubbleGtk::SetStatus(const std::wstring& status) {
}
void StatusBubbleGtk::SetURL(const GURL& url, const std::wstring& languages) {
- SetStatus(url.possibly_invalid_spec());
+ // If we want to clear a displayed URL but there is a status still to
+ // display, display that status instead.
+ if (url.is_empty() && !status_text_.empty()) {
+ url_text_.clear();
+ UpdateWidgetText(status_text_);
+ return;
+ }
+
+ // Set Elided Text corresponding to the GURL object. We limit the width of
+ // the URL to a third of the width of the browser window (matching the width
+ // on windows).
+ GdkWindow* window = gtk_widget_get_parent_window(container_.get());
+ int window_width;
+ gdk_drawable_get_size(GDK_DRAWABLE(window), &window_width, NULL);
+ // TODO(tc): We don't actually use gfx::Font as the font in the status
+ // bubble. We should extend gfx::ElideUrl to take some sort of pango font.
+ url_text_ = WideToUTF8(gfx::ElideUrl(url, gfx::Font(), window_width / 3,
+ languages));
+ UpdateWidgetText(url_text_);
+}
+
+void StatusBubbleGtk::UpdateWidgetText(const std::string& text) {
+ if (text.empty()) {
+ HideInASecond();
+ } else {
+ gtk_label_set_text(GTK_LABEL(label_), text.c_str());
+ Show();
+ }
}
void StatusBubbleGtk::Show() {
diff --git a/chrome/browser/gtk/status_bubble_gtk.h b/chrome/browser/gtk/status_bubble_gtk.h
index 5de672b..da4bfe1 100644
--- a/chrome/browser/gtk/status_bubble_gtk.h
+++ b/chrome/browser/gtk/status_bubble_gtk.h
@@ -36,14 +36,18 @@ class StatusBubbleGtk : public StatusBubble {
// the download shelf, when it is visible.
virtual void UpdateDownloadShelfVisibility(bool visible) { }
- void SetStatus(const std::string& status_utf8);
-
// Top of the widget hierarchy for a StatusBubble. This top level widget is
// guarenteed to have its gtk_widget_name set to "status-bubble" for
// identification.
GtkWidget* widget() { return container_.get(); }
private:
+ // The same as the public SetStatus method, but using utf8 instead.
+ void SetStatus(const std::string& status_utf8);
+
+ // Set the text in the gtk widget and handle when to show/hide the bubble.
+ void UpdateWidgetText(const std::string& text);
+
// Sets the status bubble's location in the parent GtkFixed, shows the widget
// and makes sure that the status bubble has the highest z-order.
void Show();
@@ -60,6 +64,11 @@ class StatusBubbleGtk : public StatusBubble {
// The GtkLabel holding the text.
GtkWidget* label_;
+ // We keep both the status and url that we want to show and try to pick the
+ // right one to display to the user.
+ std::string status_text_;
+ std::string url_text_;
+
// A timer that hides our window after a delay.
ScopedRunnableMethodFactory<StatusBubbleGtk> timer_factory_;
};