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

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: addressed yukawa@'s comments. Created 5 years, 4 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
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_mac.h ('k') | no next file » | 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 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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
1446 "RenderWidgetHostViewMac::GetFirstRectForCharacterRange"); 1447 "RenderWidgetHostViewMac::GetFirstRectForCharacterRange");
1447 1448
1448 // If requested range is same as caret location, we can just return it. 1449 // If requested range is same as caret location, we can just return it.
1449 if (selection_range_.is_empty() && gfx::Range(range) == selection_range_) { 1450 if (selection_range_.is_empty() && gfx::Range(range) == selection_range_) {
1450 if (actual_range) 1451 if (actual_range)
1451 *actual_range = range; 1452 *actual_range = range;
1452 *rect = NSRectFromCGRect(caret_rect_.ToCGRect()); 1453 *rect = NSRectFromCGRect(caret_rect_.ToCGRect());
1453 return true; 1454 return true;
1454 } 1455 }
1455 1456
1457 if (composition_range_.is_empty()) {
1458 *actual_range = selection_range_.ToNSRange();
1459 *rect = NSRectFromCGRect(first_selection_rect_.ToCGRect());
1460 return true;
1461 }
1462
1456 const gfx::Range request_range_in_composition = 1463 const gfx::Range request_range_in_composition =
1457 ConvertCharacterRangeToCompositionRange(gfx::Range(range)); 1464 ConvertCharacterRangeToCompositionRange(gfx::Range(range));
1458 if (request_range_in_composition == gfx::Range::InvalidRange()) 1465 if (request_range_in_composition == gfx::Range::InvalidRange())
1459 return false; 1466 return false;
1460 1467
1461 // If firstRectForCharacterRange in WebFrame is failed in renderer, 1468 // If firstRectForCharacterRange in WebFrame is failed in renderer,
1462 // ImeCompositionRangeChanged will be sent with empty vector. 1469 // ImeCompositionRangeChanged will be sent with empty vector.
1463 if (composition_bounds_.empty()) 1470 if (composition_bounds_.empty())
1464 return false; 1471 return false;
1465 DCHECK_EQ(composition_bounds_.size(), composition_range_.length()); 1472 DCHECK_EQ(composition_bounds_.size(), composition_range_.length());
(...skipping 1414 matching lines...) Expand 10 before | Expand all | Expand 10 after
2880 // there. (When this method returns an empty range, the input method doesn't 2887 // there. (When this method returns an empty range, the input method doesn't
2881 // call the setMarkedText method.) 2888 // call the setMarkedText method.)
2882 return hasMarkedText_ ? markedRange_ : NSMakeRange(NSNotFound, 0); 2889 return hasMarkedText_ ? markedRange_ : NSMakeRange(NSNotFound, 0);
2883 } 2890 }
2884 2891
2885 - (NSAttributedString*)attributedSubstringForProposedRange:(NSRange)range 2892 - (NSAttributedString*)attributedSubstringForProposedRange:(NSRange)range
2886 actualRange:(NSRangePointer)actualRange { 2893 actualRange:(NSRangePointer)actualRange {
2887 // TODO(thakis): Pipe |actualRange| through TextInputClientMac machinery. 2894 // TODO(thakis): Pipe |actualRange| through TextInputClientMac machinery.
2888 if (actualRange) 2895 if (actualRange)
2889 *actualRange = range; 2896 *actualRange = range;
2890 NSAttributedString* str = 2897 gfx::Range expected_range;
yukawa 2015/08/21 03:46:13 How about making sure if |range| is not reversed a
Shu Chen 2015/08/21 05:17:04 Done.
2891 TextInputClientMac::GetInstance()->GetAttributedSubstringFromRange( 2898 // Using pointer to avoid string copy.
2892 renderWidgetHostView_->render_widget_host_, range); 2899 const base::string16* expected_text;
yukawa 2015/08/21 03:46:13 Can we use StringPiece16 instead?
Shu Chen 2015/08/21 05:17:04 Using StringPiece16 cannot make the code more conc
yukawa 2015/08/21 05:45:24 I see. Well, sorry for asking you for different t
Shu Chen 2015/08/21 05:59:49 Sorry I don't understand. The |exptected_text| is
yukawa 2015/08/21 06:19:26 const std::string selection_text() { return std:
yukawa 2015/08/21 06:25:00 So, it's not the internal details but the object t
Shu Chen 2015/08/21 06:36:49 OK. The string copy sounds a reasonable price to p
2893 return str; 2900
2901 if (!renderWidgetHostView_->composition_range().is_empty()) {
2902 expected_text = &markedText_;
2903 expected_range = renderWidgetHostView_->composition_range();
2904 } else {
2905 expected_text = &(renderWidgetHostView_->selection_text());
2906 size_t offset = renderWidgetHostView_->selection_text_offset();
2907 expected_range = gfx::Range(offset, offset + expected_text->length());
2908 }
2909
2910 if (expected_range.start() > range.location ||
yukawa 2015/08/21 03:46:13 if (!expected_range.Contains(expected_range))
yukawa 2015/08/21 03:49:36 Correction: if (!expected_range.Contains(request
Shu Chen 2015/08/21 05:17:04 Done.
2911 expected_range.end() < range.location + range.length) {
2912 return nil;
2913 }
2914
2915 // Uses wide string for Unicode string truncation.
2916 std::string result_text = base::WideToUTF8(
2917 base::UTF16ToWide(*expected_text).substr(
2918 range.location - expected_range.start(), range.length));
2919 NSString *nstr = [[NSString alloc] initWithUTF8String:result_text.c_str()];
2920 return [[NSAttributedString alloc] initWithString:nstr];
2894 } 2921 }
2895 2922
2896 - (NSInteger)conversationIdentifier { 2923 - (NSInteger)conversationIdentifier {
2897 return reinterpret_cast<NSInteger>(self); 2924 return reinterpret_cast<NSInteger>(self);
2898 } 2925 }
2899 2926
2900 // Each RenderWidgetHostViewCocoa has its own input context, but we return 2927 // 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 2928 // nil when the caret is in non-editable content or password box to avoid
2902 // making input methods do their work. 2929 // making input methods do their work.
2903 - (NSTextInputContext *)inputContext { 2930 - (NSTextInputContext *)inputContext {
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
3315 3342
3316 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 3343 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
3317 // regions that are not draggable. (See ControlRegionView in 3344 // regions that are not draggable. (See ControlRegionView in
3318 // native_app_window_cocoa.mm). This requires the render host view to be 3345 // native_app_window_cocoa.mm). This requires the render host view to be
3319 // draggable by default. 3346 // draggable by default.
3320 - (BOOL)mouseDownCanMoveWindow { 3347 - (BOOL)mouseDownCanMoveWindow {
3321 return YES; 3348 return YES;
3322 } 3349 }
3323 3350
3324 @end 3351 @end
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698