Home | History | Annotate | Download | only in gtk
      1 // Copyright 2012 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_TAB_CONTENTS_CONTAINER_GTK_H_
      6 #define CHROME_BROWSER_UI_GTK_TAB_CONTENTS_CONTAINER_GTK_H_
      7 
      8 #include <gtk/gtk.h>
      9 
     10 #include "base/basictypes.h"
     11 #include "base/compiler_specific.h"
     12 #include "chrome/browser/ui/gtk/view_id_util.h"
     13 #include "content/public/browser/notification_observer.h"
     14 #include "content/public/browser/notification_registrar.h"
     15 #include "ui/base/gtk/gtk_signal.h"
     16 #include "ui/base/gtk/owned_widget_gtk.h"
     17 
     18 class StatusBubbleGtk;
     19 
     20 namespace content {
     21 class WebContents;
     22 }
     23 
     24 typedef struct _GtkFloatingContainer GtkFloatingContainer;
     25 
     26 class TabContentsContainerGtk : public content::NotificationObserver,
     27                                 public ViewIDUtil::Delegate {
     28  public:
     29   explicit TabContentsContainerGtk(StatusBubbleGtk* status_bubble);
     30   virtual ~TabContentsContainerGtk();
     31 
     32   void Init();
     33 
     34   // Make the specified tab visible.
     35   void SetTab(content::WebContents* tab);
     36   content::WebContents* tab() const { return tab_; }
     37 
     38   void SetOverlay(content::WebContents* overlay);
     39   bool HasOverlay() const { return overlay_ != NULL; }
     40 
     41   // Returns the WebContents currently displayed.
     42   content::WebContents* GetVisibleTab() const {
     43     return overlay_ ? overlay_ : tab_;
     44   }
     45 
     46   // Remove the tab from the hierarchy.
     47   void DetachTab(content::WebContents* tab);
     48 
     49   // content::NotificationObserver implementation.
     50   virtual void Observe(int type,
     51                        const content::NotificationSource& source,
     52                        const content::NotificationDetails& details) OVERRIDE;
     53 
     54   GtkWidget* widget() { return floating_.get(); }
     55 
     56   // ViewIDUtil::Delegate implementation ---------------------------------------
     57   virtual GtkWidget* GetWidgetForViewID(ViewID id) OVERRIDE;
     58 
     59  private:
     60   // Called when a WebContents is destroyed. This gives us a chance to clean
     61   // up our internal state if the WebContents is somehow destroyed before we
     62   // get notified.
     63   void WebContentsDestroyed(content::WebContents* contents);
     64 
     65   // Handler for |floating_|'s "set-floating-position" signal. During this
     66   // callback, we manually set the position of the status bubble.
     67   static void OnSetFloatingPosition(
     68       GtkFloatingContainer* container, GtkAllocation* allocation,
     69       TabContentsContainerGtk* tab_contents_container);
     70 
     71   // Adds |tab| to the container and starts showing it.
     72   void PackTab(content::WebContents* tab);
     73 
     74   // Stops showing |tab|.
     75   void HideTab(content::WebContents* tab);
     76 
     77   // Handle focus traversal on the tab contents container. Focus should not
     78   // traverse to the overlay contents.
     79   CHROMEGTK_CALLBACK_1(TabContentsContainerGtk, gboolean, OnFocus,
     80                        GtkDirectionType);
     81 
     82   content::NotificationRegistrar registrar_;
     83 
     84   // The WebContents for the currently selected tab. This will be showing
     85   // unless there is an overlay contents.
     86   content::WebContents* tab_;
     87 
     88   // The current overlay contents (for Instant). If non-NULL, it will be
     89   // visible.
     90   content::WebContents* overlay_;
     91 
     92   // The status bubble manager.  Always non-NULL.
     93   StatusBubbleGtk* status_bubble_;
     94 
     95   // Top of the TabContentsContainerGtk widget hierarchy. A cross between a
     96   // GtkBin and a GtkFixed, |floating_| has |expanded_| as its one "real" child,
     97   // and the various things that hang off the bottom (status bubble, etc) have
     98   // their positions manually set in OnSetFloatingPosition.
     99   ui::OwnedWidgetGtk floating_;
    100 
    101   // We insert and remove WebContents GtkWidgets into this expanded_. This
    102   // should not be a GtkVBox since there were errors with timing where the vbox
    103   // was horizontally split with the top half displaying the current WebContents
    104   // and bottom half displaying the loading page.
    105   GtkWidget* expanded_;
    106 
    107   DISALLOW_COPY_AND_ASSIGN(TabContentsContainerGtk);
    108 };
    109 
    110 #endif  // CHROME_BROWSER_UI_GTK_TAB_CONTENTS_CONTAINER_GTK_H_
    111