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