| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "content/browser/renderer_host/render_widget_host_view_mac.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h" |
| 6 | 6 |
| 7 #import <Carbon/Carbon.h> | 7 #import <Carbon/Carbon.h> |
| 8 #import <objc/runtime.h> | 8 #import <objc/runtime.h> |
| 9 #include <OpenGL/gl.h> | 9 #include <OpenGL/gl.h> |
| 10 #include <QuartzCore/QuartzCore.h> | 10 #include <QuartzCore/QuartzCore.h> |
| (...skipping 2404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2415 | 2415 |
| 2416 if ([text length] == 0) | 2416 if ([text length] == 0) |
| 2417 return; | 2417 return; |
| 2418 scoped_refptr<ui::UniquePasteboard> pasteboard = new ui::UniquePasteboard; | 2418 scoped_refptr<ui::UniquePasteboard> pasteboard = new ui::UniquePasteboard; |
| 2419 NSArray* types = [NSArray arrayWithObject:NSStringPboardType]; | 2419 NSArray* types = [NSArray arrayWithObject:NSStringPboardType]; |
| 2420 [pasteboard->get() declareTypes:types owner:nil]; | 2420 [pasteboard->get() declareTypes:types owner:nil]; |
| 2421 if ([pasteboard->get() setString:text forType:NSStringPboardType]) | 2421 if ([pasteboard->get() setString:text forType:NSStringPboardType]) |
| 2422 NSPerformService(@"Look Up in Dictionary", pasteboard->get()); | 2422 NSPerformService(@"Look Up in Dictionary", pasteboard->get()); |
| 2423 return; | 2423 return; |
| 2424 } | 2424 } |
| 2425 dispatch_async(dispatch_get_main_queue(), ^{ | 2425 NSPoint flippedBaselinePoint = { |
| 2426 NSPoint flippedBaselinePoint = { | 2426 baselinePoint.x, [view frame].size.height - baselinePoint.y, |
| 2427 baselinePoint.x, [view frame].size.height - baselinePoint.y, | 2427 }; |
| 2428 }; | 2428 [view showDefinitionForAttributedString:string atPoint:flippedBaselinePoint]; |
| 2429 [view showDefinitionForAttributedString:string | |
| 2430 atPoint:flippedBaselinePoint]; | |
| 2431 }); | |
| 2432 } | 2429 } |
| 2433 | 2430 |
| 2434 - (void)showLookUpDictionaryOverlayFromRange:(NSRange)range | 2431 - (void)showLookUpDictionaryOverlayFromRange:(NSRange)range |
| 2435 targetView:(NSView*)targetView { | 2432 targetView:(NSView*)targetView { |
| 2436 RenderWidgetHostImpl* widgetHost = renderWidgetHostView_->render_widget_host_; | 2433 content::RenderWidgetHostViewBase* focusedView = |
| 2437 if (!widgetHost || !widgetHost->delegate()) | 2434 renderWidgetHostView_->GetFocusedViewForTextSelection(); |
| 2435 if (!focusedView) |
| 2438 return; | 2436 return; |
| 2439 widgetHost = widgetHost->delegate()->GetFocusedRenderWidgetHost(widgetHost); | |
| 2440 | 2437 |
| 2438 RenderWidgetHostImpl* widgetHost = |
| 2439 RenderWidgetHostImpl::From(focusedView->GetRenderWidgetHost()); |
| 2441 if (!widgetHost) | 2440 if (!widgetHost) |
| 2442 return; | 2441 return; |
| 2443 | 2442 |
| 2444 // TODO(ekaramad): The position reported by the renderer is with respect to | |
| 2445 // |widgetHost|'s coordinate space with y-axis inverted to conform to AppKit | |
| 2446 // coordinate system. The point will need to be transformed into root view's | |
| 2447 // coordinate system (RenderWidgetHostViewMac in this case). However, since | |
| 2448 // the callback is invoked on IO thread it will require some thread hopping to | |
| 2449 // do so. For this reason, for now, we accept this non-ideal way of fixing the | |
| 2450 // point offset manually from the view bounds. This should be revisited when | |
| 2451 // fixing issues in TextInputClientMac (https://crbug.com/643233). | |
| 2452 gfx::Rect root_box = renderWidgetHostView_->GetViewBounds(); | |
| 2453 gfx::Rect view_box = widgetHost->GetView()->GetViewBounds(); | |
| 2454 | |
| 2455 TextInputClientMac::GetInstance()->GetStringFromRange( | 2443 TextInputClientMac::GetInstance()->GetStringFromRange( |
| 2456 widgetHost, range, ^(NSAttributedString* string, NSPoint baselinePoint) { | 2444 widgetHost, range, ^(NSAttributedString* string, NSPoint baselinePoint) { |
| 2457 baselinePoint.x += view_box.origin().x() - root_box.origin().x(); | 2445 if (auto* rwhv = widgetHost->GetView()) { |
| 2458 baselinePoint.y += | 2446 gfx::Point pointInRootView = rwhv->TransformPointToRootCoordSpace( |
| 2459 root_box.bottom_left().y() - view_box.bottom_left().y(); | 2447 gfx::Point(baselinePoint.x, baselinePoint.y)); |
| 2448 baselinePoint.x = pointInRootView.x(); |
| 2449 baselinePoint.y = pointInRootView.y(); |
| 2450 } |
| 2460 [self showLookUpDictionaryOverlayInternal:string | 2451 [self showLookUpDictionaryOverlayInternal:string |
| 2461 baselinePoint:baselinePoint | 2452 baselinePoint:baselinePoint |
| 2462 targetView:targetView]; | 2453 targetView:targetView]; |
| 2463 }); | 2454 }); |
| 2464 } | 2455 } |
| 2465 | 2456 |
| 2466 - (void)showLookUpDictionaryOverlayAtPoint:(NSPoint)point { | 2457 - (void)showLookUpDictionaryOverlayAtPoint:(NSPoint)point { |
| 2467 gfx::Point rootPoint(point.x, NSHeight([self frame]) - point.y); | 2458 gfx::Point rootPoint(point.x, NSHeight([self frame]) - point.y); |
| 2468 gfx::Point transformedPoint; | 2459 gfx::Point transformedPoint; |
| 2469 if (!renderWidgetHostView_->render_widget_host_ || | 2460 if (!renderWidgetHostView_->render_widget_host_ || |
| 2470 !renderWidgetHostView_->render_widget_host_->delegate() || | 2461 !renderWidgetHostView_->render_widget_host_->delegate() || |
| 2471 !renderWidgetHostView_->render_widget_host_->delegate() | 2462 !renderWidgetHostView_->render_widget_host_->delegate() |
| 2472 ->GetInputEventRouter()) | 2463 ->GetInputEventRouter()) |
| 2473 return; | 2464 return; |
| 2474 | 2465 |
| 2475 RenderWidgetHostImpl* widgetHost = | 2466 RenderWidgetHostImpl* widgetHost = |
| 2476 renderWidgetHostView_->render_widget_host_->delegate() | 2467 renderWidgetHostView_->render_widget_host_->delegate() |
| 2477 ->GetInputEventRouter() | 2468 ->GetInputEventRouter() |
| 2478 ->GetRenderWidgetHostAtPoint(renderWidgetHostView_.get(), rootPoint, | 2469 ->GetRenderWidgetHostAtPoint(renderWidgetHostView_.get(), rootPoint, |
| 2479 &transformedPoint); | 2470 &transformedPoint); |
| 2480 if (!widgetHost) | 2471 if (!widgetHost) |
| 2481 return; | 2472 return; |
| 2482 | 2473 |
| 2483 // TODO(ekaramad): The position reported by the renderer is with respect to | |
| 2484 // |widgetHost|'s coordinate space with y-axis inverted to conform to AppKit | |
| 2485 // coordinate system. The point will need to be transformed into root view's | |
| 2486 // coordinate system (RenderWidgetHostViewMac in this case). However, since | |
| 2487 // the callback is invoked on IO thread it will require some thread hopping to | |
| 2488 // do so. For this reason, for now, we accept this non-ideal way of fixing the | |
| 2489 // point offset manually from the view bounds. This should be revisited when | |
| 2490 // fixing issues in TextInputClientMac (https://crbug.com/643233). | |
| 2491 gfx::Rect root_box = renderWidgetHostView_->GetViewBounds(); | |
| 2492 gfx::Rect view_box = widgetHost->GetView()->GetViewBounds(); | |
| 2493 | |
| 2494 TextInputClientMac::GetInstance()->GetStringAtPoint( | 2474 TextInputClientMac::GetInstance()->GetStringAtPoint( |
| 2495 widgetHost, transformedPoint, | 2475 widgetHost, transformedPoint, |
| 2496 ^(NSAttributedString* string, NSPoint baselinePoint) { | 2476 ^(NSAttributedString* string, NSPoint baselinePoint) { |
| 2497 baselinePoint.x += view_box.origin().x() - root_box.origin().x(); | 2477 if (auto* rwhv = widgetHost->GetView()) { |
| 2498 baselinePoint.y += | 2478 gfx::Point pointInRootView = rwhv->TransformPointToRootCoordSpace( |
| 2499 root_box.bottom_left().y() - view_box.bottom_left().y(); | 2479 gfx::Point(baselinePoint.x, baselinePoint.y)); |
| 2480 baselinePoint.x = pointInRootView.x(); |
| 2481 baselinePoint.y = pointInRootView.y(); |
| 2482 } |
| 2500 [self showLookUpDictionaryOverlayInternal:string | 2483 [self showLookUpDictionaryOverlayInternal:string |
| 2501 baselinePoint:baselinePoint | 2484 baselinePoint:baselinePoint |
| 2502 targetView:self]; | 2485 targetView:self]; |
| 2503 }); | 2486 }); |
| 2504 } | 2487 } |
| 2505 | 2488 |
| 2506 // This is invoked only on 10.8 or newer when the user taps a word using | 2489 // This is invoked only on 10.8 or newer when the user taps a word using |
| 2507 // three fingers. | 2490 // three fingers. |
| 2508 - (void)quickLookWithEvent:(NSEvent*)event { | 2491 - (void)quickLookWithEvent:(NSEvent*)event { |
| 2509 NSPoint point = [self convertPoint:[event locationInWindow] fromView:nil]; | 2492 NSPoint point = [self convertPoint:[event locationInWindow] fromView:nil]; |
| (...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3517 | 3500 |
| 3518 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3501 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
| 3519 // regions that are not draggable. (See ControlRegionView in | 3502 // regions that are not draggable. (See ControlRegionView in |
| 3520 // native_app_window_cocoa.mm). This requires the render host view to be | 3503 // native_app_window_cocoa.mm). This requires the render host view to be |
| 3521 // draggable by default. | 3504 // draggable by default. |
| 3522 - (BOOL)mouseDownCanMoveWindow { | 3505 - (BOOL)mouseDownCanMoveWindow { |
| 3523 return YES; | 3506 return YES; |
| 3524 } | 3507 } |
| 3525 | 3508 |
| 3526 @end | 3509 @end |
| OLD | NEW |