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

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

Issue 2480893002: Fix incorrect implementation of NSTextInputClient. (Closed)
Patch Set: Fix test. Created 4 years, 1 month 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
« no previous file with comments | « no previous file | content/browser/renderer_host/render_widget_host_view_mac_unittest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <Carbon/Carbon.h> 7 #import <Carbon/Carbon.h>
8 #import <objc/runtime.h> 8 #import <objc/runtime.h>
9 #include <OpenGL/gl.h> 9 #include <OpenGL/gl.h>
10 #include <QuartzCore/QuartzCore.h> 10 #include <QuartzCore/QuartzCore.h>
(...skipping 2999 matching lines...) Expand 10 before | Expand all | Expand 10 after
3010 3010
3011 NSRect rect = [self firstViewRectForCharacterRange:theRange 3011 NSRect rect = [self firstViewRectForCharacterRange:theRange
3012 actualRange:actualRange]; 3012 actualRange:actualRange];
3013 3013
3014 // Convert into screen coordinates for return. 3014 // Convert into screen coordinates for return.
3015 rect = [self convertRect:rect toView:nil]; 3015 rect = [self convertRect:rect toView:nil];
3016 rect = [[self window] convertRectToScreen:rect]; 3016 rect = [[self window] convertRectToScreen:rect];
3017 return rect; 3017 return rect;
3018 } 3018 }
3019 3019
3020 - (NSRange)selectedRange {
3021 if (selectedRange_.location == NSNotFound)
3022 return NSMakeRange(NSNotFound, 0);
3023 return selectedRange_;
3024 }
3025
3020 - (NSRange)markedRange { 3026 - (NSRange)markedRange {
3021 // An input method calls this method to check if an application really has 3027 // An input method calls this method to check if an application really has
3022 // a text being composed when hasMarkedText call returns true. 3028 // a text being composed when hasMarkedText call returns true.
3023 // Returns the range saved in the setMarkedText method so the input method 3029 // Returns the range saved in the setMarkedText method so the input method
3024 // calls the setMarkedText method and we can update the composition node 3030 // calls the setMarkedText method and we can update the composition node
3025 // there. (When this method returns an empty range, the input method doesn't 3031 // there. (When this method returns an empty range, the input method doesn't
3026 // call the setMarkedText method.) 3032 // call the setMarkedText method.)
3027 return hasMarkedText_ ? markedRange_ : NSMakeRange(NSNotFound, 0); 3033 return hasMarkedText_ ? markedRange_ : NSMakeRange(NSNotFound, 0);
3028 } 3034 }
3029 3035
3030 - (NSAttributedString*)attributedSubstringForProposedRange:(NSRange)range 3036 - (NSAttributedString*)attributedSubstringForProposedRange:(NSRange)range
3031 actualRange:(NSRangePointer)actualRange { 3037 actualRange:(NSRangePointer)actualRange {
3032 // TODO(thakis): Pipe |actualRange| through TextInputClientMac machinery. 3038 // Prepare |actualRange| as if the proposed range is invalid. If it is valid,
3039 // then |actualRange| will be updated again.
3033 if (actualRange) 3040 if (actualRange)
3034 *actualRange = range; 3041 *actualRange = NSMakeRange(NSNotFound, 0);
3042
3043 // The caller of this method is allowed to pass nonsensical ranges. These
3044 // can't even be converted into gfx::Ranges.
3045 if (range.location == NSNotFound || range.length == 0)
3046 return nil;
3047 if (range.length >= std::numeric_limits<NSUInteger>::max() - range.location)
3048 return nil;
3035 3049
3036 const gfx::Range requested_range(range); 3050 const gfx::Range requested_range(range);
3037 if (requested_range.is_reversed()) 3051 if (requested_range.is_reversed())
3038 return nil; 3052 return nil;
3039 3053
3040 gfx::Range expected_range; 3054 gfx::Range expected_range;
3041 const base::string16* expected_text; 3055 const base::string16* expected_text;
3042 3056
3043 if (!renderWidgetHostView_->composition_range().is_empty()) { 3057 if (!renderWidgetHostView_->composition_range().is_empty()) {
3044 expected_text = &markedText_; 3058 expected_text = &markedText_;
3045 expected_range = renderWidgetHostView_->composition_range(); 3059 expected_range = renderWidgetHostView_->composition_range();
3046 } else { 3060 } else {
3047 expected_text = &renderWidgetHostView_->selection_text(); 3061 expected_text = &renderWidgetHostView_->selection_text();
3048 size_t offset = renderWidgetHostView_->selection_text_offset(); 3062 size_t offset = renderWidgetHostView_->selection_text_offset();
3049 expected_range = gfx::Range(offset, offset + expected_text->size()); 3063 expected_range = gfx::Range(offset, offset + expected_text->size());
3050 } 3064 }
3051 3065
3052 if (!expected_range.Contains(requested_range)) 3066 gfx::Range actual_range = expected_range.Intersect(requested_range);
3067 if (!actual_range.IsValid())
3053 return nil; 3068 return nil;
3054 3069
3055 // Gets the raw bytes to avoid unnecessary string copies for generating 3070 // Gets the raw bytes to avoid unnecessary string copies for generating
3056 // NSString. 3071 // NSString.
3057 const base::char16* bytes = 3072 const base::char16* bytes =
3058 &(*expected_text)[requested_range.start() - expected_range.start()]; 3073 &(*expected_text)[actual_range.start() - expected_range.start()];
3059 // Avoid integer overflow. 3074 // Avoid integer overflow.
3060 base::CheckedNumeric<size_t> requested_len = requested_range.length(); 3075 base::CheckedNumeric<size_t> requested_len = actual_range.length();
3061 requested_len *= sizeof(base::char16); 3076 requested_len *= sizeof(base::char16);
3062 NSUInteger bytes_len = base::strict_cast<NSUInteger, size_t>( 3077 NSUInteger bytes_len = base::strict_cast<NSUInteger, size_t>(
3063 requested_len.ValueOrDefault(0)); 3078 requested_len.ValueOrDefault(0));
3064 base::scoped_nsobject<NSString> ns_string( 3079 base::scoped_nsobject<NSString> ns_string(
3065 [[NSString alloc] initWithBytes:bytes 3080 [[NSString alloc] initWithBytes:bytes
3066 length:bytes_len 3081 length:bytes_len
3067 encoding:NSUTF16LittleEndianStringEncoding]); 3082 encoding:NSUTF16LittleEndianStringEncoding]);
3083 if (actualRange)
3084 *actualRange = actual_range.ToNSRange();
3085
3068 return [[[NSAttributedString alloc] initWithString:ns_string] autorelease]; 3086 return [[[NSAttributedString alloc] initWithString:ns_string] autorelease];
3069 } 3087 }
3070 3088
3071 - (NSInteger)conversationIdentifier { 3089 - (NSInteger)conversationIdentifier {
3072 return reinterpret_cast<NSInteger>(self); 3090 return reinterpret_cast<NSInteger>(self);
3073 } 3091 }
3074 3092
3075 // Each RenderWidgetHostViewCocoa has its own input context, but we return 3093 // Each RenderWidgetHostViewCocoa has its own input context, but we return
3076 // nil when the caret is in non-editable content or password box to avoid 3094 // nil when the caret is in non-editable content or password box to avoid
3077 // making input methods do their work. 3095 // making input methods do their work.
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
3420 3438
3421 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 3439 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
3422 // regions that are not draggable. (See ControlRegionView in 3440 // regions that are not draggable. (See ControlRegionView in
3423 // native_app_window_cocoa.mm). This requires the render host view to be 3441 // native_app_window_cocoa.mm). This requires the render host view to be
3424 // draggable by default. 3442 // draggable by default.
3425 - (BOOL)mouseDownCanMoveWindow { 3443 - (BOOL)mouseDownCanMoveWindow {
3426 return YES; 3444 return YES;
3427 } 3445 }
3428 3446
3429 @end 3447 @end
OLDNEW
« no previous file with comments | « no previous file | content/browser/renderer_host/render_widget_host_view_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698