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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_mac.mm

Issue 2382003002: Fix dictionary look-up for highlighted text in Mac. (Closed)
Patch Set: Created 4 years, 2 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <objc/runtime.h> 7 #import <objc/runtime.h>
8 #include <OpenGL/gl.h> 8 #include <OpenGL/gl.h>
9 #include <QuartzCore/QuartzCore.h> 9 #include <QuartzCore/QuartzCore.h>
10 #include <stdint.h> 10 #include <stdint.h>
(...skipping 2339 matching lines...) Expand 10 before | Expand all | Expand 10 after
2350 return; 2350 return;
2351 } 2351 }
2352 dispatch_async(dispatch_get_main_queue(), ^{ 2352 dispatch_async(dispatch_get_main_queue(), ^{
2353 [view showDefinitionForAttributedString:string 2353 [view showDefinitionForAttributedString:string
2354 atPoint:baselinePoint]; 2354 atPoint:baselinePoint];
2355 }); 2355 });
2356 } 2356 }
2357 2357
2358 - (void)showLookUpDictionaryOverlayFromRange:(NSRange)range 2358 - (void)showLookUpDictionaryOverlayFromRange:(NSRange)range
2359 targetView:(NSView*)targetView { 2359 targetView:(NSView*)targetView {
2360 RenderWidgetHostImpl* widgetHost = renderWidgetHostView_->render_widget_host_;
2361 if (!widgetHost || !widgetHost->delegate())
2362 return;
2363 widgetHost = widgetHost->delegate()->GetFocusedRenderWidgetHost(widgetHost);
2364
2365 if (!widgetHost)
2366 return;
2367
2368 // TODO(ekaramad): The position reported by the renderer is with respect to
2369 // |widgetHost|'s coordinate space with y-axis inverted to conform to AppKit
2370 // coordinate system. The point will need to be transformed into root view's
2371 // coordinate system (RenderWidgetHostViewMac in this case). However, since
2372 // the callback is invoked on IO thread it will require some thread hopping to
2373 // do so. For this reason, for now, we accept this non-ideal way of fixing the
2374 // point offset manually from the view bounds. This should be revisited when
2375 // fixing issues in TextInputClientMac (https://crbug.com/643233).
2376 gfx::Rect root_box = renderWidgetHostView_->GetViewBounds();
EhsanK 2016/09/29 18:20:35 The logic is almost identical to showLookupDiction
Charlie Reis 2016/09/30 23:00:55 Will we be able to resolve these TODOs soon? I'm
EhsanK 2016/10/06 19:36:09 This one unfortunately might need a major reworkin
2377 gfx::Rect view_box = widgetHost->GetView()->GetViewBounds();
2378
2360 TextInputClientMac::GetInstance()->GetStringFromRange( 2379 TextInputClientMac::GetInstance()->GetStringFromRange(
2361 renderWidgetHostView_->render_widget_host_, range, 2380 widgetHost, range, ^(NSAttributedString* string, NSPoint baselinePoint) {
2362 ^(NSAttributedString* string, NSPoint baselinePoint) { 2381 baselinePoint.x += view_box.origin().x() - root_box.origin().x();
2382 baselinePoint.y +=
2383 root_box.bottom_left().y() - view_box.bottom_left().y();
2363 [self showLookUpDictionaryOverlayInternal:string 2384 [self showLookUpDictionaryOverlayInternal:string
2364 baselinePoint:baselinePoint 2385 baselinePoint:baselinePoint
2365 targetView:targetView]; 2386 targetView:targetView];
2366 } 2387 });
2367 );
2368 } 2388 }
2369 2389
2370 - (void)showLookUpDictionaryOverlayAtPoint:(NSPoint)point { 2390 - (void)showLookUpDictionaryOverlayAtPoint:(NSPoint)point {
2371 gfx::Point rootPoint(point.x, NSHeight([self frame]) - point.y); 2391 gfx::Point rootPoint(point.x, NSHeight([self frame]) - point.y);
2372 gfx::Point transformedPoint; 2392 gfx::Point transformedPoint;
2373 if (!renderWidgetHostView_->render_widget_host_ || 2393 if (!renderWidgetHostView_->render_widget_host_ ||
2374 !renderWidgetHostView_->render_widget_host_->delegate() || 2394 !renderWidgetHostView_->render_widget_host_->delegate() ||
2375 !renderWidgetHostView_->render_widget_host_->delegate() 2395 !renderWidgetHostView_->render_widget_host_->delegate()
2376 ->GetInputEventRouter()) 2396 ->GetInputEventRouter())
2377 return; 2397 return;
(...skipping 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after
3389 3409
3390 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 3410 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
3391 // regions that are not draggable. (See ControlRegionView in 3411 // regions that are not draggable. (See ControlRegionView in
3392 // native_app_window_cocoa.mm). This requires the render host view to be 3412 // native_app_window_cocoa.mm). This requires the render host view to be
3393 // draggable by default. 3413 // draggable by default.
3394 - (BOOL)mouseDownCanMoveWindow { 3414 - (BOOL)mouseDownCanMoveWindow {
3395 return YES; 3415 return YES;
3396 } 3416 }
3397 3417
3398 @end 3418 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698