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

Side by Side Diff: webkit/tools/test_shell/webwidget_host_win.cc

Issue 149620: Use WebWidget from the WebKit API. This change also makes... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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
« no previous file with comments | « webkit/tools/test_shell/webwidget_host_gtk.cc ('k') | webkit/webkit.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved........... 1 // Copyright (c) 2006-2008 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 #include "webkit/tools/test_shell/webwidget_host.h" 5 #include "webkit/tools/test_shell/webwidget_host.h"
6 6
7 #include "base/gfx/rect.h" 7 #include "base/gfx/rect.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/win_util.h" 9 #include "base/win_util.h"
10 #include "skia/ext/platform_canvas.h" 10 #include "skia/ext/platform_canvas.h"
11 #include "webkit/api/public/WebInputEvent.h" 11 #include "webkit/api/public/WebInputEvent.h"
12 #include "webkit/api/public/WebPopupMenu.h"
12 #include "webkit/api/public/WebScreenInfo.h" 13 #include "webkit/api/public/WebScreenInfo.h"
13 #include "webkit/api/public/WebSize.h" 14 #include "webkit/api/public/WebSize.h"
14 #include "webkit/api/public/win/WebInputEventFactory.h" 15 #include "webkit/api/public/win/WebInputEventFactory.h"
15 #include "webkit/api/public/win/WebScreenInfoFactory.h" 16 #include "webkit/api/public/win/WebScreenInfoFactory.h"
16 #include "webkit/glue/webwidget.h"
17 #include "webkit/tools/test_shell/test_shell.h" 17 #include "webkit/tools/test_shell/test_shell.h"
18 18
19 using WebKit::WebInputEvent; 19 using WebKit::WebInputEvent;
20 using WebKit::WebInputEventFactory; 20 using WebKit::WebInputEventFactory;
21 using WebKit::WebKeyboardEvent; 21 using WebKit::WebKeyboardEvent;
22 using WebKit::WebMouseEvent; 22 using WebKit::WebMouseEvent;
23 using WebKit::WebMouseWheelEvent; 23 using WebKit::WebMouseWheelEvent;
24 using WebKit::WebPopupMenu;
24 using WebKit::WebScreenInfo; 25 using WebKit::WebScreenInfo;
25 using WebKit::WebScreenInfoFactory; 26 using WebKit::WebScreenInfoFactory;
26 using WebKit::WebSize; 27 using WebKit::WebSize;
28 using WebKit::WebWidget;
29 using WebKit::WebWidgetClient;
27 30
28 static const wchar_t kWindowClassName[] = L"WebWidgetHost"; 31 static const wchar_t kWindowClassName[] = L"WebWidgetHost";
29 32
30 /*static*/ 33 /*static*/
31 WebWidgetHost* WebWidgetHost::Create(HWND parent_view, 34 WebWidgetHost* WebWidgetHost::Create(HWND parent_view,
32 WebWidgetDelegate* delegate) { 35 WebWidgetClient* client) {
33 WebWidgetHost* host = new WebWidgetHost(); 36 WebWidgetHost* host = new WebWidgetHost();
34 37
35 static bool registered_class = false; 38 static bool registered_class = false;
36 if (!registered_class) { 39 if (!registered_class) {
37 WNDCLASSEX wcex = {0}; 40 WNDCLASSEX wcex = {0};
38 wcex.cbSize = sizeof(wcex); 41 wcex.cbSize = sizeof(wcex);
39 wcex.style = CS_DBLCLKS; 42 wcex.style = CS_DBLCLKS;
40 wcex.lpfnWndProc = WebWidgetHost::WndProc; 43 wcex.lpfnWndProc = WebWidgetHost::WndProc;
41 wcex.hInstance = GetModuleHandle(NULL); 44 wcex.hInstance = GetModuleHandle(NULL);
42 wcex.hCursor = LoadCursor(NULL, IDC_ARROW); 45 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
43 wcex.lpszClassName = kWindowClassName; 46 wcex.lpszClassName = kWindowClassName;
44 RegisterClassEx(&wcex); 47 RegisterClassEx(&wcex);
45 registered_class = true; 48 registered_class = true;
46 } 49 }
47 50
48 host->view_ = CreateWindowEx(WS_EX_TOOLWINDOW, 51 host->view_ = CreateWindowEx(WS_EX_TOOLWINDOW,
49 kWindowClassName, kWindowClassName, WS_POPUP, 52 kWindowClassName, kWindowClassName, WS_POPUP,
50 0, 0, 0, 0, 53 0, 0, 0, 0,
51 parent_view, NULL, GetModuleHandle(NULL), NULL); 54 parent_view, NULL, GetModuleHandle(NULL), NULL);
52 win_util::SetWindowUserData(host->view_, host); 55 win_util::SetWindowUserData(host->view_, host);
53 56
54 host->webwidget_ = WebWidget::Create(delegate); 57 host->webwidget_ = WebPopupMenu::create(client);
55 58
56 return host; 59 return host;
57 } 60 }
58 61
59 static WebWidgetHost* FromWindow(HWND view) { 62 static WebWidgetHost* FromWindow(HWND view) {
60 return reinterpret_cast<WebWidgetHost*>(win_util::GetWindowUserData(view)); 63 return reinterpret_cast<WebWidgetHost*>(win_util::GetWindowUserData(view));
61 } 64 }
62 65
63 /*static*/ 66 /*static*/
64 LRESULT CALLBACK WebWidgetHost::WndProc(HWND hwnd, UINT message, WPARAM wparam, 67 LRESULT CALLBACK WebWidgetHost::WndProc(HWND hwnd, UINT message, WPARAM wparam,
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 scroll_dx_(0), 194 scroll_dx_(0),
192 scroll_dy_(0) { 195 scroll_dy_(0) {
193 set_painting(false); 196 set_painting(false);
194 } 197 }
195 198
196 WebWidgetHost::~WebWidgetHost() { 199 WebWidgetHost::~WebWidgetHost() {
197 win_util::SetWindowUserData(view_, 0); 200 win_util::SetWindowUserData(view_, 0);
198 201
199 TrackMouseLeave(false); 202 TrackMouseLeave(false);
200 203
201 webwidget_->Close(); 204 webwidget_->close();
202 } 205 }
203 206
204 bool WebWidgetHost::WndProc(UINT message, WPARAM wparam, LPARAM lparam) { 207 bool WebWidgetHost::WndProc(UINT message, WPARAM wparam, LPARAM lparam) {
205 switch (message) { 208 switch (message) {
206 case WM_ACTIVATE: 209 case WM_ACTIVATE:
207 if (wparam == WA_INACTIVE) { 210 if (wparam == WA_INACTIVE) {
208 PostMessage(view_, WM_CLOSE, 0, 0); 211 PostMessage(view_, WM_CLOSE, 0, 0);
209 return true; 212 return true;
210 } 213 }
211 break; 214 break;
(...skipping 13 matching lines...) Expand all
225 228
226 // Allocate a canvas if necessary 229 // Allocate a canvas if necessary
227 if (!canvas_.get()) { 230 if (!canvas_.get()) {
228 ResetScrollRect(); 231 ResetScrollRect();
229 paint_rect_ = client_rect; 232 paint_rect_ = client_rect;
230 canvas_.reset(new skia::PlatformCanvas( 233 canvas_.reset(new skia::PlatformCanvas(
231 paint_rect_.width(), paint_rect_.height(), true)); 234 paint_rect_.width(), paint_rect_.height(), true));
232 } 235 }
233 236
234 // This may result in more invalidation 237 // This may result in more invalidation
235 webwidget_->Layout(); 238 webwidget_->layout();
236 239
237 // Scroll the canvas if necessary 240 // Scroll the canvas if necessary
238 scroll_rect_ = client_rect.Intersect(scroll_rect_); 241 scroll_rect_ = client_rect.Intersect(scroll_rect_);
239 if (!scroll_rect_.IsEmpty()) { 242 if (!scroll_rect_.IsEmpty()) {
240 HDC hdc = canvas_->getTopPlatformDevice().getBitmapDC(); 243 HDC hdc = canvas_->getTopPlatformDevice().getBitmapDC();
241 244
242 RECT damaged_rect, r = scroll_rect_.ToRECT(); 245 RECT damaged_rect, r = scroll_rect_.ToRECT();
243 ScrollDC(hdc, scroll_dx_, scroll_dy_, NULL, &r, NULL, &damaged_rect); 246 ScrollDC(hdc, scroll_dx_, scroll_dy_, NULL, &r, NULL, &damaged_rect);
244 247
245 PaintRect(gfx::Rect(damaged_rect)); 248 PaintRect(gfx::Rect(damaged_rect));
(...skipping 29 matching lines...) Expand all
275 } 278 }
276 279
277 WebScreenInfo WebWidgetHost::GetScreenInfo() { 280 WebScreenInfo WebWidgetHost::GetScreenInfo() {
278 return WebScreenInfoFactory::screenInfo(view_); 281 return WebScreenInfoFactory::screenInfo(view_);
279 } 282 }
280 283
281 void WebWidgetHost::Resize(LPARAM lparam) { 284 void WebWidgetHost::Resize(LPARAM lparam) {
282 // Force an entire re-paint. TODO(darin): Maybe reuse this memory buffer. 285 // Force an entire re-paint. TODO(darin): Maybe reuse this memory buffer.
283 DiscardBackingStore(); 286 DiscardBackingStore();
284 287
285 webwidget_->Resize(WebSize(LOWORD(lparam), HIWORD(lparam))); 288 webwidget_->resize(WebSize(LOWORD(lparam), HIWORD(lparam)));
286 } 289 }
287 290
288 void WebWidgetHost::MouseEvent(UINT message, WPARAM wparam, LPARAM lparam) { 291 void WebWidgetHost::MouseEvent(UINT message, WPARAM wparam, LPARAM lparam) {
289 const WebMouseEvent& event = WebInputEventFactory::mouseEvent( 292 const WebMouseEvent& event = WebInputEventFactory::mouseEvent(
290 view_, message, wparam, lparam); 293 view_, message, wparam, lparam);
291 switch (event.type) { 294 switch (event.type) {
292 case WebInputEvent::MouseMove: 295 case WebInputEvent::MouseMove:
293 TrackMouseLeave(true); 296 TrackMouseLeave(true);
294 break; 297 break;
295 case WebInputEvent::MouseLeave: 298 case WebInputEvent::MouseLeave:
296 TrackMouseLeave(false); 299 TrackMouseLeave(false);
297 break; 300 break;
298 case WebInputEvent::MouseDown: 301 case WebInputEvent::MouseDown:
299 SetCapture(view_); 302 SetCapture(view_);
300 // This mimics a temporary workaround in RenderWidgetHostViewWin for bug 303 // This mimics a temporary workaround in RenderWidgetHostViewWin for bug
301 // 765011 to get focus when the mouse is clicked. This happens after the 304 // 765011 to get focus when the mouse is clicked. This happens after the
302 // mouse down event is sent to the renderer because normally Windows does 305 // mouse down event is sent to the renderer because normally Windows does
303 // a WM_SETFOCUS after WM_LBUTTONDOWN. 306 // a WM_SETFOCUS after WM_LBUTTONDOWN.
304 ::SetFocus(view_); 307 ::SetFocus(view_);
305 break; 308 break;
306 case WebInputEvent::MouseUp: 309 case WebInputEvent::MouseUp:
307 if (GetCapture() == view_) 310 if (GetCapture() == view_)
308 ReleaseCapture(); 311 ReleaseCapture();
309 break; 312 break;
310 } 313 }
311 webwidget_->HandleInputEvent(&event); 314 webwidget_->handleInputEvent(event);
312 } 315 }
313 316
314 void WebWidgetHost::WheelEvent(WPARAM wparam, LPARAM lparam) { 317 void WebWidgetHost::WheelEvent(WPARAM wparam, LPARAM lparam) {
315 const WebMouseWheelEvent& event = WebInputEventFactory::mouseWheelEvent( 318 const WebMouseWheelEvent& event = WebInputEventFactory::mouseWheelEvent(
316 view_, WM_MOUSEWHEEL, wparam, lparam); 319 view_, WM_MOUSEWHEEL, wparam, lparam);
317 webwidget_->HandleInputEvent(&event); 320 webwidget_->handleInputEvent(event);
318 } 321 }
319 322
320 void WebWidgetHost::KeyEvent(UINT message, WPARAM wparam, LPARAM lparam) { 323 void WebWidgetHost::KeyEvent(UINT message, WPARAM wparam, LPARAM lparam) {
321 const WebKeyboardEvent& event = WebInputEventFactory::keyboardEvent( 324 const WebKeyboardEvent& event = WebInputEventFactory::keyboardEvent(
322 view_, message, wparam, lparam); 325 view_, message, wparam, lparam);
323 webwidget_->HandleInputEvent(&event); 326 webwidget_->handleInputEvent(event);
324 } 327 }
325 328
326 void WebWidgetHost::CaptureLostEvent() { 329 void WebWidgetHost::CaptureLostEvent() {
327 webwidget_->MouseCaptureLost(); 330 webwidget_->mouseCaptureLost();
328 } 331 }
329 332
330 void WebWidgetHost::SetFocus(bool enable) { 333 void WebWidgetHost::SetFocus(bool enable) {
331 // Ignore focus calls in layout test mode so that tests don't mess with each 334 // Ignore focus calls in layout test mode so that tests don't mess with each
332 // other's focus when running in parallel. 335 // other's focus when running in parallel.
333 if (!TestShell::layout_test_mode()) 336 if (!TestShell::layout_test_mode())
334 webwidget_->SetFocus(enable); 337 webwidget_->setFocus(enable);
335 } 338 }
336 339
337 void WebWidgetHost::TrackMouseLeave(bool track) { 340 void WebWidgetHost::TrackMouseLeave(bool track) {
338 if (track == track_mouse_leave_) 341 if (track == track_mouse_leave_)
339 return; 342 return;
340 track_mouse_leave_ = track; 343 track_mouse_leave_ = track;
341 344
342 DCHECK(view_); 345 DCHECK(view_);
343 346
344 TRACKMOUSEEVENT tme; 347 TRACKMOUSEEVENT tme;
(...skipping 12 matching lines...) Expand all
357 scroll_dy_ = 0; 360 scroll_dy_ = 0;
358 } 361 }
359 362
360 void WebWidgetHost::PaintRect(const gfx::Rect& rect) { 363 void WebWidgetHost::PaintRect(const gfx::Rect& rect) {
361 #ifndef NDEBUG 364 #ifndef NDEBUG
362 DCHECK(!painting_); 365 DCHECK(!painting_);
363 #endif 366 #endif
364 DCHECK(canvas_.get()); 367 DCHECK(canvas_.get());
365 368
366 set_painting(true); 369 set_painting(true);
367 webwidget_->Paint(canvas_.get(), rect); 370 webwidget_->paint(canvas_.get(), rect);
368 set_painting(false); 371 set_painting(false);
369 } 372 }
OLDNEW
« no previous file with comments | « webkit/tools/test_shell/webwidget_host_gtk.cc ('k') | webkit/webkit.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698