1 // Copyright (c) 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.
5 #ifndef CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_GTK_H_
6 #define CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_GTK_H_
12 #include "base/memory/scoped_ptr.h"
13 #include "content/common/content_export.h"
14 #include "content/common/drag_event_source_info.h"
15 #include "content/port/browser/render_view_host_delegate_view.h"
16 #include "content/port/browser/web_contents_view_port.h"
17 #include "ui/base/gtk/focus_store_gtk.h"
18 #include "ui/base/gtk/gtk_signal.h"
19 #include "ui/base/gtk/owned_widget_gtk.h"
24 class WebContentsImpl
;
25 class WebContentsViewDelegate
;
26 class WebDragDestDelegate
;
28 class WebDragSourceGtk
;
30 class CONTENT_EXPORT WebContentsViewGtk
31 : public WebContentsViewPort
,
32 public RenderViewHostDelegateView
{
34 // The corresponding WebContentsImpl is passed in the constructor, and manages
35 // our lifetime. This doesn't need to be the case, but is this way currently
36 // because that's what was easiest when they were split. We optionally take
37 // |wrapper| which creates an intermediary widget layer for features from the
38 // Embedding layer that lives with the WebContentsView.
39 WebContentsViewGtk(WebContentsImpl
* web_contents
,
40 WebContentsViewDelegate
* delegate
);
41 virtual ~WebContentsViewGtk();
43 WebContentsViewDelegate
* delegate() const { return delegate_
.get(); }
44 WebContents
* web_contents();
46 // WebContentsView implementation --------------------------------------------
48 virtual gfx::NativeView
GetNativeView() const OVERRIDE
;
49 virtual gfx::NativeView
GetContentNativeView() const OVERRIDE
;
50 virtual gfx::NativeWindow
GetTopLevelNativeWindow() const OVERRIDE
;
51 virtual void GetContainerBounds(gfx::Rect
* out
) const OVERRIDE
;
52 virtual void OnTabCrashed(base::TerminationStatus status
,
53 int error_code
) OVERRIDE
;
54 virtual void SizeContents(const gfx::Size
& size
) OVERRIDE
;
55 virtual void Focus() OVERRIDE
;
56 virtual void SetInitialFocus() OVERRIDE
;
57 virtual void StoreFocus() OVERRIDE
;
58 virtual void RestoreFocus() OVERRIDE
;
59 virtual DropData
* GetDropData() const OVERRIDE
;
60 virtual gfx::Rect
GetViewBounds() const OVERRIDE
;
62 // WebContentsViewPort implementation ----------------------------------------
63 virtual void CreateView(
64 const gfx::Size
& initial_size
, gfx::NativeView context
) OVERRIDE
;
65 virtual RenderWidgetHostView
* CreateViewForWidget(
66 RenderWidgetHost
* render_widget_host
) OVERRIDE
;
67 virtual RenderWidgetHostView
* CreateViewForPopupWidget(
68 RenderWidgetHost
* render_widget_host
) OVERRIDE
;
69 virtual void SetPageTitle(const base::string16
& title
) OVERRIDE
;
70 virtual void RenderViewCreated(RenderViewHost
* host
) OVERRIDE
;
71 virtual void RenderViewSwappedIn(RenderViewHost
* host
) OVERRIDE
;
72 virtual void SetOverscrollControllerEnabled(bool enabled
) OVERRIDE
;
74 // Backend implementation of RenderViewHostDelegateView.
75 virtual void ShowContextMenu(RenderFrameHost
* render_frame_host
,
76 const ContextMenuParams
& params
) OVERRIDE
;
77 virtual void StartDragging(const DropData
& drop_data
,
78 blink::WebDragOperationsMask allowed_ops
,
79 const gfx::ImageSkia
& image
,
80 const gfx::Vector2d
& image_offset
,
81 const DragEventSourceInfo
& event_info
) OVERRIDE
;
82 virtual void UpdateDragCursor(blink::WebDragOperation operation
) OVERRIDE
;
83 virtual void GotFocus() OVERRIDE
;
84 virtual void TakeFocus(bool reverse
) OVERRIDE
;
87 // Insert the given widget into the content area. Should only be used for
88 // web pages and the like (including interstitials and sad tab). Note that
89 // this will be perfectly happy to insert overlapping render views, so care
90 // should be taken that the correct one is hidden/shown.
91 void InsertIntoContentArea(GtkWidget
* widget
);
93 // Replaces, or updates, the existing WebDragDestGtk with one for |new_host|.
94 // This must be called when swapping in, or creating a swapped in, RVH.
95 void UpdateDragDest(RenderViewHost
* new_host
);
97 // Handle focus traversal on the render widget native view. Can be overridden
99 CHROMEGTK_CALLBACK_1(WebContentsViewGtk
, gboolean
, OnFocus
, GtkDirectionType
);
101 // Used to adjust the size of its children when the size of |expanded_| is
103 CHROMEGTK_CALLBACK_2(WebContentsViewGtk
, void, OnChildSizeRequest
,
104 GtkWidget
*, GtkRequisition
*);
106 // Used to propagate the size change of |expanded_| to our RWHV to resize the
108 CHROMEGTK_CALLBACK_1(WebContentsViewGtk
, void, OnSizeAllocate
,
111 // The WebContentsImpl whose contents we display.
112 WebContentsImpl
* web_contents_
;
114 // This container holds the tab's web page views. It is a GtkExpandedContainer
115 // so that we can control the size of the web pages.
116 ui::OwnedWidgetGtk expanded_
;
118 ui::FocusStoreGtk focus_store_
;
120 // The helper object that handles drag destination related interactions with
122 scoped_ptr
<WebDragDestGtk
> drag_dest_
;
124 // Object responsible for handling drags from the page for us.
125 scoped_ptr
<WebDragSourceGtk
> drag_source_
;
127 // Our optional views wrapper. If non-NULL, we return this widget as our
128 // GetNativeView() and insert |expanded_| as its child in the GtkWidget
130 scoped_ptr
<WebContentsViewDelegate
> delegate_
;
132 // The size we want the view to be. We keep this in a separate variable
133 // because resizing in GTK+ is async.
134 gfx::Size requested_size_
;
136 DISALLOW_COPY_AND_ASSIGN(WebContentsViewGtk
);
139 } // namespace content
141 #endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_GTK_H_