Chromium Code Reviews| Index: chrome/browser/renderer_host/render_widget_host_view_mac.mm |
| diff --git a/chrome/browser/renderer_host/render_widget_host_view_mac.mm b/chrome/browser/renderer_host/render_widget_host_view_mac.mm |
| index f93e8b930e15bee74c520b819de64ed39e7d4639..e0d4c90502c3e1d0c13dea22357f625839a359a1 100644 |
| --- a/chrome/browser/renderer_host/render_widget_host_view_mac.mm |
| +++ b/chrome/browser/renderer_host/render_widget_host_view_mac.mm |
| @@ -1,4 +1,4 @@ |
| -// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| @@ -28,6 +28,7 @@ |
| #include "chrome/browser/renderer_host/render_view_host.h" |
| #include "chrome/browser/renderer_host/render_widget_host.h" |
| #include "chrome/browser/spellchecker_platform_engine.h" |
| +#import "chrome/browser/ui/cocoa/lookup_in_dictionary.h" |
| #import "chrome/browser/ui/cocoa/rwhvm_editcommand_helper.h" |
| #import "chrome/browser/ui/cocoa/view_id_util.h" |
| #include "chrome/common/chrome_switches.h" |
| @@ -36,6 +37,7 @@ |
| #include "chrome/common/gpu_messages.h" |
| #include "chrome/common/plugin_messages.h" |
| #include "chrome/common/render_messages.h" |
| +#include "gfx/point.h" |
| #include "skia/ext/platform_canvas.h" |
| #include "third_party/skia/include/core/SkColor.h" |
| #include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebInputEventFactory.h" |
| @@ -728,13 +730,6 @@ void RenderWidgetHostViewMac::ImeUpdateTextInputState( |
| if (HasFocus()) |
| SetTextInputActive(true); |
| } |
| - |
| - // We need to convert the coordinate of the cursor rectangle sent from the |
| - // renderer and save it. Our input method backend uses a coordinate system |
| - // whose origin is the upper-left corner of this view. On the other hand, |
| - // Cocoa uses a coordinate system whose origin is the lower-left corner of |
| - // this view. So, we convert the cursor rectangle and save it. |
| - [cocoa_view_ setCaretRect:[cocoa_view_ flipRectToNSRect:caret_rect]]; |
| } |
| void RenderWidgetHostViewMac::ImeCancelComposition() { |
| @@ -1319,8 +1314,6 @@ void RenderWidgetHostViewMac::SetTextInputActive(bool active) { |
| @implementation RenderWidgetHostViewCocoa |
| -@synthesize caretRect = caretRect_; |
| - |
| - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r { |
| self = [super initWithFrame:NSZeroRect]; |
| if (self) { |
| @@ -2346,26 +2339,44 @@ extern NSString *NSTextInputReplacementRangeAttributeName; |
| } |
| - (NSUInteger)characterIndexForPoint:(NSPoint)thePoint { |
| - NOTIMPLEMENTED(); |
| - return NSNotFound; |
| + DCHECK([self window]); |
| + // |thePoint| is in screen coordinates, but needs to be converted to WebKit |
| + // coordinates (upper left origin). Scroll offsets will be taken care of in |
| + // the renderer. |
| + thePoint = [[self window] convertScreenToBase:thePoint]; |
| + thePoint = [self convertPoint:thePoint fromView:nil]; |
| + thePoint.y = NSHeight([self frame]) - thePoint.y; |
| + |
| + LookupInDictionary* service = LookupInDictionary::GetInstance(); |
| + service->BeforeRequest(); |
| + renderWidgetHostView_->render_widget_host_->Send( |
| + new ViewMsg_CharacterIndexForPoint( |
| + renderWidgetHostView_->render_widget_host_->routing_id(), |
| + gfx::Point(thePoint.x, thePoint.y))); |
| + NSUInteger index = service->WaitForCharacterIndex(); |
| + service->AfterRequest(); |
|
James Su
2011/01/19 20:29:06
I'm wondering if it's possible to move this piece
Robert Sesek
2011/01/20 15:06:33
I was wondering the same thing. I could add a IPC:
James Su
2011/01/20 23:46:05
I mean is it possible to simplify this part to som
Robert Sesek
2011/01/21 23:40:07
Done.
|
| + return index; |
| } |
| - (NSRect)firstRectForCharacterRange:(NSRange)theRange { |
| - // An input method requests a cursor rectangle to display its candidate |
| - // window. |
| - // Calculate the screen coordinate of the cursor rectangle saved in |
| - // RenderWidgetHostViewMac::ImeUpdateTextInputState() and send it to the |
| - // input method. |
| - // Since this window may be moved since we receive the cursor rectangle last |
| - // time we sent the cursor rectangle to the input method, so we should map |
| - // from the view coordinate to the screen coordinate every time when an input |
| - // method need it. |
| - NSRect resultRect = [self convertRect:caretRect_ toView:nil]; |
| - NSWindow* window = [self window]; |
| - if (window) |
| - resultRect.origin = [window convertBaseToScreen:resultRect.origin]; |
| - |
| - return resultRect; |
| + LookupInDictionary* service = LookupInDictionary::GetInstance(); |
| + service->BeforeRequest(); |
| + renderWidgetHostView_->render_widget_host_->Send( |
| + new ViewMsg_FirstRectForCharacterRange( |
| + renderWidgetHostView_->render_widget_host_->routing_id(), |
| + theRange.location, |
| + theRange.length)); |
| + NSRect rect = service->WaitForFirstRect(); |
| + service->AfterRequest(); |
| + // The returned rectangle is in WebKit coordinates (upper left origin), so |
| + // flip the coordinate system and then convert it into screen coordinates for |
| + // return. |
| + NSRect viewFrame = [self frame]; |
| + rect.origin.y = NSHeight(viewFrame) - rect.origin.y; |
| + rect.origin.y -= rect.size.height; |
| + rect = [self convertRectToBase:rect]; |
| + rect.origin = [[self window] convertBaseToScreen:rect.origin]; |
| + return rect; |
| } |
| - (NSRange)selectedRange { |
| @@ -2383,12 +2394,17 @@ extern NSString *NSTextInputReplacementRangeAttributeName; |
| return hasMarkedText_ ? markedRange_ : NSMakeRange(NSNotFound, 0); |
| } |
| -- (NSAttributedString *)attributedSubstringFromRange:(NSRange)range { |
| - // TODO(hbono): Even though many input method works without implementing |
| - // this method, we need to save a copy of the string in the setMarkedText |
| - // method and create a NSAttributedString with the given range. |
| - // http://crbug.com/37715 |
| - return nil; |
| +- (NSAttributedString*)attributedSubstringFromRange:(NSRange)range { |
| + LookupInDictionary* service = LookupInDictionary::GetInstance(); |
| + service->BeforeRequest(); |
| + renderWidgetHostView_->render_widget_host_->Send( |
| + new ViewMsg_StringForRange( |
| + renderWidgetHostView_->render_widget_host_->routing_id(), |
| + range.location, |
| + range.length)); |
| + NSAttributedString* string = service->WaitForSubstring(); |
| + service->AfterRequest(); |
| + return string; |
| } |
| - (NSInteger)conversationIdentifier { |