| 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/scoped_nsobject.h" | 8 #import "base/mac/scoped_nsobject.h" |
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.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 #import "ui/gfx/mac/coordinate_conversion.h" |
| 12 #include "ui/gfx/geometry/rect.h" | 13 #include "ui/gfx/geometry/rect.h" |
| 13 #include "ui/strings/grit/ui_strings.h" | 14 #include "ui/strings/grit/ui_strings.h" |
| 14 #include "ui/views/view.h" | 15 #include "ui/views/view.h" |
| 15 #include "ui/views/widget/widget.h" | 16 #include "ui/views/widget/widget.h" |
| 16 | 17 |
| 17 @interface BridgedContentView () | 18 @interface BridgedContentView () |
| 18 | 19 |
| 19 // Translates the location of |theEvent| to toolkit-views coordinates and passes | 20 // Translates the location of |theEvent| to toolkit-views coordinates and passes |
| 20 // the event to NativeWidgetMac for handling. | 21 // the event to NativeWidgetMac for handling. |
| 21 - (void)handleMouseEvent:(NSEvent*)theEvent; | 22 - (void)handleMouseEvent:(NSEvent*)theEvent; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 52 } | 53 } |
| 53 return self; | 54 return self; |
| 54 } | 55 } |
| 55 | 56 |
| 56 - (void)clearView { | 57 - (void)clearView { |
| 57 hostedView_ = NULL; | 58 hostedView_ = NULL; |
| 58 [trackingArea_.get() clearOwner]; | 59 [trackingArea_.get() clearOwner]; |
| 59 [self removeTrackingArea:trackingArea_.get()]; | 60 [self removeTrackingArea:trackingArea_.get()]; |
| 60 } | 61 } |
| 61 | 62 |
| 63 - (void)processCapturedMouseEvent:(NSEvent*)theEvent { |
| 64 if (!hostedView_) |
| 65 return; |
| 66 |
| 67 NSWindow* source = [theEvent window]; |
| 68 NSWindow* target = [self window]; |
| 69 DCHECK(target); |
| 70 |
| 71 // If there's no window, or it's the view's window, process normally. |
| 72 if (!source || [target isEqual:source]) { |
| 73 [self handleMouseEvent:theEvent]; |
| 74 return; |
| 75 } |
| 76 |
| 77 // Otherwise, the coordinates will be based in another window's. Modifying |
| 78 // NSEvents is hard, so convert by translating by the relative locations of |
| 79 // *top* left of the *content* area of each window, in screen coordinates. |
| 80 NSRect sourceRect = [source contentRectForFrameRect:[source frame]]; |
| 81 NSRect targetRect = [target contentRectForFrameRect:[target frame]]; |
| 82 gfx::Vector2d offset(NSMinX(sourceRect) - NSMinX(targetRect), |
| 83 NSMaxY(targetRect) - NSMaxY(sourceRect)); |
| 84 |
| 85 ui::MouseEvent event(theEvent); |
| 86 event.set_location(event.location() + offset); |
| 87 hostedView_->GetWidget()->OnMouseEvent(&event); |
| 88 } |
| 89 |
| 62 // BridgedContentView private implementation. | 90 // BridgedContentView private implementation. |
| 63 | 91 |
| 64 - (void)handleMouseEvent:(NSEvent*)theEvent { | 92 - (void)handleMouseEvent:(NSEvent*)theEvent { |
| 65 if (!hostedView_) | 93 if (!hostedView_) |
| 66 return; | 94 return; |
| 67 | 95 |
| 68 ui::MouseEvent event(theEvent); | 96 ui::MouseEvent event(theEvent); |
| 69 hostedView_->GetWidget()->OnMouseEvent(&event); | 97 hostedView_->GetWidget()->OnMouseEvent(&event); |
| 70 } | 98 } |
| 71 | 99 |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 } | 349 } |
| 322 | 350 |
| 323 return [super accessibilityAttributeValue:attribute]; | 351 return [super accessibilityAttributeValue:attribute]; |
| 324 } | 352 } |
| 325 | 353 |
| 326 - (id)accessibilityHitTest:(NSPoint)point { | 354 - (id)accessibilityHitTest:(NSPoint)point { |
| 327 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; | 355 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; |
| 328 } | 356 } |
| 329 | 357 |
| 330 @end | 358 @end |
| OLD | NEW |