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 #import "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" |
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 | 696 |
697 // We don't get insertText: calls if ctrl is down and not even a keyDown: | 697 // We don't get insertText: calls if ctrl is down and not even a keyDown: |
698 // call if cmd is down, so synthesize a keypress event for these cases. | 698 // call if cmd is down, so synthesize a keypress event for these cases. |
699 // Note that this makes our behavior deviate from the windows and linux | 699 // Note that this makes our behavior deviate from the windows and linux |
700 // versions of chrome (however, see http://crbug.com/13891 ), but it makes | 700 // versions of chrome (however, see http://crbug.com/13891 ), but it makes |
701 // us behave similar to how Safari behaves. | 701 // us behave similar to how Safari behaves. |
702 if ([theEvent modifierFlags] & (NSControlKeyMask | NSCommandKeyMask) && | 702 if ([theEvent modifierFlags] & (NSControlKeyMask | NSCommandKeyMask) && |
703 lastKeyPressedEvent_.get() != theEvent && | 703 lastKeyPressedEvent_.get() != theEvent && |
704 [[theEvent characters] length] > 0 && | 704 [[theEvent characters] length] > 0 && |
705 renderWidgetHostView_->render_widget_host_) { | 705 renderWidgetHostView_->render_widget_host_) { |
706 NativeWebKeyboardEvent event([[theEvent characters] characterAtIndex:0], | 706 // Just fabricate a Char event by changing the type of the RawKeyDown |
707 ToWebKitModifiers([theEvent modifierFlags]), | 707 // event, to retain all necessary informations, such as unmodifiedText. |
708 base::Time::Now().ToDoubleT()); | 708 event.type = WebKit::WebInputEvent::Char; |
709 // We fire menu items on keydown, we don't want to activate menu items | 709 // We fire menu items on keydown, we don't want to activate menu items |
710 // twice. | 710 // twice. |
711 event.skip_in_browser = true; | 711 event.skip_in_browser = true; |
712 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); | 712 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); |
713 } | 713 } |
714 } | 714 } |
715 | 715 |
716 // Possibly autohide the cursor. | 716 // Possibly autohide the cursor. |
717 if ([RenderWidgetHostViewCocoa shouldAutohideCursorForEvent:theEvent]) | 717 if ([RenderWidgetHostViewCocoa shouldAutohideCursorForEvent:theEvent]) |
718 [NSCursor setHiddenUntilMouseMoves:YES]; | 718 [NSCursor setHiddenUntilMouseMoves:YES]; |
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1345 - (void)doCommandBySelector:(SEL)selector { | 1345 - (void)doCommandBySelector:(SEL)selector { |
1346 // An input method calls this function to dispatch an editing command to be | 1346 // An input method calls this function to dispatch an editing command to be |
1347 // handled by this view. | 1347 // handled by this view. |
1348 // Even though most editing commands has been already handled by the | 1348 // Even though most editing commands has been already handled by the |
1349 // RWHVMEditCommandHelper object, we need to handle an insertNewline: command | 1349 // RWHVMEditCommandHelper object, we need to handle an insertNewline: command |
1350 // and send a '\r' character to WebKit so that WebKit dispatches this | 1350 // and send a '\r' character to WebKit so that WebKit dispatches this |
1351 // character to onkeypress() event handlers. | 1351 // character to onkeypress() event handlers. |
1352 // TODO(hbono): need to handle more commands? | 1352 // TODO(hbono): need to handle more commands? |
1353 if (selector == @selector(insertNewline:)) { | 1353 if (selector == @selector(insertNewline:)) { |
1354 lastKeyPressedEvent_.reset([[NSApp currentEvent] retain]); | 1354 lastKeyPressedEvent_.reset([[NSApp currentEvent] retain]); |
1355 NativeWebKeyboardEvent event('\r', renderWidgetHostView_->im_modifiers_, | 1355 // Create the Char event from the NSEvent object, so that we can retain |
1356 base::Time::Now().ToDoubleT()); | 1356 // necessary informations, especially unmodifiedText. |
| 1357 NativeWebKeyboardEvent event(lastKeyPressedEvent_.get()); |
| 1358 event.type = WebKit::WebInputEvent::Char; |
| 1359 event.text[0] = '\r'; |
| 1360 event.text[1] = 0; |
| 1361 event.skip_in_browser = true; |
1357 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); | 1362 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); |
1358 } | 1363 } |
1359 } | 1364 } |
1360 | 1365 |
1361 - (void)insertText:(id)string { | 1366 - (void)insertText:(id)string { |
1362 // An input method has characters to be inserted. | 1367 // An input method has characters to be inserted. |
1363 // Same as Linux, Mac calls this method not only: | 1368 // Same as Linux, Mac calls this method not only: |
1364 // * when an input method finishs composing text, but also; | 1369 // * when an input method finishs composing text, but also; |
1365 // * when we type an ASCII character (without using input methods). | 1370 // * when we type an ASCII character (without using input methods). |
1366 // When we aren't using input methods, we should send the given character as | 1371 // When we aren't using input methods, we should send the given character as |
1367 // a Char event so it is dispatched to an onkeypress() event handler of | 1372 // a Char event so it is dispatched to an onkeypress() event handler of |
1368 // JavaScript. | 1373 // JavaScript. |
1369 // On the other hand, when we are using input methods, we should send the | 1374 // On the other hand, when we are using input methods, we should send the |
1370 // given characters as an IME event and prevent the characters from being | 1375 // given characters as an IME event and prevent the characters from being |
1371 // dispatched to onkeypress() event handlers. | 1376 // dispatched to onkeypress() event handlers. |
1372 BOOL isAttributedString = [string isKindOfClass:[NSAttributedString class]]; | 1377 BOOL isAttributedString = [string isKindOfClass:[NSAttributedString class]]; |
1373 NSString* im_text = isAttributedString ? [string string] : string; | 1378 NSString* im_text = isAttributedString ? [string string] : string; |
1374 if (!renderWidgetHostView_->im_composing_ && [im_text length] == 1) { | 1379 if (!renderWidgetHostView_->im_composing_ && [im_text length] == 1) { |
1375 lastKeyPressedEvent_.reset([[NSApp currentEvent] retain]); | 1380 lastKeyPressedEvent_.reset([[NSApp currentEvent] retain]); |
1376 NativeWebKeyboardEvent event([im_text characterAtIndex:0], | 1381 // Create the Char event from the NSEvent object, so that we can retain |
1377 renderWidgetHostView_->im_modifiers_, | 1382 // necessary informations, especially unmodifiedText. |
1378 base::Time::Now().ToDoubleT()); | 1383 NativeWebKeyboardEvent event(lastKeyPressedEvent_.get()); |
| 1384 event.type = WebKit::WebInputEvent::Char; |
| 1385 event.text[0] = [im_text characterAtIndex:0]; |
| 1386 event.text[1] = 0; |
| 1387 event.skip_in_browser = true; |
1379 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); | 1388 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); |
1380 } else { | 1389 } else { |
1381 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( | 1390 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( |
1382 UTF8ToUTF16([im_text UTF8String])); | 1391 UTF8ToUTF16([im_text UTF8String])); |
1383 } | 1392 } |
1384 renderWidgetHostView_->im_composing_ = false; | 1393 renderWidgetHostView_->im_composing_ = false; |
1385 } | 1394 } |
1386 | 1395 |
1387 @end | 1396 @end |
OLD | NEW |