OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "skia/ext/platform_canvas.h" | 8 #include "skia/ext/platform_canvas.h" |
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 | 136 |
137 return DefWindowProc(hwnd, message, wparam, lparam);; | 137 return DefWindowProc(hwnd, message, wparam, lparam);; |
138 } | 138 } |
139 | 139 |
140 void WebWidgetHost::DidInvalidateRect(const gfx::Rect& damaged_rect) { | 140 void WebWidgetHost::DidInvalidateRect(const gfx::Rect& damaged_rect) { |
141 DLOG_IF(WARNING, painting_) << "unexpected invalidation while painting"; | 141 DLOG_IF(WARNING, painting_) << "unexpected invalidation while painting"; |
142 | 142 |
143 // If this invalidate overlaps with a pending scroll, then we have to | 143 // If this invalidate overlaps with a pending scroll, then we have to |
144 // downgrade to invalidating the scroll rect. | 144 // downgrade to invalidating the scroll rect. |
145 if (damaged_rect.Intersects(scroll_rect_)) { | 145 if (damaged_rect.Intersects(scroll_rect_)) { |
146 paint_rect_ = paint_rect_.Union(scroll_rect_); | 146 paint_rect_.Union(scroll_rect_); |
147 ResetScrollRect(); | 147 ResetScrollRect(); |
148 } | 148 } |
149 paint_rect_ = paint_rect_.Union(damaged_rect); | 149 paint_rect_.Union(damaged_rect); |
150 | 150 |
151 RECT r = damaged_rect.ToRECT(); | 151 RECT r = damaged_rect.ToRECT(); |
152 InvalidateRect(view_, &r, FALSE); | 152 InvalidateRect(view_, &r, FALSE); |
153 } | 153 } |
154 | 154 |
155 void WebWidgetHost::DidScrollRect(int dx, int dy, const gfx::Rect& clip_rect) { | 155 void WebWidgetHost::DidScrollRect(int dx, int dy, const gfx::Rect& clip_rect) { |
156 if (dx != 0 && dy != 0) { | 156 if (dx != 0 && dy != 0) { |
157 // We only support uni-directional scroll | 157 // We only support uni-directional scroll |
158 DidScrollRect(0, dy, clip_rect); | 158 DidScrollRect(0, dy, clip_rect); |
159 dy = 0; | 159 dy = 0; |
160 } | 160 } |
161 | 161 |
162 // If we already have a pending scroll operation or if this scroll operation | 162 // If we already have a pending scroll operation or if this scroll operation |
163 // intersects the existing paint region, then just failover to invalidating. | 163 // intersects the existing paint region, then just failover to invalidating. |
164 if (!scroll_rect_.IsEmpty() || paint_rect_.Intersects(clip_rect)) { | 164 if (!scroll_rect_.IsEmpty() || paint_rect_.Intersects(clip_rect)) { |
165 paint_rect_ = paint_rect_.Union(scroll_rect_); | 165 paint_rect_.Union(scroll_rect_); |
166 ResetScrollRect(); | 166 ResetScrollRect(); |
167 paint_rect_ = paint_rect_.Union(clip_rect); | 167 paint_rect_.Union(clip_rect); |
168 } | 168 } |
169 | 169 |
170 // We will perform scrolling lazily, when requested to actually paint. | 170 // We will perform scrolling lazily, when requested to actually paint. |
171 scroll_rect_ = clip_rect; | 171 scroll_rect_ = clip_rect; |
172 scroll_dx_ = dx; | 172 scroll_dx_ = dx; |
173 scroll_dy_ = dy; | 173 scroll_dy_ = dy; |
174 | 174 |
175 RECT r = clip_rect.ToRECT(); | 175 RECT r = clip_rect.ToRECT(); |
176 InvalidateRect(view_, &r, FALSE); | 176 InvalidateRect(view_, &r, FALSE); |
177 } | 177 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 PostMessage(view_, WM_CLOSE, 0, 0); | 220 PostMessage(view_, WM_CLOSE, 0, 0); |
221 return true; | 221 return true; |
222 } | 222 } |
223 break; | 223 break; |
224 } | 224 } |
225 | 225 |
226 return false; | 226 return false; |
227 } | 227 } |
228 | 228 |
229 void WebWidgetHost::UpdatePaintRect(const gfx::Rect& rect) { | 229 void WebWidgetHost::UpdatePaintRect(const gfx::Rect& rect) { |
230 paint_rect_ = paint_rect_.Union(rect); | 230 paint_rect_.Union(rect); |
231 } | 231 } |
232 | 232 |
233 void WebWidgetHost::Paint() { | 233 void WebWidgetHost::Paint() { |
234 RECT r; | 234 RECT r; |
235 GetClientRect(view_, &r); | 235 GetClientRect(view_, &r); |
236 gfx::Rect client_rect(r); | 236 gfx::Rect client_rect(r); |
237 | 237 |
238 // Allocate a canvas if necessary | 238 // Allocate a canvas if necessary |
239 if (!canvas_.get()) { | 239 if (!canvas_.get()) { |
240 ResetScrollRect(); | 240 ResetScrollRect(); |
241 paint_rect_ = client_rect; | 241 paint_rect_ = client_rect; |
242 canvas_.reset(new skia::PlatformCanvas( | 242 canvas_.reset(new skia::PlatformCanvas( |
243 paint_rect_.width(), paint_rect_.height(), true)); | 243 paint_rect_.width(), paint_rect_.height(), true)); |
244 } | 244 } |
245 | 245 |
246 webwidget_->animate(0.0); | 246 webwidget_->animate(0.0); |
247 | 247 |
248 // This may result in more invalidation | 248 // This may result in more invalidation |
249 webwidget_->layout(); | 249 webwidget_->layout(); |
250 | 250 |
251 // Scroll the canvas if necessary | 251 // Scroll the canvas if necessary |
252 scroll_rect_ = client_rect.Intersect(scroll_rect_); | 252 scroll_rect_.Intersect(client_rect); |
253 if (!scroll_rect_.IsEmpty()) { | 253 if (!scroll_rect_.IsEmpty()) { |
254 skia::ScopedPlatformPaint scoped_platform_paint(canvas_.get()); | 254 skia::ScopedPlatformPaint scoped_platform_paint(canvas_.get()); |
255 HDC hdc = scoped_platform_paint.GetPlatformSurface(); | 255 HDC hdc = scoped_platform_paint.GetPlatformSurface(); |
256 | 256 |
257 RECT damaged_rect, r = scroll_rect_.ToRECT(); | 257 RECT damaged_rect, r = scroll_rect_.ToRECT(); |
258 ScrollDC(hdc, scroll_dx_, scroll_dy_, NULL, &r, NULL, &damaged_rect); | 258 ScrollDC(hdc, scroll_dx_, scroll_dy_, NULL, &r, NULL, &damaged_rect); |
259 | 259 |
260 PaintRect(gfx::Rect(damaged_rect)); | 260 PaintRect(gfx::Rect(damaged_rect)); |
261 } | 261 } |
262 ResetScrollRect(); | 262 ResetScrollRect(); |
263 | 263 |
264 // Paint the canvas if necessary. Allow painting to generate extra rects the | 264 // Paint the canvas if necessary. Allow painting to generate extra rects the |
265 // first time we call it. This is necessary because some WebCore rendering | 265 // first time we call it. This is necessary because some WebCore rendering |
266 // objects update their layout only when painted. | 266 // objects update their layout only when painted. |
267 for (int i = 0; i < 2; ++i) { | 267 for (int i = 0; i < 2; ++i) { |
268 paint_rect_ = client_rect.Intersect(paint_rect_); | 268 paint_rect_.Intersect(client_rect); |
269 if (!paint_rect_.IsEmpty()) { | 269 if (!paint_rect_.IsEmpty()) { |
270 gfx::Rect rect(paint_rect_); | 270 gfx::Rect rect(paint_rect_); |
271 paint_rect_ = gfx::Rect(); | 271 paint_rect_ = gfx::Rect(); |
272 | 272 |
273 DLOG_IF(WARNING, i == 1) << "painting caused additional invalidations"; | 273 DLOG_IF(WARNING, i == 1) << "painting caused additional invalidations"; |
274 PaintRect(rect); | 274 PaintRect(rect); |
275 } | 275 } |
276 } | 276 } |
277 DCHECK(paint_rect_.IsEmpty()); | 277 DCHECK(paint_rect_.IsEmpty()); |
278 | 278 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 void WebWidgetHost::PaintRect(const gfx::Rect& rect) { | 373 void WebWidgetHost::PaintRect(const gfx::Rect& rect) { |
374 #ifndef NDEBUG | 374 #ifndef NDEBUG |
375 DCHECK(!painting_); | 375 DCHECK(!painting_); |
376 #endif | 376 #endif |
377 DCHECK(canvas_.get()); | 377 DCHECK(canvas_.get()); |
378 | 378 |
379 set_painting(true); | 379 set_painting(true); |
380 webwidget_->paint(canvas_.get(), rect); | 380 webwidget_->paint(canvas_.get(), rect); |
381 set_painting(false); | 381 set_painting(false); |
382 } | 382 } |
OLD | NEW |