summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/renderer_host/render_view_host.cc41
-rw-r--r--chrome/browser/renderer_host/render_view_host.h13
-rw-r--r--chrome/browser/renderer_host/render_widget_host_view_mac.mm38
3 files changed, 91 insertions, 1 deletions
diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc
index 3c84f8c..3749f12 100644
--- a/chrome/browser/renderer_host/render_view_host.cc
+++ b/chrome/browser/renderer_host/render_view_host.cc
@@ -44,6 +44,7 @@
#include "chrome/common/notification_type.h"
#include "chrome/common/render_messages.h"
#include "chrome/common/render_messages_params.h"
+#include "chrome/common/render_view_commands.h"
#include "chrome/common/result_codes.h"
#include "chrome/common/thumbnail_score.h"
#include "chrome/common/translate_errors.h"
@@ -340,6 +341,22 @@ int RenderViewHost::GetPendingRequestId() {
return pending_request_id_;
}
+RenderViewHost::CommandState RenderViewHost::GetStateForCommand(
+ RenderViewCommand command) const {
+ if (command != RENDER_VIEW_COMMAND_TOGGLE_SPELL_CHECK)
+ LOG(DFATAL) << "Unknown command " << command;
+
+ std::map<RenderViewCommand, CommandState>::const_iterator it =
+ command_states_.find(command);
+ if (it == command_states_.end()) {
+ CommandState state;
+ state.is_enabled = false;
+ state.checked_state = RENDER_VIEW_COMMAND_CHECKED_STATE_UNCHECKED;
+ return state;
+ }
+ return it->second;
+}
+
void RenderViewHost::Stop() {
Send(new ViewMsg_Stop(routing_id()));
}
@@ -806,6 +823,8 @@ bool RenderViewHost::OnMessageReceived(const IPC::Message& msg) {
#endif
IPC_MESSAGE_HANDLER(ViewHostMsg_PagesReadyForPreview,
OnPagesReadyForPreview)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_CommandStateChanged,
+ OnCommandStateChanged)
// Have the super handle all other messages.
IPC_MESSAGE_UNHANDLED(handled = RenderWidgetHost::OnMessageReceived(msg))
IPC_END_MESSAGE_MAP_EX()
@@ -1738,3 +1757,25 @@ void RenderViewHost::OnPagesReadyForPreview(
// Send the printingDone msg for now.
Send(new ViewMsg_PrintingDone(routing_id(), params.document_cookie, true));
}
+
+void RenderViewHost::OnCommandStateChanged(int command,
+ bool is_enabled,
+ int checked_state) {
+ if (command != RENDER_VIEW_COMMAND_TOGGLE_SPELL_CHECK) {
+ LOG(DFATAL) << "Unknown command " << command;
+ return;
+ }
+
+ if (checked_state != RENDER_VIEW_COMMAND_CHECKED_STATE_UNCHECKED &&
+ checked_state != RENDER_VIEW_COMMAND_CHECKED_STATE_CHECKED &&
+ checked_state != RENDER_VIEW_COMMAND_CHECKED_STATE_MIXED) {
+ LOG(DFATAL) << "Invalid checked state " << checked_state;
+ return;
+ }
+
+ CommandState state;
+ state.is_enabled = is_enabled;
+ state.checked_state =
+ static_cast<RenderViewCommandCheckedState>(checked_state);
+ command_states_[static_cast<RenderViewCommand>(command)] = state;
+}
diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h
index 5ceddd7..e56a03b 100644
--- a/chrome/browser/renderer_host/render_view_host.h
+++ b/chrome/browser/renderer_host/render_view_host.h
@@ -15,6 +15,7 @@
#include "chrome/browser/ui/find_bar/find_bar_controller.h"
#include "chrome/common/content_settings_types.h"
#include "chrome/common/page_zoom.h"
+#include "chrome/common/render_view_commands.h"
#include "chrome/common/translate_errors.h"
#include "chrome/common/view_types.h"
#include "chrome/common/window_container_type.h"
@@ -199,6 +200,12 @@ class RenderViewHost : public RenderWidgetHost {
// hangs, in which case we need to swap to the pending RenderViewHost.
int GetPendingRequestId();
+ struct CommandState {
+ bool is_enabled;
+ RenderViewCommandCheckedState checked_state;
+ };
+ CommandState GetStateForCommand(RenderViewCommand command) const;
+
// Stops the current load.
void Stop();
@@ -641,6 +648,9 @@ class RenderViewHost : public RenderWidgetHost {
void OnScriptEvalResponse(int id, const ListValue& result);
void OnPagesReadyForPreview(
const ViewHostMsg_DidPreviewDocument_Params& params);
+ void OnCommandStateChanged(int command,
+ bool is_enabled,
+ int checked_state);
#if defined(OS_MACOSX)
void OnMsgShowPopup(const ViewHostMsg_ShowPopup_Params& params);
@@ -729,6 +739,9 @@ class RenderViewHost : public RenderWidgetHost {
// The termination status of the last render view that terminated.
base::TerminationStatus render_view_termination_status_;
+ // The enabled/disabled states of various commands.
+ std::map<RenderViewCommand, CommandState> command_states_;
+
DISALLOW_COPY_AND_ASSIGN(RenderViewHost);
};
diff --git a/chrome/browser/renderer_host/render_widget_host_view_mac.mm b/chrome/browser/renderer_host/render_widget_host_view_mac.mm
index 7c84fb3..5f65e6d 100644
--- a/chrome/browser/renderer_host/render_widget_host_view_mac.mm
+++ b/chrome/browser/renderer_host/render_widget_host_view_mac.mm
@@ -1969,10 +1969,38 @@ void RenderWidgetHostViewMac::SetTextInputActive(bool active) {
action == @selector(copy:) ||
action == @selector(copyToFindPboard:) ||
action == @selector(paste:) ||
- action == @selector(pasteAsPlainText:)) {
+ action == @selector(pasteAsPlainText:) ||
+ action == @selector(checkSpelling:)) {
return renderWidgetHostView_->render_widget_host_->IsRenderView();
}
+ if (action == @selector(toggleContinuousSpellChecking:)) {
+ RenderViewHost::CommandState state;
+ state.is_enabled = false;
+ state.checked_state = RENDER_VIEW_COMMAND_CHECKED_STATE_UNCHECKED;
+ if (renderWidgetHostView_->render_widget_host_->IsRenderView()) {
+ state = static_cast<RenderViewHost*>(
+ renderWidgetHostView_->render_widget_host_)->
+ GetStateForCommand(RENDER_VIEW_COMMAND_TOGGLE_SPELL_CHECK);
+ }
+ if ([(id)item respondsToSelector:@selector(setState:)]) {
+ NSCellStateValue checked_state;
+ switch (state.checked_state) {
+ case RENDER_VIEW_COMMAND_CHECKED_STATE_UNCHECKED:
+ checked_state = NSOffState;
+ break;
+ case RENDER_VIEW_COMMAND_CHECKED_STATE_CHECKED:
+ checked_state = NSOnState;
+ break;
+ case RENDER_VIEW_COMMAND_CHECKED_STATE_MIXED:
+ checked_state = NSMixedState;
+ break;
+ }
+ [(id)item setState:checked_state];
+ }
+ return state.is_enabled;
+ }
+
return editCommand_helper_->IsMenuItemEnabled(action, self);
}
@@ -2124,6 +2152,7 @@ void RenderWidgetHostViewMac::SetTextInputActive(bool active) {
// other spelling panel methods. This is probably because Apple assumes that the
// the spelling panel will be used with an NSText, which will automatically
// catch this and advance to the next word for you. Thanks Apple.
+// This is also called from the Edit -> Spelling -> Check Spelling menu item.
- (void)checkSpelling:(id)sender {
RenderWidgetHostViewMac* thisHostView = [self renderWidgetHostViewMac];
thisHostView->GetRenderWidgetHost()->AdvanceToNextMisspelling();
@@ -2146,6 +2175,13 @@ void RenderWidgetHostViewMac::SetTextInputActive(bool active) {
SpellCheckerPlatform::SpellingPanelVisible());
}
+- (void)toggleContinuousSpellChecking:(id)sender {
+ if (renderWidgetHostView_->render_widget_host_->IsRenderView()) {
+ static_cast<RenderViewHost*>(renderWidgetHostView_->render_widget_host_)->
+ ToggleSpellCheck();
+ }
+}
+
// END Spellchecking methods
// Below is the nasty tooltip stuff -- copied from WebKit's WebHTMLView.mm