| 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 2355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2366 return; | 2366 return; |
| 2367 } | 2367 } |
| 2368 dispatch_async(dispatch_get_main_queue(), ^{ | 2368 dispatch_async(dispatch_get_main_queue(), ^{ |
| 2369 [view showDefinitionForAttributedString:string | 2369 [view showDefinitionForAttributedString:string |
| 2370 atPoint:baselinePoint]; | 2370 atPoint:baselinePoint]; |
| 2371 }); | 2371 }); |
| 2372 } | 2372 } |
| 2373 | 2373 |
| 2374 - (void)showLookUpDictionaryOverlayFromRange:(NSRange)range | 2374 - (void)showLookUpDictionaryOverlayFromRange:(NSRange)range |
| 2375 targetView:(NSView*)targetView { | 2375 targetView:(NSView*)targetView { |
| 2376 RenderWidgetHostImpl* widgetHost = renderWidgetHostView_->render_widget_host_; |
| 2377 if (!widgetHost || !widgetHost->delegate()) |
| 2378 return; |
| 2379 widgetHost = widgetHost->delegate()->GetFocusedRenderWidgetHost(widgetHost); |
| 2380 |
| 2381 if (!widgetHost) |
| 2382 return; |
| 2383 |
| 2384 // TODO(ekaramad): The position reported by the renderer is with respect to |
| 2385 // |widgetHost|'s coordinate space with y-axis inverted to conform to AppKit |
| 2386 // coordinate system. The point will need to be transformed into root view's |
| 2387 // coordinate system (RenderWidgetHostViewMac in this case). However, since |
| 2388 // the callback is invoked on IO thread it will require some thread hopping to |
| 2389 // do so. For this reason, for now, we accept this non-ideal way of fixing the |
| 2390 // point offset manually from the view bounds. This should be revisited when |
| 2391 // fixing issues in TextInputClientMac (https://crbug.com/643233). |
| 2392 gfx::Rect root_box = renderWidgetHostView_->GetViewBounds(); |
| 2393 gfx::Rect view_box = widgetHost->GetView()->GetViewBounds(); |
| 2394 |
| 2376 TextInputClientMac::GetInstance()->GetStringFromRange( | 2395 TextInputClientMac::GetInstance()->GetStringFromRange( |
| 2377 renderWidgetHostView_->render_widget_host_, range, | 2396 widgetHost, range, ^(NSAttributedString* string, NSPoint baselinePoint) { |
| 2378 ^(NSAttributedString* string, NSPoint baselinePoint) { | 2397 baselinePoint.x += view_box.origin().x() - root_box.origin().x(); |
| 2398 baselinePoint.y += |
| 2399 root_box.bottom_left().y() - view_box.bottom_left().y(); |
| 2379 [self showLookUpDictionaryOverlayInternal:string | 2400 [self showLookUpDictionaryOverlayInternal:string |
| 2380 baselinePoint:baselinePoint | 2401 baselinePoint:baselinePoint |
| 2381 targetView:targetView]; | 2402 targetView:targetView]; |
| 2382 } | 2403 }); |
| 2383 ); | |
| 2384 } | 2404 } |
| 2385 | 2405 |
| 2386 - (void)showLookUpDictionaryOverlayAtPoint:(NSPoint)point { | 2406 - (void)showLookUpDictionaryOverlayAtPoint:(NSPoint)point { |
| 2387 gfx::Point rootPoint(point.x, NSHeight([self frame]) - point.y); | 2407 gfx::Point rootPoint(point.x, NSHeight([self frame]) - point.y); |
| 2388 gfx::Point transformedPoint; | 2408 gfx::Point transformedPoint; |
| 2389 if (!renderWidgetHostView_->render_widget_host_ || | 2409 if (!renderWidgetHostView_->render_widget_host_ || |
| 2390 !renderWidgetHostView_->render_widget_host_->delegate() || | 2410 !renderWidgetHostView_->render_widget_host_->delegate() || |
| 2391 !renderWidgetHostView_->render_widget_host_->delegate() | 2411 !renderWidgetHostView_->render_widget_host_->delegate() |
| 2392 ->GetInputEventRouter()) | 2412 ->GetInputEventRouter()) |
| 2393 return; | 2413 return; |
| (...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3396 | 3416 |
| 3397 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3417 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
| 3398 // regions that are not draggable. (See ControlRegionView in | 3418 // regions that are not draggable. (See ControlRegionView in |
| 3399 // native_app_window_cocoa.mm). This requires the render host view to be | 3419 // native_app_window_cocoa.mm). This requires the render host view to be |
| 3400 // draggable by default. | 3420 // draggable by default. |
| 3401 - (BOOL)mouseDownCanMoveWindow { | 3421 - (BOOL)mouseDownCanMoveWindow { |
| 3402 return YES; | 3422 return YES; |
| 3403 } | 3423 } |
| 3404 | 3424 |
| 3405 @end | 3425 @end |
| OLD | NEW |