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