| 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 - (void)speakString:(NSString*)string; | 143 - (void)speakString:(NSString*)string; |
| 144 - (void)stopSpeaking:(id)sender; | 144 - (void)stopSpeaking:(id)sender; |
| 145 - (BOOL)isSpeaking; | 145 - (BOOL)isSpeaking; |
| 146 @end | 146 @end |
| 147 | 147 |
| 148 // Private methods: | 148 // Private methods: |
| 149 @interface RenderWidgetHostViewCocoa () | 149 @interface RenderWidgetHostViewCocoa () |
| 150 @property(nonatomic, assign) NSRange selectedRange; | 150 @property(nonatomic, assign) NSRange selectedRange; |
| 151 @property(nonatomic, assign) NSRange markedRange; | 151 @property(nonatomic, assign) NSRange markedRange; |
| 152 | 152 |
| 153 + (BOOL)shouldAutohideCursorForEvent:(NSEvent*)event; | 153 - (BOOL)shouldAutohideCursorForEvent:(NSEvent*)event; |
| 154 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r; | 154 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r; |
| 155 - (void)processedWheelEvent:(const blink::WebMouseWheelEvent&)event | 155 - (void)processedWheelEvent:(const blink::WebMouseWheelEvent&)event |
| 156 consumed:(BOOL)consumed; | 156 consumed:(BOOL)consumed; |
| 157 - (void)processedGestureScrollEvent:(const blink::WebGestureEvent&)event | 157 - (void)processedGestureScrollEvent:(const blink::WebGestureEvent&)event |
| 158 consumed:(BOOL)consumed; | 158 consumed:(BOOL)consumed; |
| 159 | 159 |
| 160 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv; | 160 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv; |
| 161 - (void)windowDidChangeBackingProperties:(NSNotification*)notification; | 161 - (void)windowDidChangeBackingProperties:(NSNotification*)notification; |
| 162 - (void)windowChangedGlobalFrame:(NSNotification*)notification; | 162 - (void)windowChangedGlobalFrame:(NSNotification*)notification; |
| 163 - (void)windowDidBecomeKey:(NSNotification*)notification; | 163 - (void)windowDidBecomeKey:(NSNotification*)notification; |
| (...skipping 1976 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2140 auto numErased = keyDownCodes_.erase([theEvent keyCode]); | 2140 auto numErased = keyDownCodes_.erase([theEvent keyCode]); |
| 2141 if (numErased < 1) | 2141 if (numErased < 1) |
| 2142 return; | 2142 return; |
| 2143 } | 2143 } |
| 2144 | 2144 |
| 2145 // We only handle key down events and just simply forward other events. | 2145 // We only handle key down events and just simply forward other events. |
| 2146 if ([theEvent type] != NSKeyDown) { | 2146 if ([theEvent type] != NSKeyDown) { |
| 2147 widgetHost->ForwardKeyboardEvent(event); | 2147 widgetHost->ForwardKeyboardEvent(event); |
| 2148 | 2148 |
| 2149 // Possibly autohide the cursor. | 2149 // Possibly autohide the cursor. |
| 2150 if ([RenderWidgetHostViewCocoa shouldAutohideCursorForEvent:theEvent]) | 2150 if ([self shouldAutohideCursorForEvent:theEvent]) |
| 2151 [NSCursor setHiddenUntilMouseMoves:YES]; | 2151 [NSCursor setHiddenUntilMouseMoves:YES]; |
| 2152 | 2152 |
| 2153 return; | 2153 return; |
| 2154 } | 2154 } |
| 2155 | 2155 |
| 2156 keyDownCodes_.insert([theEvent keyCode]); | 2156 keyDownCodes_.insert([theEvent keyCode]); |
| 2157 | 2157 |
| 2158 base::scoped_nsobject<RenderWidgetHostViewCocoa> keepSelfAlive([self retain]); | 2158 base::scoped_nsobject<RenderWidgetHostViewCocoa> keepSelfAlive([self retain]); |
| 2159 | 2159 |
| 2160 // Records the current marked text state, so that we can know if the marked | 2160 // Records the current marked text state, so that we can know if the marked |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2306 // We don't get insertText: calls if ctrl or cmd is down, or the key event | 2306 // We don't get insertText: calls if ctrl or cmd is down, or the key event |
| 2307 // generates an insert command. So synthesize a keypress event for these | 2307 // generates an insert command. So synthesize a keypress event for these |
| 2308 // cases, unless the key event generated any other command. | 2308 // cases, unless the key event generated any other command. |
| 2309 event.SetType(blink::WebInputEvent::kChar); | 2309 event.SetType(blink::WebInputEvent::kChar); |
| 2310 event.skip_in_browser = true; | 2310 event.skip_in_browser = true; |
| 2311 widgetHost->ForwardKeyboardEvent(event); | 2311 widgetHost->ForwardKeyboardEvent(event); |
| 2312 } | 2312 } |
| 2313 } | 2313 } |
| 2314 | 2314 |
| 2315 // Possibly autohide the cursor. | 2315 // Possibly autohide the cursor. |
| 2316 if ([RenderWidgetHostViewCocoa shouldAutohideCursorForEvent:theEvent]) | 2316 if ([self shouldAutohideCursorForEvent:theEvent]) |
| 2317 [NSCursor setHiddenUntilMouseMoves:YES]; | 2317 [NSCursor setHiddenUntilMouseMoves:YES]; |
| 2318 } | 2318 } |
| 2319 | 2319 |
| 2320 - (void)forceTouchEvent:(NSEvent*)theEvent { | 2320 - (void)forceTouchEvent:(NSEvent*)theEvent { |
| 2321 if (ui::ForceClickInvokesQuickLook()) | 2321 if (ui::ForceClickInvokesQuickLook()) |
| 2322 [self quickLookWithEvent:theEvent]; | 2322 [self quickLookWithEvent:theEvent]; |
| 2323 } | 2323 } |
| 2324 | 2324 |
| 2325 - (void)shortCircuitScrollWheelEvent:(NSEvent*)event { | 2325 - (void)shortCircuitScrollWheelEvent:(NSEvent*)event { |
| 2326 if ([event phase] != NSEventPhaseEnded && | 2326 if ([event phase] != NSEventPhaseEnded && |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2824 return editCommand_helper_->IsMenuItemEnabled(action, self); | 2824 return editCommand_helper_->IsMenuItemEnabled(action, self); |
| 2825 } | 2825 } |
| 2826 | 2826 |
| 2827 - (RenderWidgetHostViewMac*)renderWidgetHostViewMac { | 2827 - (RenderWidgetHostViewMac*)renderWidgetHostViewMac { |
| 2828 return renderWidgetHostView_.get(); | 2828 return renderWidgetHostView_.get(); |
| 2829 } | 2829 } |
| 2830 | 2830 |
| 2831 // Determine whether we should autohide the cursor (i.e., hide it until mouse | 2831 // Determine whether we should autohide the cursor (i.e., hide it until mouse |
| 2832 // move) for the given event. Customize here to be more selective about which | 2832 // move) for the given event. Customize here to be more selective about which |
| 2833 // key presses to autohide on. | 2833 // key presses to autohide on. |
| 2834 + (BOOL)shouldAutohideCursorForEvent:(NSEvent*)event { | 2834 - (BOOL)shouldAutohideCursorForEvent:(NSEvent*)event { |
| 2835 return ([event type] == NSKeyDown && | 2835 return (renderWidgetHostView_->GetTextInputType() != |
| 2836 !([event modifierFlags] & NSCommandKeyMask)) ? YES : NO; | 2836 ui::TEXT_INPUT_TYPE_NONE && |
| 2837 [event type] == NSKeyDown && |
| 2838 !([event modifierFlags] & NSCommandKeyMask)) |
| 2839 ? YES |
| 2840 : NO; |
| 2837 } | 2841 } |
| 2838 | 2842 |
| 2839 - (NSArray *)accessibilityArrayAttributeValues:(NSString *)attribute | 2843 - (NSArray *)accessibilityArrayAttributeValues:(NSString *)attribute |
| 2840 index:(NSUInteger)index | 2844 index:(NSUInteger)index |
| 2841 maxCount:(NSUInteger)maxCount { | 2845 maxCount:(NSUInteger)maxCount { |
| 2842 NSArray* fullArray = [self accessibilityAttributeValue:attribute]; | 2846 NSArray* fullArray = [self accessibilityAttributeValue:attribute]; |
| 2843 NSUInteger totalLength = [fullArray count]; | 2847 NSUInteger totalLength = [fullArray count]; |
| 2844 if (index >= totalLength) | 2848 if (index >= totalLength) |
| 2845 return nil; | 2849 return nil; |
| 2846 NSUInteger length = MIN(totalLength - index, maxCount); | 2850 NSUInteger length = MIN(totalLength - index, maxCount); |
| (...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3514 | 3518 |
| 3515 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3519 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
| 3516 // regions that are not draggable. (See ControlRegionView in | 3520 // regions that are not draggable. (See ControlRegionView in |
| 3517 // native_app_window_cocoa.mm). This requires the render host view to be | 3521 // native_app_window_cocoa.mm). This requires the render host view to be |
| 3518 // draggable by default. | 3522 // draggable by default. |
| 3519 - (BOOL)mouseDownCanMoveWindow { | 3523 - (BOOL)mouseDownCanMoveWindow { |
| 3520 return YES; | 3524 return YES; |
| 3521 } | 3525 } |
| 3522 | 3526 |
| 3523 @end | 3527 @end |
| OLD | NEW |