summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/gtk/tab_contents_container_gtk.h
blob: 377d509c1becd82068fdd12731d7b0a1b8b59820 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_GTK_TAB_CONTENTS_CONTAINER_GTK_H_
#define CHROME_BROWSER_UI_GTK_TAB_CONTENTS_CONTAINER_GTK_H_
#pragma once

#include <gtk/gtk.h>

#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "chrome/browser/ui/gtk/view_id_util.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "ui/base/gtk/gtk_signal.h"
#include "ui/base/gtk/owned_widget_gtk.h"

class StatusBubbleGtk;
class TabContentsWrapper;

namespace content {
class WebContents;
}

typedef struct _GtkFloatingContainer GtkFloatingContainer;

class TabContentsContainerGtk : public content::NotificationObserver,
                                public ViewIDUtil::Delegate {
 public:
  explicit TabContentsContainerGtk(StatusBubbleGtk* status_bubble);
  virtual ~TabContentsContainerGtk();

  void Init();

  // Make the specified tab visible.
  void SetTab(TabContentsWrapper* tab);
  TabContentsWrapper* tab() const { return tab_; }

  // Returns the TabContentsWrapper currently displayed.
  TabContentsWrapper* GetVisibleTab();

  bool HasPreview() const { return preview_ != NULL; }

  void SetPreview(TabContentsWrapper* preview);
  void PopPreview();

  // Remove the tab from the hierarchy.
  void DetachTab(TabContentsWrapper* tab);

  // content::NotificationObserver implementation.
  virtual void Observe(int type,
                       const content::NotificationSource& source,
                       const content::NotificationDetails& details) OVERRIDE;

  GtkWidget* widget() { return floating_.get(); }

  // ViewIDUtil::Delegate implementation ---------------------------------------
  virtual GtkWidget* GetWidgetForViewID(ViewID id) OVERRIDE;

 private:
  // Called when a WebContents is destroyed. This gives us a chance to clean
  // up our internal state if the WebContents is somehow destroyed before we
  // get notified.
  void WebContentsDestroyed(content::WebContents* contents);

  // Handler for |floating_|'s "set-floating-position" signal. During this
  // callback, we manually set the position of the status bubble.
  static void OnSetFloatingPosition(
      GtkFloatingContainer* container, GtkAllocation* allocation,
      TabContentsContainerGtk* tab_contents_container);

  // Adds |tab| to the container and starts showing it.
  void PackTab(TabContentsWrapper* );

  // Stops showing |tab|.
  void HideTab(TabContentsWrapper* tab);

  // Removes |preview_|.
  void RemovePreview();

  // Handle focus traversal on the tab contents container. Focus should not
  // traverse to the preview contents.
  CHROMEGTK_CALLBACK_1(TabContentsContainerGtk, gboolean, OnFocus,
                       GtkDirectionType);

  content::NotificationRegistrar registrar_;

  // The TabContentsWrapper for the currently selected tab. This will be showing
  // unless there is a preview contents.
  TabContentsWrapper* tab_;

  // The current preview contents (for instant). If non-NULL, it will be
  // visible.
  TabContentsWrapper* preview_;

  // The status bubble manager.  Always non-NULL.
  StatusBubbleGtk* status_bubble_;

  // Top of the TabContentsContainerGtk widget hierarchy. A cross between a
  // GtkBin and a GtkFixed, |floating_| has |expanded_| as its one "real" child,
  // and the various things that hang off the bottom (status bubble, etc) have
  // their positions manually set in OnSetFloatingPosition.
  ui::OwnedWidgetGtk floating_;

  // We insert and remove TabContents GtkWidgets into this expanded_. This
  // should not be a GtkVBox since there were errors with timing where the vbox
  // was horizontally split with the top half displaying the current TabContents
  // and bottom half displaying the loading page.
  GtkWidget* expanded_;

  DISALLOW_COPY_AND_ASSIGN(TabContentsContainerGtk);
};

#endif  // CHROME_BROWSER_UI_GTK_TAB_CONTENTS_CONTAINER_GTK_H_