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_TAB_CONTENTS_TAB_CONTENTS_VIEW_GTK_H_
6#define CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_VIEW_GTK_H_
7#pragma once
8
9#include <gtk/gtk.h>
10
11#include <vector>
12
13#include "base/memory/scoped_ptr.h"
14#include "chrome/browser/ui/gtk/focus_store_gtk.h"
15#include "chrome/browser/ui/gtk/owned_widget_gtk.h"
16#include "content/browser/tab_contents/tab_contents_view.h"
17#include "content/common/notification_observer.h"
18#include "content/common/notification_registrar.h"
19#include "ui/base/gtk/gtk_signal.h"
20
21class ConstrainedWindowGtk;
22class RenderViewContextMenuGtk;
23class SadTabGtk;
24class TabContentsDragSource;
25class WebDragDestGtk;
26
27class TabContentsViewGtk : public TabContentsView,
28                           public NotificationObserver {
29 public:
30  // The corresponding TabContents is passed in the constructor, and manages our
31  // lifetime. This doesn't need to be the case, but is this way currently
32  // because that's what was easiest when they were split.
33  explicit TabContentsViewGtk(TabContents* tab_contents);
34  virtual ~TabContentsViewGtk();
35
36  // Unlike Windows, ConstrainedWindows need to collaborate with the
37  // TabContentsViewGtk to position the dialogs.
38  void AttachConstrainedWindow(ConstrainedWindowGtk* constrained_window);
39  void RemoveConstrainedWindow(ConstrainedWindowGtk* constrained_window);
40
41  // Override the stored focus widget. This call only makes sense when the
42  // tab contents is not focused.
43  void SetFocusedWidget(GtkWidget* widget);
44
45  // TabContentsView implementation --------------------------------------------
46
47  virtual void CreateView(const gfx::Size& initial_size);
48  virtual RenderWidgetHostView* CreateViewForWidget(
49      RenderWidgetHost* render_widget_host);
50
51  virtual gfx::NativeView GetNativeView() const;
52  virtual gfx::NativeView GetContentNativeView() const;
53  virtual gfx::NativeWindow GetTopLevelNativeWindow() const;
54  virtual void GetContainerBounds(gfx::Rect* out) const;
55  virtual void SetPageTitle(const std::wstring& title);
56  virtual void OnTabCrashed(base::TerminationStatus status,
57                            int error_code);
58  virtual void SizeContents(const gfx::Size& size);
59  virtual void Focus();
60  virtual void SetInitialFocus();
61  virtual void StoreFocus();
62  virtual void RestoreFocus();
63  virtual void GetViewBounds(gfx::Rect* out) const;
64
65  // Backend implementation of RenderViewHostDelegate::View.
66  virtual void ShowContextMenu(const ContextMenuParams& params);
67  virtual void ShowPopupMenu(const gfx::Rect& bounds,
68                             int item_height,
69                             double item_font_size,
70                             int selected_item,
71                             const std::vector<WebMenuItem>& items,
72                             bool right_aligned);
73  virtual void StartDragging(const WebDropData& drop_data,
74                             WebKit::WebDragOperationsMask allowed_ops,
75                             const SkBitmap& image,
76                             const gfx::Point& image_offset);
77  virtual void UpdateDragCursor(WebKit::WebDragOperation operation);
78  virtual void GotFocus();
79  virtual void TakeFocus(bool reverse);
80
81  // NotificationObserver implementation ---------------------------------------
82
83  virtual void Observe(NotificationType type,
84                       const NotificationSource& source,
85                       const NotificationDetails& details);
86
87 private:
88  // Insert the given widget into the content area. Should only be used for
89  // web pages and the like (including interstitials and sad tab). Note that
90  // this will be perfectly happy to insert overlapping render views, so care
91  // should be taken that the correct one is hidden/shown.
92  void InsertIntoContentArea(GtkWidget* widget);
93
94  void CancelDragIfAny();
95
96  // Handle focus traversal on the render widget native view.
97  CHROMEGTK_CALLBACK_1(TabContentsViewGtk, gboolean, OnFocus, GtkDirectionType);
98
99  // Used to adjust the size of its children when the size of |expanded_| is
100  // changed.
101  CHROMEGTK_CALLBACK_2(TabContentsViewGtk, void, OnChildSizeRequest,
102                       GtkWidget*, GtkRequisition*);
103
104  // Used to propagate the size change of |expanded_| to our RWHV to resize the
105  // renderer content.
106  CHROMEGTK_CALLBACK_1(TabContentsViewGtk, void, OnSizeAllocate,
107                       GtkAllocation*);
108
109  CHROMEGTK_CALLBACK_1(TabContentsViewGtk, void, OnSetFloatingPosition,
110                       GtkAllocation*);
111
112  // Contains |expanded_| as its GtkBin member.
113  OwnedWidgetGtk floating_;
114
115  // This container holds the tab's web page views. It is a GtkExpandedContainer
116  // so that we can control the size of the web pages.
117  GtkWidget* expanded_;
118
119  // The context menu is reset every time we show it, but we keep a pointer to
120  // between uses so that it won't go out of scope before we're done with it.
121  scoped_ptr<RenderViewContextMenuGtk> context_menu_;
122
123  // Used to get notifications about renderers coming and going.
124  NotificationRegistrar registrar_;
125
126  scoped_ptr<SadTabGtk> sad_tab_;
127
128  FocusStoreGtk focus_store_;
129
130  // The UI for the constrained dialog currently displayed. This is owned by
131  // TabContents, not the view.
132  ConstrainedWindowGtk* constrained_window_;
133
134  // The helper object that handles drag destination related interactions with
135  // GTK.
136  scoped_ptr<WebDragDestGtk> drag_dest_;
137
138  // Object responsible for handling drags from the page for us.
139  scoped_ptr<TabContentsDragSource> drag_source_;
140
141  // The size we want the tab contents view to be.  We keep this in a separate
142  // variable because resizing in GTK+ is async.
143  gfx::Size requested_size_;
144
145  DISALLOW_COPY_AND_ASSIGN(TabContentsViewGtk);
146};
147
148#endif  // CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_VIEW_GTK_H_
149