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 17 class GURL; 18 19 namespace gfx { 20 class Rect; 21 class Size; 22 } 23 24 namespace ui { 25 class TextInputClient; 26 } 27 28 namespace content { 29 30 class RenderWidgetHost; 31 class 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. 45 class 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 native view used to contain plugins and identify the 65 // renderer in IPC messages. 66 virtual gfx::NativeView GetNativeView() const = 0; 67 virtual gfx::NativeViewId GetNativeViewId() const = 0; 68 virtual gfx::NativeViewAccessible GetNativeViewAccessible() = 0; 69 70 // Returns a ui::TextInputClient to support text input or NULL if this RWHV 71 // doesn't support text input. 72 // Note: Not all the platforms use ui::InputMethod and ui::TextInputClient for 73 // text input. Some platforms (Mac and Android for example) use their own 74 // text input system. 75 virtual ui::TextInputClient* GetTextInputClient() = 0; 76 77 // Set focus to the associated View component. 78 virtual void Focus() = 0; 79 // Returns true if the View currently has the focus. 80 virtual bool HasFocus() const = 0; 81 // Returns true is the current display surface is available. 82 virtual bool IsSurfaceAvailableForCopy() const = 0; 83 84 // Shows/hides the view. These must always be called together in pairs. 85 // It is not legal to call Hide() multiple times in a row. 86 virtual void Show() = 0; 87 virtual void Hide() = 0; 88 89 // Whether the view is showing. 90 virtual bool IsShowing() = 0; 91 92 // Retrieve the bounds of the View, in screen coordinates. 93 virtual gfx::Rect GetViewBounds() const = 0; 94 95 // Returns true if the View's context menu is showing. 96 virtual bool IsShowingContextMenu() const = 0; 97 98 // Tells the View whether the context menu is showing. 99 virtual void SetShowingContextMenu(bool showing) = 0; 100 101 // Returns the currently selected text. 102 virtual base::string16 GetSelectedText() const = 0; 103 104 // Subclasses should override this method to do what is appropriate to set 105 // the background to be transparent or opaque. 106 virtual void SetBackgroundOpaque(bool opaque) = 0; 107 virtual bool GetBackgroundOpaque() = 0; 108 109 // Return value indicates whether the mouse is locked successfully or not. 110 virtual bool LockMouse() = 0; 111 virtual void UnlockMouse() = 0; 112 // Returns true if the mouse pointer is currently locked. 113 virtual bool IsMouseLocked() = 0; 114 115 // Retrives the size of the viewport for the visible region. May be smaller 116 // than the view size if a portion of the view is obstructed (e.g. by a 117 // virtual keyboard). 118 virtual gfx::Size GetVisibleViewportSize() const = 0; 119 120 // Set insets for the visible region of the root window. Used to compute the 121 // visible viewport. 122 virtual void SetInsets(const gfx::Insets& insets) = 0; 123 124 // Begin subscribing for presentation events and captured frames. 125 // |subscriber| is now owned by this object, it will be called only on the 126 // UI thread. 127 virtual void BeginFrameSubscription( 128 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) = 0; 129 130 // End subscribing for frame presentation events. FrameSubscriber will be 131 // deleted after this call. 132 virtual void EndFrameSubscription() = 0; 133 134 #if defined(OS_MACOSX) 135 // Set the view's active state (i.e., tint state of controls). 136 virtual void SetActive(bool active) = 0; 137 138 // Tells the view whether or not to accept first responder status. If |flag| 139 // is true, the view does not accept first responder status and instead 140 // manually becomes first responder when it receives a mouse down event. If 141 // |flag| is false, the view participates in the key-view chain as normal. 142 virtual void SetTakesFocusOnlyOnMouseDown(bool flag) = 0; 143 144 // Notifies the view that its enclosing window has changed visibility 145 // (minimized/unminimized, app hidden/unhidden, etc). 146 // TODO(stuartmorgan): This is a temporary plugin-specific workaround for 147 // <http://crbug.com/34266>. Once that is fixed, this (and the corresponding 148 // message and renderer-side handling) can be removed in favor of using 149 // WasHidden/WasShown. 150 virtual void SetWindowVisibility(bool visible) = 0; 151 152 // Informs the view that its containing window's frame changed. 153 virtual void WindowFrameChanged() = 0; 154 155 // Brings up the dictionary showing a definition for the selected text. 156 virtual void ShowDefinitionForSelection() = 0; 157 158 // Returns |true| if Mac OS X text to speech is supported. 159 virtual bool SupportsSpeech() const = 0; 160 // Tells the view to speak the currently selected text. 161 virtual void SpeakSelection() = 0; 162 // Returns |true| if text is currently being spoken by Mac OS X. 163 virtual bool IsSpeaking() const = 0; 164 // Stops speaking, if it is currently in progress. 165 virtual void StopSpeaking() = 0; 166 #endif // defined(OS_MACOSX) 167 }; 168 169 } // namespace content 170 171 #endif // CONTENT_PUBLIC_BROWSER_RENDER_WIDGET_HOST_VIEW_H_ 172