summaryrefslogtreecommitdiffstats
path: root/chrome/browser/tab_contents
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/tab_contents')
-rw-r--r--chrome/browser/tab_contents/web_contents.cc82
-rw-r--r--chrome/browser/tab_contents/web_contents.h66
-rw-r--r--chrome/browser/tab_contents/web_contents_view.h41
-rw-r--r--chrome/browser/tab_contents/web_contents_view_win.cc74
-rw-r--r--chrome/browser/tab_contents/web_contents_view_win.h16
5 files changed, 138 insertions, 141 deletions
diff --git a/chrome/browser/tab_contents/web_contents.cc b/chrome/browser/tab_contents/web_contents.cc
index 54b8d6e..ecf33c9 100644
--- a/chrome/browser/tab_contents/web_contents.cc
+++ b/chrome/browser/tab_contents/web_contents.cc
@@ -182,6 +182,9 @@ class WebContents::GearsCreateShortcutCallbackFunctor {
WebContents* contents_;
};
+// static
+int WebContents::find_request_id_counter_ = -1;
+
WebContents::WebContents(Profile* profile,
SiteInstance* site_instance,
RenderViewHostFactory* render_view_factory,
@@ -201,8 +204,10 @@ WebContents::WebContents(Profile* profile,
#endif
ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)),
suppress_javascript_messages_(false),
- load_state_(net::LOAD_STATE_IDLE) {
-
+ load_state_(net::LOAD_STATE_IDLE),
+ find_ui_active_(false),
+ find_op_aborted_(false),
+ current_find_request_id_(find_request_id_counter_++) {
pending_install_.page_id = 0;
pending_install_.callback_functor = NULL;
@@ -532,6 +537,43 @@ void WebContents::CreateShortcut() {
render_view_host()->GetApplicationInfo(pending_install_.page_id);
}
+void WebContents::StartFinding(const std::wstring& find_text,
+ bool forward_direction) {
+ // If find_text is empty, it means FindNext was pressed with a keyboard
+ // shortcut so unless we have something to search for we return early.
+ if (find_text.empty() && find_text_.empty())
+ return;
+
+ // This is a FindNext operation if we are searching for the same text again,
+ // or if the passed in search text is empty (FindNext keyboard shortcut). The
+ // exception to this is if the Find was aborted (then we don't want FindNext
+ // because the highlighting has been cleared and we need it to reappear). We
+ // therefore treat FindNext after an aborted Find operation as a full fledged
+ // Find.
+ bool find_next = (find_text_ == find_text || find_text.empty()) &&
+ !find_op_aborted_;
+ if (!find_next)
+ current_find_request_id_ = find_request_id_counter_++;
+
+ if (!find_text.empty())
+ find_text_ = find_text;
+
+ find_op_aborted_ = false;
+
+ render_view_host()->StartFinding(current_find_request_id_,
+ find_text_,
+ forward_direction,
+ false, // case sensitive
+ find_next);
+}
+
+void WebContents::StopFinding(bool clear_selection) {
+ find_ui_active_ = false;
+ find_op_aborted_ = true;
+ find_result_ = FindNotificationDetails();
+ render_view_host()->StopFinding(clear_selection);
+}
+
void WebContents::OnJavaScriptMessageBoxClosed(IPC::Message* reply_msg,
bool success,
const std::wstring& prompt) {
@@ -591,9 +633,6 @@ bool WebContents::PrintNow() {
if (showing_interstitial_page())
return false;
- // If we have a find bar it needs to hide as well.
- view_->HideFindBar(false);
-
return render_view_host()->PrintPages();
}
@@ -1356,6 +1395,33 @@ void WebContents::OnEnterOrSpace() {
#endif
}
+void WebContents::OnFindReply(int request_id,
+ int number_of_matches,
+ const gfx::Rect& selection_rect,
+ int active_match_ordinal,
+ bool final_update) {
+ // Ignore responses for requests other than the one we have most recently
+ // issued. That way we won't act on stale results when the user has
+ // already typed in another query.
+ if (request_id != current_find_request_id_)
+ return;
+
+ if (number_of_matches == -1)
+ number_of_matches = find_result_.number_of_matches();
+ if (active_match_ordinal == -1)
+ active_match_ordinal = find_result_.active_match_ordinal();
+
+ // Notify the UI, automation and any other observers that a find result was
+ // found.
+ find_result_ = FindNotificationDetails(request_id, number_of_matches,
+ selection_rect, active_match_ordinal,
+ final_update);
+ NotificationService::current()->Notify(
+ NotificationType::FIND_RESULT_AVAILABLE,
+ Source<TabContents>(this),
+ Details<FindNotificationDetails>(&find_result_));
+}
+
bool WebContents::CanTerminate() const {
if (!delegate())
return true;
@@ -1498,12 +1564,6 @@ void WebContents::DidNavigateMainFramePostCommit(
// Close constrained popups if necessary.
MaybeCloseChildWindows(details.previous_url, details.entry->url());
- // We hide the FindInPage window when the user navigates away, except on
- // reload.
- if (PageTransition::StripQualifier(params.transition) !=
- PageTransition::RELOAD)
- view_->HideFindBar(true);
-
// Update the starred state.
UpdateStarredStateForCurrentURL();
}
diff --git a/chrome/browser/tab_contents/web_contents.h b/chrome/browser/tab_contents/web_contents.h
index 52b48fe..08ac907 100644
--- a/chrome/browser/tab_contents/web_contents.h
+++ b/chrome/browser/tab_contents/web_contents.h
@@ -14,6 +14,7 @@
#include "chrome/browser/cancelable_request.h"
#include "chrome/browser/download/save_package.h"
#include "chrome/browser/fav_icon_helper.h"
+#include "chrome/browser/find_notification_details.h"
#include "chrome/browser/renderer_host/render_view_host_delegate.h"
#include "chrome/browser/tab_contents/navigation_controller.h"
#include "chrome/browser/tab_contents/render_view_host_manager.h"
@@ -171,6 +172,40 @@ class WebContents : public TabContents,
return render_manager_.interstitial_page();
}
+ // Find in Page --------------------------------------------------------------
+
+ // Starts the Find operation by calling StartFinding on the Tab. This function
+ // can be called from the outside as a result of hot-keys, so it uses the
+ // last remembered search string as specified with set_find_string(). This
+ // function does not block while a search is in progress. The controller will
+ // receive the results through the notification mechanism. See Observe(...)
+ // for details.
+ void StartFinding(const std::wstring& find_text, bool forward_direction);
+
+ // Stops the current Find operation. If |clear_selection| is true, it will
+ // also clear the selection on the focused frame.
+ void StopFinding(bool clear_selection);
+
+ // Accessors/Setters for find_ui_active_.
+ bool find_ui_active() const { return find_ui_active_; }
+ void set_find_ui_active(bool find_ui_active) {
+ find_ui_active_ = find_ui_active;
+ }
+
+ // Used _only_ by testing to set the current request ID, since it calls
+ // StartFinding on the RenderViewHost directly, rather than by using
+ // StartFinding's more limited API.
+ void set_current_find_request_id(int current_find_request_id) {
+ current_find_request_id_ = current_find_request_id;
+ }
+
+ // Accessor for find_text_. Used to determine if this WebContents has any
+ // active searches.
+ std::wstring find_text() const { return find_text_; }
+
+ // Accessor for find_result_.
+ const FindNotificationDetails& find_result() const { return find_result_; }
+
// Misc state & callbacks ----------------------------------------------------
// Set whether the contents should block javascript message boxes or not.
@@ -346,6 +381,11 @@ class WebContents : public TabContents,
int32 page_id,
const webkit_glue::WebApplicationInfo& info);
virtual void OnEnterOrSpace();
+ virtual void OnFindReply(int request_id,
+ int number_of_matches,
+ const gfx::Rect& selection_rect,
+ int active_match_ordinal,
+ bool final_update);
virtual bool CanTerminate() const;
@@ -589,6 +629,32 @@ class WebContents : public TabContents,
net::LoadState load_state_;
std::wstring load_state_host_;
+ // True if the Find UI is active for this Tab.
+ bool find_ui_active_;
+
+ // True if a Find operation was aborted. This can happen if the Find box is
+ // closed or if the search term inside the Find box is erased while a search
+ // is in progress.
+ bool find_op_aborted_;
+
+ // Each time a search request comes in we assign it an id before passing it
+ // over the IPC so that when the results come in we can evaluate whether we
+ // still care about the results of the search (in some cases we don't because
+ // the user has issued a new search).
+ static int find_request_id_counter_;
+
+ // This variable keeps track of what the most recent request id is.
+ int current_find_request_id_;
+
+ // The last string we searched for. This is used to figure out if this is a
+ // Find or a FindNext operation (FindNext should not increase the request id).
+ std::wstring find_text_;
+
+ // The last find result. This object contains details about the number of
+ // matches, the find selection rectangle, etc. The UI can access this
+ // information to build its presentation.
+ FindNotificationDetails find_result_;
+
DISALLOW_COPY_AND_ASSIGN(WebContents);
};
diff --git a/chrome/browser/tab_contents/web_contents_view.h b/chrome/browser/tab_contents/web_contents_view.h
index 4bf8dca..1a8b4f6 100644
--- a/chrome/browser/tab_contents/web_contents_view.h
+++ b/chrome/browser/tab_contents/web_contents_view.h
@@ -108,47 +108,6 @@ class WebContentsView : public RenderViewHostDelegate::View {
// RenderWidgetHost is deleted. Removes |host| from internal maps.
void RenderWidgetHostDestroyed(RenderWidgetHost* host);
- // Find in page --------------------------------------------------------------
-
- // Opens the find in page window if it isn't already open. It will advance to
- // the next match if |find_next| is set and there is a search string,
- // otherwise, the find window will merely be opened. |forward_direction|
- // indicates the direction to search when find_next is set, otherwise it is
- // ignored.
- virtual void FindInPage(const Browser& browser,
- bool find_next, bool forward_direction) = 0;
-
- // Hides the find bar if there is one shown. Does nothing otherwise. The find
- // bar will not be deleted, merely hidden. This ensures that any search terms
- // are preserved if the user subsequently opens the find bar.
- //
- // If |end_session| is true, then the find session will be ended, which
- // indicates the user requested they no longer be in find mode for that tab.
- // The find bar will not be restored when we switch back to the tab.
- // Otherwise, we assume that the find bar is being hidden because the tab is
- // being hidden, and all state like visibility and tickmarks will be restored
- // when the tab comes back.
- virtual void HideFindBar(bool end_session) = 0;
-
-#if defined(OS_WIN)
- // Called when the tab is reparented to a new browser window. On MS Windows,
- // we have to change the parent of our find bar to go with the new window.
- //
- // TODO(brettw) this seems like it could be improved. Possibly all doohickies
- // around the tab like this, the download bar etc. should be managed by the
- // BrowserView2 object.
- virtual void ReparentFindWindow(Browser* new_browser) const = 0;
-#endif
-
- // Computes the location of the find bar and whether it is fully visible in
- // its parent window. The return value indicates if the window is visible at
- // all. Both out arguments are required.
- //
- // This is used for UI tests of the find bar. If the find bar is not currently
- // shown (return value of false), the out params will be {(0, 0), false}.
- virtual bool GetFindBarWindowInfo(gfx::Point* position,
- bool* fully_visible) const = 0;
-
protected:
WebContentsView() {} // Abstract interface.
diff --git a/chrome/browser/tab_contents/web_contents_view_win.cc b/chrome/browser/tab_contents/web_contents_view_win.cc
index 9728ec8..52989e4 100644
--- a/chrome/browser/tab_contents/web_contents_view_win.cc
+++ b/chrome/browser/tab_contents/web_contents_view_win.cc
@@ -7,7 +7,7 @@
#include <windows.h>
#include "chrome/browser/bookmarks/bookmark_drag_data.h"
-#include "chrome/browser/browser.h" // TODO(beng): this dependency is awful.
+#include "chrome/browser/browser.h" // TODO(beng): this dependency is awful.
#include "chrome/browser/browser_process.h"
#include "chrome/browser/download/download_request_manager.h"
#include "chrome/browser/renderer_host/render_process_host.h"
@@ -20,7 +20,6 @@
#include "chrome/browser/tab_contents/web_contents.h"
#include "chrome/browser/tab_contents/web_drag_source.h"
#include "chrome/browser/tab_contents/web_drop_target.h"
-#include "chrome/browser/views/find_bar_win.h"
#include "chrome/browser/views/sad_tab_view.h"
#include "chrome/common/gfx/chrome_canvas.h"
#include "chrome/common/os_exchange_data.h"
@@ -180,10 +179,6 @@ void WebContentsViewWin::OnContentsDestroy() {
// automatically. The detached plugin windows will get cleaned up in proper
// sequence as part of the usual cleanup when the plugin instance goes away.
EnumChildWindows(GetHWND(), DetachPluginWindowsCallback, NULL);
-
- // Close the find bar if any.
- if (find_bar_.get())
- find_bar_->Close();
}
void WebContentsViewWin::OnDestroy() {
@@ -216,52 +211,6 @@ void WebContentsViewWin::SizeContents(const gfx::Size& size) {
WasSized(size);
}
-void WebContentsViewWin::FindInPage(const Browser& browser,
- bool find_next, bool forward_direction) {
- if (!find_bar_.get()) {
- // We want the Chrome top-level (Frame) window.
- HWND hwnd = reinterpret_cast<HWND>(browser.window()->GetNativeHandle());
- find_bar_.reset(new FindBarWin(this, hwnd));
- } else {
- find_bar_->Show();
- }
-
- if (find_next && !find_bar_->find_string().empty())
- find_bar_->StartFinding(forward_direction);
-}
-
-void WebContentsViewWin::HideFindBar(bool end_session) {
- if (find_bar_.get()) {
- if (end_session)
- find_bar_->EndFindSession();
- else
- find_bar_->DidBecomeUnselected();
- }
-}
-
-void WebContentsViewWin::ReparentFindWindow(Browser* new_browser) const {
- if (find_bar_.get()) {
- find_bar_->SetParent(
- reinterpret_cast<HWND>(new_browser->window()->GetNativeHandle()));
- }
-}
-
-bool WebContentsViewWin::GetFindBarWindowInfo(gfx::Point* position,
- bool* fully_visible) const {
- CRect window_rect;
- if (!find_bar_.get() ||
- !::IsWindow(find_bar_->GetHWND()) ||
- !::GetWindowRect(find_bar_->GetHWND(), &window_rect)) {
- *position = gfx::Point(0, 0);
- *fully_visible = false;
- return false;
- }
-
- *position = gfx::Point(window_rect.TopLeft().x, window_rect.TopLeft().y);
- *fully_visible = find_bar_->IsVisible() && !find_bar_->IsAnimating();
- return true;
-}
-
void WebContentsViewWin::UpdateDragCursor(bool is_drop_target) {
drop_target_->set_is_drop_target(is_drop_target);
}
@@ -326,17 +275,6 @@ void WebContentsViewWin::HandleKeyboardEvent(const WebKeyboardEvent& event) {
event.actual_message.lParam);
}
-void WebContentsViewWin::OnFindReply(int request_id,
- int number_of_matches,
- const gfx::Rect& selection_rect,
- int active_match_ordinal,
- bool final_update) {
- if (find_bar_.get()) {
- find_bar_->OnFindReply(request_id, number_of_matches, selection_rect,
- active_match_ordinal, final_update);
- }
-}
-
void WebContentsViewWin::ShowContextMenu(const ContextMenuParams& params) {
RenderViewContextMenuController menu_controller(web_contents_, params);
RenderViewContextMenu menu(&menu_controller,
@@ -568,10 +506,6 @@ void WebContentsViewWin::OnWindowPosChanged(WINDOWPOS* window_pos) {
// size hasn't changed.
if (!(window_pos->flags & SWP_NOSIZE))
WasSized(gfx::Size(window_pos->cx, window_pos->cy));
-
- // If we have a FindInPage dialog, notify it that the window changed.
- if (find_bar_.get() && find_bar_->IsVisible())
- find_bar_->MoveWindowIfNecessary(gfx::Rect());
}
}
@@ -620,14 +554,10 @@ void WebContentsViewWin::ScrollCommon(UINT message, int scroll_type,
void WebContentsViewWin::WasHidden() {
web_contents_->HideContents();
- if (find_bar_.get())
- find_bar_->DidBecomeUnselected();
}
void WebContentsViewWin::WasShown() {
web_contents_->ShowContents();
- if (find_bar_.get())
- find_bar_->DidBecomeSelected();
}
void WebContentsViewWin::WasSized(const gfx::Size& size) {
@@ -635,8 +565,6 @@ void WebContentsViewWin::WasSized(const gfx::Size& size) {
web_contents_->interstitial_page()->SetSize(size);
if (web_contents_->render_widget_host_view())
web_contents_->render_widget_host_view()->SetSize(size);
- if (find_bar_.get())
- find_bar_->RespondToResize(size);
// TODO(brettw) this function can probably be moved to this class.
web_contents_->RepositionSupressedPopupsToFit(size);
diff --git a/chrome/browser/tab_contents/web_contents_view_win.h b/chrome/browser/tab_contents/web_contents_view_win.h
index a8649d7..6b891cf 100644
--- a/chrome/browser/tab_contents/web_contents_view_win.h
+++ b/chrome/browser/tab_contents/web_contents_view_win.h
@@ -10,7 +10,6 @@
#include "chrome/browser/tab_contents/web_contents_view.h"
#include "chrome/views/widget_win.h"
-class FindBarWin;
class SadTabView;
struct WebDropData;
class WebDropTarget;
@@ -40,12 +39,6 @@ class WebContentsViewWin : public WebContentsView,
virtual void SetPageTitle(const std::wstring& title);
virtual void Invalidate();
virtual void SizeContents(const gfx::Size& size);
- virtual void FindInPage(const Browser& browser,
- bool find_next, bool forward_direction);
- virtual void HideFindBar(bool end_session);
- virtual void ReparentFindWindow(Browser* new_browser) const;
- virtual bool GetFindBarWindowInfo(gfx::Point* position,
- bool* fully_visible) const;
// Backend implementation of RenderViewHostDelegate::View.
virtual WebContents* CreateNewWindowInternal(
@@ -63,11 +56,6 @@ class WebContentsViewWin : public WebContentsView,
virtual void UpdateDragCursor(bool is_drop_target);
virtual void TakeFocus(bool reverse);
virtual void HandleKeyboardEvent(const WebKeyboardEvent& event);
- virtual void OnFindReply(int request_id,
- int number_of_matches,
- const gfx::Rect& selection_rect,
- int active_match_ordinal,
- bool final_update);
private:
// Windows events ------------------------------------------------------------
@@ -108,10 +96,6 @@ class WebContentsViewWin : public WebContentsView,
WebContents* web_contents_;
- // For find in page. This may be NULL if there is no find bar, and if it is
- // non-NULL, it may or may not be visible.
- scoped_ptr<FindBarWin> find_bar_;
-
// A drop target object that handles drags over this WebContents.
scoped_refptr<WebDropTarget> drop_target_;