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

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

Issue 1318483007: Implement "Look Up In Dictionary" context menu item asynchronously. (OS X) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed review comments. Created 5 years, 3 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
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 10
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 - (void)processedWheelEvent:(const blink::WebMouseWheelEvent&)event 173 - (void)processedWheelEvent:(const blink::WebMouseWheelEvent&)event
174 consumed:(BOOL)consumed; 174 consumed:(BOOL)consumed;
175 175
176 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv; 176 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv;
177 - (void)windowDidChangeBackingProperties:(NSNotification*)notification; 177 - (void)windowDidChangeBackingProperties:(NSNotification*)notification;
178 - (void)windowChangedGlobalFrame:(NSNotification*)notification; 178 - (void)windowChangedGlobalFrame:(NSNotification*)notification;
179 - (void)checkForPluginImeCancellation; 179 - (void)checkForPluginImeCancellation;
180 - (void)updateScreenProperties; 180 - (void)updateScreenProperties;
181 - (void)setResponderDelegate: 181 - (void)setResponderDelegate:
182 (NSObject<RenderWidgetHostViewMacDelegate>*)delegate; 182 (NSObject<RenderWidgetHostViewMacDelegate>*)delegate;
183 - (void)showLookUpDictionaryOverlayInternal:(NSAttributedString*) string
184 baselinePoint:(NSPoint) baselinePoint;
183 @end 185 @end
184 186
185 // A window subclass that allows the fullscreen window to become main and gain 187 // A window subclass that allows the fullscreen window to become main and gain
186 // keyboard focus. This is only used for pepper flash. Normal fullscreen is 188 // keyboard focus. This is only used for pepper flash. Normal fullscreen is
187 // handled by the browser. 189 // handled by the browser.
188 @interface PepperFlashFullscreenWindow : UnderlayOpenGLHostingWindow 190 @interface PepperFlashFullscreenWindow : UnderlayOpenGLHostingWindow
189 @end 191 @end
190 192
191 @implementation PepperFlashFullscreenWindow 193 @implementation PepperFlashFullscreenWindow
192 194
(...skipping 2232 matching lines...) Expand 10 before | Expand all | Expand 10 after
2425 2427
2426 - (void)smartMagnifyWithEvent:(NSEvent*)event { 2428 - (void)smartMagnifyWithEvent:(NSEvent*)event {
2427 const WebGestureEvent& smartMagnifyEvent = 2429 const WebGestureEvent& smartMagnifyEvent =
2428 WebGestureEventBuilder::Build(event, self); 2430 WebGestureEventBuilder::Build(event, self);
2429 if (renderWidgetHostView_ && renderWidgetHostView_->render_widget_host_) { 2431 if (renderWidgetHostView_ && renderWidgetHostView_->render_widget_host_) {
2430 renderWidgetHostView_->render_widget_host_->ForwardGestureEvent( 2432 renderWidgetHostView_->render_widget_host_->ForwardGestureEvent(
2431 smartMagnifyEvent); 2433 smartMagnifyEvent);
2432 } 2434 }
2433 } 2435 }
2434 2436
2437 - (void)showLookUpDictionaryOverlayInternal:(NSAttributedString*) string
2438 baselinePoint:(NSPoint) baselinePoint {
2439 if ([string length] == 0) {
2440 // The PDF plugin does not support getting the attributed string at point.
2441 // Until it does, use NSPerformService(), which opens Dictionary.app.
2442 // TODO(shuchen): Support GetStringAtPoint() & GetStringFromRange() for PDF.
2443 // See crbug.com/152438.
2444 NSString* text = base::SysUTF8ToNSString(
2445 renderWidgetHostView_->selected_text());
2446 if ([text length] == 0)
2447 return;
2448 NSPasteboard* pasteboard = [NSPasteboard pasteboardWithUniqueName];
2449 NSArray* types = [NSArray arrayWithObject:NSStringPboardType];
2450 [pasteboard declareTypes:types owner:nil];
2451 if ([pasteboard setString:text forType:NSStringPboardType])
2452 NSPerformService(@"Look Up in Dictionary", pasteboard);
2453 return;
2454 }
2455 dispatch_async(dispatch_get_main_queue(), ^{
2456 [self showDefinitionForAttributedString:string
2457 atPoint:baselinePoint];
2458 });
2459 }
2460
2461 - (void)showLookUpDictionaryOverlayFromRange:(NSRange)range {
2462 TextInputClientMac::GetInstance()->GetStringFromRange(
2463 renderWidgetHostView_->render_widget_host_, range,
2464 ^(NSAttributedString* string, NSPoint baselinePoint) {
2465 [self showLookUpDictionaryOverlayInternal:string
2466 baselinePoint:baselinePoint];
2467 }
2468 );
2469 }
2470
2471 - (void)showLookUpDictionaryOverlayAtPoint:(NSPoint)point {
2472 TextInputClientMac::GetInstance()->GetStringAtPoint(
2473 renderWidgetHostView_->render_widget_host_,
2474 gfx::Point(point.x, NSHeight([self frame]) - point.y),
2475 ^(NSAttributedString* string, NSPoint baselinePoint) {
2476 [self showLookUpDictionaryOverlayInternal:string
2477 baselinePoint:baselinePoint];
2478 }
2479 );
2480 }
2481
2435 // This is invoked only on 10.8 or newer when the user taps a word using 2482 // This is invoked only on 10.8 or newer when the user taps a word using
2436 // three fingers. 2483 // three fingers.
2437 - (void)quickLookWithEvent:(NSEvent*)event { 2484 - (void)quickLookWithEvent:(NSEvent*)event {
2438 NSPoint point = [self convertPoint:[event locationInWindow] fromView:nil]; 2485 NSPoint point = [self convertPoint:[event locationInWindow] fromView:nil];
2439 TextInputClientMac::GetInstance()->GetStringAtPoint( 2486 [self showLookUpDictionaryOverlayAtPoint:point];
2440 renderWidgetHostView_->render_widget_host_,
2441 gfx::Point(point.x, NSHeight([self frame]) - point.y),
2442 ^(NSAttributedString* string, NSPoint baselinePoint) {
2443 if (string && [string length] > 0) {
2444 dispatch_async(dispatch_get_main_queue(), ^{
2445 [self showDefinitionForAttributedString:string
2446 atPoint:baselinePoint];
2447 });
2448 }
2449 }
2450 );
2451 } 2487 }
2452 2488
2453 // This method handles 2 different types of hardware events. 2489 // This method handles 2 different types of hardware events.
2454 // (Apple does not distinguish between them). 2490 // (Apple does not distinguish between them).
2455 // a. Scrolling the middle wheel of a mouse. 2491 // a. Scrolling the middle wheel of a mouse.
2456 // b. Swiping on the track pad. 2492 // b. Swiping on the track pad.
2457 // 2493 //
2458 // This method is responsible for 2 types of behavior: 2494 // This method is responsible for 2 types of behavior:
2459 // a. Scrolling the content of window. 2495 // a. Scrolling the content of window.
2460 // b. Navigating forwards/backwards in history. 2496 // b. Navigating forwards/backwards in history.
(...skipping 946 matching lines...) Expand 10 before | Expand all | Expand 10 after
3407 3443
3408 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 3444 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
3409 // regions that are not draggable. (See ControlRegionView in 3445 // regions that are not draggable. (See ControlRegionView in
3410 // native_app_window_cocoa.mm). This requires the render host view to be 3446 // native_app_window_cocoa.mm). This requires the render host view to be
3411 // draggable by default. 3447 // draggable by default.
3412 - (BOOL)mouseDownCanMoveWindow { 3448 - (BOOL)mouseDownCanMoveWindow {
3413 return YES; 3449 return YES;
3414 } 3450 }
3415 3451
3416 @end 3452 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698