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

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

Issue 1301173002: Avoid sync IPCs for firstRectForCharacterRange/attributedSubstringForProposedRange. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed test failures 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 1207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 [cocoa_view_ setMarkedRange:range.ToNSRange()]; 1218 [cocoa_view_ setMarkedRange:range.ToNSRange()];
1219 } 1219 }
1220 1220
1221 RenderWidgetHostViewBase::SelectionChanged(text, offset, range); 1221 RenderWidgetHostViewBase::SelectionChanged(text, offset, range);
1222 } 1222 }
1223 1223
1224 void RenderWidgetHostViewMac::SelectionBoundsChanged( 1224 void RenderWidgetHostViewMac::SelectionBoundsChanged(
1225 const ViewHostMsg_SelectionBounds_Params& params) { 1225 const ViewHostMsg_SelectionBounds_Params& params) {
1226 if (params.anchor_rect == params.focus_rect) 1226 if (params.anchor_rect == params.focus_rect)
1227 caret_rect_ = params.anchor_rect; 1227 caret_rect_ = params.anchor_rect;
1228 first_selection_rect_ = params.anchor_rect;
1228 } 1229 }
1229 1230
1230 void RenderWidgetHostViewMac::SetShowingContextMenu(bool showing) { 1231 void RenderWidgetHostViewMac::SetShowingContextMenu(bool showing) {
1231 RenderWidgetHostViewBase::SetShowingContextMenu(showing); 1232 RenderWidgetHostViewBase::SetShowingContextMenu(showing);
1232 1233
1233 // Create a fake mouse event to inform the render widget that the mouse 1234 // Create a fake mouse event to inform the render widget that the mouse
1234 // left or entered. 1235 // left or entered.
1235 NSWindow* window = [cocoa_view_ window]; 1236 NSWindow* window = [cocoa_view_ window];
1236 // TODO(asvitkine): If the location outside of the event stream doesn't 1237 // TODO(asvitkine): If the location outside of the event stream doesn't
1237 // correspond to the current event (due to delayed event processing), then 1238 // correspond to the current event (due to delayed event processing), then
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
1438 1439
1439 bool RenderWidgetHostViewMac::GetCachedFirstRectForCharacterRange( 1440 bool RenderWidgetHostViewMac::GetCachedFirstRectForCharacterRange(
1440 NSRange range, 1441 NSRange range,
1441 NSRect* rect, 1442 NSRect* rect,
1442 NSRange* actual_range) { 1443 NSRange* actual_range) {
1443 DCHECK(rect); 1444 DCHECK(rect);
1444 // This exists to make IMEs more responsive, see http://crbug.com/115920 1445 // This exists to make IMEs more responsive, see http://crbug.com/115920
1445 TRACE_EVENT0("browser", 1446 TRACE_EVENT0("browser",
1446 "RenderWidgetHostViewMac::GetFirstRectForCharacterRange"); 1447 "RenderWidgetHostViewMac::GetFirstRectForCharacterRange");
1447 1448
1449 const gfx::Range requested_range(range);
1448 // If requested range is same as caret location, we can just return it. 1450 // If requested range is same as caret location, we can just return it.
1449 if (selection_range_.is_empty() && gfx::Range(range) == selection_range_) { 1451 if (selection_range_.is_empty() && requested_range == selection_range_) {
1450 if (actual_range) 1452 if (actual_range)
1451 *actual_range = range; 1453 *actual_range = range;
1452 *rect = NSRectFromCGRect(caret_rect_.ToCGRect()); 1454 *rect = NSRectFromCGRect(caret_rect_.ToCGRect());
1453 return true; 1455 return true;
1454 } 1456 }
1455 1457
1458 if (composition_range_.is_empty()) {
1459 if (!selection_range_.Contains(requested_range))
1460 return false;
1461 *actual_range = selection_range_.ToNSRange();
1462 *rect = NSRectFromCGRect(first_selection_rect_.ToCGRect());
1463 return true;
1464 }
1465
1456 const gfx::Range request_range_in_composition = 1466 const gfx::Range request_range_in_composition =
1457 ConvertCharacterRangeToCompositionRange(gfx::Range(range)); 1467 ConvertCharacterRangeToCompositionRange(requested_range);
1458 if (request_range_in_composition == gfx::Range::InvalidRange()) 1468 if (request_range_in_composition == gfx::Range::InvalidRange())
1459 return false; 1469 return false;
1460 1470
1461 // If firstRectForCharacterRange in WebFrame is failed in renderer, 1471 // If firstRectForCharacterRange in WebFrame is failed in renderer,
1462 // ImeCompositionRangeChanged will be sent with empty vector. 1472 // ImeCompositionRangeChanged will be sent with empty vector.
1463 if (composition_bounds_.empty()) 1473 if (composition_bounds_.empty())
1464 return false; 1474 return false;
1465 DCHECK_EQ(composition_bounds_.size(), composition_range_.length()); 1475 DCHECK_EQ(composition_bounds_.size(), composition_range_.length());
1466 1476
1467 gfx::Range ui_actual_range; 1477 gfx::Range ui_actual_range;
(...skipping 1412 matching lines...) Expand 10 before | Expand all | Expand 10 after
2880 // there. (When this method returns an empty range, the input method doesn't 2890 // there. (When this method returns an empty range, the input method doesn't
2881 // call the setMarkedText method.) 2891 // call the setMarkedText method.)
2882 return hasMarkedText_ ? markedRange_ : NSMakeRange(NSNotFound, 0); 2892 return hasMarkedText_ ? markedRange_ : NSMakeRange(NSNotFound, 0);
2883 } 2893 }
2884 2894
2885 - (NSAttributedString*)attributedSubstringForProposedRange:(NSRange)range 2895 - (NSAttributedString*)attributedSubstringForProposedRange:(NSRange)range
2886 actualRange:(NSRangePointer)actualRange { 2896 actualRange:(NSRangePointer)actualRange {
2887 // TODO(thakis): Pipe |actualRange| through TextInputClientMac machinery. 2897 // TODO(thakis): Pipe |actualRange| through TextInputClientMac machinery.
2888 if (actualRange) 2898 if (actualRange)
2889 *actualRange = range; 2899 *actualRange = range;
2890 NSAttributedString* str = 2900
2891 TextInputClientMac::GetInstance()->GetAttributedSubstringFromRange( 2901 const gfx::Range requested_range(range);
2892 renderWidgetHostView_->render_widget_host_, range); 2902 if (requested_range.is_reversed())
2893 return str; 2903 return nil;
2904
2905 gfx::Range expected_range;
2906 const base::string16* expected_text;
2907
2908 if (!renderWidgetHostView_->composition_range().is_empty()) {
2909 expected_text = &markedText_;
2910 expected_range = renderWidgetHostView_->composition_range();
2911 } else {
2912 expected_text = &renderWidgetHostView_->selection_text();
2913 size_t offset = renderWidgetHostView_->selection_text_offset();
2914 expected_range = gfx::Range(offset, offset + expected_text->size());
2915 }
2916
2917 if (!expected_range.Contains(requested_range))
2918 return nil;
2919
2920 // Gets the raw bytes to avoid unnecessary string copies for generating
2921 // NSString.
2922 const base::char16* bytes =
2923 &(*expected_text)[requested_range.start() - expected_range.start()];
2924 NSUInteger bytes_len = requested_range.length() * sizeof(base::char16);
2925 base::scoped_nsobject<NSString> ns_string(
2926 [[NSString alloc] initWithBytes:bytes
2927 length:bytes_len
2928 encoding:NSUTF16StringEncoding]);
2929 return [[[NSAttributedString alloc] initWithString:ns_string] autorelease];
2894 } 2930 }
2895 2931
2896 - (NSInteger)conversationIdentifier { 2932 - (NSInteger)conversationIdentifier {
2897 return reinterpret_cast<NSInteger>(self); 2933 return reinterpret_cast<NSInteger>(self);
2898 } 2934 }
2899 2935
2900 // Each RenderWidgetHostViewCocoa has its own input context, but we return 2936 // Each RenderWidgetHostViewCocoa has its own input context, but we return
2901 // nil when the caret is in non-editable content or password box to avoid 2937 // nil when the caret is in non-editable content or password box to avoid
2902 // making input methods do their work. 2938 // making input methods do their work.
2903 - (NSTextInputContext *)inputContext { 2939 - (NSTextInputContext *)inputContext {
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
3315 3351
3316 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 3352 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
3317 // regions that are not draggable. (See ControlRegionView in 3353 // regions that are not draggable. (See ControlRegionView in
3318 // native_app_window_cocoa.mm). This requires the render host view to be 3354 // native_app_window_cocoa.mm). This requires the render host view to be
3319 // draggable by default. 3355 // draggable by default.
3320 - (BOOL)mouseDownCanMoveWindow { 3356 - (BOOL)mouseDownCanMoveWindow {
3321 return YES; 3357 return YES;
3322 } 3358 }
3323 3359
3324 @end 3360 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698