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