Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Side by Side Diff: webkit/tools/test_shell/mac/webwidget_host.mm

Issue 43058: Reverting 11396. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/tools/test_shell/layout_test_controller.cc ('k') | webkit/tools/test_shell/test_shell.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 TrackMouseLeave(false); 136 TrackMouseLeave(false);
137 137
138 webwidget_->Close(); 138 webwidget_->Close();
139 } 139 }
140 140
141 void WebWidgetHost::UpdatePaintRect(const gfx::Rect& rect) { 141 void WebWidgetHost::UpdatePaintRect(const gfx::Rect& rect) {
142 paint_rect_ = paint_rect_.Union(rect); 142 paint_rect_ = paint_rect_.Union(rect);
143 } 143 }
144 144
145 void WebWidgetHost::Paint() { 145 void WebWidgetHost::Paint() {
146 PaintToCanvas();
147 PaintCanvasToView();
148 }
149
150 void WebWidgetHost::PaintToCanvas() {
151 NSRect r = [view_ frame]; 146 NSRect r = [view_ frame];
152 gfx::Rect client_rect(NSRectToCGRect(r)); 147 gfx::Rect client_rect(NSRectToCGRect(r));
153 NSGraphicsContext* view_context = [NSGraphicsContext currentContext]; 148 NSGraphicsContext* view_context = [NSGraphicsContext currentContext];
149 CGContextRef context = static_cast<CGContextRef>([view_context graphicsPort]);
154 150
155 // Allocate a canvas if necessary 151 // Allocate a canvas if necessary
156 if (!canvas_.get()) { 152 if (!canvas_.get()) {
157 ResetScrollRect(); 153 ResetScrollRect();
158 paint_rect_ = client_rect; 154 paint_rect_ = client_rect;
159 canvas_.reset(new skia::PlatformCanvas( 155 canvas_.reset(new skia::PlatformCanvas(
160 paint_rect_.width(), paint_rect_.height(), true)); 156 paint_rect_.width(), paint_rect_.height(), true));
161 } 157 }
162 158
163 // make sure webkit draws into our bitmap, not the window 159 // make sure webkit draws into our bitmap, not the window
(...skipping 24 matching lines...) Expand all
188 paint_rect_ = gfx::Rect(); 184 paint_rect_ = gfx::Rect();
189 185
190 // DLOG_IF(WARNING, i == 1) << "painting caused additional invalidations"; 186 // DLOG_IF(WARNING, i == 1) << "painting caused additional invalidations";
191 PaintRect(rect); 187 PaintRect(rect);
192 } 188 }
193 } 189 }
194 DCHECK(paint_rect_.IsEmpty()); 190 DCHECK(paint_rect_.IsEmpty());
195 191
196 // set the context back to our window 192 // set the context back to our window
197 [NSGraphicsContext setCurrentContext: view_context]; 193 [NSGraphicsContext setCurrentContext: view_context];
198 }
199 194
200 void WebWidgetHost::PaintCanvasToView() {
201 // Paint to the screen 195 // Paint to the screen
202 if ([view_ lockFocusIfCanDraw]) { 196 if ([view_ lockFocusIfCanDraw]) {
203 NSGraphicsContext* view_context = [NSGraphicsContext currentContext];
204 NSRect r = [view_ frame];
205 CGContextRef bitmap_context =
206 canvas_->getTopPlatformDevice().GetBitmapContext();
207 CGContextRef context =
208 static_cast<CGContextRef>([view_context graphicsPort]);
209 CGRect paint_rect = NSRectToCGRect(r); 197 CGRect paint_rect = NSRectToCGRect(r);
210 int bitmap_height = CGBitmapContextGetHeight(bitmap_context); 198 int bitmap_height = CGBitmapContextGetHeight(bitmap_context);
211 int bitmap_width = CGBitmapContextGetWidth(bitmap_context); 199 int bitmap_width = CGBitmapContextGetWidth(bitmap_context);
212 CGRect bitmap_rect = { { 0, 0 }, 200 CGRect bitmap_rect = { { 0, 0 },
213 { bitmap_width, bitmap_height } }; 201 { bitmap_width, bitmap_height } };
214 canvas_->getTopPlatformDevice().DrawToContext( 202 canvas_->getTopPlatformDevice().DrawToContext(
215 context, 0, r.size.height - bitmap_height, &bitmap_rect); 203 context, 0, client_rect.height() - bitmap_height, &bitmap_rect);
216 204
217 [view_ unlockFocus]; 205 [view_ unlockFocus];
218 } 206 }
219 } 207 }
220 208
221 void WebWidgetHost::DisplayForRepaint() {
222 PaintToCanvas();
223
224 // Paint a gray mask over everything for the repaint Layout tests.
225 CGContextRef bitmap_context =
226 canvas_->getTopPlatformDevice().GetBitmapContext();
227 CGRect bitmap_rect = { { 0, 0 },
228 { CGBitmapContextGetWidth(bitmap_context),
229 CGBitmapContextGetHeight(bitmap_context) } };
230 CGContextSetBlendMode(bitmap_context, kCGBlendModeNormal);
231 CGContextSetRGBFillColor(bitmap_context, 0, 0, 0, 0.66);
232 CGContextFillRect(bitmap_context, bitmap_rect);
233
234 PaintCanvasToView();
235 }
236
237 void WebWidgetHost::Resize(const gfx::Rect& rect) { 209 void WebWidgetHost::Resize(const gfx::Rect& rect) {
238 // Force an entire re-paint. TODO(darin): Maybe reuse this memory buffer. 210 // Force an entire re-paint. TODO(darin): Maybe reuse this memory buffer.
239 DiscardBackingStore(); 211 DiscardBackingStore();
240 webwidget_->Resize(gfx::Size(rect.width(), rect.height())); 212 webwidget_->Resize(gfx::Size(rect.width(), rect.height()));
241 } 213 }
242 214
243 void WebWidgetHost::MouseEvent(NSEvent *event) { 215 void WebWidgetHost::MouseEvent(NSEvent *event) {
244 WebMouseEvent web_event(event, view_); 216 WebMouseEvent web_event(event, view_);
245 switch (web_event.type) { 217 switch (web_event.type) {
246 case WebInputEvent::MOUSE_MOVE: 218 case WebInputEvent::MOUSE_MOVE:
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 void WebWidgetHost::PaintRect(const gfx::Rect& rect) { 253 void WebWidgetHost::PaintRect(const gfx::Rect& rect) {
282 #ifndef NDEBUG 254 #ifndef NDEBUG
283 DCHECK(!painting_); 255 DCHECK(!painting_);
284 #endif 256 #endif
285 DCHECK(canvas_.get()); 257 DCHECK(canvas_.get());
286 258
287 set_painting(true); 259 set_painting(true);
288 webwidget_->Paint(canvas_.get(), rect); 260 webwidget_->Paint(canvas_.get(), rect);
289 set_painting(false); 261 set_painting(false);
290 } 262 }
OLDNEW
« no previous file with comments | « webkit/tools/test_shell/layout_test_controller.cc ('k') | webkit/tools/test_shell/test_shell.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698