diff options
author | robertshield@chromium.org <robertshield@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-15 13:50:00 +0000 |
---|---|---|
committer | robertshield@chromium.org <robertshield@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-15 13:50:00 +0000 |
commit | 6bcf6c6b8cbd99abed045ed73d3533e2f30ea095 (patch) | |
tree | a770d786714d86d43b9dec62466cc756c1bab085 /chrome_frame | |
parent | 992b4e66e7728147f59893a74bf77c9326a5daac (diff) | |
download | chromium_src-6bcf6c6b8cbd99abed045ed73d3533e2f30ea095.zip chromium_src-6bcf6c6b8cbd99abed045ed73d3533e2f30ea095.tar.gz chromium_src-6bcf6c6b8cbd99abed045ed73d3533e2f30ea095.tar.bz2 |
Correctly handle FindNext from the Find dialog.
Also handle unselecting the current selection when the Find dialog is dismissed.
BUG=112193
TEST=Open the find dialog in CF, search for the same string twice.
Review URL: http://codereview.chromium.org/9700053
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126904 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_frame')
-rw-r--r-- | chrome_frame/chrome_frame_automation.cc | 4 | ||||
-rw-r--r-- | chrome_frame/find_dialog.cc | 25 | ||||
-rw-r--r-- | chrome_frame/find_dialog.h | 7 |
3 files changed, 28 insertions, 8 deletions
diff --git a/chrome_frame/chrome_frame_automation.cc b/chrome_frame/chrome_frame_automation.cc index 147cdee..b4d3023 100644 --- a/chrome_frame/chrome_frame_automation.cc +++ b/chrome_frame/chrome_frame_automation.cc @@ -783,7 +783,9 @@ void ChromeFrameAutomationClient::FindInPage(const std::wstring& search_string, FindInPageDirection forward, FindInPageCase match_case, bool find_next) { - DCHECK(tab_.get()); + // Note that we can be called by the find dialog after the tab has gone away. + if (!tab_) + return; // What follows is quite similar to TabProxy::FindInPage() but uses // the SyncMessageReplyDispatcher to avoid concerns about blocking diff --git a/chrome_frame/find_dialog.cc b/chrome_frame/find_dialog.cc index eddfc81..2c10866 100644 --- a/chrome_frame/find_dialog.cc +++ b/chrome_frame/find_dialog.cc @@ -1,11 +1,13 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "chrome_frame/find_dialog.h" -#include <Richedit.h> +#include <richedit.h> +#include "base/utf_string_conversions.h" +#include "chrome/common/guid.h" #include "chrome_frame/chrome_frame_automation.h" const int kMaxFindChars = 1024; @@ -20,15 +22,26 @@ void CFFindDialog::Init(ChromeFrameAutomationClient* automation_client) { LRESULT CFFindDialog::OnDestroy(UINT msg, WPARAM wparam, LPARAM lparam, BOOL& handled) { + // In order to cancel the selection when the Find dialog is dismissed, we + // do a fake search for a string that is unlikely to appear on the page. + // TODO(robertshield): Change this to plumb through a StopFinding automation + // message that triggers a ViewMsg_StopFinding. + std::string guid(guid::GenerateGUID()); + automation_client_->FindInPage(ASCIIToWide(guid), FWD, CASE_SENSITIVE, false); + UninstallMessageHook(); return 0; } LRESULT CFFindDialog::OnFind(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) { - wchar_t buffer[kMaxFindChars + 1]; - GetDlgItemText(IDC_FIND_TEXT, buffer, kMaxFindChars); - std::wstring find_text(buffer); + string16 find_text(kMaxFindChars, L'\0'); + find_text.resize(GetDlgItemText(IDC_FIND_TEXT, &find_text[0], kMaxFindChars)); + + // Repeated searches for the same string should move to the next instance. + bool find_next = (find_text == last_find_text_); + if (!find_next) + last_find_text_ = find_text; bool match_case = IsDlgButtonChecked(IDC_MATCH_CASE) == BST_CHECKED; bool search_down = IsDlgButtonChecked(IDC_DIRECTION_DOWN) == BST_CHECKED; @@ -36,7 +49,7 @@ LRESULT CFFindDialog::OnFind(WORD wNotifyCode, WORD wID, HWND hWndCtl, automation_client_->FindInPage(find_text, search_down ? FWD : BACK, match_case ? CASE_SENSITIVE : IGNORE_CASE, - false); + find_next); return 0; } diff --git a/chrome_frame/find_dialog.h b/chrome_frame/find_dialog.h index 07e2d39..f7ccaba 100644 --- a/chrome_frame/find_dialog.h +++ b/chrome_frame/find_dialog.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -9,6 +9,7 @@ #include <atlwin.h> #include "base/memory/ref_counted.h" +#include "base/string16.h" #include "resource.h" #include "grit/chrome_frame_dialogs.h" @@ -47,6 +48,10 @@ class CFFindDialog : public CDialogImpl<CFFindDialog> { static LRESULT CALLBACK GetMsgProc(int code, WPARAM wparam, LPARAM lparam); static HHOOK msg_hook_; + // Store the text we searched for last to determine whether we are doing a + // "Find" or a "Find Next". + string16 last_find_text_; + // We don't own these, and they must exist at least as long as we do. scoped_refptr<ChromeFrameAutomationClient> automation_client_; }; |