web_contents_view_android.h revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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.
4
5#ifndef CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_ANDROID_H_
6#define CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_ANDROID_H_
7
8#include "base/memory/scoped_ptr.h"
9#include "content/browser/web_contents/web_contents_impl.h"
10#include "content/port/browser/render_view_host_delegate_view.h"
11#include "content/port/browser/web_contents_view_port.h"
12#include "content/public/browser/web_contents_view_delegate.h"
13#include "content/public/common/context_menu_params.h"
14
15namespace content {
16class ContentViewCoreImpl;
17
18// Android-specific implementation of the WebContentsView.
19class WebContentsViewAndroid : public WebContentsViewPort,
20                               public RenderViewHostDelegateView {
21 public:
22  WebContentsViewAndroid(WebContentsImpl* web_contents,
23                         WebContentsViewDelegate* delegate);
24  virtual ~WebContentsViewAndroid();
25
26  // Sets the interface to the view system. ContentViewCoreImpl is owned
27  // by its Java ContentViewCore counterpart, whose lifetime is managed
28  // by the UI frontend.
29  void SetContentViewCore(ContentViewCoreImpl* content_view_core);
30
31  void RequestExternalVideoSurface(int player_id);
32
33  // WebContentsView implementation --------------------------------------------
34  virtual gfx::NativeView GetNativeView() const OVERRIDE;
35  virtual gfx::NativeView GetContentNativeView() const OVERRIDE;
36  virtual gfx::NativeWindow GetTopLevelNativeWindow() const OVERRIDE;
37  virtual void GetContainerBounds(gfx::Rect* out) const OVERRIDE;
38  virtual void OnTabCrashed(base::TerminationStatus status,
39                            int error_code) OVERRIDE;
40  virtual void SizeContents(const gfx::Size& size) OVERRIDE;
41  virtual void Focus() OVERRIDE;
42  virtual void SetInitialFocus() OVERRIDE;
43  virtual void StoreFocus() OVERRIDE;
44  virtual void RestoreFocus() OVERRIDE;
45  virtual WebDropData* GetDropData() const OVERRIDE;
46  virtual gfx::Rect GetViewBounds() const OVERRIDE;
47
48  // WebContentsViewPort implementation ----------------------------------------
49  virtual void CreateView(
50      const gfx::Size& initial_size, gfx::NativeView context) OVERRIDE;
51  virtual RenderWidgetHostView* CreateViewForWidget(
52      RenderWidgetHost* render_widget_host) OVERRIDE;
53  virtual RenderWidgetHostView* CreateViewForPopupWidget(
54      RenderWidgetHost* render_widget_host) OVERRIDE;
55  virtual void SetPageTitle(const string16& title) OVERRIDE;
56  virtual void RenderViewCreated(RenderViewHost* host) OVERRIDE;
57  virtual void RenderViewSwappedIn(RenderViewHost* host) OVERRIDE;
58  virtual void SetOverscrollControllerEnabled(bool enabled) OVERRIDE;
59
60  // Backend implementation of RenderViewHostDelegateView.
61  virtual void ShowContextMenu(const ContextMenuParams& params,
62                               ContextMenuSourceType type) OVERRIDE;
63  virtual void ShowPopupMenu(const gfx::Rect& bounds,
64                             int item_height,
65                             double item_font_size,
66                             int selected_item,
67                             const std::vector<WebMenuItem>& items,
68                             bool right_aligned,
69                             bool allow_multiple_selection) OVERRIDE;
70  virtual void StartDragging(const WebDropData& drop_data,
71                             WebKit::WebDragOperationsMask allowed_ops,
72                             const gfx::ImageSkia& image,
73                             const gfx::Vector2d& image_offset,
74                             const DragEventSourceInfo& event_info) OVERRIDE;
75  virtual void UpdateDragCursor(WebKit::WebDragOperation operation) OVERRIDE;
76  virtual void GotFocus() OVERRIDE;
77  virtual void TakeFocus(bool reverse) OVERRIDE;
78
79 private:
80  // The WebContents whose contents we display.
81  WebContentsImpl* web_contents_;
82
83  // ContentViewCoreImpl is our interface to the view system.
84  ContentViewCoreImpl* content_view_core_;
85
86  // Interface for extensions to WebContentsView. Used to show the context menu.
87  scoped_ptr<WebContentsViewDelegate> delegate_;
88
89  DISALLOW_COPY_AND_ASSIGN(WebContentsViewAndroid);
90};
91
92} // namespace content
93
94#endif  // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_ANDROID_H_
95