| OLD | NEW |
| 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #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/gfx/platform_canvas_mac.h" | 9 #include "base/gfx/platform_canvas_mac.h" |
| 10 #include "base/gfx/rect.h" | 10 #include "base/gfx/rect.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 137 |
| 138 webwidget_->Close(); | 138 webwidget_->Close(); |
| 139 webwidget_->Release(); | 139 webwidget_->Release(); |
| 140 } | 140 } |
| 141 | 141 |
| 142 void WebWidgetHost::UpdatePaintRect(const gfx::Rect& rect) { | 142 void WebWidgetHost::UpdatePaintRect(const gfx::Rect& rect) { |
| 143 paint_rect_ = paint_rect_.Union(rect); | 143 paint_rect_ = paint_rect_.Union(rect); |
| 144 } | 144 } |
| 145 | 145 |
| 146 void WebWidgetHost::Paint() { | 146 void WebWidgetHost::Paint() { |
| 147 PaintToCanvas(); |
| 148 PaintCanvasToView(); |
| 149 } |
| 150 |
| 151 void WebWidgetHost::PaintToCanvas() { |
| 147 NSRect r = [view_ frame]; | 152 NSRect r = [view_ frame]; |
| 148 gfx::Rect client_rect(NSRectToCGRect(r)); | 153 gfx::Rect client_rect(NSRectToCGRect(r)); |
| 149 NSGraphicsContext* view_context = [NSGraphicsContext currentContext]; | 154 NSGraphicsContext* view_context = [NSGraphicsContext currentContext]; |
| 150 CGContextRef context = static_cast<CGContextRef>([view_context graphicsPort]); | |
| 151 | 155 |
| 152 // Allocate a canvas if necessary | 156 // Allocate a canvas if necessary |
| 153 if (!canvas_.get()) { | 157 if (!canvas_.get()) { |
| 154 ResetScrollRect(); | 158 ResetScrollRect(); |
| 155 paint_rect_ = client_rect; | 159 paint_rect_ = client_rect; |
| 156 canvas_.reset(new skia::PlatformCanvas( | 160 canvas_.reset(new skia::PlatformCanvas( |
| 157 paint_rect_.width(), paint_rect_.height(), true)); | 161 paint_rect_.width(), paint_rect_.height(), true)); |
| 158 } | 162 } |
| 159 | 163 |
| 160 // make sure webkit draws into our bitmap, not the window | 164 // make sure webkit draws into our bitmap, not the window |
| (...skipping 24 matching lines...) Expand all Loading... |
| 185 paint_rect_ = gfx::Rect(); | 189 paint_rect_ = gfx::Rect(); |
| 186 | 190 |
| 187 // DLOG_IF(WARNING, i == 1) << "painting caused additional invalidations"; | 191 // DLOG_IF(WARNING, i == 1) << "painting caused additional invalidations"; |
| 188 PaintRect(rect); | 192 PaintRect(rect); |
| 189 } | 193 } |
| 190 } | 194 } |
| 191 DCHECK(paint_rect_.IsEmpty()); | 195 DCHECK(paint_rect_.IsEmpty()); |
| 192 | 196 |
| 193 // set the context back to our window | 197 // set the context back to our window |
| 194 [NSGraphicsContext setCurrentContext: view_context]; | 198 [NSGraphicsContext setCurrentContext: view_context]; |
| 199 } |
| 195 | 200 |
| 201 void WebWidgetHost::PaintCanvasToView() { |
| 196 // Paint to the screen | 202 // Paint to the screen |
| 197 if ([view_ lockFocusIfCanDraw]) { | 203 if ([view_ lockFocusIfCanDraw]) { |
| 204 NSGraphicsContext* view_context = [NSGraphicsContext currentContext]; |
| 205 NSRect r = [view_ frame]; |
| 206 CGContextRef bitmap_context = |
| 207 canvas_->getTopPlatformDevice().GetBitmapContext(); |
| 208 CGContextRef context = |
| 209 static_cast<CGContextRef>([view_context graphicsPort]); |
| 198 CGRect paint_rect = NSRectToCGRect(r); | 210 CGRect paint_rect = NSRectToCGRect(r); |
| 199 int bitmap_height = CGBitmapContextGetHeight(bitmap_context); | 211 int bitmap_height = CGBitmapContextGetHeight(bitmap_context); |
| 200 int bitmap_width = CGBitmapContextGetWidth(bitmap_context); | 212 int bitmap_width = CGBitmapContextGetWidth(bitmap_context); |
| 201 CGRect bitmap_rect = { { 0, 0 }, | 213 CGRect bitmap_rect = { { 0, 0 }, |
| 202 { bitmap_width, bitmap_height } }; | 214 { bitmap_width, bitmap_height } }; |
| 203 canvas_->getTopPlatformDevice().DrawToContext( | 215 canvas_->getTopPlatformDevice().DrawToContext( |
| 204 context, 0, client_rect.height() - bitmap_height, &bitmap_rect); | 216 context, 0, r.size.height - bitmap_height, &bitmap_rect); |
| 205 | 217 |
| 206 [view_ unlockFocus]; | 218 [view_ unlockFocus]; |
| 207 } | 219 } |
| 208 } | 220 } |
| 209 | 221 |
| 222 void WebWidgetHost::DisplayForRepaint() { |
| 223 PaintToCanvas(); |
| 224 |
| 225 // Paint a gray mask over everything for the repaint Layout tests. |
| 226 CGContextRef bitmap_context = |
| 227 canvas_->getTopPlatformDevice().GetBitmapContext(); |
| 228 CGRect bitmap_rect = { { 0, 0 }, |
| 229 { CGBitmapContextGetWidth(bitmap_context), |
| 230 CGBitmapContextGetHeight(bitmap_context) } }; |
| 231 CGContextSetBlendMode(bitmap_context, kCGBlendModeNormal); |
| 232 CGContextSetRGBFillColor(bitmap_context, 0, 0, 0, 0.66); |
| 233 CGContextFillRect(bitmap_context, bitmap_rect); |
| 234 |
| 235 PaintCanvasToView(); |
| 236 } |
| 237 |
| 210 void WebWidgetHost::Resize(const gfx::Rect& rect) { | 238 void WebWidgetHost::Resize(const gfx::Rect& rect) { |
| 211 // Force an entire re-paint. TODO(darin): Maybe reuse this memory buffer. | 239 // Force an entire re-paint. TODO(darin): Maybe reuse this memory buffer. |
| 212 DiscardBackingStore(); | 240 DiscardBackingStore(); |
| 213 webwidget_->Resize(gfx::Size(rect.width(), rect.height())); | 241 webwidget_->Resize(gfx::Size(rect.width(), rect.height())); |
| 214 } | 242 } |
| 215 | 243 |
| 216 void WebWidgetHost::MouseEvent(NSEvent *event) { | 244 void WebWidgetHost::MouseEvent(NSEvent *event) { |
| 217 WebMouseEvent web_event(event, view_); | 245 WebMouseEvent web_event(event, view_); |
| 218 switch (web_event.type) { | 246 switch (web_event.type) { |
| 219 case WebInputEvent::MOUSE_MOVE: | 247 case WebInputEvent::MOUSE_MOVE: |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 void WebWidgetHost::PaintRect(const gfx::Rect& rect) { | 290 void WebWidgetHost::PaintRect(const gfx::Rect& rect) { |
| 263 #ifndef NDEBUG | 291 #ifndef NDEBUG |
| 264 DCHECK(!painting_); | 292 DCHECK(!painting_); |
| 265 #endif | 293 #endif |
| 266 DCHECK(canvas_.get()); | 294 DCHECK(canvas_.get()); |
| 267 | 295 |
| 268 set_painting(true); | 296 set_painting(true); |
| 269 webwidget_->Paint(canvas_.get(), rect); | 297 webwidget_->Paint(canvas_.get(), rect); |
| 270 set_painting(false); | 298 set_painting(false); |
| 271 } | 299 } |
| OLD | NEW |