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

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

Issue 1255483004: Implement surface-based browser process hit testing for Mac and Aura (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments addressed Created 5 years, 3 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 10
(...skipping 21 matching lines...) Expand all
32 #import "content/browser/cocoa/system_hotkey_helper_mac.h" 32 #import "content/browser/cocoa/system_hotkey_helper_mac.h"
33 #import "content/browser/cocoa/system_hotkey_map.h" 33 #import "content/browser/cocoa/system_hotkey_map.h"
34 #include "content/browser/compositor/resize_lock.h" 34 #include "content/browser/compositor/resize_lock.h"
35 #include "content/browser/frame_host/frame_tree.h" 35 #include "content/browser/frame_host/frame_tree.h"
36 #include "content/browser/frame_host/frame_tree_node.h" 36 #include "content/browser/frame_host/frame_tree_node.h"
37 #include "content/browser/frame_host/render_frame_host_impl.h" 37 #include "content/browser/frame_host/render_frame_host_impl.h"
38 #include "content/browser/gpu/compositor_util.h" 38 #include "content/browser/gpu/compositor_util.h"
39 #include "content/browser/renderer_host/render_view_host_impl.h" 39 #include "content/browser/renderer_host/render_view_host_impl.h"
40 #include "content/browser/renderer_host/render_widget_helper.h" 40 #include "content/browser/renderer_host/render_widget_helper.h"
41 #include "content/browser/renderer_host/render_widget_host_delegate.h" 41 #include "content/browser/renderer_host/render_widget_host_delegate.h"
42 #include "content/browser/renderer_host/render_widget_host_input_event_router.h"
42 #import "content/browser/renderer_host/render_widget_host_view_mac_dictionary_he lper.h" 43 #import "content/browser/renderer_host/render_widget_host_view_mac_dictionary_he lper.h"
43 #import "content/browser/renderer_host/render_widget_host_view_mac_editcommand_h elper.h" 44 #import "content/browser/renderer_host/render_widget_host_view_mac_editcommand_h elper.h"
44 #include "content/browser/renderer_host/render_widget_resize_helper.h" 45 #include "content/browser/renderer_host/render_widget_resize_helper.h"
45 #import "content/browser/renderer_host/text_input_client_mac.h" 46 #import "content/browser/renderer_host/text_input_client_mac.h"
46 #include "content/common/accessibility_messages.h" 47 #include "content/common/accessibility_messages.h"
47 #include "content/common/edit_command.h" 48 #include "content/common/edit_command.h"
48 #include "content/common/gpu/gpu_messages.h" 49 #include "content/common/gpu/gpu_messages.h"
49 #include "content/common/input_messages.h" 50 #include "content/common/input_messages.h"
50 #include "content/common/view_messages.h" 51 #include "content/common/view_messages.h"
51 #include "content/common/webplugin_geometry.h" 52 #include "content/common/webplugin_geometry.h"
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 592
592 if (IsDelegatedRendererEnabled()) { 593 if (IsDelegatedRendererEnabled()) {
593 root_layer_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); 594 root_layer_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR));
594 delegated_frame_host_.reset(new DelegatedFrameHost(this)); 595 delegated_frame_host_.reset(new DelegatedFrameHost(this));
595 } 596 }
596 597
597 gfx::Screen::GetScreenFor(cocoa_view_)->AddObserver(this); 598 gfx::Screen::GetScreenFor(cocoa_view_)->AddObserver(this);
598 599
599 if (!is_guest_view_hack_) 600 if (!is_guest_view_hack_)
600 render_widget_host_->SetView(this); 601 render_widget_host_->SetView(this);
602
603 // Let the page-level input event router know about our surface ID
604 // namespace for surface-based hit testing.
605 if (UseSurfacesEnabled() &&
606 render_widget_host_->delegate()->GetInputEventRouter()) {
607 render_widget_host_->delegate()
608 ->GetInputEventRouter()
609 ->AddSurfaceIdNamespaceOwner(GetSurfaceIdNamespace(), this);
610 }
601 } 611 }
602 612
603 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { 613 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() {
604 gfx::Screen::GetScreenFor(cocoa_view_)->RemoveObserver(this); 614 gfx::Screen::GetScreenFor(cocoa_view_)->RemoveObserver(this);
605 615
606 // This is being called from |cocoa_view_|'s destructor, so invalidate the 616 // This is being called from |cocoa_view_|'s destructor, so invalidate the
607 // pointer. 617 // pointer.
608 cocoa_view_ = nil; 618 cocoa_view_ = nil;
609 619
610 UnlockMouse(); 620 UnlockMouse();
611 621
622 if (UseSurfacesEnabled() && render_widget_host_ &&
623 render_widget_host_->delegate()->GetInputEventRouter()) {
624 render_widget_host_->delegate()
625 ->GetInputEventRouter()
626 ->RemoveSurfaceIdNamespaceOwner(GetSurfaceIdNamespace());
627 }
628
612 // Ensure that the browser compositor is destroyed in a safe order. 629 // Ensure that the browser compositor is destroyed in a safe order.
613 ShutdownBrowserCompositor(); 630 ShutdownBrowserCompositor();
614 631
615 // We are owned by RenderWidgetHostViewCocoa, so if we go away before the 632 // We are owned by RenderWidgetHostViewCocoa, so if we go away before the
616 // RenderWidgetHost does we need to tell it not to hold a stale pointer to 633 // RenderWidgetHost does we need to tell it not to hold a stale pointer to
617 // us. 634 // us.
618 if (render_widget_host_) { 635 if (render_widget_host_) {
619 // If this is a RenderWidgetHostViewGuest's platform_view_, we're not the 636 // If this is a RenderWidgetHostViewGuest's platform_view_, we're not the
620 // RWH's view, the RenderWidgetHostViewGuest is. So don't reset the RWH's 637 // RWH's view, the RenderWidgetHostViewGuest is. So don't reset the RWH's
621 // view, the RenderWidgetHostViewGuest will do it. 638 // view, the RenderWidgetHostViewGuest will do it.
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 composition_range_ = range; 1107 composition_range_ = range;
1091 composition_bounds_ = character_bounds; 1108 composition_bounds_ = character_bounds;
1092 } 1109 }
1093 1110
1094 void RenderWidgetHostViewMac::RenderProcessGone(base::TerminationStatus status, 1111 void RenderWidgetHostViewMac::RenderProcessGone(base::TerminationStatus status,
1095 int error_code) { 1112 int error_code) {
1096 Destroy(); 1113 Destroy();
1097 } 1114 }
1098 1115
1099 void RenderWidgetHostViewMac::RenderWidgetHostGone() { 1116 void RenderWidgetHostViewMac::RenderWidgetHostGone() {
1117 // Clear SurfaceID namespace ownership before we shutdown the
1118 // compositor.
1119 if (UseSurfacesEnabled() && render_widget_host_ &&
1120 render_widget_host_->delegate()->GetInputEventRouter()) {
1121 render_widget_host_->delegate()
1122 ->GetInputEventRouter()
1123 ->RemoveSurfaceIdNamespaceOwner(GetSurfaceIdNamespace());
1124 }
1125
1100 // Destroy the DelegatedFrameHost, to prevent crashes when Destroy is never 1126 // Destroy the DelegatedFrameHost, to prevent crashes when Destroy is never
1101 // called on the view. 1127 // called on the view.
1102 // http://crbug.com/404828 1128 // http://crbug.com/404828
1103 ShutdownBrowserCompositor(); 1129 ShutdownBrowserCompositor();
1104 } 1130 }
1105 1131
1106 void RenderWidgetHostViewMac::Destroy() { 1132 void RenderWidgetHostViewMac::Destroy() {
1107 [[NSNotificationCenter defaultCenter] 1133 [[NSNotificationCenter defaultCenter]
1108 removeObserver:cocoa_view_ 1134 removeObserver:cocoa_view_
1109 name:NSWindowWillCloseNotification 1135 name:NSWindowWillCloseNotification
1110 object:popup_window_]; 1136 object:popup_window_];
1111 1137
1112 // We've been told to destroy. 1138 // We've been told to destroy.
1113 [cocoa_view_ retain]; 1139 [cocoa_view_ retain];
1114 [cocoa_view_ removeFromSuperview]; 1140 [cocoa_view_ removeFromSuperview];
1115 [cocoa_view_ autorelease]; 1141 [cocoa_view_ autorelease];
1116 1142
1117 [popup_window_ close]; 1143 [popup_window_ close];
1118 popup_window_.autorelease(); 1144 popup_window_.autorelease();
1119 1145
1120 [fullscreen_window_manager_ exitFullscreenMode]; 1146 [fullscreen_window_manager_ exitFullscreenMode];
1121 fullscreen_window_manager_.reset(); 1147 fullscreen_window_manager_.reset();
1122 [pepper_fullscreen_window_ close]; 1148 [pepper_fullscreen_window_ close];
1123 1149
1124 // This can be called as part of processing the window's responder 1150 // This can be called as part of processing the window's responder
1125 // chain, for instance |-performKeyEquivalent:|. In that case the 1151 // chain, for instance |-performKeyEquivalent:|. In that case the
1126 // object needs to survive until the stack unwinds. 1152 // object needs to survive until the stack unwinds.
1127 pepper_fullscreen_window_.autorelease(); 1153 pepper_fullscreen_window_.autorelease();
1128 1154
1155 // Clear SurfaceID namespace ownership before we shutdown the
1156 // compositor.
1157 if (UseSurfacesEnabled() && render_widget_host_ &&
1158 render_widget_host_->delegate()->GetInputEventRouter()) {
lazyboy 2015/09/01 21:29:42 FYI, the mac failures seems to be b/c render_widge
kenrb 2015/09/02 16:35:05 Thanks for helping with debugging this! I didn't r
1159 render_widget_host_->delegate()
1160 ->GetInputEventRouter()
1161 ->RemoveSurfaceIdNamespaceOwner(GetSurfaceIdNamespace());
1162 }
1163
1129 // Delete the delegated frame state, which will reach back into 1164 // Delete the delegated frame state, which will reach back into
1130 // render_widget_host_. 1165 // render_widget_host_.
1131 ShutdownBrowserCompositor(); 1166 ShutdownBrowserCompositor();
1132 1167
1133 // We get this call just before |render_widget_host_| deletes 1168 // We get this call just before |render_widget_host_| deletes
1134 // itself. But we are owned by |cocoa_view_|, which may be retained 1169 // itself. But we are owned by |cocoa_view_|, which may be retained
1135 // by some other code. Examples are WebContentsViewMac's 1170 // by some other code. Examples are WebContentsViewMac's
1136 // |latent_focus_view_| and TabWindowController's 1171 // |latent_focus_view_| and TabWindowController's
1137 // |cachedContentView_|. 1172 // |cachedContentView_|.
1138 render_widget_host_ = NULL; 1173 render_widget_host_ = NULL;
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
1594 [cocoa_view_ processedWheelEvent:event consumed:consumed]; 1629 [cocoa_view_ processedWheelEvent:event consumed:consumed];
1595 } 1630 }
1596 1631
1597 uint32_t RenderWidgetHostViewMac::GetSurfaceIdNamespace() { 1632 uint32_t RenderWidgetHostViewMac::GetSurfaceIdNamespace() {
1598 if (delegated_frame_host_) 1633 if (delegated_frame_host_)
1599 return delegated_frame_host_->GetSurfaceIdNamespace(); 1634 return delegated_frame_host_->GetSurfaceIdNamespace();
1600 1635
1601 return 0; 1636 return 0;
1602 } 1637 }
1603 1638
1639 uint32_t RenderWidgetHostViewMac::SurfaceIdNamespaceAtPoint(
1640 const gfx::Point& point,
1641 gfx::Point* transformed_point) {
1642 cc::SurfaceId id =
1643 delegated_frame_host_->SurfaceIdAtPoint(point, transformed_point);
1644 // It is possible that the renderer has not yet produced a surface, in which
1645 // case we return our current namespace.
1646 if (id.is_null())
1647 return GetSurfaceIdNamespace();
1648 return cc::SurfaceIdAllocator::NamespaceForId(id);
1649 }
1650
1651 void RenderWidgetHostViewMac::ProcessMouseEvent(
1652 const blink::WebMouseEvent& event) {
1653 render_widget_host_->ForwardMouseEvent(event);
1654 }
1655 void RenderWidgetHostViewMac::ProcessMouseWheelEvent(
1656 const blink::WebMouseWheelEvent& event) {
1657 render_widget_host_->ForwardWheelEvent(event);
1658 }
1659
1604 bool RenderWidgetHostViewMac::Send(IPC::Message* message) { 1660 bool RenderWidgetHostViewMac::Send(IPC::Message* message) {
1605 if (render_widget_host_) 1661 if (render_widget_host_)
1606 return render_widget_host_->Send(message); 1662 return render_widget_host_->Send(message);
1607 delete message; 1663 delete message;
1608 return false; 1664 return false;
1609 } 1665 }
1610 1666
1611 void RenderWidgetHostViewMac::ShutdownHost() { 1667 void RenderWidgetHostViewMac::ShutdownHost() {
1612 weak_factory_.InvalidateWeakPtrs(); 1668 weak_factory_.InvalidateWeakPtrs();
1613 render_widget_host_->Shutdown(); 1669 render_widget_host_->Shutdown();
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
1929 } 1985 }
1930 1986
1931 if (mouseEventWasIgnored_) { 1987 if (mouseEventWasIgnored_) {
1932 // If this is the first mouse event after a previous event that was ignored 1988 // If this is the first mouse event after a previous event that was ignored
1933 // due to the hitTest, send a mouse enter event to the host view. 1989 // due to the hitTest, send a mouse enter event to the host view.
1934 if (renderWidgetHostView_->render_widget_host_) { 1990 if (renderWidgetHostView_->render_widget_host_) {
1935 WebMouseEvent enterEvent = 1991 WebMouseEvent enterEvent =
1936 WebInputEventFactory::mouseEvent(theEvent, self); 1992 WebInputEventFactory::mouseEvent(theEvent, self);
1937 enterEvent.type = WebInputEvent::MouseMove; 1993 enterEvent.type = WebInputEvent::MouseMove;
1938 enterEvent.button = WebMouseEvent::ButtonNone; 1994 enterEvent.button = WebMouseEvent::ButtonNone;
1939 renderWidgetHostView_->ForwardMouseEvent(enterEvent); 1995 if (renderWidgetHostView_->render_widget_host_->delegate()
1996 ->GetInputEventRouter()) {
1997 renderWidgetHostView_->render_widget_host_->delegate()
1998 ->GetInputEventRouter()
1999 ->RouteMouseEvent(renderWidgetHostView_.get(), &enterEvent);
2000 } else {
2001 renderWidgetHostView_->ForwardMouseEvent(enterEvent);
2002 }
1940 } 2003 }
1941 } 2004 }
1942 mouseEventWasIgnored_ = NO; 2005 mouseEventWasIgnored_ = NO;
1943 2006
1944 // Don't cancel child popups; killing them on a mouse click would prevent the 2007 // Don't cancel child popups; killing them on a mouse click would prevent the
1945 // user from positioning the insertion point in the text field spawning the 2008 // user from positioning the insertion point in the text field spawning the
1946 // popup. A click outside the text field would cause the text field to drop 2009 // popup. A click outside the text field would cause the text field to drop
1947 // the focus, and then EditorClientImpl::textFieldDidEndEditing() would cancel 2010 // the focus, and then EditorClientImpl::textFieldDidEndEditing() would cancel
1948 // the popup anyway, so we're OK. 2011 // the popup anyway, so we're OK.
1949 2012
1950 NSEventType type = [theEvent type]; 2013 NSEventType type = [theEvent type];
1951 if (type == NSLeftMouseDown) 2014 if (type == NSLeftMouseDown)
1952 hasOpenMouseDown_ = YES; 2015 hasOpenMouseDown_ = YES;
1953 else if (type == NSLeftMouseUp) 2016 else if (type == NSLeftMouseUp)
1954 hasOpenMouseDown_ = NO; 2017 hasOpenMouseDown_ = NO;
1955 2018
1956 // TODO(suzhe): We should send mouse events to the input method first if it 2019 // TODO(suzhe): We should send mouse events to the input method first if it
1957 // wants to handle them. But it won't work without implementing method 2020 // wants to handle them. But it won't work without implementing method
1958 // - (NSUInteger)characterIndexForPoint:. 2021 // - (NSUInteger)characterIndexForPoint:.
1959 // See: http://code.google.com/p/chromium/issues/detail?id=47141 2022 // See: http://code.google.com/p/chromium/issues/detail?id=47141
1960 // Instead of sending mouse events to the input method first, we now just 2023 // Instead of sending mouse events to the input method first, we now just
1961 // simply confirm all ongoing composition here. 2024 // simply confirm all ongoing composition here.
1962 if (type == NSLeftMouseDown || type == NSRightMouseDown || 2025 if (type == NSLeftMouseDown || type == NSRightMouseDown ||
1963 type == NSOtherMouseDown) { 2026 type == NSOtherMouseDown) {
1964 [self confirmComposition]; 2027 [self confirmComposition];
1965 } 2028 }
1966 2029
1967 const WebMouseEvent event = 2030 WebMouseEvent event = WebInputEventFactory::mouseEvent(theEvent, self);
1968 WebInputEventFactory::mouseEvent(theEvent, self); 2031 if (renderWidgetHostView_->render_widget_host_->delegate()
1969 renderWidgetHostView_->ForwardMouseEvent(event); 2032 ->GetInputEventRouter()) {
2033 renderWidgetHostView_->render_widget_host_->delegate()
2034 ->GetInputEventRouter()
2035 ->RouteMouseEvent(renderWidgetHostView_.get(), &event);
2036 } else {
2037 renderWidgetHostView_->ForwardMouseEvent(event);
2038 }
1970 } 2039 }
1971 2040
1972 - (BOOL)performKeyEquivalent:(NSEvent*)theEvent { 2041 - (BOOL)performKeyEquivalent:(NSEvent*)theEvent {
1973 // |performKeyEquivalent:| is sent to all views of a window, not only down the 2042 // |performKeyEquivalent:| is sent to all views of a window, not only down the
1974 // responder chain (cf. "Handling Key Equivalents" in 2043 // responder chain (cf. "Handling Key Equivalents" in
1975 // http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Event Overview/HandlingKeyEvents/HandlingKeyEvents.html 2044 // http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Event Overview/HandlingKeyEvents/HandlingKeyEvents.html
1976 // ). We only want to handle key equivalents if we're first responder. 2045 // ). We only want to handle key equivalents if we're first responder.
1977 if ([[self window] firstResponder] != self) 2046 if ([[self window] firstResponder] != self)
1978 return NO; 2047 return NO;
1979 2048
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
2417 }]; 2486 }];
2418 } 2487 }
2419 2488
2420 // This is responsible for content scrolling! 2489 // This is responsible for content scrolling!
2421 if (renderWidgetHostView_->render_widget_host_) { 2490 if (renderWidgetHostView_->render_widget_host_) {
2422 BOOL canRubberbandLeft = [responderDelegate_ canRubberbandLeft:self]; 2491 BOOL canRubberbandLeft = [responderDelegate_ canRubberbandLeft:self];
2423 BOOL canRubberbandRight = [responderDelegate_ canRubberbandRight:self]; 2492 BOOL canRubberbandRight = [responderDelegate_ canRubberbandRight:self];
2424 WebMouseWheelEvent webEvent = WebInputEventFactory::mouseWheelEvent( 2493 WebMouseWheelEvent webEvent = WebInputEventFactory::mouseWheelEvent(
2425 event, self, canRubberbandLeft, canRubberbandRight); 2494 event, self, canRubberbandLeft, canRubberbandRight);
2426 webEvent.railsMode = mouseWheelFilter_.UpdateRailsMode(webEvent); 2495 webEvent.railsMode = mouseWheelFilter_.UpdateRailsMode(webEvent);
2427 renderWidgetHostView_->render_widget_host_->ForwardWheelEvent(webEvent); 2496 if (renderWidgetHostView_->render_widget_host_->delegate()
2497 ->GetInputEventRouter()) {
2498 renderWidgetHostView_->render_widget_host_->delegate()
2499 ->GetInputEventRouter()
2500 ->RouteMouseWheelEvent(renderWidgetHostView_.get(), &webEvent);
2501 } else {
2502 renderWidgetHostView_->render_widget_host_->ForwardWheelEvent(webEvent);
2503 }
2428 } 2504 }
2429 } 2505 }
2430 2506
2431 // Called repeatedly during a pinch gesture, with incremental change values. 2507 // Called repeatedly during a pinch gesture, with incremental change values.
2432 - (void)magnifyWithEvent:(NSEvent*)event { 2508 - (void)magnifyWithEvent:(NSEvent*)event {
2433 if (!renderWidgetHostView_->render_widget_host_) 2509 if (!renderWidgetHostView_->render_widget_host_)
2434 return; 2510 return;
2435 2511
2436 // If, due to nesting of multiple gestures (e.g, from multiple touch 2512 // If, due to nesting of multiple gestures (e.g, from multiple touch
2437 // devices), the beginning of the gesture has been lost, skip the remainder 2513 // devices), the beginning of the gesture has been lost, skip the remainder
(...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after
3323 3399
3324 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 3400 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
3325 // regions that are not draggable. (See ControlRegionView in 3401 // regions that are not draggable. (See ControlRegionView in
3326 // native_app_window_cocoa.mm). This requires the render host view to be 3402 // native_app_window_cocoa.mm). This requires the render host view to be
3327 // draggable by default. 3403 // draggable by default.
3328 - (BOOL)mouseDownCanMoveWindow { 3404 - (BOOL)mouseDownCanMoveWindow {
3329 return YES; 3405 return YES;
3330 } 3406 }
3331 3407
3332 @end 3408 @end
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_mac.h ('k') | content/browser/site_per_process_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698