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

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

Issue 2373733002: Send pointerleave and pointerenter events for styluses on Mac (Closed)
Patch Set: Ready for review Created 4 years, 2 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 1690 matching lines...) Expand 10 before | Expand all | Expand 10 after
1701 self = [super initWithFrame:NSZeroRect]; 1701 self = [super initWithFrame:NSZeroRect];
1702 if (self) { 1702 if (self) {
1703 self.acceptsTouchEvents = YES; 1703 self.acceptsTouchEvents = YES;
1704 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper); 1704 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper);
1705 editCommand_helper_->AddEditingSelectorsToClass([self class]); 1705 editCommand_helper_->AddEditingSelectorsToClass([self class]);
1706 1706
1707 renderWidgetHostView_.reset(r); 1707 renderWidgetHostView_.reset(r);
1708 canBeKeyView_ = YES; 1708 canBeKeyView_ = YES;
1709 opaque_ = YES; 1709 opaque_ = YES;
1710 pinchHasReachedZoomThreshold_ = false; 1710 pinchHasReachedZoomThreshold_ = false;
1711 isStylusEnteringProximity_ = false;
mustaq 2016/10/14 16:07:17 I think the name |isStylusInProximity| better refl
1711 1712
1712 // OpenGL support: 1713 // OpenGL support:
1713 if ([self respondsToSelector: 1714 if ([self respondsToSelector:
1714 @selector(setWantsBestResolutionOpenGLSurface:)]) { 1715 @selector(setWantsBestResolutionOpenGLSurface:)]) {
1715 [self setWantsBestResolutionOpenGLSurface:YES]; 1716 [self setWantsBestResolutionOpenGLSurface:YES];
1716 } 1717 }
1717 [[NSNotificationCenter defaultCenter] 1718 [[NSNotificationCenter defaultCenter]
1718 addObserver:self 1719 addObserver:self
1719 selector:@selector(didChangeScreenParameters:) 1720 selector:@selector(didChangeScreenParameters:)
1720 name:NSApplicationDidChangeScreenParametersNotification 1721 name:NSApplicationDidChangeScreenParametersNotification
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1848 1849
1849 - (void)mouseEvent:(NSEvent*)theEvent { 1850 - (void)mouseEvent:(NSEvent*)theEvent {
1850 TRACE_EVENT0("browser", "RenderWidgetHostViewCocoa::mouseEvent"); 1851 TRACE_EVENT0("browser", "RenderWidgetHostViewCocoa::mouseEvent");
1851 if (responderDelegate_ && 1852 if (responderDelegate_ &&
1852 [responderDelegate_ respondsToSelector:@selector(handleEvent:)]) { 1853 [responderDelegate_ respondsToSelector:@selector(handleEvent:)]) {
1853 BOOL handled = [responderDelegate_ handleEvent:theEvent]; 1854 BOOL handled = [responderDelegate_ handleEvent:theEvent];
1854 if (handled) 1855 if (handled)
1855 return; 1856 return;
1856 } 1857 }
1857 1858
1859 // Set the pointer type when we are receiving a NSMouseEntered event and the
1860 // following NSMouseExited event should have the same pointer type.
1861 NSEventType type = [theEvent type];
1862 if (type == NSMouseEntered) {
1863 pointerType_ = isStylusEnteringProximity_
1864 ? blink::WebPointerProperties::PointerType::Pen
1865 : blink::WebPointerProperties::PointerType::Mouse;
1866 }
1867
1858 if ([self shouldIgnoreMouseEvent:theEvent]) { 1868 if ([self shouldIgnoreMouseEvent:theEvent]) {
1859 // If this is the first such event, send a mouse exit to the host view. 1869 // If this is the first such event, send a mouse exit to the host view.
1860 if (!mouseEventWasIgnored_ && renderWidgetHostView_->render_widget_host_) { 1870 if (!mouseEventWasIgnored_ && renderWidgetHostView_->render_widget_host_) {
1861 WebMouseEvent exitEvent = WebMouseEventBuilder::Build(theEvent, self); 1871 WebMouseEvent exitEvent =
1872 WebMouseEventBuilder::Build(theEvent, self, pointerType_);
1862 exitEvent.type = WebInputEvent::MouseLeave; 1873 exitEvent.type = WebInputEvent::MouseLeave;
1863 exitEvent.button = WebMouseEvent::Button::NoButton; 1874 exitEvent.button = WebMouseEvent::Button::NoButton;
1864 renderWidgetHostView_->ForwardMouseEvent(exitEvent); 1875 renderWidgetHostView_->ForwardMouseEvent(exitEvent);
1865 } 1876 }
1866 mouseEventWasIgnored_ = YES; 1877 mouseEventWasIgnored_ = YES;
1867 return; 1878 return;
1868 } 1879 }
1869 1880
1870 if (mouseEventWasIgnored_) { 1881 if (mouseEventWasIgnored_) {
1871 // If this is the first mouse event after a previous event that was ignored 1882 // If this is the first mouse event after a previous event that was ignored
1872 // due to the hitTest, send a mouse enter event to the host view. 1883 // due to the hitTest, send a mouse enter event to the host view.
1873 if (renderWidgetHostView_->render_widget_host_) { 1884 if (renderWidgetHostView_->render_widget_host_) {
1874 WebMouseEvent enterEvent = WebMouseEventBuilder::Build(theEvent, self); 1885 WebMouseEvent enterEvent =
1886 WebMouseEventBuilder::Build(theEvent, self, pointerType_);
1875 enterEvent.type = WebInputEvent::MouseMove; 1887 enterEvent.type = WebInputEvent::MouseMove;
1876 enterEvent.button = WebMouseEvent::Button::NoButton; 1888 enterEvent.button = WebMouseEvent::Button::NoButton;
1877 ui::LatencyInfo latency_info(ui::SourceEventType::OTHER); 1889 ui::LatencyInfo latency_info(ui::SourceEventType::OTHER);
1878 latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); 1890 latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0);
1879 if (renderWidgetHostView_->ShouldRouteEvent(enterEvent)) { 1891 if (renderWidgetHostView_->ShouldRouteEvent(enterEvent)) {
1880 renderWidgetHostView_->render_widget_host_->delegate() 1892 renderWidgetHostView_->render_widget_host_->delegate()
1881 ->GetInputEventRouter() 1893 ->GetInputEventRouter()
1882 ->RouteMouseEvent(renderWidgetHostView_.get(), &enterEvent, 1894 ->RouteMouseEvent(renderWidgetHostView_.get(), &enterEvent,
1883 latency_info); 1895 latency_info);
1884 } else { 1896 } else {
1885 renderWidgetHostView_->ProcessMouseEvent(enterEvent, latency_info); 1897 renderWidgetHostView_->ProcessMouseEvent(enterEvent, latency_info);
1886 } 1898 }
1887 } 1899 }
1888 } 1900 }
1889 mouseEventWasIgnored_ = NO; 1901 mouseEventWasIgnored_ = NO;
1890 1902
1891 // Don't cancel child popups; killing them on a mouse click would prevent the 1903 // Don't cancel child popups; killing them on a mouse click would prevent the
1892 // user from positioning the insertion point in the text field spawning the 1904 // user from positioning the insertion point in the text field spawning the
1893 // popup. A click outside the text field would cause the text field to drop 1905 // popup. A click outside the text field would cause the text field to drop
1894 // the focus, and then EditorClientImpl::textFieldDidEndEditing() would cancel 1906 // the focus, and then EditorClientImpl::textFieldDidEndEditing() would cancel
1895 // the popup anyway, so we're OK. 1907 // the popup anyway, so we're OK.
1896
1897 NSEventType type = [theEvent type];
1898 if (type == NSLeftMouseDown) 1908 if (type == NSLeftMouseDown)
1899 hasOpenMouseDown_ = YES; 1909 hasOpenMouseDown_ = YES;
1900 else if (type == NSLeftMouseUp) 1910 else if (type == NSLeftMouseUp)
1901 hasOpenMouseDown_ = NO; 1911 hasOpenMouseDown_ = NO;
1902 1912
1903 // TODO(suzhe): We should send mouse events to the input method first if it 1913 // TODO(suzhe): We should send mouse events to the input method first if it
1904 // wants to handle them. But it won't work without implementing method 1914 // wants to handle them. But it won't work without implementing method
1905 // - (NSUInteger)characterIndexForPoint:. 1915 // - (NSUInteger)characterIndexForPoint:.
1906 // See: http://code.google.com/p/chromium/issues/detail?id=47141 1916 // See: http://code.google.com/p/chromium/issues/detail?id=47141
1907 // Instead of sending mouse events to the input method first, we now just 1917 // Instead of sending mouse events to the input method first, we now just
1908 // simply confirm all ongoing composition here. 1918 // simply confirm all ongoing composition here.
1909 if (type == NSLeftMouseDown || type == NSRightMouseDown || 1919 if (type == NSLeftMouseDown || type == NSRightMouseDown ||
1910 type == NSOtherMouseDown) { 1920 type == NSOtherMouseDown) {
1911 [self finishComposingText]; 1921 [self finishComposingText];
1912 } 1922 }
1913 1923
1914 WebMouseEvent event = WebMouseEventBuilder::Build(theEvent, self); 1924 WebMouseEvent event =
1925 WebMouseEventBuilder::Build(theEvent, self, pointerType_);
1915 ui::LatencyInfo latency_info(ui::SourceEventType::OTHER); 1926 ui::LatencyInfo latency_info(ui::SourceEventType::OTHER);
1916 latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); 1927 latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0);
1917 if (renderWidgetHostView_->ShouldRouteEvent(event)) { 1928 if (renderWidgetHostView_->ShouldRouteEvent(event)) {
1918 renderWidgetHostView_->render_widget_host_->delegate() 1929 renderWidgetHostView_->render_widget_host_->delegate()
1919 ->GetInputEventRouter() 1930 ->GetInputEventRouter()
1920 ->RouteMouseEvent(renderWidgetHostView_.get(), &event, latency_info); 1931 ->RouteMouseEvent(renderWidgetHostView_.get(), &event, latency_info);
1921 } else { 1932 } else {
1922 renderWidgetHostView_->ProcessMouseEvent(event, latency_info); 1933 renderWidgetHostView_->ProcessMouseEvent(event, latency_info);
1923 } 1934 }
1924 } 1935 }
1925 1936
1937 - (void)tabletEvent:(NSEvent*)theEvent {
1938 if ([theEvent type] == NSTabletProximity)
1939 isStylusEnteringProximity_ = [theEvent isEnteringProximity];
1940 }
1941
1926 - (BOOL)performKeyEquivalent:(NSEvent*)theEvent { 1942 - (BOOL)performKeyEquivalent:(NSEvent*)theEvent {
1927 // |performKeyEquivalent:| is sent to all views of a window, not only down the 1943 // |performKeyEquivalent:| is sent to all views of a window, not only down the
1928 // responder chain (cf. "Handling Key Equivalents" in 1944 // responder chain (cf. "Handling Key Equivalents" in
1929 // http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Event Overview/HandlingKeyEvents/HandlingKeyEvents.html 1945 // http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Event Overview/HandlingKeyEvents/HandlingKeyEvents.html
1930 // ). We only want to handle key equivalents if we're first responder. 1946 // ). We only want to handle key equivalents if we're first responder.
1931 if ([[self window] firstResponder] != self) 1947 if ([[self window] firstResponder] != self)
1932 return NO; 1948 return NO;
1933 1949
1934 // If the event is reserved by the system, then do not pass it to web content. 1950 // If the event is reserved by the system, then do not pass it to web content.
1935 if (EventIsReservedBySystem(theEvent)) 1951 if (EventIsReservedBySystem(theEvent))
(...skipping 1437 matching lines...) Expand 10 before | Expand all | Expand 10 after
3373 3389
3374 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 3390 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
3375 // regions that are not draggable. (See ControlRegionView in 3391 // regions that are not draggable. (See ControlRegionView in
3376 // native_app_window_cocoa.mm). This requires the render host view to be 3392 // native_app_window_cocoa.mm). This requires the render host view to be
3377 // draggable by default. 3393 // draggable by default.
3378 - (BOOL)mouseDownCanMoveWindow { 3394 - (BOOL)mouseDownCanMoveWindow {
3379 return YES; 3395 return YES;
3380 } 3396 }
3381 3397
3382 @end 3398 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698