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

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

Issue 2493383002: [Merge to 2883] 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 <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 2947 matching lines...) Expand 10 before | Expand all | Expand 10 after
2958 2958
2959 NSRect rect = [self firstViewRectForCharacterRange:theRange 2959 NSRect rect = [self firstViewRectForCharacterRange:theRange
2960 actualRange:actualRange]; 2960 actualRange:actualRange];
2961 2961
2962 // Convert into screen coordinates for return. 2962 // Convert into screen coordinates for return.
2963 rect = [self convertRect:rect toView:nil]; 2963 rect = [self convertRect:rect toView:nil];
2964 rect = [[self window] convertRectToScreen:rect]; 2964 rect = [[self window] convertRectToScreen:rect];
2965 return rect; 2965 return rect;
2966 } 2966 }
2967 2967
2968 - (NSRange)selectedRange {
2969 if (selectedRange_.location == NSNotFound || selectedRange_.length == 0)
2970 return NSMakeRange(NSNotFound, 0);
2971 return selectedRange_;
2972 }
2973
2974 - (NSRange)markedRange { 2968 - (NSRange)markedRange {
2975 // An input method calls this method to check if an application really has 2969 // An input method calls this method to check if an application really has
2976 // a text being composed when hasMarkedText call returns true. 2970 // a text being composed when hasMarkedText call returns true.
2977 // Returns the range saved in the setMarkedText method so the input method 2971 // Returns the range saved in the setMarkedText method so the input method
2978 // calls the setMarkedText method and we can update the composition node 2972 // calls the setMarkedText method and we can update the composition node
2979 // there. (When this method returns an empty range, the input method doesn't 2973 // there. (When this method returns an empty range, the input method doesn't
2980 // call the setMarkedText method.) 2974 // call the setMarkedText method.)
2981 return hasMarkedText_ ? markedRange_ : NSMakeRange(NSNotFound, 0); 2975 return hasMarkedText_ ? markedRange_ : NSMakeRange(NSNotFound, 0);
2982 } 2976 }
2983 2977
2984 - (NSAttributedString*)attributedSubstringForProposedRange:(NSRange)range 2978 - (NSAttributedString*)attributedSubstringForProposedRange:(NSRange)range
2985 actualRange:(NSRangePointer)actualRange { 2979 actualRange:(NSRangePointer)actualRange {
2986 // Prepare |actualRange| as if the proposed range is invalid. If it is valid, 2980 // TODO(thakis): Pipe |actualRange| through TextInputClientMac machinery.
2987 // then |actualRange| will be updated again.
2988 if (actualRange) 2981 if (actualRange)
2989 *actualRange = NSMakeRange(NSNotFound, 0); 2982 *actualRange = range;
2990
2991 // The caller of this method is allowed to pass nonsensical ranges. These
2992 // can't even be converted into gfx::Ranges.
2993 if (range.location == NSNotFound || range.length == 0)
2994 return nil;
2995 if (range.length >= std::numeric_limits<NSUInteger>::max() - range.location)
2996 return nil;
2997 2983
2998 const gfx::Range requested_range(range); 2984 const gfx::Range requested_range(range);
2999 if (requested_range.is_reversed()) 2985 if (requested_range.is_reversed())
3000 return nil; 2986 return nil;
3001 2987
3002 gfx::Range expected_range; 2988 gfx::Range expected_range;
3003 const base::string16* expected_text; 2989 const base::string16* expected_text;
3004 2990
3005 if (!renderWidgetHostView_->composition_range().is_empty()) { 2991 if (!renderWidgetHostView_->composition_range().is_empty()) {
3006 expected_text = &markedText_; 2992 expected_text = &markedText_;
3007 expected_range = renderWidgetHostView_->composition_range(); 2993 expected_range = renderWidgetHostView_->composition_range();
3008 } else { 2994 } else {
3009 expected_text = &renderWidgetHostView_->selection_text(); 2995 expected_text = &renderWidgetHostView_->selection_text();
3010 size_t offset = renderWidgetHostView_->selection_text_offset(); 2996 size_t offset = renderWidgetHostView_->selection_text_offset();
3011 expected_range = gfx::Range(offset, offset + expected_text->size()); 2997 expected_range = gfx::Range(offset, offset + expected_text->size());
3012 } 2998 }
3013 2999
3014 gfx::Range actual_range = expected_range.Intersect(requested_range); 3000 if (!expected_range.Contains(requested_range))
3015 if (!actual_range.IsValid())
3016 return nil; 3001 return nil;
3017 3002
3018 // Gets the raw bytes to avoid unnecessary string copies for generating 3003 // Gets the raw bytes to avoid unnecessary string copies for generating
3019 // NSString. 3004 // NSString.
3020 const base::char16* bytes = 3005 const base::char16* bytes =
3021 &(*expected_text)[actual_range.start() - expected_range.start()]; 3006 &(*expected_text)[requested_range.start() - expected_range.start()];
3022 // Avoid integer overflow. 3007 // Avoid integer overflow.
3023 base::CheckedNumeric<size_t> requested_len = actual_range.length(); 3008 base::CheckedNumeric<size_t> requested_len = requested_range.length();
3024 requested_len *= sizeof(base::char16); 3009 requested_len *= sizeof(base::char16);
3025 NSUInteger bytes_len = base::strict_cast<NSUInteger, size_t>( 3010 NSUInteger bytes_len = base::strict_cast<NSUInteger, size_t>(
3026 requested_len.ValueOrDefault(0)); 3011 requested_len.ValueOrDefault(0));
3027 base::scoped_nsobject<NSString> ns_string( 3012 base::scoped_nsobject<NSString> ns_string(
3028 [[NSString alloc] initWithBytes:bytes 3013 [[NSString alloc] initWithBytes:bytes
3029 length:bytes_len 3014 length:bytes_len
3030 encoding:NSUTF16LittleEndianStringEncoding]); 3015 encoding:NSUTF16LittleEndianStringEncoding]);
3031 if (actualRange)
3032 *actualRange = actual_range.ToNSRange();
3033
3034 return [[[NSAttributedString alloc] initWithString:ns_string] autorelease]; 3016 return [[[NSAttributedString alloc] initWithString:ns_string] autorelease];
3035 } 3017 }
3036 3018
3037 - (NSInteger)conversationIdentifier { 3019 - (NSInteger)conversationIdentifier {
3038 return reinterpret_cast<NSInteger>(self); 3020 return reinterpret_cast<NSInteger>(self);
3039 } 3021 }
3040 3022
3041 // Each RenderWidgetHostViewCocoa has its own input context, but we return 3023 // Each RenderWidgetHostViewCocoa has its own input context, but we return
3042 // nil when the caret is in non-editable content or password box to avoid 3024 // nil when the caret is in non-editable content or password box to avoid
3043 // making input methods do their work. 3025 // making input methods do their work.
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
3386 3368
3387 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 3369 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
3388 // regions that are not draggable. (See ControlRegionView in 3370 // regions that are not draggable. (See ControlRegionView in
3389 // native_app_window_cocoa.mm). This requires the render host view to be 3371 // native_app_window_cocoa.mm). This requires the render host view to be
3390 // draggable by default. 3372 // draggable by default.
3391 - (BOOL)mouseDownCanMoveWindow { 3373 - (BOOL)mouseDownCanMoveWindow {
3392 return YES; 3374 return YES;
3393 } 3375 }
3394 3376
3395 @end 3377 @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