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

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: Disabled test on Android (not implemented there) 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() && render_widget_host_->delegate() &&
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() &&
624 render_widget_host_->delegate()->GetInputEventRouter()) {
625 render_widget_host_->delegate()
626 ->GetInputEventRouter()
627 ->RemoveSurfaceIdNamespaceOwner(GetSurfaceIdNamespace());
628 }
629
612 // Ensure that the browser compositor is destroyed in a safe order. 630 // Ensure that the browser compositor is destroyed in a safe order.
613 ShutdownBrowserCompositor(); 631 ShutdownBrowserCompositor();
614 632
615 // We are owned by RenderWidgetHostViewCocoa, so if we go away before the 633 // 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 634 // RenderWidgetHost does we need to tell it not to hold a stale pointer to
617 // us. 635 // us.
618 if (render_widget_host_) { 636 if (render_widget_host_) {
619 // If this is a RenderWidgetHostViewGuest's platform_view_, we're not the 637 // 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 638 // RWH's view, the RenderWidgetHostViewGuest is. So don't reset the RWH's
621 // view, the RenderWidgetHostViewGuest will do it. 639 // view, the RenderWidgetHostViewGuest will do it.
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 composition_range_ = range; 1108 composition_range_ = range;
1091 composition_bounds_ = character_bounds; 1109 composition_bounds_ = character_bounds;
1092 } 1110 }
1093 1111
1094 void RenderWidgetHostViewMac::RenderProcessGone(base::TerminationStatus status, 1112 void RenderWidgetHostViewMac::RenderProcessGone(base::TerminationStatus status,
1095 int error_code) { 1113 int error_code) {
1096 Destroy(); 1114 Destroy();
1097 } 1115 }
1098 1116
1099 void RenderWidgetHostViewMac::RenderWidgetHostGone() { 1117 void RenderWidgetHostViewMac::RenderWidgetHostGone() {
1118 // Clear SurfaceID namespace ownership before we shutdown the
1119 // compositor.
1120 if (UseSurfacesEnabled() && render_widget_host_ &&
1121 render_widget_host_->delegate() &&
1122 render_widget_host_->delegate()->GetInputEventRouter()) {
1123 render_widget_host_->delegate()
1124 ->GetInputEventRouter()
1125 ->RemoveSurfaceIdNamespaceOwner(GetSurfaceIdNamespace());
1126 }
1127
1100 // Destroy the DelegatedFrameHost, to prevent crashes when Destroy is never 1128 // Destroy the DelegatedFrameHost, to prevent crashes when Destroy is never
1101 // called on the view. 1129 // called on the view.
1102 // http://crbug.com/404828 1130 // http://crbug.com/404828
1103 ShutdownBrowserCompositor(); 1131 ShutdownBrowserCompositor();
1104 } 1132 }
1105 1133
1106 void RenderWidgetHostViewMac::Destroy() { 1134 void RenderWidgetHostViewMac::Destroy() {
1107 [[NSNotificationCenter defaultCenter] 1135 [[NSNotificationCenter defaultCenter]
1108 removeObserver:cocoa_view_ 1136 removeObserver:cocoa_view_
1109 name:NSWindowWillCloseNotification 1137 name:NSWindowWillCloseNotification
1110 object:popup_window_]; 1138 object:popup_window_];
1111 1139
1112 // We've been told to destroy. 1140 // We've been told to destroy.
1113 [cocoa_view_ retain]; 1141 [cocoa_view_ retain];
1114 [cocoa_view_ removeFromSuperview]; 1142 [cocoa_view_ removeFromSuperview];
1115 [cocoa_view_ autorelease]; 1143 [cocoa_view_ autorelease];
1116 1144
1117 [popup_window_ close]; 1145 [popup_window_ close];
1118 popup_window_.autorelease(); 1146 popup_window_.autorelease();
1119 1147
1120 [fullscreen_window_manager_ exitFullscreenMode]; 1148 [fullscreen_window_manager_ exitFullscreenMode];
1121 fullscreen_window_manager_.reset(); 1149 fullscreen_window_manager_.reset();
1122 [pepper_fullscreen_window_ close]; 1150 [pepper_fullscreen_window_ close];
1123 1151
1124 // This can be called as part of processing the window's responder 1152 // This can be called as part of processing the window's responder
1125 // chain, for instance |-performKeyEquivalent:|. In that case the 1153 // chain, for instance |-performKeyEquivalent:|. In that case the
1126 // object needs to survive until the stack unwinds. 1154 // object needs to survive until the stack unwinds.
1127 pepper_fullscreen_window_.autorelease(); 1155 pepper_fullscreen_window_.autorelease();
1128 1156
1157 // Clear SurfaceID namespace ownership before we shutdown the
1158 // compositor.
1159 if (UseSurfacesEnabled() && render_widget_host_ &&
1160 render_widget_host_->delegate() &&
1161 render_widget_host_->delegate()->GetInputEventRouter()) {
1162 render_widget_host_->delegate()
1163 ->GetInputEventRouter()
1164 ->RemoveSurfaceIdNamespaceOwner(GetSurfaceIdNamespace());
1165 }
1166
1129 // Delete the delegated frame state, which will reach back into 1167 // Delete the delegated frame state, which will reach back into
1130 // render_widget_host_. 1168 // render_widget_host_.
1131 ShutdownBrowserCompositor(); 1169 ShutdownBrowserCompositor();
1132 1170
1133 // We get this call just before |render_widget_host_| deletes 1171 // We get this call just before |render_widget_host_| deletes
1134 // itself. But we are owned by |cocoa_view_|, which may be retained 1172 // itself. But we are owned by |cocoa_view_|, which may be retained
1135 // by some other code. Examples are WebContentsViewMac's 1173 // by some other code. Examples are WebContentsViewMac's
1136 // |latent_focus_view_| and TabWindowController's 1174 // |latent_focus_view_| and TabWindowController's
1137 // |cachedContentView_|. 1175 // |cachedContentView_|.
1138 render_widget_host_ = NULL; 1176 render_widget_host_ = NULL;
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
1594 [cocoa_view_ processedWheelEvent:event consumed:consumed]; 1632 [cocoa_view_ processedWheelEvent:event consumed:consumed];
1595 } 1633 }
1596 1634
1597 uint32_t RenderWidgetHostViewMac::GetSurfaceIdNamespace() { 1635 uint32_t RenderWidgetHostViewMac::GetSurfaceIdNamespace() {
1598 if (delegated_frame_host_) 1636 if (delegated_frame_host_)
1599 return delegated_frame_host_->GetSurfaceIdNamespace(); 1637 return delegated_frame_host_->GetSurfaceIdNamespace();
1600 1638
1601 return 0; 1639 return 0;
1602 } 1640 }
1603 1641
1642 uint32_t RenderWidgetHostViewMac::SurfaceIdNamespaceAtPoint(
1643 const gfx::Point& point,
1644 gfx::Point* transformed_point) {
1645 cc::SurfaceId id =
1646 delegated_frame_host_->SurfaceIdAtPoint(point, transformed_point);
1647 // It is possible that the renderer has not yet produced a surface, in which
1648 // case we return our current namespace.
1649 if (id.is_null())
1650 return GetSurfaceIdNamespace();
1651 return cc::SurfaceIdAllocator::NamespaceForId(id);
1652 }
1653
1654 void RenderWidgetHostViewMac::ProcessMouseEvent(
1655 const blink::WebMouseEvent& event) {
1656 render_widget_host_->ForwardMouseEvent(event);
1657 }
1658 void RenderWidgetHostViewMac::ProcessMouseWheelEvent(
1659 const blink::WebMouseWheelEvent& event) {
1660 render_widget_host_->ForwardWheelEvent(event);
1661 }
1662
1604 bool RenderWidgetHostViewMac::Send(IPC::Message* message) { 1663 bool RenderWidgetHostViewMac::Send(IPC::Message* message) {
1605 if (render_widget_host_) 1664 if (render_widget_host_)
1606 return render_widget_host_->Send(message); 1665 return render_widget_host_->Send(message);
1607 delete message; 1666 delete message;
1608 return false; 1667 return false;
1609 } 1668 }
1610 1669
1611 void RenderWidgetHostViewMac::ShutdownHost() { 1670 void RenderWidgetHostViewMac::ShutdownHost() {
1612 weak_factory_.InvalidateWeakPtrs(); 1671 weak_factory_.InvalidateWeakPtrs();
1613 render_widget_host_->Shutdown(); 1672 render_widget_host_->Shutdown();
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
1929 } 1988 }
1930 1989
1931 if (mouseEventWasIgnored_) { 1990 if (mouseEventWasIgnored_) {
1932 // If this is the first mouse event after a previous event that was ignored 1991 // 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. 1992 // due to the hitTest, send a mouse enter event to the host view.
1934 if (renderWidgetHostView_->render_widget_host_) { 1993 if (renderWidgetHostView_->render_widget_host_) {
1935 WebMouseEvent enterEvent = 1994 WebMouseEvent enterEvent =
1936 WebInputEventFactory::mouseEvent(theEvent, self); 1995 WebInputEventFactory::mouseEvent(theEvent, self);
1937 enterEvent.type = WebInputEvent::MouseMove; 1996 enterEvent.type = WebInputEvent::MouseMove;
1938 enterEvent.button = WebMouseEvent::ButtonNone; 1997 enterEvent.button = WebMouseEvent::ButtonNone;
1939 renderWidgetHostView_->ForwardMouseEvent(enterEvent); 1998 if (renderWidgetHostView_->render_widget_host_->delegate() &&
1999 renderWidgetHostView_->render_widget_host_->delegate()
2000 ->GetInputEventRouter()) {
2001 renderWidgetHostView_->render_widget_host_->delegate()
2002 ->GetInputEventRouter()
2003 ->RouteMouseEvent(renderWidgetHostView_.get(), &enterEvent);
2004 } else {
2005 renderWidgetHostView_->ForwardMouseEvent(enterEvent);
2006 }
1940 } 2007 }
1941 } 2008 }
1942 mouseEventWasIgnored_ = NO; 2009 mouseEventWasIgnored_ = NO;
1943 2010
1944 // Don't cancel child popups; killing them on a mouse click would prevent the 2011 // 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 2012 // 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 2013 // popup. A click outside the text field would cause the text field to drop
1947 // the focus, and then EditorClientImpl::textFieldDidEndEditing() would cancel 2014 // the focus, and then EditorClientImpl::textFieldDidEndEditing() would cancel
1948 // the popup anyway, so we're OK. 2015 // the popup anyway, so we're OK.
1949 2016
1950 NSEventType type = [theEvent type]; 2017 NSEventType type = [theEvent type];
1951 if (type == NSLeftMouseDown) 2018 if (type == NSLeftMouseDown)
1952 hasOpenMouseDown_ = YES; 2019 hasOpenMouseDown_ = YES;
1953 else if (type == NSLeftMouseUp) 2020 else if (type == NSLeftMouseUp)
1954 hasOpenMouseDown_ = NO; 2021 hasOpenMouseDown_ = NO;
1955 2022
1956 // TODO(suzhe): We should send mouse events to the input method first if it 2023 // 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 2024 // wants to handle them. But it won't work without implementing method
1958 // - (NSUInteger)characterIndexForPoint:. 2025 // - (NSUInteger)characterIndexForPoint:.
1959 // See: http://code.google.com/p/chromium/issues/detail?id=47141 2026 // 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 2027 // Instead of sending mouse events to the input method first, we now just
1961 // simply confirm all ongoing composition here. 2028 // simply confirm all ongoing composition here.
1962 if (type == NSLeftMouseDown || type == NSRightMouseDown || 2029 if (type == NSLeftMouseDown || type == NSRightMouseDown ||
1963 type == NSOtherMouseDown) { 2030 type == NSOtherMouseDown) {
1964 [self confirmComposition]; 2031 [self confirmComposition];
1965 } 2032 }
1966 2033
1967 const WebMouseEvent event = 2034 WebMouseEvent event = WebInputEventFactory::mouseEvent(theEvent, self);
1968 WebInputEventFactory::mouseEvent(theEvent, self); 2035 if (renderWidgetHostView_->render_widget_host_->delegate() &&
1969 renderWidgetHostView_->ForwardMouseEvent(event); 2036 renderWidgetHostView_->render_widget_host_->delegate()
2037 ->GetInputEventRouter()) {
2038 renderWidgetHostView_->render_widget_host_->delegate()
2039 ->GetInputEventRouter()
2040 ->RouteMouseEvent(renderWidgetHostView_.get(), &event);
2041 } else {
2042 renderWidgetHostView_->ForwardMouseEvent(event);
2043 }
1970 } 2044 }
1971 2045
1972 - (BOOL)performKeyEquivalent:(NSEvent*)theEvent { 2046 - (BOOL)performKeyEquivalent:(NSEvent*)theEvent {
1973 // |performKeyEquivalent:| is sent to all views of a window, not only down the 2047 // |performKeyEquivalent:| is sent to all views of a window, not only down the
1974 // responder chain (cf. "Handling Key Equivalents" in 2048 // responder chain (cf. "Handling Key Equivalents" in
1975 // http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Event Overview/HandlingKeyEvents/HandlingKeyEvents.html 2049 // 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. 2050 // ). We only want to handle key equivalents if we're first responder.
1977 if ([[self window] firstResponder] != self) 2051 if ([[self window] firstResponder] != self)
1978 return NO; 2052 return NO;
1979 2053
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
2417 }]; 2491 }];
2418 } 2492 }
2419 2493
2420 // This is responsible for content scrolling! 2494 // This is responsible for content scrolling!
2421 if (renderWidgetHostView_->render_widget_host_) { 2495 if (renderWidgetHostView_->render_widget_host_) {
2422 BOOL canRubberbandLeft = [responderDelegate_ canRubberbandLeft:self]; 2496 BOOL canRubberbandLeft = [responderDelegate_ canRubberbandLeft:self];
2423 BOOL canRubberbandRight = [responderDelegate_ canRubberbandRight:self]; 2497 BOOL canRubberbandRight = [responderDelegate_ canRubberbandRight:self];
2424 WebMouseWheelEvent webEvent = WebInputEventFactory::mouseWheelEvent( 2498 WebMouseWheelEvent webEvent = WebInputEventFactory::mouseWheelEvent(
2425 event, self, canRubberbandLeft, canRubberbandRight); 2499 event, self, canRubberbandLeft, canRubberbandRight);
2426 webEvent.railsMode = mouseWheelFilter_.UpdateRailsMode(webEvent); 2500 webEvent.railsMode = mouseWheelFilter_.UpdateRailsMode(webEvent);
2427 renderWidgetHostView_->render_widget_host_->ForwardWheelEvent(webEvent); 2501 if (renderWidgetHostView_->render_widget_host_->delegate() &&
2502 renderWidgetHostView_->render_widget_host_->delegate()
2503 ->GetInputEventRouter()) {
2504 renderWidgetHostView_->render_widget_host_->delegate()
2505 ->GetInputEventRouter()
2506 ->RouteMouseWheelEvent(renderWidgetHostView_.get(), &webEvent);
2507 } else {
2508 renderWidgetHostView_->render_widget_host_->ForwardWheelEvent(webEvent);
2509 }
2428 } 2510 }
2429 } 2511 }
2430 2512
2431 // Called repeatedly during a pinch gesture, with incremental change values. 2513 // Called repeatedly during a pinch gesture, with incremental change values.
2432 - (void)magnifyWithEvent:(NSEvent*)event { 2514 - (void)magnifyWithEvent:(NSEvent*)event {
2433 if (!renderWidgetHostView_->render_widget_host_) 2515 if (!renderWidgetHostView_->render_widget_host_)
2434 return; 2516 return;
2435 2517
2436 // If, due to nesting of multiple gestures (e.g, from multiple touch 2518 // 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 2519 // 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 3405
3324 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 3406 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
3325 // regions that are not draggable. (See ControlRegionView in 3407 // regions that are not draggable. (See ControlRegionView in
3326 // native_app_window_cocoa.mm). This requires the render host view to be 3408 // native_app_window_cocoa.mm). This requires the render host view to be
3327 // draggable by default. 3409 // draggable by default.
3328 - (BOOL)mouseDownCanMoveWindow { 3410 - (BOOL)mouseDownCanMoveWindow {
3329 return YES; 3411 return YES;
3330 } 3412 }
3331 3413
3332 @end 3414 @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