| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_H_ | 5 #ifndef CONTENT_PORT_BROWSER_RENDER_WIDGET_HOST_VIEW_PORT_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_H_ | 6 #define CONTENT_PORT_BROWSER_RENDER_WIDGET_HOST_VIEW_PORT_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #if defined(OS_MACOSX) | |
| 10 #include <OpenGL/OpenGL.h> | |
| 11 #endif | |
| 12 | |
| 13 #if defined(TOOLKIT_USES_GTK) | |
| 14 #include <gdk/gdk.h> | |
| 15 #endif | |
| 16 | |
| 17 #include <string> | |
| 18 #include <vector> | |
| 19 | |
| 20 #include "base/memory/scoped_ptr.h" | |
| 21 #include "base/process_util.h" | 9 #include "base/process_util.h" |
| 22 #include "base/callback_forward.h" | 10 #include "base/string16.h" |
| 23 #include "content/common/content_export.h" | 11 #include "content/common/content_export.h" |
| 24 #include "third_party/skia/include/core/SkBitmap.h" | 12 #include "content/public/browser/render_widget_host_view.h" |
| 25 #include "third_party/skia/include/core/SkColor.h" | |
| 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | |
| 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupType.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupType.h" |
| 28 #include "ui/base/ime/text_input_type.h" | 14 #include "ui/base/ime/text_input_type.h" |
| 15 #include "ui/gfx/surface/transport_dib.h" |
| 29 #include "ui/base/range/range.h" | 16 #include "ui/base/range/range.h" |
| 30 #include "ui/gfx/native_widget_types.h" | |
| 31 #include "ui/gfx/surface/transport_dib.h" | |
| 32 | 17 |
| 18 class BackingStore; |
| 19 class WebCursor; |
| 20 |
| 21 struct AccessibilityHostMsg_NotificationParams; |
| 33 struct GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params; | 22 struct GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params; |
| 34 struct GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params; | 23 struct GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params; |
| 35 | |
| 36 class BackingStore; | |
| 37 class BrowserAccessibilityManager; | |
| 38 class RenderWidgetHost; | |
| 39 class WebCursor; | |
| 40 struct AccessibilityHostMsg_NotificationParams; | |
| 41 struct NativeWebKeyboardEvent; | 24 struct NativeWebKeyboardEvent; |
| 42 | 25 |
| 43 namespace content { | |
| 44 class RenderProcessHost; | |
| 45 } | |
| 46 | |
| 47 namespace gfx { | |
| 48 class Rect; | |
| 49 class Size; | |
| 50 } | |
| 51 | |
| 52 namespace webkit { | 26 namespace webkit { |
| 53 namespace npapi { | 27 namespace npapi { |
| 54 struct WebPluginGeometry; | 28 struct WebPluginGeometry; |
| 55 } | 29 } |
| 56 } | 30 } |
| 57 | 31 |
| 58 #if defined(OS_POSIX) || defined(USE_AURA) | 32 #if defined(OS_POSIX) || defined(USE_AURA) |
| 59 namespace WebKit { | 33 namespace WebKit { |
| 60 struct WebScreenInfo; | 34 struct WebScreenInfo; |
| 61 } | 35 } |
| 62 #endif | 36 #endif |
| 63 | 37 |
| 64 // RenderWidgetHostView is an interface implemented by an object that acts as | 38 namespace content { |
| 65 // the "View" portion of a RenderWidgetHost. The RenderWidgetHost and its | |
| 66 // associated RenderProcessHost own the "Model" in this case which is the | |
| 67 // child renderer process. The View is responsible for receiving events from | |
| 68 // the surrounding environment and passing them to the RenderWidgetHost, and | |
| 69 // for actually displaying the content of the RenderWidgetHost when it | |
| 70 // changes. | |
| 71 // | |
| 72 // TODO(joi): Move this to content/public/browser | |
| 73 class CONTENT_EXPORT RenderWidgetHostView { | |
| 74 public: | |
| 75 virtual ~RenderWidgetHostView(); | |
| 76 | |
| 77 // Platform-specific creator. Use this to construct new RenderWidgetHostViews | |
| 78 // rather than using RenderWidgetHostViewWin & friends. | |
| 79 // | |
| 80 // This function must NOT size it, because the RenderView in the renderer | |
| 81 // wouldn't have been created yet. The widget would set its "waiting for | |
| 82 // resize ack" flag, and the ack would never come becasue no RenderView | |
| 83 // received it. | |
| 84 // | |
| 85 // The RenderWidgetHost must already be created (because we can't know if it's | |
| 86 // going to be a regular RenderWidgetHost or a RenderViewHost (a subclass). | |
| 87 static RenderWidgetHostView* CreateViewForWidget( | |
| 88 RenderWidgetHost* widget); | |
| 89 | |
| 90 // Initialize this object for use as a drawing area. |parent_view| may be | |
| 91 // left as NULL on platforms where a parent view is not required to initialize | |
| 92 // a child window. | |
| 93 virtual void InitAsChild(gfx::NativeView parent_view) = 0; | |
| 94 | |
| 95 // Returns the associated RenderWidgetHost. | |
| 96 virtual RenderWidgetHost* GetRenderWidgetHost() const = 0; | |
| 97 | |
| 98 // Tells the View to size itself to the specified size. | |
| 99 virtual void SetSize(const gfx::Size& size) = 0; | |
| 100 | |
| 101 // Tells the View to size and move itself to the specified size and point in | |
| 102 // screen space. | |
| 103 virtual void SetBounds(const gfx::Rect& rect) = 0; | |
| 104 | |
| 105 // Retrieves the native view used to contain plugins and identify the | |
| 106 // renderer in IPC messages. | |
| 107 virtual gfx::NativeView GetNativeView() const = 0; | |
| 108 virtual gfx::NativeViewId GetNativeViewId() const = 0; | |
| 109 virtual gfx::NativeViewAccessible GetNativeViewAccessible() = 0; | |
| 110 | |
| 111 // Set focus to the associated View component. | |
| 112 virtual void Focus() = 0; | |
| 113 // Returns true if the View currently has the focus. | |
| 114 virtual bool HasFocus() const = 0; | |
| 115 | |
| 116 // Shows/hides the view. These must always be called together in pairs. | |
| 117 // It is not legal to call Hide() multiple times in a row. | |
| 118 virtual void Show() = 0; | |
| 119 virtual void Hide() = 0; | |
| 120 | |
| 121 // Whether the view is showing. | |
| 122 virtual bool IsShowing() = 0; | |
| 123 | |
| 124 // Retrieve the bounds of the View, in screen coordinates. | |
| 125 virtual gfx::Rect GetViewBounds() const = 0; | |
| 126 | |
| 127 // Returns true if the View's context menu is showing. | |
| 128 virtual bool IsShowingContextMenu() const = 0; | |
| 129 | |
| 130 // Tells the View whether the context menu is showing. | |
| 131 virtual void SetShowingContextMenu(bool showing) = 0; | |
| 132 | |
| 133 #if defined(OS_MACOSX) | |
| 134 // Set the view's active state (i.e., tint state of controls). | |
| 135 virtual void SetActive(bool active) = 0; | |
| 136 | |
| 137 // Tells the view whether or not to accept first responder status. If |flag| | |
| 138 // is true, the view does not accept first responder status and instead | |
| 139 // manually becomes first responder when it receives a mouse down event. If | |
| 140 // |flag| is false, the view participates in the key-view chain as normal. | |
| 141 virtual void SetTakesFocusOnlyOnMouseDown(bool flag) = 0; | |
| 142 | |
| 143 // Notifies the view that its enclosing window has changed visibility | |
| 144 // (minimized/unminimized, app hidden/unhidden, etc). | |
| 145 // TODO(stuartmorgan): This is a temporary plugin-specific workaround for | |
| 146 // <http://crbug.com/34266>. Once that is fixed, this (and the corresponding | |
| 147 // message and renderer-side handling) can be removed in favor of using | |
| 148 // WasHidden/DidBecomeSelected. | |
| 149 virtual void SetWindowVisibility(bool visible) = 0; | |
| 150 | |
| 151 // Informs the view that its containing window's frame changed. | |
| 152 virtual void WindowFrameChanged() = 0; | |
| 153 #endif // defined(OS_MACOSX) | |
| 154 | |
| 155 #if defined(TOOLKIT_USES_GTK) | |
| 156 // Gets the event for the last mouse down. | |
| 157 virtual GdkEventButton* GetLastMouseDown() = 0; | |
| 158 #if !defined(TOOLKIT_VIEWS) | |
| 159 // Builds a submenu containing all the gtk input method commands. | |
| 160 virtual gfx::NativeView BuildInputMethodsGtkMenu() = 0; | |
| 161 #endif // !defined(TOOLKIT_VIEWS) | |
| 162 #endif // defined(TOOLKIT_USES_GTK) | |
| 163 | |
| 164 // TODO(joi): May be able to move into impl if RWHVMacDelegate stops | |
| 165 // being exposed to Chrome. | |
| 166 virtual void UnhandledWheelEvent(const WebKit::WebMouseWheelEvent& event) = 0; | |
| 167 | |
| 168 // Subclasses should override this method to do what is appropriate to set | |
| 169 // the custom background for their platform. | |
| 170 virtual void SetBackground(const SkBitmap& background) = 0; | |
| 171 virtual const SkBitmap& GetBackground() = 0; | |
| 172 | |
| 173 // TODO(joi): Remove this when we remove the dependency by chrome/ | |
| 174 // on browser_accessibility* files in content. | |
| 175 virtual BrowserAccessibilityManager* | |
| 176 GetBrowserAccessibilityManager() const = 0; | |
| 177 | |
| 178 protected: | |
| 179 RenderWidgetHostView(); | |
| 180 | |
| 181 private: | |
| 182 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostView); | |
| 183 }; | |
| 184 | 39 |
| 185 // This is the larger RenderWidgetHostView interface exposed only | 40 // This is the larger RenderWidgetHostView interface exposed only |
| 186 // within content/, plus some basic implementation. | 41 // within content/ and to embedders looking to port to new platforms. |
| 187 // | 42 class CONTENT_EXPORT RenderWidgetHostViewPort : public RenderWidgetHostView { |
| 188 // TODO(joi): Extract a pure virtual interface from these additional | |
| 189 // methods (named RenderWidgetHostViewPort?), move it to content/port, | |
| 190 // and have content/ use that interface everywhere except where it is | |
| 191 // using concrete implementation classes. The RWHVBase class might | |
| 192 // still exist for shared implementation between existing concrete | |
| 193 // implementations. | |
| 194 class CONTENT_EXPORT RenderWidgetHostViewBase : public RenderWidgetHostView { | |
| 195 public: | 43 public: |
| 196 virtual ~RenderWidgetHostViewBase(); | 44 virtual ~RenderWidgetHostViewPort() {} |
| 197 | 45 |
| 198 // Does the cast for you. | 46 // Does the cast for you. |
| 199 static RenderWidgetHostViewBase* FromRWHV(RenderWidgetHostView* rwhv); | 47 static RenderWidgetHostViewPort* FromRWHV(RenderWidgetHostView* rwhv); |
| 200 | 48 |
| 201 // Convenience function instead of | 49 // Like RenderWidgetHostView::CreateViewForWidget, with cast. |
| 202 // RenderWidgetHostView::CreateViewForWidget if you want a | 50 static RenderWidgetHostViewPort* CreateViewForWidget( |
| 203 // RenderWidgetHostViewBase. | |
| 204 static RenderWidgetHostViewBase* CreateViewForWidget( | |
| 205 RenderWidgetHost* widget); | 51 RenderWidgetHost* widget); |
| 206 | 52 |
| 207 // Perform all the initialization steps necessary for this object to represent | 53 // Perform all the initialization steps necessary for this object to represent |
| 208 // a popup (such as a <select> dropdown), then shows the popup at |pos|. | 54 // a popup (such as a <select> dropdown), then shows the popup at |pos|. |
| 209 virtual void InitAsPopup(RenderWidgetHostView* parent_host_view, | 55 virtual void InitAsPopup(RenderWidgetHostView* parent_host_view, |
| 210 const gfx::Rect& pos) = 0; | 56 const gfx::Rect& pos) = 0; |
| 211 | 57 |
| 212 // Perform all the initialization steps necessary for this object to represent | 58 // Perform all the initialization steps necessary for this object to represent |
| 213 // a full screen window. | 59 // a full screen window. |
| 214 // |reference_host_view| is the view associated with the creating page that | 60 // |reference_host_view| is the view associated with the creating page that |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 // Tells the View to destroy itself. | 120 // Tells the View to destroy itself. |
| 275 virtual void Destroy() = 0; | 121 virtual void Destroy() = 0; |
| 276 | 122 |
| 277 // Tells the View that the tooltip text for the current mouse position over | 123 // Tells the View that the tooltip text for the current mouse position over |
| 278 // the page has changed. | 124 // the page has changed. |
| 279 virtual void SetTooltipText(const string16& tooltip_text) = 0; | 125 virtual void SetTooltipText(const string16& tooltip_text) = 0; |
| 280 | 126 |
| 281 // Notifies the View that the renderer text selection has changed. | 127 // Notifies the View that the renderer text selection has changed. |
| 282 virtual void SelectionChanged(const string16& text, | 128 virtual void SelectionChanged(const string16& text, |
| 283 size_t offset, | 129 size_t offset, |
| 284 const ui::Range& range); | 130 const ui::Range& range) = 0; |
| 285 | 131 |
| 286 // Notifies the View that the renderer selection bounds has changed. | 132 // Notifies the View that the renderer selection bounds has changed. |
| 287 // |start_rect| and |end_rect| are the bounds end of the selection in the | 133 // |start_rect| and |end_rect| are the bounds end of the selection in the |
| 288 // coordinate system of the render view. | 134 // coordinate system of the render view. |
| 289 virtual void SelectionBoundsChanged(const gfx::Rect& start_rect, | 135 virtual void SelectionBoundsChanged(const gfx::Rect& start_rect, |
| 290 const gfx::Rect& end_rect) {} | 136 const gfx::Rect& end_rect) {} |
| 291 | 137 |
| 292 // Allocate a backing store for this view. | 138 // Allocate a backing store for this view. |
| 293 virtual BackingStore* AllocBackingStore(const gfx::Size& size) = 0; | 139 virtual BackingStore* AllocBackingStore(const gfx::Size& size) = 0; |
| 294 | 140 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 // processed (when |processed| is false) or ignored (when |processed| is true) | 228 // processed (when |processed| is false) or ignored (when |processed| is true) |
| 383 virtual void ProcessTouchAck(bool processed) = 0; | 229 virtual void ProcessTouchAck(bool processed) = 0; |
| 384 | 230 |
| 385 virtual void SetHasHorizontalScrollbar(bool has_horizontal_scrollbar) = 0; | 231 virtual void SetHasHorizontalScrollbar(bool has_horizontal_scrollbar) = 0; |
| 386 virtual void SetScrollOffsetPinning( | 232 virtual void SetScrollOffsetPinning( |
| 387 bool is_pinned_to_left, bool is_pinned_to_right) = 0; | 233 bool is_pinned_to_left, bool is_pinned_to_right) = 0; |
| 388 | 234 |
| 389 // Return value indicates whether the mouse is locked successfully or not. | 235 // Return value indicates whether the mouse is locked successfully or not. |
| 390 virtual bool LockMouse() = 0; | 236 virtual bool LockMouse() = 0; |
| 391 virtual void UnlockMouse() = 0; | 237 virtual void UnlockMouse() = 0; |
| 238 virtual bool IsMouseLocked() = 0; |
| 239 |
| 240 virtual void SetPopupType(WebKit::WebPopupType popup_type) = 0; |
| 241 virtual WebKit::WebPopupType GetPopupType() = 0; |
| 392 | 242 |
| 393 virtual void OnAccessibilityNotifications( | 243 virtual void OnAccessibilityNotifications( |
| 394 const std::vector<AccessibilityHostMsg_NotificationParams>& params) { | 244 const std::vector<AccessibilityHostMsg_NotificationParams>& params) { |
| 395 } | 245 } |
| 396 | |
| 397 virtual void SetBackground(const SkBitmap& background) OVERRIDE; | |
| 398 virtual const SkBitmap& GetBackground() OVERRIDE; | |
| 399 | |
| 400 virtual bool IsShowingContextMenu() const OVERRIDE; | |
| 401 virtual void SetShowingContextMenu(bool) OVERRIDE; | |
| 402 | |
| 403 virtual BrowserAccessibilityManager* | |
| 404 GetBrowserAccessibilityManager() const OVERRIDE; | |
| 405 | |
| 406 void set_popup_type(WebKit::WebPopupType popup_type) { | |
| 407 popup_type_ = popup_type; | |
| 408 } | |
| 409 WebKit::WebPopupType popup_type() const { return popup_type_; } | |
| 410 | |
| 411 void SetBrowserAccessibilityManager(BrowserAccessibilityManager* manager); | |
| 412 | |
| 413 bool mouse_locked() const { return mouse_locked_; } | |
| 414 | |
| 415 protected: | |
| 416 // Interface class only, do not construct. | |
| 417 RenderWidgetHostViewBase(); | |
| 418 | |
| 419 // Whether this view is a popup and what kind of popup it is (select, | |
| 420 // autofill...). | |
| 421 WebKit::WebPopupType popup_type_; | |
| 422 | |
| 423 // A custom background to paint behind the web content. This will be tiled | |
| 424 // horizontally. Can be null, in which case we fall back to painting white. | |
| 425 SkBitmap background_; | |
| 426 | |
| 427 // While the mouse is locked, the cursor is hidden from the user. Mouse events | |
| 428 // are still generated. However, the position they report is the last known | |
| 429 // mouse position just as mouse lock was entered; the movement they report | |
| 430 // indicates what the change in position of the mouse would be had it not been | |
| 431 // locked. | |
| 432 bool mouse_locked_; | |
| 433 | |
| 434 // Whether we are showing a context menu. | |
| 435 bool showing_context_menu_; | |
| 436 | |
| 437 // A buffer containing the text inside and around the current selection range. | |
| 438 string16 selection_text_; | |
| 439 | |
| 440 // The offset of the text stored in |selection_text_| relative to the start of | |
| 441 // the web page. | |
| 442 size_t selection_text_offset_; | |
| 443 | |
| 444 // The current selection range relative to the start of the web page. | |
| 445 ui::Range selection_range_; | |
| 446 | |
| 447 private: | |
| 448 // Manager of the tree representation of the WebKit render tree. | |
| 449 scoped_ptr<BrowserAccessibilityManager> browser_accessibility_manager_; | |
| 450 | |
| 451 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewBase); | |
| 452 }; | 246 }; |
| 453 | 247 |
| 454 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_H_ | 248 } // namespace content |
| 249 |
| 250 #endif // CONTENT_PORT_BROWSER_RENDER_WIDGET_HOST_VIEW_PORT_H_ |
| OLD | NEW |