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" |
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" |
19 #include "chrome/common/render_messages.h" | 19 #include "chrome/common/render_messages.h" |
20 #include "skia/ext/platform_canvas.h" | 20 #include "skia/ext/platform_canvas.h" |
21 #include "webkit/api/public/mac/WebInputEventFactory.h" | 21 #include "webkit/api/public/mac/WebInputEventFactory.h" |
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::WebInputEvent; | |
25 using WebKit::WebInputEventFactory; | 26 using WebKit::WebInputEventFactory; |
26 using WebKit::WebMouseEvent; | 27 using WebKit::WebMouseEvent; |
27 using WebKit::WebMouseWheelEvent; | 28 using WebKit::WebMouseWheelEvent; |
28 | 29 |
30 static inline int ToWebKitModifiers(NSUInteger flags) { | |
pink (ping after 24hrs)
2009/11/11 15:46:16
if this is a bitfield, should it be an unsigned in
Nico
2009/11/12 00:11:16
Technically yes, but the NativeWebKeyboardEvent co
| |
31 int modifiers = 0; | |
32 if (flags & NSControlKeyMask) modifiers |= WebInputEvent::ControlKey; | |
33 if (flags & NSShiftKeyMask) modifiers |= WebInputEvent::ShiftKey; | |
34 if (flags & NSAlternateKeyMask) modifiers |= WebInputEvent::AltKey; | |
35 if (flags & NSCommandKeyMask) modifiers |= WebInputEvent::MetaKey; | |
36 return modifiers; | |
37 } | |
38 | |
29 @interface RenderWidgetHostViewCocoa (Private) | 39 @interface RenderWidgetHostViewCocoa (Private) |
30 + (BOOL)shouldAutohideCursorForEvent:(NSEvent*)event; | 40 + (BOOL)shouldAutohideCursorForEvent:(NSEvent*)event; |
31 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r; | 41 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r; |
32 - (void)keyEvent:(NSEvent *)theEvent wasKeyEquivalent:(BOOL)equiv; | 42 - (void)keyEvent:(NSEvent *)theEvent wasKeyEquivalent:(BOOL)equiv; |
33 - (void)cancelChildPopups; | 43 - (void)cancelChildPopups; |
34 @end | 44 @end |
35 | 45 |
36 namespace { | 46 namespace { |
37 | 47 |
38 // Maximum number of characters we allow in a tooltip. | 48 // Maximum number of characters we allow in a tooltip. |
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
645 // To send an onkeydown() event before an onkeypress() event, we should | 655 // To send an onkeydown() event before an onkeypress() event, we should |
646 // dispatch this NSKeyDown event AFTER sending it to the renderer. | 656 // dispatch this NSKeyDown event AFTER sending it to the renderer. |
647 // (See <https://bugs.webkit.org/show_bug.cgi?id=25119>). | 657 // (See <https://bugs.webkit.org/show_bug.cgi?id=25119>). |
648 // | 658 // |
649 // If this object's retainCount is 1, the only reference is the one held by | 659 // If this object's retainCount is 1, the only reference is the one held by |
650 // keepSelfAlive. All other references may have been destroyed in the | 660 // keepSelfAlive. All other references may have been destroyed in the |
651 // RenderWidgetHost::ForwardKeyboardEvent call above if it resulted in tab | 661 // RenderWidgetHost::ForwardKeyboardEvent call above if it resulted in tab |
652 // closure. Were it not for that single reference, this object would | 662 // closure. Were it not for that single reference, this object would |
653 // already be deallocated. In that case, there's no point in calling | 663 // already be deallocated. In that case, there's no point in calling |
654 // -interpretKeyEvents:. | 664 // -interpretKeyEvents:. |
655 if ([self retainCount] > 1 && [theEvent type] == NSKeyDown) | 665 if ([self retainCount] > 1 && [theEvent type] == NSKeyDown) { |
656 [self interpretKeyEvents:[NSArray arrayWithObject:theEvent]]; | 666 [self interpretKeyEvents:[NSArray arrayWithObject:theEvent]]; |
657 | 667 |
668 // We don't get insertText: calls if ctrl is down, so synthesize a keypress | |
669 // event for that case. Note that this makes our behavior deviate from the | |
670 // windows and linux versions of chrome (however, see http://crbug.com/13891 | |
671 // ), but it makes us similar to how Safari behaves. | |
pink (ping after 24hrs)
2009/11/11 15:46:16
should you be specific about Mac Safari? Does Win
Nico
2009/11/12 00:11:16
Safari/win seems to be similar. At least for keys
| |
672 if ([theEvent modifierFlags] & (NSControlKeyMask | NSCommandKeyMask) && | |
pink (ping after 24hrs)
2009/11/11 15:46:16
the comment only mentions control, but this fires
Nico
2009/11/12 00:11:16
Updated the comment.
| |
673 lastKeyPressedEvent_.get() != theEvent) { | |
674 NativeWebKeyboardEvent event([[theEvent characters] characterAtIndex:0], | |
675 ToWebKitModifiers([theEvent modifierFlags]), | |
676 base::Time::Now().ToDoubleT()); | |
677 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); | |
678 } | |
679 } | |
680 | |
658 // Possibly autohide the cursor. | 681 // Possibly autohide the cursor. |
659 if ([RenderWidgetHostViewCocoa shouldAutohideCursorForEvent:theEvent]) | 682 if ([RenderWidgetHostViewCocoa shouldAutohideCursorForEvent:theEvent]) |
660 [NSCursor setHiddenUntilMouseMoves:YES]; | 683 [NSCursor setHiddenUntilMouseMoves:YES]; |
661 } | 684 } |
662 | 685 |
663 - (void)scrollWheel:(NSEvent *)theEvent { | 686 - (void)scrollWheel:(NSEvent *)theEvent { |
664 [self cancelChildPopups]; | 687 [self cancelChildPopups]; |
665 | 688 |
666 const WebMouseWheelEvent& event = | 689 const WebMouseWheelEvent& event = |
667 WebInputEventFactory::mouseWheelEvent(theEvent, self); | 690 WebInputEventFactory::mouseWheelEvent(theEvent, self); |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1277 | 1300 |
1278 - (void)doCommandBySelector:(SEL)selector { | 1301 - (void)doCommandBySelector:(SEL)selector { |
1279 // An input method calls this function to dispatch an editing command to be | 1302 // An input method calls this function to dispatch an editing command to be |
1280 // handled by this view. | 1303 // handled by this view. |
1281 // Even though most editing commands has been already handled by the | 1304 // Even though most editing commands has been already handled by the |
1282 // RWHVMEditCommandHelper object, we need to handle an insertNewline: command | 1305 // RWHVMEditCommandHelper object, we need to handle an insertNewline: command |
1283 // and send a '\r' character to WebKit so that WebKit dispatches this | 1306 // and send a '\r' character to WebKit so that WebKit dispatches this |
1284 // character to onkeypress() event handlers. | 1307 // character to onkeypress() event handlers. |
1285 // TODO(hbono): need to handle more commands? | 1308 // TODO(hbono): need to handle more commands? |
1286 if (selector == @selector(insertNewline:)) { | 1309 if (selector == @selector(insertNewline:)) { |
1310 lastKeyPressedEvent_.reset([[NSApp currentEvent] retain]); | |
1287 NativeWebKeyboardEvent event('\r', renderWidgetHostView_->im_modifiers_, | 1311 NativeWebKeyboardEvent event('\r', renderWidgetHostView_->im_modifiers_, |
1288 base::Time::Now().ToDoubleT()); | 1312 base::Time::Now().ToDoubleT()); |
1289 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); | 1313 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); |
1290 } | 1314 } |
1291 } | 1315 } |
1292 | 1316 |
1293 - (void)insertText:(id)string { | 1317 - (void)insertText:(id)string { |
1294 // An input method has characters to be inserted. | 1318 // An input method has characters to be inserted. |
1295 // Same as Linux, Mac calls this method not only: | 1319 // Same as Linux, Mac calls this method not only: |
1296 // * when an input method finishs composing text, but also; | 1320 // * when an input method finishs composing text, but also; |
1297 // * when we type an ASCII character (without using input methods). | 1321 // * when we type an ASCII character (without using input methods). |
1298 // When we aren't using input methods, we should send the given character as | 1322 // When we aren't using input methods, we should send the given character as |
1299 // a Char event so it is dispatched to an onkeypress() event handler of | 1323 // a Char event so it is dispatched to an onkeypress() event handler of |
1300 // JavaScript. | 1324 // JavaScript. |
1301 // On the other hand, when we are using input methods, we should send the | 1325 // On the other hand, when we are using input methods, we should send the |
1302 // given characters as an IME event and prevent the characters from being | 1326 // given characters as an IME event and prevent the characters from being |
1303 // dispatched to onkeypress() event handlers. | 1327 // dispatched to onkeypress() event handlers. |
1304 BOOL isAttributedString = [string isKindOfClass:[NSAttributedString class]]; | 1328 BOOL isAttributedString = [string isKindOfClass:[NSAttributedString class]]; |
1305 NSString* im_text = isAttributedString ? [string string] : string; | 1329 NSString* im_text = isAttributedString ? [string string] : string; |
1306 if (!renderWidgetHostView_->im_composing_ && [im_text length] == 1) { | 1330 if (!renderWidgetHostView_->im_composing_ && [im_text length] == 1) { |
1331 lastKeyPressedEvent_.reset([[NSApp currentEvent] retain]); | |
1307 NativeWebKeyboardEvent event([im_text characterAtIndex:0], | 1332 NativeWebKeyboardEvent event([im_text characterAtIndex:0], |
1308 renderWidgetHostView_->im_modifiers_, | 1333 renderWidgetHostView_->im_modifiers_, |
1309 base::Time::Now().ToDoubleT()); | 1334 base::Time::Now().ToDoubleT()); |
1310 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); | 1335 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); |
1311 } else { | 1336 } else { |
1312 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( | 1337 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( |
1313 UTF8ToUTF16([im_text UTF8String])); | 1338 UTF8ToUTF16([im_text UTF8String])); |
1314 } | 1339 } |
1315 renderWidgetHostView_->im_composing_ = false; | 1340 renderWidgetHostView_->im_composing_ = false; |
1316 } | 1341 } |
1317 | 1342 |
1318 @end | 1343 @end |
OLD | NEW |