| 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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 } | 200 } |
| 201 | 201 |
| 202 return false; | 202 return false; |
| 203 } | 203 } |
| 204 | 204 |
| 205 void WebWidgetHost::UpdatePaintRect(const gfx::Rect& rect) { | 205 void WebWidgetHost::UpdatePaintRect(const gfx::Rect& rect) { |
| 206 paint_rect_ = paint_rect_.Union(rect); | 206 paint_rect_ = paint_rect_.Union(rect); |
| 207 } | 207 } |
| 208 | 208 |
| 209 void WebWidgetHost::Paint() { | 209 void WebWidgetHost::Paint() { |
| 210 PaintToCanvas(); |
| 211 PaintCanvasToView(); |
| 212 } |
| 213 |
| 214 void WebWidgetHost::PaintToCanvas() { |
| 210 RECT r; | 215 RECT r; |
| 211 GetClientRect(view_, &r); | 216 GetClientRect(view_, &r); |
| 212 gfx::Rect client_rect(r); | 217 gfx::Rect client_rect(r); |
| 213 | 218 |
| 214 // Allocate a canvas if necessary | 219 // Allocate a canvas if necessary |
| 215 if (!canvas_.get()) { | 220 if (!canvas_.get()) { |
| 216 ResetScrollRect(); | 221 ResetScrollRect(); |
| 217 paint_rect_ = client_rect; | 222 paint_rect_ = client_rect; |
| 218 canvas_.reset(new skia::PlatformCanvas( | 223 canvas_.reset(new skia::PlatformCanvas( |
| 219 paint_rect_.width(), paint_rect_.height(), true)); | 224 paint_rect_.width(), paint_rect_.height(), true)); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 241 paint_rect_ = client_rect.Intersect(paint_rect_); | 246 paint_rect_ = client_rect.Intersect(paint_rect_); |
| 242 if (!paint_rect_.IsEmpty()) { | 247 if (!paint_rect_.IsEmpty()) { |
| 243 gfx::Rect rect(paint_rect_); | 248 gfx::Rect rect(paint_rect_); |
| 244 paint_rect_ = gfx::Rect(); | 249 paint_rect_ = gfx::Rect(); |
| 245 | 250 |
| 246 DLOG_IF(WARNING, i == 1) << "painting caused additional invalidations"; | 251 DLOG_IF(WARNING, i == 1) << "painting caused additional invalidations"; |
| 247 PaintRect(rect); | 252 PaintRect(rect); |
| 248 } | 253 } |
| 249 } | 254 } |
| 250 DCHECK(paint_rect_.IsEmpty()); | 255 DCHECK(paint_rect_.IsEmpty()); |
| 256 } |
| 251 | 257 |
| 252 // Paint to the screen | 258 void WebWidgetHost::PaintCanvasToView() { |
| 253 PAINTSTRUCT ps; | 259 PAINTSTRUCT ps; |
| 254 BeginPaint(view_, &ps); | 260 BeginPaint(view_, &ps); |
| 255 canvas_->getTopPlatformDevice().drawToHDC(ps.hdc, | 261 canvas_->getTopPlatformDevice().drawToHDC(ps.hdc, |
| 256 ps.rcPaint.left, | 262 ps.rcPaint.left, |
| 257 ps.rcPaint.top, | 263 ps.rcPaint.top, |
| 258 &ps.rcPaint); | 264 &ps.rcPaint); |
| 259 EndPaint(view_, &ps); | 265 EndPaint(view_, &ps); |
| 260 | 266 |
| 261 // Draw children | 267 // Draw children |
| 262 UpdateWindow(view_); | 268 UpdateWindow(view_); |
| 263 } | 269 } |
| 264 | 270 |
| 271 void WebWidgetHost::DisplayForRepaint() { |
| 272 PaintToCanvas(); |
| 273 |
| 274 // Paint a gray mask over everything for the repaint Layout tests. |
| 275 const SkColor kMaskColor = SkColorSetARGB(168, 0, 0, 0); // alpha=0.66 |
| 276 canvas_->drawColor(kMaskColor, SkPorterDuff::kSrcOver_Mode); |
| 277 |
| 278 PaintCanvasToView(); |
| 279 } |
| 280 |
| 265 void WebWidgetHost::Resize(LPARAM lparam) { | 281 void WebWidgetHost::Resize(LPARAM lparam) { |
| 266 // Force an entire re-paint. TODO(darin): Maybe reuse this memory buffer. | 282 // Force an entire re-paint. TODO(darin): Maybe reuse this memory buffer. |
| 267 DiscardBackingStore(); | 283 DiscardBackingStore(); |
| 268 | 284 |
| 269 webwidget_->Resize(gfx::Size(LOWORD(lparam), HIWORD(lparam))); | 285 webwidget_->Resize(gfx::Size(LOWORD(lparam), HIWORD(lparam))); |
| 270 } | 286 } |
| 271 | 287 |
| 272 void WebWidgetHost::MouseEvent(UINT message, WPARAM wparam, LPARAM lparam) { | 288 void WebWidgetHost::MouseEvent(UINT message, WPARAM wparam, LPARAM lparam) { |
| 273 WebMouseEvent event(view_, message, wparam, lparam); | 289 WebMouseEvent event(view_, message, wparam, lparam); |
| 274 switch (event.type) { | 290 switch (event.type) { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 void WebWidgetHost::PaintRect(const gfx::Rect& rect) { | 357 void WebWidgetHost::PaintRect(const gfx::Rect& rect) { |
| 342 #ifndef NDEBUG | 358 #ifndef NDEBUG |
| 343 DCHECK(!painting_); | 359 DCHECK(!painting_); |
| 344 #endif | 360 #endif |
| 345 DCHECK(canvas_.get()); | 361 DCHECK(canvas_.get()); |
| 346 | 362 |
| 347 set_painting(true); | 363 set_painting(true); |
| 348 webwidget_->Paint(canvas_.get(), rect); | 364 webwidget_->Paint(canvas_.get(), rect); |
| 349 set_painting(false); | 365 set_painting(false); |
| 350 } | 366 } |
| OLD | NEW |