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

Side by Side Diff: ui/views/cocoa/bridged_content_view.mm

Issue 322893005: MacViews: Add WidgetEventGenerator to abstract platform-specific event generation for tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cull orthogonal stuff, add WidgetTest.MouseEventTypesViaGenerator Created 6 years, 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ui/views/cocoa/bridged_content_view.h" 5 #import "ui/views/cocoa/bridged_content_view.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "ui/gfx/canvas_paint_mac.h" 8 #include "ui/gfx/canvas_paint_mac.h"
9 #include "ui/views/view.h" 9 #include "ui/views/view.h"
10 #include "ui/views/widget/widget.h"
11
12 @interface BridgedContentView ()
13
14 // Translates the location of |theEvent| to toolkit-views coordinates and passes
15 // the event to NativeWidgetMac for handling.
16 - (void)handleMouseEvent:(NSEvent*)theEvent;
17
18 @end
10 19
11 @implementation BridgedContentView 20 @implementation BridgedContentView
12 21
13 @synthesize hostedView = hostedView_; 22 @synthesize hostedView = hostedView_;
14 23
15 - (id)initWithView:(views::View*)viewToHost { 24 - (id)initWithView:(views::View*)viewToHost {
16 DCHECK(viewToHost); 25 DCHECK(viewToHost);
17 gfx::Rect bounds = viewToHost->bounds(); 26 gfx::Rect bounds = viewToHost->bounds();
18 // To keep things simple, assume the origin is (0, 0) until there exists a use 27 // To keep things simple, assume the origin is (0, 0) until there exists a use
19 // case for something other than that. 28 // case for something other than that.
20 DCHECK(bounds.origin().IsOrigin()); 29 DCHECK(bounds.origin().IsOrigin());
21 NSRect initialFrame = NSMakeRect(0, 0, bounds.width(), bounds.height()); 30 NSRect initialFrame = NSMakeRect(0, 0, bounds.width(), bounds.height());
22 if ((self = [super initWithFrame:initialFrame])) 31 if ((self = [super initWithFrame:initialFrame]))
23 hostedView_ = viewToHost; 32 hostedView_ = viewToHost;
24 33
25 return self; 34 return self;
26 } 35 }
27 36
28 - (void)clearView { 37 - (void)clearView {
29 hostedView_ = NULL; 38 hostedView_ = NULL;
30 } 39 }
31 40
41 // BridgedContentView private implementation.
42
43 - (void)handleMouseEvent:(NSEvent*)theEvent {
44 if (!hostedView_)
45 return;
46
47 ui::MouseEvent event(theEvent);
48 hostedView_->GetWidget()->OnMouseEvent(&event);
49 }
50
32 // NSView implementation. 51 // NSView implementation.
33 52
34 - (void)setFrameSize:(NSSize)newSize { 53 - (void)setFrameSize:(NSSize)newSize {
35 [super setFrameSize:newSize]; 54 [super setFrameSize:newSize];
36 if (!hostedView_) 55 if (!hostedView_)
37 return; 56 return;
38 57
39 hostedView_->SetSize(gfx::Size(newSize.width, newSize.height)); 58 hostedView_->SetSize(gfx::Size(newSize.width, newSize.height));
40 } 59 }
41 60
42 - (void)drawRect:(NSRect)dirtyRect { 61 - (void)drawRect:(NSRect)dirtyRect {
43 if (!hostedView_) 62 if (!hostedView_)
44 return; 63 return;
45 64
46 gfx::CanvasSkiaPaint canvas(dirtyRect, false /* opaque */); 65 gfx::CanvasSkiaPaint canvas(dirtyRect, false /* opaque */);
47 hostedView_->Paint(&canvas, views::CullSet()); 66 hostedView_->Paint(&canvas, views::CullSet());
48 } 67 }
49 68
69 - (void)mouseDown:(NSEvent*)theEvent {
70 [self handleMouseEvent:theEvent];
71 }
72
73 - (void)rightMouseDown:(NSEvent*)theEvent {
74 [self handleMouseEvent:theEvent];
75 }
76
77 - (void)otherMouseDown:(NSEvent*)theEvent {
78 [self handleMouseEvent:theEvent];
79 }
80
81 - (void)mouseUp:(NSEvent*)theEvent {
82 [self handleMouseEvent:theEvent];
83 }
84
85 - (void)rightMouseUp:(NSEvent*)theEvent {
86 [self handleMouseEvent:theEvent];
87 }
88
89 - (void)otherMouseUp:(NSEvent*)theEvent {
90 [self handleMouseEvent:theEvent];
91 }
92
93 - (void)mouseDragged:(NSEvent*)theEvent {
94 [self handleMouseEvent:theEvent];
95 }
96
97 - (void)rightMouseDragged:(NSEvent*)theEvent {
98 [self handleMouseEvent:theEvent];
99 }
100
101 - (void)otherMouseDragged:(NSEvent*)theEvent {
102 [self handleMouseEvent:theEvent];
103 }
104
105 - (void)mouseMoved:(NSEvent*)theEvent {
106 [self handleMouseEvent:theEvent];
107 }
108
109 - (void)scrollWheel:(NSEvent*)theEvent {
110 [self handleMouseEvent:theEvent];
111 }
112
113 - (void)mouseEntered:(NSEvent*)theEvent {
114 [self handleMouseEvent:theEvent];
115 }
116
117 - (void)mouseExited:(NSEvent*)theEvent {
118 [self handleMouseEvent:theEvent];
119 }
120
50 @end 121 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698