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

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

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