| 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; |
| 32 - (void)cancelChildPopups; | 33 - (void)cancelChildPopups; |
| 33 @end | 34 @end |
| 34 | 35 |
| 35 namespace { | 36 namespace { |
| 36 | 37 |
| 37 // Maximum number of characters we allow in a tooltip. | 38 // Maximum number of characters we allow in a tooltip. |
| 38 const size_t kMaxTooltipLength = 1024; | 39 const size_t kMaxTooltipLength = 1024; |
| 39 | 40 |
| 40 } | 41 } |
| 41 | 42 |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 // popup. A click outside the text field would cause the text field to drop | 530 // popup. A click outside the text field would cause the text field to drop |
| 530 // the focus, and then EditorClientImpl::textFieldDidEndEditing() would cancel | 531 // the focus, and then EditorClientImpl::textFieldDidEndEditing() would cancel |
| 531 // the popup anyway, so we're OK. | 532 // the popup anyway, so we're OK. |
| 532 | 533 |
| 533 const WebMouseEvent& event = | 534 const WebMouseEvent& event = |
| 534 WebInputEventFactory::mouseEvent(theEvent, self); | 535 WebInputEventFactory::mouseEvent(theEvent, self); |
| 535 if (renderWidgetHostView_->render_widget_host_) | 536 if (renderWidgetHostView_->render_widget_host_) |
| 536 renderWidgetHostView_->render_widget_host_->ForwardMouseEvent(event); | 537 renderWidgetHostView_->render_widget_host_->ForwardMouseEvent(event); |
| 537 } | 538 } |
| 538 | 539 |
| 540 - (BOOL)performKeyEquivalent:(NSEvent*)theEvent { |
| 541 // |performKeyEquivalent:| is sent to the whole view tree, not only down the |
| 542 // responder chain. We only want to handle key equivalents if we're first |
| 543 // responder. |
| 544 if ([[self window] firstResponder] != self) |
| 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 } |
| 567 |
| 539 - (void)keyEvent:(NSEvent*)theEvent { | 568 - (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)); |
| 540 // TODO(avi): Possibly kill self? See RenderWidgetHostViewWin::OnKeyEvent and | 575 // TODO(avi): Possibly kill self? See RenderWidgetHostViewWin::OnKeyEvent and |
| 541 // http://b/issue?id=1192881 . | 576 // http://b/issue?id=1192881 . |
| 542 | 577 |
| 543 // Don't cancel child popups; the key events are probably what's triggering | 578 // Don't cancel child popups; the key events are probably what's triggering |
| 544 // the popup in the first place. | 579 // the popup in the first place. |
| 545 | 580 |
| 546 NativeWebKeyboardEvent event(theEvent); | 581 NativeWebKeyboardEvent event(theEvent); |
| 547 | 582 |
| 548 // Save the modifier keys so the insertText method can use it when it sends | 583 // Save the modifier keys so the insertText method can use it when it sends |
| 549 // a Char event, which is dispatched as an onkeypress() event of JavaScript. | 584 // a Char event, which is dispatched as an onkeypress() event of JavaScript. |
| (...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1229 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); | 1264 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); |
| 1230 } else { | 1265 } else { |
| 1231 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( | 1266 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( |
| 1232 UTF8ToUTF16([im_text UTF8String])); | 1267 UTF8ToUTF16([im_text UTF8String])); |
| 1233 } | 1268 } |
| 1234 renderWidgetHostView_->im_composing_ = false; | 1269 renderWidgetHostView_->im_composing_ = false; |
| 1235 } | 1270 } |
| 1236 | 1271 |
| 1237 @end | 1272 @end |
| 1238 | 1273 |
| OLD | NEW |