diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-26 05:20:22 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-26 05:20:22 +0000 |
commit | cf4e2a6035cc02b7b0957264afdbb57981926b75 (patch) | |
tree | d1833185ca97b8ab6bcb50b9521062a3d6255bb1 /webkit/glue | |
parent | 6017951dcd626f9b910aeb9881985e50fce589e7 (diff) | |
download | chromium_src-cf4e2a6035cc02b7b0957264afdbb57981926b75.zip chromium_src-cf4e2a6035cc02b7b0957264afdbb57981926b75.tar.gz chromium_src-cf4e2a6035cc02b7b0957264afdbb57981926b75.tar.bz2 |
Replace MessageLoop+ScopedRunnableMethodFactory with WebCore::Timer+Vector
This solution is clearly not as elegant, but it gets the job done, and it
eliminates the last remaining base/ reference from webframe_impl.cc!
R=dglazkov
BUG=24608
TEST=none
Review URL: http://codereview.chromium.org/335019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30035 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue')
-rw-r--r-- | webkit/glue/chrome_client_impl.cc | 4 | ||||
-rw-r--r-- | webkit/glue/webframe_impl.cc | 86 | ||||
-rw-r--r-- | webkit/glue/webframe_impl.h | 22 | ||||
-rw-r--r-- | webkit/glue/webview_impl.cc | 17 |
4 files changed, 94 insertions, 35 deletions
diff --git a/webkit/glue/chrome_client_impl.cc b/webkit/glue/chrome_client_impl.cc index 4498324..135cda2 100644 --- a/webkit/glue/chrome_client_impl.cc +++ b/webkit/glue/chrome_client_impl.cc @@ -451,7 +451,7 @@ void ChromeClientImpl::scroll( WebCore::IntPoint ChromeClientImpl::screenToWindow( const WebCore::IntPoint&) const { - NOTIMPLEMENTED(); + notImplemented(); return WebCore::IntPoint(); } @@ -616,7 +616,7 @@ void ChromeClientImpl::GetPopupMenuInfo(PopupContainer* popup_container, output_item.type = WebPopupMenuInfo::Item::Separator; break; default: - NOTREACHED(); + ASSERT_NOT_REACHED(); } } diff --git a/webkit/glue/webframe_impl.cc b/webkit/glue/webframe_impl.cc index b64af0f..29a2339 100644 --- a/webkit/glue/webframe_impl.cc +++ b/webkit/glue/webframe_impl.cc @@ -128,7 +128,6 @@ #include <wtf/CurrentTime.h> #undef LOG -#include "base/message_loop.h" #include "webkit/api/public/WebConsoleMessage.h" #include "webkit/api/public/WebFindOptions.h" #include "webkit/api/public/WebForm.h" @@ -189,6 +188,7 @@ using WebCore::SharedBuffer; using WebCore::String; using WebCore::SubstituteData; using WebCore::TextIterator; +using WebCore::Timer; using WebCore::VisiblePosition; using WebCore::XPathResult; @@ -348,6 +348,40 @@ static WebDataSource* DataSourceForDocLoader(DocumentLoader* loader) { return loader ? WebDataSourceImpl::fromDocumentLoader(loader) : NULL; } + +// WebFrame ------------------------------------------------------------------- + +class WebFrameImpl::DeferredScopeStringMatches { + public: + DeferredScopeStringMatches(WebFrameImpl* webframe, + int identifier, + const WebString& search_text, + const WebFindOptions& options, + bool reset) + : timer_(this, &DeferredScopeStringMatches::DoTimeout), + webframe_(webframe), + identifier_(identifier), + search_text_(search_text), + options_(options), + reset_(reset) { + timer_.startOneShot(0.0); + } + + private: + void DoTimeout(Timer<DeferredScopeStringMatches>*) { + webframe_->CallScopeStringMatches( + this, identifier_, search_text_, options_, reset_); + } + + Timer<DeferredScopeStringMatches> timer_; + RefPtr<WebFrameImpl> webframe_; + int identifier_; + WebString search_text_; + WebFindOptions options_; + bool reset_; +}; + + // WebFrame ------------------------------------------------------------------- // static @@ -1227,14 +1261,11 @@ void WebFrameImpl::scopeStringMatches(int request_id, main_frame_impl->frames_scoping_count_++; // Now, defer scoping until later to allow find operation to finish quickly. - // TODO(darin): Replace with a WebCore Timer. - MessageLoop::current()->PostTask(FROM_HERE, - scope_matches_factory_.NewRunnableMethod( - &WebFrameImpl::scopeStringMatches, - request_id, - search_text, - options, - false)); // false=we just reset, so don't do it again. + ScopeStringMatchesSoon( + request_id, + search_text, + options, + false); // false=we just reset, so don't do it again. return; } @@ -1366,15 +1397,11 @@ void WebFrameImpl::scopeStringMatches(int request_id, InvalidateIfNecessary(); // Scoping effort ran out of time, lets ask for another time-slice. - // TODO(darin): Replace with a WebCore Timer. - MessageLoop::current()->PostTask(FROM_HERE, - scope_matches_factory_.NewRunnableMethod( - &WebFrameImpl::scopeStringMatches, - request_id, - search_text, - options, - false)); // don't reset. - + ScopeStringMatchesSoon( + request_id, + search_text, + options, + false); // don't reset. return; // Done for now, resume work later. } @@ -1393,7 +1420,9 @@ void WebFrameImpl::scopeStringMatches(int request_id, } void WebFrameImpl::cancelPendingScopingEffort() { - scope_matches_factory_.RevokeAll(); + deleteAllValues(deferred_scoping_work_); + deferred_scoping_work_.clear(); + active_match_index_ = -1; } @@ -1457,7 +1486,6 @@ PassRefPtr<WebFrameImpl> WebFrameImpl::create(WebFrameClient* client) { WebFrameImpl::WebFrameImpl(PassRefPtr<ClientHandle> client_handle) : ALLOW_THIS_IN_INITIALIZER_LIST(frame_loader_client_(this)), - ALLOW_THIS_IN_INITIALIZER_LIST(scope_matches_factory_(this)), client_handle_(client_handle), active_match_frame_(NULL), active_match_index_(-1), @@ -1823,6 +1851,24 @@ bool WebFrameImpl::ShouldScopeMatches(const string16& search_text) { return true; } +void WebFrameImpl::ScopeStringMatchesSoon( + int identifier, const WebString& search_text, + const WebFindOptions& options, bool reset) { + deferred_scoping_work_.append(new DeferredScopeStringMatches( + this, identifier, search_text, options, reset)); +} + +void WebFrameImpl::CallScopeStringMatches( + DeferredScopeStringMatches* caller, int identifier, + const WebString& search_text, const WebFindOptions& options, bool reset) { + deferred_scoping_work_.remove(deferred_scoping_work_.find(caller)); + + scopeStringMatches(identifier, search_text, options, reset); + + // This needs to happen last since search_text is passed by reference. + delete caller; +} + void WebFrameImpl::InvalidateIfNecessary() { if (last_match_count_ > next_invalidate_after_) { // TODO(finnur): (http://b/1088165) Optimize the drawing of the diff --git a/webkit/glue/webframe_impl.h b/webkit/glue/webframe_impl.h index 9d0b86d..f15b3a1 100644 --- a/webkit/glue/webframe_impl.h +++ b/webkit/glue/webframe_impl.h @@ -31,7 +31,6 @@ #include <wtf/OwnPtr.h> #include <wtf/RefCounted.h> -#include "base/task.h" #include "webkit/api/public/WebFrame.h" #include "webkit/glue/webframeloaderclient_impl.h" @@ -268,10 +267,6 @@ class WebFrameImpl : public WebKit::WebFrame, public RefCounted<WebFrameImpl> { WebFrameLoaderClient frame_loader_client_; - // This is a factory for creating cancelable tasks for this frame that run - // asynchronously in order to scope string matches during a find operation. - ScopedRunnableMethodFactory<WebFrameImpl> scope_matches_factory_; - RefPtr<ClientHandle> client_handle_; // This is a weak pointer to our corresponding WebCore frame. A reference to @@ -328,6 +323,9 @@ class WebFrameImpl : public WebKit::WebFrame, public RefCounted<WebFrameImpl> { int next_invalidate_after_; private: + class DeferredScopeStringMatches; + friend class DeferredScopeStringMatches; + // A bit mask specifying area of the frame to invalidate. enum AreaToInvalidate { INVALIDATE_NOTHING = 0, @@ -362,6 +360,17 @@ class WebFrameImpl : public WebKit::WebFrame, public RefCounted<WebFrameImpl> { // was searched. bool ShouldScopeMatches(const string16& search_text); + // Queue up a deferred call to scopeStringMatches. + void ScopeStringMatchesSoon( + int identifier, const WebKit::WebString& search_text, + const WebKit::WebFindOptions& options, bool reset); + + // Called by a DeferredScopeStringMatches instance. + void CallScopeStringMatches( + DeferredScopeStringMatches* deferred, + int identifier, const WebKit::WebString& search_text, + const WebKit::WebFindOptions& options, bool reset); + // Determines whether to invalidate the content area and scrollbar. void InvalidateIfNecessary(); @@ -370,6 +379,9 @@ class WebFrameImpl : public WebKit::WebFrame, public RefCounted<WebFrameImpl> { void LoadJavaScriptURL(const WebCore::KURL& url); + // A list of all of the pending calls to scopeStringMatches. + Vector<DeferredScopeStringMatches*> deferred_scoping_work_; + // Valid between calls to BeginPrint() and EndPrint(). Containts the print // information. Is used by PrintPage(). OwnPtr<ChromePrintContext> print_context_; diff --git a/webkit/glue/webview_impl.cc b/webkit/glue/webview_impl.cc index c479af1..7992909 100644 --- a/webkit/glue/webview_impl.cc +++ b/webkit/glue/webview_impl.cc @@ -199,7 +199,7 @@ class AutocompletePopupMenuClient : public WebCore::PopupMenuClient { } virtual WebCore::String itemToolTip(unsigned last_index) const { - NOTIMPLEMENTED(); + notImplemented(); return WebCore::String(); } @@ -301,9 +301,10 @@ class AutocompletePopupMenuClient : public WebCore::PopupMenuClient { WebCore::RenderStyle* style = text_field_->computedStyle(); if (!style) { // It seems we can only have an NULL style in a TextField if the node is - // dettached, in which case we the popup shoud not be showing. - NOTREACHED() << "Please report this in http://crbug.com/7708 and include " - "the page you were visiting."; + // dettached, in which case we the popup shoud not be showing. Please + // report this in http://crbug.com/7708 and include the page you were + // visiting. + ASSERT_NOT_REACHED(); } return style; } @@ -664,12 +665,12 @@ bool WebViewImpl::AutocompleteHandleKeyEvent(const WebKeyboardEvent& event) { autocomplete_popup_->selectedIndex() != -1) { Node* node = GetFocusedNode(); if (!node || (node->nodeType() != WebCore::Node::ELEMENT_NODE)) { - NOTREACHED(); + ASSERT_NOT_REACHED(); return false; } WebCore::Element* element = static_cast<WebCore::Element*>(node); if (!element->hasLocalName(WebCore::HTMLNames::inputTag)) { - NOTREACHED(); + ASSERT_NOT_REACHED(); return false; } @@ -1261,7 +1262,7 @@ void WebViewImpl::setTextDirection(WebTextDirection direction) { break; default: - NOTIMPLEMENTED(); + notImplemented(); break; } } @@ -1702,7 +1703,7 @@ void WebViewImpl::applyAutofillSuggestions( } if (!focused_node->hasTagName(WebCore::HTMLNames::inputTag)) { - NOTREACHED(); + ASSERT_NOT_REACHED(); return; } |