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 #include <stdint.h> | 10 #include <stdint.h> |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 536 | 536 |
| 537 void RenderWidgetHostViewMac::SetAllowPauseForResizeOrRepaint(bool allow) { | 537 void RenderWidgetHostViewMac::SetAllowPauseForResizeOrRepaint(bool allow) { |
| 538 allow_pause_for_resize_or_repaint_ = allow; | 538 allow_pause_for_resize_or_repaint_ = allow; |
| 539 } | 539 } |
| 540 | 540 |
| 541 cc::SurfaceId RenderWidgetHostViewMac::SurfaceIdForTesting() const { | 541 cc::SurfaceId RenderWidgetHostViewMac::SurfaceIdForTesting() const { |
| 542 return browser_compositor_->GetDelegatedFrameHost()->SurfaceIdForTesting(); | 542 return browser_compositor_->GetDelegatedFrameHost()->SurfaceIdForTesting(); |
| 543 } | 543 } |
| 544 | 544 |
| 545 ui::TextInputType RenderWidgetHostViewMac::GetTextInputType() { | 545 ui::TextInputType RenderWidgetHostViewMac::GetTextInputType() { |
| 546 if (!GetTextInputManager() || !GetTextInputManager()->GetActiveWidget()) | 546 if (!GetActiveWidget()) |
| 547 return ui::TEXT_INPUT_TYPE_NONE; | 547 return ui::TEXT_INPUT_TYPE_NONE; |
| 548 return GetTextInputManager()->GetTextInputState()->type; | 548 return GetTextInputManager()->GetTextInputState()->type; |
| 549 } | 549 } |
| 550 | 550 |
| 551 RenderWidgetHostImpl* RenderWidgetHostViewMac::GetActiveWidget() { | 551 RenderWidgetHostImpl* RenderWidgetHostViewMac::GetActiveWidget() { |
| 552 return GetTextInputManager() ? GetTextInputManager()->GetActiveWidget() | 552 return GetTextInputManager() ? GetTextInputManager()->GetActiveWidget() |
| 553 : nullptr; | 553 : nullptr; |
| 554 } | 554 } |
| 555 | 555 |
| 556 /////////////////////////////////////////////////////////////////////////////// | 556 /////////////////////////////////////////////////////////////////////////////// |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1038 // Updates markedRange when there is no marked text so that retrieving | 1038 // Updates markedRange when there is no marked text so that retrieving |
| 1039 // markedRange immediately after calling setMarkdText: returns the current | 1039 // markedRange immediately after calling setMarkdText: returns the current |
| 1040 // caret position. | 1040 // caret position. |
| 1041 if (![cocoa_view_ hasMarkedText]) { | 1041 if (![cocoa_view_ hasMarkedText]) { |
| 1042 [cocoa_view_ setMarkedRange:range.ToNSRange()]; | 1042 [cocoa_view_ setMarkedRange:range.ToNSRange()]; |
| 1043 } | 1043 } |
| 1044 | 1044 |
| 1045 RenderWidgetHostViewBase::SelectionChanged(text, offset, range); | 1045 RenderWidgetHostViewBase::SelectionChanged(text, offset, range); |
| 1046 } | 1046 } |
| 1047 | 1047 |
| 1048 void RenderWidgetHostViewMac::SelectionBoundsChanged( | |
| 1049 const ViewHostMsg_SelectionBounds_Params& params) { | |
| 1050 if (params.anchor_rect == params.focus_rect) | |
| 1051 caret_rect_ = params.anchor_rect; | |
| 1052 first_selection_rect_ = params.anchor_rect; | |
| 1053 } | |
| 1054 | |
| 1055 void RenderWidgetHostViewMac::SetShowingContextMenu(bool showing) { | 1048 void RenderWidgetHostViewMac::SetShowingContextMenu(bool showing) { |
| 1056 RenderWidgetHostViewBase::SetShowingContextMenu(showing); | 1049 RenderWidgetHostViewBase::SetShowingContextMenu(showing); |
| 1057 | 1050 |
| 1058 // Create a fake mouse event to inform the render widget that the mouse | 1051 // Create a fake mouse event to inform the render widget that the mouse |
| 1059 // left or entered. | 1052 // left or entered. |
| 1060 NSWindow* window = [cocoa_view_ window]; | 1053 NSWindow* window = [cocoa_view_ window]; |
| 1061 // TODO(asvitkine): If the location outside of the event stream doesn't | 1054 // TODO(asvitkine): If the location outside of the event stream doesn't |
| 1062 // correspond to the current event (due to delayed event processing), then | 1055 // correspond to the current event (due to delayed event processing), then |
| 1063 // this may result in a cursor flicker if there are later mouse move events | 1056 // this may result in a cursor flicker if there are later mouse move events |
| 1064 // in the pipeline. Find a way to use the mouse location from the event that | 1057 // in the pipeline. Find a way to use the mouse location from the event that |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1230 | 1223 |
| 1231 WebContents* RenderWidgetHostViewMac::GetWebContents() { | 1224 WebContents* RenderWidgetHostViewMac::GetWebContents() { |
| 1232 return WebContents::FromRenderViewHost( | 1225 return WebContents::FromRenderViewHost( |
| 1233 RenderViewHost::From(render_widget_host_)); | 1226 RenderViewHost::From(render_widget_host_)); |
| 1234 } | 1227 } |
| 1235 | 1228 |
| 1236 bool RenderWidgetHostViewMac::GetCachedFirstRectForCharacterRange( | 1229 bool RenderWidgetHostViewMac::GetCachedFirstRectForCharacterRange( |
| 1237 NSRange range, | 1230 NSRange range, |
| 1238 NSRect* rect, | 1231 NSRect* rect, |
| 1239 NSRange* actual_range) { | 1232 NSRange* actual_range) { |
| 1233 if (!GetTextInputManager()) | |
| 1234 return false; | |
| 1235 | |
| 1240 DCHECK(rect); | 1236 DCHECK(rect); |
| 1241 // This exists to make IMEs more responsive, see http://crbug.com/115920 | 1237 // This exists to make IMEs more responsive, see http://crbug.com/115920 |
| 1242 TRACE_EVENT0("browser", | 1238 TRACE_EVENT0("browser", |
| 1243 "RenderWidgetHostViewMac::GetFirstRectForCharacterRange"); | 1239 "RenderWidgetHostViewMac::GetFirstRectForCharacterRange"); |
| 1244 | 1240 |
| 1245 const gfx::Range requested_range(range); | 1241 const gfx::Range requested_range(range); |
| 1246 // If requested range is same as caret location, we can just return it. | 1242 // If requested range is same as caret location, we can just return it. |
| 1247 if (selection_range_.is_empty() && requested_range == selection_range_) { | 1243 if (selection_range_.is_empty() && requested_range == selection_range_) { |
| 1248 if (actual_range) | 1244 if (actual_range) |
| 1249 *actual_range = range; | 1245 *actual_range = range; |
| 1250 *rect = NSRectFromCGRect(caret_rect_.ToCGRect()); | 1246 *rect = |
| 1247 NSRectFromCGRect(GetTextInputManager() | |
| 1248 ->GetSelectionRegion(GetFocusedWidget()->GetView()) | |
|
erikchen
2016/08/17 23:31:16
This relies on the assumption that GetFocusedWidge
EhsanK
2016/08/22 14:48:28
Done. I strongly believe that is the case since th
| |
| 1249 ->caret_rect.ToCGRect()); | |
| 1251 return true; | 1250 return true; |
| 1252 } | 1251 } |
| 1253 | 1252 |
| 1254 if (composition_range_.is_empty()) { | 1253 if (composition_range_.is_empty()) { |
| 1255 if (!selection_range_.Contains(requested_range)) | 1254 if (!selection_range_.Contains(requested_range)) |
| 1256 return false; | 1255 return false; |
| 1257 if (actual_range) | 1256 if (actual_range) |
| 1258 *actual_range = selection_range_.ToNSRange(); | 1257 *actual_range = selection_range_.ToNSRange(); |
| 1259 *rect = NSRectFromCGRect(first_selection_rect_.ToCGRect()); | 1258 *rect = |
| 1259 NSRectFromCGRect(GetTextInputManager() | |
| 1260 ->GetSelectionRegion(GetFocusedWidget()->GetView()) | |
| 1261 ->first_selection_rect.ToCGRect()); | |
| 1260 return true; | 1262 return true; |
| 1261 } | 1263 } |
| 1262 | 1264 |
| 1263 const gfx::Range request_range_in_composition = | 1265 const gfx::Range request_range_in_composition = |
| 1264 ConvertCharacterRangeToCompositionRange(requested_range); | 1266 ConvertCharacterRangeToCompositionRange(requested_range); |
| 1265 if (request_range_in_composition == gfx::Range::InvalidRange()) | 1267 if (request_range_in_composition == gfx::Range::InvalidRange()) |
| 1266 return false; | 1268 return false; |
| 1267 | 1269 |
| 1268 // If firstRectForCharacterRange in WebFrame is failed in renderer, | 1270 // If firstRectForCharacterRange in WebFrame is failed in renderer, |
| 1269 // ImeCompositionRangeChanged will be sent with empty vector. | 1271 // ImeCompositionRangeChanged will be sent with empty vector. |
| (...skipping 1529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2799 } | 2801 } |
| 2800 | 2802 |
| 2801 - (NSRect)firstViewRectForCharacterRange:(NSRange)theRange | 2803 - (NSRect)firstViewRectForCharacterRange:(NSRange)theRange |
| 2802 actualRange:(NSRangePointer)actualRange { | 2804 actualRange:(NSRangePointer)actualRange { |
| 2803 NSRect rect; | 2805 NSRect rect; |
| 2804 if (!renderWidgetHostView_->GetCachedFirstRectForCharacterRange( | 2806 if (!renderWidgetHostView_->GetCachedFirstRectForCharacterRange( |
| 2805 theRange, | 2807 theRange, |
| 2806 &rect, | 2808 &rect, |
| 2807 actualRange)) { | 2809 actualRange)) { |
| 2808 rect = TextInputClientMac::GetInstance()->GetFirstRectForRange( | 2810 rect = TextInputClientMac::GetInstance()->GetFirstRectForRange( |
| 2809 renderWidgetHostView_->render_widget_host_, theRange); | 2811 renderWidgetHostView_->GetFocusedWidget(), theRange); |
| 2810 | 2812 |
| 2811 // TODO(thakis): Pipe |actualRange| through TextInputClientMac machinery. | 2813 // TODO(thakis): Pipe |actualRange| through TextInputClientMac machinery. |
| 2812 if (actualRange) | 2814 if (actualRange) |
| 2813 *actualRange = theRange; | 2815 *actualRange = theRange; |
| 2814 } | 2816 } |
| 2815 | 2817 |
| 2816 // The returned rectangle is in WebKit coordinates (upper left origin), so | 2818 // The returned rectangle is in WebKit coordinates (upper left origin), so |
| 2817 // flip the coordinate system. | 2819 // flip the coordinate system. |
| 2818 NSRect viewFrame = [self frame]; | 2820 NSRect viewFrame = [self frame]; |
| 2819 rect.origin.y = NSHeight(viewFrame) - NSMaxY(rect); | 2821 rect.origin.y = NSHeight(viewFrame) - NSMaxY(rect); |
| 2820 return rect; | 2822 return rect; |
| 2821 } | 2823 } |
| 2822 | 2824 |
| 2823 - (NSRect)firstRectForCharacterRange:(NSRange)theRange | 2825 - (NSRect)firstRectForCharacterRange:(NSRange)theRange |
| 2824 actualRange:(NSRangePointer)actualRange { | 2826 actualRange:(NSRangePointer)actualRange { |
| 2825 // During tab closure, events can arrive after RenderWidgetHostViewMac:: | 2827 // During tab closure, events can arrive after RenderWidgetHostViewMac:: |
| 2826 // Destroy() is called, which will have set |render_widget_host_| to null. | 2828 // Destroy() is called, which will have set |render_widget_host_| to null. |
| 2827 if (!renderWidgetHostView_->render_widget_host_) { | 2829 if (!renderWidgetHostView_->GetFocusedWidget()) { |
| 2828 [self cancelComposition]; | 2830 [self cancelComposition]; |
| 2829 return NSZeroRect; | 2831 return NSZeroRect; |
| 2830 } | 2832 } |
| 2831 | 2833 |
| 2832 NSRect rect = [self firstViewRectForCharacterRange:theRange | 2834 NSRect rect = [self firstViewRectForCharacterRange:theRange |
| 2833 actualRange:actualRange]; | 2835 actualRange:actualRange]; |
| 2834 | 2836 |
| 2835 // Convert into screen coordinates for return. | 2837 // Convert into screen coordinates for return. |
| 2836 rect = [self convertRect:rect toView:nil]; | 2838 rect = [self convertRect:rect toView:nil]; |
| 2837 rect = [[self window] convertRectToScreen:rect]; | 2839 rect = [[self window] convertRectToScreen:rect]; |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3246 | 3248 |
| 3247 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3249 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
| 3248 // regions that are not draggable. (See ControlRegionView in | 3250 // regions that are not draggable. (See ControlRegionView in |
| 3249 // native_app_window_cocoa.mm). This requires the render host view to be | 3251 // native_app_window_cocoa.mm). This requires the render host view to be |
| 3250 // draggable by default. | 3252 // draggable by default. |
| 3251 - (BOOL)mouseDownCanMoveWindow { | 3253 - (BOOL)mouseDownCanMoveWindow { |
| 3252 return YES; | 3254 return YES; |
| 3253 } | 3255 } |
| 3254 | 3256 |
| 3255 @end | 3257 @end |
| OLD | NEW |