Chromium Code Reviews| 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 1175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1186 | 1186 |
| 1187 void RenderWidgetHostViewMac::StopSpeaking() { | 1187 void RenderWidgetHostViewMac::StopSpeaking() { |
| 1188 if ([NSApp respondsToSelector:@selector(stopSpeaking:)]) | 1188 if ([NSApp respondsToSelector:@selector(stopSpeaking:)]) |
| 1189 [NSApp stopSpeaking:cocoa_view_]; | 1189 [NSApp stopSpeaking:cocoa_view_]; |
| 1190 } | 1190 } |
| 1191 | 1191 |
| 1192 // | 1192 // |
| 1193 // RenderWidgetHostViewCocoa uses the stored selection text, | 1193 // RenderWidgetHostViewCocoa uses the stored selection text, |
| 1194 // which implements NSServicesRequests protocol. | 1194 // which implements NSServicesRequests protocol. |
| 1195 // | 1195 // |
| 1196 void RenderWidgetHostViewMac::SelectionChanged(const base::string16& text, | 1196 void RenderWidgetHostViewMac::SelectionChanged(const base::string16& text, |
|
yukawa
2015/08/20 09:14:49
Just out of curiosity, if we send NSAttributedStri
Shu Chen
2015/08/21 03:13:11
It is not easy to do that without a bigger refacto
| |
| 1197 size_t offset, | 1197 size_t offset, |
| 1198 const gfx::Range& range) { | 1198 const gfx::Range& range) { |
| 1199 if (range.is_empty() || text.empty()) { | 1199 if (range.is_empty() || text.empty()) { |
| 1200 selected_text_.clear(); | 1200 selected_text_.clear(); |
| 1201 } else { | 1201 } else { |
| 1202 size_t pos = range.GetMin() - offset; | 1202 size_t pos = range.GetMin() - offset; |
| 1203 size_t n = range.length(); | 1203 size_t n = range.length(); |
| 1204 | 1204 |
| 1205 DCHECK(pos + n <= text.length()) << "The text can not fully cover range."; | 1205 DCHECK(pos + n <= text.length()) << "The text can not fully cover range."; |
| 1206 if (pos >= text.length()) { | 1206 if (pos >= text.length()) { |
| (...skipping 11 matching lines...) Expand all 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 gfx::Range expected_range; |
| 2891 TextInputClientMac::GetInstance()->GetAttributedSubstringFromRange( | 2898 std::wstring expected_text; // Using wide string for string truncation. |
| 2892 renderWidgetHostView_->render_widget_host_, range); | 2899 std::string result_text(""); |
| 2893 return str; | 2900 |
| 2901 if (!renderWidgetHostView_->composition_range().is_empty()) { | |
| 2902 expected_range = renderWidgetHostView_->composition_range(); | |
| 2903 expected_text = base::UTF16ToWide(markedText_); | |
| 2904 } else if (!renderWidgetHostView_->selection_range().is_empty()) { | |
|
yukawa
2015/08/20 09:14:49
I think we can take advantage of |RenderWidgetHost
Shu Chen
2015/08/21 03:13:11
Done.
| |
| 2905 expected_range = renderWidgetHostView_->selection_range(); | |
| 2906 expected_text = base::UTF8ToWide(renderWidgetHostView_->selected_text()); | |
| 2907 } | |
| 2908 | |
| 2909 if (expected_range.start() <= range.location && | |
|
yukawa
2015/08/20 09:14:49
Don't we need to return nil when there is no inter
Shu Chen
2015/08/21 03:13:11
Done. I think we don't need to update |actualRange
| |
| 2910 expected_range.end() >= range.location + range.length) { | |
| 2911 result_text = base::WideToUTF8(expected_text.substr( | |
| 2912 range.location - expected_range.start(), range.length)); | |
| 2913 } | |
| 2914 | |
| 2915 NSString *nstr = [[NSString alloc] initWithUTF8String:result_text.c_str()]; | |
| 2916 return [[NSAttributedString alloc] initWithString:nstr]; | |
| 2894 } | 2917 } |
| 2895 | 2918 |
| 2896 - (NSInteger)conversationIdentifier { | 2919 - (NSInteger)conversationIdentifier { |
| 2897 return reinterpret_cast<NSInteger>(self); | 2920 return reinterpret_cast<NSInteger>(self); |
| 2898 } | 2921 } |
| 2899 | 2922 |
| 2900 // Each RenderWidgetHostViewCocoa has its own input context, but we return | 2923 // 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 | 2924 // nil when the caret is in non-editable content or password box to avoid |
| 2902 // making input methods do their work. | 2925 // making input methods do their work. |
| 2903 - (NSTextInputContext *)inputContext { | 2926 - (NSTextInputContext *)inputContext { |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3315 | 3338 |
| 3316 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3339 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
| 3317 // regions that are not draggable. (See ControlRegionView in | 3340 // regions that are not draggable. (See ControlRegionView in |
| 3318 // native_app_window_cocoa.mm). This requires the render host view to be | 3341 // native_app_window_cocoa.mm). This requires the render host view to be |
| 3319 // draggable by default. | 3342 // draggable by default. |
| 3320 - (BOOL)mouseDownCanMoveWindow { | 3343 - (BOOL)mouseDownCanMoveWindow { |
| 3321 return YES; | 3344 return YES; |
| 3322 } | 3345 } |
| 3323 | 3346 |
| 3324 @end | 3347 @end |
| OLD | NEW |