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 #import "base/mac/mac_util.h" | 8 #import "base/mac/mac_util.h" |
9 #import "base/mac/scoped_nsobject.h" | 9 #import "base/mac/scoped_nsobject.h" |
10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "ui/strings/grit/ui_strings.h" | 24 #include "ui/strings/grit/ui_strings.h" |
25 #include "ui/views/controls/menu/menu_config.h" | 25 #include "ui/views/controls/menu/menu_config.h" |
26 #include "ui/views/controls/menu/menu_controller.h" | 26 #include "ui/views/controls/menu/menu_controller.h" |
27 #include "ui/views/view.h" | 27 #include "ui/views/view.h" |
28 #include "ui/views/widget/widget.h" | 28 #include "ui/views/widget/widget.h" |
29 | 29 |
30 using views::MenuController; | 30 using views::MenuController; |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
| 34 bool g_ignore_mouse_events = false; |
| 35 |
34 // Returns true if all four corners of |rect| are contained inside |path|. | 36 // Returns true if all four corners of |rect| are contained inside |path|. |
35 bool IsRectInsidePath(NSRect rect, NSBezierPath* path) { | 37 bool IsRectInsidePath(NSRect rect, NSBezierPath* path) { |
36 return [path containsPoint:rect.origin] && | 38 return [path containsPoint:rect.origin] && |
37 [path containsPoint:NSMakePoint(rect.origin.x + rect.size.width, | 39 [path containsPoint:NSMakePoint(rect.origin.x + rect.size.width, |
38 rect.origin.y)] && | 40 rect.origin.y)] && |
39 [path containsPoint:NSMakePoint(rect.origin.x, | 41 [path containsPoint:NSMakePoint(rect.origin.x, |
40 rect.origin.y + rect.size.height)] && | 42 rect.origin.y + rect.size.height)] && |
41 [path containsPoint:NSMakePoint(rect.origin.x + rect.size.width, | 43 [path containsPoint:NSMakePoint(rect.origin.x + rect.size.width, |
42 rect.origin.y + rect.size.height)]; | 44 rect.origin.y + rect.size.height)]; |
43 } | 45 } |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 - (void)paste:(id)sender; | 193 - (void)paste:(id)sender; |
192 - (void)selectAll:(id)sender; | 194 - (void)selectAll:(id)sender; |
193 | 195 |
194 @end | 196 @end |
195 | 197 |
196 @implementation BridgedContentView | 198 @implementation BridgedContentView |
197 | 199 |
198 @synthesize hostedView = hostedView_; | 200 @synthesize hostedView = hostedView_; |
199 @synthesize textInputClient = textInputClient_; | 201 @synthesize textInputClient = textInputClient_; |
200 @synthesize drawMenuBackgroundForBlur = drawMenuBackgroundForBlur_; | 202 @synthesize drawMenuBackgroundForBlur = drawMenuBackgroundForBlur_; |
| 203 @synthesize ignoreMouseEvents = ignoreMouseEvents_; |
201 @synthesize mouseDownCanMoveWindow = mouseDownCanMoveWindow_; | 204 @synthesize mouseDownCanMoveWindow = mouseDownCanMoveWindow_; |
202 | 205 |
203 - (id)initWithView:(views::View*)viewToHost { | 206 - (id)initWithView:(views::View*)viewToHost { |
204 DCHECK(viewToHost); | 207 DCHECK(viewToHost); |
205 gfx::Rect bounds = viewToHost->bounds(); | 208 gfx::Rect bounds = viewToHost->bounds(); |
206 // To keep things simple, assume the origin is (0, 0) until there exists a use | 209 // To keep things simple, assume the origin is (0, 0) until there exists a use |
207 // case for something other than that. | 210 // case for something other than that. |
208 DCHECK(bounds.origin().IsOrigin()); | 211 DCHECK(bounds.origin().IsOrigin()); |
209 NSRect initialFrame = NSMakeRect(0, 0, bounds.width(), bounds.height()); | 212 NSRect initialFrame = NSMakeRect(0, 0, bounds.width(), bounds.height()); |
210 if ((self = [super initWithFrame:initialFrame])) { | 213 if ((self = [super initWithFrame:initialFrame])) { |
211 hostedView_ = viewToHost; | 214 hostedView_ = viewToHost; |
212 | 215 |
213 // Apple's documentation says that NSTrackingActiveAlways is incompatible | 216 // Apple's documentation says that NSTrackingActiveAlways is incompatible |
214 // with NSTrackingCursorUpdate, so use NSTrackingActiveInActiveApp. | 217 // with NSTrackingCursorUpdate, so use NSTrackingActiveInActiveApp. |
215 cursorTrackingArea_.reset([[CrTrackingArea alloc] | 218 cursorTrackingArea_.reset([[CrTrackingArea alloc] |
216 initWithRect:NSZeroRect | 219 initWithRect:NSZeroRect |
217 options:NSTrackingMouseMoved | NSTrackingCursorUpdate | | 220 options:NSTrackingMouseMoved | NSTrackingCursorUpdate | |
218 NSTrackingActiveInActiveApp | NSTrackingInVisibleRect | 221 NSTrackingActiveInActiveApp | NSTrackingInVisibleRect |
219 owner:self | 222 owner:self |
220 userInfo:nil]); | 223 userInfo:nil]); |
221 [self addTrackingArea:cursorTrackingArea_.get()]; | 224 [self addTrackingArea:cursorTrackingArea_.get()]; |
222 } | 225 } |
223 return self; | 226 return self; |
224 } | 227 } |
225 | 228 |
| 229 - (void)setIgnoreMouseEvents:(BOOL)flag { |
| 230 ignoreMouseEvents_ = flag; |
| 231 g_ignore_mouse_events = flag; |
| 232 } |
| 233 |
226 - (void)clearView { | 234 - (void)clearView { |
227 textInputClient_ = nullptr; | 235 textInputClient_ = nullptr; |
228 hostedView_ = nullptr; | 236 hostedView_ = nullptr; |
229 [cursorTrackingArea_.get() clearOwner]; | 237 [cursorTrackingArea_.get() clearOwner]; |
230 [self removeTrackingArea:cursorTrackingArea_.get()]; | 238 [self removeTrackingArea:cursorTrackingArea_.get()]; |
231 } | 239 } |
232 | 240 |
233 - (void)processCapturedMouseEvent:(NSEvent*)theEvent { | 241 - (void)processCapturedMouseEvent:(NSEvent*)theEvent { |
| 242 if (CGEventGetIntegerValueField([theEvent CGEvent], kCGEventSourceUserData)) { |
| 243 return; |
| 244 } |
| 245 |
234 if (!hostedView_) | 246 if (!hostedView_) |
235 return; | 247 return; |
236 | 248 |
237 NSWindow* source = [theEvent window]; | 249 NSWindow* source = [theEvent window]; |
238 NSWindow* target = [self window]; | 250 NSWindow* target = [self window]; |
239 DCHECK(target); | 251 DCHECK(target); |
240 | 252 |
241 // If it's the view's window, process normally. | 253 // If it's the view's window, process normally. |
242 if ([target isEqual:source]) { | 254 if ([target isEqual:source]) { |
243 [self mouseEvent:theEvent]; | 255 [self mouseEvent:theEvent]; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 // BaseView implementation. | 394 // BaseView implementation. |
383 | 395 |
384 // Don't use tracking areas from BaseView. BridgedContentView's tracks | 396 // Don't use tracking areas from BaseView. BridgedContentView's tracks |
385 // NSTrackingCursorUpdate and Apple's documentation suggests it's incompatible. | 397 // NSTrackingCursorUpdate and Apple's documentation suggests it's incompatible. |
386 - (void)enableTracking { | 398 - (void)enableTracking { |
387 } | 399 } |
388 | 400 |
389 // Translates the location of |theEvent| to toolkit-views coordinates and passes | 401 // Translates the location of |theEvent| to toolkit-views coordinates and passes |
390 // the event to NativeWidgetMac for handling. | 402 // the event to NativeWidgetMac for handling. |
391 - (void)mouseEvent:(NSEvent*)theEvent { | 403 - (void)mouseEvent:(NSEvent*)theEvent { |
392 if (!hostedView_) | 404 if (CGEventGetIntegerValueField([theEvent CGEvent], kCGEventSourceUserData)) { |
| 405 return; |
| 406 } |
| 407 |
| 408 if (!hostedView_ || g_ignore_mouse_events) |
393 return; | 409 return; |
394 | 410 |
395 ui::MouseEvent event(theEvent); | 411 ui::MouseEvent event(theEvent); |
396 | 412 |
397 // Aura updates tooltips with the help of aura::Window::AddPreTargetHandler(). | 413 // Aura updates tooltips with the help of aura::Window::AddPreTargetHandler(). |
398 // Mac hooks in here. | 414 // Mac hooks in here. |
399 [self updateTooltipIfRequiredAt:event.location()]; | 415 [self updateTooltipIfRequiredAt:event.location()]; |
400 | 416 |
401 hostedView_->GetWidget()->OnMouseEvent(&event); | 417 hostedView_->GetWidget()->OnMouseEvent(&event); |
402 } | 418 } |
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
904 } | 920 } |
905 | 921 |
906 return [super accessibilityAttributeValue:attribute]; | 922 return [super accessibilityAttributeValue:attribute]; |
907 } | 923 } |
908 | 924 |
909 - (id)accessibilityHitTest:(NSPoint)point { | 925 - (id)accessibilityHitTest:(NSPoint)point { |
910 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; | 926 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; |
911 } | 927 } |
912 | 928 |
913 @end | 929 @end |
OLD | NEW |