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

Unified 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: avoid string copies. 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/renderer_host/render_widget_host_view_mac.mm
diff --git a/content/browser/renderer_host/render_widget_host_view_mac.mm b/content/browser/renderer_host/render_widget_host_view_mac.mm
index 66f1c31650f7799701f8aba763b515e7c340aaeb..aeb9db2d4d6d275c32bbe07520d582346a2f3c98 100644
--- a/content/browser/renderer_host/render_widget_host_view_mac.mm
+++ b/content/browser/renderer_host/render_widget_host_view_mac.mm
@@ -1225,6 +1225,7 @@ void RenderWidgetHostViewMac::SelectionBoundsChanged(
const ViewHostMsg_SelectionBounds_Params& params) {
if (params.anchor_rect == params.focus_rect)
caret_rect_ = params.anchor_rect;
+ first_selection_rect_ = params.anchor_rect;
}
void RenderWidgetHostViewMac::SetShowingContextMenu(bool showing) {
@@ -1453,6 +1454,12 @@ bool RenderWidgetHostViewMac::GetCachedFirstRectForCharacterRange(
return true;
}
+ if (composition_range_.is_empty()) {
+ *actual_range = selection_range_.ToNSRange();
+ *rect = NSRectFromCGRect(first_selection_rect_.ToCGRect());
+ return true;
+ }
+
const gfx::Range request_range_in_composition =
ConvertCharacterRangeToCompositionRange(gfx::Range(range));
if (request_range_in_composition == gfx::Range::InvalidRange())
@@ -2887,10 +2894,34 @@ extern NSString *NSTextInputReplacementRangeAttributeName;
// TODO(thakis): Pipe |actualRange| through TextInputClientMac machinery.
if (actualRange)
*actualRange = range;
- NSAttributedString* str =
- TextInputClientMac::GetInstance()->GetAttributedSubstringFromRange(
- renderWidgetHostView_->render_widget_host_, range);
- return str;
+
+ const gfx::Range requested_range(range);
+ if (requested_range.is_reversed())
+ return nil;
+
+ gfx::Range expected_range;
+ const base::string16* expected_text;
+
+ if (!renderWidgetHostView_->composition_range().is_empty()) {
+ expected_text = &markedText_;
+ expected_range = renderWidgetHostView_->composition_range();
+ } else {
+ expected_text = &(renderWidgetHostView_->selection_text());
Alexei Svitkine (slow) 2015/08/26 15:09:22 Nit: I'm not sure the parentheses are necessary.
Shu Chen 2015/08/26 15:21:02 Done.
+ size_t offset = renderWidgetHostView_->selection_text_offset();
+ expected_range = gfx::Range(offset, offset + expected_text->size());
+ }
+
+ if (!expected_range.Contains(requested_range))
+ return nil;
+
+ const base::char16* bytes =
Alexei Svitkine (slow) 2015/08/26 15:09:22 Nit: Add a comment about why we're doing things th
Shu Chen 2015/08/26 15:21:02 Done.
+ &(*expected_text)[requested_range.start() - expected_range.start()];
+ NSUInteger bytes_len = requested_range.length() * sizeof(base::char16);
+ base::scoped_nsobject<NSString> ns_string(
+ [[NSString alloc] initWithBytes:bytes
+ length:bytes_len
Alexei Svitkine (slow) 2015/08/26 15:09:22 Nit: Align :'s
Shu Chen 2015/08/26 15:21:02 Done.
+ encoding:NSUTF16StringEncoding]);
+ return [[[NSAttributedString alloc] initWithString:ns_string] autorelease];
}
- (NSInteger)conversationIdentifier {
« 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