| 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 #include <stdint.h> | 10 #include <stdint.h> |
| (...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 } | 561 } |
| 562 | 562 |
| 563 void RenderWidgetHostViewMac::SetAllowPauseForResizeOrRepaint(bool allow) { | 563 void RenderWidgetHostViewMac::SetAllowPauseForResizeOrRepaint(bool allow) { |
| 564 allow_pause_for_resize_or_repaint_ = allow; | 564 allow_pause_for_resize_or_repaint_ = allow; |
| 565 } | 565 } |
| 566 | 566 |
| 567 cc::SurfaceId RenderWidgetHostViewMac::SurfaceIdForTesting() const { | 567 cc::SurfaceId RenderWidgetHostViewMac::SurfaceIdForTesting() const { |
| 568 return browser_compositor_->GetDelegatedFrameHost()->SurfaceIdForTesting(); | 568 return browser_compositor_->GetDelegatedFrameHost()->SurfaceIdForTesting(); |
| 569 } | 569 } |
| 570 | 570 |
| 571 RenderWidgetHostImpl* RenderWidgetHostViewMac::GetActiveWidget() { |
| 572 if (GetTextInputManager() && GetTextInputManager()->GetActiveWidget()) |
| 573 return GetTextInputManager()->GetActiveWidget(); |
| 574 return render_widget_host_; |
| 575 } |
| 576 |
| 571 ui::TextInputType RenderWidgetHostViewMac::GetTextInputType() { | 577 ui::TextInputType RenderWidgetHostViewMac::GetTextInputType() { |
| 572 if (!GetTextInputManager() || !GetTextInputManager()->GetActiveWidget()) | 578 const TextInputState* text_input_state = |
| 579 GetTextInputManager() ? GetTextInputManager()->GetTextInputState() |
| 580 : nullptr; |
| 581 |
| 582 if (!text_input_state) |
| 573 return ui::TEXT_INPUT_TYPE_NONE; | 583 return ui::TEXT_INPUT_TYPE_NONE; |
| 574 return GetTextInputManager()->GetTextInputState()->type; | 584 |
| 585 return text_input_state->type; |
| 575 } | 586 } |
| 576 | 587 |
| 577 /////////////////////////////////////////////////////////////////////////////// | 588 /////////////////////////////////////////////////////////////////////////////// |
| 578 // RenderWidgetHostViewMac, RenderWidgetHostView implementation: | 589 // RenderWidgetHostViewMac, RenderWidgetHostView implementation: |
| 579 | 590 |
| 580 bool RenderWidgetHostViewMac::OnMessageReceived(const IPC::Message& message) { | 591 bool RenderWidgetHostViewMac::OnMessageReceived(const IPC::Message& message) { |
| 581 bool handled = true; | 592 bool handled = true; |
| 582 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewMac, message) | 593 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewMac, message) |
| 583 IPC_MESSAGE_HANDLER(ViewMsg_GetRenderedTextCompleted, | 594 IPC_MESSAGE_HANDLER(ViewMsg_GetRenderedTextCompleted, |
| 584 OnGetRenderedTextCompleted) | 595 OnGetRenderedTextCompleted) |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1055 // Updates markedRange when there is no marked text so that retrieving | 1066 // Updates markedRange when there is no marked text so that retrieving |
| 1056 // markedRange immediately after calling setMarkdText: returns the current | 1067 // markedRange immediately after calling setMarkdText: returns the current |
| 1057 // caret position. | 1068 // caret position. |
| 1058 if (![cocoa_view_ hasMarkedText]) { | 1069 if (![cocoa_view_ hasMarkedText]) { |
| 1059 [cocoa_view_ setMarkedRange:range.ToNSRange()]; | 1070 [cocoa_view_ setMarkedRange:range.ToNSRange()]; |
| 1060 } | 1071 } |
| 1061 | 1072 |
| 1062 RenderWidgetHostViewBase::SelectionChanged(text, offset, range); | 1073 RenderWidgetHostViewBase::SelectionChanged(text, offset, range); |
| 1063 } | 1074 } |
| 1064 | 1075 |
| 1065 void RenderWidgetHostViewMac::SelectionBoundsChanged( | |
| 1066 const ViewHostMsg_SelectionBounds_Params& params) { | |
| 1067 if (params.anchor_rect == params.focus_rect) | |
| 1068 caret_rect_ = params.anchor_rect; | |
| 1069 first_selection_rect_ = params.anchor_rect; | |
| 1070 } | |
| 1071 | |
| 1072 void RenderWidgetHostViewMac::SetShowingContextMenu(bool showing) { | 1076 void RenderWidgetHostViewMac::SetShowingContextMenu(bool showing) { |
| 1073 RenderWidgetHostViewBase::SetShowingContextMenu(showing); | 1077 RenderWidgetHostViewBase::SetShowingContextMenu(showing); |
| 1074 | 1078 |
| 1075 // Create a fake mouse event to inform the render widget that the mouse | 1079 // Create a fake mouse event to inform the render widget that the mouse |
| 1076 // left or entered. | 1080 // left or entered. |
| 1077 NSWindow* window = [cocoa_view_ window]; | 1081 NSWindow* window = [cocoa_view_ window]; |
| 1078 // TODO(asvitkine): If the location outside of the event stream doesn't | 1082 // TODO(asvitkine): If the location outside of the event stream doesn't |
| 1079 // correspond to the current event (due to delayed event processing), then | 1083 // correspond to the current event (due to delayed event processing), then |
| 1080 // this may result in a cursor flicker if there are later mouse move events | 1084 // this may result in a cursor flicker if there are later mouse move events |
| 1081 // in the pipeline. Find a way to use the mouse location from the event that | 1085 // in the pipeline. Find a way to use the mouse location from the event that |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1257 DCHECK(rect); | 1261 DCHECK(rect); |
| 1258 // This exists to make IMEs more responsive, see http://crbug.com/115920 | 1262 // This exists to make IMEs more responsive, see http://crbug.com/115920 |
| 1259 TRACE_EVENT0("browser", | 1263 TRACE_EVENT0("browser", |
| 1260 "RenderWidgetHostViewMac::GetFirstRectForCharacterRange"); | 1264 "RenderWidgetHostViewMac::GetFirstRectForCharacterRange"); |
| 1261 | 1265 |
| 1262 const gfx::Range requested_range(range); | 1266 const gfx::Range requested_range(range); |
| 1263 // If requested range is same as caret location, we can just return it. | 1267 // If requested range is same as caret location, we can just return it. |
| 1264 if (selection_range_.is_empty() && requested_range == selection_range_) { | 1268 if (selection_range_.is_empty() && requested_range == selection_range_) { |
| 1265 if (actual_range) | 1269 if (actual_range) |
| 1266 *actual_range = range; | 1270 *actual_range = range; |
| 1267 *rect = NSRectFromCGRect(caret_rect_.ToCGRect()); | 1271 *rect = NSRectFromCGRect( |
| 1272 GetTextInputManager()->GetCaretRect(GetActiveWidget())->ToCGRect()); |
| 1268 return true; | 1273 return true; |
| 1269 } | 1274 } |
| 1270 | 1275 |
| 1271 if (composition_range_.is_empty()) { | 1276 if (composition_range_.is_empty()) { |
| 1272 if (!selection_range_.Contains(requested_range)) | 1277 if (!selection_range_.Contains(requested_range)) |
| 1273 return false; | 1278 return false; |
| 1274 if (actual_range) | 1279 if (actual_range) |
| 1275 *actual_range = selection_range_.ToNSRange(); | 1280 *actual_range = selection_range_.ToNSRange(); |
| 1276 *rect = NSRectFromCGRect(first_selection_rect_.ToCGRect()); | 1281 *rect = NSRectFromCGRect(GetTextInputManager() |
| 1282 ->GetFirstSelectionRect(GetActiveWidget()) |
| 1283 ->ToCGRect()); |
| 1277 return true; | 1284 return true; |
| 1278 } | 1285 } |
| 1279 | 1286 |
| 1280 const gfx::Range request_range_in_composition = | 1287 const gfx::Range request_range_in_composition = |
| 1281 ConvertCharacterRangeToCompositionRange(requested_range); | 1288 ConvertCharacterRangeToCompositionRange(requested_range); |
| 1282 if (request_range_in_composition == gfx::Range::InvalidRange()) | 1289 if (request_range_in_composition == gfx::Range::InvalidRange()) |
| 1283 return false; | 1290 return false; |
| 1284 | 1291 |
| 1285 // If firstRectForCharacterRange in WebFrame is failed in renderer, | 1292 // If firstRectForCharacterRange in WebFrame is failed in renderer, |
| 1286 // ImeCompositionRangeChanged will be sent with empty vector. | 1293 // ImeCompositionRangeChanged will be sent with empty vector. |
| (...skipping 1532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2819 } | 2826 } |
| 2820 | 2827 |
| 2821 - (NSRect)firstViewRectForCharacterRange:(NSRange)theRange | 2828 - (NSRect)firstViewRectForCharacterRange:(NSRange)theRange |
| 2822 actualRange:(NSRangePointer)actualRange { | 2829 actualRange:(NSRangePointer)actualRange { |
| 2823 NSRect rect; | 2830 NSRect rect; |
| 2824 if (!renderWidgetHostView_->GetCachedFirstRectForCharacterRange( | 2831 if (!renderWidgetHostView_->GetCachedFirstRectForCharacterRange( |
| 2825 theRange, | 2832 theRange, |
| 2826 &rect, | 2833 &rect, |
| 2827 actualRange)) { | 2834 actualRange)) { |
| 2828 rect = TextInputClientMac::GetInstance()->GetFirstRectForRange( | 2835 rect = TextInputClientMac::GetInstance()->GetFirstRectForRange( |
| 2829 renderWidgetHostView_->render_widget_host_, theRange); | 2836 renderWidgetHostView_->GetActiveWidget(), theRange); |
| 2830 | 2837 |
| 2831 // TODO(thakis): Pipe |actualRange| through TextInputClientMac machinery. | 2838 // TODO(thakis): Pipe |actualRange| through TextInputClientMac machinery. |
| 2832 if (actualRange) | 2839 if (actualRange) |
| 2833 *actualRange = theRange; | 2840 *actualRange = theRange; |
| 2834 } | 2841 } |
| 2835 | 2842 |
| 2836 // The returned rectangle is in WebKit coordinates (upper left origin), so | 2843 // The returned rectangle is in WebKit coordinates (upper left origin), so |
| 2837 // flip the coordinate system. | 2844 // flip the coordinate system. |
| 2838 NSRect viewFrame = [self frame]; | 2845 NSRect viewFrame = [self frame]; |
| 2839 rect.origin.y = NSHeight(viewFrame) - NSMaxY(rect); | 2846 rect.origin.y = NSHeight(viewFrame) - NSMaxY(rect); |
| 2840 return rect; | 2847 return rect; |
| 2841 } | 2848 } |
| 2842 | 2849 |
| 2843 - (NSRect)firstRectForCharacterRange:(NSRange)theRange | 2850 - (NSRect)firstRectForCharacterRange:(NSRange)theRange |
| 2844 actualRange:(NSRangePointer)actualRange { | 2851 actualRange:(NSRangePointer)actualRange { |
| 2845 // During tab closure, events can arrive after RenderWidgetHostViewMac:: | 2852 // During tab closure, events can arrive after RenderWidgetHostViewMac:: |
| 2846 // Destroy() is called, which will have set |render_widget_host_| to null. | 2853 // Destroy() is called, which will have set |render_widget_host_| to null. |
| 2847 if (!renderWidgetHostView_->render_widget_host_) { | 2854 if (!renderWidgetHostView_->GetActiveWidget()) { |
| 2848 [self cancelComposition]; | 2855 [self cancelComposition]; |
| 2849 return NSZeroRect; | 2856 return NSZeroRect; |
| 2850 } | 2857 } |
| 2851 | 2858 |
| 2852 NSRect rect = [self firstViewRectForCharacterRange:theRange | 2859 NSRect rect = [self firstViewRectForCharacterRange:theRange |
| 2853 actualRange:actualRange]; | 2860 actualRange:actualRange]; |
| 2854 | 2861 |
| 2855 // Convert into screen coordinates for return. | 2862 // Convert into screen coordinates for return. |
| 2856 rect = [self convertRect:rect toView:nil]; | 2863 rect = [self convertRect:rect toView:nil]; |
| 2857 rect = [[self window] convertRectToScreen:rect]; | 2864 rect = [[self window] convertRectToScreen:rect]; |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3259 | 3266 |
| 3260 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3267 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
| 3261 // regions that are not draggable. (See ControlRegionView in | 3268 // regions that are not draggable. (See ControlRegionView in |
| 3262 // native_app_window_cocoa.mm). This requires the render host view to be | 3269 // native_app_window_cocoa.mm). This requires the render host view to be |
| 3263 // draggable by default. | 3270 // draggable by default. |
| 3264 - (BOOL)mouseDownCanMoveWindow { | 3271 - (BOOL)mouseDownCanMoveWindow { |
| 3265 return YES; | 3272 return YES; |
| 3266 } | 3273 } |
| 3267 | 3274 |
| 3268 @end | 3275 @end |
| OLD | NEW |