| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #ifndef CHROME_BROWSER_GTK_STATUS_BUBBLE_GTK_H_ | 5 #ifndef CHROME_BROWSER_GTK_STATUS_BUBBLE_GTK_H_ |
| 6 #define CHROME_BROWSER_GTK_STATUS_BUBBLE_GTK_H_ | 6 #define CHROME_BROWSER_GTK_STATUS_BUBBLE_GTK_H_ |
| 7 | 7 |
| 8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/gfx/point.h" |
| 12 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
| 13 #include "base/task.h" | 14 #include "base/task.h" |
| 14 #include "chrome/browser/status_bubble.h" | 15 #include "chrome/browser/status_bubble.h" |
| 15 #include "chrome/common/notification_observer.h" | 16 #include "chrome/common/notification_observer.h" |
| 16 #include "chrome/common/notification_registrar.h" | 17 #include "chrome/common/notification_registrar.h" |
| 17 #include "chrome/common/owned_widget_gtk.h" | 18 #include "chrome/common/owned_widget_gtk.h" |
| 18 | 19 |
| 19 class GtkThemeProvider; | 20 class GtkThemeProvider; |
| 20 class GURL; | 21 class GURL; |
| 21 class Profile; | 22 class Profile; |
| 22 | 23 |
| 23 // GTK implementation of StatusBubble. Unlike Windows, our status bubble | 24 // GTK implementation of StatusBubble. Unlike Windows, our status bubble |
| 24 // doesn't have the nice leave-the-window effect since we can't rely on the | 25 // doesn't have the nice leave-the-window effect since we can't rely on the |
| 25 // window manager to not try to be "helpful" and center our popups, etc. | 26 // window manager to not try to be "helpful" and center our popups, etc. |
| 26 // We therefore position it absolutely in a GtkFixed, that we don't own. | 27 // We therefore position it absolutely in a GtkFixed, that we don't own. |
| 27 class StatusBubbleGtk : public StatusBubble, | 28 class StatusBubbleGtk : public StatusBubble, |
| 28 public NotificationObserver { | 29 public NotificationObserver { |
| 29 public: | 30 public: |
| 30 explicit StatusBubbleGtk(Profile* profile); | 31 explicit StatusBubbleGtk(Profile* profile); |
| 31 virtual ~StatusBubbleGtk(); | 32 virtual ~StatusBubbleGtk(); |
| 32 | 33 |
| 34 bool flip_horizontally() const { return flip_horizontally_; } |
| 35 int y_offset() const { return y_offset_; } |
| 36 |
| 33 // StatusBubble implementation. | 37 // StatusBubble implementation. |
| 34 virtual void SetStatus(const std::wstring& status); | 38 virtual void SetStatus(const std::wstring& status); |
| 35 virtual void SetURL(const GURL& url, const std::wstring& languages); | 39 virtual void SetURL(const GURL& url, const std::wstring& languages); |
| 36 virtual void Hide(); | 40 virtual void Hide(); |
| 37 virtual void MouseMoved(); | 41 virtual void MouseMoved(const gfx::Point& location, bool left_content); |
| 38 | 42 |
| 39 // Called when the download shelf becomes visible or invisible. | 43 // Called when the download shelf becomes visible or invisible. |
| 40 // This is used by to ensure that the status bubble does not obscure | 44 // This is used by to ensure that the status bubble does not obscure |
| 41 // the download shelf, when it is visible. | 45 // the download shelf, when it is visible. |
| 42 virtual void UpdateDownloadShelfVisibility(bool visible) { } | 46 virtual void UpdateDownloadShelfVisibility(bool visible); |
| 43 | 47 |
| 44 // Overridden from NotificationObserver: | 48 // Overridden from NotificationObserver: |
| 45 void Observe(NotificationType type, | 49 void Observe(NotificationType type, |
| 46 const NotificationSource& source, | 50 const NotificationSource& source, |
| 47 const NotificationDetails& details); | 51 const NotificationDetails& details); |
| 48 | 52 |
| 49 // Top of the widget hierarchy for a StatusBubble. This top level widget is | 53 // Top of the widget hierarchy for a StatusBubble. This top level widget is |
| 50 // guarenteed to have its gtk_widget_name set to "status-bubble" for | 54 // guarenteed to have its gtk_widget_name set to "status-bubble" for |
| 51 // identification. | 55 // identification. |
| 52 GtkWidget* widget() { return container_.get(); } | 56 GtkWidget* widget() { return container_.get(); } |
| 53 | 57 |
| 54 private: | 58 private: |
| 55 // Sets the text of the label widget and controls visibility. (As contrasted | 59 // Sets the text of the label widget and controls visibility. (As contrasted |
| 56 // with setting the current status or URL text, which may be ignored for now). | 60 // with setting the current status or URL text, which may be ignored for now). |
| 57 void SetStatusTextTo(const std::string& status_utf8); | 61 void SetStatusTextTo(const std::string& status_utf8); |
| 58 | 62 |
| 59 // Sets the status bubble's location in the parent GtkFixed, shows the widget | 63 // Sets the status bubble's location in the parent GtkFixed, shows the widget |
| 60 // and makes sure that the status bubble has the highest z-order. | 64 // and makes sure that the status bubble has the highest z-order. |
| 61 void Show(); | 65 void Show(); |
| 62 | 66 |
| 63 // Sets an internal timer to hide the status bubble after a delay. | 67 // Sets an internal timer to hide the status bubble after a delay. |
| 64 void HideInASecond(); | 68 void HideInASecond(); |
| 65 | 69 |
| 66 // Builds the widgets, containers, etc. | 70 // Builds the widgets, containers, etc. |
| 67 void InitWidgets(); | 71 void InitWidgets(); |
| 68 | 72 |
| 69 // Notification from the window that we should retheme ourself. | 73 // Notification from the window that we should retheme ourself. |
| 70 void UserChangedTheme(); | 74 void UserChangedTheme(); |
| 71 | 75 |
| 76 // Sets whether the bubble should be flipped horizontally and displayed on the |
| 77 // opposite side of the tab contents. Reshapes the container and queues a |
| 78 // redraw if necessary. |
| 79 void SetFlipHorizontally(bool flip_horizontally); |
| 80 |
| 81 static gboolean HandleMotionNotifyThunk(GtkWidget* widget, |
| 82 GdkEventMotion* event, |
| 83 gpointer user_data) { |
| 84 return reinterpret_cast<StatusBubbleGtk*>(user_data)-> |
| 85 HandleMotionNotify(event); |
| 86 } |
| 87 gboolean HandleMotionNotify(GdkEventMotion* event); |
| 88 |
| 72 NotificationRegistrar registrar_; | 89 NotificationRegistrar registrar_; |
| 73 | 90 |
| 74 // Provides colors. | 91 // Provides colors. |
| 75 GtkThemeProvider* theme_provider_; | 92 GtkThemeProvider* theme_provider_; |
| 76 | 93 |
| 77 // The toplevel event box. | 94 // The toplevel event box. |
| 78 OwnedWidgetGtk container_; | 95 OwnedWidgetGtk container_; |
| 79 | 96 |
| 97 // The GtkAlignment holding |label_|. |
| 98 GtkWidget* padding_; |
| 99 |
| 80 // The GtkLabel holding the text. | 100 // The GtkLabel holding the text. |
| 81 GtkWidget* label_; | 101 GtkWidget* label_; |
| 82 | 102 |
| 83 // The status text we want to display when there are no URLs to display. | 103 // The status text we want to display when there are no URLs to display. |
| 84 std::string status_text_; | 104 std::string status_text_; |
| 85 | 105 |
| 86 // The url we want to display when there is no status text to display. | 106 // The url we want to display when there is no status text to display. |
| 87 std::string url_text_; | 107 std::string url_text_; |
| 88 | 108 |
| 89 // A timer that hides our window after a delay. | 109 // A timer that hides our window after a delay. |
| 90 ScopedRunnableMethodFactory<StatusBubbleGtk> timer_factory_; | 110 ScopedRunnableMethodFactory<StatusBubbleGtk> timer_factory_; |
| 111 |
| 112 // Should the bubble be flipped horizontally (e.g. displayed on the right for |
| 113 // an LTR language)? We move the bubble to the other side of the tab contents |
| 114 // rather than sliding it down when the download shelf is visible. |
| 115 bool flip_horizontally_; |
| 116 |
| 117 // Vertical offset used to hide the status bubble as the pointer nears it. |
| 118 int y_offset_; |
| 119 |
| 120 // If the download shelf is visible, do not obscure it. |
| 121 bool download_shelf_is_visible_; |
| 91 }; | 122 }; |
| 92 | 123 |
| 93 #endif // CHROME_BROWSER_GTK_STATUS_BUBBLE_GTK_H_ | 124 #endif // CHROME_BROWSER_GTK_STATUS_BUBBLE_GTK_H_ |
| OLD | NEW |