Chromium Code Reviews| 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 #import "base/mac/sdk_forward_declarations.h" | 10 #import "base/mac/sdk_forward_declarations.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 bool IsRectInsidePath(NSRect rect, NSBezierPath* path) { | 48 bool IsRectInsidePath(NSRect rect, NSBezierPath* path) { |
| 49 return [path containsPoint:rect.origin] && | 49 return [path containsPoint:rect.origin] && |
| 50 [path containsPoint:NSMakePoint(rect.origin.x + rect.size.width, | 50 [path containsPoint:NSMakePoint(rect.origin.x + rect.size.width, |
| 51 rect.origin.y)] && | 51 rect.origin.y)] && |
| 52 [path containsPoint:NSMakePoint(rect.origin.x, | 52 [path containsPoint:NSMakePoint(rect.origin.x, |
| 53 rect.origin.y + rect.size.height)] && | 53 rect.origin.y + rect.size.height)] && |
| 54 [path containsPoint:NSMakePoint(rect.origin.x + rect.size.width, | 54 [path containsPoint:NSMakePoint(rect.origin.x + rect.size.width, |
| 55 rect.origin.y + rect.size.height)]; | 55 rect.origin.y + rect.size.height)]; |
| 56 } | 56 } |
| 57 | 57 |
| 58 #if 0 // BROWSER-55005 | |
|
Avi (use Gerrit)
2016/10/25 15:34:50
Don't commit commented-out code.
snake
2016/10/25 15:46:18
Done.
| |
| 58 // Convert a |point| in |source_window|'s AppKit coordinate system (origin at | 59 // Convert a |point| in |source_window|'s AppKit coordinate system (origin at |
| 59 // the bottom left of the window) to |target_window|'s content rect, with the | 60 // the bottom left of the window) to |target_window|'s content rect, with the |
| 60 // origin at the top left of the content area. | 61 // origin at the top left of the content area. |
| 61 // If |source_window| is nil, |point| will be treated as screen coordinates. | 62 // If |source_window| is nil, |point| will be treated as screen coordinates. |
| 62 gfx::Point MovePointToWindow(const NSPoint& point, | 63 gfx::Point MovePointToWindow(const NSPoint& point, |
| 63 NSWindow* source_window, | 64 NSWindow* source_window, |
| 64 NSWindow* target_window) { | 65 NSWindow* target_window) { |
| 65 NSPoint point_in_screen = source_window | 66 NSPoint point_in_screen = source_window |
| 66 ? ui::ConvertPointFromWindowToScreen(source_window, point) | 67 ? ui::ConvertPointFromWindowToScreen(source_window, point) |
| 67 : point; | 68 : point; |
| 68 | 69 |
| 69 NSPoint point_in_window = | 70 NSPoint point_in_window = |
| 70 ui::ConvertPointFromScreenToWindow(target_window, point_in_screen); | 71 ui::ConvertPointFromScreenToWindow(target_window, point_in_screen); |
| 71 NSRect content_rect = | 72 NSRect content_rect = |
| 72 [target_window contentRectForFrameRect:[target_window frame]]; | 73 [target_window contentRectForFrameRect:[target_window frame]]; |
| 73 return gfx::Point(point_in_window.x, | 74 return gfx::Point(point_in_window.x, |
| 74 NSHeight(content_rect) - point_in_window.y); | 75 NSHeight(content_rect) - point_in_window.y); |
| 75 } | 76 } |
| 77 #endif // BROWSER-55005 | |
| 76 | 78 |
| 77 // Dispatch |event| to |menu_controller| and return true if |event| is | 79 // Dispatch |event| to |menu_controller| and return true if |event| is |
| 78 // swallowed. | 80 // swallowed. |
| 79 bool DispatchEventToMenu(MenuController* menu_controller, ui::KeyEvent* event) { | 81 bool DispatchEventToMenu(MenuController* menu_controller, ui::KeyEvent* event) { |
| 80 return menu_controller && | 82 return menu_controller && |
| 81 menu_controller->OnWillDispatchKeyEvent(event) == | 83 menu_controller->OnWillDispatchKeyEvent(event) == |
| 82 ui::POST_DISPATCH_NONE; | 84 ui::POST_DISPATCH_NONE; |
| 83 } | 85 } |
| 84 | 86 |
| 85 // Returns true if |client| has RTL text. | 87 // Returns true if |client| has RTL text. |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 338 } | 340 } |
| 339 | 341 |
| 340 - (void)clearView { | 342 - (void)clearView { |
| 341 textInputClient_ = nullptr; | 343 textInputClient_ = nullptr; |
| 342 hostedView_ = nullptr; | 344 hostedView_ = nullptr; |
| 343 [[NSDistributedNotificationCenter defaultCenter] removeObserver:self]; | 345 [[NSDistributedNotificationCenter defaultCenter] removeObserver:self]; |
| 344 [cursorTrackingArea_.get() clearOwner]; | 346 [cursorTrackingArea_.get() clearOwner]; |
| 345 [self removeTrackingArea:cursorTrackingArea_.get()]; | 347 [self removeTrackingArea:cursorTrackingArea_.get()]; |
| 346 } | 348 } |
| 347 | 349 |
| 348 - (void)processCapturedMouseEvent:(NSEvent*)theEvent { | |
| 349 if (!hostedView_) | |
| 350 return; | |
| 351 | |
| 352 NSWindow* source = [theEvent window]; | |
| 353 NSWindow* target = [self window]; | |
| 354 DCHECK(target); | |
| 355 | |
| 356 // If it's the view's window, process normally. | |
| 357 if ([target isEqual:source]) { | |
| 358 [self mouseEvent:theEvent]; | |
| 359 return; | |
| 360 } | |
| 361 | |
| 362 ui::MouseEvent event(theEvent); | |
| 363 event.set_location( | |
| 364 MovePointToWindow([theEvent locationInWindow], source, target)); | |
| 365 hostedView_->GetWidget()->OnMouseEvent(&event); | |
| 366 } | |
| 367 | |
| 368 - (void)updateTooltipIfRequiredAt:(const gfx::Point&)locationInContent { | 350 - (void)updateTooltipIfRequiredAt:(const gfx::Point&)locationInContent { |
| 369 DCHECK(hostedView_); | 351 DCHECK(hostedView_); |
| 370 base::string16 newTooltipText; | 352 base::string16 newTooltipText; |
| 371 | 353 |
| 372 views::View* view = hostedView_->GetTooltipHandlerForPoint(locationInContent); | 354 views::View* view = hostedView_->GetTooltipHandlerForPoint(locationInContent); |
| 373 if (view) { | 355 if (view) { |
| 374 gfx::Point viewPoint = locationInContent; | 356 gfx::Point viewPoint = locationInContent; |
| 375 views::View::ConvertPointToScreen(hostedView_, &viewPoint); | 357 views::View::ConvertPointToScreen(hostedView_, &viewPoint); |
| 376 views::View::ConvertPointFromScreen(view, &viewPoint); | 358 views::View::ConvertPointFromScreen(view, &viewPoint); |
| 377 if (!view->GetTooltipText(viewPoint, &newTooltipText)) | 359 if (!view->GetTooltipText(viewPoint, &newTooltipText)) |
| 378 DCHECK(newTooltipText.empty()); | 360 DCHECK(newTooltipText.empty()); |
| 379 } | 361 } |
| 380 if (newTooltipText != lastTooltipText_) { | 362 if (newTooltipText != lastTooltipText_) { |
| 381 std::swap(newTooltipText, lastTooltipText_); | 363 std::swap(newTooltipText, lastTooltipText_); |
| 382 [self setToolTipAtMousePoint:base::SysUTF16ToNSString(lastTooltipText_)]; | 364 [self setToolTipAtMousePoint:base::SysUTF16ToNSString(lastTooltipText_)]; |
| 383 } | 365 } |
| 384 } | 366 } |
| 385 | 367 |
| 368 - (void)hideTooltipIfRequired { | |
| 369 if (!lastTooltipText_.empty()) { | |
| 370 lastTooltipText_.clear(); | |
| 371 [self setToolTipAtMousePoint:nil]; | |
| 372 } | |
| 373 } | |
| 374 | |
| 386 - (void)updateWindowMask { | 375 - (void)updateWindowMask { |
| 387 DCHECK(![self inLiveResize]); | 376 DCHECK(![self inLiveResize]); |
| 388 DCHECK(base::mac::IsOS10_9()); | 377 DCHECK(base::mac::IsOS10_9()); |
| 389 DCHECK(hostedView_); | 378 DCHECK(hostedView_); |
| 390 | 379 |
| 391 views::Widget* widget = hostedView_->GetWidget(); | 380 views::Widget* widget = hostedView_->GetWidget(); |
| 392 if (!widget->non_client_view()) | 381 if (!widget->non_client_view()) |
| 393 return; | 382 return; |
| 394 | 383 |
| 395 const NSRect frameRect = [self bounds]; | 384 const NSRect frameRect = [self bounds]; |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 573 eventFlags:ui::EF_CONTROL_DOWN]; | 562 eventFlags:ui::EF_CONTROL_DOWN]; |
| 574 } | 563 } |
| 575 | 564 |
| 576 // BaseView implementation. | 565 // BaseView implementation. |
| 577 | 566 |
| 578 // Don't use tracking areas from BaseView. BridgedContentView's tracks | 567 // Don't use tracking areas from BaseView. BridgedContentView's tracks |
| 579 // NSTrackingCursorUpdate and Apple's documentation suggests it's incompatible. | 568 // NSTrackingCursorUpdate and Apple's documentation suggests it's incompatible. |
| 580 - (void)enableTracking { | 569 - (void)enableTracking { |
| 581 } | 570 } |
| 582 | 571 |
| 572 // Explicitly ignore BaseView's |dragging_| logic | |
| 573 - (void)mouseDown:(NSEvent*)theEvent { | |
| 574 [self mouseEvent:theEvent]; | |
| 575 } | |
| 576 | |
| 583 // Translates the location of |theEvent| to toolkit-views coordinates and passes | 577 // Translates the location of |theEvent| to toolkit-views coordinates and passes |
| 584 // the event to NativeWidgetMac for handling. | 578 // the event to NativeWidgetMac for handling. |
| 585 - (void)mouseEvent:(NSEvent*)theEvent { | 579 - (void)mouseEvent:(NSEvent*)theEvent { |
| 586 if (!hostedView_) | 580 if (!hostedView_) |
| 587 return; | 581 return; |
| 588 | 582 views::NativeWidgetMac::GetBridgeForNativeWindow([self window]) |
| 589 ui::MouseEvent event(theEvent); | 583 ->OnMouseEvent(theEvent); |
| 590 | |
| 591 // Aura updates tooltips with the help of aura::Window::AddPreTargetHandler(). | |
| 592 // Mac hooks in here. | |
| 593 [self updateTooltipIfRequiredAt:event.location()]; | |
| 594 | |
| 595 hostedView_->GetWidget()->OnMouseEvent(&event); | |
| 596 } | 584 } |
| 597 | 585 |
| 598 // NSView implementation. | 586 // NSView implementation. |
| 599 | 587 |
| 600 - (BOOL)acceptsFirstResponder { | 588 - (BOOL)acceptsFirstResponder { |
| 601 return YES; | 589 return YES; |
| 602 } | 590 } |
| 603 | 591 |
| 604 - (BOOL)becomeFirstResponder { | 592 - (BOOL)becomeFirstResponder { |
| 605 BOOL result = [super becomeFirstResponder]; | 593 BOOL result = [super becomeFirstResponder]; |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 769 | 757 |
| 770 - (void)keyUp:(NSEvent*)theEvent { | 758 - (void)keyUp:(NSEvent*)theEvent { |
| 771 ui::KeyEvent event(theEvent); | 759 ui::KeyEvent event(theEvent); |
| 772 [self handleKeyEvent:&event]; | 760 [self handleKeyEvent:&event]; |
| 773 } | 761 } |
| 774 | 762 |
| 775 - (void)scrollWheel:(NSEvent*)theEvent { | 763 - (void)scrollWheel:(NSEvent*)theEvent { |
| 776 if (!hostedView_) | 764 if (!hostedView_) |
| 777 return; | 765 return; |
| 778 | 766 |
| 779 ui::ScrollEvent event(theEvent); | 767 // Passes the event to BridgedNativeWidget for handling. |
| 780 hostedView_->GetWidget()->OnScrollEvent(&event); | 768 views::NativeWidgetMac::GetBridgeForNativeWindow([self window]) |
| 769 ->OnMouseEvent(theEvent); | |
| 781 } | 770 } |
| 782 | 771 |
| 783 - (void)quickLookWithEvent:(NSEvent*)theEvent { | 772 - (void)quickLookWithEvent:(NSEvent*)theEvent { |
| 784 if (!hostedView_) | 773 if (!hostedView_) |
| 785 return; | 774 return; |
| 786 | 775 |
| 787 const gfx::Point locationInContent = ui::EventLocationFromNative(theEvent); | 776 const gfx::Point locationInContent = ui::EventLocationFromNative(theEvent); |
| 788 views::View* target = hostedView_->GetEventHandlerForPoint(locationInContent); | 777 views::View* target = hostedView_->GetEventHandlerForPoint(locationInContent); |
| 789 if (!target) | 778 if (!target) |
| 790 return; | 779 return; |
| (...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1432 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; | 1421 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; |
| 1433 } | 1422 } |
| 1434 | 1423 |
| 1435 - (id)accessibilityFocusedUIElement { | 1424 - (id)accessibilityFocusedUIElement { |
| 1436 if (!hostedView_) | 1425 if (!hostedView_) |
| 1437 return nil; | 1426 return nil; |
| 1438 return [hostedView_->GetNativeViewAccessible() accessibilityFocusedUIElement]; | 1427 return [hostedView_->GetNativeViewAccessible() accessibilityFocusedUIElement]; |
| 1439 } | 1428 } |
| 1440 | 1429 |
| 1441 @end | 1430 @end |
| OLD | NEW |