| 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 <Carbon/Carbon.h> | 7 #import <Carbon/Carbon.h> |
| 8 #import <objc/runtime.h> | 8 #import <objc/runtime.h> |
| 9 #include <OpenGL/gl.h> | 9 #include <OpenGL/gl.h> |
| 10 #include <QuartzCore/QuartzCore.h> | 10 #include <QuartzCore/QuartzCore.h> |
| (...skipping 1713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1724 self = [super initWithFrame:NSZeroRect]; | 1724 self = [super initWithFrame:NSZeroRect]; |
| 1725 if (self) { | 1725 if (self) { |
| 1726 self.acceptsTouchEvents = YES; | 1726 self.acceptsTouchEvents = YES; |
| 1727 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper); | 1727 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper); |
| 1728 editCommand_helper_->AddEditingSelectorsToClass([self class]); | 1728 editCommand_helper_->AddEditingSelectorsToClass([self class]); |
| 1729 | 1729 |
| 1730 renderWidgetHostView_.reset(r); | 1730 renderWidgetHostView_.reset(r); |
| 1731 canBeKeyView_ = YES; | 1731 canBeKeyView_ = YES; |
| 1732 opaque_ = YES; | 1732 opaque_ = YES; |
| 1733 pinchHasReachedZoomThreshold_ = false; | 1733 pinchHasReachedZoomThreshold_ = false; |
| 1734 isStylusEnteringProximity_ = false; |
| 1734 | 1735 |
| 1735 // OpenGL support: | 1736 // OpenGL support: |
| 1736 if ([self respondsToSelector: | 1737 if ([self respondsToSelector: |
| 1737 @selector(setWantsBestResolutionOpenGLSurface:)]) { | 1738 @selector(setWantsBestResolutionOpenGLSurface:)]) { |
| 1738 [self setWantsBestResolutionOpenGLSurface:YES]; | 1739 [self setWantsBestResolutionOpenGLSurface:YES]; |
| 1739 } | 1740 } |
| 1740 [[NSNotificationCenter defaultCenter] | 1741 [[NSNotificationCenter defaultCenter] |
| 1741 addObserver:self | 1742 addObserver:self |
| 1742 selector:@selector(didChangeScreenParameters:) | 1743 selector:@selector(didChangeScreenParameters:) |
| 1743 name:NSApplicationDidChangeScreenParametersNotification | 1744 name:NSApplicationDidChangeScreenParametersNotification |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1871 | 1872 |
| 1872 - (void)mouseEvent:(NSEvent*)theEvent { | 1873 - (void)mouseEvent:(NSEvent*)theEvent { |
| 1873 TRACE_EVENT0("browser", "RenderWidgetHostViewCocoa::mouseEvent"); | 1874 TRACE_EVENT0("browser", "RenderWidgetHostViewCocoa::mouseEvent"); |
| 1874 if (responderDelegate_ && | 1875 if (responderDelegate_ && |
| 1875 [responderDelegate_ respondsToSelector:@selector(handleEvent:)]) { | 1876 [responderDelegate_ respondsToSelector:@selector(handleEvent:)]) { |
| 1876 BOOL handled = [responderDelegate_ handleEvent:theEvent]; | 1877 BOOL handled = [responderDelegate_ handleEvent:theEvent]; |
| 1877 if (handled) | 1878 if (handled) |
| 1878 return; | 1879 return; |
| 1879 } | 1880 } |
| 1880 | 1881 |
| 1882 // Set the pointer type when we are receiving a NSMouseEntered event and the |
| 1883 // following NSMouseExited event should have the same pointer type. |
| 1884 NSEventType type = [theEvent type]; |
| 1885 if (type == NSMouseEntered) { |
| 1886 pointerType_ = isStylusEnteringProximity_ |
| 1887 ? blink::WebPointerProperties::PointerType::Pen |
| 1888 : blink::WebPointerProperties::PointerType::Mouse; |
| 1889 } |
| 1890 |
| 1881 if ([self shouldIgnoreMouseEvent:theEvent]) { | 1891 if ([self shouldIgnoreMouseEvent:theEvent]) { |
| 1882 // If this is the first such event, send a mouse exit to the host view. | 1892 // If this is the first such event, send a mouse exit to the host view. |
| 1883 if (!mouseEventWasIgnored_ && renderWidgetHostView_->render_widget_host_) { | 1893 if (!mouseEventWasIgnored_ && renderWidgetHostView_->render_widget_host_) { |
| 1884 WebMouseEvent exitEvent = WebMouseEventBuilder::Build(theEvent, self); | 1894 WebMouseEvent exitEvent = |
| 1895 WebMouseEventBuilder::Build(theEvent, self, pointerType_); |
| 1885 exitEvent.setType(WebInputEvent::MouseLeave); | 1896 exitEvent.setType(WebInputEvent::MouseLeave); |
| 1886 exitEvent.button = WebMouseEvent::Button::NoButton; | 1897 exitEvent.button = WebMouseEvent::Button::NoButton; |
| 1887 renderWidgetHostView_->ForwardMouseEvent(exitEvent); | 1898 renderWidgetHostView_->ForwardMouseEvent(exitEvent); |
| 1888 } | 1899 } |
| 1889 mouseEventWasIgnored_ = YES; | 1900 mouseEventWasIgnored_ = YES; |
| 1890 return; | 1901 return; |
| 1891 } | 1902 } |
| 1892 | 1903 |
| 1893 if (mouseEventWasIgnored_) { | 1904 if (mouseEventWasIgnored_) { |
| 1894 // If this is the first mouse event after a previous event that was ignored | 1905 // If this is the first mouse event after a previous event that was ignored |
| 1895 // due to the hitTest, send a mouse enter event to the host view. | 1906 // due to the hitTest, send a mouse enter event to the host view. |
| 1896 if (renderWidgetHostView_->render_widget_host_) { | 1907 if (renderWidgetHostView_->render_widget_host_) { |
| 1897 WebMouseEvent enterEvent = WebMouseEventBuilder::Build(theEvent, self); | 1908 WebMouseEvent enterEvent = |
| 1909 WebMouseEventBuilder::Build(theEvent, self, pointerType_); |
| 1898 enterEvent.setType(WebInputEvent::MouseMove); | 1910 enterEvent.setType(WebInputEvent::MouseMove); |
| 1899 enterEvent.button = WebMouseEvent::Button::NoButton; | 1911 enterEvent.button = WebMouseEvent::Button::NoButton; |
| 1900 ui::LatencyInfo latency_info(ui::SourceEventType::OTHER); | 1912 ui::LatencyInfo latency_info(ui::SourceEventType::OTHER); |
| 1901 latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 1913 latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
| 1902 if (renderWidgetHostView_->ShouldRouteEvent(enterEvent)) { | 1914 if (renderWidgetHostView_->ShouldRouteEvent(enterEvent)) { |
| 1903 renderWidgetHostView_->render_widget_host_->delegate() | 1915 renderWidgetHostView_->render_widget_host_->delegate() |
| 1904 ->GetInputEventRouter() | 1916 ->GetInputEventRouter() |
| 1905 ->RouteMouseEvent(renderWidgetHostView_.get(), &enterEvent, | 1917 ->RouteMouseEvent(renderWidgetHostView_.get(), &enterEvent, |
| 1906 latency_info); | 1918 latency_info); |
| 1907 } else { | 1919 } else { |
| 1908 renderWidgetHostView_->ProcessMouseEvent(enterEvent, latency_info); | 1920 renderWidgetHostView_->ProcessMouseEvent(enterEvent, latency_info); |
| 1909 } | 1921 } |
| 1910 } | 1922 } |
| 1911 } | 1923 } |
| 1912 mouseEventWasIgnored_ = NO; | 1924 mouseEventWasIgnored_ = NO; |
| 1913 | 1925 |
| 1914 // Don't cancel child popups; killing them on a mouse click would prevent the | 1926 // Don't cancel child popups; killing them on a mouse click would prevent the |
| 1915 // user from positioning the insertion point in the text field spawning the | 1927 // user from positioning the insertion point in the text field spawning the |
| 1916 // popup. A click outside the text field would cause the text field to drop | 1928 // popup. A click outside the text field would cause the text field to drop |
| 1917 // the focus, and then EditorClientImpl::textFieldDidEndEditing() would cancel | 1929 // the focus, and then EditorClientImpl::textFieldDidEndEditing() would cancel |
| 1918 // the popup anyway, so we're OK. | 1930 // the popup anyway, so we're OK. |
| 1919 | |
| 1920 NSEventType type = [theEvent type]; | |
| 1921 if (type == NSLeftMouseDown) | 1931 if (type == NSLeftMouseDown) |
| 1922 hasOpenMouseDown_ = YES; | 1932 hasOpenMouseDown_ = YES; |
| 1923 else if (type == NSLeftMouseUp) | 1933 else if (type == NSLeftMouseUp) |
| 1924 hasOpenMouseDown_ = NO; | 1934 hasOpenMouseDown_ = NO; |
| 1925 | 1935 |
| 1926 // TODO(suzhe): We should send mouse events to the input method first if it | 1936 // TODO(suzhe): We should send mouse events to the input method first if it |
| 1927 // wants to handle them. But it won't work without implementing method | 1937 // wants to handle them. But it won't work without implementing method |
| 1928 // - (NSUInteger)characterIndexForPoint:. | 1938 // - (NSUInteger)characterIndexForPoint:. |
| 1929 // See: http://code.google.com/p/chromium/issues/detail?id=47141 | 1939 // See: http://code.google.com/p/chromium/issues/detail?id=47141 |
| 1930 // Instead of sending mouse events to the input method first, we now just | 1940 // Instead of sending mouse events to the input method first, we now just |
| 1931 // simply confirm all ongoing composition here. | 1941 // simply confirm all ongoing composition here. |
| 1932 if (type == NSLeftMouseDown || type == NSRightMouseDown || | 1942 if (type == NSLeftMouseDown || type == NSRightMouseDown || |
| 1933 type == NSOtherMouseDown) { | 1943 type == NSOtherMouseDown) { |
| 1934 [self finishComposingText]; | 1944 [self finishComposingText]; |
| 1935 } | 1945 } |
| 1936 | 1946 |
| 1937 WebMouseEvent event = WebMouseEventBuilder::Build(theEvent, self); | 1947 WebMouseEvent event = |
| 1948 WebMouseEventBuilder::Build(theEvent, self, pointerType_); |
| 1938 ui::LatencyInfo latency_info(ui::SourceEventType::OTHER); | 1949 ui::LatencyInfo latency_info(ui::SourceEventType::OTHER); |
| 1939 latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 1950 latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
| 1940 if (renderWidgetHostView_->ShouldRouteEvent(event)) { | 1951 if (renderWidgetHostView_->ShouldRouteEvent(event)) { |
| 1941 renderWidgetHostView_->render_widget_host_->delegate() | 1952 renderWidgetHostView_->render_widget_host_->delegate() |
| 1942 ->GetInputEventRouter() | 1953 ->GetInputEventRouter() |
| 1943 ->RouteMouseEvent(renderWidgetHostView_.get(), &event, latency_info); | 1954 ->RouteMouseEvent(renderWidgetHostView_.get(), &event, latency_info); |
| 1944 } else { | 1955 } else { |
| 1945 renderWidgetHostView_->ProcessMouseEvent(event, latency_info); | 1956 renderWidgetHostView_->ProcessMouseEvent(event, latency_info); |
| 1946 } | 1957 } |
| 1947 } | 1958 } |
| 1948 | 1959 |
| 1960 - (void)tabletEvent:(NSEvent*)theEvent { |
| 1961 if ([theEvent type] == NSTabletProximity) |
| 1962 isStylusEnteringProximity_ = [theEvent isEnteringProximity]; |
| 1963 } |
| 1964 |
| 1949 - (BOOL)performKeyEquivalent:(NSEvent*)theEvent { | 1965 - (BOOL)performKeyEquivalent:(NSEvent*)theEvent { |
| 1950 // |performKeyEquivalent:| is sent to all views of a window, not only down the | 1966 // |performKeyEquivalent:| is sent to all views of a window, not only down the |
| 1951 // responder chain (cf. "Handling Key Equivalents" in | 1967 // responder chain (cf. "Handling Key Equivalents" in |
| 1952 // http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Event
Overview/HandlingKeyEvents/HandlingKeyEvents.html | 1968 // http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Event
Overview/HandlingKeyEvents/HandlingKeyEvents.html |
| 1953 // ). We only want to handle key equivalents if we're first responder. | 1969 // ). We only want to handle key equivalents if we're first responder. |
| 1954 if ([[self window] firstResponder] != self) | 1970 if ([[self window] firstResponder] != self) |
| 1955 return NO; | 1971 return NO; |
| 1956 | 1972 |
| 1957 // If the event is reserved by the system, then do not pass it to web content. | 1973 // If the event is reserved by the system, then do not pass it to web content. |
| 1958 if (EventIsReservedBySystem(theEvent)) | 1974 if (EventIsReservedBySystem(theEvent)) |
| (...skipping 1465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3424 | 3440 |
| 3425 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3441 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
| 3426 // regions that are not draggable. (See ControlRegionView in | 3442 // regions that are not draggable. (See ControlRegionView in |
| 3427 // native_app_window_cocoa.mm). This requires the render host view to be | 3443 // native_app_window_cocoa.mm). This requires the render host view to be |
| 3428 // draggable by default. | 3444 // draggable by default. |
| 3429 - (BOOL)mouseDownCanMoveWindow { | 3445 - (BOOL)mouseDownCanMoveWindow { |
| 3430 return YES; | 3446 return YES; |
| 3431 } | 3447 } |
| 3432 | 3448 |
| 3433 @end | 3449 @end |
| OLD | NEW |