render_widget_host_view.h revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
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/strings/string16.h"
10#include "content/common/content_export.h"
11#include "third_party/skia/include/core/SkBitmap.h"
12#include "third_party/skia/include/core/SkRegion.h"
13#include "third_party/WebKit/public/web/WebInputEvent.h"
14#include "ui/gfx/native_widget_types.h"
15
16#if defined(TOOLKIT_GTK)
17#include <gdk/gdk.h>
18#endif
19
20class GURL;
21
22namespace gfx {
23class Rect;
24class Size;
25}
26
27namespace content {
28
29class BrowserAccessibilityManager;
30class RenderWidgetHost;
31
32// RenderWidgetHostView is an interface implemented by an object that acts as
33// the "View" portion of a RenderWidgetHost. The RenderWidgetHost and its
34// associated RenderProcessHost own the "Model" in this case which is the
35// child renderer process. The View is responsible for receiving events from
36// the surrounding environment and passing them to the RenderWidgetHost, and
37// for actually displaying the content of the RenderWidgetHost when it
38// changes.
39//
40// RenderWidgetHostView Class Hierarchy:
41//   RenderWidgetHostView - Public interface.
42//   RenderWidgetHostViewPort - Private interface for content/ and ports.
43//   RenderWidgetHostViewBase - Common implementation between platforms.
44//   RenderWidgetHostViewWin, ... - Platform specific implementations.
45class CONTENT_EXPORT RenderWidgetHostView {
46 public:
47  virtual ~RenderWidgetHostView() {}
48
49  // Platform-specific creator. Use this to construct new RenderWidgetHostViews
50  // rather than using RenderWidgetHostViewWin & friends.
51  //
52  // This function must NOT size it, because the RenderView in the renderer
53  // wouldn't have been created yet. The widget would set its "waiting for
54  // resize ack" flag, and the ack would never come becasue no RenderView
55  // received it.
56  //
57  // The RenderWidgetHost must already be created (because we can't know if it's
58  // going to be a regular RenderWidgetHost or a RenderViewHost (a subclass).
59  static RenderWidgetHostView* CreateViewForWidget(
60      RenderWidgetHost* widget);
61
62  // Initialize this object for use as a drawing area.  |parent_view| may be
63  // left as NULL on platforms where a parent view is not required to initialize
64  // a child window.
65  virtual void InitAsChild(gfx::NativeView parent_view) = 0;
66
67  // Returns the associated RenderWidgetHost.
68  virtual RenderWidgetHost* GetRenderWidgetHost() const = 0;
69
70  // Tells the View to size itself to the specified size.
71  virtual void SetSize(const gfx::Size& size) = 0;
72
73  // Tells the View to size and move itself to the specified size and point in
74  // screen space.
75  virtual void SetBounds(const gfx::Rect& rect) = 0;
76
77  // Retrieves the native view used to contain plugins and identify the
78  // renderer in IPC messages.
79  virtual gfx::NativeView GetNativeView() const = 0;
80  virtual gfx::NativeViewId GetNativeViewId() const = 0;
81  virtual gfx::NativeViewAccessible GetNativeViewAccessible() = 0;
82
83  // Set focus to the associated View component.
84  virtual void Focus() = 0;
85  // Returns true if the View currently has the focus.
86  virtual bool HasFocus() const = 0;
87  // Returns true is the current display surface is available.
88  virtual bool IsSurfaceAvailableForCopy() const = 0;
89
90  // Shows/hides the view.  These must always be called together in pairs.
91  // It is not legal to call Hide() multiple times in a row.
92  virtual void Show() = 0;
93  virtual void Hide() = 0;
94
95  // Whether the view is showing.
96  virtual bool IsShowing() = 0;
97
98  // Retrieve the bounds of the View, in screen coordinates.
99  virtual gfx::Rect GetViewBounds() const = 0;
100
101  // Returns true if the View's context menu is showing.
102  virtual bool IsShowingContextMenu() const = 0;
103
104  // Tells the View whether the context menu is showing.
105  virtual void SetShowingContextMenu(bool showing) = 0;
106
107  // Returns the currently selected text.
108  virtual base::string16 GetSelectedText() const = 0;
109
110  // Subclasses should override this method to do what is appropriate to set
111  // the custom background for their platform.
112  virtual void SetBackground(const SkBitmap& background) = 0;
113  virtual const SkBitmap& GetBackground() = 0;
114
115  // Return value indicates whether the mouse is locked successfully or not.
116  virtual bool LockMouse() = 0;
117  virtual void UnlockMouse() = 0;
118  // Returns true if the mouse pointer is currently locked.
119  virtual bool IsMouseLocked() = 0;
120
121#if defined(OS_MACOSX)
122  // Set the view's active state (i.e., tint state of controls).
123  virtual void SetActive(bool active) = 0;
124
125  // Tells the view whether or not to accept first responder status.  If |flag|
126  // is true, the view does not accept first responder status and instead
127  // manually becomes first responder when it receives a mouse down event.  If
128  // |flag| is false, the view participates in the key-view chain as normal.
129  virtual void SetTakesFocusOnlyOnMouseDown(bool flag) = 0;
130
131  // Notifies the view that its enclosing window has changed visibility
132  // (minimized/unminimized, app hidden/unhidden, etc).
133  // TODO(stuartmorgan): This is a temporary plugin-specific workaround for
134  // <http://crbug.com/34266>. Once that is fixed, this (and the corresponding
135  // message and renderer-side handling) can be removed in favor of using
136  // WasHidden/WasShown.
137  virtual void SetWindowVisibility(bool visible) = 0;
138
139  // Informs the view that its containing window's frame changed.
140  virtual void WindowFrameChanged() = 0;
141
142  // Brings up the dictionary showing a definition for the selected text.
143  virtual void ShowDefinitionForSelection() = 0;
144
145  // Returns |true| if Mac OS X text to speech is supported.
146  virtual bool SupportsSpeech() const = 0;
147  // Tells the view to speak the currently selected text.
148  virtual void SpeakSelection() = 0;
149  // Returns |true| if text is currently being spoken by Mac OS X.
150  virtual bool IsSpeaking() const = 0;
151  // Stops speaking, if it is currently in progress.
152  virtual void StopSpeaking() = 0;
153#endif  // defined(OS_MACOSX)
154
155#if defined(TOOLKIT_GTK)
156  // Gets the event for the last mouse down.
157  virtual GdkEventButton* GetLastMouseDown() = 0;
158  // Builds a submenu containing all the gtk input method commands.
159  virtual gfx::NativeView BuildInputMethodsGtkMenu() = 0;
160#endif  // defined(TOOLKIT_GTK)
161
162#if defined(OS_WIN) && !defined(USE_AURA)
163  // The region specified will be transparent to mouse clicks.
164  virtual void SetClickthroughRegion(SkRegion* region) = 0;
165#endif
166};
167
168}  // namespace content
169
170#endif  // CONTENT_PUBLIC_BROWSER_RENDER_WIDGET_HOST_VIEW_H_
171