| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_INFOBAR_GTK_H_ | 5 #ifndef CHROME_BROWSER_GTK_INFOBAR_GTK_H_ |
| 6 #define CHROME_BROWSER_GTK_INFOBAR_GTK_H_ | 6 #define CHROME_BROWSER_GTK_INFOBAR_GTK_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "app/gtk_signal.h" | 9 #include "chrome/browser/ui/gtk/infobar_gtk.h" |
| 10 #include "base/basictypes.h" | 10 // TODO(msw): remove this file once all includes have been updated. |
| 11 #include "base/scoped_ptr.h" | |
| 12 #include "chrome/browser/gtk/infobar_arrow_model.h" | |
| 13 #include "chrome/browser/gtk/owned_widget_gtk.h" | |
| 14 #include "chrome/browser/gtk/slide_animator_gtk.h" | |
| 15 #include "chrome/browser/tab_contents/infobar_delegate.h" | |
| 16 #include "chrome/common/notification_observer.h" | |
| 17 #include "chrome/common/notification_registrar.h" | |
| 18 #include "third_party/skia/include/core/SkPaint.h" | |
| 19 | |
| 20 class CustomDrawButton; | |
| 21 class GtkThemeProvider; | |
| 22 class InfoBarContainerGtk; | |
| 23 class InfoBarDelegate; | |
| 24 | |
| 25 class InfoBar : public SlideAnimatorGtk::Delegate, | |
| 26 public NotificationObserver, | |
| 27 public InfoBarArrowModel::Observer { | |
| 28 public: | |
| 29 explicit InfoBar(InfoBarDelegate* delegate); | |
| 30 virtual ~InfoBar(); | |
| 31 | |
| 32 InfoBarDelegate* delegate() const { return delegate_; } | |
| 33 | |
| 34 // Get the top level native GTK widget for this infobar. | |
| 35 GtkWidget* widget(); | |
| 36 | |
| 37 // Set a link to the parent InfoBarContainer. This must be set before the | |
| 38 // InfoBar is added to the view hierarchy. | |
| 39 void set_container(InfoBarContainerGtk* container) { container_ = container; } | |
| 40 | |
| 41 // Starts animating the InfoBar open. | |
| 42 void AnimateOpen(); | |
| 43 | |
| 44 // Opens the InfoBar immediately. | |
| 45 void Open(); | |
| 46 | |
| 47 // Starts animating the InfoBar closed. It will not be closed until the | |
| 48 // animation has completed, when |Close| will be called. | |
| 49 void AnimateClose(); | |
| 50 | |
| 51 // Closes the InfoBar immediately and removes it from its container. Notifies | |
| 52 // the delegate that it has closed. The InfoBar is deleted after this function | |
| 53 // is called. | |
| 54 void Close(); | |
| 55 | |
| 56 // Returns true if the infobar is showing the its open or close animation. | |
| 57 bool IsAnimating(); | |
| 58 | |
| 59 // Returns true if the infobar is showing the close animation. | |
| 60 bool IsClosing(); | |
| 61 | |
| 62 void SetThemeProvider(GtkThemeProvider* theme_provider); | |
| 63 | |
| 64 // Show an arrow that originates from another infobar (i.e. a bar was added | |
| 65 // below this one). If |other| is NULL, stop showing the arrow. | |
| 66 void ShowArrowFor(InfoBar* other, bool animate); | |
| 67 | |
| 68 // InfoBarArrowModel::Observer implementation. | |
| 69 virtual void PaintStateChanged(); | |
| 70 | |
| 71 // SlideAnimatorGtk::Delegate implementation. | |
| 72 virtual void Closed(); | |
| 73 | |
| 74 // NotificationObserver implementation. | |
| 75 virtual void Observe(NotificationType type, | |
| 76 const NotificationSource& source, | |
| 77 const NotificationDetails& details); | |
| 78 | |
| 79 // Retrieves the component colors for the infobar's background | |
| 80 // gradient. (This varies by infobars and can be animated to change). | |
| 81 virtual void GetTopColor(InfoBarDelegate::Type type, | |
| 82 double* r, double* g, double *b); | |
| 83 virtual void GetBottomColor(InfoBarDelegate::Type type, | |
| 84 double* r, double* g, double *b); | |
| 85 | |
| 86 // The total height of the info bar. | |
| 87 static const int kInfoBarHeight; | |
| 88 | |
| 89 protected: | |
| 90 // Removes our associated InfoBarDelegate from the associated TabContents. | |
| 91 // (Will lead to this InfoBar being closed). | |
| 92 void RemoveInfoBar() const; | |
| 93 | |
| 94 // Adds |display_text| to the infobar. If |link_text| is not empty, it is | |
| 95 // rendered as a hyperlink and inserted into |display_text| at |link_offset|, | |
| 96 // or right aligned in the infobar if |link_offset| is |npos|. If a link is | |
| 97 // supplied, |link_callback| must not be null. It will be invoked on click. | |
| 98 void AddLabelWithInlineLink(const string16& display_text, | |
| 99 const string16& link_text, | |
| 100 size_t link_offset, | |
| 101 GCallback callback); | |
| 102 | |
| 103 // Adds |display_text| to the infobar. If |link_text| is not empty, it is | |
| 104 // right aligned in the infobar. | |
| 105 void AddLabelAndLink(const string16& display_text, | |
| 106 const string16& link_text, | |
| 107 GCallback callback); | |
| 108 // The top level widget of the infobar. | |
| 109 scoped_ptr<SlideAnimatorGtk> slide_widget_; | |
| 110 | |
| 111 // The second highest widget in the hierarchy (after the slide widget). | |
| 112 GtkWidget* bg_box_; | |
| 113 | |
| 114 // The hbox that holds infobar elements (button, text, icon, etc.). | |
| 115 GtkWidget* hbox_; | |
| 116 | |
| 117 // The x that closes the bar. | |
| 118 scoped_ptr<CustomDrawButton> close_button_; | |
| 119 | |
| 120 // The InfoBar's container | |
| 121 InfoBarContainerGtk* container_; | |
| 122 | |
| 123 // The InfoBar's delegate. | |
| 124 InfoBarDelegate* delegate_; | |
| 125 | |
| 126 // The theme provider, used for getting border colors. | |
| 127 GtkThemeProvider* theme_provider_; | |
| 128 | |
| 129 // The model that tracks the paint state of the arrow for the infobar | |
| 130 // below this one (if it exists). | |
| 131 InfoBarArrowModel arrow_model_; | |
| 132 | |
| 133 NotificationRegistrar registrar_; | |
| 134 | |
| 135 private: | |
| 136 CHROMEGTK_CALLBACK_0(InfoBar, void, OnCloseButton); | |
| 137 CHROMEGTK_CALLBACK_1(InfoBar, gboolean, OnBackgroundExpose, GdkEventExpose*); | |
| 138 | |
| 139 void UpdateBorderColor(); | |
| 140 | |
| 141 DISALLOW_COPY_AND_ASSIGN(InfoBar); | |
| 142 }; | |
| 143 | 11 |
| 144 #endif // CHROME_BROWSER_GTK_INFOBAR_GTK_H_ | 12 #endif // CHROME_BROWSER_GTK_INFOBAR_GTK_H_ |
| OLD | NEW |