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_PUBLIC_BROWSER_RENDER_WIDGET_HOST_VIEW_H_
6#define CONTENT_PUBLIC_BROWSER_RENDER_WIDGET_HOST_VIEW_H_
7
8#include "base/basictypes.h"
9#include "base/memory/scoped_ptr.h"
10#include "base/strings/string16.h"
11#include "content/common/content_export.h"
12#include "third_party/skia/include/core/SkBitmap.h"
13#include "third_party/skia/include/core/SkRegion.h"
14#include "third_party/WebKit/public/web/WebInputEvent.h"
15#include "ui/gfx/native_widget_types.h"
16
17class GURL;
18
19namespace gfx {
20class Rect;
21class Size;
22}
23
24namespace ui {
25class TextInputClient;
26}
27
28namespace content {
29
30class RenderWidgetHost;
31class RenderWidgetHostViewFrameSubscriber;
32
33// RenderWidgetHostView is an interface implemented by an object that acts as
34// the "View" portion of a RenderWidgetHost. The RenderWidgetHost and its
35// associated RenderProcessHost own the "Model" in this case which is the
36// child renderer process. The View is responsible for receiving events from
37// the surrounding environment and passing them to the RenderWidgetHost, and
38// for actually displaying the content of the RenderWidgetHost when it
39// changes.
40//
41// RenderWidgetHostView Class Hierarchy:
42//   RenderWidgetHostView - Public interface.
43//   RenderWidgetHostViewBase - Common implementation between platforms.
44//   RenderWidgetHostViewAura, ... - Platform specific implementations.
45class CONTENT_EXPORT RenderWidgetHostView {
46 public:
47  virtual ~RenderWidgetHostView() {}
48
49  // Initialize this object for use as a drawing area.  |parent_view| may be
50  // left as NULL on platforms where a parent view is not required to initialize
51  // a child window.
52  virtual void InitAsChild(gfx::NativeView parent_view) = 0;
53
54  // Returns the associated RenderWidgetHost.
55  virtual RenderWidgetHost* GetRenderWidgetHost() const = 0;
56
57  // Tells the View to size itself to the specified size.
58  virtual void SetSize(const gfx::Size& size) = 0;
59
60  // Tells the View to size and move itself to the specified size and point in
61  // screen space.
62  virtual void SetBounds(const gfx::Rect& rect) = 0;
63
64  // Retrieves the last known scroll position.
65  virtual gfx::Vector2dF GetLastScrollOffset() const = 0;
66
67  // Retrieves the native view used to contain plugins and identify the
68  // renderer in IPC messages.
69  virtual gfx::NativeView GetNativeView() const = 0;
70  virtual gfx::NativeViewId GetNativeViewId() const = 0;
71  virtual gfx::NativeViewAccessible GetNativeViewAccessible() = 0;
72
73  // Returns a ui::TextInputClient to support text input or NULL if this RWHV
74  // doesn't support text input.
75  // Note: Not all the platforms use ui::InputMethod and ui::TextInputClient for
76  // text input.  Some platforms (Mac and Android for example) use their own
77  // text input system.
78  virtual ui::TextInputClient* GetTextInputClient() = 0;
79
80  // Set focus to the associated View component.
81  virtual void Focus() = 0;
82  // Returns true if the View currently has the focus.
83  virtual bool HasFocus() const = 0;
84  // Returns true is the current display surface is available.
85  virtual bool IsSurfaceAvailableForCopy() const = 0;
86
87  // Shows/hides the view.  These must always be called together in pairs.
88  // It is not legal to call Hide() multiple times in a row.
89  virtual void Show() = 0;
90  virtual void Hide() = 0;
91
92  // Whether the view is showing.
93  virtual bool IsShowing() = 0;
94
95  // Retrieve the bounds of the View, in screen coordinates.
96  virtual gfx::Rect GetViewBounds() const = 0;
97
98  // Returns true if the View's context menu is showing.
99  virtual bool IsShowingContextMenu() const = 0;
100
101  // Tells the View whether the context menu is showing.
102  virtual void SetShowingContextMenu(bool showing) = 0;
103
104  // Returns the currently selected text.
105  virtual base::string16 GetSelectedText() const = 0;
106
107  // Subclasses should override this method to do what is appropriate to set
108  // the background to be transparent or opaque.
109  virtual void SetBackgroundOpaque(bool opaque) = 0;
110  virtual bool GetBackgroundOpaque() = 0;
111
112  // Return value indicates whether the mouse is locked successfully or not.
113  virtual bool LockMouse() = 0;
114  virtual void UnlockMouse() = 0;
115  // Returns true if the mouse pointer is currently locked.
116  virtual bool IsMouseLocked() = 0;
117
118  // Retrives the size of the viewport for the visible region. May be smaller
119  // than the view size if a portion of the view is obstructed (e.g. by a
120  // virtual keyboard).
121  virtual gfx::Size GetVisibleViewportSize() const = 0;
122
123  // Set insets for the visible region of the root window. Used to compute the
124  // visible viewport.
125  virtual void SetInsets(const gfx::Insets& insets) = 0;
126
127  // Begin subscribing for presentation events and captured frames.
128  // |subscriber| is now owned by this object, it will be called only on the
129  // UI thread.
130  virtual void BeginFrameSubscription(
131      scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) = 0;
132
133  // End subscribing for frame presentation events. FrameSubscriber will be
134  // deleted after this call.
135  virtual void EndFrameSubscription() = 0;
136
137#if defined(OS_MACOSX)
138  // Set the view's active state (i.e., tint state of controls).
139  virtual void SetActive(bool active) = 0;
140
141  // Tells the view whether or not to accept first responder status.  If |flag|
142  // is true, the view does not accept first responder status and instead
143  // manually becomes first responder when it receives a mouse down event.  If
144  // |flag| is false, the view participates in the key-view chain as normal.
145  virtual void SetTakesFocusOnlyOnMouseDown(bool flag) = 0;
146
147  // Notifies the view that its enclosing window has changed visibility
148  // (minimized/unminimized, app hidden/unhidden, etc).
149  // TODO(stuartmorgan): This is a temporary plugin-specific workaround for
150  // <http://crbug.com/34266>. Once that is fixed, this (and the corresponding
151  // message and renderer-side handling) can be removed in favor of using
152  // WasHidden/WasShown.
153  virtual void SetWindowVisibility(bool visible) = 0;
154
155  // Informs the view that its containing window's frame changed.
156  virtual void WindowFrameChanged() = 0;
157
158  // Brings up the dictionary showing a definition for the selected text.
159  virtual void ShowDefinitionForSelection() = 0;
160
161  // Returns |true| if Mac OS X text to speech is supported.
162  virtual bool SupportsSpeech() const = 0;
163  // Tells the view to speak the currently selected text.
164  virtual void SpeakSelection() = 0;
165  // Returns |true| if text is currently being spoken by Mac OS X.
166  virtual bool IsSpeaking() const = 0;
167  // Stops speaking, if it is currently in progress.
168  virtual void StopSpeaking() = 0;
169#endif  // defined(OS_MACOSX)
170};
171
172}  // namespace content
173
174#endif  // CONTENT_PUBLIC_BROWSER_RENDER_WIDGET_HOST_VIEW_H_
175