Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(215)

Side by Side Diff: ui/views/cocoa/bridged_content_view.mm

Issue 789763002: MacViews: Implement capture using NSEvent local+global monitors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@20140812-MacViews-LAYERS2-PRESQUASH
Patch Set: fix sorting Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/cocoa/bridged_content_view.h ('k') | ui/views/cocoa/bridged_native_widget.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "ui/gfx/geometry/rect.h" 12 #include "ui/gfx/geometry/rect.h"
13 #include "ui/strings/grit/ui_strings.h" 13 #include "ui/strings/grit/ui_strings.h"
14 #include "ui/views/view.h" 14 #include "ui/views/view.h"
15 #include "ui/views/widget/widget.h" 15 #include "ui/views/widget/widget.h"
16 16
17 namespace {
18
19 // Convert a |point| in |source_window|'s AppKit coordinate system (origin at
20 // the bottom left of the window) to |target_window|'s content rect, with the
21 // origin at the top left of the content area.
22 // If |source_window| is nil, |point| will be treated as screen coordinates.
23 gfx::Point MovePointToWindow(const NSPoint& point,
24 NSWindow* source_window,
25 NSWindow* target_window) {
26 NSPoint point_in_screen = source_window
27 ? [source_window convertBaseToScreen:point]
28 : point;
29
30 NSPoint point_in_window = [target_window convertScreenToBase:point_in_screen];
31 NSRect content_rect =
32 [target_window contentRectForFrameRect:[target_window frame]];
33 return gfx::Point(point_in_window.x,
34 NSHeight(content_rect) - point_in_window.y);
35 }
36
37 }
38
17 @interface BridgedContentView () 39 @interface BridgedContentView ()
18 40
19 // Translates the location of |theEvent| to toolkit-views coordinates and passes 41 // Translates the location of |theEvent| to toolkit-views coordinates and passes
20 // the event to NativeWidgetMac for handling. 42 // the event to NativeWidgetMac for handling.
21 - (void)handleMouseEvent:(NSEvent*)theEvent; 43 - (void)handleMouseEvent:(NSEvent*)theEvent;
22 44
23 // Execute a command on the currently focused TextInputClient. 45 // Execute a command on the currently focused TextInputClient.
24 // |commandId| should be a resource ID from ui_strings.grd. 46 // |commandId| should be a resource ID from ui_strings.grd.
25 - (void)doCommandByID:(int)commandId; 47 - (void)doCommandByID:(int)commandId;
26 48
(...skipping 25 matching lines...) Expand all
52 } 74 }
53 return self; 75 return self;
54 } 76 }
55 77
56 - (void)clearView { 78 - (void)clearView {
57 hostedView_ = NULL; 79 hostedView_ = NULL;
58 [trackingArea_.get() clearOwner]; 80 [trackingArea_.get() clearOwner];
59 [self removeTrackingArea:trackingArea_.get()]; 81 [self removeTrackingArea:trackingArea_.get()];
60 } 82 }
61 83
84 - (void)processCapturedMouseEvent:(NSEvent*)theEvent {
85 if (!hostedView_)
86 return;
87
88 NSWindow* source = [theEvent window];
89 NSWindow* target = [self window];
90 DCHECK(target);
91
92 // If it's the view's window, process normally.
93 if ([target isEqual:source]) {
94 [self handleMouseEvent:theEvent];
95 return;
96 }
97
98 ui::MouseEvent event(theEvent);
99 event.set_location(
100 MovePointToWindow([theEvent locationInWindow], source, target));
101 hostedView_->GetWidget()->OnMouseEvent(&event);
102 }
103
62 // BridgedContentView private implementation. 104 // BridgedContentView private implementation.
63 105
64 - (void)handleMouseEvent:(NSEvent*)theEvent { 106 - (void)handleMouseEvent:(NSEvent*)theEvent {
65 if (!hostedView_) 107 if (!hostedView_)
66 return; 108 return;
67 109
68 ui::MouseEvent event(theEvent); 110 ui::MouseEvent event(theEvent);
69 hostedView_->GetWidget()->OnMouseEvent(&event); 111 hostedView_->GetWidget()->OnMouseEvent(&event);
70 } 112 }
71 113
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 } 363 }
322 364
323 return [super accessibilityAttributeValue:attribute]; 365 return [super accessibilityAttributeValue:attribute];
324 } 366 }
325 367
326 - (id)accessibilityHitTest:(NSPoint)point { 368 - (id)accessibilityHitTest:(NSPoint)point {
327 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; 369 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point];
328 } 370 }
329 371
330 @end 372 @end
OLDNEW
« no previous file with comments | « ui/views/cocoa/bridged_content_view.h ('k') | ui/views/cocoa/bridged_native_widget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698