Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(401)

Side by Side Diff: chrome/browser/renderer_host/render_widget_host_view_mac.mm

Issue 383004: A quick fix for Issue 26880.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #import <Carbon/Carbon.h>
8 #include <ApplicationServices/ApplicationServices.h>
9 #include <AvailabilityMacros.h>
10
7 #include "base/histogram.h" 11 #include "base/histogram.h"
8 #import "base/scoped_nsobject.h" 12 #import "base/scoped_nsobject.h"
9 #include "base/string_util.h" 13 #include "base/string_util.h"
10 #include "base/sys_string_conversions.h" 14 #include "base/sys_string_conversions.h"
11 #include "chrome/browser/browser_trial.h" 15 #include "chrome/browser/browser_trial.h"
12 #import "chrome/browser/cocoa/rwhvm_editcommand_helper.h" 16 #import "chrome/browser/cocoa/rwhvm_editcommand_helper.h"
13 #include "chrome/browser/renderer_host/backing_store.h" 17 #include "chrome/browser/renderer_host/backing_store.h"
14 #include "chrome/browser/renderer_host/render_process_host.h" 18 #include "chrome/browser/renderer_host/render_process_host.h"
15 #include "chrome/browser/renderer_host/render_widget_host.h" 19 #include "chrome/browser/renderer_host/render_widget_host.h"
16 #include "chrome/browser/spellchecker_platform_engine.h" 20 #include "chrome/browser/spellchecker_platform_engine.h"
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 } 229 }
226 230
227 void RenderWidgetHostViewMac::SetIsLoading(bool is_loading) { 231 void RenderWidgetHostViewMac::SetIsLoading(bool is_loading) {
228 is_loading_ = is_loading; 232 is_loading_ = is_loading;
229 UpdateCursorIfOverSelf(); 233 UpdateCursorIfOverSelf();
230 } 234 }
231 235
232 void RenderWidgetHostViewMac::IMEUpdateStatus(int control, 236 void RenderWidgetHostViewMac::IMEUpdateStatus(int control,
233 const gfx::Rect& caret_rect) { 237 const gfx::Rect& caret_rect) {
234 // The renderer updates its IME status. 238 // The renderer updates its IME status.
235 // We need to control the input method according to the given message. 239 #if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_5
240 // Complete the ongoing composition when a renderer finishes it.
241 // We need to use Carbon APIs to finish an ongoing composition since Leopard
242 // doesn't implement a Cocoa API -[NSTextInputContext discardMarkedText:]
243 // that discards the marked text.
244 if (control == IME_DISABLE || control == IME_COMPLETE_COMPOSITION)
245 ::FixTSMDocument(::TSMGetActiveDocument());
246 #endif
236 247
237 // We need to convert the coordinate of the cursor rectangle sent from the 248 // We need to convert the coordinate of the cursor rectangle sent from the
238 // renderer and save it. Our IME backend uses a coordinate system whose 249 // renderer and save it. Our IME backend uses a coordinate system whose
239 // origin is the upper-left corner of this view. On the other hand, Cocoa 250 // origin is the upper-left corner of this view. On the other hand, Cocoa
240 // uses a coordinate system whose origin is the lower-left corner of this 251 // uses a coordinate system whose origin is the lower-left corner of this
241 // view. So, we convert the cursor rectangle and save it. 252 // view. So, we convert the cursor rectangle and save it.
242 NSRect view_rect = [cocoa_view_ bounds]; 253 NSRect view_rect = [cocoa_view_ bounds];
243 const int y_offset = static_cast<int>(view_rect.size.height); 254 const int y_offset = static_cast<int>(view_rect.size.height);
244 im_caret_rect_ = NSMakeRect(caret_rect.x(), 255 im_caret_rect_ = NSMakeRect(caret_rect.x(),
245 y_offset - caret_rect.y() - caret_rect.height(), 256 y_offset - caret_rect.y() - caret_rect.height(),
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 577
567 - (BOOL)performKeyEquivalent:(NSEvent*)theEvent { 578 - (BOOL)performKeyEquivalent:(NSEvent*)theEvent {
568 if (ignoreKeyEvents_) 579 if (ignoreKeyEvents_)
569 return NO; 580 return NO;
570 581
571 // |performKeyEquivalent:| is sent to all views of a window, not only down the 582 // |performKeyEquivalent:| is sent to all views of a window, not only down the
572 // responder chain (cf. "Handling Key Equivalents" in 583 // responder chain (cf. "Handling Key Equivalents" in
573 // http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Event Overview/HandlingKeyEvents/HandlingKeyEvents.html 584 // http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Event Overview/HandlingKeyEvents/HandlingKeyEvents.html
574 // ). We only want to handle key equivalents if we're first responder. 585 // ). We only want to handle key equivalents if we're first responder.
575 if ([[self window] firstResponder] != self) 586 if ([[self window] firstResponder] != self)
576 return NO;» 587 return NO;
577 588
578 // If we return |NO| from this function, cocoa will send the key event to» 589 // If we return |NO| from this function, cocoa will send the key event to
579 // the menu and only if the menu does not process the event to |keyDown:|. We» 590 // the menu and only if the menu does not process the event to |keyDown:|. We
580 // want to send the event to a renderer _before_ sending it to the menu, so» 591 // want to send the event to a renderer _before_ sending it to the menu, so
581 // we need to return |YES| for all events that might be swallowed by the menu. » 592 // we need to return |YES| for all events that might be swallowed by the menu.
582 // We do not return |YES| for every keypress because we don't get |keyDown:|» 593 // We do not return |YES| for every keypress because we don't get |keyDown:|
583 // events for keys that we handle this way.» 594 // events for keys that we handle this way.
584 NSUInteger modifierFlags = [theEvent modifierFlags];» 595 NSUInteger modifierFlags = [theEvent modifierFlags];
585 if ((modifierFlags & NSCommandKeyMask) == 0) {» 596 if ((modifierFlags & NSCommandKeyMask) == 0) {
586 // Make sure the menu does not contain key equivalents that don't» 597 // Make sure the menu does not contain key equivalents that don't
587 // contain cmd.» 598 // contain cmd.
588 DCHECK(![[NSApp mainMenu] performKeyEquivalent:theEvent]);» 599 DCHECK(![[NSApp mainMenu] performKeyEquivalent:theEvent]);
589 return NO;» 600 return NO;
590 } 601 }
591 602
592 // Command key combinations are sent via performKeyEquivalent rather than» 603 // Command key combinations are sent via performKeyEquivalent rather than
593 // keyDown:. We just forward this on and if WebCore doesn't want to handle» 604 // keyDown:. We just forward this on and if WebCore doesn't want to handle
594 // it, we let the TabContentsView figure out how to reinject it.» 605 // it, we let the TabContentsView figure out how to reinject it.
595 [self keyEvent:theEvent wasKeyEquivalent:YES];» 606 [self keyEvent:theEvent wasKeyEquivalent:YES];
596 return YES; 607 return YES;
597 } 608 }
598 609
599 - (BOOL)_wantsKeyDownForEvent:(NSEvent*)event { 610 - (BOOL)_wantsKeyDownForEvent:(NSEvent*)event {
600 // This is a SPI that AppKit apparently calls after |performKeyEquivalent:| 611 // This is a SPI that AppKit apparently calls after |performKeyEquivalent:|
601 // returned NO. If this function returns |YES|, Cocoa sends the event to 612 // returned NO. If this function returns |YES|, Cocoa sends the event to
602 // |keyDown:| instead of doing other things with it. Ctrl-tab will be sent 613 // |keyDown:| instead of doing other things with it. Ctrl-tab will be sent
603 // to us instead of doing key view loop control, ctrl-left/right get handled 614 // to us instead of doing key view loop control, ctrl-left/right get handled
604 // correctly, etc. 615 // correctly, etc.
605 // (However, there are still some keys that Cocoa swallows, e.g. the key 616 // (However, there are still some keys that Cocoa swallows, e.g. the key
606 // equivalent that Cocoa uses for toggling the input langauge. In this case, 617 // equivalent that Cocoa uses for toggling the input langauge. In this case,
607 // that's actually a good thing, though -- see http://crbug.com/26115 .) 618 // that's actually a good thing, though -- see http://crbug.com/26115 .)
608 return YES; 619 return YES;
609 } 620 }
610 621
611 - (void)keyEvent:(NSEvent*)theEvent { 622 - (void)keyEvent:(NSEvent*)theEvent {
612 [self keyEvent:theEvent wasKeyEquivalent:NO];» 623 [self keyEvent:theEvent wasKeyEquivalent:NO];
613 }» 624 }
614 625
615 - (void)keyEvent:(NSEvent *)theEvent wasKeyEquivalent:(BOOL)equiv {» 626 - (void)keyEvent:(NSEvent *)theEvent wasKeyEquivalent:(BOOL)equiv {
616 if (ignoreKeyEvents_) 627 if (ignoreKeyEvents_)
617 return; 628 return;
618 629
619 DCHECK([theEvent type] != NSKeyDown ||» 630 DCHECK([theEvent type] != NSKeyDown ||
620 !equiv == !([theEvent modifierFlags] & NSCommandKeyMask)); 631 !equiv == !([theEvent modifierFlags] & NSCommandKeyMask));
621 632
622 scoped_nsobject<RenderWidgetHostViewCocoa> keepSelfAlive([self retain]); 633 scoped_nsobject<RenderWidgetHostViewCocoa> keepSelfAlive([self retain]);
623 634
624 // Don't cancel child popups; the key events are probably what's triggering 635 // Don't cancel child popups; the key events are probably what's triggering
625 // the popup in the first place. 636 // the popup in the first place.
626 637
627 NativeWebKeyboardEvent event(theEvent); 638 NativeWebKeyboardEvent event(theEvent);
628 639
629 // Save the modifier keys so the insertText method can use it when it sends 640 // Save the modifier keys so the insertText method can use it when it sends
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after
1339 base::Time::Now().ToDoubleT()); 1350 base::Time::Now().ToDoubleT());
1340 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); 1351 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event);
1341 } else { 1352 } else {
1342 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( 1353 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition(
1343 UTF8ToUTF16([im_text UTF8String])); 1354 UTF8ToUTF16([im_text UTF8String]));
1344 } 1355 }
1345 renderWidgetHostView_->im_composing_ = false; 1356 renderWidgetHostView_->im_composing_ = false;
1346 } 1357 }
1347 1358
1348 @end 1359 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698