OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/logging.h" | 7 #include "base/logging.h" |
8 #include "gfx/rect.h" | 8 #include "gfx/rect.h" |
9 #include "skia/ext/platform_canvas.h" | 9 #include "skia/ext/platform_canvas.h" |
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h" |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/win/WebInputEventFact
ory.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/win/WebInputEventFact
ory.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/win/WebScreenInfoFact
ory.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/win/WebScreenInfoFact
ory.h" |
16 #include "ui/base/win/hwnd_util.h" | 16 #include "ui/base/win/hwnd_util.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::WebPaintSurface; |
24 using WebKit::WebPopupMenu; | 25 using WebKit::WebPopupMenu; |
25 using WebKit::WebScreenInfo; | 26 using WebKit::WebScreenInfo; |
26 using WebKit::WebScreenInfoFactory; | 27 using WebKit::WebScreenInfoFactory; |
27 using WebKit::WebSize; | 28 using WebKit::WebSize; |
28 using WebKit::WebWidget; | 29 using WebKit::WebWidget; |
29 using WebKit::WebWidgetClient; | 30 using WebKit::WebWidgetClient; |
30 | 31 |
31 static const wchar_t kWindowClassName[] = L"WebWidgetHost"; | 32 static const wchar_t kWindowClassName[] = L"WebWidgetHost"; |
32 | 33 |
33 /*static*/ | 34 /*static*/ |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 | 131 |
131 case WM_KILLFOCUS: | 132 case WM_KILLFOCUS: |
132 host->SetFocus(false); | 133 host->SetFocus(false); |
133 break; | 134 break; |
134 } | 135 } |
135 } | 136 } |
136 | 137 |
137 return DefWindowProc(hwnd, message, wparam, lparam);; | 138 return DefWindowProc(hwnd, message, wparam, lparam);; |
138 } | 139 } |
139 | 140 |
| 141 #if WEBKIT_USING_PAINTSURFACE |
| 142 |
| 143 WebPaintSurface* WebWidgetHost::GetPaintSurface() { |
| 144 gfx::Size widget_size = webwidget_->size(); |
| 145 if (!paint_surface_.get() || paint_surface_->size() != widget_size) { |
| 146 // This may result in discarding a previously allocated paint surface, |
| 147 // which had not yet been fully rendered (see DidModifyPaintSurface). |
| 148 pending_paint_surface_.reset( |
| 149 new SimpleWebPaintSurfaceImpl(this, widget_size)); |
| 150 return pending_paint_surface_.get(); |
| 151 } |
| 152 return paint_surface_.get(); |
| 153 } |
| 154 |
| 155 #else // WEBKIT_USING_PAINTSURFACE |
| 156 |
140 void WebWidgetHost::DidInvalidateRect(const gfx::Rect& damaged_rect) { | 157 void WebWidgetHost::DidInvalidateRect(const gfx::Rect& damaged_rect) { |
141 DLOG_IF(WARNING, painting_) << "unexpected invalidation while painting"; | 158 DLOG_IF(WARNING, painting_) << "unexpected invalidation while painting"; |
142 | 159 |
143 // If this invalidate overlaps with a pending scroll, then we have to | 160 // If this invalidate overlaps with a pending scroll, then we have to |
144 // downgrade to invalidating the scroll rect. | 161 // downgrade to invalidating the scroll rect. |
145 if (damaged_rect.Intersects(scroll_rect_)) { | 162 if (damaged_rect.Intersects(scroll_rect_)) { |
146 paint_rect_ = paint_rect_.Union(scroll_rect_); | 163 paint_rect_ = paint_rect_.Union(scroll_rect_); |
147 ResetScrollRect(); | 164 ResetScrollRect(); |
148 } | 165 } |
149 paint_rect_ = paint_rect_.Union(damaged_rect); | 166 paint_rect_ = paint_rect_.Union(damaged_rect); |
(...skipping 19 matching lines...) Expand all Loading... |
169 | 186 |
170 // We will perform scrolling lazily, when requested to actually paint. | 187 // We will perform scrolling lazily, when requested to actually paint. |
171 scroll_rect_ = clip_rect; | 188 scroll_rect_ = clip_rect; |
172 scroll_dx_ = dx; | 189 scroll_dx_ = dx; |
173 scroll_dy_ = dy; | 190 scroll_dy_ = dy; |
174 | 191 |
175 RECT r = clip_rect.ToRECT(); | 192 RECT r = clip_rect.ToRECT(); |
176 InvalidateRect(view_, &r, FALSE); | 193 InvalidateRect(view_, &r, FALSE); |
177 } | 194 } |
178 | 195 |
| 196 #endif // WEBKIT_USING_PAINTSURFACE |
| 197 |
179 void WebWidgetHost::ScheduleComposite() { | 198 void WebWidgetHost::ScheduleComposite() { |
180 if (!webwidget_) | 199 if (!webwidget_) |
181 return; | 200 return; |
182 WebSize size = webwidget_->size(); | 201 WebSize size = webwidget_->size(); |
183 gfx::Rect rect(0, 0, size.width, size.height); | 202 gfx::Rect rect(0, 0, size.width, size.height); |
184 RECT r = rect.ToRECT(); | 203 RECT r = rect.ToRECT(); |
185 InvalidateRect(view_, &r, FALSE); | 204 InvalidateRect(view_, &r, FALSE); |
186 } | 205 } |
187 | 206 |
188 void WebWidgetHost::SetCursor(HCURSOR cursor) { | 207 void WebWidgetHost::SetCursor(HCURSOR cursor) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 } | 243 } |
225 | 244 |
226 return false; | 245 return false; |
227 } | 246 } |
228 | 247 |
229 void WebWidgetHost::UpdatePaintRect(const gfx::Rect& rect) { | 248 void WebWidgetHost::UpdatePaintRect(const gfx::Rect& rect) { |
230 paint_rect_ = paint_rect_.Union(rect); | 249 paint_rect_ = paint_rect_.Union(rect); |
231 } | 250 } |
232 | 251 |
233 void WebWidgetHost::Paint() { | 252 void WebWidgetHost::Paint() { |
| 253 #if WEBKIT_USING_PAINTSURFACE |
| 254 // Paint to the screen |
| 255 PAINTSTRUCT ps; |
| 256 BeginPaint(view_, &ps); |
| 257 |
| 258 gfx::Rect damage_rect(ps.rcPaint); |
| 259 gfx::Rect canvas_rect; |
| 260 |
| 261 if (paint_surface_.get()) { |
| 262 canvas_rect.set_size(paint_surface_->size()); |
| 263 canvas_rect = canvas_rect.Intersect(damage_rect); |
| 264 if (!canvas_rect.IsEmpty()) { |
| 265 skia::PlatformCanvas* canvas = paint_surface_->canvas(); |
| 266 canvas->getTopPlatformDevice().drawToHDC(ps.hdc, |
| 267 canvas_rect.x(), |
| 268 canvas_rect.y(), |
| 269 &canvas_rect.ToRECT()); |
| 270 } |
| 271 } |
| 272 |
| 273 if (damage_rect.right() > canvas_rect.right()) { |
| 274 // Paint right edge. |
| 275 gfx::Rect r(canvas_rect.right(), |
| 276 damage_rect.y(), |
| 277 damage_rect.right() - canvas_rect.right(), |
| 278 damage_rect.height()); |
| 279 FillRect(ps.hdc, &r.ToRECT(), (HBRUSH)GetStockObject(WHITE_BRUSH)); |
| 280 } |
| 281 |
| 282 if (damage_rect.bottom() > canvas_rect.bottom()) { |
| 283 // Paint bottom edge, possibly overpainting the corner for simplicity. |
| 284 gfx::Rect r(damage_rect.x(), |
| 285 canvas_rect.bottom(), |
| 286 damage_rect.width(), |
| 287 damage_rect.bottom() - canvas_rect.bottom()); |
| 288 FillRect(ps.hdc, &r.ToRECT(), (HBRUSH)GetStockObject(WHITE_BRUSH)); |
| 289 } |
| 290 |
| 291 EndPaint(view_, &ps); |
| 292 |
| 293 if (paint_surface_.get()) |
| 294 paint_surface_->DidCopyPaintSurface(); |
| 295 #else |
234 RECT r; | 296 RECT r; |
235 GetClientRect(view_, &r); | 297 GetClientRect(view_, &r); |
236 gfx::Rect client_rect(r); | 298 gfx::Rect client_rect(r); |
237 | 299 |
238 // Allocate a canvas if necessary | 300 // Allocate a canvas if necessary |
239 if (!canvas_.get()) { | 301 if (!canvas_.get()) { |
240 ResetScrollRect(); | 302 ResetScrollRect(); |
241 paint_rect_ = client_rect; | 303 paint_rect_ = client_rect; |
242 canvas_.reset(new skia::PlatformCanvas( | 304 canvas_.reset(new skia::PlatformCanvas( |
243 paint_rect_.width(), paint_rect_.height(), true)); | 305 paint_rect_.width(), paint_rect_.height(), true)); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 PAINTSTRUCT ps; | 341 PAINTSTRUCT ps; |
280 BeginPaint(view_, &ps); | 342 BeginPaint(view_, &ps); |
281 canvas_->getTopPlatformDevice().drawToHDC(ps.hdc, | 343 canvas_->getTopPlatformDevice().drawToHDC(ps.hdc, |
282 ps.rcPaint.left, | 344 ps.rcPaint.left, |
283 ps.rcPaint.top, | 345 ps.rcPaint.top, |
284 &ps.rcPaint); | 346 &ps.rcPaint); |
285 EndPaint(view_, &ps); | 347 EndPaint(view_, &ps); |
286 | 348 |
287 // Draw children | 349 // Draw children |
288 UpdateWindow(view_); | 350 UpdateWindow(view_); |
| 351 #endif |
289 } | 352 } |
290 | 353 |
291 WebScreenInfo WebWidgetHost::GetScreenInfo() { | 354 WebScreenInfo WebWidgetHost::GetScreenInfo() { |
292 return WebScreenInfoFactory::screenInfo(view_); | 355 return WebScreenInfoFactory::screenInfo(view_); |
293 } | 356 } |
294 | 357 |
295 void WebWidgetHost::Resize(LPARAM lparam) { | 358 void WebWidgetHost::Resize(LPARAM lparam) { |
296 // Force an entire re-paint. TODO(darin): Maybe reuse this memory buffer. | 359 // Force an entire re-paint. TODO(darin): Maybe reuse this memory buffer. |
297 DiscardBackingStore(); | 360 DiscardBackingStore(); |
298 | 361 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 | 427 |
365 TrackMouseEvent(&tme); | 428 TrackMouseEvent(&tme); |
366 } | 429 } |
367 | 430 |
368 void WebWidgetHost::ResetScrollRect() { | 431 void WebWidgetHost::ResetScrollRect() { |
369 scroll_rect_ = gfx::Rect(); | 432 scroll_rect_ = gfx::Rect(); |
370 scroll_dx_ = 0; | 433 scroll_dx_ = 0; |
371 scroll_dy_ = 0; | 434 scroll_dy_ = 0; |
372 } | 435 } |
373 | 436 |
| 437 void WebWidgetHost::DidModifyPaintSurface(const gfx::Rect& bounds) { |
| 438 // If there is a pending paint surface, then we can now consider it |
| 439 // up-to-date and usable. |
| 440 if (pending_paint_surface_.get()) |
| 441 paint_surface_.reset(pending_paint_surface_.release()); |
| 442 |
| 443 InvalidateRect(view_, &bounds.ToRECT(), FALSE); |
| 444 } |
| 445 |
374 void WebWidgetHost::PaintRect(const gfx::Rect& rect) { | 446 void WebWidgetHost::PaintRect(const gfx::Rect& rect) { |
375 #ifndef NDEBUG | 447 #ifndef NDEBUG |
376 DCHECK(!painting_); | 448 DCHECK(!painting_); |
377 #endif | 449 #endif |
378 DCHECK(canvas_.get()); | 450 DCHECK(canvas_.get()); |
379 | 451 |
380 set_painting(true); | 452 set_painting(true); |
381 webwidget_->paint(canvas_.get(), rect); | 453 webwidget_->paint(canvas_.get(), rect); |
382 set_painting(false); | 454 set_painting(false); |
383 } | 455 } |
OLD | NEW |