OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
6 | 6 |
7 #include "webkit/tools/test_shell/webwidget_host.h" | 7 #include "webkit/tools/test_shell/webwidget_host.h" |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "skia/ext/platform_canvas.h" | 10 #include "skia/ext/platform_canvas.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 } | 90 } |
91 | 91 |
92 void WebWidgetHost::DidInvalidateRect(const gfx::Rect& damaged_rect) { | 92 void WebWidgetHost::DidInvalidateRect(const gfx::Rect& damaged_rect) { |
93 #ifndef NDEBUG | 93 #ifndef NDEBUG |
94 DLOG_IF(WARNING, painting_) << "unexpected invalidation while painting"; | 94 DLOG_IF(WARNING, painting_) << "unexpected invalidation while painting"; |
95 #endif | 95 #endif |
96 | 96 |
97 // If this invalidate overlaps with a pending scroll, then we have to | 97 // If this invalidate overlaps with a pending scroll, then we have to |
98 // downgrade to invalidating the scroll rect. | 98 // downgrade to invalidating the scroll rect. |
99 if (damaged_rect.Intersects(scroll_rect_)) { | 99 if (damaged_rect.Intersects(scroll_rect_)) { |
100 paint_rect_ = paint_rect_.Union(scroll_rect_); | 100 paint_rect_.Union(scroll_rect_); |
101 ResetScrollRect(); | 101 ResetScrollRect(); |
102 } | 102 } |
103 paint_rect_ = paint_rect_.Union(damaged_rect); | 103 paint_rect_.Union(damaged_rect); |
104 | 104 |
105 NSRect r = NSRectFromCGRect(damaged_rect.ToCGRect()); | 105 NSRect r = NSRectFromCGRect(damaged_rect.ToCGRect()); |
106 // flip to cocoa coordinates | 106 // flip to cocoa coordinates |
107 r.origin.y = [view_ frame].size.height - r.size.height - r.origin.y; | 107 r.origin.y = [view_ frame].size.height - r.size.height - r.origin.y; |
108 [view_ setNeedsDisplayInRect:r]; | 108 [view_ setNeedsDisplayInRect:r]; |
109 } | 109 } |
110 | 110 |
111 void WebWidgetHost::DidScrollRect(int dx, int dy, const gfx::Rect& clip_rect) { | 111 void WebWidgetHost::DidScrollRect(int dx, int dy, const gfx::Rect& clip_rect) { |
112 DCHECK(dx || dy); | 112 DCHECK(dx || dy); |
113 | 113 |
114 // If we already have a pending scroll operation or if this scroll operation | 114 // If we already have a pending scroll operation or if this scroll operation |
115 // intersects the existing paint region, then just failover to invalidating. | 115 // intersects the existing paint region, then just failover to invalidating. |
116 if (!scroll_rect_.IsEmpty() || paint_rect_.Intersects(clip_rect)) { | 116 if (!scroll_rect_.IsEmpty() || paint_rect_.Intersects(clip_rect)) { |
117 paint_rect_ = paint_rect_.Union(scroll_rect_); | 117 paint_rect_.Union(scroll_rect_); |
118 ResetScrollRect(); | 118 ResetScrollRect(); |
119 paint_rect_ = paint_rect_.Union(clip_rect); | 119 paint_rect_.Union(clip_rect); |
120 } | 120 } |
121 | 121 |
122 // We will perform scrolling lazily, when requested to actually paint. | 122 // We will perform scrolling lazily, when requested to actually paint. |
123 scroll_rect_ = clip_rect; | 123 scroll_rect_ = clip_rect; |
124 scroll_dx_ = dx; | 124 scroll_dx_ = dx; |
125 scroll_dy_ = dy; | 125 scroll_dy_ = dy; |
126 | 126 |
127 NSRect r = NSRectFromCGRect(clip_rect.ToCGRect()); | 127 NSRect r = NSRectFromCGRect(clip_rect.ToCGRect()); |
128 // flip to cocoa coordinates | 128 // flip to cocoa coordinates |
129 r.origin.y = [view_ frame].size.height - r.size.height - r.origin.y; | 129 r.origin.y = [view_ frame].size.height - r.size.height - r.origin.y; |
(...skipping 24 matching lines...) Expand all Loading... |
154 set_painting(false); | 154 set_painting(false); |
155 } | 155 } |
156 | 156 |
157 WebWidgetHost::~WebWidgetHost() { | 157 WebWidgetHost::~WebWidgetHost() { |
158 // ui::SetWindowUserData(hwnd_, 0); | 158 // ui::SetWindowUserData(hwnd_, 0); |
159 | 159 |
160 webwidget_->close(); | 160 webwidget_->close(); |
161 } | 161 } |
162 | 162 |
163 void WebWidgetHost::UpdatePaintRect(const gfx::Rect& rect) { | 163 void WebWidgetHost::UpdatePaintRect(const gfx::Rect& rect) { |
164 paint_rect_ = paint_rect_.Union(rect); | 164 paint_rect_.Union(rect); |
165 } | 165 } |
166 | 166 |
167 void WebWidgetHost::Paint() { | 167 void WebWidgetHost::Paint() { |
168 gfx::Rect client_rect(NSRectToCGRect([view_ frame])); | 168 gfx::Rect client_rect(NSRectToCGRect([view_ frame])); |
169 NSGraphicsContext* view_context = [NSGraphicsContext currentContext]; | 169 NSGraphicsContext* view_context = [NSGraphicsContext currentContext]; |
170 CGContextRef context = static_cast<CGContextRef>([view_context graphicsPort]); | 170 CGContextRef context = static_cast<CGContextRef>([view_context graphicsPort]); |
171 | 171 |
172 // Allocate a canvas if necessary | 172 // Allocate a canvas if necessary |
173 if (!canvas_.get()) { | 173 if (!canvas_.get()) { |
174 ResetScrollRect(); | 174 ResetScrollRect(); |
175 paint_rect_ = client_rect; | 175 paint_rect_ = client_rect; |
176 canvas_.reset(new skia::PlatformCanvas( | 176 canvas_.reset(new skia::PlatformCanvas( |
177 paint_rect_.width(), paint_rect_.height(), true)); | 177 paint_rect_.width(), paint_rect_.height(), true)); |
178 } | 178 } |
179 | 179 |
180 // make sure webkit draws into our bitmap, not the window | 180 // make sure webkit draws into our bitmap, not the window |
181 CGContextRef bitmap_context = | 181 CGContextRef bitmap_context = |
182 skia::GetBitmapContext(skia::GetTopDevice(*canvas_)); | 182 skia::GetBitmapContext(skia::GetTopDevice(*canvas_)); |
183 [NSGraphicsContext setCurrentContext: | 183 [NSGraphicsContext setCurrentContext: |
184 [NSGraphicsContext graphicsContextWithGraphicsPort:bitmap_context | 184 [NSGraphicsContext graphicsContextWithGraphicsPort:bitmap_context |
185 flipped:YES]]; | 185 flipped:YES]]; |
186 | 186 |
187 webwidget_->animate(0.0); | 187 webwidget_->animate(0.0); |
188 | 188 |
189 // This may result in more invalidation | 189 // This may result in more invalidation |
190 webwidget_->layout(); | 190 webwidget_->layout(); |
191 | 191 |
192 // Scroll the canvas if necessary | 192 // Scroll the canvas if necessary |
193 scroll_rect_ = client_rect.Intersect(scroll_rect_); | 193 scroll_rect_.Intersect(client_rect); |
194 if (!scroll_rect_.IsEmpty()) { | 194 if (!scroll_rect_.IsEmpty()) { |
195 // add to invalidate rect, since there's no equivalent of ScrollDC. | 195 // add to invalidate rect, since there's no equivalent of ScrollDC. |
196 paint_rect_ = paint_rect_.Union(scroll_rect_); | 196 paint_rect_.Union(scroll_rect_); |
197 } | 197 } |
198 ResetScrollRect(); | 198 ResetScrollRect(); |
199 | 199 |
200 // Paint the canvas if necessary. Allow painting to generate extra rects the | 200 // Paint the canvas if necessary. Allow painting to generate extra rects the |
201 // first time we call it. This is necessary because some WebCore rendering | 201 // first time we call it. This is necessary because some WebCore rendering |
202 // objects update their layout only when painted. | 202 // objects update their layout only when painted. |
203 for (int i = 0; i < 2; ++i) { | 203 for (int i = 0; i < 2; ++i) { |
204 paint_rect_ = client_rect.Intersect(paint_rect_); | 204 paint_rect_.Intersect(client_rect); |
205 if (!paint_rect_.IsEmpty()) { | 205 if (!paint_rect_.IsEmpty()) { |
206 gfx::Rect rect(paint_rect_); | 206 gfx::Rect rect(paint_rect_); |
207 paint_rect_ = gfx::Rect(); | 207 paint_rect_ = gfx::Rect(); |
208 | 208 |
209 // DLOG_IF(WARNING, i == 1) << "painting caused additional invalidations"; | 209 // DLOG_IF(WARNING, i == 1) << "painting caused additional invalidations"; |
210 PaintRect(rect); | 210 PaintRect(rect); |
211 } | 211 } |
212 } | 212 } |
213 DCHECK(paint_rect_.IsEmpty()); | 213 DCHECK(paint_rect_.IsEmpty()); |
214 | 214 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 void WebWidgetHost::PaintRect(const gfx::Rect& rect) { | 277 void WebWidgetHost::PaintRect(const gfx::Rect& rect) { |
278 #ifndef NDEBUG | 278 #ifndef NDEBUG |
279 DCHECK(!painting_); | 279 DCHECK(!painting_); |
280 #endif | 280 #endif |
281 DCHECK(canvas_.get()); | 281 DCHECK(canvas_.get()); |
282 | 282 |
283 set_painting(true); | 283 set_painting(true); |
284 webwidget_->paint(webkit_glue::ToWebCanvas(canvas_.get()), rect); | 284 webwidget_->paint(webkit_glue::ToWebCanvas(canvas_.get()), rect); |
285 set_painting(false); | 285 set_painting(false); |
286 } | 286 } |
OLD | NEW |