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

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

Issue 160565: Adds support for the os x spelling panel to chromium. Users can... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 3 months 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
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 #include "base/histogram.h" 7 #include "base/histogram.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/sys_string_conversions.h" 9 #include "base/sys_string_conversions.h"
10 #include "chrome/browser/browser_trial.h" 10 #include "chrome/browser/browser_trial.h"
11 #import "chrome/browser/cocoa/rwhvm_editcommand_helper.h" 11 #import "chrome/browser/cocoa/rwhvm_editcommand_helper.h"
12 #include "chrome/browser/renderer_host/backing_store.h" 12 #include "chrome/browser/renderer_host/backing_store.h"
13 #include "chrome/browser/renderer_host/render_process_host.h" 13 #include "chrome/browser/renderer_host/render_process_host.h"
14 #include "chrome/browser/renderer_host/render_widget_host.h" 14 #include "chrome/browser/renderer_host/render_widget_host.h"
15 #include "chrome/browser/spellchecker_platform_engine.h"
15 #include "chrome/common/native_web_keyboard_event.h" 16 #include "chrome/common/native_web_keyboard_event.h"
16 #include "skia/ext/platform_canvas.h" 17 #include "skia/ext/platform_canvas.h"
17 #include "webkit/api/public/mac/WebInputEventFactory.h" 18 #include "webkit/api/public/mac/WebInputEventFactory.h"
18 #include "webkit/api/public/WebInputEvent.h" 19 #include "webkit/api/public/WebInputEvent.h"
19 #include "webkit/glue/webmenurunner_mac.h" 20 #include "webkit/glue/webmenurunner_mac.h"
20 21
21 using WebKit::WebInputEventFactory; 22 using WebKit::WebInputEventFactory;
22 using WebKit::WebMouseEvent; 23 using WebKit::WebMouseEvent;
23 using WebKit::WebMouseWheelEvent; 24 using WebKit::WebMouseWheelEvent;
24 25
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 return renderWidgetHostView_; 684 return renderWidgetHostView_;
684 } 685 }
685 686
686 // Determine whether we should autohide the cursor (i.e., hide it until mouse 687 // Determine whether we should autohide the cursor (i.e., hide it until mouse
687 // move) for the given event. Customize here to be more selective about which 688 // move) for the given event. Customize here to be more selective about which
688 // key presses to autohide on. 689 // key presses to autohide on.
689 + (BOOL)shouldAutohideCursorForEvent:(NSEvent*)event { 690 + (BOOL)shouldAutohideCursorForEvent:(NSEvent*)event {
690 return ([event type] == NSKeyDown) ? YES : NO; 691 return ([event type] == NSKeyDown) ? YES : NO;
691 } 692 }
692 693
694 // Spellchecking methods
695 // The next three methods are implemented here since this class is the first
696 // responder for anything in the browser.
697
698 // This message is sent whenever the user specifies that a word should be
699 // changed from the spellChecker.
700 - (void)changeSpelling:(id)sender {
701 // Grab the currently selected word from the spell panel, as this is the word
702 // that we want to replace the selected word in the text with.
703 NSString* newWord = [[sender selectedCell] stringValue];
704 if (newWord != nil) {
705 RenderWidgetHostViewMac* thisHostView = [self renderWidgetHostViewMac];
706 thisHostView->GetRenderWidgetHost()->ReplaceWord(
707 base::SysNSStringToWide(newWord));
708 }
709 }
710
711 // This message is sent by NSSpellChecker whenever the next word should be
712 // advanced to, either after a correction or clicking the "Find Next" button.
713 // This isn't documented anywhere useful, like in NSSpellProtocol.h with the
714 // other spelling panel methods. This is probably because Apple assumes that the
715 // the spelling panel will be used with an NSText, which will automatically
716 // catch this and advance to the next word for you. Thanks Apple.
717 - (void)checkSpelling:(id)sender {
718 RenderWidgetHostViewMac* thisHostView = [self renderWidgetHostViewMac];
719 thisHostView->GetRenderWidgetHost()->AdvanceToNextMisspelling();
720 }
721
722 // This message is sent by the spelling panel whenever a word is ignored.
723 - (void)ignoreSpelling:(id)sender {
724 // Ideally, we would ask the current RenderView for its tag, but that would
725 // mean making a blocking IPC call from the browser. Instead,
726 // SpellCheckerPlatform::CheckSpelling remembers the last tag and
727 // SpellCheckerPlatform::IgnoreWord assumes that is the correct tag.
728 NSString* wordToIgnore = [sender stringValue];
729 if (wordToIgnore != nil) {
730 SpellCheckerPlatform::IgnoreWord(base::SysNSStringToUTF8(wordToIgnore));
731
732 // Strangely, the spellingPanel doesn't send checkSpelling after a word is
733 // ignored, so we have to explicitly call AdvanceToNextMisspelling here.
734 RenderWidgetHostViewMac* thisHostView = [self renderWidgetHostViewMac];
735 thisHostView->GetRenderWidgetHost()->AdvanceToNextMisspelling();
736 }
737 }
738
739 // This message is sent when the "Show Spelling and Grammar" item in the main
740 // menu is clicked.
741 - (void)showGuessPanel:(id)sender {
742 RenderWidgetHostViewMac* thisHostView = [self renderWidgetHostViewMac];
743 thisHostView->GetRenderWidgetHost()->ToggleSpellPanel(
744 SpellCheckerPlatform::SpellingPanelVisible());
745 }
746
747 // END Spellchecking methods
693 748
694 // Below is the nasty tooltip stuff -- copied from WebKit's WebHTMLView.mm 749 // Below is the nasty tooltip stuff -- copied from WebKit's WebHTMLView.mm
695 // with minor modifications for code style and commenting. 750 // with minor modifications for code style and commenting.
696 // 751 //
697 // The 'public' interface is -setToolTipAtMousePoint:. This differs from 752 // The 'public' interface is -setToolTipAtMousePoint:. This differs from
698 // -setToolTip: in that the updated tooltip takes effect immediately, 753 // -setToolTip: in that the updated tooltip takes effect immediately,
699 // without the user's having to move the mouse out of and back into the view. 754 // without the user's having to move the mouse out of and back into the view.
700 // 755 //
701 // Unfortunately, doing this requires sending fake mouseEnter/Exit events to 756 // Unfortunately, doing this requires sending fake mouseEnter/Exit events to
702 // the view, which in turn requires overriding some internal tracking-rect 757 // the view, which in turn requires overriding some internal tracking-rect
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); 1149 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event);
1095 } else { 1150 } else {
1096 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( 1151 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition(
1097 UTF8ToUTF16([im_text UTF8String])); 1152 UTF8ToUTF16([im_text UTF8String]));
1098 } 1153 }
1099 renderWidgetHostView_->im_composing_ = false; 1154 renderWidgetHostView_->im_composing_ = false;
1100 } 1155 }
1101 1156
1102 @end 1157 @end
1103 1158
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/render_widget_host_view_mac.h ('k') | chrome/browser/renderer_host/resource_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698