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 1237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1248 NSPoint location = [window mouseLocationOutsideOfEventStream]; | 1248 NSPoint location = [window mouseLocationOutsideOfEventStream]; |
| 1249 NSEvent* event = [NSEvent mouseEventWithType:NSMouseMoved | 1249 NSEvent* event = [NSEvent mouseEventWithType:NSMouseMoved |
| 1250 location:location | 1250 location:location |
| 1251 modifierFlags:0 | 1251 modifierFlags:0 |
| 1252 timestamp:0 | 1252 timestamp:0 |
| 1253 windowNumber:window_number() | 1253 windowNumber:window_number() |
| 1254 context:nil | 1254 context:nil |
| 1255 eventNumber:0 | 1255 eventNumber:0 |
| 1256 clickCount:0 | 1256 clickCount:0 |
| 1257 pressure:0]; | 1257 pressure:0]; |
| 1258 WebMouseEvent web_event = WebMouseEventBuilder::Build(event, cocoa_view_); | 1258 WebMouseEvent web_event = WebMouseEventBuilder::Build( |
| 1259 event, cocoa_view_, blink::WebPointerProperties::PointerType::Mouse); | |
| 1259 if (showing) | 1260 if (showing) |
| 1260 web_event.type = WebInputEvent::MouseLeave; | 1261 web_event.type = WebInputEvent::MouseLeave; |
| 1261 ForwardMouseEvent(web_event); | 1262 ForwardMouseEvent(web_event); |
| 1262 } | 1263 } |
| 1263 | 1264 |
| 1264 bool RenderWidgetHostViewMac::IsPopup() const { | 1265 bool RenderWidgetHostViewMac::IsPopup() const { |
| 1265 return popup_type_ != blink::WebPopupTypeNone; | 1266 return popup_type_ != blink::WebPopupTypeNone; |
| 1266 } | 1267 } |
| 1267 | 1268 |
| 1268 void RenderWidgetHostViewMac::CopyFromCompositingSurface( | 1269 void RenderWidgetHostViewMac::CopyFromCompositingSurface( |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1835 self = [super initWithFrame:NSZeroRect]; | 1836 self = [super initWithFrame:NSZeroRect]; |
| 1836 if (self) { | 1837 if (self) { |
| 1837 self.acceptsTouchEvents = YES; | 1838 self.acceptsTouchEvents = YES; |
| 1838 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper); | 1839 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper); |
| 1839 editCommand_helper_->AddEditingSelectorsToClass([self class]); | 1840 editCommand_helper_->AddEditingSelectorsToClass([self class]); |
| 1840 | 1841 |
| 1841 renderWidgetHostView_.reset(r); | 1842 renderWidgetHostView_.reset(r); |
| 1842 canBeKeyView_ = YES; | 1843 canBeKeyView_ = YES; |
| 1843 opaque_ = YES; | 1844 opaque_ = YES; |
| 1844 pinchHasReachedZoomThreshold_ = false; | 1845 pinchHasReachedZoomThreshold_ = false; |
| 1846 stylusEnteringProximityCount_ = 0; | |
| 1845 | 1847 |
| 1846 // OpenGL support: | 1848 // OpenGL support: |
| 1847 if ([self respondsToSelector: | 1849 if ([self respondsToSelector: |
| 1848 @selector(setWantsBestResolutionOpenGLSurface:)]) { | 1850 @selector(setWantsBestResolutionOpenGLSurface:)]) { |
| 1849 [self setWantsBestResolutionOpenGLSurface:YES]; | 1851 [self setWantsBestResolutionOpenGLSurface:YES]; |
| 1850 } | 1852 } |
| 1851 [[NSNotificationCenter defaultCenter] | 1853 [[NSNotificationCenter defaultCenter] |
| 1852 addObserver:self | 1854 addObserver:self |
| 1853 selector:@selector(didChangeScreenParameters:) | 1855 selector:@selector(didChangeScreenParameters:) |
| 1854 name:NSApplicationDidChangeScreenParametersNotification | 1856 name:NSApplicationDidChangeScreenParametersNotification |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1982 | 1984 |
| 1983 - (void)mouseEvent:(NSEvent*)theEvent { | 1985 - (void)mouseEvent:(NSEvent*)theEvent { |
| 1984 TRACE_EVENT0("browser", "RenderWidgetHostViewCocoa::mouseEvent"); | 1986 TRACE_EVENT0("browser", "RenderWidgetHostViewCocoa::mouseEvent"); |
| 1985 if (responderDelegate_ && | 1987 if (responderDelegate_ && |
| 1986 [responderDelegate_ respondsToSelector:@selector(handleEvent:)]) { | 1988 [responderDelegate_ respondsToSelector:@selector(handleEvent:)]) { |
| 1987 BOOL handled = [responderDelegate_ handleEvent:theEvent]; | 1989 BOOL handled = [responderDelegate_ handleEvent:theEvent]; |
| 1988 if (handled) | 1990 if (handled) |
| 1989 return; | 1991 return; |
| 1990 } | 1992 } |
| 1991 | 1993 |
| 1994 // If the pointing device enters proximity of its tablet and does not leave, | |
| 1995 // the pointer type should be pen, otherwise is mouse. | |
| 1996 blink::WebPointerProperties::PointerType pointerType = | |
|
mustaq
2016/06/02 15:39:12
As in the other file, rename |pointerType| to |poi
lanwei
2016/06/03 14:13:15
Done.
| |
| 1997 (stylusEnteringProximityCount_ > 0) | |
| 1998 ? blink::WebPointerProperties::PointerType::Pen | |
| 1999 : blink::WebPointerProperties::PointerType::Mouse; | |
| 1992 if ([self shouldIgnoreMouseEvent:theEvent]) { | 2000 if ([self shouldIgnoreMouseEvent:theEvent]) { |
| 1993 // If this is the first such event, send a mouse exit to the host view. | 2001 // If this is the first such event, send a mouse exit to the host view. |
| 1994 if (!mouseEventWasIgnored_ && renderWidgetHostView_->render_widget_host_) { | 2002 if (!mouseEventWasIgnored_ && renderWidgetHostView_->render_widget_host_) { |
| 1995 WebMouseEvent exitEvent = WebMouseEventBuilder::Build(theEvent, self); | 2003 WebMouseEvent exitEvent = |
| 2004 WebMouseEventBuilder::Build(theEvent, self, pointerType); | |
| 1996 exitEvent.type = WebInputEvent::MouseLeave; | 2005 exitEvent.type = WebInputEvent::MouseLeave; |
| 1997 exitEvent.button = WebMouseEvent::ButtonNone; | 2006 exitEvent.button = WebMouseEvent::ButtonNone; |
| 1998 renderWidgetHostView_->ForwardMouseEvent(exitEvent); | 2007 renderWidgetHostView_->ForwardMouseEvent(exitEvent); |
| 1999 } | 2008 } |
| 2000 mouseEventWasIgnored_ = YES; | 2009 mouseEventWasIgnored_ = YES; |
| 2001 return; | 2010 return; |
| 2002 } | 2011 } |
| 2003 | 2012 |
| 2004 if (mouseEventWasIgnored_) { | 2013 if (mouseEventWasIgnored_) { |
| 2005 // If this is the first mouse event after a previous event that was ignored | 2014 // If this is the first mouse event after a previous event that was ignored |
| 2006 // due to the hitTest, send a mouse enter event to the host view. | 2015 // due to the hitTest, send a mouse enter event to the host view. |
| 2007 if (renderWidgetHostView_->render_widget_host_) { | 2016 if (renderWidgetHostView_->render_widget_host_) { |
| 2008 WebMouseEvent enterEvent = WebMouseEventBuilder::Build(theEvent, self); | 2017 WebMouseEvent enterEvent = |
| 2018 WebMouseEventBuilder::Build(theEvent, self, pointerType); | |
| 2009 enterEvent.type = WebInputEvent::MouseMove; | 2019 enterEvent.type = WebInputEvent::MouseMove; |
| 2010 enterEvent.button = WebMouseEvent::ButtonNone; | 2020 enterEvent.button = WebMouseEvent::ButtonNone; |
| 2011 if (renderWidgetHostView_->ShouldRouteEvent(enterEvent)) { | 2021 if (renderWidgetHostView_->ShouldRouteEvent(enterEvent)) { |
| 2012 renderWidgetHostView_->render_widget_host_->delegate() | 2022 renderWidgetHostView_->render_widget_host_->delegate() |
| 2013 ->GetInputEventRouter() | 2023 ->GetInputEventRouter() |
| 2014 ->RouteMouseEvent(renderWidgetHostView_.get(), &enterEvent); | 2024 ->RouteMouseEvent(renderWidgetHostView_.get(), &enterEvent); |
| 2015 } else { | 2025 } else { |
| 2016 renderWidgetHostView_->ProcessMouseEvent(enterEvent); | 2026 renderWidgetHostView_->ProcessMouseEvent(enterEvent); |
| 2017 } | 2027 } |
| 2018 } | 2028 } |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 2035 // wants to handle them. But it won't work without implementing method | 2045 // wants to handle them. But it won't work without implementing method |
| 2036 // - (NSUInteger)characterIndexForPoint:. | 2046 // - (NSUInteger)characterIndexForPoint:. |
| 2037 // See: http://code.google.com/p/chromium/issues/detail?id=47141 | 2047 // See: http://code.google.com/p/chromium/issues/detail?id=47141 |
| 2038 // Instead of sending mouse events to the input method first, we now just | 2048 // Instead of sending mouse events to the input method first, we now just |
| 2039 // simply confirm all ongoing composition here. | 2049 // simply confirm all ongoing composition here. |
| 2040 if (type == NSLeftMouseDown || type == NSRightMouseDown || | 2050 if (type == NSLeftMouseDown || type == NSRightMouseDown || |
| 2041 type == NSOtherMouseDown) { | 2051 type == NSOtherMouseDown) { |
| 2042 [self confirmComposition]; | 2052 [self confirmComposition]; |
| 2043 } | 2053 } |
| 2044 | 2054 |
| 2045 WebMouseEvent event = WebMouseEventBuilder::Build(theEvent, self); | 2055 WebMouseEvent event = |
| 2056 WebMouseEventBuilder::Build(theEvent, self, pointerType); | |
| 2046 if (renderWidgetHostView_->ShouldRouteEvent(event)) { | 2057 if (renderWidgetHostView_->ShouldRouteEvent(event)) { |
| 2047 renderWidgetHostView_->render_widget_host_->delegate() | 2058 renderWidgetHostView_->render_widget_host_->delegate() |
| 2048 ->GetInputEventRouter() | 2059 ->GetInputEventRouter() |
| 2049 ->RouteMouseEvent(renderWidgetHostView_.get(), &event); | 2060 ->RouteMouseEvent(renderWidgetHostView_.get(), &event); |
| 2050 } else { | 2061 } else { |
| 2051 renderWidgetHostView_->ProcessMouseEvent(event); | 2062 renderWidgetHostView_->ProcessMouseEvent(event); |
| 2052 } | 2063 } |
| 2053 } | 2064 } |
| 2054 | 2065 |
| 2066 - (void)tabletEvent:(NSEvent*)theEvent { | |
| 2067 if ([theEvent isEnteringProximity]) | |
| 2068 stylusEnteringProximityCount_++; | |
| 2069 else | |
| 2070 stylusEnteringProximityCount_--; | |
| 2071 } | |
| 2072 | |
| 2055 - (BOOL)performKeyEquivalent:(NSEvent*)theEvent { | 2073 - (BOOL)performKeyEquivalent:(NSEvent*)theEvent { |
| 2056 // |performKeyEquivalent:| is sent to all views of a window, not only down the | 2074 // |performKeyEquivalent:| is sent to all views of a window, not only down the |
| 2057 // responder chain (cf. "Handling Key Equivalents" in | 2075 // responder chain (cf. "Handling Key Equivalents" in |
| 2058 // http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Event Overview/HandlingKeyEvents/HandlingKeyEvents.html | 2076 // http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Event Overview/HandlingKeyEvents/HandlingKeyEvents.html |
| 2059 // ). We only want to handle key equivalents if we're first responder. | 2077 // ). We only want to handle key equivalents if we're first responder. |
| 2060 if ([[self window] firstResponder] != self) | 2078 if ([[self window] firstResponder] != self) |
| 2061 return NO; | 2079 return NO; |
| 2062 | 2080 |
| 2063 // If the event is reserved by the system, then do not pass it to web content. | 2081 // If the event is reserved by the system, then do not pass it to web content. |
| 2064 if (EventIsReservedBySystem(theEvent)) | 2082 if (EventIsReservedBySystem(theEvent)) |
| (...skipping 1385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3450 | 3468 |
| 3451 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3469 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
| 3452 // regions that are not draggable. (See ControlRegionView in | 3470 // regions that are not draggable. (See ControlRegionView in |
| 3453 // native_app_window_cocoa.mm). This requires the render host view to be | 3471 // native_app_window_cocoa.mm). This requires the render host view to be |
| 3454 // draggable by default. | 3472 // draggable by default. |
| 3455 - (BOOL)mouseDownCanMoveWindow { | 3473 - (BOOL)mouseDownCanMoveWindow { |
| 3456 return YES; | 3474 return YES; |
| 3457 } | 3475 } |
| 3458 | 3476 |
| 3459 @end | 3477 @end |
| OLD | NEW |