| 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 d46560d571ab2855ef8ea6f985cd6208357ab1c2..f444aed57ba8b05ff22b8c79d165f17581870a0f 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_process_host.h"
|
| #include "chrome/browser/renderer_host/render_view_host.h"
|
| #include "chrome/browser/renderer_host/render_widget_host.h"
|
| +#import "chrome/browser/renderer_host/text_input_client_mac.h"
|
| #include "chrome/browser/spellchecker_platform_engine.h"
|
| #import "chrome/browser/ui/cocoa/rwhvm_editcommand_helper.h"
|
| #import "chrome/browser/ui/cocoa/view_id_util.h"
|
| @@ -41,6 +42,7 @@
|
| #include "third_party/skia/include/core/SkColor.h"
|
| #include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebInputEventFactory.h"
|
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
|
| +#include "ui/gfx/point.h"
|
| #include "webkit/glue/webaccessibility.h"
|
| #include "webkit/plugins/npapi/webplugin.h"
|
| #import "third_party/mozilla/ComplexTextInputPanel.h"
|
| @@ -59,10 +61,14 @@ static inline int ToWebKitModifiers(NSUInteger flags) {
|
| return modifiers;
|
| }
|
|
|
| -@interface RenderWidgetHostViewCocoa (Private)
|
| +// Private methods:
|
| +@interface RenderWidgetHostViewCocoa ()
|
| +@property(nonatomic, assign) NSRange selectedRange;
|
| +@property(nonatomic, assign) NSRange markedRange;
|
| +
|
| + (BOOL)shouldAutohideCursorForEvent:(NSEvent*)event;
|
| - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r;
|
| -- (void)keyEvent:(NSEvent *)theEvent wasKeyEquivalent:(BOOL)equiv;
|
| +- (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv;
|
| - (void)cancelChildPopups;
|
| - (void)checkForPluginImeCancellation;
|
| @end
|
| @@ -827,19 +833,18 @@ 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() {
|
| [cocoa_view_ cancelComposition];
|
| }
|
|
|
| +void RenderWidgetHostViewMac::ImeCompositionRangeChanged(int start, int end) {
|
| + // The RangeChanged message is only sent with valid values. The current
|
| + // caret position (start == end) will be sent if there is no IME range.
|
| + [cocoa_view_ setMarkedRange:NSMakeRange(start, end - start)];
|
| +}
|
| +
|
| void RenderWidgetHostViewMac::DidUpdateBackingStore(
|
| const gfx::Rect& scroll_rect, int scroll_dx, int scroll_dy,
|
| const std::vector<gfx::Rect>& copy_rects) {
|
| @@ -957,8 +962,14 @@ void RenderWidgetHostViewMac::SetTooltipText(const std::wstring& tooltip_text) {
|
| // RenderWidgetHostViewCocoa uses the stored selection text,
|
| // which implements NSServicesRequests protocol.
|
| //
|
| -void RenderWidgetHostViewMac::SelectionChanged(const std::string& text) {
|
| +void RenderWidgetHostViewMac::SelectionChanged(const std::string& text,
|
| + int range_start,
|
| + int range_end) {
|
| selected_text_ = text;
|
| + NSRange range = NSMakeRange(range_start, range_end - range_start);
|
| + if (range_start == 0 && range_end == 0)
|
| + range.location = NSNotFound;
|
| + [cocoa_view_ setSelectedRange:range];
|
| }
|
|
|
| BackingStore* RenderWidgetHostViewMac::AllocBackingStore(
|
| @@ -1373,7 +1384,8 @@ void RenderWidgetHostViewMac::SetTextInputActive(bool active) {
|
|
|
| @implementation RenderWidgetHostViewCocoa
|
|
|
| -@synthesize caretRect = caretRect_;
|
| +@synthesize selectedRange = selectedRange_;
|
| +@synthesize markedRange = markedRange_;
|
|
|
| - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r {
|
| self = [super initWithFrame:NSZeroRect];
|
| @@ -2443,31 +2455,36 @@ 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;
|
| +
|
| + NSUInteger point =
|
| + TextInputClientMac::GetInstance()->GetCharacterIndexAtPoint(
|
| + renderWidgetHostView_->render_widget_host_,
|
| + gfx::Point(thePoint.x, thePoint.y));
|
| + NSLog(@"%s:%@ -> %d", _cmd, NSStringFromPoint(thePoint), point);
|
| + return point;
|
| }
|
|
|
| - (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;
|
| -}
|
| + NSRect rect = TextInputClientMac::GetInstance()->GetFirstRectForRange(
|
| + renderWidgetHostView_->render_widget_host_, theRange);
|
|
|
| -- (NSRange)selectedRange {
|
| - // Return the selected range saved in the setMarkedText method.
|
| - return hasMarkedText_ ? selectedRange_ : NSMakeRange(NSNotFound, 0);
|
| + // 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];
|
| + NSLog(@"%s:%@ -> %@", _cmd, NSStringFromRange(theRange), NSStringFromRect(rect));
|
| + return rect;
|
| }
|
|
|
| - (NSRange)markedRange {
|
| @@ -2477,15 +2494,16 @@ extern NSString *NSTextInputReplacementRangeAttributeName;
|
| // calls the setMarkedText method and we can update the composition node
|
| // there. (When this method returns an empty range, the input method doesn't
|
| // call the setMarkedText method.)
|
| + NSLog(@"%s -> %@", _cmd, NSStringFromRange(markedRange_));
|
| 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 {
|
| + NSAttributedString* str =
|
| + TextInputClientMac::GetInstance()->GetAttributedSubstringFromRange(
|
| + renderWidgetHostView_->render_widget_host_, range);
|
| + NSLog(@"%s:%@ -> %@", _cmd, NSStringFromRange(range), [str string]);
|
| + return str;
|
| }
|
|
|
| - (NSInteger)conversationIdentifier {
|
| @@ -2544,7 +2562,7 @@ extern NSString *NSTextInputReplacementRangeAttributeName;
|
| NSString* im_text = isAttributedString ? [string string] : string;
|
| int length = [im_text length];
|
|
|
| - markedRange_ = NSMakeRange(0, length);
|
| + // |markedRange_| will get set on a callback from ImeSetComposition().
|
| selectedRange_ = newSelRange;
|
| markedText_ = base::SysNSStringToUTF16(im_text);
|
| hasMarkedText_ = (length > 0);
|
|
|