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 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 9 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
| 10 #include "chrome/browser/browser_trial.h" | 11 #include "chrome/browser/browser_trial.h" |
| 11 #import "chrome/browser/cocoa/rwhvm_editcommand_helper.h" | 12 #import "chrome/browser/cocoa/rwhvm_editcommand_helper.h" |
| 12 #include "chrome/browser/renderer_host/backing_store.h" | 13 #include "chrome/browser/renderer_host/backing_store.h" |
| 13 #include "chrome/browser/renderer_host/render_process_host.h" | 14 #include "chrome/browser/renderer_host/render_process_host.h" |
| 14 #include "chrome/browser/renderer_host/render_widget_host.h" | 15 #include "chrome/browser/renderer_host/render_widget_host.h" |
| 15 #include "chrome/browser/spellchecker_platform_engine.h" | 16 #include "chrome/browser/spellchecker_platform_engine.h" |
| 16 #include "chrome/common/native_web_keyboard_event.h" | 17 #include "chrome/common/native_web_keyboard_event.h" |
| 18 #include "chrome/common/edit_command.h" | |
| 17 #include "chrome/common/render_messages.h" | 19 #include "chrome/common/render_messages.h" |
| 18 #include "skia/ext/platform_canvas.h" | 20 #include "skia/ext/platform_canvas.h" |
| 19 #include "webkit/api/public/mac/WebInputEventFactory.h" | 21 #include "webkit/api/public/mac/WebInputEventFactory.h" |
| 20 #include "webkit/api/public/WebInputEvent.h" | 22 #include "webkit/api/public/WebInputEvent.h" |
| 21 #include "webkit/glue/webmenurunner_mac.h" | 23 #include "webkit/glue/webmenurunner_mac.h" |
| 22 | 24 |
| 23 using WebKit::WebInputEventFactory; | 25 using WebKit::WebInputEventFactory; |
| 24 using WebKit::WebMouseEvent; | 26 using WebKit::WebMouseEvent; |
| 25 using WebKit::WebMouseWheelEvent; | 27 using WebKit::WebMouseWheelEvent; |
| 26 | 28 |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 423 render_widget_host_->SetActive(active); | 425 render_widget_host_->SetActive(active); |
| 424 } | 426 } |
| 425 | 427 |
| 426 void RenderWidgetHostViewMac::SetBackground(const SkBitmap& background) { | 428 void RenderWidgetHostViewMac::SetBackground(const SkBitmap& background) { |
| 427 RenderWidgetHostView::SetBackground(background); | 429 RenderWidgetHostView::SetBackground(background); |
| 428 if (render_widget_host_) | 430 if (render_widget_host_) |
| 429 render_widget_host_->Send(new ViewMsg_SetBackground( | 431 render_widget_host_->Send(new ViewMsg_SetBackground( |
| 430 render_widget_host_->routing_id(), background)); | 432 render_widget_host_->routing_id(), background)); |
| 431 } | 433 } |
| 432 | 434 |
| 435 // EditCommandMatcher --------------------------------------------------------- | |
| 436 | |
| 437 // This class is used to capture the shortcuts that a given key event maps to. | |
| 438 // We instantiate a vanilla NSResponder, call interpretKeyEvents on it, and | |
| 439 // record all of the selectors passed into doCommandBySelector while | |
| 440 // interpreting the key event. The selectors are converted into edit commands | |
| 441 // which can be passed to the render process. | |
| 442 // | |
| 443 // Caveats: | |
| 444 // - Shortcuts involving a sequence of key combinations (chords) don't work, | |
| 445 // because we instantiate a new responder for each event. | |
| 446 // - We ignore key combinations that don't include a modifier (ctrl, cmd, alt) | |
| 447 // because this was causing strange behavior (e.g. tab always inserted a tab | |
| 448 // rather than moving to the next field on the page). | |
| 449 | |
| 450 @interface EditCommandMatcher : NSResponder { | |
| 451 EditCommands* edit_commands_; | |
| 452 } | |
| 453 @end | |
| 454 | |
| 455 @implementation EditCommandMatcher | |
| 456 | |
| 457 - (id)initWithEditCommands:(EditCommands*)edit_commands { | |
| 458 if ((self = [super init]) != nil) { | |
| 459 edit_commands_ = edit_commands; | |
| 460 } | |
| 461 return self; | |
| 462 } | |
| 463 | |
| 464 - (void)doCommandBySelector:(SEL)selector { | |
| 465 NSString* editCommand = | |
| 466 RWHVMEditCommandHelper::CommandNameForSelector(selector); | |
| 467 edit_commands_->push_back( | |
| 468 EditCommand(base::SysNSStringToUTF8(editCommand), "")); | |
| 469 } | |
| 470 | |
| 471 - (void)insertText:(id)string { | |
| 472 // If we don't ignore this, then sometimes we get a bell. | |
| 473 } | |
| 474 | |
| 475 + (void)matchEditCommands:(EditCommands*)edit_commands | |
| 476 forEvent:(NSEvent*)theEvent { | |
| 477 if ([theEvent type] != NSKeyDown) return; | |
| 478 // Don't interpret plain key presses. This screws up things like <Tab>. | |
| 479 NSUInteger flags = [theEvent modifierFlags]; | |
| 480 flags &= (NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask); | |
| 481 if (flags == 0) return; | |
| 482 scoped_nsobject<EditCommandMatcher> matcher( | |
| 483 [[EditCommandMatcher alloc] initWithEditCommands:edit_commands]); | |
| 484 [matcher.get() interpretKeyEvents:[NSArray arrayWithObject:theEvent]]; | |
| 485 } | |
| 486 | |
| 487 @end | |
| 488 | |
| 433 // RenderWidgetHostViewCocoa --------------------------------------------------- | 489 // RenderWidgetHostViewCocoa --------------------------------------------------- |
| 434 | 490 |
| 435 @implementation RenderWidgetHostViewCocoa | 491 @implementation RenderWidgetHostViewCocoa |
| 436 | 492 |
| 437 // Tons of stuff goes here, where we grab events going on in Cocoaland and send | 493 // Tons of stuff goes here, where we grab events going on in Cocoaland and send |
| 438 // them into the C++ system. TODO(avi): all that jazz | 494 // them into the C++ system. TODO(avi): all that jazz |
| 439 | 495 |
| 440 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r { | 496 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r { |
| 441 self = [super initWithFrame:NSZeroRect]; | 497 self = [super initWithFrame:NSZeroRect]; |
| 442 if (self != nil) { | 498 if (self != nil) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 492 renderWidgetHostView_->im_modifiers_ = event.modifiers; | 548 renderWidgetHostView_->im_modifiers_ = event.modifiers; |
| 493 | 549 |
| 494 // To emulate Windows, over-write |event.windowsKeyCode| to VK_PROCESSKEY | 550 // To emulate Windows, over-write |event.windowsKeyCode| to VK_PROCESSKEY |
| 495 // while an input method is composing a text. | 551 // while an input method is composing a text. |
| 496 // Gmail checks this code in its onkeydown handler to stop auto-completing | 552 // Gmail checks this code in its onkeydown handler to stop auto-completing |
| 497 // e-mail addresses while composing a CJK text. | 553 // e-mail addresses while composing a CJK text. |
| 498 if ([theEvent type] == NSKeyDown && renderWidgetHostView_->im_composing_) | 554 if ([theEvent type] == NSKeyDown && renderWidgetHostView_->im_composing_) |
| 499 event.windowsKeyCode = 0xE5; | 555 event.windowsKeyCode = 0xE5; |
| 500 | 556 |
| 501 // Dispatch this keyboard event to the renderer. | 557 // Dispatch this keyboard event to the renderer. |
| 502 if (renderWidgetHostView_->render_widget_host_) | 558 if (renderWidgetHostView_->render_widget_host_) { |
| 559 // Look up shortcut, if any, for this key combination. | |
| 560 EditCommands editCommands; | |
| 561 [EditCommandMatcher matchEditCommands:&editCommands forEvent:theEvent]; | |
| 562 if (!editCommands.empty()) | |
| 563 renderWidgetHostView_->render_widget_host_->ForwardEditCommandsForNextKeyE vent( | |
|
Avi (use Gerrit)
2009/09/21 16:45:56
80 columns, please
| |
| 564 editCommands); | |
| 503 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); | 565 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); |
| 566 } | |
| 504 | 567 |
| 505 // Dispatch a NSKeyDown event to an input method. | 568 // Dispatch a NSKeyDown event to an input method. |
| 506 // To send an onkeydown() event before an onkeypress() event, we should | 569 // To send an onkeydown() event before an onkeypress() event, we should |
| 507 // dispatch this NSKeyDown event AFTER sending it to the renderer. | 570 // dispatch this NSKeyDown event AFTER sending it to the renderer. |
| 508 // (See <https://bugs.webkit.org/show_bug.cgi?id=25119>). | 571 // (See <https://bugs.webkit.org/show_bug.cgi?id=25119>). |
| 509 if ([theEvent type] == NSKeyDown) | 572 if ([theEvent type] == NSKeyDown) |
| 510 [self interpretKeyEvents:[NSArray arrayWithObject:theEvent]]; | 573 [self interpretKeyEvents:[NSArray arrayWithObject:theEvent]]; |
| 511 | 574 |
| 512 // Possibly autohide the cursor. | 575 // Possibly autohide the cursor. |
| 513 if ([RenderWidgetHostViewCocoa shouldAutohideCursorForEvent:theEvent]) | 576 if ([RenderWidgetHostViewCocoa shouldAutohideCursorForEvent:theEvent]) |
| (...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1157 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); | 1220 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); |
| 1158 } else { | 1221 } else { |
| 1159 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( | 1222 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( |
| 1160 UTF8ToUTF16([im_text UTF8String])); | 1223 UTF8ToUTF16([im_text UTF8String])); |
| 1161 } | 1224 } |
| 1162 renderWidgetHostView_->im_composing_ = false; | 1225 renderWidgetHostView_->im_composing_ = false; |
| 1163 } | 1226 } |
| 1164 | 1227 |
| 1165 @end | 1228 @end |
| 1166 | 1229 |
| OLD | NEW |