| 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 13 matching lines...) Expand all Loading... |
| 24 #include "ui/strings/grit/ui_strings.h" | 24 #include "ui/strings/grit/ui_strings.h" |
| 25 #include "ui/views/controls/menu/menu_config.h" | 25 #include "ui/views/controls/menu/menu_config.h" |
| 26 #include "ui/views/controls/menu/menu_controller.h" | 26 #include "ui/views/controls/menu/menu_controller.h" |
| 27 #include "ui/views/view.h" | 27 #include "ui/views/view.h" |
| 28 #include "ui/views/widget/widget.h" | 28 #include "ui/views/widget/widget.h" |
| 29 | 29 |
| 30 using views::MenuController; | 30 using views::MenuController; |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 bool g_ignore_mouse_events = false; |
| 35 |
| 34 // Returns true if all four corners of |rect| are contained inside |path|. | 36 // Returns true if all four corners of |rect| are contained inside |path|. |
| 35 bool IsRectInsidePath(NSRect rect, NSBezierPath* path) { | 37 bool IsRectInsidePath(NSRect rect, NSBezierPath* path) { |
| 36 return [path containsPoint:rect.origin] && | 38 return [path containsPoint:rect.origin] && |
| 37 [path containsPoint:NSMakePoint(rect.origin.x + rect.size.width, | 39 [path containsPoint:NSMakePoint(rect.origin.x + rect.size.width, |
| 38 rect.origin.y)] && | 40 rect.origin.y)] && |
| 39 [path containsPoint:NSMakePoint(rect.origin.x, | 41 [path containsPoint:NSMakePoint(rect.origin.x, |
| 40 rect.origin.y + rect.size.height)] && | 42 rect.origin.y + rect.size.height)] && |
| 41 [path containsPoint:NSMakePoint(rect.origin.x + rect.size.width, | 43 [path containsPoint:NSMakePoint(rect.origin.x + rect.size.width, |
| 42 rect.origin.y + rect.size.height)]; | 44 rect.origin.y + rect.size.height)]; |
| 43 } | 45 } |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 - (void)paste:(id)sender; | 193 - (void)paste:(id)sender; |
| 192 - (void)selectAll:(id)sender; | 194 - (void)selectAll:(id)sender; |
| 193 | 195 |
| 194 @end | 196 @end |
| 195 | 197 |
| 196 @implementation BridgedContentView | 198 @implementation BridgedContentView |
| 197 | 199 |
| 198 @synthesize hostedView = hostedView_; | 200 @synthesize hostedView = hostedView_; |
| 199 @synthesize textInputClient = textInputClient_; | 201 @synthesize textInputClient = textInputClient_; |
| 200 @synthesize drawMenuBackgroundForBlur = drawMenuBackgroundForBlur_; | 202 @synthesize drawMenuBackgroundForBlur = drawMenuBackgroundForBlur_; |
| 203 @synthesize ignoreMouseEvents = ignoreMouseEvents_; |
| 201 @synthesize mouseDownCanMoveWindow = mouseDownCanMoveWindow_; | 204 @synthesize mouseDownCanMoveWindow = mouseDownCanMoveWindow_; |
| 202 | 205 |
| 203 - (id)initWithView:(views::View*)viewToHost { | 206 - (id)initWithView:(views::View*)viewToHost { |
| 204 DCHECK(viewToHost); | 207 DCHECK(viewToHost); |
| 205 gfx::Rect bounds = viewToHost->bounds(); | 208 gfx::Rect bounds = viewToHost->bounds(); |
| 206 // To keep things simple, assume the origin is (0, 0) until there exists a use | 209 // To keep things simple, assume the origin is (0, 0) until there exists a use |
| 207 // case for something other than that. | 210 // case for something other than that. |
| 208 DCHECK(bounds.origin().IsOrigin()); | 211 DCHECK(bounds.origin().IsOrigin()); |
| 209 NSRect initialFrame = NSMakeRect(0, 0, bounds.width(), bounds.height()); | 212 NSRect initialFrame = NSMakeRect(0, 0, bounds.width(), bounds.height()); |
| 210 if ((self = [super initWithFrame:initialFrame])) { | 213 if ((self = [super initWithFrame:initialFrame])) { |
| 211 hostedView_ = viewToHost; | 214 hostedView_ = viewToHost; |
| 212 | 215 |
| 213 // Apple's documentation says that NSTrackingActiveAlways is incompatible | 216 // Apple's documentation says that NSTrackingActiveAlways is incompatible |
| 214 // with NSTrackingCursorUpdate, so use NSTrackingActiveInActiveApp. | 217 // with NSTrackingCursorUpdate, so use NSTrackingActiveInActiveApp. |
| 215 cursorTrackingArea_.reset([[CrTrackingArea alloc] | 218 cursorTrackingArea_.reset([[CrTrackingArea alloc] |
| 216 initWithRect:NSZeroRect | 219 initWithRect:NSZeroRect |
| 217 options:NSTrackingMouseMoved | NSTrackingCursorUpdate | | 220 options:NSTrackingMouseMoved | NSTrackingCursorUpdate | |
| 218 NSTrackingActiveInActiveApp | NSTrackingInVisibleRect | 221 NSTrackingActiveInActiveApp | NSTrackingInVisibleRect |
| 219 owner:self | 222 owner:self |
| 220 userInfo:nil]); | 223 userInfo:nil]); |
| 221 [self addTrackingArea:cursorTrackingArea_.get()]; | 224 [self addTrackingArea:cursorTrackingArea_.get()]; |
| 222 } | 225 } |
| 223 return self; | 226 return self; |
| 224 } | 227 } |
| 225 | 228 |
| 229 - (void)setIgnoreMouseEvents:(BOOL)flag { |
| 230 ignoreMouseEvents_ = flag; |
| 231 g_ignore_mouse_events = flag; |
| 232 } |
| 233 |
| 226 - (void)clearView { | 234 - (void)clearView { |
| 227 textInputClient_ = nullptr; | 235 textInputClient_ = nullptr; |
| 228 hostedView_ = nullptr; | 236 hostedView_ = nullptr; |
| 229 [cursorTrackingArea_.get() clearOwner]; | 237 [cursorTrackingArea_.get() clearOwner]; |
| 230 [self removeTrackingArea:cursorTrackingArea_.get()]; | 238 [self removeTrackingArea:cursorTrackingArea_.get()]; |
| 231 } | 239 } |
| 232 | 240 |
| 233 - (void)processCapturedMouseEvent:(NSEvent*)theEvent { | 241 - (void)processCapturedMouseEvent:(NSEvent*)theEvent { |
| 242 if (CGEventGetIntegerValueField([theEvent CGEvent], kCGEventSourceUserData)) { |
| 243 DLOG(INFO) << "Ignoring generated event in capture."; |
| 244 return; |
| 245 } |
| 246 |
| 234 if (!hostedView_) | 247 if (!hostedView_) |
| 235 return; | 248 return; |
| 236 | 249 |
| 237 NSWindow* source = [theEvent window]; | 250 NSWindow* source = [theEvent window]; |
| 238 NSWindow* target = [self window]; | 251 NSWindow* target = [self window]; |
| 239 DCHECK(target); | 252 DCHECK(target); |
| 240 | 253 |
| 241 // If it's the view's window, process normally. | 254 // If it's the view's window, process normally. |
| 242 if ([target isEqual:source]) { | 255 if ([target isEqual:source]) { |
| 243 [self mouseEvent:theEvent]; | 256 [self mouseEvent:theEvent]; |
| 244 return; | 257 return; |
| 245 } | 258 } |
| 246 | 259 |
| 247 ui::MouseEvent event(theEvent); | 260 ui::MouseEvent event(theEvent); |
| 248 event.set_location( | 261 event.set_location( |
| 249 MovePointToWindow([theEvent locationInWindow], source, target)); | 262 MovePointToWindow([theEvent locationInWindow], source, target)); |
| 263 DLOG(INFO) << "processing captured event in window at: " |
| 264 << event.location().ToString(); |
| 250 hostedView_->GetWidget()->OnMouseEvent(&event); | 265 hostedView_->GetWidget()->OnMouseEvent(&event); |
| 251 } | 266 } |
| 252 | 267 |
| 253 - (void)updateTooltipIfRequiredAt:(const gfx::Point&)locationInContent { | 268 - (void)updateTooltipIfRequiredAt:(const gfx::Point&)locationInContent { |
| 254 DCHECK(hostedView_); | 269 DCHECK(hostedView_); |
| 255 base::string16 newTooltipText; | 270 base::string16 newTooltipText; |
| 256 | 271 |
| 257 views::View* view = hostedView_->GetTooltipHandlerForPoint(locationInContent); | 272 views::View* view = hostedView_->GetTooltipHandlerForPoint(locationInContent); |
| 258 if (view) { | 273 if (view) { |
| 259 gfx::Point viewPoint = locationInContent; | 274 gfx::Point viewPoint = locationInContent; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 // BaseView implementation. | 397 // BaseView implementation. |
| 383 | 398 |
| 384 // Don't use tracking areas from BaseView. BridgedContentView's tracks | 399 // Don't use tracking areas from BaseView. BridgedContentView's tracks |
| 385 // NSTrackingCursorUpdate and Apple's documentation suggests it's incompatible. | 400 // NSTrackingCursorUpdate and Apple's documentation suggests it's incompatible. |
| 386 - (void)enableTracking { | 401 - (void)enableTracking { |
| 387 } | 402 } |
| 388 | 403 |
| 389 // Translates the location of |theEvent| to toolkit-views coordinates and passes | 404 // Translates the location of |theEvent| to toolkit-views coordinates and passes |
| 390 // the event to NativeWidgetMac for handling. | 405 // the event to NativeWidgetMac for handling. |
| 391 - (void)mouseEvent:(NSEvent*)theEvent { | 406 - (void)mouseEvent:(NSEvent*)theEvent { |
| 392 if (!hostedView_) | 407 if (CGEventGetIntegerValueField([theEvent CGEvent], kCGEventSourceUserData)) { |
| 408 DLOG(INFO) << "Ignoring generated event [regular]."; |
| 409 return; |
| 410 } |
| 411 |
| 412 if (!hostedView_ || g_ignore_mouse_events) |
| 393 return; | 413 return; |
| 394 | 414 |
| 395 ui::MouseEvent event(theEvent); | 415 ui::MouseEvent event(theEvent); |
| 396 | 416 |
| 417 // DLOG(INFO) << "processing regular mouse event event in window at: " << |
| 418 // event.location().ToString(); |
| 419 |
| 397 // Aura updates tooltips with the help of aura::Window::AddPreTargetHandler(). | 420 // Aura updates tooltips with the help of aura::Window::AddPreTargetHandler(). |
| 398 // Mac hooks in here. | 421 // Mac hooks in here. |
| 399 [self updateTooltipIfRequiredAt:event.location()]; | 422 [self updateTooltipIfRequiredAt:event.location()]; |
| 400 | 423 |
| 401 hostedView_->GetWidget()->OnMouseEvent(&event); | 424 hostedView_->GetWidget()->OnMouseEvent(&event); |
| 402 } | 425 } |
| 403 | 426 |
| 404 // NSView implementation. | 427 // NSView implementation. |
| 405 | 428 |
| 406 - (BOOL)acceptsFirstResponder { | 429 - (BOOL)acceptsFirstResponder { |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 } | 927 } |
| 905 | 928 |
| 906 return [super accessibilityAttributeValue:attribute]; | 929 return [super accessibilityAttributeValue:attribute]; |
| 907 } | 930 } |
| 908 | 931 |
| 909 - (id)accessibilityHitTest:(NSPoint)point { | 932 - (id)accessibilityHitTest:(NSPoint)point { |
| 910 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; | 933 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; |
| 911 } | 934 } |
| 912 | 935 |
| 913 @end | 936 @end |
| OLD | NEW |