Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome_frame/find_dialog.h" | 5 #include "chrome_frame/find_dialog.h" |
| 6 | 6 |
| 7 #include <Richedit.h> | 7 #include <richedit.h> |
| 8 | 8 |
| 9 #include "base/utf_string_conversions.h" | |
| 10 #include "chrome/common/guid.h" | |
| 9 #include "chrome_frame/chrome_frame_automation.h" | 11 #include "chrome_frame/chrome_frame_automation.h" |
| 10 | 12 |
| 11 const int kMaxFindChars = 1024; | 13 const int kMaxFindChars = 1024; |
| 12 | 14 |
| 13 HHOOK CFFindDialog::msg_hook_ = NULL; | 15 HHOOK CFFindDialog::msg_hook_ = NULL; |
| 14 | 16 |
| 15 CFFindDialog::CFFindDialog() {} | 17 CFFindDialog::CFFindDialog() {} |
| 16 | 18 |
| 17 void CFFindDialog::Init(ChromeFrameAutomationClient* automation_client) { | 19 void CFFindDialog::Init(ChromeFrameAutomationClient* automation_client) { |
| 18 automation_client_ = automation_client; | 20 automation_client_ = automation_client; |
| 19 } | 21 } |
| 20 | 22 |
| 21 LRESULT CFFindDialog::OnDestroy(UINT msg, WPARAM wparam, LPARAM lparam, | 23 LRESULT CFFindDialog::OnDestroy(UINT msg, WPARAM wparam, LPARAM lparam, |
| 22 BOOL& handled) { | 24 BOOL& handled) { |
| 25 // In order to cancel the selection when the Find dialog is dismissed, we | |
| 26 // do a fake search for a string that is unlikely to appear on the page. | |
| 27 // TODO(robertshield): Change this to plumb through a StopFinding automation | |
| 28 // message that triggers a ViewMsg_StopFinding. | |
| 29 std::string guid = guid::GenerateGUID(); | |
|
grt (UTC plus 2)
2012/03/15 02:29:52
nit: std::string guid(guid::GenerateGUID());
robertshield
2012/03/15 02:54:22
Done.
| |
| 30 automation_client_->FindInPage(ASCIIToWide(guid), FWD, CASE_SENSITIVE, false); | |
| 31 | |
| 23 UninstallMessageHook(); | 32 UninstallMessageHook(); |
| 24 return 0; | 33 return 0; |
| 25 } | 34 } |
| 26 | 35 |
| 27 LRESULT CFFindDialog::OnFind(WORD wNotifyCode, WORD wID, HWND hWndCtl, | 36 LRESULT CFFindDialog::OnFind(WORD wNotifyCode, WORD wID, HWND hWndCtl, |
| 28 BOOL& bHandled) { | 37 BOOL& bHandled) { |
| 29 wchar_t buffer[kMaxFindChars + 1]; | 38 wchar_t buffer[kMaxFindChars + 1]; |
| 30 GetDlgItemText(IDC_FIND_TEXT, buffer, kMaxFindChars); | 39 GetDlgItemText(IDC_FIND_TEXT, buffer, kMaxFindChars); |
|
grt (UTC plus 2)
2012/03/15 02:29:52
what do you think about doing this to avoid extra
robertshield
2012/03/15 02:54:22
lgtm, done
| |
| 31 std::wstring find_text(buffer); | 40 string16 find_text(buffer); |
| 41 | |
| 42 // Repeated searches for the same string should move to the next instance. | |
| 43 bool find_next = (find_text == last_find_text_); | |
| 44 if (!find_next) { | |
|
grt (UTC plus 2)
2012/03/15 02:29:52
remove braces (chromium hates wasted vertical spac
robertshield
2012/03/15 02:54:22
Done.
| |
| 45 last_find_text_ = find_text; | |
| 46 } | |
| 32 | 47 |
| 33 bool match_case = IsDlgButtonChecked(IDC_MATCH_CASE) == BST_CHECKED; | 48 bool match_case = IsDlgButtonChecked(IDC_MATCH_CASE) == BST_CHECKED; |
| 34 bool search_down = IsDlgButtonChecked(IDC_DIRECTION_DOWN) == BST_CHECKED; | 49 bool search_down = IsDlgButtonChecked(IDC_DIRECTION_DOWN) == BST_CHECKED; |
| 35 | 50 |
| 36 automation_client_->FindInPage(find_text, | 51 automation_client_->FindInPage(find_text, |
| 37 search_down ? FWD : BACK, | 52 search_down ? FWD : BACK, |
| 38 match_case ? CASE_SENSITIVE : IGNORE_CASE, | 53 match_case ? CASE_SENSITIVE : IGNORE_CASE, |
| 39 false); | 54 find_next); |
| 40 | 55 |
| 41 return 0; | 56 return 0; |
| 42 } | 57 } |
| 43 | 58 |
| 44 LRESULT CFFindDialog::OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, | 59 LRESULT CFFindDialog::OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, |
| 45 BOOL& bHandled) { | 60 BOOL& bHandled) { |
| 46 DestroyWindow(); | 61 DestroyWindow(); |
| 47 return 0; | 62 return 0; |
| 48 } | 63 } |
| 49 | 64 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 } | 113 } |
| 99 | 114 |
| 100 bool CFFindDialog::UninstallMessageHook() { | 115 bool CFFindDialog::UninstallMessageHook() { |
| 101 DCHECK(msg_hook_ != NULL); | 116 DCHECK(msg_hook_ != NULL); |
| 102 BOOL result = ::UnhookWindowsHookEx(msg_hook_); | 117 BOOL result = ::UnhookWindowsHookEx(msg_hook_); |
| 103 DCHECK(result); | 118 DCHECK(result); |
| 104 msg_hook_ = NULL; | 119 msg_hook_ = NULL; |
| 105 | 120 |
| 106 return result != FALSE; | 121 return result != FALSE; |
| 107 } | 122 } |
| OLD | NEW |