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

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

Issue 1259913003: MacViews: Implement Tab Dragging (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@20150529-ViewsBrowser-DisableCertificateDialog
Patch Set: update comments, still a TODO Created 5 years, 4 months 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/input_method.h" 10 #include "ui/base/ime/input_method.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 bool DispatchEventToMenu(views::Widget* widget, ui::KeyboardCode key_code) { 47 bool DispatchEventToMenu(views::Widget* widget, ui::KeyboardCode key_code) {
48 MenuController* menuController = MenuController::GetActiveInstance(); 48 MenuController* menuController = MenuController::GetActiveInstance();
49 if (menuController && menuController->owner() == widget) { 49 if (menuController && menuController->owner() == widget) {
50 if (menuController->OnWillDispatchKeyEvent(0, key_code) == 50 if (menuController->OnWillDispatchKeyEvent(0, key_code) ==
51 ui::POST_DISPATCH_NONE) 51 ui::POST_DISPATCH_NONE)
52 return true; 52 return true;
53 } 53 }
54 return false; 54 return false;
55 } 55 }
56 56
57 bool g_ignore_mouse_events = false;
58
57 } // namespace 59 } // namespace
58 60
59 @interface BridgedContentView () 61 @interface BridgedContentView ()
60 62
61 // Translates keycodes and modifiers on |theEvent| to ui::KeyEvents and passes 63 // Translates keycodes and modifiers on |theEvent| to ui::KeyEvents and passes
62 // the event to the InputMethod for dispatch. 64 // the event to the InputMethod for dispatch.
63 - (void)handleKeyEvent:(NSEvent*)theEvent; 65 - (void)handleKeyEvent:(NSEvent*)theEvent;
64 66
65 // Handles an NSResponder Action Message by mapping it to a corresponding text 67 // Handles an NSResponder Action Message by mapping it to a corresponding text
66 // editing command from ui_strings.grd and, when not being sent to a 68 // editing command from ui_strings.grd and, when not being sent to a
(...skipping 19 matching lines...) Expand all
86 - (void)copy:(id)sender; 88 - (void)copy:(id)sender;
87 - (void)paste:(id)sender; 89 - (void)paste:(id)sender;
88 - (void)selectAll:(id)sender; 90 - (void)selectAll:(id)sender;
89 91
90 @end 92 @end
91 93
92 @implementation BridgedContentView 94 @implementation BridgedContentView
93 95
94 @synthesize hostedView = hostedView_; 96 @synthesize hostedView = hostedView_;
95 @synthesize textInputClient = textInputClient_; 97 @synthesize textInputClient = textInputClient_;
98 @synthesize ignoreMouseEvents = ignoreMouseEvents_;
96 @synthesize mouseDownCanMoveWindow = mouseDownCanMoveWindow_; 99 @synthesize mouseDownCanMoveWindow = mouseDownCanMoveWindow_;
97 100
98 - (id)initWithView:(views::View*)viewToHost { 101 - (id)initWithView:(views::View*)viewToHost {
99 DCHECK(viewToHost); 102 DCHECK(viewToHost);
100 gfx::Rect bounds = viewToHost->bounds(); 103 gfx::Rect bounds = viewToHost->bounds();
101 // To keep things simple, assume the origin is (0, 0) until there exists a use 104 // To keep things simple, assume the origin is (0, 0) until there exists a use
102 // case for something other than that. 105 // case for something other than that.
103 DCHECK(bounds.origin().IsOrigin()); 106 DCHECK(bounds.origin().IsOrigin());
104 NSRect initialFrame = NSMakeRect(0, 0, bounds.width(), bounds.height()); 107 NSRect initialFrame = NSMakeRect(0, 0, bounds.width(), bounds.height());
105 if ((self = [super initWithFrame:initialFrame])) { 108 if ((self = [super initWithFrame:initialFrame])) {
106 hostedView_ = viewToHost; 109 hostedView_ = viewToHost;
107 110
108 // Apple's documentation says that NSTrackingActiveAlways is incompatible 111 // Apple's documentation says that NSTrackingActiveAlways is incompatible
109 // with NSTrackingCursorUpdate, so use NSTrackingActiveInActiveApp. 112 // with NSTrackingCursorUpdate, so use NSTrackingActiveInActiveApp.
110 cursorTrackingArea_.reset([[CrTrackingArea alloc] 113 cursorTrackingArea_.reset([[CrTrackingArea alloc]
111 initWithRect:NSZeroRect 114 initWithRect:NSZeroRect
112 options:NSTrackingMouseMoved | NSTrackingCursorUpdate | 115 options:NSTrackingMouseMoved | NSTrackingCursorUpdate |
113 NSTrackingActiveInActiveApp | NSTrackingInVisibleRect 116 NSTrackingActiveInActiveApp | NSTrackingInVisibleRect
114 owner:self 117 owner:self
115 userInfo:nil]); 118 userInfo:nil]);
116 [self addTrackingArea:cursorTrackingArea_.get()]; 119 [self addTrackingArea:cursorTrackingArea_.get()];
117 } 120 }
118 return self; 121 return self;
119 } 122 }
120 123
124 - (void)setIgnoreMouseEvents:(BOOL)flag {
125 ignoreMouseEvents_ = flag;
126 g_ignore_mouse_events = flag;
127 }
128
121 - (void)clearView { 129 - (void)clearView {
122 hostedView_ = NULL; 130 hostedView_ = NULL;
123 [cursorTrackingArea_.get() clearOwner]; 131 [cursorTrackingArea_.get() clearOwner];
124 [self removeTrackingArea:cursorTrackingArea_.get()]; 132 [self removeTrackingArea:cursorTrackingArea_.get()];
125 } 133 }
126 134
127 - (void)processCapturedMouseEvent:(NSEvent*)theEvent { 135 - (void)processCapturedMouseEvent:(NSEvent*)theEvent {
136 if (CGEventGetIntegerValueField([theEvent CGEvent], kCGEventSourceUserData)) {
137 DLOG(INFO) << "Ignoring generated event in capture.";
138 return;
139 }
140
128 if (!hostedView_) 141 if (!hostedView_)
129 return; 142 return;
130 143
131 NSWindow* source = [theEvent window]; 144 NSWindow* source = [theEvent window];
132 NSWindow* target = [self window]; 145 NSWindow* target = [self window];
133 DCHECK(target); 146 DCHECK(target);
134 147
135 // If it's the view's window, process normally. 148 // If it's the view's window, process normally.
136 if ([target isEqual:source]) { 149 if ([target isEqual:source]) {
137 [self mouseEvent:theEvent]; 150 [self mouseEvent:theEvent];
138 return; 151 return;
139 } 152 }
140 153
141 ui::MouseEvent event(theEvent); 154 ui::MouseEvent event(theEvent);
142 event.set_location( 155 event.set_location(
143 MovePointToWindow([theEvent locationInWindow], source, target)); 156 MovePointToWindow([theEvent locationInWindow], source, target));
157 DLOG(INFO) << "processing captured event in window at: " << event.location().T oString();
144 hostedView_->GetWidget()->OnMouseEvent(&event); 158 hostedView_->GetWidget()->OnMouseEvent(&event);
145 } 159 }
146 160
147 - (void)updateTooltipIfRequiredAt:(const gfx::Point&)locationInContent { 161 - (void)updateTooltipIfRequiredAt:(const gfx::Point&)locationInContent {
148 DCHECK(hostedView_); 162 DCHECK(hostedView_);
149 base::string16 newTooltipText; 163 base::string16 newTooltipText;
150 164
151 views::View* view = hostedView_->GetTooltipHandlerForPoint(locationInContent); 165 views::View* view = hostedView_->GetTooltipHandlerForPoint(locationInContent);
152 if (view) { 166 if (view) {
153 gfx::Point viewPoint = locationInContent; 167 gfx::Point viewPoint = locationInContent;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 // BaseView implementation. 266 // BaseView implementation.
253 267
254 // Don't use tracking areas from BaseView. BridgedContentView's tracks 268 // Don't use tracking areas from BaseView. BridgedContentView's tracks
255 // NSTrackingCursorUpdate and Apple's documentation suggests it's incompatible. 269 // NSTrackingCursorUpdate and Apple's documentation suggests it's incompatible.
256 - (void)enableTracking { 270 - (void)enableTracking {
257 } 271 }
258 272
259 // Translates the location of |theEvent| to toolkit-views coordinates and passes 273 // Translates the location of |theEvent| to toolkit-views coordinates and passes
260 // the event to NativeWidgetMac for handling. 274 // the event to NativeWidgetMac for handling.
261 - (void)mouseEvent:(NSEvent*)theEvent { 275 - (void)mouseEvent:(NSEvent*)theEvent {
262 if (!hostedView_) 276 if (CGEventGetIntegerValueField([theEvent CGEvent], kCGEventSourceUserData)) {
277 DLOG(INFO) << "Ignoring generated event [regular].";
278 return;
279 }
280
281 if (!hostedView_ || g_ignore_mouse_events)
263 return; 282 return;
264 283
265 ui::MouseEvent event(theEvent); 284 ui::MouseEvent event(theEvent);
266 285
286 //DLOG(INFO) << "processing regular mouse event event in window at: " << event .location().ToString();
287
267 // Aura updates tooltips with the help of aura::Window::AddPreTargetHandler(). 288 // Aura updates tooltips with the help of aura::Window::AddPreTargetHandler().
268 // Mac hooks in here. 289 // Mac hooks in here.
269 [self updateTooltipIfRequiredAt:event.location()]; 290 [self updateTooltipIfRequiredAt:event.location()];
270 291
271 hostedView_->GetWidget()->OnMouseEvent(&event); 292 hostedView_->GetWidget()->OnMouseEvent(&event);
272 } 293 }
273 294
274 // NSView implementation. 295 // NSView implementation.
275 296
276 - (BOOL)acceptsFirstResponder { 297 - (BOOL)acceptsFirstResponder {
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 } 728 }
708 729
709 return [super accessibilityAttributeValue:attribute]; 730 return [super accessibilityAttributeValue:attribute];
710 } 731 }
711 732
712 - (id)accessibilityHitTest:(NSPoint)point { 733 - (id)accessibilityHitTest:(NSPoint)point {
713 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; 734 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point];
714 } 735 }
715 736
716 @end 737 @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