| 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 1902 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1913 | 1913 |
| 1914 // For now, these actions are always enabled for render view, | 1914 // For now, these actions are always enabled for render view, |
| 1915 // this is sub-optimal. | 1915 // this is sub-optimal. |
| 1916 // TODO(suzhe): Plumb the "can*" methods up from WebCore. | 1916 // TODO(suzhe): Plumb the "can*" methods up from WebCore. |
| 1917 if (action == @selector(undo:) || | 1917 if (action == @selector(undo:) || |
| 1918 action == @selector(redo:) || | 1918 action == @selector(redo:) || |
| 1919 action == @selector(cut:) || | 1919 action == @selector(cut:) || |
| 1920 action == @selector(copy:) || | 1920 action == @selector(copy:) || |
| 1921 action == @selector(copyToFindPboard:) || | 1921 action == @selector(copyToFindPboard:) || |
| 1922 action == @selector(paste:) || | 1922 action == @selector(paste:) || |
| 1923 action == @selector(pasteAsPlainText:) || | 1923 action == @selector(pasteAsPlainText:)) { |
| 1924 action == @selector(checkSpelling:)) { | |
| 1925 return renderWidgetHostView_->render_widget_host_->IsRenderView(); | 1924 return renderWidgetHostView_->render_widget_host_->IsRenderView(); |
| 1926 } | 1925 } |
| 1927 | 1926 |
| 1928 if (action == @selector(toggleContinuousSpellChecking:)) { | |
| 1929 RenderViewHost::CommandState state; | |
| 1930 state.is_enabled = false; | |
| 1931 state.checked_state = RENDER_VIEW_COMMAND_CHECKED_STATE_UNCHECKED; | |
| 1932 if (renderWidgetHostView_->render_widget_host_->IsRenderView()) { | |
| 1933 state = static_cast<RenderViewHost*>( | |
| 1934 renderWidgetHostView_->render_widget_host_)-> | |
| 1935 GetStateForCommand(RENDER_VIEW_COMMAND_TOGGLE_SPELL_CHECK); | |
| 1936 } | |
| 1937 if ([(id)item respondsToSelector:@selector(setState:)]) { | |
| 1938 NSCellStateValue checked_state; | |
| 1939 switch (state.checked_state) { | |
| 1940 case RENDER_VIEW_COMMAND_CHECKED_STATE_UNCHECKED: | |
| 1941 checked_state = NSOffState; | |
| 1942 break; | |
| 1943 case RENDER_VIEW_COMMAND_CHECKED_STATE_CHECKED: | |
| 1944 checked_state = NSOnState; | |
| 1945 break; | |
| 1946 case RENDER_VIEW_COMMAND_CHECKED_STATE_MIXED: | |
| 1947 checked_state = NSMixedState; | |
| 1948 break; | |
| 1949 } | |
| 1950 [(id)item setState:checked_state]; | |
| 1951 } | |
| 1952 return state.is_enabled; | |
| 1953 } | |
| 1954 | |
| 1955 return editCommand_helper_->IsMenuItemEnabled(action, self); | 1927 return editCommand_helper_->IsMenuItemEnabled(action, self); |
| 1956 } | 1928 } |
| 1957 | 1929 |
| 1958 - (RenderWidgetHostViewMac*)renderWidgetHostViewMac { | 1930 - (RenderWidgetHostViewMac*)renderWidgetHostViewMac { |
| 1959 return renderWidgetHostView_.get(); | 1931 return renderWidgetHostView_.get(); |
| 1960 } | 1932 } |
| 1961 | 1933 |
| 1962 // Determine whether we should autohide the cursor (i.e., hide it until mouse | 1934 // Determine whether we should autohide the cursor (i.e., hide it until mouse |
| 1963 // move) for the given event. Customize here to be more selective about which | 1935 // move) for the given event. Customize here to be more selective about which |
| 1964 // key presses to autohide on. | 1936 // key presses to autohide on. |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2096 base::SysNSStringToUTF16(newWord)); | 2068 base::SysNSStringToUTF16(newWord)); |
| 2097 } | 2069 } |
| 2098 } | 2070 } |
| 2099 | 2071 |
| 2100 // This message is sent by NSSpellChecker whenever the next word should be | 2072 // This message is sent by NSSpellChecker whenever the next word should be |
| 2101 // advanced to, either after a correction or clicking the "Find Next" button. | 2073 // advanced to, either after a correction or clicking the "Find Next" button. |
| 2102 // This isn't documented anywhere useful, like in NSSpellProtocol.h with the | 2074 // This isn't documented anywhere useful, like in NSSpellProtocol.h with the |
| 2103 // other spelling panel methods. This is probably because Apple assumes that the | 2075 // other spelling panel methods. This is probably because Apple assumes that the |
| 2104 // the spelling panel will be used with an NSText, which will automatically | 2076 // the spelling panel will be used with an NSText, which will automatically |
| 2105 // catch this and advance to the next word for you. Thanks Apple. | 2077 // catch this and advance to the next word for you. Thanks Apple. |
| 2106 // This is also called from the Edit -> Spelling -> Check Spelling menu item. | |
| 2107 - (void)checkSpelling:(id)sender { | 2078 - (void)checkSpelling:(id)sender { |
| 2108 RenderWidgetHostViewMac* thisHostView = [self renderWidgetHostViewMac]; | 2079 RenderWidgetHostViewMac* thisHostView = [self renderWidgetHostViewMac]; |
| 2109 thisHostView->GetRenderWidgetHost()->AdvanceToNextMisspelling(); | 2080 thisHostView->GetRenderWidgetHost()->AdvanceToNextMisspelling(); |
| 2110 } | 2081 } |
| 2111 | 2082 |
| 2112 // This message is sent by the spelling panel whenever a word is ignored. | 2083 // This message is sent by the spelling panel whenever a word is ignored. |
| 2113 - (void)ignoreSpelling:(id)sender { | 2084 - (void)ignoreSpelling:(id)sender { |
| 2114 // Ideally, we would ask the current RenderView for its tag, but that would | 2085 // Ideally, we would ask the current RenderView for its tag, but that would |
| 2115 // mean making a blocking IPC call from the browser. Instead, | 2086 // mean making a blocking IPC call from the browser. Instead, |
| 2116 // SpellCheckerPlatform::CheckSpelling remembers the last tag and | 2087 // SpellCheckerPlatform::CheckSpelling remembers the last tag and |
| 2117 // SpellCheckerPlatform::IgnoreWord assumes that is the correct tag. | 2088 // SpellCheckerPlatform::IgnoreWord assumes that is the correct tag. |
| 2118 NSString* wordToIgnore = [sender stringValue]; | 2089 NSString* wordToIgnore = [sender stringValue]; |
| 2119 if (wordToIgnore != nil) | 2090 if (wordToIgnore != nil) |
| 2120 SpellCheckerPlatform::IgnoreWord(base::SysNSStringToUTF16(wordToIgnore)); | 2091 SpellCheckerPlatform::IgnoreWord(base::SysNSStringToUTF16(wordToIgnore)); |
| 2121 } | 2092 } |
| 2122 | 2093 |
| 2123 - (void)showGuessPanel:(id)sender { | 2094 - (void)showGuessPanel:(id)sender { |
| 2124 RenderWidgetHostViewMac* thisHostView = [self renderWidgetHostViewMac]; | 2095 RenderWidgetHostViewMac* thisHostView = [self renderWidgetHostViewMac]; |
| 2125 thisHostView->GetRenderWidgetHost()->ToggleSpellPanel( | 2096 thisHostView->GetRenderWidgetHost()->ToggleSpellPanel( |
| 2126 SpellCheckerPlatform::SpellingPanelVisible()); | 2097 SpellCheckerPlatform::SpellingPanelVisible()); |
| 2127 } | 2098 } |
| 2128 | 2099 |
| 2129 - (void)toggleContinuousSpellChecking:(id)sender { | |
| 2130 if (renderWidgetHostView_->render_widget_host_->IsRenderView()) { | |
| 2131 static_cast<RenderViewHost*>(renderWidgetHostView_->render_widget_host_)-> | |
| 2132 ToggleSpellCheck(); | |
| 2133 } | |
| 2134 } | |
| 2135 | |
| 2136 // END Spellchecking methods | 2100 // END Spellchecking methods |
| 2137 | 2101 |
| 2138 // Below is the nasty tooltip stuff -- copied from WebKit's WebHTMLView.mm | 2102 // Below is the nasty tooltip stuff -- copied from WebKit's WebHTMLView.mm |
| 2139 // with minor modifications for code style and commenting. | 2103 // with minor modifications for code style and commenting. |
| 2140 // | 2104 // |
| 2141 // The 'public' interface is -setToolTipAtMousePoint:. This differs from | 2105 // The 'public' interface is -setToolTipAtMousePoint:. This differs from |
| 2142 // -setToolTip: in that the updated tooltip takes effect immediately, | 2106 // -setToolTip: in that the updated tooltip takes effect immediately, |
| 2143 // without the user's having to move the mouse out of and back into the view. | 2107 // without the user's having to move the mouse out of and back into the view. |
| 2144 // | 2108 // |
| 2145 // Unfortunately, doing this requires sending fake mouseEnter/Exit events to | 2109 // Unfortunately, doing this requires sending fake mouseEnter/Exit events to |
| (...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2781 if (!string) return NO; | 2745 if (!string) return NO; |
| 2782 | 2746 |
| 2783 // If the user is currently using an IME, confirm the IME input, | 2747 // If the user is currently using an IME, confirm the IME input, |
| 2784 // and then insert the text from the service, the same as TextEdit and Safari. | 2748 // and then insert the text from the service, the same as TextEdit and Safari. |
| 2785 [self confirmComposition]; | 2749 [self confirmComposition]; |
| 2786 [self insertText:string]; | 2750 [self insertText:string]; |
| 2787 return YES; | 2751 return YES; |
| 2788 } | 2752 } |
| 2789 | 2753 |
| 2790 @end | 2754 @end |
| OLD | NEW |