| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/browser/renderer_host/render_widget_host_view_mac.h" | 5 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" |
| 6 | 6 |
| 7 #include "base/histogram.h" | 7 #include "base/histogram.h" |
| 8 #include "base/scoped_nsobject.h" | 8 #include "base/scoped_nsobject.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "webkit/api/public/WebInputEvent.h" | 22 #include "webkit/api/public/WebInputEvent.h" |
| 23 #include "webkit/glue/webmenurunner_mac.h" | 23 #include "webkit/glue/webmenurunner_mac.h" |
| 24 | 24 |
| 25 using WebKit::WebInputEventFactory; | 25 using WebKit::WebInputEventFactory; |
| 26 using WebKit::WebMouseEvent; | 26 using WebKit::WebMouseEvent; |
| 27 using WebKit::WebMouseWheelEvent; | 27 using WebKit::WebMouseWheelEvent; |
| 28 | 28 |
| 29 @interface RenderWidgetHostViewCocoa (Private) | 29 @interface RenderWidgetHostViewCocoa (Private) |
| 30 + (BOOL)shouldAutohideCursorForEvent:(NSEvent*)event; | 30 + (BOOL)shouldAutohideCursorForEvent:(NSEvent*)event; |
| 31 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r; | 31 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r; |
| 32 - (void)keyEvent:(NSEvent *)theEvent wasKeyEquivalent:(BOOL)equiv; | |
| 33 - (void)cancelChildPopups; | 32 - (void)cancelChildPopups; |
| 34 @end | 33 @end |
| 35 | 34 |
| 36 namespace { | 35 namespace { |
| 37 | 36 |
| 38 // Maximum number of characters we allow in a tooltip. | 37 // Maximum number of characters we allow in a tooltip. |
| 39 const size_t kMaxTooltipLength = 1024; | 38 const size_t kMaxTooltipLength = 1024; |
| 40 | 39 |
| 41 } | 40 } |
| 42 | 41 |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 // the focus, and then EditorClientImpl::textFieldDidEndEditing() would cancel | 530 // the focus, and then EditorClientImpl::textFieldDidEndEditing() would cancel |
| 532 // the popup anyway, so we're OK. | 531 // the popup anyway, so we're OK. |
| 533 | 532 |
| 534 const WebMouseEvent& event = | 533 const WebMouseEvent& event = |
| 535 WebInputEventFactory::mouseEvent(theEvent, self); | 534 WebInputEventFactory::mouseEvent(theEvent, self); |
| 536 if (renderWidgetHostView_->render_widget_host_) | 535 if (renderWidgetHostView_->render_widget_host_) |
| 537 renderWidgetHostView_->render_widget_host_->ForwardMouseEvent(event); | 536 renderWidgetHostView_->render_widget_host_->ForwardMouseEvent(event); |
| 538 } | 537 } |
| 539 | 538 |
| 540 - (BOOL)performKeyEquivalent:(NSEvent*)theEvent { | 539 - (BOOL)performKeyEquivalent:(NSEvent*)theEvent { |
| 541 // |performKeyEquivalent:| is sent to the whole view tree, not only down the | 540 // We have some magic in |CrApplication sendEvent:| that always sends key |
| 542 // responder chain. We only want to handle key equivalents if we're first | 541 // events to |keyEvent:| so that cocoa doesn't have a chance to intercept it. |
| 543 // responder. | 542 DCHECK([[self window] firstResponder] != self); |
| 544 if ([[self window] firstResponder] != self) | 543 return NO; |
| 545 return NO; | |
| 546 | |
| 547 // If we return |NO| from this function, cocoa will send the key event to | |
| 548 // the menu and only if the menu does not process the event to |keyDown:|. We | |
| 549 // want to send the event to a renderer _before_ sending it to the menu, so | |
| 550 // we need to return |YES| for all events that might be swallowed by the menu. | |
| 551 // We do not return |YES| for every keypress because we don't get |keyDown:| | |
| 552 // events for keys that we handle this way. | |
| 553 NSUInteger modifierFlags = [theEvent modifierFlags]; | |
| 554 if ((modifierFlags & NSCommandKeyMask) == 0) { | |
| 555 // Make sure the menu does not contain key equivalents that don't | |
| 556 // contain cmd. | |
| 557 DCHECK(![[NSApp mainMenu] performKeyEquivalent:theEvent]); | |
| 558 return NO; | |
| 559 } | |
| 560 | |
| 561 // Command key combinations are sent via performKeyEquivalent rather than | |
| 562 // keyDown:. We just forward this on and if WebCore doesn't want to handle | |
| 563 // it, we let the TabContentsView figure out how to reinject it. | |
| 564 [self keyEvent:theEvent wasKeyEquivalent:YES]; | |
| 565 return YES; | |
| 566 } | 544 } |
| 567 | 545 |
| 568 - (void)keyEvent:(NSEvent*)theEvent { | 546 - (void)keyEvent:(NSEvent*)theEvent { |
| 569 [self keyEvent:theEvent wasKeyEquivalent:NO]; | |
| 570 } | |
| 571 | |
| 572 - (void)keyEvent:(NSEvent *)theEvent wasKeyEquivalent:(BOOL)equiv { | |
| 573 DCHECK([theEvent type] != NSKeyDown || | |
| 574 !equiv == !([theEvent modifierFlags] & NSCommandKeyMask)); | |
| 575 // TODO(avi): Possibly kill self? See RenderWidgetHostViewWin::OnKeyEvent and | 547 // TODO(avi): Possibly kill self? See RenderWidgetHostViewWin::OnKeyEvent and |
| 576 // http://b/issue?id=1192881 . | 548 // http://b/issue?id=1192881 . |
| 577 | 549 |
| 578 // Don't cancel child popups; the key events are probably what's triggering | 550 // Don't cancel child popups; the key events are probably what's triggering |
| 579 // the popup in the first place. | 551 // the popup in the first place. |
| 580 | 552 |
| 581 NativeWebKeyboardEvent event(theEvent); | 553 NativeWebKeyboardEvent event(theEvent); |
| 582 | 554 |
| 583 // Save the modifier keys so the insertText method can use it when it sends | 555 // Save the modifier keys so the insertText method can use it when it sends |
| 584 // a Char event, which is dispatched as an onkeypress() event of JavaScript. | 556 // a Char event, which is dispatched as an onkeypress() event of JavaScript. |
| (...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1267 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); | 1239 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); |
| 1268 } else { | 1240 } else { |
| 1269 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( | 1241 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( |
| 1270 UTF8ToUTF16([im_text UTF8String])); | 1242 UTF8ToUTF16([im_text UTF8String])); |
| 1271 } | 1243 } |
| 1272 renderWidgetHostView_->im_composing_ = false; | 1244 renderWidgetHostView_->im_composing_ = false; |
| 1273 } | 1245 } |
| 1274 | 1246 |
| 1275 @end | 1247 @end |
| 1276 | 1248 |
| OLD | NEW |