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_CONTAINER_GTK_H_ 6 #define CHROME_BROWSER_UI_GTK_INFOBARS_INFOBAR_CONTAINER_GTK_H_ 7 8 #include <vector> 9 10 #include "base/basictypes.h" 11 #include "base/compiler_specific.h" 12 #include "chrome/browser/infobars/infobar_container.h" 13 #include "ui/base/gtk/owned_widget_gtk.h" 14 15 class InfoBar; 16 class InfoBarGtk; 17 class InfoBarDelegate; 18 class Profile; 19 20 namespace gfx { 21 class Rect; 22 } 23 24 typedef struct _GdkColor GdkColor; 25 typedef struct _GdkEventExpose GdkEventExpose; 26 typedef struct _GtkWidget GtkWidget; 27 28 // Container that both contains the currently displaying infobars, and does 29 // drawing of infobar arrows on other widgets. 30 // 31 // Due to how X11/GTK+ works, this class owns the methods to draw arrows on top 32 // of other widgets. Since most bars in the top of the window have their own 33 // event boxes, we can't just draw over the coordinates in the toplevel window 34 // as event boxes get their own canvases (and they need to have their own event 35 // boxes for a mixture of handling mouse events and themeing). And because they 36 // have their own event boxes and event boxes can't be partially transparent, 37 // we can't just overlap the widgets. 38 class InfoBarContainerGtk : public InfoBarContainer { 39 public: 40 InfoBarContainerGtk(InfoBarContainer::Delegate* delegate, 41 Profile* profile); 42 virtual ~InfoBarContainerGtk(); 43 44 // Get the native widget. 45 GtkWidget* widget() const { return container_.get(); } 46 47 // Remove the specified InfoBarDelegate from the selected WebContents. This 48 // will notify us back and cause us to close the View. This is called from 49 // the InfoBar's close button handler. 50 void RemoveDelegate(InfoBarDelegate* delegate); 51 52 // Returns the total pixel height of all infobars in this container that 53 // are currently animating. 54 int TotalHeightOfAnimatingBars() const; 55 56 // True if we are displaying any infobars. 57 bool ContainsInfobars() const; 58 59 // Paints parts of infobars that aren't inside the infobar's widget. This 60 // method is called with |widget|/|expose| pairs for both infobars and 61 // toolbars. All infobars starting from |infobar| (NULL for the first) to the 62 // end of the list will be rendered. 63 void PaintInfobarBitsOn(GtkWidget* widget, 64 GdkEventExpose* expose, 65 InfoBarGtk* infobar); 66 67 protected: 68 // InfoBarContainer: 69 virtual void PlatformSpecificAddInfoBar(InfoBar* infobar, 70 size_t position) OVERRIDE; 71 virtual void PlatformSpecificRemoveInfoBar(InfoBar* infobar) OVERRIDE; 72 virtual void PlatformSpecificInfoBarStateChanged(bool is_animating) OVERRIDE; 73 74 private: 75 // Performs the actual painting of the arrow in an expose event. 76 void PaintArrowOn(GtkWidget* widget, 77 GdkEventExpose* expose, 78 const gfx::Rect& bounds, 79 InfoBarGtk* source); 80 81 // The profile for the browser that hosts this InfoBarContainer. 82 Profile* profile_; 83 84 // A list of the InfoBarGtk* instances. Used during drawing to determine 85 // which InfoBarGtk supplies information about drawing the arrows. 86 std::vector<InfoBarGtk*> infobars_gtk_; 87 88 // VBox that holds the info bars. 89 ui::OwnedWidgetGtk container_; 90 91 DISALLOW_COPY_AND_ASSIGN(InfoBarContainerGtk); 92 }; 93 94 #endif // CHROME_BROWSER_UI_GTK_INFOBARS_INFOBAR_CONTAINER_GTK_H_ 95