Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(985)

Side by Side Diff: chrome/browser/renderer_host/render_widget_host_view_win.h

Issue 7745024: Move RenderWidgetHostViewWin to content. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Fix deps Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_WIN_H_
6 #define CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_WIN_H_
7 #pragma once
8
9 #include <atlbase.h>
10 #include <atlapp.h>
11 #include <atlcrack.h>
12 #include <atlmisc.h>
13
14 #include <vector>
15
16 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/scoped_vector.h"
18 #include "base/task.h"
19 #include "base/win/scoped_comptr.h"
20 #include "content/browser/accessibility/browser_accessibility_manager.h"
21 #include "content/browser/renderer_host/render_widget_host_view.h"
22 #include "content/common/notification_observer.h"
23 #include "content/common/notification_registrar.h"
24 #include "ui/base/win/ime_input.h"
25 #include "ui/gfx/native_widget_types.h"
26 #include "webkit/glue/webcursor.h"
27
28 class BackingStore;
29 class RenderWidgetHost;
30
31 namespace gfx {
32 class Size;
33 class Rect;
34 }
35
36 namespace IPC {
37 class Message;
38 }
39
40 namespace ui {
41 class ViewProp;
42 }
43
44 typedef CWinTraits<WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0>
45 RenderWidgetHostHWNDTraits;
46
47 extern const wchar_t kRenderWidgetHostHWNDClass[];
48
49 ///////////////////////////////////////////////////////////////////////////////
50 // RenderWidgetHostViewWin
51 //
52 // An object representing the "View" of a rendered web page. This object is
53 // responsible for displaying the content of the web page, receiving windows
54 // messages, and containing plugins HWNDs. It is the implementation of the
55 // RenderWidgetHostView that the cross-platform RenderWidgetHost object uses
56 // to display the data.
57 //
58 // Comment excerpted from render_widget_host.h:
59 //
60 // "The lifetime of the RenderWidgetHostHWND is tied to the render process.
61 // If the render process dies, the RenderWidgetHostHWND goes away and all
62 // references to it must become NULL."
63 //
64 class RenderWidgetHostViewWin
65 : public CWindowImpl<RenderWidgetHostViewWin,
66 CWindow,
67 RenderWidgetHostHWNDTraits>,
68 public RenderWidgetHostView,
69 public NotificationObserver,
70 public BrowserAccessibilityDelegate {
71 public:
72 // The view will associate itself with the given widget.
73 explicit RenderWidgetHostViewWin(RenderWidgetHost* widget);
74 virtual ~RenderWidgetHostViewWin();
75
76 void CreateWnd(HWND parent);
77
78 void ScheduleComposite();
79
80 IAccessible* GetIAccessible();
81
82 DECLARE_WND_CLASS_EX(kRenderWidgetHostHWNDClass, CS_DBLCLKS, 0);
83
84 BEGIN_MSG_MAP(RenderWidgetHostHWND)
85 MSG_WM_CREATE(OnCreate)
86 MSG_WM_ACTIVATE(OnActivate)
87 MSG_WM_DESTROY(OnDestroy)
88 MSG_WM_PAINT(OnPaint)
89 MSG_WM_NCPAINT(OnNCPaint)
90 MSG_WM_ERASEBKGND(OnEraseBkgnd)
91 MSG_WM_SETCURSOR(OnSetCursor)
92 MSG_WM_SETFOCUS(OnSetFocus)
93 MSG_WM_KILLFOCUS(OnKillFocus)
94 MSG_WM_CAPTURECHANGED(OnCaptureChanged)
95 MSG_WM_CANCELMODE(OnCancelMode)
96 MSG_WM_INPUTLANGCHANGE(OnInputLangChange)
97 MSG_WM_THEMECHANGED(OnThemeChanged)
98 MSG_WM_NOTIFY(OnNotify)
99 MESSAGE_HANDLER(WM_IME_SETCONTEXT, OnImeSetContext)
100 MESSAGE_HANDLER(WM_IME_STARTCOMPOSITION, OnImeStartComposition)
101 MESSAGE_HANDLER(WM_IME_COMPOSITION, OnImeComposition)
102 MESSAGE_HANDLER(WM_IME_ENDCOMPOSITION, OnImeEndComposition)
103 MESSAGE_HANDLER(WM_MOUSEMOVE, OnMouseEvent)
104 MESSAGE_HANDLER(WM_MOUSELEAVE, OnMouseEvent)
105 MESSAGE_HANDLER(WM_LBUTTONDOWN, OnMouseEvent)
106 MESSAGE_HANDLER(WM_MBUTTONDOWN, OnMouseEvent)
107 MESSAGE_HANDLER(WM_RBUTTONDOWN, OnMouseEvent)
108 MESSAGE_HANDLER(WM_LBUTTONUP, OnMouseEvent)
109 MESSAGE_HANDLER(WM_MBUTTONUP, OnMouseEvent)
110 MESSAGE_HANDLER(WM_RBUTTONUP, OnMouseEvent)
111 MESSAGE_HANDLER(WM_LBUTTONDBLCLK, OnMouseEvent)
112 MESSAGE_HANDLER(WM_MBUTTONDBLCLK, OnMouseEvent)
113 MESSAGE_HANDLER(WM_RBUTTONDBLCLK, OnMouseEvent)
114 MESSAGE_HANDLER(WM_SYSKEYDOWN, OnKeyEvent)
115 MESSAGE_HANDLER(WM_SYSKEYUP, OnKeyEvent)
116 MESSAGE_HANDLER(WM_KEYDOWN, OnKeyEvent)
117 MESSAGE_HANDLER(WM_KEYUP, OnKeyEvent)
118 MESSAGE_HANDLER(WM_MOUSEWHEEL, OnWheelEvent)
119 MESSAGE_HANDLER(WM_MOUSEHWHEEL, OnWheelEvent)
120 MESSAGE_HANDLER(WM_HSCROLL, OnWheelEvent)
121 MESSAGE_HANDLER(WM_VSCROLL, OnWheelEvent)
122 MESSAGE_HANDLER(WM_CHAR, OnKeyEvent)
123 MESSAGE_HANDLER(WM_SYSCHAR, OnKeyEvent)
124 MESSAGE_HANDLER(WM_IME_CHAR, OnKeyEvent)
125 MESSAGE_HANDLER(WM_MOUSEACTIVATE, OnMouseActivate)
126 MESSAGE_HANDLER(WM_GETOBJECT, OnGetObject)
127 MESSAGE_HANDLER(WM_PARENTNOTIFY, OnParentNotify)
128 END_MSG_MAP()
129
130 // Implementation of RenderWidgetHostView:
131 virtual void InitAsPopup(RenderWidgetHostView* parent_host_view,
132 const gfx::Rect& pos) OVERRIDE;
133 virtual void InitAsFullscreen(
134 RenderWidgetHostView* reference_host_view) OVERRIDE;
135 virtual RenderWidgetHost* GetRenderWidgetHost() const OVERRIDE;
136 virtual void DidBecomeSelected() OVERRIDE;
137 virtual void WasHidden() OVERRIDE;
138 virtual void SetSize(const gfx::Size& size) OVERRIDE;
139 virtual void SetBounds(const gfx::Rect& rect) OVERRIDE;
140 virtual gfx::NativeView GetNativeView() const OVERRIDE;
141 virtual gfx::NativeViewId GetNativeViewId() const OVERRIDE;
142 virtual void MovePluginWindows(
143 const std::vector<webkit::npapi::WebPluginGeometry>& moves) OVERRIDE;
144 virtual void Focus() OVERRIDE;
145 virtual void Blur() OVERRIDE;
146 virtual bool HasFocus() OVERRIDE;
147 virtual void Show() OVERRIDE;
148 virtual void Hide() OVERRIDE;
149 virtual bool IsShowing() OVERRIDE;
150 virtual gfx::Rect GetViewBounds() const OVERRIDE;
151 virtual void UpdateCursor(const WebCursor& cursor) OVERRIDE;
152 virtual void SetIsLoading(bool is_loading) OVERRIDE;
153 virtual void ImeUpdateTextInputState(ui::TextInputType type,
154 bool can_compose_inline,
155 const gfx::Rect& caret_rect) OVERRIDE;
156 virtual void ImeCancelComposition() OVERRIDE;
157 virtual void DidUpdateBackingStore(
158 const gfx::Rect& scroll_rect, int scroll_dx, int scroll_dy,
159 const std::vector<gfx::Rect>& copy_rects) OVERRIDE;
160 virtual void RenderViewGone(base::TerminationStatus status,
161 int error_code) OVERRIDE;
162 // called by TabContents before DestroyWindow
163 virtual void WillWmDestroy() OVERRIDE;
164 virtual void Destroy() OVERRIDE;
165 virtual void SetTooltipText(const std::wstring& tooltip_text) OVERRIDE;
166 virtual BackingStore* AllocBackingStore(const gfx::Size& size) OVERRIDE;
167 virtual void SetBackground(const SkBitmap& background) OVERRIDE;
168 virtual void SetVisuallyDeemphasized(const SkColor* color,
169 bool animate) OVERRIDE;
170 virtual void UnhandledWheelEvent(
171 const WebKit::WebMouseWheelEvent& event) OVERRIDE;
172 virtual void SetHasHorizontalScrollbar(
173 bool has_horizontal_scrollbar) OVERRIDE;
174 virtual void SetScrollOffsetPinning(
175 bool is_pinned_to_left, bool is_pinned_to_right) OVERRIDE;
176 virtual gfx::PluginWindowHandle GetCompositingSurface() OVERRIDE;
177 virtual void ShowCompositorHostWindow(bool show) OVERRIDE;
178 virtual void OnAccessibilityNotifications(
179 const std::vector<ViewHostMsg_AccessibilityNotification_Params>& params
180 ) OVERRIDE;
181
182 // Implementation of NotificationObserver:
183 virtual void Observe(int type,
184 const NotificationSource& source,
185 const NotificationDetails& details) OVERRIDE;
186
187 // Implementation of BrowserAccessibilityDelegate:
188 virtual void SetAccessibilityFocus(int acc_obj_id) OVERRIDE;
189 virtual void AccessibilityDoDefaultAction(int acc_obj_id) OVERRIDE;
190
191 protected:
192 // Windows Message Handlers
193 LRESULT OnCreate(CREATESTRUCT* create_struct);
194 void OnActivate(UINT, BOOL, HWND);
195 void OnDestroy();
196 void OnPaint(HDC unused_dc);
197 void OnNCPaint(HRGN update_region);
198 LRESULT OnEraseBkgnd(HDC dc);
199 LRESULT OnSetCursor(HWND window, UINT hittest_code, UINT mouse_message_id);
200 void OnSetFocus(HWND window);
201 void OnKillFocus(HWND window);
202 void OnCaptureChanged(HWND window);
203 void OnCancelMode();
204 void OnInputLangChange(DWORD character_set, HKL input_language_id);
205 void OnThemeChanged();
206 LRESULT OnNotify(int w_param, NMHDR* header);
207 LRESULT OnImeSetContext(
208 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled);
209 LRESULT OnImeStartComposition(
210 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled);
211 LRESULT OnImeComposition(
212 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled);
213 LRESULT OnImeEndComposition(
214 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled);
215 LRESULT OnMouseEvent(
216 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled);
217 LRESULT OnKeyEvent(
218 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled);
219 LRESULT OnWheelEvent(
220 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled);
221 LRESULT OnMouseActivate(UINT message,
222 WPARAM wparam,
223 LPARAM lparam,
224 BOOL& handled);
225 // Handle MSAA requests for accessibility information.
226 LRESULT OnGetObject(UINT message, WPARAM wparam, LPARAM lparam,
227 BOOL& handled);
228 // Handle vertical scrolling
229 LRESULT OnVScroll(int code, short position, HWND scrollbar_control);
230 // Handle horizontal scrolling
231 LRESULT OnHScroll(int code, short position, HWND scrollbar_control);
232
233 LRESULT OnParentNotify(UINT message, WPARAM wparam, LPARAM lparam,
234 BOOL& handled);
235
236 void OnFinalMessage(HWND window);
237
238 private:
239 // Updates the display cursor to the current cursor if the cursor is over this
240 // render view.
241 void UpdateCursorIfOverSelf();
242
243 // Tells Windows that we want to hear about mouse exit messages.
244 void TrackMouseLeave(bool start_tracking);
245
246 // Sends a message to the RenderView in the renderer process.
247 bool Send(IPC::Message* message);
248
249 // Set the tooltip region to the size of the window, creating the tooltip
250 // hwnd if it has not been created yet.
251 void EnsureTooltip();
252
253 // Tooltips become invalid when the root ancestor changes. When the View
254 // becomes hidden, this method is called to reset the tooltip.
255 void ResetTooltip();
256
257 // Sends the specified mouse event to the renderer.
258 void ForwardMouseEventToRenderer(UINT message, WPARAM wparam, LPARAM lparam);
259
260 // Synthesize mouse wheel event.
261 LRESULT SynthesizeMouseWheel(bool is_vertical, int scroll_code,
262 short scroll_position);
263
264 // Shuts down the render_widget_host_. This is a separate function so we can
265 // invoke it from the message loop.
266 void ShutdownHost();
267
268 // Redraws the window synchronously, and any child windows (i.e. plugins)
269 // asynchronously.
270 void Redraw();
271
272 // Draw our background over the given HDC in the given |rect|. The background
273 // will be tiled such that it lines up with existing tiles starting from the
274 // origin of |dc|.
275 void DrawBackground(const RECT& rect, CPaintDC* dc);
276
277 // Create an intermediate window between the given HWND and its parent.
278 HWND ReparentWindow(HWND window);
279
280 // Clean up the compositor window, if needed.
281 void CleanupCompositorWindow();
282
283 // Whether the window should be activated.
284 bool IsActivatable() const;
285
286 // Do initialization needed by both InitAsPopup() and InitAsFullscreen().
287 void DoPopupOrFullscreenInit(HWND parent_hwnd,
288 const gfx::Rect& pos,
289 DWORD ex_style);
290
291 // The associated Model. While |this| is being Destroyed,
292 // |render_widget_host_| is NULL and the Windows message loop is run one last
293 // time. Message handlers must check for a NULL |render_widget_host_|.
294 RenderWidgetHost* render_widget_host_;
295
296 // When we are doing accelerated compositing
297 HWND compositor_host_window_;
298
299 // true if the compositor host window must be hidden after the
300 // software renderered view is updated.
301 bool hide_compositor_window_at_next_paint_;
302
303 // The cursor for the page. This is passed up from the renderer.
304 WebCursor current_cursor_;
305
306 // Indicates if the page is loading.
307 bool is_loading_;
308
309 // true if we are currently tracking WM_MOUSEEXIT messages.
310 bool track_mouse_leave_;
311
312 // Wrapper class for IME input.
313 // (See "ui/base/win/ime_input.h" for its details.)
314 ui::ImeInput ime_input_;
315
316 // Represents whether or not this browser process is receiving status
317 // messages about the focused edit control from a renderer process.
318 bool ime_notification_;
319
320 // true if Enter was hit when render widget host was in focus.
321 bool capture_enter_key_;
322
323 // true if the View is not visible.
324 bool is_hidden_;
325
326 // True if we're in the midst of a paint operation and should respond to
327 // DidPaintRect() notifications by merely invalidating. See comments on
328 // render_widget_host_view.h:DidPaintRect().
329 bool about_to_validate_and_paint_;
330
331 // true if the View should be closed when its HWND is deactivated (used to
332 // support SELECT popups which are closed when they are deactivated).
333 bool close_on_deactivate_;
334
335 // Whether Destroy() has been called. Used to detect a crasher
336 // (http://crbug.com/24248) where render_view_host_ has been deleted when
337 // OnFinalMessage is called.
338 bool being_destroyed_;
339
340 // Tooltips
341 // The text to be shown in the tooltip, supplied by the renderer.
342 std::wstring tooltip_text_;
343 // The tooltip control hwnd
344 HWND tooltip_hwnd_;
345 // Whether or not a tooltip is currently visible. We use this to track
346 // whether or not we want to force-close the tooltip when we receive mouse
347 // move notifications from the renderer. See comment in OnMsgSetTooltipText.
348 bool tooltip_showing_;
349
350 // Factory used to safely scope delayed calls to ShutdownHost().
351 ScopedRunnableMethodFactory<RenderWidgetHostViewWin> shutdown_factory_;
352
353 // Our parent HWND. We keep a reference to it as we SetParent(NULL) when
354 // hidden to prevent getting messages (Paint, Resize...), and we reattach
355 // when shown again.
356 HWND parent_hwnd_;
357
358 // Instance of accessibility information for the root of the MSAA
359 // tree representation of the WebKit render tree.
360 scoped_ptr<BrowserAccessibilityManager> browser_accessibility_manager_;
361
362 // The time at which this view started displaying white pixels as a result of
363 // not having anything to paint (empty backing store from renderer). This
364 // value returns true for is_null() if we are not recording whiteout times.
365 base::TimeTicks whiteout_start_time_;
366
367 // The time it took after this view was selected for it to be fully painted.
368 base::TimeTicks tab_switch_paint_time_;
369
370 // A color we use to shade the entire render view. If 100% transparent, we do
371 // not shade the render view.
372 SkColor overlay_color_;
373
374 // Registrar so we can listen to RENDERER_PROCESS_TERMINATED events.
375 NotificationRegistrar registrar_;
376
377 // Stores the current text input type received by ImeUpdateTextInputState()
378 // method.
379 ui::TextInputType text_input_type_;
380
381 ScopedVector<ui::ViewProp> props_;
382
383 // Is the widget fullscreen?
384 bool is_fullscreen_;
385
386 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewWin);
387 };
388
389 #endif // CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698