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

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: Added missing test file 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()) {
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 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
1604 [cocoa_view_ processedWheelEvent:event consumed:consumed]; 1639 [cocoa_view_ processedWheelEvent:event consumed:consumed];
1605 } 1640 }
1606 1641
1607 uint32_t RenderWidgetHostViewMac::GetSurfaceIdNamespace() { 1642 uint32_t RenderWidgetHostViewMac::GetSurfaceIdNamespace() {
1608 if (delegated_frame_host_) 1643 if (delegated_frame_host_)
1609 return delegated_frame_host_->GetSurfaceIdNamespace(); 1644 return delegated_frame_host_->GetSurfaceIdNamespace();
1610 1645
1611 return 0; 1646 return 0;
1612 } 1647 }
1613 1648
1649 uint32_t RenderWidgetHostViewMac::SurfaceIdNamespaceAtPoint(
1650 const gfx::Point& point,
1651 gfx::Point* transformed_point) {
1652 cc::SurfaceId id =
1653 delegated_frame_host_->SurfaceIdAtPoint(point, transformed_point);
1654 // It is possible that the renderer has not yet produced a surface, in which
1655 // case we return our current namespace.
1656 if (id.is_null())
1657 return GetSurfaceIdNamespace();
1658 return cc::SurfaceIdAllocator::NamespaceForId(id);
1659 }
1660
1661 void RenderWidgetHostViewMac::ProcessMouseEvent(
1662 const blink::WebMouseEvent& event) {
1663 render_widget_host_->ForwardMouseEvent(event);
1664 }
1665 void RenderWidgetHostViewMac::ProcessMouseWheelEvent(
1666 const blink::WebMouseWheelEvent& event) {
1667 render_widget_host_->ForwardWheelEvent(event);
1668 }
1669
1614 bool RenderWidgetHostViewMac::Send(IPC::Message* message) { 1670 bool RenderWidgetHostViewMac::Send(IPC::Message* message) {
1615 if (render_widget_host_) 1671 if (render_widget_host_)
1616 return render_widget_host_->Send(message); 1672 return render_widget_host_->Send(message);
1617 delete message; 1673 delete message;
1618 return false; 1674 return false;
1619 } 1675 }
1620 1676
1621 void RenderWidgetHostViewMac::ShutdownHost() { 1677 void RenderWidgetHostViewMac::ShutdownHost() {
1622 weak_factory_.InvalidateWeakPtrs(); 1678 weak_factory_.InvalidateWeakPtrs();
1623 render_widget_host_->Shutdown(); 1679 render_widget_host_->Shutdown();
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
1939 } 1995 }
1940 1996
1941 if (mouseEventWasIgnored_) { 1997 if (mouseEventWasIgnored_) {
1942 // If this is the first mouse event after a previous event that was ignored 1998 // If this is the first mouse event after a previous event that was ignored
1943 // due to the hitTest, send a mouse enter event to the host view. 1999 // due to the hitTest, send a mouse enter event to the host view.
1944 if (renderWidgetHostView_->render_widget_host_) { 2000 if (renderWidgetHostView_->render_widget_host_) {
1945 WebMouseEvent enterEvent = 2001 WebMouseEvent enterEvent =
1946 WebInputEventFactory::mouseEvent(theEvent, self); 2002 WebInputEventFactory::mouseEvent(theEvent, self);
1947 enterEvent.type = WebInputEvent::MouseMove; 2003 enterEvent.type = WebInputEvent::MouseMove;
1948 enterEvent.button = WebMouseEvent::ButtonNone; 2004 enterEvent.button = WebMouseEvent::ButtonNone;
1949 renderWidgetHostView_->ForwardMouseEvent(enterEvent); 2005 if (renderWidgetHostView_->render_widget_host_->delegate()
2006 ->GetInputEventRouter()) {
2007 renderWidgetHostView_->render_widget_host_->delegate()
2008 ->GetInputEventRouter()
2009 ->RouteMouseEvent(renderWidgetHostView_.get(), &enterEvent);
2010 } else {
2011 renderWidgetHostView_->ForwardMouseEvent(enterEvent);
2012 }
1950 } 2013 }
1951 } 2014 }
1952 mouseEventWasIgnored_ = NO; 2015 mouseEventWasIgnored_ = NO;
1953 2016
1954 // Don't cancel child popups; killing them on a mouse click would prevent the 2017 // Don't cancel child popups; killing them on a mouse click would prevent the
1955 // user from positioning the insertion point in the text field spawning the 2018 // user from positioning the insertion point in the text field spawning the
1956 // popup. A click outside the text field would cause the text field to drop 2019 // popup. A click outside the text field would cause the text field to drop
1957 // the focus, and then EditorClientImpl::textFieldDidEndEditing() would cancel 2020 // the focus, and then EditorClientImpl::textFieldDidEndEditing() would cancel
1958 // the popup anyway, so we're OK. 2021 // the popup anyway, so we're OK.
1959 2022
1960 NSEventType type = [theEvent type]; 2023 NSEventType type = [theEvent type];
1961 if (type == NSLeftMouseDown) 2024 if (type == NSLeftMouseDown)
1962 hasOpenMouseDown_ = YES; 2025 hasOpenMouseDown_ = YES;
1963 else if (type == NSLeftMouseUp) 2026 else if (type == NSLeftMouseUp)
1964 hasOpenMouseDown_ = NO; 2027 hasOpenMouseDown_ = NO;
1965 2028
1966 // TODO(suzhe): We should send mouse events to the input method first if it 2029 // TODO(suzhe): We should send mouse events to the input method first if it
1967 // wants to handle them. But it won't work without implementing method 2030 // wants to handle them. But it won't work without implementing method
1968 // - (NSUInteger)characterIndexForPoint:. 2031 // - (NSUInteger)characterIndexForPoint:.
1969 // See: http://code.google.com/p/chromium/issues/detail?id=47141 2032 // See: http://code.google.com/p/chromium/issues/detail?id=47141
1970 // Instead of sending mouse events to the input method first, we now just 2033 // Instead of sending mouse events to the input method first, we now just
1971 // simply confirm all ongoing composition here. 2034 // simply confirm all ongoing composition here.
1972 if (type == NSLeftMouseDown || type == NSRightMouseDown || 2035 if (type == NSLeftMouseDown || type == NSRightMouseDown ||
1973 type == NSOtherMouseDown) { 2036 type == NSOtherMouseDown) {
1974 [self confirmComposition]; 2037 [self confirmComposition];
1975 } 2038 }
1976 2039
1977 const WebMouseEvent event = 2040 WebMouseEvent event = WebInputEventFactory::mouseEvent(theEvent, self);
1978 WebInputEventFactory::mouseEvent(theEvent, self); 2041 if (renderWidgetHostView_->render_widget_host_->delegate()
1979 renderWidgetHostView_->ForwardMouseEvent(event); 2042 ->GetInputEventRouter()) {
2043 renderWidgetHostView_->render_widget_host_->delegate()
2044 ->GetInputEventRouter()
2045 ->RouteMouseEvent(renderWidgetHostView_.get(), &event);
2046 } else {
2047 renderWidgetHostView_->ForwardMouseEvent(event);
2048 }
1980 } 2049 }
1981 2050
1982 - (BOOL)performKeyEquivalent:(NSEvent*)theEvent { 2051 - (BOOL)performKeyEquivalent:(NSEvent*)theEvent {
1983 // |performKeyEquivalent:| is sent to all views of a window, not only down the 2052 // |performKeyEquivalent:| is sent to all views of a window, not only down the
1984 // responder chain (cf. "Handling Key Equivalents" in 2053 // responder chain (cf. "Handling Key Equivalents" in
1985 // http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Event Overview/HandlingKeyEvents/HandlingKeyEvents.html 2054 // http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Event Overview/HandlingKeyEvents/HandlingKeyEvents.html
1986 // ). We only want to handle key equivalents if we're first responder. 2055 // ). We only want to handle key equivalents if we're first responder.
1987 if ([[self window] firstResponder] != self) 2056 if ([[self window] firstResponder] != self)
1988 return NO; 2057 return NO;
1989 2058
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
2427 }]; 2496 }];
2428 } 2497 }
2429 2498
2430 // This is responsible for content scrolling! 2499 // This is responsible for content scrolling!
2431 if (renderWidgetHostView_->render_widget_host_) { 2500 if (renderWidgetHostView_->render_widget_host_) {
2432 BOOL canRubberbandLeft = [responderDelegate_ canRubberbandLeft:self]; 2501 BOOL canRubberbandLeft = [responderDelegate_ canRubberbandLeft:self];
2433 BOOL canRubberbandRight = [responderDelegate_ canRubberbandRight:self]; 2502 BOOL canRubberbandRight = [responderDelegate_ canRubberbandRight:self];
2434 WebMouseWheelEvent webEvent = WebInputEventFactory::mouseWheelEvent( 2503 WebMouseWheelEvent webEvent = WebInputEventFactory::mouseWheelEvent(
2435 event, self, canRubberbandLeft, canRubberbandRight); 2504 event, self, canRubberbandLeft, canRubberbandRight);
2436 webEvent.railsMode = mouseWheelFilter_.UpdateRailsMode(webEvent); 2505 webEvent.railsMode = mouseWheelFilter_.UpdateRailsMode(webEvent);
2437 renderWidgetHostView_->render_widget_host_->ForwardWheelEvent(webEvent); 2506 if (renderWidgetHostView_->render_widget_host_->delegate()
2507 ->GetInputEventRouter()) {
2508 renderWidgetHostView_->render_widget_host_->delegate()
2509 ->GetInputEventRouter()
2510 ->RouteMouseWheelEvent(renderWidgetHostView_.get(), &webEvent);
2511 } else {
2512 renderWidgetHostView_->render_widget_host_->ForwardWheelEvent(webEvent);
2513 }
2438 } 2514 }
2439 } 2515 }
2440 2516
2441 // Called repeatedly during a pinch gesture, with incremental change values. 2517 // Called repeatedly during a pinch gesture, with incremental change values.
2442 - (void)magnifyWithEvent:(NSEvent*)event { 2518 - (void)magnifyWithEvent:(NSEvent*)event {
2443 if (!renderWidgetHostView_->render_widget_host_) 2519 if (!renderWidgetHostView_->render_widget_host_)
2444 return; 2520 return;
2445 2521
2446 // If, due to nesting of multiple gestures (e.g, from multiple touch 2522 // If, due to nesting of multiple gestures (e.g, from multiple touch
2447 // devices), the beginning of the gesture has been lost, skip the remainder 2523 // devices), the beginning of the gesture has been lost, skip the remainder
(...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after
3359 3435
3360 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 3436 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
3361 // regions that are not draggable. (See ControlRegionView in 3437 // regions that are not draggable. (See ControlRegionView in
3362 // native_app_window_cocoa.mm). This requires the render host view to be 3438 // native_app_window_cocoa.mm). This requires the render host view to be
3363 // draggable by default. 3439 // draggable by default.
3364 - (BOOL)mouseDownCanMoveWindow { 3440 - (BOOL)mouseDownCanMoveWindow {
3365 return YES; 3441 return YES;
3366 } 3442 }
3367 3443
3368 @end 3444 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698