| 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" |
| 11 #include "skia/ext/skia_utils_mac.h" | 11 #include "skia/ext/skia_utils_mac.h" |
| 12 #include "ui/base/cocoa/cocoa_base_utils.h" | 12 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 13 #include "ui/base/ime/input_method.h" | 13 #include "ui/base/ime/input_method.h" |
| 14 #include "ui/base/ime/text_input_client.h" | 14 #include "ui/base/ime/text_input_client.h" |
| 15 #include "ui/compositor/canvas_painter.h" | 15 #include "ui/compositor/canvas_painter.h" |
| 16 #import "ui/events/cocoa/cocoa_event_utils.h" | 16 #import "ui/events/cocoa/cocoa_event_utils.h" |
| 17 #include "ui/events/keycodes/dom/dom_code.h" | 17 #include "ui/events/keycodes/dom/dom_code.h" |
| 18 #import "ui/events/keycodes/keyboard_code_conversion_mac.h" | 18 #import "ui/events/keycodes/keyboard_code_conversion_mac.h" |
| 19 #include "ui/gfx/canvas_paint_mac.h" | 19 #include "ui/gfx/canvas_paint_mac.h" |
| 20 #include "ui/gfx/geometry/rect.h" | 20 #include "ui/gfx/geometry/rect.h" |
| 21 #import "ui/gfx/mac/coordinate_conversion.h" | 21 #import "ui/gfx/mac/coordinate_conversion.h" |
| 22 #include "ui/gfx/path.h" | 22 #include "ui/gfx/path.h" |
| 23 #import "ui/gfx/path_mac.h" | 23 #import "ui/gfx/path_mac.h" |
| 24 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 24 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
| 25 #include "ui/strings/grit/ui_strings.h" | 25 #include "ui/strings/grit/ui_strings.h" |
| 26 #include "ui/views/cocoa/cocoa_window_move_loop.h" |
| 26 #include "ui/views/controls/menu/menu_config.h" | 27 #include "ui/views/controls/menu/menu_config.h" |
| 27 #include "ui/views/controls/menu/menu_controller.h" | 28 #include "ui/views/controls/menu/menu_controller.h" |
| 28 #include "ui/views/view.h" | 29 #include "ui/views/view.h" |
| 29 #include "ui/views/widget/widget.h" | 30 #include "ui/views/widget/widget.h" |
| 30 | 31 |
| 31 using views::MenuController; | 32 using views::MenuController; |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 36 // We're sending simulated mouse events in CocoaWindowMoveLoop, and don't want |
| 37 // BridgedContentView to react when we're starting/ending the RunMoveLoop. |
| 38 // When reattaching the dragged tab we're sending the mouse down event to the |
| 39 // parent window we don't have the pointer to, so this flag is global for the |
| 40 // RunMoveLoop. |
| 41 bool g_ignore_mouse_events = false; |
| 42 |
| 35 // Returns true if all four corners of |rect| are contained inside |path|. | 43 // Returns true if all four corners of |rect| are contained inside |path|. |
| 36 bool IsRectInsidePath(NSRect rect, NSBezierPath* path) { | 44 bool IsRectInsidePath(NSRect rect, NSBezierPath* path) { |
| 37 return [path containsPoint:rect.origin] && | 45 return [path containsPoint:rect.origin] && |
| 38 [path containsPoint:NSMakePoint(rect.origin.x + rect.size.width, | 46 [path containsPoint:NSMakePoint(rect.origin.x + rect.size.width, |
| 39 rect.origin.y)] && | 47 rect.origin.y)] && |
| 40 [path containsPoint:NSMakePoint(rect.origin.x, | 48 [path containsPoint:NSMakePoint(rect.origin.x, |
| 41 rect.origin.y + rect.size.height)] && | 49 rect.origin.y + rect.size.height)] && |
| 42 [path containsPoint:NSMakePoint(rect.origin.x + rect.size.width, | 50 [path containsPoint:NSMakePoint(rect.origin.x + rect.size.width, |
| 43 rect.origin.y + rect.size.height)]; | 51 rect.origin.y + rect.size.height)]; |
| 44 } | 52 } |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 initWithRect:NSZeroRect | 226 initWithRect:NSZeroRect |
| 219 options:NSTrackingMouseMoved | NSTrackingCursorUpdate | | 227 options:NSTrackingMouseMoved | NSTrackingCursorUpdate | |
| 220 NSTrackingActiveInActiveApp | NSTrackingInVisibleRect | 228 NSTrackingActiveInActiveApp | NSTrackingInVisibleRect |
| 221 owner:self | 229 owner:self |
| 222 userInfo:nil]); | 230 userInfo:nil]); |
| 223 [self addTrackingArea:cursorTrackingArea_.get()]; | 231 [self addTrackingArea:cursorTrackingArea_.get()]; |
| 224 } | 232 } |
| 225 return self; | 233 return self; |
| 226 } | 234 } |
| 227 | 235 |
| 236 + (void)setIgnoreMouseEvents:(BOOL)flag { |
| 237 g_ignore_mouse_events = flag; |
| 238 } |
| 239 |
| 228 - (void)clearView { | 240 - (void)clearView { |
| 229 textInputClient_ = nullptr; | 241 textInputClient_ = nullptr; |
| 230 hostedView_ = nullptr; | 242 hostedView_ = nullptr; |
| 231 [cursorTrackingArea_.get() clearOwner]; | 243 [cursorTrackingArea_.get() clearOwner]; |
| 232 [self removeTrackingArea:cursorTrackingArea_.get()]; | 244 [self removeTrackingArea:cursorTrackingArea_.get()]; |
| 233 } | 245 } |
| 234 | 246 |
| 235 - (void)processCapturedMouseEvent:(NSEvent*)theEvent { | 247 - (void)processCapturedMouseEvent:(NSEvent*)theEvent { |
| 248 if (CGEventGetIntegerValueField([theEvent CGEvent], kCGEventSourceUserData) == |
| 249 views::CocoaWindowMoveLoop::kCocoaWindowMoveLoopSimulatedEventUserData) { |
| 250 return; |
| 251 } |
| 252 |
| 236 if (!hostedView_) | 253 if (!hostedView_) |
| 237 return; | 254 return; |
| 238 | 255 |
| 239 NSWindow* source = [theEvent window]; | 256 NSWindow* source = [theEvent window]; |
| 240 NSWindow* target = [self window]; | 257 NSWindow* target = [self window]; |
| 241 DCHECK(target); | 258 DCHECK(target); |
| 242 | 259 |
| 243 // If it's the view's window, process normally. | 260 // If it's the view's window, process normally. |
| 244 if ([target isEqual:source]) { | 261 if ([target isEqual:source]) { |
| 245 [self mouseEvent:theEvent]; | 262 [self mouseEvent:theEvent]; |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 // BaseView implementation. | 401 // BaseView implementation. |
| 385 | 402 |
| 386 // Don't use tracking areas from BaseView. BridgedContentView's tracks | 403 // Don't use tracking areas from BaseView. BridgedContentView's tracks |
| 387 // NSTrackingCursorUpdate and Apple's documentation suggests it's incompatible. | 404 // NSTrackingCursorUpdate and Apple's documentation suggests it's incompatible. |
| 388 - (void)enableTracking { | 405 - (void)enableTracking { |
| 389 } | 406 } |
| 390 | 407 |
| 391 // Translates the location of |theEvent| to toolkit-views coordinates and passes | 408 // Translates the location of |theEvent| to toolkit-views coordinates and passes |
| 392 // the event to NativeWidgetMac for handling. | 409 // the event to NativeWidgetMac for handling. |
| 393 - (void)mouseEvent:(NSEvent*)theEvent { | 410 - (void)mouseEvent:(NSEvent*)theEvent { |
| 394 if (!hostedView_) | 411 if (CGEventGetIntegerValueField([theEvent CGEvent], kCGEventSourceUserData) == |
| 412 views::CocoaWindowMoveLoop::kCocoaWindowMoveLoopSimulatedEventUserData) { |
| 413 return; |
| 414 } |
| 415 |
| 416 if (!hostedView_ || g_ignore_mouse_events) |
| 395 return; | 417 return; |
| 396 | 418 |
| 397 ui::MouseEvent event(theEvent); | 419 ui::MouseEvent event(theEvent); |
| 398 | 420 |
| 399 // Aura updates tooltips with the help of aura::Window::AddPreTargetHandler(). | 421 // Aura updates tooltips with the help of aura::Window::AddPreTargetHandler(). |
| 400 // Mac hooks in here. | 422 // Mac hooks in here. |
| 401 [self updateTooltipIfRequiredAt:event.location()]; | 423 [self updateTooltipIfRequiredAt:event.location()]; |
| 402 | 424 |
| 403 hostedView_->GetWidget()->OnMouseEvent(&event); | 425 hostedView_->GetWidget()->OnMouseEvent(&event); |
| 404 } | 426 } |
| (...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 927 } | 949 } |
| 928 | 950 |
| 929 return [super accessibilityAttributeValue:attribute]; | 951 return [super accessibilityAttributeValue:attribute]; |
| 930 } | 952 } |
| 931 | 953 |
| 932 - (id)accessibilityHitTest:(NSPoint)point { | 954 - (id)accessibilityHitTest:(NSPoint)point { |
| 933 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; | 955 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; |
| 934 } | 956 } |
| 935 | 957 |
| 936 @end | 958 @end |
| OLD | NEW |