| 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 <QuartzCore/QuartzCore.h> | 8 #include <QuartzCore/QuartzCore.h> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 return ui::GetImageScale(ui::GetScaleFactorForNativeView(view)); | 136 return ui::GetImageScale(ui::GetScaleFactorForNativeView(view)); |
| 137 } | 137 } |
| 138 | 138 |
| 139 // Private methods: | 139 // Private methods: |
| 140 @interface RenderWidgetHostViewCocoa () | 140 @interface RenderWidgetHostViewCocoa () |
| 141 @property(nonatomic, assign) NSRange selectedRange; | 141 @property(nonatomic, assign) NSRange selectedRange; |
| 142 @property(nonatomic, assign) NSRange markedRange; | 142 @property(nonatomic, assign) NSRange markedRange; |
| 143 | 143 |
| 144 + (BOOL)shouldAutohideCursorForEvent:(NSEvent*)event; | 144 + (BOOL)shouldAutohideCursorForEvent:(NSEvent*)event; |
| 145 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r; | 145 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r; |
| 146 - (void)gotUnhandledWheelEvent; | 146 - (void)gotWheelEventConsumed:(BOOL)consumed; |
| 147 - (void)scrollOffsetPinnedToLeft:(BOOL)left toRight:(BOOL)right; | |
| 148 - (void)setHasHorizontalScrollbar:(BOOL)has_horizontal_scrollbar; | |
| 149 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv; | 147 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv; |
| 150 - (void)windowDidChangeBackingProperties:(NSNotification*)notification; | 148 - (void)windowDidChangeBackingProperties:(NSNotification*)notification; |
| 151 - (void)windowChangedGlobalFrame:(NSNotification*)notification; | 149 - (void)windowChangedGlobalFrame:(NSNotification*)notification; |
| 152 - (void)drawBackingStore:(BackingStoreMac*)backingStore | 150 - (void)drawBackingStore:(BackingStoreMac*)backingStore |
| 153 dirtyRect:(CGRect)dirtyRect | 151 dirtyRect:(CGRect)dirtyRect |
| 154 inContext:(CGContextRef)context; | 152 inContext:(CGContextRef)context; |
| 155 - (void)checkForPluginImeCancellation; | 153 - (void)checkForPluginImeCancellation; |
| 156 - (void)updateScreenProperties; | 154 - (void)updateScreenProperties; |
| 157 - (void)setResponderDelegate: | 155 - (void)setResponderDelegate: |
| 158 (NSObject<RenderWidgetHostViewMacDelegate>*)delegate; | 156 (NSObject<RenderWidgetHostViewMacDelegate>*)delegate; |
| (...skipping 1696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1855 } | 1853 } |
| 1856 | 1854 |
| 1857 gfx::GLSurfaceHandle RenderWidgetHostViewMac::GetCompositingSurface() { | 1855 gfx::GLSurfaceHandle RenderWidgetHostViewMac::GetCompositingSurface() { |
| 1858 // TODO(kbr): may be able to eliminate PluginWindowHandle argument | 1856 // TODO(kbr): may be able to eliminate PluginWindowHandle argument |
| 1859 // completely on Mac OS. | 1857 // completely on Mac OS. |
| 1860 return gfx::GLSurfaceHandle(gfx::kNullPluginWindow, gfx::NATIVE_TRANSPORT); | 1858 return gfx::GLSurfaceHandle(gfx::kNullPluginWindow, gfx::NATIVE_TRANSPORT); |
| 1861 } | 1859 } |
| 1862 | 1860 |
| 1863 void RenderWidgetHostViewMac::SetHasHorizontalScrollbar( | 1861 void RenderWidgetHostViewMac::SetHasHorizontalScrollbar( |
| 1864 bool has_horizontal_scrollbar) { | 1862 bool has_horizontal_scrollbar) { |
| 1865 [cocoa_view_ setHasHorizontalScrollbar:has_horizontal_scrollbar]; | |
| 1866 } | 1863 } |
| 1867 | 1864 |
| 1868 void RenderWidgetHostViewMac::SetScrollOffsetPinning( | 1865 void RenderWidgetHostViewMac::SetScrollOffsetPinning( |
| 1869 bool is_pinned_to_left, bool is_pinned_to_right) { | 1866 bool is_pinned_to_left, bool is_pinned_to_right) { |
| 1870 [cocoa_view_ scrollOffsetPinnedToLeft:is_pinned_to_left | |
| 1871 toRight:is_pinned_to_right]; | |
| 1872 } | 1867 } |
| 1873 | 1868 |
| 1874 bool RenderWidgetHostViewMac::LockMouse() { | 1869 bool RenderWidgetHostViewMac::LockMouse() { |
| 1875 if (mouse_locked_) | 1870 if (mouse_locked_) |
| 1876 return true; | 1871 return true; |
| 1877 | 1872 |
| 1878 mouse_locked_ = true; | 1873 mouse_locked_ = true; |
| 1879 | 1874 |
| 1880 // Lock position of mouse cursor and hide it. | 1875 // Lock position of mouse cursor and hide it. |
| 1881 CGAssociateMouseAndMouseCursorPosition(NO); | 1876 CGAssociateMouseAndMouseCursorPosition(NO); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1893 mouse_locked_ = false; | 1888 mouse_locked_ = false; |
| 1894 | 1889 |
| 1895 // Unlock position of mouse cursor and unhide it. | 1890 // Unlock position of mouse cursor and unhide it. |
| 1896 CGAssociateMouseAndMouseCursorPosition(YES); | 1891 CGAssociateMouseAndMouseCursorPosition(YES); |
| 1897 [NSCursor unhide]; | 1892 [NSCursor unhide]; |
| 1898 | 1893 |
| 1899 if (render_widget_host_) | 1894 if (render_widget_host_) |
| 1900 render_widget_host_->LostMouseLock(); | 1895 render_widget_host_->LostMouseLock(); |
| 1901 } | 1896 } |
| 1902 | 1897 |
| 1903 void RenderWidgetHostViewMac::UnhandledWheelEvent( | 1898 void RenderWidgetHostViewMac::HandledWheelEvent( |
| 1904 const blink::WebMouseWheelEvent& event) { | 1899 const blink::WebMouseWheelEvent& event, |
| 1905 // Only record a wheel event as unhandled if JavaScript handlers got a chance | 1900 bool consumed) { |
| 1906 // to see it (no-op wheel events are ignored by the event dispatcher) | |
| 1907 if (event.deltaX || event.deltaY) | 1901 if (event.deltaX || event.deltaY) |
| 1908 [cocoa_view_ gotUnhandledWheelEvent]; | 1902 [cocoa_view_ gotWheelEventConsumed:consumed]; |
| 1909 } | 1903 } |
| 1910 | 1904 |
| 1911 bool RenderWidgetHostViewMac::Send(IPC::Message* message) { | 1905 bool RenderWidgetHostViewMac::Send(IPC::Message* message) { |
| 1912 if (render_widget_host_) | 1906 if (render_widget_host_) |
| 1913 return render_widget_host_->Send(message); | 1907 return render_widget_host_->Send(message); |
| 1914 delete message; | 1908 delete message; |
| 1915 return false; | 1909 return false; |
| 1916 } | 1910 } |
| 1917 | 1911 |
| 1918 void RenderWidgetHostViewMac::SoftwareFrameWasFreed( | 1912 void RenderWidgetHostViewMac::SoftwareFrameWasFreed( |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2357 responderDelegate_.reset([delegate retain]); | 2351 responderDelegate_.reset([delegate retain]); |
| 2358 } | 2352 } |
| 2359 | 2353 |
| 2360 - (void)resetCursorRects { | 2354 - (void)resetCursorRects { |
| 2361 if (currentCursor_) { | 2355 if (currentCursor_) { |
| 2362 [self addCursorRect:[self visibleRect] cursor:currentCursor_]; | 2356 [self addCursorRect:[self visibleRect] cursor:currentCursor_]; |
| 2363 [currentCursor_ setOnMouseEntered:YES]; | 2357 [currentCursor_ setOnMouseEntered:YES]; |
| 2364 } | 2358 } |
| 2365 } | 2359 } |
| 2366 | 2360 |
| 2367 - (void)gotUnhandledWheelEvent { | 2361 - (void)gotWheelEventConsumed:(BOOL)consumed { |
| 2368 if (responderDelegate_ && | 2362 [responderDelegate_ gotWheelEventConsumed:consumed]; |
| 2369 [responderDelegate_ | |
| 2370 respondsToSelector:@selector(gotUnhandledWheelEvent)]) { | |
| 2371 [responderDelegate_ gotUnhandledWheelEvent]; | |
| 2372 } | |
| 2373 } | |
| 2374 | |
| 2375 - (void)scrollOffsetPinnedToLeft:(BOOL)left toRight:(BOOL)right { | |
| 2376 if (responderDelegate_ && | |
| 2377 [responderDelegate_ | |
| 2378 respondsToSelector:@selector(scrollOffsetPinnedToLeft:toRight:)]) { | |
| 2379 [responderDelegate_ scrollOffsetPinnedToLeft:left toRight:right]; | |
| 2380 } | |
| 2381 } | |
| 2382 | |
| 2383 - (void)setHasHorizontalScrollbar:(BOOL)has_horizontal_scrollbar { | |
| 2384 if (responderDelegate_ && | |
| 2385 [responderDelegate_ | |
| 2386 respondsToSelector:@selector(setHasHorizontalScrollbar:)]) { | |
| 2387 [responderDelegate_ setHasHorizontalScrollbar:has_horizontal_scrollbar]; | |
| 2388 } | |
| 2389 } | 2363 } |
| 2390 | 2364 |
| 2391 - (BOOL)respondsToSelector:(SEL)selector { | 2365 - (BOOL)respondsToSelector:(SEL)selector { |
| 2392 // Trickiness: this doesn't mean "does this object's superclass respond to | 2366 // Trickiness: this doesn't mean "does this object's superclass respond to |
| 2393 // this selector" but rather "does the -respondsToSelector impl from the | 2367 // this selector" but rather "does the -respondsToSelector impl from the |
| 2394 // superclass say that this class responds to the selector". | 2368 // superclass say that this class responds to the selector". |
| 2395 if ([super respondsToSelector:selector]) | 2369 if ([super respondsToSelector:selector]) |
| 2396 return YES; | 2370 return YES; |
| 2397 | 2371 |
| 2398 if (responderDelegate_) | 2372 if (responderDelegate_) |
| (...skipping 1923 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4322 } | 4296 } |
| 4323 | 4297 |
| 4324 - (void)disableRendering { | 4298 - (void)disableRendering { |
| 4325 // Disable the fade-out animation as the layer is removed. | 4299 // Disable the fade-out animation as the layer is removed. |
| 4326 ScopedCAActionDisabler disabler; | 4300 ScopedCAActionDisabler disabler; |
| 4327 [self removeFromSuperlayer]; | 4301 [self removeFromSuperlayer]; |
| 4328 renderWidgetHostView_ = nil; | 4302 renderWidgetHostView_ = nil; |
| 4329 } | 4303 } |
| 4330 | 4304 |
| 4331 @end // implementation SoftwareLayer | 4305 @end // implementation SoftwareLayer |
| OLD | NEW |