| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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/browser/views/find_bar_view.h" | 5 #include "chrome/browser/views/find_bar_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "app/gfx/canvas.h" | 9 #include "app/gfx/canvas.h" |
| 10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 } | 167 } |
| 168 | 168 |
| 169 void FindBarView::UpdateForResult(const FindNotificationDetails& result, | 169 void FindBarView::UpdateForResult(const FindNotificationDetails& result, |
| 170 const string16& find_text) { | 170 const string16& find_text) { |
| 171 bool have_valid_range = | 171 bool have_valid_range = |
| 172 result.number_of_matches() != -1 && result.active_match_ordinal() != -1; | 172 result.number_of_matches() != -1 && result.active_match_ordinal() != -1; |
| 173 | 173 |
| 174 // If we don't have any results and something was passed in, then that means | 174 // If we don't have any results and something was passed in, then that means |
| 175 // someone pressed F3 while the Find box was closed. In that case we need to | 175 // someone pressed F3 while the Find box was closed. In that case we need to |
| 176 // repopulate the Find box with what was passed in. | 176 // repopulate the Find box with what was passed in. |
| 177 std::wstring search_string = find_text_->GetText(); | 177 std::wstring search_string = find_text_->text(); |
| 178 if (search_string.empty() && !find_text.empty()) { | 178 if (search_string.empty() && !find_text.empty()) { |
| 179 find_text_->SetText(UTF16ToWide(find_text)); | 179 find_text_->SetText(UTF16ToWide(find_text)); |
| 180 find_text_->SelectAll(); | 180 find_text_->SelectAll(); |
| 181 } | 181 } |
| 182 | 182 |
| 183 if (!search_string.empty() && have_valid_range) { | 183 if (!search_string.empty() && have_valid_range) { |
| 184 match_count_text_->SetText( | 184 match_count_text_->SetText( |
| 185 l10n_util::GetStringF(IDS_FIND_IN_PAGE_COUNT, | 185 l10n_util::GetStringF(IDS_FIND_IN_PAGE_COUNT, |
| 186 IntToWString(result.active_match_ordinal()), | 186 IntToWString(result.active_match_ordinal()), |
| 187 IntToWString(result.number_of_matches()))); | 187 IntToWString(result.number_of_matches()))); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 207 | 207 |
| 208 // Make sure Find Next and Find Previous are enabled if we found any matches. | 208 // Make sure Find Next and Find Previous are enabled if we found any matches. |
| 209 find_previous_button_->SetEnabled(result.number_of_matches() > 0); | 209 find_previous_button_->SetEnabled(result.number_of_matches() > 0); |
| 210 find_next_button_->SetEnabled(result.number_of_matches() > 0); | 210 find_next_button_->SetEnabled(result.number_of_matches() > 0); |
| 211 | 211 |
| 212 Layout(); // The match_count label may have increased/decreased in size. | 212 Layout(); // The match_count label may have increased/decreased in size. |
| 213 } | 213 } |
| 214 | 214 |
| 215 void FindBarView::SetFocusAndSelection() { | 215 void FindBarView::SetFocusAndSelection() { |
| 216 find_text_->RequestFocus(); | 216 find_text_->RequestFocus(); |
| 217 if (!find_text_->GetText().empty()) { | 217 if (!find_text_->text().empty()) { |
| 218 find_text_->SelectAll(); | 218 find_text_->SelectAll(); |
| 219 | 219 |
| 220 find_previous_button_->SetEnabled(true); | 220 find_previous_button_->SetEnabled(true); |
| 221 find_next_button_->SetEnabled(true); | 221 find_next_button_->SetEnabled(true); |
| 222 } | 222 } |
| 223 } | 223 } |
| 224 | 224 |
| 225 /////////////////////////////////////////////////////////////////////////////// | 225 /////////////////////////////////////////////////////////////////////////////// |
| 226 // FindBarView, views::View overrides: | 226 // FindBarView, views::View overrides: |
| 227 | 227 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 return prefsize; | 391 return prefsize; |
| 392 } | 392 } |
| 393 | 393 |
| 394 //////////////////////////////////////////////////////////////////////////////// | 394 //////////////////////////////////////////////////////////////////////////////// |
| 395 // FindBarView, views::ButtonListener implementation: | 395 // FindBarView, views::ButtonListener implementation: |
| 396 | 396 |
| 397 void FindBarView::ButtonPressed(views::Button* sender) { | 397 void FindBarView::ButtonPressed(views::Button* sender) { |
| 398 switch (sender->tag()) { | 398 switch (sender->tag()) { |
| 399 case FIND_PREVIOUS_TAG: | 399 case FIND_PREVIOUS_TAG: |
| 400 case FIND_NEXT_TAG: | 400 case FIND_NEXT_TAG: |
| 401 if (!find_text_->GetText().empty()) { | 401 if (!find_text_->text().empty()) { |
| 402 container_->GetFindBarController()->tab_contents()->StartFinding( | 402 container_->GetFindBarController()->tab_contents()->StartFinding( |
| 403 WideToUTF16(find_text_->GetText()), | 403 WideToUTF16(find_text_->text()), |
| 404 sender->tag() == FIND_NEXT_TAG, | 404 sender->tag() == FIND_NEXT_TAG, |
| 405 false); // Not case sensitive. | 405 false); // Not case sensitive. |
| 406 } | 406 } |
| 407 // Move the focus back to the text-field, we don't want the button | 407 // Move the focus back to the text-field, we don't want the button |
| 408 // focused. | 408 // focused. |
| 409 // TODO(jcampan): http://crbug.com/9867 we should not change the focus | 409 // TODO(jcampan): http://crbug.com/9867 we should not change the focus |
| 410 // when teh button was pressed by pressing a key. | 410 // when teh button was pressed by pressing a key. |
| 411 find_text_->RequestFocus(); | 411 find_text_->RequestFocus(); |
| 412 break; | 412 break; |
| 413 case CLOSE_TAG: | 413 case CLOSE_TAG: |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 return false; | 452 return false; |
| 453 | 453 |
| 454 // TODO(port): Handle this for other platforms. | 454 // TODO(port): Handle this for other platforms. |
| 455 #if defined(OS_WIN) | 455 #if defined(OS_WIN) |
| 456 if (container_->MaybeForwardKeystrokeToWebpage(key.message, key.key, | 456 if (container_->MaybeForwardKeystrokeToWebpage(key.message, key.key, |
| 457 key.flags)) | 457 key.flags)) |
| 458 return true; // Handled, we are done! | 458 return true; // Handled, we are done! |
| 459 | 459 |
| 460 if (views::Textfield::IsKeystrokeEnter(key)) { | 460 if (views::Textfield::IsKeystrokeEnter(key)) { |
| 461 // Pressing Return/Enter starts the search (unless text box is empty). | 461 // Pressing Return/Enter starts the search (unless text box is empty). |
| 462 std::wstring find_string = find_text_->GetText(); | 462 std::wstring find_string = find_text_->text(); |
| 463 if (!find_string.empty()) { | 463 if (!find_string.empty()) { |
| 464 // Search forwards for enter, backwards for shift-enter. | 464 // Search forwards for enter, backwards for shift-enter. |
| 465 container_->GetFindBarController()->tab_contents()->StartFinding( | 465 container_->GetFindBarController()->tab_contents()->StartFinding( |
| 466 find_string, | 466 find_string, |
| 467 GetKeyState(VK_SHIFT) >= 0, | 467 GetKeyState(VK_SHIFT) >= 0, |
| 468 false); // Not case sensitive. | 468 false); // Not case sensitive. |
| 469 } | 469 } |
| 470 } | 470 } |
| 471 #endif | 471 #endif |
| 472 | 472 |
| 473 return false; | 473 return false; |
| 474 } | 474 } |
| 475 | 475 |
| 476 void FindBarView::ResetMatchCountBackground() { | 476 void FindBarView::ResetMatchCountBackground() { |
| 477 match_count_text_->set_background( | 477 match_count_text_->set_background( |
| 478 views::Background::CreateSolidBackground(kBackgroundColorMatch)); | 478 views::Background::CreateSolidBackground(kBackgroundColorMatch)); |
| 479 match_count_text_->SetColor(kTextColorMatchCount); | 479 match_count_text_->SetColor(kTextColorMatchCount); |
| 480 } | 480 } |
| 481 | 481 |
| 482 bool FindBarView::FocusForwarderView::OnMousePressed( | 482 bool FindBarView::FocusForwarderView::OnMousePressed( |
| 483 const views::MouseEvent& event) { | 483 const views::MouseEvent& event) { |
| 484 if (view_to_focus_on_mousedown_) { | 484 if (view_to_focus_on_mousedown_) { |
| 485 view_to_focus_on_mousedown_->ClearSelection(); | 485 view_to_focus_on_mousedown_->ClearSelection(); |
| 486 view_to_focus_on_mousedown_->RequestFocus(); | 486 view_to_focus_on_mousedown_->RequestFocus(); |
| 487 } | 487 } |
| 488 return true; | 488 return true; |
| 489 } | 489 } |
| OLD | NEW |