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

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

Issue 1327743002: Avoid sync IPCs for firstRectForCharacterRange/attributedSubstringForProposedRange. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed bugs in original cl 1301173002. Created 5 years, 3 months 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
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 10
(...skipping 1208 matching lines...) Expand 10 before | Expand all | Expand 10 after
1219 [cocoa_view_ setMarkedRange:range.ToNSRange()]; 1219 [cocoa_view_ setMarkedRange:range.ToNSRange()];
1220 } 1220 }
1221 1221
1222 RenderWidgetHostViewBase::SelectionChanged(text, offset, range); 1222 RenderWidgetHostViewBase::SelectionChanged(text, offset, range);
1223 } 1223 }
1224 1224
1225 void RenderWidgetHostViewMac::SelectionBoundsChanged( 1225 void RenderWidgetHostViewMac::SelectionBoundsChanged(
1226 const ViewHostMsg_SelectionBounds_Params& params) { 1226 const ViewHostMsg_SelectionBounds_Params& params) {
1227 if (params.anchor_rect == params.focus_rect) 1227 if (params.anchor_rect == params.focus_rect)
1228 caret_rect_ = params.anchor_rect; 1228 caret_rect_ = params.anchor_rect;
1229 first_selection_rect_ = params.anchor_rect;
1229 } 1230 }
1230 1231
1231 void RenderWidgetHostViewMac::SetShowingContextMenu(bool showing) { 1232 void RenderWidgetHostViewMac::SetShowingContextMenu(bool showing) {
1232 RenderWidgetHostViewBase::SetShowingContextMenu(showing); 1233 RenderWidgetHostViewBase::SetShowingContextMenu(showing);
1233 1234
1234 // Create a fake mouse event to inform the render widget that the mouse 1235 // Create a fake mouse event to inform the render widget that the mouse
1235 // left or entered. 1236 // left or entered.
1236 NSWindow* window = [cocoa_view_ window]; 1237 NSWindow* window = [cocoa_view_ window];
1237 // TODO(asvitkine): If the location outside of the event stream doesn't 1238 // TODO(asvitkine): If the location outside of the event stream doesn't
1238 // correspond to the current event (due to delayed event processing), then 1239 // correspond to the current event (due to delayed event processing), then
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
1439 1440
1440 bool RenderWidgetHostViewMac::GetCachedFirstRectForCharacterRange( 1441 bool RenderWidgetHostViewMac::GetCachedFirstRectForCharacterRange(
1441 NSRange range, 1442 NSRange range,
1442 NSRect* rect, 1443 NSRect* rect,
1443 NSRange* actual_range) { 1444 NSRange* actual_range) {
1444 DCHECK(rect); 1445 DCHECK(rect);
1445 // This exists to make IMEs more responsive, see http://crbug.com/115920 1446 // This exists to make IMEs more responsive, see http://crbug.com/115920
1446 TRACE_EVENT0("browser", 1447 TRACE_EVENT0("browser",
1447 "RenderWidgetHostViewMac::GetFirstRectForCharacterRange"); 1448 "RenderWidgetHostViewMac::GetFirstRectForCharacterRange");
1448 1449
1450 const gfx::Range requested_range(range);
1449 // If requested range is same as caret location, we can just return it. 1451 // If requested range is same as caret location, we can just return it.
1450 if (selection_range_.is_empty() && gfx::Range(range) == selection_range_) { 1452 if (selection_range_.is_empty() && requested_range == selection_range_) {
1451 if (actual_range) 1453 if (actual_range)
1452 *actual_range = range; 1454 *actual_range = range;
1453 *rect = NSRectFromCGRect(caret_rect_.ToCGRect()); 1455 *rect = NSRectFromCGRect(caret_rect_.ToCGRect());
1454 return true; 1456 return true;
1455 } 1457 }
1456 1458
1459 if (composition_range_.is_empty()) {
1460 if (!selection_range_.Contains(requested_range))
1461 return false;
1462 if (actual_range)
1463 *actual_range = selection_range_.ToNSRange();
1464 *rect = NSRectFromCGRect(first_selection_rect_.ToCGRect());
1465 return true;
1466 }
1467
1457 const gfx::Range request_range_in_composition = 1468 const gfx::Range request_range_in_composition =
1458 ConvertCharacterRangeToCompositionRange(gfx::Range(range)); 1469 ConvertCharacterRangeToCompositionRange(requested_range);
1459 if (request_range_in_composition == gfx::Range::InvalidRange()) 1470 if (request_range_in_composition == gfx::Range::InvalidRange())
1460 return false; 1471 return false;
1461 1472
1462 // If firstRectForCharacterRange in WebFrame is failed in renderer, 1473 // If firstRectForCharacterRange in WebFrame is failed in renderer,
1463 // ImeCompositionRangeChanged will be sent with empty vector. 1474 // ImeCompositionRangeChanged will be sent with empty vector.
1464 if (composition_bounds_.empty()) 1475 if (composition_bounds_.empty())
1465 return false; 1476 return false;
1466 DCHECK_EQ(composition_bounds_.size(), composition_range_.length()); 1477 DCHECK_EQ(composition_bounds_.size(), composition_range_.length());
1467 1478
1468 gfx::Range ui_actual_range; 1479 gfx::Range ui_actual_range;
(...skipping 1419 matching lines...) Expand 10 before | Expand all | Expand 10 after
2888 // there. (When this method returns an empty range, the input method doesn't 2899 // there. (When this method returns an empty range, the input method doesn't
2889 // call the setMarkedText method.) 2900 // call the setMarkedText method.)
2890 return hasMarkedText_ ? markedRange_ : NSMakeRange(NSNotFound, 0); 2901 return hasMarkedText_ ? markedRange_ : NSMakeRange(NSNotFound, 0);
2891 } 2902 }
2892 2903
2893 - (NSAttributedString*)attributedSubstringForProposedRange:(NSRange)range 2904 - (NSAttributedString*)attributedSubstringForProposedRange:(NSRange)range
2894 actualRange:(NSRangePointer)actualRange { 2905 actualRange:(NSRangePointer)actualRange {
2895 // TODO(thakis): Pipe |actualRange| through TextInputClientMac machinery. 2906 // TODO(thakis): Pipe |actualRange| through TextInputClientMac machinery.
2896 if (actualRange) 2907 if (actualRange)
2897 *actualRange = range; 2908 *actualRange = range;
2898 NSAttributedString* str = 2909
2899 TextInputClientMac::GetInstance()->GetAttributedSubstringFromRange( 2910 const gfx::Range requested_range(range);
2900 renderWidgetHostView_->render_widget_host_, range); 2911 if (requested_range.is_reversed())
2901 return str; 2912 return nil;
2913
2914 gfx::Range expected_range;
2915 const base::string16* expected_text;
2916
2917 if (!renderWidgetHostView_->composition_range().is_empty()) {
2918 expected_text = &markedText_;
2919 expected_range = renderWidgetHostView_->composition_range();
2920 } else {
2921 expected_text = &renderWidgetHostView_->selection_text();
2922 size_t offset = renderWidgetHostView_->selection_text_offset();
2923 expected_range = gfx::Range(offset, offset + expected_text->size());
Shu Chen 2015/09/02 05:04:36 from palmer@: How do you know this range is valid
Shu Chen 2015/09/02 05:41:22 RenderWidgetHostViewBase must make sure selection_
2924 }
2925
2926 if (!expected_range.Contains(requested_range))
2927 return nil;
2928
2929 // Gets the raw bytes to avoid unnecessary string copies for generating
2930 // NSString.
2931 const base::char16* bytes =
2932 &(*expected_text)[requested_range.start() - expected_range.start()];
Shu Chen 2015/09/02 05:04:36 from palmer@: I don't understand this code. What
Shu Chen 2015/09/02 05:41:22 The above "expected_range.Contains(requested_range
2933 NSUInteger bytes_len = requested_range.length() * sizeof(base::char16);
Shu Chen 2015/09/02 05:04:36 from palmer@: Is NSUInteger guaranteed to have th
Shu Chen 2015/09/02 05:41:22 Doc says "When building 32-bit applications, NSUIn
2934 base::scoped_nsobject<NSString> ns_string(
2935 [[NSString alloc] initWithBytes:bytes
2936 length:bytes_len
2937 encoding:NSUTF16LittleEndianStringEncoding]);
2938 return [[[NSAttributedString alloc] initWithString:ns_string] autorelease];
2902 } 2939 }
2903 2940
2904 - (NSInteger)conversationIdentifier { 2941 - (NSInteger)conversationIdentifier {
2905 return reinterpret_cast<NSInteger>(self); 2942 return reinterpret_cast<NSInteger>(self);
2906 } 2943 }
2907 2944
2908 // Each RenderWidgetHostViewCocoa has its own input context, but we return 2945 // Each RenderWidgetHostViewCocoa has its own input context, but we return
2909 // nil when the caret is in non-editable content or password box to avoid 2946 // nil when the caret is in non-editable content or password box to avoid
2910 // making input methods do their work. 2947 // making input methods do their work.
2911 - (NSTextInputContext *)inputContext { 2948 - (NSTextInputContext *)inputContext {
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
3323 3360
3324 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 3361 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
3325 // regions that are not draggable. (See ControlRegionView in 3362 // regions that are not draggable. (See ControlRegionView in
3326 // native_app_window_cocoa.mm). This requires the render host view to be 3363 // native_app_window_cocoa.mm). This requires the render host view to be
3327 // draggable by default. 3364 // draggable by default.
3328 - (BOOL)mouseDownCanMoveWindow { 3365 - (BOOL)mouseDownCanMoveWindow {
3329 return YES; 3366 return YES;
3330 } 3367 }
3331 3368
3332 @end 3369 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698