Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_mac.mm

Issue 2213503002: Tracking SelectionBounds for all RenderWidgets on the Browser Side (Mac) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 void RenderWidgetHostViewMac::StopSpeaking() { 1051 void RenderWidgetHostViewMac::StopSpeaking() {
1052 if ([NSApp respondsToSelector:@selector(stopSpeaking:)]) 1052 if ([NSApp respondsToSelector:@selector(stopSpeaking:)])
1053 [NSApp stopSpeaking:cocoa_view_]; 1053 [NSApp stopSpeaking:cocoa_view_];
1054 } 1054 }
1055 1055
1056 // 1056 //
1057 // RenderWidgetHostViewCocoa uses the stored selection text, 1057 // RenderWidgetHostViewCocoa uses the stored selection text,
1058 // which implements NSServicesRequests protocol. 1058 // which implements NSServicesRequests protocol.
1059 // 1059 //
1060 1060
1061 void RenderWidgetHostViewMac::SelectionBoundsChanged(
1062 const ViewHostMsg_SelectionBounds_Params& params) {
1063 if (params.anchor_rect == params.focus_rect)
1064 caret_rect_ = params.anchor_rect;
1065 first_selection_rect_ = params.anchor_rect;
1066 }
1067
1068 void RenderWidgetHostViewMac::SetShowingContextMenu(bool showing) { 1061 void RenderWidgetHostViewMac::SetShowingContextMenu(bool showing) {
1069 RenderWidgetHostViewBase::SetShowingContextMenu(showing); 1062 RenderWidgetHostViewBase::SetShowingContextMenu(showing);
1070 1063
1071 // Create a fake mouse event to inform the render widget that the mouse 1064 // Create a fake mouse event to inform the render widget that the mouse
1072 // left or entered. 1065 // left or entered.
1073 NSWindow* window = [cocoa_view_ window]; 1066 NSWindow* window = [cocoa_view_ window];
1074 // TODO(asvitkine): If the location outside of the event stream doesn't 1067 // TODO(asvitkine): If the location outside of the event stream doesn't
1075 // correspond to the current event (due to delayed event processing), then 1068 // correspond to the current event (due to delayed event processing), then
1076 // this may result in a cursor flicker if there are later mouse move events 1069 // this may result in a cursor flicker if there are later mouse move events
1077 // in the pipeline. Find a way to use the mouse location from the event that 1070 // 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
1243 1236
1244 WebContents* RenderWidgetHostViewMac::GetWebContents() { 1237 WebContents* RenderWidgetHostViewMac::GetWebContents() {
1245 return WebContents::FromRenderViewHost( 1238 return WebContents::FromRenderViewHost(
1246 RenderViewHost::From(render_widget_host_)); 1239 RenderViewHost::From(render_widget_host_));
1247 } 1240 }
1248 1241
1249 bool RenderWidgetHostViewMac::GetCachedFirstRectForCharacterRange( 1242 bool RenderWidgetHostViewMac::GetCachedFirstRectForCharacterRange(
1250 NSRange range, 1243 NSRange range,
1251 NSRect* rect, 1244 NSRect* rect,
1252 NSRange* actual_range) { 1245 NSRange* actual_range) {
1246 if (!GetTextInputManager())
1247 return false;
1248
1253 DCHECK(rect); 1249 DCHECK(rect);
1254 // This exists to make IMEs more responsive, see http://crbug.com/115920 1250 // This exists to make IMEs more responsive, see http://crbug.com/115920
1255 TRACE_EVENT0("browser", 1251 TRACE_EVENT0("browser",
1256 "RenderWidgetHostViewMac::GetFirstRectForCharacterRange"); 1252 "RenderWidgetHostViewMac::GetFirstRectForCharacterRange");
1257 1253
1258 const gfx::Range requested_range(range); 1254 const gfx::Range requested_range(range);
1259 // If requested range is same as caret location, we can just return it. 1255 // If requested range is same as caret location, we can just return it.
1260 if (selection_range_.is_empty() && requested_range == selection_range_) { 1256 if (selection_range_.is_empty() && requested_range == selection_range_) {
1257 DCHECK(GetFocusedWidget());
1261 if (actual_range) 1258 if (actual_range)
1262 *actual_range = range; 1259 *actual_range = range;
1263 *rect = NSRectFromCGRect(caret_rect_.ToCGRect()); 1260 *rect =
1261 NSRectFromCGRect(GetTextInputManager()
1262 ->GetSelectionRegion(GetFocusedWidget()->GetView())
1263 ->caret_rect.ToCGRect());
1264 return true; 1264 return true;
1265 } 1265 }
1266 1266
1267 if (composition_range_.is_empty()) { 1267 if (composition_range_.is_empty()) {
1268 if (!selection_range_.Contains(requested_range)) 1268 if (!selection_range_.Contains(requested_range))
1269 return false; 1269 return false;
1270 DCHECK(GetFocusedWidget());
1270 if (actual_range) 1271 if (actual_range)
1271 *actual_range = selection_range_.ToNSRange(); 1272 *actual_range = selection_range_.ToNSRange();
1272 *rect = NSRectFromCGRect(first_selection_rect_.ToCGRect()); 1273 *rect =
1274 NSRectFromCGRect(GetTextInputManager()
1275 ->GetSelectionRegion(GetFocusedWidget()->GetView())
1276 ->first_selection_rect.ToCGRect());
1273 return true; 1277 return true;
1274 } 1278 }
1275 1279
1276 const gfx::Range request_range_in_composition = 1280 const gfx::Range request_range_in_composition =
1277 ConvertCharacterRangeToCompositionRange(requested_range); 1281 ConvertCharacterRangeToCompositionRange(requested_range);
1278 if (request_range_in_composition == gfx::Range::InvalidRange()) 1282 if (request_range_in_composition == gfx::Range::InvalidRange())
1279 return false; 1283 return false;
1280 1284
1281 // If firstRectForCharacterRange in WebFrame is failed in renderer, 1285 // If firstRectForCharacterRange in WebFrame is failed in renderer,
1282 // ImeCompositionRangeChanged will be sent with empty vector. 1286 // ImeCompositionRangeChanged will be sent with empty vector.
(...skipping 1529 matching lines...) Expand 10 before | Expand all | Expand 10 after
2812 } 2816 }
2813 2817
2814 - (NSRect)firstViewRectForCharacterRange:(NSRange)theRange 2818 - (NSRect)firstViewRectForCharacterRange:(NSRange)theRange
2815 actualRange:(NSRangePointer)actualRange { 2819 actualRange:(NSRangePointer)actualRange {
2816 NSRect rect; 2820 NSRect rect;
2817 if (!renderWidgetHostView_->GetCachedFirstRectForCharacterRange( 2821 if (!renderWidgetHostView_->GetCachedFirstRectForCharacterRange(
2818 theRange, 2822 theRange,
2819 &rect, 2823 &rect,
2820 actualRange)) { 2824 actualRange)) {
2821 rect = TextInputClientMac::GetInstance()->GetFirstRectForRange( 2825 rect = TextInputClientMac::GetInstance()->GetFirstRectForRange(
2822 renderWidgetHostView_->render_widget_host_, theRange); 2826 renderWidgetHostView_->GetFocusedWidget(), theRange);
2823 2827
2824 // TODO(thakis): Pipe |actualRange| through TextInputClientMac machinery. 2828 // TODO(thakis): Pipe |actualRange| through TextInputClientMac machinery.
2825 if (actualRange) 2829 if (actualRange)
2826 *actualRange = theRange; 2830 *actualRange = theRange;
2827 } 2831 }
2828 2832
2829 // The returned rectangle is in WebKit coordinates (upper left origin), so 2833 // The returned rectangle is in WebKit coordinates (upper left origin), so
2830 // flip the coordinate system. 2834 // flip the coordinate system.
2831 NSRect viewFrame = [self frame]; 2835 NSRect viewFrame = [self frame];
2832 rect.origin.y = NSHeight(viewFrame) - NSMaxY(rect); 2836 rect.origin.y = NSHeight(viewFrame) - NSMaxY(rect);
2833 return rect; 2837 return rect;
2834 } 2838 }
2835 2839
2836 - (NSRect)firstRectForCharacterRange:(NSRange)theRange 2840 - (NSRect)firstRectForCharacterRange:(NSRange)theRange
2837 actualRange:(NSRangePointer)actualRange { 2841 actualRange:(NSRangePointer)actualRange {
2838 // During tab closure, events can arrive after RenderWidgetHostViewMac:: 2842 // During tab closure, events can arrive after RenderWidgetHostViewMac::
2839 // Destroy() is called, which will have set |render_widget_host_| to null. 2843 // Destroy() is called, which will have set |render_widget_host_| to null.
2840 if (!renderWidgetHostView_->render_widget_host_) { 2844 if (!renderWidgetHostView_->GetFocusedWidget()) {
2841 [self cancelComposition]; 2845 [self cancelComposition];
2842 return NSZeroRect; 2846 return NSZeroRect;
2843 } 2847 }
2844 2848
2845 NSRect rect = [self firstViewRectForCharacterRange:theRange 2849 NSRect rect = [self firstViewRectForCharacterRange:theRange
2846 actualRange:actualRange]; 2850 actualRange:actualRange];
2847 2851
2848 // Convert into screen coordinates for return. 2852 // Convert into screen coordinates for return.
2849 rect = [self convertRect:rect toView:nil]; 2853 rect = [self convertRect:rect toView:nil];
2850 rect = [[self window] convertRectToScreen:rect]; 2854 rect = [[self window] convertRectToScreen:rect];
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
3259 3263
3260 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 3264 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
3261 // regions that are not draggable. (See ControlRegionView in 3265 // regions that are not draggable. (See ControlRegionView in
3262 // native_app_window_cocoa.mm). This requires the render host view to be 3266 // native_app_window_cocoa.mm). This requires the render host view to be
3263 // draggable by default. 3267 // draggable by default.
3264 - (BOOL)mouseDownCanMoveWindow { 3268 - (BOOL)mouseDownCanMoveWindow {
3265 return YES; 3269 return YES;
3266 } 3270 }
3267 3271
3268 @end 3272 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698