| OLD | NEW |
| 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" |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 } | 203 } |
| 204 | 204 |
| 205 return false; | 205 return false; |
| 206 } | 206 } |
| 207 | 207 |
| 208 void WebWidgetHost::UpdatePaintRect(const gfx::Rect& rect) { | 208 void WebWidgetHost::UpdatePaintRect(const gfx::Rect& rect) { |
| 209 paint_rect_ = paint_rect_.Union(rect); | 209 paint_rect_ = paint_rect_.Union(rect); |
| 210 } | 210 } |
| 211 | 211 |
| 212 void WebWidgetHost::Paint() { | 212 void WebWidgetHost::Paint() { |
| 213 PaintToCanvas(); | |
| 214 PaintCanvasToView(); | |
| 215 } | |
| 216 | |
| 217 void WebWidgetHost::PaintToCanvas() { | |
| 218 RECT r; | 213 RECT r; |
| 219 GetClientRect(view_, &r); | 214 GetClientRect(view_, &r); |
| 220 gfx::Rect client_rect(r); | 215 gfx::Rect client_rect(r); |
| 221 | 216 |
| 222 // Allocate a canvas if necessary | 217 // Allocate a canvas if necessary |
| 223 if (!canvas_.get()) { | 218 if (!canvas_.get()) { |
| 224 ResetScrollRect(); | 219 ResetScrollRect(); |
| 225 paint_rect_ = client_rect; | 220 paint_rect_ = client_rect; |
| 226 canvas_.reset(new skia::PlatformCanvas( | 221 canvas_.reset(new skia::PlatformCanvas( |
| 227 paint_rect_.width(), paint_rect_.height(), true)); | 222 paint_rect_.width(), paint_rect_.height(), true)); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 249 paint_rect_ = client_rect.Intersect(paint_rect_); | 244 paint_rect_ = client_rect.Intersect(paint_rect_); |
| 250 if (!paint_rect_.IsEmpty()) { | 245 if (!paint_rect_.IsEmpty()) { |
| 251 gfx::Rect rect(paint_rect_); | 246 gfx::Rect rect(paint_rect_); |
| 252 paint_rect_ = gfx::Rect(); | 247 paint_rect_ = gfx::Rect(); |
| 253 | 248 |
| 254 DLOG_IF(WARNING, i == 1) << "painting caused additional invalidations"; | 249 DLOG_IF(WARNING, i == 1) << "painting caused additional invalidations"; |
| 255 PaintRect(rect); | 250 PaintRect(rect); |
| 256 } | 251 } |
| 257 } | 252 } |
| 258 DCHECK(paint_rect_.IsEmpty()); | 253 DCHECK(paint_rect_.IsEmpty()); |
| 259 } | |
| 260 | 254 |
| 261 void WebWidgetHost::PaintCanvasToView() { | 255 // Paint to the screen |
| 262 PAINTSTRUCT ps; | 256 PAINTSTRUCT ps; |
| 263 BeginPaint(view_, &ps); | 257 BeginPaint(view_, &ps); |
| 264 canvas_->getTopPlatformDevice().drawToHDC(ps.hdc, | 258 canvas_->getTopPlatformDevice().drawToHDC(ps.hdc, |
| 265 ps.rcPaint.left, | 259 ps.rcPaint.left, |
| 266 ps.rcPaint.top, | 260 ps.rcPaint.top, |
| 267 &ps.rcPaint); | 261 &ps.rcPaint); |
| 268 EndPaint(view_, &ps); | 262 EndPaint(view_, &ps); |
| 269 | 263 |
| 270 // Draw children | 264 // Draw children |
| 271 UpdateWindow(view_); | 265 UpdateWindow(view_); |
| 272 } | 266 } |
| 273 | 267 |
| 274 void WebWidgetHost::DisplayForRepaint() { | |
| 275 PaintToCanvas(); | |
| 276 | |
| 277 // Paint a gray mask over everything for the repaint Layout tests. | |
| 278 const SkColor kMaskColor = SkColorSetARGB(168, 0, 0, 0); // alpha=0.66 | |
| 279 canvas_->drawColor(kMaskColor, SkPorterDuff::kSrcOver_Mode); | |
| 280 | |
| 281 PaintCanvasToView(); | |
| 282 } | |
| 283 | |
| 284 void WebWidgetHost::Resize(LPARAM lparam) { | 268 void WebWidgetHost::Resize(LPARAM lparam) { |
| 285 // Force an entire re-paint. TODO(darin): Maybe reuse this memory buffer. | 269 // Force an entire re-paint. TODO(darin): Maybe reuse this memory buffer. |
| 286 DiscardBackingStore(); | 270 DiscardBackingStore(); |
| 287 | 271 |
| 288 webwidget_->Resize(gfx::Size(LOWORD(lparam), HIWORD(lparam))); | 272 webwidget_->Resize(gfx::Size(LOWORD(lparam), HIWORD(lparam))); |
| 289 } | 273 } |
| 290 | 274 |
| 291 void WebWidgetHost::MouseEvent(UINT message, WPARAM wparam, LPARAM lparam) { | 275 void WebWidgetHost::MouseEvent(UINT message, WPARAM wparam, LPARAM lparam) { |
| 292 WebMouseEvent event(view_, message, wparam, lparam); | 276 WebMouseEvent event(view_, message, wparam, lparam); |
| 293 switch (event.type) { | 277 switch (event.type) { |
| 294 case WebInputEvent::MOUSE_MOVE: | 278 case WebInputEvent::MOUSE_MOVE: |
| 295 TrackMouseLeave(true); | 279 TrackMouseLeave(true); |
| 296 break; | 280 break; |
| 297 case WebInputEvent::MOUSE_LEAVE: | 281 case WebInputEvent::MOUSE_LEAVE: |
| 298 TrackMouseLeave(false); | 282 TrackMouseLeave(false); |
| 299 break; | 283 break; |
| 300 case WebInputEvent::MOUSE_DOWN: | 284 case WebInputEvent::MOUSE_DOWN: |
| 301 SetCapture(view_); | 285 SetCapture(view_); |
| 302 // This mimics a temporary workaround in RenderWidgetHostViewWin | 286 // This mimics a temporary workaround in RenderWidgetHostViewWin |
| 303 // for bug 765011 to get focus when the mouse is clicked. This | 287 // for bug 765011 to get focus when the mouse is clicked. This |
| 304 // happens after the mouse down event is sent to the renderer | 288 // happens after the mouse down event is sent to the renderer |
| 305 // because normally Windows does a WM_SETFOCUS after WM_LBUTTONDOWN. | 289 // because normally Windows does a WM_SETFOCUS after WM_LBUTTONDOWN. |
| 306 ::SetFocus(view_); | 290 ::SetFocus(view_); |
| 307 break; | 291 break; |
| 308 case WebInputEvent::MOUSE_UP: | 292 case WebInputEvent::MOUSE_UP: |
| 309 if (GetCapture() == view_) | 293 if (GetCapture() == view_) |
| 310 ReleaseCapture(); | 294 ReleaseCapture(); |
| 311 break; | 295 break; |
| 312 } | 296 } |
| 313 webwidget_->HandleInputEvent(&event); | 297 webwidget_->HandleInputEvent(&event); |
| 314 } | 298 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 void WebWidgetHost::PaintRect(const gfx::Rect& rect) { | 341 void WebWidgetHost::PaintRect(const gfx::Rect& rect) { |
| 358 #ifndef NDEBUG | 342 #ifndef NDEBUG |
| 359 DCHECK(!painting_); | 343 DCHECK(!painting_); |
| 360 #endif | 344 #endif |
| 361 DCHECK(canvas_.get()); | 345 DCHECK(canvas_.get()); |
| 362 | 346 |
| 363 set_painting(true); | 347 set_painting(true); |
| 364 webwidget_->Paint(canvas_.get(), rect); | 348 webwidget_->Paint(canvas_.get(), rect); |
| 365 set_painting(false); | 349 set_painting(false); |
| 366 } | 350 } |
| OLD | NEW |