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

Side by Side Diff: chrome/browser/renderer_host/render_widget_host_view_mac.mm

Issue 6904026: Add and use gfx::ScopedNSGraphicsContextState (ui/gfx/scoped_ns_graphics_context_state_mac.h). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 8 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
OLDNEW
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 <QuartzCore/QuartzCore.h> 5 #include <QuartzCore/QuartzCore.h>
6 6
7 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" 7 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h"
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 24 matching lines...) Expand all
35 #include "content/common/gpu/gpu_messages.h" 35 #include "content/common/gpu/gpu_messages.h"
36 #include "content/common/native_web_keyboard_event.h" 36 #include "content/common/native_web_keyboard_event.h"
37 #include "content/common/plugin_messages.h" 37 #include "content/common/plugin_messages.h"
38 #include "content/common/view_messages.h" 38 #include "content/common/view_messages.h"
39 #include "skia/ext/platform_canvas.h" 39 #include "skia/ext/platform_canvas.h"
40 #import "third_party/mozilla/ComplexTextInputPanel.h" 40 #import "third_party/mozilla/ComplexTextInputPanel.h"
41 #include "third_party/skia/include/core/SkColor.h" 41 #include "third_party/skia/include/core/SkColor.h"
42 #include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebInputEventFact ory.h" 42 #include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebInputEventFact ory.h"
43 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 43 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
44 #include "ui/gfx/gl/gl_switches.h" 44 #include "ui/gfx/gl/gl_switches.h"
45 #include "ui/gfx/scoped_ns_graphics_context_state_mac.h"
45 #include "ui/gfx/surface/io_surface_support_mac.h" 46 #include "ui/gfx/surface/io_surface_support_mac.h"
46 #include "webkit/glue/webaccessibility.h" 47 #include "webkit/glue/webaccessibility.h"
47 #include "webkit/plugins/npapi/webplugin.h" 48 #include "webkit/plugins/npapi/webplugin.h"
48 49
49 using WebKit::WebInputEvent; 50 using WebKit::WebInputEvent;
50 using WebKit::WebInputEventFactory; 51 using WebKit::WebInputEventFactory;
51 using WebKit::WebMouseEvent; 52 using WebKit::WebMouseEvent;
52 using WebKit::WebMouseWheelEvent; 53 using WebKit::WebMouseWheelEvent;
53 54
54 static inline int ToWebKitModifiers(NSUInteger flags) { 55 static inline int ToWebKitModifiers(NSUInteger flags) {
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 CGLUnlockContext(cglContext_); 410 CGLUnlockContext(cglContext_);
410 } 411 }
411 412
412 - (void)drawRect:(NSRect)rect { 413 - (void)drawRect:(NSRect)rect {
413 if (!CommandLine::ForCurrentProcess()->HasSwitch( 414 if (!CommandLine::ForCurrentProcess()->HasSwitch(
414 switches::kDisableHolePunching)) { 415 switches::kDisableHolePunching)) {
415 const NSRect* dirtyRects; 416 const NSRect* dirtyRects;
416 int dirtyRectCount; 417 int dirtyRectCount;
417 [self getRectsBeingDrawn:&dirtyRects count:&dirtyRectCount]; 418 [self getRectsBeingDrawn:&dirtyRects count:&dirtyRectCount];
418 419
419 [NSGraphicsContext saveGraphicsState]; 420 gfx::ScopedNSGraphicsContextState scopedGState;
Nico 2011/04/26 17:56:28 hm, this line in itself isn't very obvious. Maybe
Robert Sesek 2011/04/26 18:50:53 This matches the CGContext version...
420 421
421 // Mask out any cutout rects--somewhat counterintuitively cutout rects are 422 // Mask out any cutout rects--somewhat counterintuitively cutout rects are
422 // places where clearColor is *not* drawn. The trick is that drawing nothing 423 // places where clearColor is *not* drawn. The trick is that drawing nothing
423 // lets the parent view (i.e., the web page) show through, whereas drawing 424 // lets the parent view (i.e., the web page) show through, whereas drawing
424 // clearColor punches a hole in the window (letting OpenGL show through). 425 // clearColor punches a hole in the window (letting OpenGL show through).
425 if ([cutoutRects_.get() count] > 0) { 426 if ([cutoutRects_.get() count] > 0) {
426 NSBezierPath* path = [NSBezierPath bezierPath]; 427 NSBezierPath* path = [NSBezierPath bezierPath];
427 // Trace the bounds clockwise to give a base clip rect of the whole view. 428 // Trace the bounds clockwise to give a base clip rect of the whole view.
428 NSRect bounds = [self bounds]; 429 NSRect bounds = [self bounds];
429 [path moveToPoint:bounds.origin]; 430 [path moveToPoint:bounds.origin];
430 [path lineToPoint:NSMakePoint(NSMinX(bounds), NSMaxY(bounds))]; 431 [path lineToPoint:NSMakePoint(NSMinX(bounds), NSMaxY(bounds))];
431 [path lineToPoint:NSMakePoint(NSMaxX(bounds), NSMaxY(bounds))]; 432 [path lineToPoint:NSMakePoint(NSMaxX(bounds), NSMaxY(bounds))];
432 [path lineToPoint:NSMakePoint(NSMaxX(bounds), NSMinY(bounds))]; 433 [path lineToPoint:NSMakePoint(NSMaxX(bounds), NSMinY(bounds))];
433 [path closePath]; 434 [path closePath];
434 435
435 // Then trace each cutout rect counterclockwise to remove that region from 436 // Then trace each cutout rect counterclockwise to remove that region from
436 // the clip region. 437 // the clip region.
437 for (NSValue* rectWrapper in cutoutRects_.get()) { 438 for (NSValue* rectWrapper in cutoutRects_.get()) {
438 [path appendBezierPathWithRect:[rectWrapper rectValue]]; 439 [path appendBezierPathWithRect:[rectWrapper rectValue]];
439 } 440 }
440 441
441 [path addClip]; 442 [path addClip];
442 } 443 }
443 444
444 // Punch a hole so that the OpenGL view shows through. 445 // Punch a hole so that the OpenGL view shows through.
445 [[NSColor clearColor] set]; 446 [[NSColor clearColor] set];
446 NSRectFillList(dirtyRects, dirtyRectCount); 447 NSRectFillList(dirtyRects, dirtyRectCount);
447
448 [NSGraphicsContext restoreGraphicsState];
449 } 448 }
450 449
451 [self drawView]; 450 [self drawView];
452 } 451 }
453 452
454 - (void)rightMouseDown:(NSEvent*)event { 453 - (void)rightMouseDown:(NSEvent*)event {
455 // The NSResponder documentation: "Note: The NSView implementation of this 454 // The NSResponder documentation: "Note: The NSView implementation of this
456 // method does not pass the message up the responder chain, it handles it 455 // method does not pass the message up the responder chain, it handles it
457 // directly." 456 // directly."
458 // That's bad, we want the next responder (RWHVMac) to handle this event to 457 // That's bad, we want the next responder (RWHVMac) to handle this event to
(...skipping 2443 matching lines...) Expand 10 before | Expand all | Expand 10 after
2902 if (!string) return NO; 2901 if (!string) return NO;
2903 2902
2904 // If the user is currently using an IME, confirm the IME input, 2903 // If the user is currently using an IME, confirm the IME input,
2905 // and then insert the text from the service, the same as TextEdit and Safari. 2904 // and then insert the text from the service, the same as TextEdit and Safari.
2906 [self confirmComposition]; 2905 [self confirmComposition];
2907 [self insertText:string]; 2906 [self insertText:string];
2908 return YES; 2907 return YES;
2909 } 2908 }
2910 2909
2911 @end 2910 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698