web_contents_view_android.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
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/port/browser/render_view_host_delegate_view.h"
10#include "content/public/browser/web_contents_view.h"
11#include "content/browser/web_contents/web_contents_impl.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 WebContentsView,
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  // WebContentsView implementation --------------------------------------------
32
33  virtual void CreateView(const gfx::Size& initial_size) OVERRIDE;
34  virtual RenderWidgetHostView* CreateViewForWidget(
35      RenderWidgetHost* render_widget_host) OVERRIDE;
36  virtual gfx::NativeView GetNativeView() const OVERRIDE;
37  virtual gfx::NativeView GetContentNativeView() const OVERRIDE;
38  virtual gfx::NativeWindow GetTopLevelNativeWindow() const OVERRIDE;
39  virtual void GetContainerBounds(gfx::Rect* out) const OVERRIDE;
40  virtual void SetPageTitle(const string16& title) OVERRIDE;
41  virtual void OnTabCrashed(base::TerminationStatus status,
42                            int error_code) OVERRIDE;
43  virtual void SizeContents(const gfx::Size& size) OVERRIDE;
44  virtual void RenderViewCreated(RenderViewHost* host) OVERRIDE;
45  virtual void Focus() OVERRIDE;
46  virtual void SetInitialFocus() OVERRIDE;
47  virtual void StoreFocus() OVERRIDE;
48  virtual void RestoreFocus() OVERRIDE;
49  virtual WebDropData* GetDropData() const OVERRIDE;
50  virtual bool IsEventTracking() const OVERRIDE;
51  virtual void CloseTabAfterEventTracking() OVERRIDE;
52  virtual gfx::Rect GetViewBounds() const OVERRIDE;
53
54  // Backend implementation of RenderViewHostDelegateView.
55  virtual void ShowContextMenu(const ContextMenuParams& params,
56                               ContextMenuSourceType type) OVERRIDE;
57  virtual void ShowPopupMenu(const gfx::Rect& bounds,
58                             int item_height,
59                             double item_font_size,
60                             int selected_item,
61                             const std::vector<WebMenuItem>& items,
62                             bool right_aligned,
63                             bool allow_multiple_selection) OVERRIDE;
64  virtual void StartDragging(const WebDropData& drop_data,
65                             WebKit::WebDragOperationsMask allowed_ops,
66                             const gfx::ImageSkia& image,
67                             const gfx::Vector2d& image_offset,
68                             const DragEventSourceInfo& event_info) OVERRIDE;
69  virtual void UpdateDragCursor(WebKit::WebDragOperation operation) OVERRIDE;
70  virtual void GotFocus() OVERRIDE;
71  virtual void TakeFocus(bool reverse) OVERRIDE;
72
73 private:
74  // The WebContents whose contents we display.
75  WebContentsImpl* web_contents_;
76
77  // ContentViewCoreImpl is our interface to the view system.
78  ContentViewCoreImpl* content_view_core_;
79
80  // Interface for extensions to WebContentsView. Used to show the context menu.
81  scoped_ptr<WebContentsViewDelegate> delegate_;
82
83  DISALLOW_COPY_AND_ASSIGN(WebContentsViewAndroid);
84};
85
86} // namespace content
87
88#endif  // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_ANDROID_H_
89