Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 // The Mac interface forwards most of these commands to the application layer, | 5 // The Mac interface forwards most of these commands to the application layer, |
| 6 // and I'm not really sure what to do about most of them. | 6 // and I'm not really sure what to do about most of them. |
| 7 | 7 |
| 8 #include "config.h" | 8 #include "config.h" |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 | 66 |
| 67 } | 67 } |
| 68 | 68 |
| 69 EditorClientImpl::EditorClientImpl(WebView* web_view) | 69 EditorClientImpl::EditorClientImpl(WebView* web_view) |
| 70 : web_view_(static_cast<WebViewImpl*>(web_view)), | 70 : web_view_(static_cast<WebViewImpl*>(web_view)), |
| 71 use_editor_delegate_(false), | 71 use_editor_delegate_(false), |
| 72 in_redo_(false), | 72 in_redo_(false), |
| 73 backspace_pressed_(false), | 73 backspace_pressed_(false), |
| 74 // Don't complain about using "this" in initializer list. | 74 // Don't complain about using "this" in initializer list. |
| 75 MSVC_PUSH_DISABLE_WARNING(4355) | 75 MSVC_PUSH_DISABLE_WARNING(4355) |
| 76 autofill_factory_(this) { | 76 autofill_factory_(this), |
| 77 spell_check_this_field_status_(SPELLCHECK_AUTOMATIC) { | |
| 77 MSVC_POP_WARNING() | 78 MSVC_POP_WARNING() |
| 78 } | 79 } |
| 79 | 80 |
| 80 EditorClientImpl::~EditorClientImpl() { | 81 EditorClientImpl::~EditorClientImpl() { |
| 81 } | 82 } |
| 82 | 83 |
| 83 void EditorClientImpl::pageDestroyed() { | 84 void EditorClientImpl::pageDestroyed() { |
| 84 // Called by the Page (which owns the editor client) when the page is going | 85 // Called by the Page (which owns the editor client) when the page is going |
| 85 // away. This should cause us to delete ourselves, which is stupid. The page | 86 // away. This should cause us to delete ourselves, which is stupid. The page |
| 86 // should just delete us when it's going away. Oh well. | 87 // should just delete us when it's going away. Oh well. |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 106 | 107 |
| 107 bool EditorClientImpl::isSelectTrailingWhitespaceEnabled() { | 108 bool EditorClientImpl::isSelectTrailingWhitespaceEnabled() { |
| 108 if (use_editor_delegate_) { | 109 if (use_editor_delegate_) { |
| 109 WebViewDelegate* d = web_view_->delegate(); | 110 WebViewDelegate* d = web_view_->delegate(); |
| 110 if (d) | 111 if (d) |
| 111 return d->IsSelectTrailingWhitespaceEnabled(); | 112 return d->IsSelectTrailingWhitespaceEnabled(); |
| 112 } | 113 } |
| 113 return true; | 114 return true; |
| 114 } | 115 } |
| 115 | 116 |
| 117 bool EditorClientImpl::ShouldSpellcheckByDefault() { | |
|
brettw
2008/12/12 19:12:37
Is it possible to make this function const? If so,
| |
| 118 const WebCore::Frame* frame = web_view_->GetFocusedWebCoreFrame(); | |
| 119 if (!frame) | |
| 120 return false; | |
| 121 const WebCore::Editor* editor = frame->editor(); | |
| 122 if (!editor) | |
| 123 return false; | |
| 124 const WebCore::Document* document = frame->document(); | |
| 125 if (!document) | |
| 126 return false; | |
| 127 const WebCore::Node* node = document->focusedNode(); | |
| 128 if (!node) | |
| 129 return false; | |
| 130 const WebCore::RenderObject* renderer = node->renderer(); | |
| 131 if (!renderer) | |
| 132 return false; | |
| 133 // We should also retrieve the contenteditable attribute of this element to | |
| 134 // determine if this element needs spell-checking. | |
| 135 const WebCore::EUserModify user_modify = renderer->style()->userModify(); | |
| 136 return (renderer->isTextArea() && editor->canEdit()) || | |
| 137 user_modify == WebCore::READ_WRITE || | |
| 138 user_modify == WebCore::READ_WRITE_PLAINTEXT_ONLY; | |
| 139 } | |
| 140 | |
| 116 bool EditorClientImpl::isContinuousSpellCheckingEnabled() { | 141 bool EditorClientImpl::isContinuousSpellCheckingEnabled() { |
| 117 // Spell check everything if possible. | 142 if (spell_check_this_field_status_ == SPELLCHECK_FORCED_OFF) |
| 118 // FIXME(brettw) This should be modified to do reasonable defaults depending | 143 return false; |
| 119 // on input type, and probably also allow the user to turn spellchecking on | 144 else if (spell_check_this_field_status_ == SPELLCHECK_FORCED_ON) |
| 120 // for individual fields. | 145 return true; |
| 121 return true; | 146 else |
| 147 return ShouldSpellcheckByDefault(); | |
| 122 } | 148 } |
| 123 | 149 |
| 124 void EditorClientImpl::toggleContinuousSpellChecking() { | 150 void EditorClientImpl::toggleContinuousSpellChecking() { |
| 125 NOTIMPLEMENTED(); | 151 if (isContinuousSpellCheckingEnabled()) |
| 152 spell_check_this_field_status_ = SPELLCHECK_FORCED_OFF; | |
| 153 else | |
| 154 spell_check_this_field_status_ = SPELLCHECK_FORCED_ON; | |
| 126 } | 155 } |
| 127 | 156 |
| 128 bool EditorClientImpl::isGrammarCheckingEnabled() { | 157 bool EditorClientImpl::isGrammarCheckingEnabled() { |
| 129 return false; | 158 return false; |
| 130 } | 159 } |
| 131 | 160 |
| 132 void EditorClientImpl::toggleGrammarChecking() { | 161 void EditorClientImpl::toggleGrammarChecking() { |
| 133 NOTIMPLEMENTED(); | 162 NOTIMPLEMENTED(); |
| 134 } | 163 } |
| 135 | 164 |
| (...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 711 } | 740 } |
| 712 | 741 |
| 713 void EditorClientImpl::checkSpellingOfString(const UChar* str, int length, | 742 void EditorClientImpl::checkSpellingOfString(const UChar* str, int length, |
| 714 int* misspellingLocation, | 743 int* misspellingLocation, |
| 715 int* misspellingLength) { | 744 int* misspellingLength) { |
| 716 // SpellCheckWord will write (0, 0) into the output vars, which is what our | 745 // SpellCheckWord will write (0, 0) into the output vars, which is what our |
| 717 // caller expects if the word is spelled correctly. | 746 // caller expects if the word is spelled correctly. |
| 718 int spell_location = -1; | 747 int spell_location = -1; |
| 719 int spell_length = 0; | 748 int spell_length = 0; |
| 720 WebViewDelegate* d = web_view_->delegate(); | 749 WebViewDelegate* d = web_view_->delegate(); |
| 721 if (web_view_->FocusedFrameNeedsSpellchecking() && d) { | 750 if (isContinuousSpellCheckingEnabled() && d) { |
| 722 std::wstring word = | 751 std::wstring word = |
| 723 webkit_glue::StringToStdWString(WebCore::String(str, length)); | 752 webkit_glue::StringToStdWString(WebCore::String(str, length)); |
| 724 d->SpellCheck(word, spell_location, spell_length); | 753 d->SpellCheck(word, spell_location, spell_length); |
| 725 } else { | 754 } else { |
| 726 spell_location = 0; | 755 spell_location = 0; |
| 727 spell_length = 0; | 756 spell_length = 0; |
| 728 } | 757 } |
| 729 | 758 |
| 730 // Note: the Mac code checks if the pointers are NULL before writing to them, | 759 // Note: the Mac code checks if the pointers are NULL before writing to them, |
| 731 // so we do too. | 760 // so we do too. |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 850 } | 879 } |
| 851 return L"(UNKNOWN AFFINITY)"; | 880 return L"(UNKNOWN AFFINITY)"; |
| 852 } | 881 } |
| 853 | 882 |
| 854 std::wstring EditorClientImpl::Describe(WebCore::CSSStyleDeclaration* style) { | 883 std::wstring EditorClientImpl::Describe(WebCore::CSSStyleDeclaration* style) { |
| 855 // TODO(pamg): Implement me. It's not clear what WebKit produces for this | 884 // TODO(pamg): Implement me. It's not clear what WebKit produces for this |
| 856 // (their [style description] method), and none of the layout tests provide | 885 // (their [style description] method), and none of the layout tests provide |
| 857 // an example. But because none of them use it, it's not yet important. | 886 // an example. But because none of them use it, it's not yet important. |
| 858 return std::wstring(); | 887 return std::wstring(); |
| 859 } | 888 } |
| OLD | NEW |