diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-04 05:42:51 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-04 05:42:51 +0000 |
commit | 79dbc66fba17d6b4967fe86a577b11d15548cdec (patch) | |
tree | df2853054e47aa76cea79eb6664f4c21cb54bd9e /webkit/glue | |
parent | bdc66ceff07dac7b74ddea70fabdf535936d39b1 (diff) | |
download | chromium_src-79dbc66fba17d6b4967fe86a577b11d15548cdec.zip chromium_src-79dbc66fba17d6b4967fe86a577b11d15548cdec.tar.gz chromium_src-79dbc66fba17d6b4967fe86a577b11d15548cdec.tar.bz2 |
Hook up WebEditingClient.
Moves the WebViewDelegate parameter back to WebView::Create and
adds a second parameter for WebEditingClient.
I had hoped to make the WebEditingClient NULL for RenderView on
Windows and Mac, but that turned out to not be an option. I need
a few methods on all platforms.
The Describe* functions from EditorClientImpl are moved into the
TestWebViewDelegate since they are only applicable to layout tests.
R=dglazkov
BUG=
TEST=none
Review URL: http://codereview.chromium.org/195008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25432 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue')
-rw-r--r-- | webkit/glue/editor_client_impl.cc | 278 | ||||
-rw-r--r-- | webkit/glue/editor_client_impl.h | 26 | ||||
-rw-r--r-- | webkit/glue/webview.h | 16 | ||||
-rw-r--r-- | webkit/glue/webview_delegate.h | 71 | ||||
-rw-r--r-- | webkit/glue/webview_impl.cc | 31 | ||||
-rw-r--r-- | webkit/glue/webview_impl.h | 9 | ||||
-rw-r--r-- | webkit/glue/webworker_impl.cc | 4 |
7 files changed, 111 insertions, 324 deletions
diff --git a/webkit/glue/editor_client_impl.cc b/webkit/glue/editor_client_impl.cc index 22ab39d..64a1869 100644 --- a/webkit/glue/editor_client_impl.cc +++ b/webkit/glue/editor_client_impl.cc @@ -26,7 +26,12 @@ #undef LOG #include "base/message_loop.h" #include "base/string_util.h" +#include "webkit/api/public/WebEditingAction.h" +#include "webkit/api/public/WebEditingClient.h" #include "webkit/api/public/WebKit.h" +#include "webkit/api/public/WebNode.h" +#include "webkit/api/public/WebRange.h" +#include "webkit/api/public/WebTextAffinity.h" #include "webkit/glue/autofill_form.h" #include "webkit/glue/dom_operations.h" #include "webkit/glue/editor_client_impl.h" @@ -36,6 +41,10 @@ #include "webkit/glue/webview_impl.h" using webkit_glue::AutofillForm; +using WebKit::WebEditingAction; +using WebKit::WebEditingClient; +using WebKit::WebString; +using WebKit::WebTextAffinity; // Arbitrary depth limit for the undo stack, to keep it from using // unbounded memory. This is the maximum number of distinct undoable @@ -47,48 +56,21 @@ static const size_t kMaximumUndoStackDepth = 1000; // (so to avoid sending long strings through IPC). static const size_t kMaximumTextSizeForAutofill = 1000; -namespace { - -// Record an editor command from the keyDownEntries[] below. We ignore the -// Move* and Insert* commands because they're not that interesting. -void MaybeRecordCommand(WebViewDelegate* d, const char* command_name) { - if (!d) - return; - - const char* move_prefix = "Move"; - const char* insert_prefix = "Insert"; - const char* delete_prefix = "Delete"; - // Ignore all the Move*, Insert*, and Delete* commands. - if (0 == strncmp(command_name, move_prefix, sizeof(move_prefix)) || - 0 == strncmp(command_name, insert_prefix, sizeof(insert_prefix)) || - 0 == strncmp(command_name, delete_prefix, sizeof(delete_prefix))) { - return; - } - d->UserMetricsRecordComputedAction(UTF8ToWide(command_name)); -} - -} - -EditorClientImpl::EditorClientImpl(WebView* web_view) - : web_view_(static_cast<WebViewImpl*>(web_view)), - use_editor_delegate_(false), +EditorClientImpl::EditorClientImpl(WebViewImpl* web_view, + WebEditingClient* editing_client) + : web_view_(web_view), + editing_client_(editing_client), in_redo_(false), backspace_or_delete_pressed_(false), spell_check_this_field_status_(SPELLCHECK_AUTOMATIC), -// Don't complain about using "this" in initializer list. -MSVC_PUSH_DISABLE_WARNING(4355) - autofill_factory_(this) { -MSVC_POP_WARNING() + ALLOW_THIS_IN_INITIALIZER_LIST(autofill_factory_(this)) { } EditorClientImpl::~EditorClientImpl() { } void EditorClientImpl::pageDestroyed() { - // Called by the Page (which owns the editor client) when the page is going - // away. This should cause us to delete ourselves, which is stupid. The page - // should just delete us when it's going away. Oh well. - delete this; + // Ignored since our lifetime is managed by the WebViewImpl. } bool EditorClientImpl::shouldShowDeleteInterface(WebCore::HTMLElement* elem) { @@ -100,24 +82,18 @@ bool EditorClientImpl::shouldShowDeleteInterface(WebCore::HTMLElement* elem) { } bool EditorClientImpl::smartInsertDeleteEnabled() { - if (use_editor_delegate_) { - WebViewDelegate* d = web_view_->delegate(); - if (d) - return d->SmartInsertDeleteEnabled(); - } + if (editing_client_) + return editing_client_->isSmartInsertDeleteEnabled(); return true; } bool EditorClientImpl::isSelectTrailingWhitespaceEnabled() { - if (use_editor_delegate_) { - WebViewDelegate* d = web_view_->delegate(); - if (d) - return d->IsSelectTrailingWhitespaceEnabled(); - } + if (editing_client_) + return editing_client_->isSelectTrailingWhitespaceEnabled(); #if defined(OS_WIN) return true; -#elif defined(OS_MACOSX) || defined(OS_LINUX) +#else return false; #endif } @@ -155,10 +131,9 @@ bool EditorClientImpl::ShouldSpellcheckByDefault() { bool EditorClientImpl::isContinuousSpellCheckingEnabled() { if (spell_check_this_field_status_ == SPELLCHECK_FORCED_OFF) return false; - else if (spell_check_this_field_status_ == SPELLCHECK_FORCED_ON) + if (spell_check_this_field_status_ == SPELLCHECK_FORCED_ON) return true; - else - return ShouldSpellcheckByDefault(); + return ShouldSpellcheckByDefault(); } void EditorClientImpl::toggleContinuousSpellChecking() { @@ -186,19 +161,17 @@ bool EditorClientImpl::isEditable() { } bool EditorClientImpl::shouldBeginEditing(WebCore::Range* range) { - if (use_editor_delegate_) { - WebViewDelegate* d = web_view_->delegate(); - if (d) - return d->ShouldBeginEditing(web_view_, Describe(range)); + if (editing_client_) { + return editing_client_->shouldBeginEditing( + webkit_glue::RangeToWebRange(range)); } return true; } bool EditorClientImpl::shouldEndEditing(WebCore::Range* range) { - if (use_editor_delegate_) { - WebViewDelegate* d = web_view_->delegate(); - if (d) - return d->ShouldEndEditing(web_view_, Describe(range)); + if (editing_client_) { + return editing_client_->shouldEndEditing( + webkit_glue::RangeToWebRange(range)); } return true; } @@ -206,14 +179,11 @@ bool EditorClientImpl::shouldEndEditing(WebCore::Range* range) { bool EditorClientImpl::shouldInsertNode(WebCore::Node* node, WebCore::Range* range, WebCore::EditorInsertAction action) { - if (use_editor_delegate_) { - WebViewDelegate* d = web_view_->delegate(); - if (d) { - return d->ShouldInsertNode(web_view_, - Describe(node), - Describe(range), - Describe(action)); - } + if (editing_client_) { + return editing_client_->shouldInsertNode( + webkit_glue::NodeToWebNode(node), + webkit_glue::RangeToWebRange(range), + static_cast<WebEditingAction>(action)); } return true; } @@ -221,25 +191,20 @@ bool EditorClientImpl::shouldInsertNode(WebCore::Node* node, bool EditorClientImpl::shouldInsertText(const WebCore::String& text, WebCore::Range* range, WebCore::EditorInsertAction action) { - if (use_editor_delegate_) { - WebViewDelegate* d = web_view_->delegate(); - if (d) { - std::wstring wstr = webkit_glue::StringToStdWString(text); - return d->ShouldInsertText(web_view_, - wstr, - Describe(range), - Describe(action)); - } + if (editing_client_) { + return editing_client_->shouldInsertText( + webkit_glue::StringToWebString(text), + webkit_glue::RangeToWebRange(range), + static_cast<WebEditingAction>(action)); } return true; } bool EditorClientImpl::shouldDeleteRange(WebCore::Range* range) { - if (use_editor_delegate_) { - WebViewDelegate* d = web_view_->delegate(); - if (d) - return d->ShouldDeleteRange(web_view_, Describe(range)); + if (editing_client_) { + return editing_client_->shouldDeleteRange( + webkit_glue::RangeToWebRange(range)); } return true; } @@ -248,25 +213,23 @@ bool EditorClientImpl::shouldChangeSelectedRange(WebCore::Range* from_range, WebCore::Range* to_range, WebCore::EAffinity affinity, bool still_selecting) { - if (use_editor_delegate_) { - WebViewDelegate* d = web_view_->delegate(); - if (d) { - return d->ShouldChangeSelectedRange(web_view_, - Describe(from_range), - Describe(to_range), - Describe(affinity), - still_selecting); - } + if (editing_client_) { + return editing_client_->shouldChangeSelectedRange( + webkit_glue::RangeToWebRange(from_range), + webkit_glue::RangeToWebRange(to_range), + static_cast<WebTextAffinity>(affinity), + still_selecting); } return true; } bool EditorClientImpl::shouldApplyStyle(WebCore::CSSStyleDeclaration* style, WebCore::Range* range) { - if (use_editor_delegate_) { - WebViewDelegate* d = web_view_->delegate(); - if (d) - return d->ShouldApplyStyle(web_view_, Describe(style), Describe(range)); + if (editing_client_) { + // TODO(darin): Pass a reference to the CSSStyleDeclaration somehow. + return editing_client_->shouldApplyStyle( + WebString(), + webkit_glue::RangeToWebRange(range)); } return true; } @@ -278,38 +241,26 @@ bool EditorClientImpl::shouldMoveRangeAfterDelete( } void EditorClientImpl::didBeginEditing() { - if (use_editor_delegate_) { - WebViewDelegate* d = web_view_->delegate(); - if (d) - d->DidBeginEditing(); - } + if (editing_client_) + editing_client_->didBeginEditing(); } void EditorClientImpl::respondToChangedSelection() { - if (use_editor_delegate_) { - WebViewDelegate* d = web_view_->delegate(); - if (d) { - WebCore::Frame* frame = web_view_->GetFocusedWebCoreFrame(); - if (frame) - d->DidChangeSelection(!frame->selection()->isRange()); - } + if (editing_client_) { + WebCore::Frame* frame = web_view_->GetFocusedWebCoreFrame(); + if (frame) + editing_client_->didChangeSelection(!frame->selection()->isRange()); } } void EditorClientImpl::respondToChangedContents() { - if (use_editor_delegate_) { - WebViewDelegate* d = web_view_->delegate(); - if (d) - d->DidChangeContents(); - } + if (editing_client_) + editing_client_->didChangeContents(); } void EditorClientImpl::didEndEditing() { - if (use_editor_delegate_) { - WebViewDelegate* d = web_view_->delegate(); - if (d) - d->DidEndEditing(); - } + if (editing_client_) + editing_client_->didEndEditing(); } void EditorClientImpl::didWriteSelectionToPasteboard() { @@ -599,7 +550,7 @@ bool EditorClientImpl::handleEditingKeyboardEvent( if (!frame) return false; - const char* command_name = interpretKeyEvent(evt); + WebCore::String command_name = interpretKeyEvent(evt); WebCore::Editor::Command command = frame->editor()->command(command_name); if (keyEvent->type() == WebCore::PlatformKeyboardEvent::RawKeyDown) { @@ -608,19 +559,23 @@ bool EditorClientImpl::handleEditingKeyboardEvent( // so we leave it upon WebCore to either handle them immediately // (e.g. Tab that changes focus) or let a keypress event be generated // (e.g. Tab that inserts a Tab character, or Enter). - if (command.isTextInsertion() || !command_name) + if (command.isTextInsertion() || command_name.isEmpty()) return false; if (command.execute(evt)) { - WebViewDelegate* d = web_view_->delegate(); - MaybeRecordCommand(d, command_name); + if (editing_client_) { + editing_client_->didExecuteCommand( + webkit_glue::StringToWebString(command_name)); + } return true; } return false; } if (command.execute(evt)) { - WebViewDelegate* d = web_view_->delegate(); - MaybeRecordCommand(d, command_name); + if (editing_client_) { + editing_client_->didExecuteCommand( + webkit_glue::StringToWebString(command_name)); + } return true; } @@ -942,91 +897,6 @@ void EditorClientImpl::getGuessesForWord(const WebCore::String&, } void EditorClientImpl::setInputMethodState(bool enabled) { - WebViewDelegate* d = web_view_->delegate(); - if (d) { - d->SetInputMethodState(enabled); - } -} - - -std::wstring EditorClientImpl::DescribeOrError(int number, - WebCore::ExceptionCode ec) { - if (ec) - return L"ERROR"; - - return IntToWString(number); -} - -std::wstring EditorClientImpl::DescribeOrError(WebCore::Node* node, - WebCore::ExceptionCode ec) { - if (ec) - return L"ERROR"; - - return Describe(node); -} - -// These Describe() functions match the output expected by the layout tests. -std::wstring EditorClientImpl::Describe(WebCore::Range* range) { - if (range) { - WebCore::ExceptionCode exception = 0; - std::wstring str = L"range from "; - int offset = range->startOffset(exception); - str.append(DescribeOrError(offset, exception)); - str.append(L" of "); - WebCore::Node* container = range->startContainer(exception); - str.append(DescribeOrError(container, exception)); - str.append(L" to "); - offset = range->endOffset(exception); - str.append(DescribeOrError(offset, exception)); - str.append(L" of "); - container = range->endContainer(exception); - str.append(DescribeOrError(container, exception)); - return str; - } - return L"(null)"; -} - -// See comment for Describe(), above. -std::wstring EditorClientImpl::Describe(WebCore::Node* node) { - if (node) { - std::wstring str = webkit_glue::StringToStdWString(node->nodeName()); - WebCore::Node* parent = node->parentNode(); - if (parent) { - str.append(L" > "); - str.append(Describe(parent)); - } - return str; - } - return L"(null)"; -} - -// See comment for Describe(), above. -std::wstring EditorClientImpl::Describe(WebCore::EditorInsertAction action) { - switch (action) { - case WebCore::EditorInsertActionTyped: - return L"WebViewInsertActionTyped"; - case WebCore::EditorInsertActionPasted: - return L"WebViewInsertActionPasted"; - case WebCore::EditorInsertActionDropped: - return L"WebViewInsertActionDropped"; - } - return L"(UNKNOWN ACTION)"; -} - -// See comment for Describe(), above. -std::wstring EditorClientImpl::Describe(WebCore::EAffinity affinity) { - switch (affinity) { - case WebCore::UPSTREAM: - return L"NSSelectionAffinityUpstream"; - case WebCore::DOWNSTREAM: - return L"NSSelectionAffinityDownstream"; - } - return L"(UNKNOWN AFFINITY)"; -} - -std::wstring EditorClientImpl::Describe(WebCore::CSSStyleDeclaration* style) { - // TODO(pamg): Implement me. It's not clear what WebKit produces for this - // (their [style description] method), and none of the layout tests provide - // an example. But because none of them use it, it's not yet important. - return std::wstring(); + if (editing_client_) + editing_client_->setInputMethodEnabled(enabled); } diff --git a/webkit/glue/editor_client_impl.h b/webkit/glue/editor_client_impl.h index ad133a7..1ca7ce1 100644 --- a/webkit/glue/editor_client_impl.h +++ b/webkit/glue/editor_client_impl.h @@ -18,13 +18,19 @@ class HTMLInputElement; class Node; class PlatformKeyboardEvent; } +namespace WebKit { +class WebEditingClient; +} -class WebView; class WebViewImpl; class EditorClientImpl : public WebCore::EditorClient { public: - EditorClientImpl(WebView* web_view); + EditorClientImpl(WebViewImpl* web_view, + WebKit::WebEditingClient* editing_client); + + void DropEditingClient() { editing_client_ = NULL; } + virtual ~EditorClientImpl(); virtual void pageDestroyed(); @@ -103,20 +109,6 @@ class EditorClientImpl : public WebCore::EditorClient { WTF::Vector<WebCore::String>& guesses); virtual void setInputMethodState(bool enabled); - void SetUseEditorDelegate(bool value) { use_editor_delegate_ = value; } - - // It would be better to add these methods to the objects they describe, but - // those are in WebCore and therefore inaccessible. - virtual std::wstring DescribeOrError(int number, - WebCore::ExceptionCode ec); - virtual std::wstring DescribeOrError(WebCore::Node* node, - WebCore::ExceptionCode ec); - virtual std::wstring Describe(WebCore::Range* range); - virtual std::wstring Describe(WebCore::Node* node); - virtual std::wstring Describe(WebCore::EditorInsertAction action); - virtual std::wstring Describe(WebCore::EAffinity affinity); - virtual std::wstring Describe(WebCore::CSSStyleDeclaration* style); - // Shows the form autofill popup for |node| if it is an HTMLInputElement and // it is empty. This is called when you press the up or down arrow in a // text-field or when clicking an already focused text-field. @@ -162,7 +154,7 @@ class EditorClientImpl : public WebCore::EditorClient { protected: WebViewImpl* web_view_; - bool use_editor_delegate_; + WebKit::WebEditingClient* editing_client_; bool in_redo_; typedef std::deque<WTF::RefPtr<WebCore::EditCommand> > EditCommandStack; diff --git a/webkit/glue/webview.h b/webkit/glue/webview.h index 2d75798..7346c1c 100644 --- a/webkit/glue/webview.h +++ b/webkit/glue/webview.h @@ -13,6 +13,7 @@ namespace WebKit { class WebDragData; +class WebEditingClient; class WebFrame; class WebSettings; struct WebPoint; @@ -49,12 +50,15 @@ class WebView : public WebKit::WebWidget { virtual ~WebView() {} // This method creates a WebView that is NOT yet initialized. You will need - // to call InitializeMainFrame to finish the initialization. - static WebView* Create(); + // to call InitializeMainFrame to finish the initialization. You may pass + // NULL for the editing_client parameter if you are not interested in those + // notifications. + static WebView* Create( + WebViewDelegate* delegate, WebKit::WebEditingClient* editing_client); // After creating a WebView, you should immediately call this function. // You can optionally modify the settings (via GetSettings()) in between. - virtual void InitializeMainFrame(WebViewDelegate* delegate) = 0; + virtual void InitializeMainFrame() = 0; // Tells all Page instances of this view to update the visited link state for // the specified hash. @@ -69,12 +73,6 @@ class WebView : public WebKit::WebWidget { // using it, it will be NULL during closing of the view. virtual WebViewDelegate* GetDelegate() = 0; - // Instructs the EditorClient whether to pass editing notifications on to a - // delegate, if one is present. This allows embedders that haven't - // overridden any editor delegate methods to avoid the performance impact of - // calling them. - virtual void SetUseEditorDelegate(bool value) = 0; - // Method that controls whether pressing Tab key cycles through page elements // or inserts a '\t' char in text area virtual void SetTabKeyCyclesThroughElements(bool value) = 0; diff --git a/webkit/glue/webview_delegate.h b/webkit/glue/webview_delegate.h index 11a55f8..804049d 100644 --- a/webkit/glue/webview_delegate.h +++ b/webkit/glue/webview_delegate.h @@ -655,76 +655,8 @@ class WebViewDelegate : virtual public WebKit::WebWidgetClient { virtual void JSOutOfMemory() { } - // EditorDelegate ---------------------------------------------------------- - - // These methods exist primarily to allow a specialized executable to record - // edit events for testing purposes. Most embedders are not expected to - // override them. In fact, by default these editor delegate methods aren't - // even called by the EditorClient, for performance reasons. To enable them, - // call WebView::SetUseEditorDelegate(true) for each WebView. - - virtual bool ShouldBeginEditing(WebView* webview, std::wstring range) { - return true; - } - - virtual bool ShouldEndEditing(WebView* webview, std::wstring range) { - return true; - } - - virtual bool ShouldInsertNode(WebView* webview, - std::wstring node, - std::wstring range, - std::wstring action) { - return true; - } - - virtual bool ShouldInsertText(WebView* webview, - std::wstring text, - std::wstring range, - std::wstring action) { - return true; - } - - virtual bool ShouldChangeSelectedRange(WebView* webview, - std::wstring fromRange, - std::wstring toRange, - std::wstring affinity, - bool stillSelecting) { - return true; - } - - virtual bool ShouldDeleteRange(WebView* webview, std::wstring range) { - return true; - } - - virtual bool ShouldApplyStyle(WebView* webview, - std::wstring style, - std::wstring range) { - return true; - } - - virtual bool SmartInsertDeleteEnabled() { - return true; - } - - virtual bool IsSelectTrailingWhitespaceEnabled() { -#if defined(OS_WIN) - return true; -#else - return false; -#endif - } - - virtual void DidBeginEditing() { } - virtual void DidChangeSelection(bool is_empty_selection) { } - virtual void DidChangeContents() { } - virtual void DidEndEditing() { } - // Notification that a user metric has occurred. virtual void UserMetricsRecordAction(const std::wstring& action) { } - virtual void UserMetricsRecordComputedAction(const std::wstring& action) { - UserMetricsRecordAction(action); - } // ------------------------------------------------------------------------- @@ -811,9 +743,6 @@ class WebViewDelegate : virtual public WebKit::WebWidgetClient { return std::wstring(); } - // Changes the state of the input method editor. - virtual void SetInputMethodState(bool enabled) { } - // Asks the user to print the page or a specific frame. Called in response to // a window.print() call. virtual void ScriptedPrint(WebKit::WebFrame* frame) { } diff --git a/webkit/glue/webview_impl.cc b/webkit/glue/webview_impl.cc index d5f9c06..b065563 100644 --- a/webkit/glue/webview_impl.cc +++ b/webkit/glue/webview_impl.cc @@ -101,6 +101,7 @@ using WebKit::WebCompositionCommand; using WebKit::WebCompositionCommandConfirm; using WebKit::WebCompositionCommandDiscard; using WebKit::WebDragData; +using WebKit::WebEditingClient; using WebKit::WebFrame; using WebKit::WebInputEvent; using WebKit::WebKeyboardEvent; @@ -323,24 +324,22 @@ static const WebCore::PopupContainerSettings kAutocompletePopupSettings = { // WebView ---------------------------------------------------------------- /*static*/ -WebView* WebView::Create() { - WebViewImpl* instance = new WebViewImpl(); +WebView* WebView::Create(WebViewDelegate* delegate, + WebEditingClient* editing_client) { + WebViewImpl* instance = new WebViewImpl(delegate, editing_client); instance->AddRef(); return instance; } -void WebViewImpl::InitializeMainFrame(WebViewDelegate* delegate) { +void WebViewImpl::InitializeMainFrame() { // NOTE: The WebFrameImpl takes a reference to itself within InitMainFrame // and releases that reference once the corresponding Frame is destroyed. scoped_refptr<WebFrameImpl> main_frame = new WebFrameImpl(); - // Set the delegate before initializing the frame, so that notifications like - // DidCreateDataSource make their way to the client. - delegate_ = delegate; main_frame->InitMainFrame(this); WebDevToolsAgentDelegate* tools_delegate = - delegate->GetWebDevToolsAgentDelegate(); + delegate_->GetWebDevToolsAgentDelegate(); if (tools_delegate) devtools_agent_.reset(new WebDevToolsAgentImpl(this, tools_delegate)); @@ -363,8 +362,11 @@ void WebView::ResetVisitedLinkState() { } -WebViewImpl::WebViewImpl() - : ALLOW_THIS_IN_INITIALIZER_LIST(back_forward_list_client_impl_(this)), +WebViewImpl::WebViewImpl(WebViewDelegate* delegate, + WebEditingClient* editing_client) + : delegate_(delegate), + ALLOW_THIS_IN_INITIALIZER_LIST(editor_client_impl_(this, editing_client)), + ALLOW_THIS_IN_INITIALIZER_LIST(back_forward_list_client_impl_(this)), observed_new_navigation_(false), #ifndef NDEBUG new_navigation_loader_(NULL), @@ -393,7 +395,7 @@ WebViewImpl::WebViewImpl() // the page will take ownership of the various clients page_.reset(new Page(new ChromeClientImpl(this), new ContextMenuClientImpl(this), - new EditorClientImpl(this), + &editor_client_impl_, new DragClientImpl(this), new WebInspectorClient(this))); @@ -413,14 +415,6 @@ RenderTheme* WebViewImpl::theme() const { return page_.get() ? page_->theme() : RenderTheme::defaultTheme().get(); } -void WebViewImpl::SetUseEditorDelegate(bool value) { - ASSERT(page_ != 0); // The macro doesn't like (!page_) with a scoped_ptr. - ASSERT(page_->editorClient()); - EditorClientImpl* editor_client = - static_cast<EditorClientImpl*>(page_->editorClient()); - editor_client->SetUseEditorDelegate(value); -} - void WebViewImpl::SetTabKeyCyclesThroughElements(bool value) { if (page_ != NULL) { page_->setTabKeyCyclesThroughElements(value); @@ -957,6 +951,7 @@ void WebViewImpl::close() { // Reset the delegate to prevent notifications being sent as we're being // deleted. delegate_ = NULL; + editor_client_impl_.DropEditingClient(); Release(); // Balances AddRef from WebView::Create } diff --git a/webkit/glue/webview_impl.h b/webkit/glue/webview_impl.h index f16206e..132f7b2 100644 --- a/webkit/glue/webview_impl.h +++ b/webkit/glue/webview_impl.h @@ -16,6 +16,7 @@ #include "webkit/api/public/WebSize.h" #include "webkit/api/src/NotificationPresenterImpl.h" #include "webkit/glue/back_forward_list_client_impl.h" +#include "webkit/glue/editor_client_impl.h" #include "webkit/glue/webframe_impl.h" #include "webkit/glue/webpreferences.h" #include "webkit/glue/webview.h" @@ -35,6 +36,7 @@ class Widget; } namespace WebKit { +class WebEditingClient; class WebKeyboardEvent; class WebMouseEvent; class WebMouseWheelEvent; @@ -74,11 +76,10 @@ class WebViewImpl : public WebView, public base::RefCounted<WebViewImpl> { virtual void setTextDirection(WebKit::WebTextDirection direction); // WebView methods: - virtual void InitializeMainFrame(WebViewDelegate* delegate); + virtual void InitializeMainFrame(); virtual bool ShouldClose(); virtual void ClosePage(); virtual WebViewDelegate* GetDelegate(); - virtual void SetUseEditorDelegate(bool value); virtual void SetTabKeyCyclesThroughElements(bool value); virtual WebKit::WebFrame* GetMainFrame(); virtual WebKit::WebFrame* GetFocusedFrame(); @@ -244,7 +245,8 @@ class WebViewImpl : public WebView, public base::RefCounted<WebViewImpl> { void OnImageFetchComplete(webkit_glue::ImageResourceFetcher* fetcher, const SkBitmap& bitmap); - WebViewImpl(); + WebViewImpl( + WebViewDelegate* delegate, WebKit::WebEditingClient* editing_client); ~WebViewImpl(); void ModifySelection(uint32 message, @@ -252,6 +254,7 @@ class WebViewImpl : public WebView, public base::RefCounted<WebViewImpl> { const WebCore::PlatformKeyboardEvent& e); WebViewDelegate* delegate_; + EditorClientImpl editor_client_impl_; WebKit::WebSize size_; WebKit::WebPoint last_mouse_position_; diff --git a/webkit/glue/webworker_impl.cc b/webkit/glue/webworker_impl.cc index 9ad4d49..60fe5d0 100644 --- a/webkit/glue/webworker_impl.cc +++ b/webkit/glue/webworker_impl.cc @@ -149,9 +149,9 @@ void WebWorkerImpl::startWorkerContext(const WebURL& script_url, // loading requests from the worker context to the rest of WebKit and Chromium // infrastructure. DCHECK(!web_view_); - web_view_ = WebView::Create(); + web_view_ = WebView::Create(WorkerWebViewDelegate::worker_delegate(), NULL); WebPreferences().Apply(web_view_); - web_view_->InitializeMainFrame(WorkerWebViewDelegate::worker_delegate()); + web_view_->InitializeMainFrame(); WebFrameImpl* web_frame = static_cast<WebFrameImpl*>(web_view_->GetMainFrame()); |