OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 Loading... | |
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 |
2891 TextInputClientMac::GetInstance()->GetAttributedSubstringFromRange( | 2898 const gfx::Range requested_range(range); |
2892 renderWidgetHostView_->render_widget_host_, range); | 2899 if (requested_range.is_reversed()) |
2893 return str; | 2900 return nil; |
2901 | |
2902 gfx::Range expected_range; | |
2903 base::string16 expected_text; | |
2904 | |
2905 if (!renderWidgetHostView_->composition_range().is_empty()) { | |
2906 expected_text = markedText_; | |
2907 expected_range = renderWidgetHostView_->composition_range(); | |
2908 } else { | |
2909 expected_text = renderWidgetHostView_->selection_text(); | |
2910 size_t offset = renderWidgetHostView_->selection_text_offset(); | |
2911 expected_range = gfx::Range(offset, offset + expected_text.size()); | |
2912 } | |
2913 | |
2914 if (!expected_range.Contains(requested_range)) | |
2915 return nil; | |
2916 | |
2917 expected_text = expected_text.substr( | |
2918 requested_range.start() - expected_range.start(), | |
2919 requested_range.length()); | |
2920 | |
2921 return [[NSAttributedString alloc] initWithString: | |
Alexei Svitkine (slow)
2015/08/24 15:34:43
You need to autorelease this object, otherwise you
Shu Chen
2015/08/25 03:43:10
Done.
| |
2922 base::SysUTF16ToNSString(expected_text)]; | |
Alexei Svitkine (slow)
2015/08/24 15:34:43
Isn't this losing the formatting?
If I remember c
Shu Chen
2015/08/25 03:43:10
Yes. I've explained in the cl description and in #
| |
2894 } | 2923 } |
2895 | 2924 |
2896 - (NSInteger)conversationIdentifier { | 2925 - (NSInteger)conversationIdentifier { |
2897 return reinterpret_cast<NSInteger>(self); | 2926 return reinterpret_cast<NSInteger>(self); |
2898 } | 2927 } |
2899 | 2928 |
2900 // Each RenderWidgetHostViewCocoa has its own input context, but we return | 2929 // 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 | 2930 // nil when the caret is in non-editable content or password box to avoid |
2902 // making input methods do their work. | 2931 // making input methods do their work. |
2903 - (NSTextInputContext *)inputContext { | 2932 - (NSTextInputContext *)inputContext { |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3315 | 3344 |
3316 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3345 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
3317 // regions that are not draggable. (See ControlRegionView in | 3346 // regions that are not draggable. (See ControlRegionView in |
3318 // native_app_window_cocoa.mm). This requires the render host view to be | 3347 // native_app_window_cocoa.mm). This requires the render host view to be |
3319 // draggable by default. | 3348 // draggable by default. |
3320 - (BOOL)mouseDownCanMoveWindow { | 3349 - (BOOL)mouseDownCanMoveWindow { |
3321 return YES; | 3350 return YES; |
3322 } | 3351 } |
3323 | 3352 |
3324 @end | 3353 @end |
OLD | NEW |