OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/cocoa/tab_contents/render_view_context_menu_mac.h" | 5 #include "chrome/browser/ui/cocoa/tab_contents/render_view_context_menu_mac.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #import "base/mac/scoped_sending_event.h" | 8 #import "base/mac/scoped_sending_event.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 break; | 122 break; |
123 | 123 |
124 case IDC_WRITING_DIRECTION_DEFAULT: | 124 case IDC_WRITING_DIRECTION_DEFAULT: |
125 // WebKit's current behavior is for this menu item to always be disabled. | 125 // WebKit's current behavior is for this menu item to always be disabled. |
126 NOTREACHED(); | 126 NOTREACHED(); |
127 break; | 127 break; |
128 | 128 |
129 case IDC_WRITING_DIRECTION_RTL: | 129 case IDC_WRITING_DIRECTION_RTL: |
130 case IDC_WRITING_DIRECTION_LTR: { | 130 case IDC_WRITING_DIRECTION_LTR: { |
131 content::RenderViewHost* view_host = GetRenderViewHost(); | 131 content::RenderViewHost* view_host = GetRenderViewHost(); |
132 WebKit::WebTextDirection dir = WebKit::WebTextDirectionLeftToRight; | 132 blink::WebTextDirection dir = blink::WebTextDirectionLeftToRight; |
133 if (command_id == IDC_WRITING_DIRECTION_RTL) | 133 if (command_id == IDC_WRITING_DIRECTION_RTL) |
134 dir = WebKit::WebTextDirectionRightToLeft; | 134 dir = blink::WebTextDirectionRightToLeft; |
135 view_host->UpdateTextDirection(dir); | 135 view_host->UpdateTextDirection(dir); |
136 view_host->NotifyTextDirection(); | 136 view_host->NotifyTextDirection(); |
137 break; | 137 break; |
138 } | 138 } |
139 | 139 |
140 default: | 140 default: |
141 RenderViewContextMenu::ExecuteCommand(command_id, event_flags); | 141 RenderViewContextMenu::ExecuteCommand(command_id, event_flags); |
142 break; | 142 break; |
143 } | 143 } |
144 } | 144 } |
145 | 145 |
146 bool RenderViewContextMenuMac::IsCommandIdChecked(int command_id) const { | 146 bool RenderViewContextMenuMac::IsCommandIdChecked(int command_id) const { |
147 switch (command_id) { | 147 switch (command_id) { |
148 case IDC_WRITING_DIRECTION_DEFAULT: | 148 case IDC_WRITING_DIRECTION_DEFAULT: |
149 return params_.writing_direction_default & | 149 return params_.writing_direction_default & |
150 WebKit::WebContextMenuData::CheckableMenuItemChecked; | 150 blink::WebContextMenuData::CheckableMenuItemChecked; |
151 case IDC_WRITING_DIRECTION_RTL: | 151 case IDC_WRITING_DIRECTION_RTL: |
152 return params_.writing_direction_right_to_left & | 152 return params_.writing_direction_right_to_left & |
153 WebKit::WebContextMenuData::CheckableMenuItemChecked; | 153 blink::WebContextMenuData::CheckableMenuItemChecked; |
154 case IDC_WRITING_DIRECTION_LTR: | 154 case IDC_WRITING_DIRECTION_LTR: |
155 return params_.writing_direction_left_to_right & | 155 return params_.writing_direction_left_to_right & |
156 WebKit::WebContextMenuData::CheckableMenuItemChecked; | 156 blink::WebContextMenuData::CheckableMenuItemChecked; |
157 | 157 |
158 default: | 158 default: |
159 return RenderViewContextMenu::IsCommandIdChecked(command_id); | 159 return RenderViewContextMenu::IsCommandIdChecked(command_id); |
160 } | 160 } |
161 } | 161 } |
162 | 162 |
163 bool RenderViewContextMenuMac::IsCommandIdEnabled(int command_id) const { | 163 bool RenderViewContextMenuMac::IsCommandIdEnabled(int command_id) const { |
164 switch (command_id) { | 164 switch (command_id) { |
165 case IDC_CONTENT_CONTEXT_LOOK_UP_IN_DICTIONARY: | 165 case IDC_CONTENT_CONTEXT_LOOK_UP_IN_DICTIONARY: |
166 // This is OK because the menu is not shown when it isn't | 166 // This is OK because the menu is not shown when it isn't |
167 // appropriate. | 167 // appropriate. |
168 return true; | 168 return true; |
169 | 169 |
170 case IDC_CONTENT_CONTEXT_SPEECH_START_SPEAKING: | 170 case IDC_CONTENT_CONTEXT_SPEECH_START_SPEAKING: |
171 // This is OK because the menu is not shown when it isn't | 171 // This is OK because the menu is not shown when it isn't |
172 // appropriate. | 172 // appropriate. |
173 return true; | 173 return true; |
174 | 174 |
175 case IDC_CONTENT_CONTEXT_SPEECH_STOP_SPEAKING: { | 175 case IDC_CONTENT_CONTEXT_SPEECH_STOP_SPEAKING: { |
176 content::RenderWidgetHostView* view = GetRenderViewHost()->GetView(); | 176 content::RenderWidgetHostView* view = GetRenderViewHost()->GetView(); |
177 return view && view->IsSpeaking(); | 177 return view && view->IsSpeaking(); |
178 } | 178 } |
179 | 179 |
180 case IDC_WRITING_DIRECTION_DEFAULT: // Provided to match OS defaults. | 180 case IDC_WRITING_DIRECTION_DEFAULT: // Provided to match OS defaults. |
181 return params_.writing_direction_default & | 181 return params_.writing_direction_default & |
182 WebKit::WebContextMenuData::CheckableMenuItemEnabled; | 182 blink::WebContextMenuData::CheckableMenuItemEnabled; |
183 case IDC_WRITING_DIRECTION_RTL: | 183 case IDC_WRITING_DIRECTION_RTL: |
184 return params_.writing_direction_right_to_left & | 184 return params_.writing_direction_right_to_left & |
185 WebKit::WebContextMenuData::CheckableMenuItemEnabled; | 185 blink::WebContextMenuData::CheckableMenuItemEnabled; |
186 case IDC_WRITING_DIRECTION_LTR: | 186 case IDC_WRITING_DIRECTION_LTR: |
187 return params_.writing_direction_left_to_right & | 187 return params_.writing_direction_left_to_right & |
188 WebKit::WebContextMenuData::CheckableMenuItemEnabled; | 188 blink::WebContextMenuData::CheckableMenuItemEnabled; |
189 | 189 |
190 default: | 190 default: |
191 return RenderViewContextMenu::IsCommandIdEnabled(command_id); | 191 return RenderViewContextMenu::IsCommandIdEnabled(command_id); |
192 } | 192 } |
193 } | 193 } |
194 | 194 |
195 bool RenderViewContextMenuMac::GetAcceleratorForCommandId( | 195 bool RenderViewContextMenuMac::GetAcceleratorForCommandId( |
196 int command_id, | 196 int command_id, |
197 ui::Accelerator* accelerator) { | 197 ui::Accelerator* accelerator) { |
198 return false; | 198 return false; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 command_id); | 270 command_id); |
271 if (!item) | 271 if (!item) |
272 return; | 272 return; |
273 | 273 |
274 // Update the returned NSMenuItem directly so we can update it immediately. | 274 // Update the returned NSMenuItem directly so we can update it immediately. |
275 [item setEnabled:enabled]; | 275 [item setEnabled:enabled]; |
276 [item setTitle:SysUTF16ToNSString(title)]; | 276 [item setTitle:SysUTF16ToNSString(title)]; |
277 [item setHidden:hidden]; | 277 [item setHidden:hidden]; |
278 [[item menu] itemChanged:item]; | 278 [[item menu] itemChanged:item]; |
279 } | 279 } |
OLD | NEW |