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

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

Issue 2497073002: Revert of Fix RenderWidgetHostViewMac compliance with NSTextInputClient. (Closed)
Patch Set: 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 || selectedRange_.length == 0)
3022 return NSMakeRange(NSNotFound, 0);
3023 return selectedRange_;
3024 }
3025
3026 - (NSRange)markedRange { 3020 - (NSRange)markedRange {
3027 // An input method calls this method to check if an application really has 3021 // An input method calls this method to check if an application really has
3028 // a text being composed when hasMarkedText call returns true. 3022 // a text being composed when hasMarkedText call returns true.
3029 // Returns the range saved in the setMarkedText method so the input method 3023 // Returns the range saved in the setMarkedText method so the input method
3030 // calls the setMarkedText method and we can update the composition node 3024 // calls the setMarkedText method and we can update the composition node
3031 // there. (When this method returns an empty range, the input method doesn't 3025 // there. (When this method returns an empty range, the input method doesn't
3032 // call the setMarkedText method.) 3026 // call the setMarkedText method.)
3033 return hasMarkedText_ ? markedRange_ : NSMakeRange(NSNotFound, 0); 3027 return hasMarkedText_ ? markedRange_ : NSMakeRange(NSNotFound, 0);
3034 } 3028 }
3035 3029
3036 - (NSAttributedString*)attributedSubstringForProposedRange:(NSRange)range 3030 - (NSAttributedString*)attributedSubstringForProposedRange:(NSRange)range
3037 actualRange:(NSRangePointer)actualRange { 3031 actualRange:(NSRangePointer)actualRange {
3038 // Prepare |actualRange| as if the proposed range is invalid. If it is valid, 3032 // TODO(thakis): Pipe |actualRange| through TextInputClientMac machinery.
3039 // then |actualRange| will be updated again.
3040 if (actualRange) 3033 if (actualRange)
3041 *actualRange = NSMakeRange(NSNotFound, 0); 3034 *actualRange = range;
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;
3049 3035
3050 const gfx::Range requested_range(range); 3036 const gfx::Range requested_range(range);
3051 if (requested_range.is_reversed()) 3037 if (requested_range.is_reversed())
3052 return nil; 3038 return nil;
3053 3039
3054 gfx::Range expected_range; 3040 gfx::Range expected_range;
3055 const base::string16* expected_text; 3041 const base::string16* expected_text;
3056 3042
3057 if (!renderWidgetHostView_->composition_range().is_empty()) { 3043 if (!renderWidgetHostView_->composition_range().is_empty()) {
3058 expected_text = &markedText_; 3044 expected_text = &markedText_;
3059 expected_range = renderWidgetHostView_->composition_range(); 3045 expected_range = renderWidgetHostView_->composition_range();
3060 } else { 3046 } else {
3061 expected_text = &renderWidgetHostView_->selection_text(); 3047 expected_text = &renderWidgetHostView_->selection_text();
3062 size_t offset = renderWidgetHostView_->selection_text_offset(); 3048 size_t offset = renderWidgetHostView_->selection_text_offset();
3063 expected_range = gfx::Range(offset, offset + expected_text->size()); 3049 expected_range = gfx::Range(offset, offset + expected_text->size());
3064 } 3050 }
3065 3051
3066 gfx::Range actual_range = expected_range.Intersect(requested_range); 3052 if (!expected_range.Contains(requested_range))
3067 if (!actual_range.IsValid())
3068 return nil; 3053 return nil;
3069 3054
3070 // Gets the raw bytes to avoid unnecessary string copies for generating 3055 // Gets the raw bytes to avoid unnecessary string copies for generating
3071 // NSString. 3056 // NSString.
3072 const base::char16* bytes = 3057 const base::char16* bytes =
3073 &(*expected_text)[actual_range.start() - expected_range.start()]; 3058 &(*expected_text)[requested_range.start() - expected_range.start()];
3074 // Avoid integer overflow. 3059 // Avoid integer overflow.
3075 base::CheckedNumeric<size_t> requested_len = actual_range.length(); 3060 base::CheckedNumeric<size_t> requested_len = requested_range.length();
3076 requested_len *= sizeof(base::char16); 3061 requested_len *= sizeof(base::char16);
3077 NSUInteger bytes_len = base::strict_cast<NSUInteger, size_t>( 3062 NSUInteger bytes_len = base::strict_cast<NSUInteger, size_t>(
3078 requested_len.ValueOrDefault(0)); 3063 requested_len.ValueOrDefault(0));
3079 base::scoped_nsobject<NSString> ns_string( 3064 base::scoped_nsobject<NSString> ns_string(
3080 [[NSString alloc] initWithBytes:bytes 3065 [[NSString alloc] initWithBytes:bytes
3081 length:bytes_len 3066 length:bytes_len
3082 encoding:NSUTF16LittleEndianStringEncoding]); 3067 encoding:NSUTF16LittleEndianStringEncoding]);
3083 if (actualRange)
3084 *actualRange = actual_range.ToNSRange();
3085
3086 return [[[NSAttributedString alloc] initWithString:ns_string] autorelease]; 3068 return [[[NSAttributedString alloc] initWithString:ns_string] autorelease];
3087 } 3069 }
3088 3070
3089 - (NSInteger)conversationIdentifier { 3071 - (NSInteger)conversationIdentifier {
3090 return reinterpret_cast<NSInteger>(self); 3072 return reinterpret_cast<NSInteger>(self);
3091 } 3073 }
3092 3074
3093 // Each RenderWidgetHostViewCocoa has its own input context, but we return 3075 // Each RenderWidgetHostViewCocoa has its own input context, but we return
3094 // nil when the caret is in non-editable content or password box to avoid 3076 // nil when the caret is in non-editable content or password box to avoid
3095 // making input methods do their work. 3077 // making input methods do their work.
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
3438 3420
3439 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 3421 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
3440 // regions that are not draggable. (See ControlRegionView in 3422 // regions that are not draggable. (See ControlRegionView in
3441 // native_app_window_cocoa.mm). This requires the render host view to be 3423 // native_app_window_cocoa.mm). This requires the render host view to be
3442 // draggable by default. 3424 // draggable by default.
3443 - (BOOL)mouseDownCanMoveWindow { 3425 - (BOOL)mouseDownCanMoveWindow {
3444 return YES; 3426 return YES;
3445 } 3427 }
3446 3428
3447 @end 3429 @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