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; | |
1229 } | 1228 } |
1230 | 1229 |
1231 void RenderWidgetHostViewMac::SetShowingContextMenu(bool showing) { | 1230 void RenderWidgetHostViewMac::SetShowingContextMenu(bool showing) { |
1232 RenderWidgetHostViewBase::SetShowingContextMenu(showing); | 1231 RenderWidgetHostViewBase::SetShowingContextMenu(showing); |
1233 | 1232 |
1234 // Create a fake mouse event to inform the render widget that the mouse | 1233 // Create a fake mouse event to inform the render widget that the mouse |
1235 // left or entered. | 1234 // left or entered. |
1236 NSWindow* window = [cocoa_view_ window]; | 1235 NSWindow* window = [cocoa_view_ window]; |
1237 // TODO(asvitkine): If the location outside of the event stream doesn't | 1236 // TODO(asvitkine): If the location outside of the event stream doesn't |
1238 // correspond to the current event (due to delayed event processing), then | 1237 // correspond to the current event (due to delayed event processing), then |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1439 | 1438 |
1440 bool RenderWidgetHostViewMac::GetCachedFirstRectForCharacterRange( | 1439 bool RenderWidgetHostViewMac::GetCachedFirstRectForCharacterRange( |
1441 NSRange range, | 1440 NSRange range, |
1442 NSRect* rect, | 1441 NSRect* rect, |
1443 NSRange* actual_range) { | 1442 NSRange* actual_range) { |
1444 DCHECK(rect); | 1443 DCHECK(rect); |
1445 // This exists to make IMEs more responsive, see http://crbug.com/115920 | 1444 // This exists to make IMEs more responsive, see http://crbug.com/115920 |
1446 TRACE_EVENT0("browser", | 1445 TRACE_EVENT0("browser", |
1447 "RenderWidgetHostViewMac::GetFirstRectForCharacterRange"); | 1446 "RenderWidgetHostViewMac::GetFirstRectForCharacterRange"); |
1448 | 1447 |
1449 const gfx::Range requested_range(range); | |
1450 // If requested range is same as caret location, we can just return it. | 1448 // If requested range is same as caret location, we can just return it. |
1451 if (selection_range_.is_empty() && requested_range == selection_range_) { | 1449 if (selection_range_.is_empty() && gfx::Range(range) == selection_range_) { |
1452 if (actual_range) | 1450 if (actual_range) |
1453 *actual_range = range; | 1451 *actual_range = range; |
1454 *rect = NSRectFromCGRect(caret_rect_.ToCGRect()); | 1452 *rect = NSRectFromCGRect(caret_rect_.ToCGRect()); |
1455 return true; | 1453 return true; |
1456 } | 1454 } |
1457 | 1455 |
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 | |
1466 const gfx::Range request_range_in_composition = | 1456 const gfx::Range request_range_in_composition = |
1467 ConvertCharacterRangeToCompositionRange(requested_range); | 1457 ConvertCharacterRangeToCompositionRange(gfx::Range(range)); |
1468 if (request_range_in_composition == gfx::Range::InvalidRange()) | 1458 if (request_range_in_composition == gfx::Range::InvalidRange()) |
1469 return false; | 1459 return false; |
1470 | 1460 |
1471 // If firstRectForCharacterRange in WebFrame is failed in renderer, | 1461 // If firstRectForCharacterRange in WebFrame is failed in renderer, |
1472 // ImeCompositionRangeChanged will be sent with empty vector. | 1462 // ImeCompositionRangeChanged will be sent with empty vector. |
1473 if (composition_bounds_.empty()) | 1463 if (composition_bounds_.empty()) |
1474 return false; | 1464 return false; |
1475 DCHECK_EQ(composition_bounds_.size(), composition_range_.length()); | 1465 DCHECK_EQ(composition_bounds_.size(), composition_range_.length()); |
1476 | 1466 |
1477 gfx::Range ui_actual_range; | 1467 gfx::Range ui_actual_range; |
(...skipping 1412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2890 // there. (When this method returns an empty range, the input method doesn't | 2880 // there. (When this method returns an empty range, the input method doesn't |
2891 // call the setMarkedText method.) | 2881 // call the setMarkedText method.) |
2892 return hasMarkedText_ ? markedRange_ : NSMakeRange(NSNotFound, 0); | 2882 return hasMarkedText_ ? markedRange_ : NSMakeRange(NSNotFound, 0); |
2893 } | 2883 } |
2894 | 2884 |
2895 - (NSAttributedString*)attributedSubstringForProposedRange:(NSRange)range | 2885 - (NSAttributedString*)attributedSubstringForProposedRange:(NSRange)range |
2896 actualRange:(NSRangePointer)actualRange { | 2886 actualRange:(NSRangePointer)actualRange { |
2897 // TODO(thakis): Pipe |actualRange| through TextInputClientMac machinery. | 2887 // TODO(thakis): Pipe |actualRange| through TextInputClientMac machinery. |
2898 if (actualRange) | 2888 if (actualRange) |
2899 *actualRange = range; | 2889 *actualRange = range; |
2900 | 2890 NSAttributedString* str = |
2901 const gfx::Range requested_range(range); | 2891 TextInputClientMac::GetInstance()->GetAttributedSubstringFromRange( |
2902 if (requested_range.is_reversed()) | 2892 renderWidgetHostView_->render_widget_host_, range); |
2903 return nil; | 2893 return str; |
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]; | |
2930 } | 2894 } |
2931 | 2895 |
2932 - (NSInteger)conversationIdentifier { | 2896 - (NSInteger)conversationIdentifier { |
2933 return reinterpret_cast<NSInteger>(self); | 2897 return reinterpret_cast<NSInteger>(self); |
2934 } | 2898 } |
2935 | 2899 |
2936 // Each RenderWidgetHostViewCocoa has its own input context, but we return | 2900 // Each RenderWidgetHostViewCocoa has its own input context, but we return |
2937 // nil when the caret is in non-editable content or password box to avoid | 2901 // nil when the caret is in non-editable content or password box to avoid |
2938 // making input methods do their work. | 2902 // making input methods do their work. |
2939 - (NSTextInputContext *)inputContext { | 2903 - (NSTextInputContext *)inputContext { |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3351 | 3315 |
3352 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3316 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
3353 // regions that are not draggable. (See ControlRegionView in | 3317 // regions that are not draggable. (See ControlRegionView in |
3354 // native_app_window_cocoa.mm). This requires the render host view to be | 3318 // native_app_window_cocoa.mm). This requires the render host view to be |
3355 // draggable by default. | 3319 // draggable by default. |
3356 - (BOOL)mouseDownCanMoveWindow { | 3320 - (BOOL)mouseDownCanMoveWindow { |
3357 return YES; | 3321 return YES; |
3358 } | 3322 } |
3359 | 3323 |
3360 @end | 3324 @end |
OLD | NEW |