Chromium Code Reviews| 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 <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 2411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2422 | 2422 |
| 2423 - (void)smartMagnifyWithEvent:(NSEvent*)event { | 2423 - (void)smartMagnifyWithEvent:(NSEvent*)event { |
| 2424 const WebGestureEvent& smartMagnifyEvent = | 2424 const WebGestureEvent& smartMagnifyEvent = |
| 2425 WebInputEventFactory::gestureEvent(event, self); | 2425 WebInputEventFactory::gestureEvent(event, self); |
| 2426 if (renderWidgetHostView_ && renderWidgetHostView_->render_widget_host_) { | 2426 if (renderWidgetHostView_ && renderWidgetHostView_->render_widget_host_) { |
| 2427 renderWidgetHostView_->render_widget_host_->ForwardGestureEvent( | 2427 renderWidgetHostView_->render_widget_host_->ForwardGestureEvent( |
| 2428 smartMagnifyEvent); | 2428 smartMagnifyEvent); |
| 2429 } | 2429 } |
| 2430 } | 2430 } |
| 2431 | 2431 |
| 2432 // This is invoked only on 10.8 or newer when the user taps a word using | 2432 - (void)showLookUpDictionaryOverlayFromRange:(NSRange)range { |
| 2433 // three fingers. | 2433 TextInputClientMac::GetInstance()->GetStringFromRange( |
| 2434 - (void)quickLookWithEvent:(NSEvent*)event { | 2434 renderWidgetHostView_->render_widget_host_, range, |
| 2435 NSPoint point = [self convertPoint:[event locationInWindow] fromView:nil]; | |
| 2436 TextInputClientMac::GetInstance()->GetStringAtPoint( | |
| 2437 renderWidgetHostView_->render_widget_host_, | |
| 2438 gfx::Point(point.x, NSHeight([self frame]) - point.y), | |
| 2439 ^(NSAttributedString* string, NSPoint baselinePoint) { | 2435 ^(NSAttributedString* string, NSPoint baselinePoint) { |
|
Alexei Svitkine (slow)
2015/09/18 16:48:43
Is there a reason this block is different than the
Shu Chen
2015/09/21 02:47:39
Done.
| |
| 2440 if (string && [string length] > 0) { | 2436 if (string && [string length] > 0) { |
| 2441 dispatch_async(dispatch_get_main_queue(), ^{ | 2437 dispatch_async(dispatch_get_main_queue(), ^{ |
| 2442 [self showDefinitionForAttributedString:string | 2438 [self showDefinitionForAttributedString:string |
| 2443 atPoint:baselinePoint]; | 2439 atPoint:baselinePoint]; |
| 2444 }); | 2440 }); |
| 2445 } | 2441 } |
| 2446 } | 2442 } |
| 2447 ); | 2443 ); |
| 2448 } | 2444 } |
| 2449 | 2445 |
| 2446 - (void)showLookUpDictionaryOverlayAtPoint:(NSPoint)point { | |
| 2447 TextInputClientMac::GetInstance()->GetStringAtPoint( | |
| 2448 renderWidgetHostView_->render_widget_host_, | |
| 2449 gfx::Point(point.x, NSHeight([self frame]) - point.y), | |
| 2450 ^(NSAttributedString* string, NSPoint baselinePoint) { | |
| 2451 if (!string || [string length] == 0) { | |
|
Alexei Svitkine (slow)
2015/09/18 16:48:43
Nit: [string length] == 0 check is sufficient, bec
Shu Chen
2015/09/21 02:47:39
Done.
| |
| 2452 // The PDF plugin does not support getting the attributed string | |
| 2453 // at point. Until it does, use NSPerformService(), which opens | |
| 2454 // Dictionary.app. | |
| 2455 // TODO: support GetStringAtPoint() for PDF. See crbug.com/152438. | |
|
Alexei Svitkine (slow)
2015/09/18 16:48:43
Nit: TODO()'s should have a name inside them. Sinc
Shu Chen
2015/09/21 02:47:39
Done.
| |
| 2456 NSString* text = base::SysUTF8ToNSString( | |
| 2457 renderWidgetHostView_->selected_text()); | |
| 2458 NSPasteboard* pasteboard = [NSPasteboard pasteboardWithUniqueName]; | |
| 2459 NSArray* types = [NSArray arrayWithObject:NSStringPboardType]; | |
| 2460 [pasteboard declareTypes:types owner:nil]; | |
| 2461 if ([pasteboard setString:text forType:NSStringPboardType]) | |
| 2462 NSPerformService(@"Look Up in Dictionary", pasteboard); | |
| 2463 return; | |
| 2464 } | |
| 2465 dispatch_async(dispatch_get_main_queue(), ^{ | |
| 2466 [self showDefinitionForAttributedString:string | |
| 2467 atPoint:baselinePoint]; | |
| 2468 }); | |
| 2469 } | |
| 2470 ); | |
| 2471 } | |
| 2472 | |
| 2473 // This is invoked only on 10.8 or newer when the user taps a word using | |
| 2474 // three fingers. | |
| 2475 - (void)quickLookWithEvent:(NSEvent*)event { | |
| 2476 NSPoint point = [self convertPoint:[event locationInWindow] fromView:nil]; | |
| 2477 [self showLookUpDictionaryOverlayAtPoint:point]; | |
| 2478 } | |
| 2479 | |
| 2450 // This method handles 2 different types of hardware events. | 2480 // This method handles 2 different types of hardware events. |
| 2451 // (Apple does not distinguish between them). | 2481 // (Apple does not distinguish between them). |
| 2452 // a. Scrolling the middle wheel of a mouse. | 2482 // a. Scrolling the middle wheel of a mouse. |
| 2453 // b. Swiping on the track pad. | 2483 // b. Swiping on the track pad. |
| 2454 // | 2484 // |
| 2455 // This method is responsible for 2 types of behavior: | 2485 // This method is responsible for 2 types of behavior: |
| 2456 // a. Scrolling the content of window. | 2486 // a. Scrolling the content of window. |
| 2457 // b. Navigating forwards/backwards in history. | 2487 // b. Navigating forwards/backwards in history. |
| 2458 // | 2488 // |
| 2459 // This is a brief description of the logic: | 2489 // This is a brief description of the logic: |
| (...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3405 | 3435 |
| 3406 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3436 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
| 3407 // regions that are not draggable. (See ControlRegionView in | 3437 // regions that are not draggable. (See ControlRegionView in |
| 3408 // native_app_window_cocoa.mm). This requires the render host view to be | 3438 // native_app_window_cocoa.mm). This requires the render host view to be |
| 3409 // draggable by default. | 3439 // draggable by default. |
| 3410 - (BOOL)mouseDownCanMoveWindow { | 3440 - (BOOL)mouseDownCanMoveWindow { |
| 3411 return YES; | 3441 return YES; |
| 3412 } | 3442 } |
| 3413 | 3443 |
| 3414 @end | 3444 @end |
| OLD | NEW |