Chromium Code Reviews| 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 #import "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" |
| 11 #include "chrome/browser/browser_trial.h" | 11 #include "chrome/browser/browser_trial.h" |
| 12 #import "chrome/browser/cocoa/rwhvm_editcommand_helper.h" | 12 #import "chrome/browser/cocoa/rwhvm_editcommand_helper.h" |
| 13 #include "chrome/browser/renderer_host/backing_store.h" | 13 #include "chrome/browser/renderer_host/backing_store.h" |
| 14 #include "chrome/browser/renderer_host/render_process_host.h" | 14 #include "chrome/browser/renderer_host/render_process_host.h" |
| 15 #include "chrome/browser/renderer_host/render_widget_host.h" | 15 #include "chrome/browser/renderer_host/render_widget_host.h" |
| 16 #include "chrome/browser/spellchecker_platform_engine.h" | 16 #include "chrome/browser/spellchecker_platform_engine.h" |
| 17 #include "chrome/common/native_web_keyboard_event.h" | 17 #include "chrome/common/native_web_keyboard_event.h" |
| 18 #include "chrome/common/edit_command.h" | 18 #include "chrome/common/edit_command.h" |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 537 } | 537 } |
| 538 | 538 |
| 539 - (void)setIgnoreKeyEvents:(BOOL)ignorekeyEvents { | 539 - (void)setIgnoreKeyEvents:(BOOL)ignorekeyEvents { |
| 540 ignoreKeyEvents_ = ignorekeyEvents; | 540 ignoreKeyEvents_ = ignorekeyEvents; |
| 541 } | 541 } |
| 542 | 542 |
| 543 - (BOOL)performKeyEquivalent:(NSEvent*)theEvent { | 543 - (BOOL)performKeyEquivalent:(NSEvent*)theEvent { |
| 544 if (ignoreKeyEvents_) | 544 if (ignoreKeyEvents_) |
| 545 return NO; | 545 return NO; |
| 546 | 546 |
| 547 // We have some magic in |CrApplication sendEvent:| that always sends key | 547 // We have some magic in |CrApplication sendEvent:| that always sends key |
| 548 // events to |keyEvent:| so that cocoa doesn't have a chance to intercept it. | 548 // events to |keyEvent:| so that cocoa doesn't have a chance to intercept it. |
| 549 DCHECK([[self window] firstResponder] != self); | 549 DCHECK([[self window] firstResponder] != self); |
| 550 return NO; | 550 return NO; |
| 551 } | 551 } |
| 552 | 552 |
| 553 - (void)keyEvent:(NSEvent*)theEvent { | 553 - (void)keyEvent:(NSEvent*)theEvent { |
| 554 if (ignoreKeyEvents_) | 554 if (ignoreKeyEvents_) |
| 555 return; | 555 return; |
| 556 | 556 |
| 557 // TODO(avi): Possibly kill self? See RenderWidgetHostViewWin::OnKeyEvent and | 557 scoped_nsobject<RenderWidgetHostViewCocoa> keepSelfAlive([self retain]); |
|
pink (ping after 24hrs)
2009/10/28 19:56:40
in mozilla these were generally named kungFuDeathG
| |
| 558 // http://b/issue?id=1192881 . | |
| 559 | 558 |
| 560 // Don't cancel child popups; the key events are probably what's triggering | 559 // Don't cancel child popups; the key events are probably what's triggering |
| 561 // the popup in the first place. | 560 // the popup in the first place. |
| 562 | 561 |
| 563 NativeWebKeyboardEvent event(theEvent); | 562 NativeWebKeyboardEvent event(theEvent); |
| 564 | 563 |
| 565 // Save the modifier keys so the insertText method can use it when it sends | 564 // Save the modifier keys so the insertText method can use it when it sends |
| 566 // a Char event, which is dispatched as an onkeypress() event of JavaScript. | 565 // a Char event, which is dispatched as an onkeypress() event of JavaScript. |
| 567 renderWidgetHostView_->im_modifiers_ = event.modifiers; | 566 renderWidgetHostView_->im_modifiers_ = event.modifiers; |
| 568 | 567 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 584 [EditCommandMatcher matchEditCommands:&editCommands forEvent:theEvent]; | 583 [EditCommandMatcher matchEditCommands:&editCommands forEvent:theEvent]; |
| 585 if (!editCommands.empty()) | 584 if (!editCommands.empty()) |
| 586 widgetHost->ForwardEditCommandsForNextKeyEvent(editCommands); | 585 widgetHost->ForwardEditCommandsForNextKeyEvent(editCommands); |
| 587 widgetHost->ForwardKeyboardEvent(event); | 586 widgetHost->ForwardKeyboardEvent(event); |
| 588 } | 587 } |
| 589 | 588 |
| 590 // Dispatch a NSKeyDown event to an input method. | 589 // Dispatch a NSKeyDown event to an input method. |
| 591 // To send an onkeydown() event before an onkeypress() event, we should | 590 // To send an onkeydown() event before an onkeypress() event, we should |
| 592 // dispatch this NSKeyDown event AFTER sending it to the renderer. | 591 // dispatch this NSKeyDown event AFTER sending it to the renderer. |
| 593 // (See <https://bugs.webkit.org/show_bug.cgi?id=25119>). | 592 // (See <https://bugs.webkit.org/show_bug.cgi?id=25119>). |
| 594 if ([theEvent type] == NSKeyDown) | 593 // |
| 594 // If this object's retainCount is 1, the only reference is the one held by | |
| 595 // keepSelfAlive. All other references may have been destroyed in the | |
| 596 // RenderWidgetHost::ForwardKeyboardEvent call above if it resulted in tab | |
| 597 // closure. Were it not for that single reference, this object would | |
| 598 // already be deallocated. In that case, there's no point in calling | |
| 599 // -interpretKeyEvents:. | |
| 600 if ([self retainCount] > 1 && [theEvent type] == NSKeyDown) | |
| 595 [self interpretKeyEvents:[NSArray arrayWithObject:theEvent]]; | 601 [self interpretKeyEvents:[NSArray arrayWithObject:theEvent]]; |
| 596 | 602 |
| 597 // Possibly autohide the cursor. | 603 // Possibly autohide the cursor. |
| 598 if ([RenderWidgetHostViewCocoa shouldAutohideCursorForEvent:theEvent]) | 604 if ([RenderWidgetHostViewCocoa shouldAutohideCursorForEvent:theEvent]) |
| 599 [NSCursor setHiddenUntilMouseMoves:YES]; | 605 [NSCursor setHiddenUntilMouseMoves:YES]; |
| 600 } | 606 } |
| 601 | 607 |
| 602 - (void)scrollWheel:(NSEvent *)theEvent { | 608 - (void)scrollWheel:(NSEvent *)theEvent { |
| 603 [self cancelChildPopups]; | 609 [self cancelChildPopups]; |
| 604 | 610 |
| (...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1248 base::Time::Now().ToDoubleT()); | 1254 base::Time::Now().ToDoubleT()); |
| 1249 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); | 1255 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); |
| 1250 } else { | 1256 } else { |
| 1251 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( | 1257 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( |
| 1252 UTF8ToUTF16([im_text UTF8String])); | 1258 UTF8ToUTF16([im_text UTF8String])); |
| 1253 } | 1259 } |
| 1254 renderWidgetHostView_->im_composing_ = false; | 1260 renderWidgetHostView_->im_composing_ = false; |
| 1255 } | 1261 } |
| 1256 | 1262 |
| 1257 @end | 1263 @end |
| 1258 | |
| OLD | NEW |