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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_UI_GTK_INFOBARS_INFOBAR_GTK_H_ 6 #define CHROME_BROWSER_UI_GTK_INFOBARS_INFOBAR_GTK_H_ 7 #pragma once 8 9 #include "base/basictypes.h" 10 #include "base/memory/scoped_ptr.h" 11 #include "chrome/browser/tab_contents/infobar_delegate.h" 12 #include "chrome/browser/ui/gtk/infobars/infobar_arrow_model.h" 13 #include "chrome/browser/ui/gtk/owned_widget_gtk.h" 14 #include "chrome/browser/ui/gtk/slide_animator_gtk.h" 15 #include "content/common/notification_observer.h" 16 #include "content/common/notification_registrar.h" 17 #include "third_party/skia/include/core/SkPaint.h" 18 #include "ui/base/gtk/gtk_signal.h" 19 20 class CustomDrawButton; 21 class GtkThemeService; 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 delegate()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. set_container(InfoBarContainerGtk * container)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(GtkThemeService* 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 // Spacing after message (and before buttons). 91 static const int kEndOfLabelSpacing; 92 // Spacing between buttons. 93 static const int kButtonButtonSpacing; 94 95 // Removes our associated InfoBarDelegate from the associated TabContents. 96 // (Will lead to this InfoBar being closed). 97 void RemoveInfoBar() const; 98 99 // Adds |display_text| to the infobar. If |link_text| is not empty, it is 100 // rendered as a hyperlink and inserted into |display_text| at |link_offset|, 101 // or right aligned in the infobar if |link_offset| is |npos|. If a link is 102 // supplied, |link_callback| must not be null. It will be invoked on click. 103 void AddLabelWithInlineLink(const string16& display_text, 104 const string16& link_text, 105 size_t link_offset, 106 GCallback callback); 107 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 GtkThemeService* theme_service_; 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 144 #endif // CHROME_BROWSER_UI_GTK_INFOBARS_INFOBAR_GTK_H_ 145