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

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

Issue 2278283002: Implement Mac Pop-up Dictionary for OOPIF. (Closed)
Patch Set: Addressing lfg@'s comment Created 4 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 #include <stdint.h> 10 #include <stdint.h>
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 #include "content/common/accessibility_messages.h" 53 #include "content/common/accessibility_messages.h"
54 #include "content/common/edit_command.h" 54 #include "content/common/edit_command.h"
55 #include "content/common/input_messages.h" 55 #include "content/common/input_messages.h"
56 #include "content/common/site_isolation_policy.h" 56 #include "content/common/site_isolation_policy.h"
57 #include "content/common/text_input_state.h" 57 #include "content/common/text_input_state.h"
58 #include "content/common/view_messages.h" 58 #include "content/common/view_messages.h"
59 #include "content/public/browser/browser_context.h" 59 #include "content/public/browser/browser_context.h"
60 #include "content/public/browser/browser_plugin_guest_manager.h" 60 #include "content/public/browser/browser_plugin_guest_manager.h"
61 #include "content/public/browser/browser_thread.h" 61 #include "content/public/browser/browser_thread.h"
62 #include "content/public/browser/native_web_keyboard_event.h" 62 #include "content/public/browser/native_web_keyboard_event.h"
63 #include "content/public/browser/render_widget_host.h"
Charlie Reis 2016/09/02 21:57:47 Stale? (Do we need the impl file?)
EhsanK 2016/09/08 17:10:40 impl file is already included on line 46. I think
Charlie Reis 2016/09/09 22:23:32 Ah, I missed the other uses of RenderWidgetHost in
63 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" 64 #include "content/public/browser/render_widget_host_view_frame_subscriber.h"
64 #import "content/public/browser/render_widget_host_view_mac_delegate.h" 65 #import "content/public/browser/render_widget_host_view_mac_delegate.h"
65 #include "content/public/browser/web_contents.h" 66 #include "content/public/browser/web_contents.h"
66 #include "gpu/ipc/common/gpu_messages.h" 67 #include "gpu/ipc/common/gpu_messages.h"
67 #include "skia/ext/platform_canvas.h" 68 #include "skia/ext/platform_canvas.h"
68 #include "skia/ext/skia_utils_mac.h" 69 #include "skia/ext/skia_utils_mac.h"
69 #include "third_party/WebKit/public/platform/WebScreenInfo.h" 70 #include "third_party/WebKit/public/platform/WebScreenInfo.h"
70 #include "third_party/WebKit/public/web/WebInputEvent.h" 71 #include "third_party/WebKit/public/web/WebInputEvent.h"
71 #import "ui/base/clipboard/clipboard_util_mac.h" 72 #import "ui/base/clipboard/clipboard_util_mac.h"
72 #include "ui/base/cocoa/animation_utils.h" 73 #include "ui/base/cocoa/animation_utils.h"
(...skipping 16 matching lines...) Expand all
89 #include "ui/gl/gl_switches.h" 90 #include "ui/gl/gl_switches.h"
90 91
91 using content::BrowserAccessibility; 92 using content::BrowserAccessibility;
92 using content::BrowserAccessibilityManager; 93 using content::BrowserAccessibilityManager;
93 using content::EditCommand; 94 using content::EditCommand;
94 using content::FrameTreeNode; 95 using content::FrameTreeNode;
95 using content::NativeWebKeyboardEvent; 96 using content::NativeWebKeyboardEvent;
96 using content::RenderFrameHost; 97 using content::RenderFrameHost;
97 using content::RenderViewHost; 98 using content::RenderViewHost;
98 using content::RenderViewHostImpl; 99 using content::RenderViewHostImpl;
100 using content::RenderWidgetHost;
Charlie Reis 2016/09/02 21:57:47 Stale?
EhsanK 2016/09/08 17:10:40 Same discussion as the .h file. For the override R
Charlie Reis 2016/09/09 22:23:32 I don't think you need this. This file is already
EhsanK 2016/09/13 18:52:15 Acknowledged.
99 using content::RenderWidgetHostImpl; 101 using content::RenderWidgetHostImpl;
100 using content::RenderWidgetHostViewMac; 102 using content::RenderWidgetHostViewMac;
101 using content::RenderWidgetHostViewMacEditCommandHelper; 103 using content::RenderWidgetHostViewMacEditCommandHelper;
102 using content::TextInputClientMac; 104 using content::TextInputClientMac;
103 using content::WebContents; 105 using content::WebContents;
104 using content::WebGestureEventBuilder; 106 using content::WebGestureEventBuilder;
105 using content::WebMouseEventBuilder; 107 using content::WebMouseEventBuilder;
106 using content::WebMouseWheelEventBuilder; 108 using content::WebMouseWheelEventBuilder;
107 using blink::WebInputEvent; 109 using blink::WebInputEvent;
108 using blink::WebMouseEvent; 110 using blink::WebMouseEvent;
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 if (!GetActiveWidget()) 548 if (!GetActiveWidget())
547 return ui::TEXT_INPUT_TYPE_NONE; 549 return ui::TEXT_INPUT_TYPE_NONE;
548 return GetTextInputManager()->GetTextInputState()->type; 550 return GetTextInputManager()->GetTextInputState()->type;
549 } 551 }
550 552
551 RenderWidgetHostImpl* RenderWidgetHostViewMac::GetActiveWidget() { 553 RenderWidgetHostImpl* RenderWidgetHostViewMac::GetActiveWidget() {
552 return GetTextInputManager() ? GetTextInputManager()->GetActiveWidget() 554 return GetTextInputManager() ? GetTextInputManager()->GetActiveWidget()
553 : nullptr; 555 : nullptr;
554 } 556 }
555 557
558 RenderWidgetHostImpl* RenderWidgetHostViewMac::GetRenderWidgetHostAtPoint(
559 const gfx::Point& point,
560 gfx::Point* transformed_point) {
561 if (!render_widget_host_)
562 return nullptr;
563
564 if (!render_widget_host_->delegate() ||
565 !render_widget_host_->delegate()->GetInputEventRouter())
566 return render_widget_host_;
567
568 return render_widget_host_->delegate()
569 ->GetInputEventRouter()
570 ->GetRenderWidgetHostAtPoint(this, point, transformed_point);
571 }
556 /////////////////////////////////////////////////////////////////////////////// 572 ///////////////////////////////////////////////////////////////////////////////
557 // RenderWidgetHostViewMac, RenderWidgetHostView implementation: 573 // RenderWidgetHostViewMac, RenderWidgetHostView implementation:
558 574
559 bool RenderWidgetHostViewMac::OnMessageReceived(const IPC::Message& message) { 575 bool RenderWidgetHostViewMac::OnMessageReceived(const IPC::Message& message) {
560 bool handled = true; 576 bool handled = true;
561 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewMac, message) 577 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewMac, message)
562 IPC_MESSAGE_HANDLER(ViewMsg_GetRenderedTextCompleted, 578 IPC_MESSAGE_HANDLER(ViewMsg_GetRenderedTextCompleted,
563 OnGetRenderedTextCompleted) 579 OnGetRenderedTextCompleted)
564 IPC_MESSAGE_UNHANDLED(handled = false) 580 IPC_MESSAGE_UNHANDLED(handled = false)
565 IPC_END_MESSAGE_MAP() 581 IPC_END_MESSAGE_MAP()
(...skipping 1713 matching lines...) Expand 10 before | Expand all | Expand 10 after
2279 renderWidgetHostView_->render_widget_host_, range, 2295 renderWidgetHostView_->render_widget_host_, range,
2280 ^(NSAttributedString* string, NSPoint baselinePoint) { 2296 ^(NSAttributedString* string, NSPoint baselinePoint) {
2281 [self showLookUpDictionaryOverlayInternal:string 2297 [self showLookUpDictionaryOverlayInternal:string
2282 baselinePoint:baselinePoint 2298 baselinePoint:baselinePoint
2283 targetView:targetView]; 2299 targetView:targetView];
2284 } 2300 }
2285 ); 2301 );
2286 } 2302 }
2287 2303
2288 - (void)showLookUpDictionaryOverlayAtPoint:(NSPoint)point { 2304 - (void)showLookUpDictionaryOverlayAtPoint:(NSPoint)point {
2305 gfx::Point rootPoint(point.x, NSHeight([self frame]) - point.y);
2306 gfx::Point transformedPoint;
2307 RenderWidgetHost* widgetHost =
Charlie Reis 2016/09/02 21:57:47 RenderWidgetHostImpl
EhsanK 2016/09/08 17:10:40 Done.
2308 renderWidgetHostView_->GetRenderWidgetHostAtPoint(rootPoint,
2309 &transformedPoint);
2310 if (!widgetHost)
2311 return;
2312
2313 gfx::Rect root_box = renderWidgetHostView_->GetViewBounds();
2314 gfx::Rect view_box = widgetHost->GetView()->GetViewBounds();
2315
2289 TextInputClientMac::GetInstance()->GetStringAtPoint( 2316 TextInputClientMac::GetInstance()->GetStringAtPoint(
2290 renderWidgetHostView_->render_widget_host_, 2317 widgetHost, transformedPoint,
2291 gfx::Point(point.x, NSHeight([self frame]) - point.y),
2292 ^(NSAttributedString* string, NSPoint baselinePoint) { 2318 ^(NSAttributedString* string, NSPoint baselinePoint) {
2319 baselinePoint.x += view_box.origin().x() - root_box.origin().x();
2320 baselinePoint.y +=
2321 root_box.bottom_left().y() - view_box.bottom_left().y();
kenrb 2016/09/06 18:14:48 I don't really understand why this point gets shif
EhsanK 2016/09/08 17:10:40 The return coordinate is: 1) With respect to topmo
kenrb 2016/09/12 17:28:13 I am surprised to hear about a threading problem,
EhsanK 2016/09/13 18:52:15 Following our offline conversation, I am leaving a
2293 [self showLookUpDictionaryOverlayInternal:string 2322 [self showLookUpDictionaryOverlayInternal:string
2294 baselinePoint:baselinePoint 2323 baselinePoint:baselinePoint
2295 targetView:self]; 2324 targetView:self];
2296 } 2325 });
2297 );
2298 } 2326 }
2299 2327
2300 // This is invoked only on 10.8 or newer when the user taps a word using 2328 // This is invoked only on 10.8 or newer when the user taps a word using
2301 // three fingers. 2329 // three fingers.
2302 - (void)quickLookWithEvent:(NSEvent*)event { 2330 - (void)quickLookWithEvent:(NSEvent*)event {
2303 NSPoint point = [self convertPoint:[event locationInWindow] fromView:nil]; 2331 NSPoint point = [self convertPoint:[event locationInWindow] fromView:nil];
2304 [self showLookUpDictionaryOverlayAtPoint:point]; 2332 [self showLookUpDictionaryOverlayAtPoint:point];
2305 } 2333 }
2306 2334
2307 // This method handles 2 different types of hardware events. 2335 // This method handles 2 different types of hardware events.
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
2803 2831
2804 - (NSUInteger)characterIndexForPoint:(NSPoint)thePoint { 2832 - (NSUInteger)characterIndexForPoint:(NSPoint)thePoint {
2805 DCHECK([self window]); 2833 DCHECK([self window]);
2806 // |thePoint| is in screen coordinates, but needs to be converted to WebKit 2834 // |thePoint| is in screen coordinates, but needs to be converted to WebKit
2807 // coordinates (upper left origin). Scroll offsets will be taken care of in 2835 // coordinates (upper left origin). Scroll offsets will be taken care of in
2808 // the renderer. 2836 // the renderer.
2809 thePoint = ui::ConvertPointFromScreenToWindow([self window], thePoint); 2837 thePoint = ui::ConvertPointFromScreenToWindow([self window], thePoint);
2810 thePoint = [self convertPoint:thePoint fromView:nil]; 2838 thePoint = [self convertPoint:thePoint fromView:nil];
2811 thePoint.y = NSHeight([self frame]) - thePoint.y; 2839 thePoint.y = NSHeight([self frame]) - thePoint.y;
2812 2840
2841 gfx::Point transformedPoint;
2842 RenderWidgetHost* widgetHost =
Charlie Reis 2016/09/02 21:57:47 RenderWidgetHostImpl
EhsanK 2016/09/08 17:10:40 Done.
2843 renderWidgetHostView_->GetRenderWidgetHostAtPoint(
2844 gfx::Point(thePoint.x, thePoint.y), &transformedPoint);
2845 if (!widgetHost)
2846 return NSNotFound;
2847
2813 NSUInteger index = 2848 NSUInteger index =
2814 TextInputClientMac::GetInstance()->GetCharacterIndexAtPoint( 2849 TextInputClientMac::GetInstance()->GetCharacterIndexAtPoint(
2815 renderWidgetHostView_->render_widget_host_, 2850 widgetHost, transformedPoint);
2816 gfx::Point(thePoint.x, thePoint.y));
2817 return index; 2851 return index;
2818 } 2852 }
2819 2853
2820 - (NSRect)firstViewRectForCharacterRange:(NSRange)theRange 2854 - (NSRect)firstViewRectForCharacterRange:(NSRange)theRange
2821 actualRange:(NSRangePointer)actualRange { 2855 actualRange:(NSRangePointer)actualRange {
2822 NSRect rect; 2856 NSRect rect;
2823 if (!renderWidgetHostView_->GetCachedFirstRectForCharacterRange( 2857 if (!renderWidgetHostView_->GetCachedFirstRectForCharacterRange(
2824 theRange, 2858 theRange,
2825 &rect, 2859 &rect,
2826 actualRange)) { 2860 actualRange)) {
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
3265 3299
3266 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 3300 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
3267 // regions that are not draggable. (See ControlRegionView in 3301 // regions that are not draggable. (See ControlRegionView in
3268 // native_app_window_cocoa.mm). This requires the render host view to be 3302 // native_app_window_cocoa.mm). This requires the render host view to be
3269 // draggable by default. 3303 // draggable by default.
3270 - (BOOL)mouseDownCanMoveWindow { 3304 - (BOOL)mouseDownCanMoveWindow {
3271 return YES; 3305 return YES;
3272 } 3306 }
3273 3307
3274 @end 3308 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698