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_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_BASE_H_ 6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_BASE_H_ 7 8 #if defined(OS_MACOSX) 9 #include <OpenGL/OpenGL.h> 10 #endif 11 12 #if defined(TOOLKIT_GTK) 13 #include <gdk/gdk.h> 14 #endif 15 16 #include <string> 17 #include <vector> 18 19 #include "base/memory/scoped_ptr.h" 20 #include "base/callback_forward.h" 21 #include "content/common/content_export.h" 22 #include "content/port/browser/render_widget_host_view_port.h" 23 #include "ui/base/range/range.h" 24 #include "ui/gfx/native_widget_types.h" 25 #include "ui/gfx/rect.h" 26 27 namespace content { 28 29 class RenderWidgetHostImpl; 30 31 // Basic implementation shared by concrete RenderWidgetHostView 32 // subclasses. 33 // 34 // Note that nothing should use this class, except concrete subclasses 35 // that are deriving from it, and code that is written specifically to 36 // use one of these concrete subclasses (i.e. platform-specific code). 37 // 38 // To enable embedders that add ports, everything else in content/ 39 // should use the RenderWidgetHostViewPort interface. 40 // 41 // RenderWidgetHostView class hierarchy described in render_widget_host_view.h. 42 class CONTENT_EXPORT RenderWidgetHostViewBase 43 : public RenderWidgetHostViewPort { 44 public: 45 virtual ~RenderWidgetHostViewBase(); 46 47 // RenderWidgetHostViewPort implementation. 48 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; 49 virtual void SelectionChanged(const string16& text, 50 size_t offset, 51 const ui::Range& range) OVERRIDE; 52 virtual void SetBackground(const SkBitmap& background) OVERRIDE; 53 virtual const SkBitmap& GetBackground() OVERRIDE; 54 virtual gfx::Size GetPhysicalBackingSize() const OVERRIDE; 55 virtual float GetOverdrawBottomHeight() const OVERRIDE; 56 virtual bool IsShowingContextMenu() const OVERRIDE; 57 virtual void SetShowingContextMenu(bool showing_menu) OVERRIDE; 58 virtual string16 GetSelectedText() const OVERRIDE; 59 virtual bool IsMouseLocked() OVERRIDE; 60 virtual void UnhandledWheelEvent( 61 const WebKit::WebMouseWheelEvent& event) OVERRIDE; 62 virtual InputEventAckState FilterInputEvent( 63 const WebKit::WebInputEvent& input_event) OVERRIDE; 64 virtual void GestureEventAck(int gesture_event_type, 65 InputEventAckState ack_result) OVERRIDE; 66 virtual void SetPopupType(WebKit::WebPopupType popup_type) OVERRIDE; 67 virtual WebKit::WebPopupType GetPopupType() OVERRIDE; 68 virtual BrowserAccessibilityManager* 69 GetBrowserAccessibilityManager() const OVERRIDE; 70 virtual void ProcessAckedTouchEvent(const TouchEventWithLatencyInfo& touch, 71 InputEventAckState ack_result) OVERRIDE; 72 virtual SmoothScrollGesture* CreateSmoothScrollGesture( 73 bool scroll_down, int pixels_to_scroll, int mouse_event_x, 74 int mouse_event_y) OVERRIDE; 75 virtual bool CanSubscribeFrame() const OVERRIDE; 76 virtual void BeginFrameSubscription( 77 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) OVERRIDE; 78 virtual void EndFrameSubscription() OVERRIDE; 79 virtual void OnSwapCompositorFrame( 80 uint32 output_surface_id, 81 scoped_ptr<cc::CompositorFrame> frame) OVERRIDE {} 82 virtual void OnOverscrolled(gfx::Vector2dF accumulated_overscroll, 83 gfx::Vector2dF current_fling_velocity) OVERRIDE; 84 virtual uint32 RendererFrameNumber() OVERRIDE; 85 virtual void DidReceiveRendererFrame() OVERRIDE; 86 87 void SetBrowserAccessibilityManager(BrowserAccessibilityManager* manager); 88 89 // Notification that a resize or move session ended on the native widget. 90 void UpdateScreenInfo(gfx::NativeView view); 91 92 // Tells if the display property (work area/scale factor) has 93 // changed since the last time. 94 bool HasDisplayPropertyChanged(gfx::NativeView view); 95 96 #if defined(OS_WIN) 97 // The callback that DetachPluginsHelper calls for each child window. Call 98 // this directly if you want to do custom filtering on plugin windows first. 99 static void DetachPluginWindowsCallback(HWND window); 100 #endif 101 102 protected: 103 // Interface class only, do not construct. 104 RenderWidgetHostViewBase(); 105 106 #if defined(OS_WIN) 107 // Shared implementation of MovePluginWindows for use by win and aura/wina. 108 static void MovePluginWindowsHelper( 109 HWND parent, 110 const std::vector<WebPluginGeometry>& moves); 111 112 static void PaintPluginWindowsHelper( 113 HWND parent, 114 const gfx::Rect& damaged_screen_rect); 115 116 // Needs to be called before the HWND backing the view goes away to avoid 117 // crashes in Windowed plugins. 118 static void DetachPluginsHelper(HWND parent); 119 #endif 120 121 // Whether this view is a popup and what kind of popup it is (select, 122 // autofill...). 123 WebKit::WebPopupType popup_type_; 124 125 // A custom background to paint behind the web content. This will be tiled 126 // horizontally. Can be null, in which case we fall back to painting white. 127 SkBitmap background_; 128 129 // While the mouse is locked, the cursor is hidden from the user. Mouse events 130 // are still generated. However, the position they report is the last known 131 // mouse position just as mouse lock was entered; the movement they report 132 // indicates what the change in position of the mouse would be had it not been 133 // locked. 134 bool mouse_locked_; 135 136 // Whether we are showing a context menu. 137 bool showing_context_menu_; 138 139 // A buffer containing the text inside and around the current selection range. 140 string16 selection_text_; 141 142 // The offset of the text stored in |selection_text_| relative to the start of 143 // the web page. 144 size_t selection_text_offset_; 145 146 // The current selection range relative to the start of the web page. 147 ui::Range selection_range_; 148 149 protected: 150 // The scale factor of the display the renderer is currently on. 151 float current_device_scale_factor_; 152 153 private: 154 // Manager of the tree representation of the WebKit render tree. 155 scoped_ptr<BrowserAccessibilityManager> browser_accessibility_manager_; 156 157 gfx::Rect current_display_area_; 158 159 uint32 renderer_frame_number_; 160 161 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewBase); 162 }; 163 164 } // namespace content 165 166 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_BASE_H_ 167