OLD | NEW |
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 "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
9 #include "grit/ui_strings.h" | 9 #include "grit/ui_strings.h" |
10 #include "ui/base/ime/text_input_client.h" | 10 #include "ui/base/ime/text_input_client.h" |
11 #include "ui/gfx/canvas_paint_mac.h" | 11 #include "ui/gfx/canvas_paint_mac.h" |
12 #include "ui/gfx/geometry/rect.h" | 12 #include "ui/gfx/geometry/rect.h" |
13 #include "ui/views/view.h" | 13 #include "ui/views/view.h" |
| 14 #include "ui/views/widget/widget.h" |
14 | 15 |
15 @interface BridgedContentView () | 16 @interface BridgedContentView () |
16 | 17 |
| 18 // Translates the location of |theEvent| to toolkit-views coordinates and passes |
| 19 // the event to NativeWidgetMac for handling. |
| 20 - (void)handleMouseEvent:(NSEvent*)theEvent; |
| 21 |
17 // Execute a command on the currently focused TextInputClient. | 22 // Execute a command on the currently focused TextInputClient. |
18 // |commandId| should be a resource ID from ui_strings.grd. | 23 // |commandId| should be a resource ID from ui_strings.grd. |
19 - (void)doCommandByID:(int)commandId; | 24 - (void)doCommandByID:(int)commandId; |
20 | 25 |
21 @end | 26 @end |
22 | 27 |
23 @implementation BridgedContentView | 28 @implementation BridgedContentView |
24 | 29 |
25 @synthesize hostedView = hostedView_; | 30 @synthesize hostedView = hostedView_; |
26 @synthesize textInputClient = textInputClient_; | 31 @synthesize textInputClient = textInputClient_; |
(...skipping 10 matching lines...) Expand all Loading... |
37 | 42 |
38 return self; | 43 return self; |
39 } | 44 } |
40 | 45 |
41 - (void)clearView { | 46 - (void)clearView { |
42 hostedView_ = NULL; | 47 hostedView_ = NULL; |
43 } | 48 } |
44 | 49 |
45 // BridgedContentView private implementation. | 50 // BridgedContentView private implementation. |
46 | 51 |
| 52 - (void)handleMouseEvent:(NSEvent*)theEvent { |
| 53 if (!hostedView_) |
| 54 return; |
| 55 |
| 56 ui::MouseEvent event(theEvent); |
| 57 hostedView_->GetWidget()->OnMouseEvent(&event); |
| 58 } |
| 59 |
47 - (void)doCommandByID:(int)commandId { | 60 - (void)doCommandByID:(int)commandId { |
48 if (textInputClient_ && textInputClient_->IsEditingCommandEnabled(commandId)) | 61 if (textInputClient_ && textInputClient_->IsEditingCommandEnabled(commandId)) |
49 textInputClient_->ExecuteEditingCommand(commandId); | 62 textInputClient_->ExecuteEditingCommand(commandId); |
50 } | 63 } |
51 | 64 |
52 // NSView implementation. | 65 // NSView implementation. |
53 | 66 |
| 67 - (BOOL)acceptsFirstResponder { |
| 68 return YES; |
| 69 } |
| 70 |
54 - (void)setFrameSize:(NSSize)newSize { | 71 - (void)setFrameSize:(NSSize)newSize { |
55 [super setFrameSize:newSize]; | 72 [super setFrameSize:newSize]; |
56 if (!hostedView_) | 73 if (!hostedView_) |
57 return; | 74 return; |
58 | 75 |
59 hostedView_->SetSize(gfx::Size(newSize.width, newSize.height)); | 76 hostedView_->SetSize(gfx::Size(newSize.width, newSize.height)); |
60 } | 77 } |
61 | 78 |
62 - (void)drawRect:(NSRect)dirtyRect { | 79 - (void)drawRect:(NSRect)dirtyRect { |
63 if (!hostedView_) | 80 if (!hostedView_) |
64 return; | 81 return; |
65 | 82 |
66 gfx::CanvasSkiaPaint canvas(dirtyRect, false /* opaque */); | 83 gfx::CanvasSkiaPaint canvas(dirtyRect, false /* opaque */); |
67 hostedView_->Paint(&canvas, views::CullSet()); | 84 hostedView_->Paint(&canvas, views::CullSet()); |
68 } | 85 } |
69 | 86 |
| 87 // NSResponder implementation. |
| 88 |
70 - (void)keyDown:(NSEvent*)theEvent { | 89 - (void)keyDown:(NSEvent*)theEvent { |
71 if (textInputClient_) | 90 if (textInputClient_) |
72 [self interpretKeyEvents:@[ theEvent ]]; | 91 [self interpretKeyEvents:@[ theEvent ]]; |
73 else | 92 else |
74 [super keyDown:theEvent]; | 93 [super keyDown:theEvent]; |
75 } | 94 } |
76 | 95 |
| 96 - (void)mouseDown:(NSEvent*)theEvent { |
| 97 [self handleMouseEvent:theEvent]; |
| 98 } |
| 99 |
| 100 - (void)rightMouseDown:(NSEvent*)theEvent { |
| 101 [self handleMouseEvent:theEvent]; |
| 102 } |
| 103 |
| 104 - (void)otherMouseDown:(NSEvent*)theEvent { |
| 105 [self handleMouseEvent:theEvent]; |
| 106 } |
| 107 |
| 108 - (void)mouseUp:(NSEvent*)theEvent { |
| 109 [self handleMouseEvent:theEvent]; |
| 110 } |
| 111 |
| 112 - (void)rightMouseUp:(NSEvent*)theEvent { |
| 113 [self handleMouseEvent:theEvent]; |
| 114 } |
| 115 |
| 116 - (void)otherMouseUp:(NSEvent*)theEvent { |
| 117 [self handleMouseEvent:theEvent]; |
| 118 } |
| 119 |
| 120 - (void)mouseDragged:(NSEvent*)theEvent { |
| 121 [self handleMouseEvent:theEvent]; |
| 122 } |
| 123 |
| 124 - (void)rightMouseDragged:(NSEvent*)theEvent { |
| 125 [self handleMouseEvent:theEvent]; |
| 126 } |
| 127 |
| 128 - (void)otherMouseDragged:(NSEvent*)theEvent { |
| 129 [self handleMouseEvent:theEvent]; |
| 130 } |
| 131 |
| 132 - (void)mouseMoved:(NSEvent*)theEvent { |
| 133 // Note: mouseEntered: and mouseExited: are not handled separately. |
| 134 // |hostedView_| is responsible for converting the move events into entered |
| 135 // and exited events for the view heirarchy. |
| 136 // TODO(tapted): Install/uninstall tracking areas when required so that the |
| 137 // NSView will receive these events outside of tests. |
| 138 [self handleMouseEvent:theEvent]; |
| 139 } |
| 140 |
| 141 - (void)scrollWheel:(NSEvent*)theEvent { |
| 142 [self handleMouseEvent:theEvent]; |
| 143 } |
| 144 |
77 - (void)deleteBackward:(id)sender { | 145 - (void)deleteBackward:(id)sender { |
78 [self doCommandByID:IDS_DELETE_BACKWARD]; | 146 [self doCommandByID:IDS_DELETE_BACKWARD]; |
79 } | 147 } |
80 | 148 |
81 - (void)deleteForward:(id)sender { | 149 - (void)deleteForward:(id)sender { |
82 [self doCommandByID:IDS_DELETE_FORWARD]; | 150 [self doCommandByID:IDS_DELETE_FORWARD]; |
83 } | 151 } |
84 | 152 |
85 - (void)moveLeft:(id)sender { | 153 - (void)moveLeft:(id)sender { |
86 [self doCommandByID:IDS_MOVE_LEFT]; | 154 [self doCommandByID:IDS_MOVE_LEFT]; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 - (void)unmarkText { | 243 - (void)unmarkText { |
176 if (textInputClient_) | 244 if (textInputClient_) |
177 textInputClient_->ConfirmCompositionText(); | 245 textInputClient_->ConfirmCompositionText(); |
178 } | 246 } |
179 | 247 |
180 - (NSArray*)validAttributesForMarkedText { | 248 - (NSArray*)validAttributesForMarkedText { |
181 return @[]; | 249 return @[]; |
182 } | 250 } |
183 | 251 |
184 @end | 252 @end |
OLD | NEW |