OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <QuartzCore/QuartzCore.h> | 5 #include <QuartzCore/QuartzCore.h> |
6 | 6 |
7 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" | 7 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" |
8 | 8 |
9 #include "app/app_switches.h" | 9 #include "app/app_switches.h" |
10 #include "app/surface/io_surface_support_mac.h" | 10 #include "app/surface/io_surface_support_mac.h" |
(...skipping 1889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1900 | 1900 |
1901 // For now, these actions are always enabled for render view, | 1901 // For now, these actions are always enabled for render view, |
1902 // this is sub-optimal. | 1902 // this is sub-optimal. |
1903 // TODO(suzhe): Plumb the "can*" methods up from WebCore. | 1903 // TODO(suzhe): Plumb the "can*" methods up from WebCore. |
1904 if (action == @selector(undo:) || | 1904 if (action == @selector(undo:) || |
1905 action == @selector(redo:) || | 1905 action == @selector(redo:) || |
1906 action == @selector(cut:) || | 1906 action == @selector(cut:) || |
1907 action == @selector(copy:) || | 1907 action == @selector(copy:) || |
1908 action == @selector(copyToFindPboard:) || | 1908 action == @selector(copyToFindPboard:) || |
1909 action == @selector(paste:) || | 1909 action == @selector(paste:) || |
1910 action == @selector(pasteAsPlainText:)) { | 1910 action == @selector(pasteAsPlainText:) || |
| 1911 action == @selector(checkSpelling:)) { |
1911 return renderWidgetHostView_->render_widget_host_->IsRenderView(); | 1912 return renderWidgetHostView_->render_widget_host_->IsRenderView(); |
1912 } | 1913 } |
1913 | 1914 |
| 1915 if (action == @selector(toggleContinuousSpellChecking:)) { |
| 1916 RenderViewHost::CommandState state; |
| 1917 state.is_enabled = false; |
| 1918 state.checked_state = RENDER_VIEW_COMMAND_CHECKED_STATE_UNCHECKED; |
| 1919 if (renderWidgetHostView_->render_widget_host_->IsRenderView()) { |
| 1920 state = static_cast<RenderViewHost*>( |
| 1921 renderWidgetHostView_->render_widget_host_)-> |
| 1922 GetStateForCommand(RENDER_VIEW_COMMAND_TOGGLE_SPELL_CHECK); |
| 1923 } |
| 1924 if ([(id)item respondsToSelector:@selector(setState:)]) { |
| 1925 NSCellStateValue checked_state; |
| 1926 switch (state.checked_state) { |
| 1927 case RENDER_VIEW_COMMAND_CHECKED_STATE_UNCHECKED: |
| 1928 checked_state = NSOffState; |
| 1929 break; |
| 1930 case RENDER_VIEW_COMMAND_CHECKED_STATE_CHECKED: |
| 1931 checked_state = NSOnState; |
| 1932 break; |
| 1933 case RENDER_VIEW_COMMAND_CHECKED_STATE_MIXED: |
| 1934 checked_state = NSMixedState; |
| 1935 break; |
| 1936 } |
| 1937 [(id)item setState:checked_state]; |
| 1938 } |
| 1939 return state.is_enabled; |
| 1940 } |
| 1941 |
1914 return editCommand_helper_->IsMenuItemEnabled(action, self); | 1942 return editCommand_helper_->IsMenuItemEnabled(action, self); |
1915 } | 1943 } |
1916 | 1944 |
1917 - (RenderWidgetHostViewMac*)renderWidgetHostViewMac { | 1945 - (RenderWidgetHostViewMac*)renderWidgetHostViewMac { |
1918 return renderWidgetHostView_.get(); | 1946 return renderWidgetHostView_.get(); |
1919 } | 1947 } |
1920 | 1948 |
1921 // Determine whether we should autohide the cursor (i.e., hide it until mouse | 1949 // Determine whether we should autohide the cursor (i.e., hide it until mouse |
1922 // move) for the given event. Customize here to be more selective about which | 1950 // move) for the given event. Customize here to be more selective about which |
1923 // key presses to autohide on. | 1951 // key presses to autohide on. |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2055 base::SysNSStringToUTF16(newWord)); | 2083 base::SysNSStringToUTF16(newWord)); |
2056 } | 2084 } |
2057 } | 2085 } |
2058 | 2086 |
2059 // This message is sent by NSSpellChecker whenever the next word should be | 2087 // This message is sent by NSSpellChecker whenever the next word should be |
2060 // advanced to, either after a correction or clicking the "Find Next" button. | 2088 // advanced to, either after a correction or clicking the "Find Next" button. |
2061 // This isn't documented anywhere useful, like in NSSpellProtocol.h with the | 2089 // This isn't documented anywhere useful, like in NSSpellProtocol.h with the |
2062 // other spelling panel methods. This is probably because Apple assumes that the | 2090 // other spelling panel methods. This is probably because Apple assumes that the |
2063 // the spelling panel will be used with an NSText, which will automatically | 2091 // the spelling panel will be used with an NSText, which will automatically |
2064 // catch this and advance to the next word for you. Thanks Apple. | 2092 // catch this and advance to the next word for you. Thanks Apple. |
| 2093 // This is also called from the Edit -> Spelling -> Check Spelling menu item. |
2065 - (void)checkSpelling:(id)sender { | 2094 - (void)checkSpelling:(id)sender { |
2066 RenderWidgetHostViewMac* thisHostView = [self renderWidgetHostViewMac]; | 2095 RenderWidgetHostViewMac* thisHostView = [self renderWidgetHostViewMac]; |
2067 thisHostView->GetRenderWidgetHost()->AdvanceToNextMisspelling(); | 2096 thisHostView->GetRenderWidgetHost()->AdvanceToNextMisspelling(); |
2068 } | 2097 } |
2069 | 2098 |
2070 // This message is sent by the spelling panel whenever a word is ignored. | 2099 // This message is sent by the spelling panel whenever a word is ignored. |
2071 - (void)ignoreSpelling:(id)sender { | 2100 - (void)ignoreSpelling:(id)sender { |
2072 // Ideally, we would ask the current RenderView for its tag, but that would | 2101 // Ideally, we would ask the current RenderView for its tag, but that would |
2073 // mean making a blocking IPC call from the browser. Instead, | 2102 // mean making a blocking IPC call from the browser. Instead, |
2074 // SpellCheckerPlatform::CheckSpelling remembers the last tag and | 2103 // SpellCheckerPlatform::CheckSpelling remembers the last tag and |
2075 // SpellCheckerPlatform::IgnoreWord assumes that is the correct tag. | 2104 // SpellCheckerPlatform::IgnoreWord assumes that is the correct tag. |
2076 NSString* wordToIgnore = [sender stringValue]; | 2105 NSString* wordToIgnore = [sender stringValue]; |
2077 if (wordToIgnore != nil) | 2106 if (wordToIgnore != nil) |
2078 SpellCheckerPlatform::IgnoreWord(base::SysNSStringToUTF16(wordToIgnore)); | 2107 SpellCheckerPlatform::IgnoreWord(base::SysNSStringToUTF16(wordToIgnore)); |
2079 } | 2108 } |
2080 | 2109 |
2081 - (void)showGuessPanel:(id)sender { | 2110 - (void)showGuessPanel:(id)sender { |
2082 RenderWidgetHostViewMac* thisHostView = [self renderWidgetHostViewMac]; | 2111 RenderWidgetHostViewMac* thisHostView = [self renderWidgetHostViewMac]; |
2083 thisHostView->GetRenderWidgetHost()->ToggleSpellPanel( | 2112 thisHostView->GetRenderWidgetHost()->ToggleSpellPanel( |
2084 SpellCheckerPlatform::SpellingPanelVisible()); | 2113 SpellCheckerPlatform::SpellingPanelVisible()); |
2085 } | 2114 } |
2086 | 2115 |
| 2116 - (void)toggleContinuousSpellChecking:(id)sender { |
| 2117 if (renderWidgetHostView_->render_widget_host_->IsRenderView()) { |
| 2118 static_cast<RenderViewHost*>(renderWidgetHostView_->render_widget_host_)-> |
| 2119 ToggleSpellCheck(); |
| 2120 } |
| 2121 } |
| 2122 |
2087 // END Spellchecking methods | 2123 // END Spellchecking methods |
2088 | 2124 |
2089 // Below is the nasty tooltip stuff -- copied from WebKit's WebHTMLView.mm | 2125 // Below is the nasty tooltip stuff -- copied from WebKit's WebHTMLView.mm |
2090 // with minor modifications for code style and commenting. | 2126 // with minor modifications for code style and commenting. |
2091 // | 2127 // |
2092 // The 'public' interface is -setToolTipAtMousePoint:. This differs from | 2128 // The 'public' interface is -setToolTipAtMousePoint:. This differs from |
2093 // -setToolTip: in that the updated tooltip takes effect immediately, | 2129 // -setToolTip: in that the updated tooltip takes effect immediately, |
2094 // without the user's having to move the mouse out of and back into the view. | 2130 // without the user's having to move the mouse out of and back into the view. |
2095 // | 2131 // |
2096 // Unfortunately, doing this requires sending fake mouseEnter/Exit events to | 2132 // Unfortunately, doing this requires sending fake mouseEnter/Exit events to |
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2725 if (!string) return NO; | 2761 if (!string) return NO; |
2726 | 2762 |
2727 // If the user is currently using an IME, confirm the IME input, | 2763 // If the user is currently using an IME, confirm the IME input, |
2728 // and then insert the text from the service, the same as TextEdit and Safari. | 2764 // and then insert the text from the service, the same as TextEdit and Safari. |
2729 [self confirmComposition]; | 2765 [self confirmComposition]; |
2730 [self insertText:string]; | 2766 [self insertText:string]; |
2731 return YES; | 2767 return YES; |
2732 } | 2768 } |
2733 | 2769 |
2734 @end | 2770 @end |
OLD | NEW |