| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "chrome/browser/tab_contents/web_contents.h" | 10 #include "chrome/browser/tab_contents/web_contents.h" |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 match_count_text_->SetText( | 207 match_count_text_->SetText( |
| 208 l10n_util::GetStringF(IDS_FIND_IN_PAGE_COUNT, | 208 l10n_util::GetStringF(IDS_FIND_IN_PAGE_COUNT, |
| 209 IntToWString(result.active_match_ordinal()), | 209 IntToWString(result.active_match_ordinal()), |
| 210 IntToWString(result.number_of_matches()))); | 210 IntToWString(result.number_of_matches()))); |
| 211 } else { | 211 } else { |
| 212 // If there was no text entered, we don't show anything in the result count | 212 // If there was no text entered, we don't show anything in the result count |
| 213 // area. | 213 // area. |
| 214 match_count_text_->SetText(std::wstring()); | 214 match_count_text_->SetText(std::wstring()); |
| 215 } | 215 } |
| 216 | 216 |
| 217 if (search_string.empty() || result.number_of_matches() > 0) { | 217 if (search_string.empty() || result.number_of_matches() > 0 || |
| 218 !have_valid_range) { |
| 218 // If there was no text entered or there were results, the match_count label | 219 // If there was no text entered or there were results, the match_count label |
| 219 // should have a normal background color. | 220 // should have a normal background color. We also reset the background if |
| 221 // we don't have_valid_range, so that the text field will not show red |
| 222 // background when reopened after an unsuccessful find. |
| 220 ResetMatchCountBackground(); | 223 ResetMatchCountBackground(); |
| 221 } else if (result.final_update()) { | 224 } else if (result.final_update()) { |
| 222 // Otherwise we show an error background behind the match_count label. | 225 // Otherwise we show an error background behind the match_count label. |
| 223 match_count_text_->set_background( | 226 match_count_text_->set_background( |
| 224 views::Background::CreateSolidBackground(kBackgroundColorNoMatch)); | 227 views::Background::CreateSolidBackground(kBackgroundColorNoMatch)); |
| 225 match_count_text_->SetColor(kTextColorNoMatch); | 228 match_count_text_->SetColor(kTextColorNoMatch); |
| 226 MessageBeep(MB_OK); | 229 MessageBeep(MB_OK); |
| 227 } | 230 } |
| 228 | 231 |
| 229 // Make sure Find Next and Find Previous are enabled if we found any matches. | 232 // Make sure Find Next and Find Previous are enabled if we found any matches. |
| 230 find_previous_button_->SetEnabled(result.number_of_matches() > 0); | 233 find_previous_button_->SetEnabled(result.number_of_matches() > 0); |
| 231 find_next_button_->SetEnabled(result.number_of_matches() > 0); | 234 find_next_button_->SetEnabled(result.number_of_matches() > 0); |
| 232 | 235 |
| 233 Layout(); // The match_count label may have increased/decreased in size. | 236 Layout(); // The match_count label may have increased/decreased in size. |
| 234 } | 237 } |
| 235 | 238 |
| 236 void FindBarView::SetFocusAndSelection() { | 239 void FindBarView::SetFocusAndSelection() { |
| 237 find_text_->RequestFocus(); | 240 find_text_->RequestFocus(); |
| 238 find_text_->SelectAll(); | 241 if (!find_text_->GetText().empty()) { |
| 242 find_text_->SelectAll(); |
| 243 |
| 244 find_previous_button_->SetEnabled(true); |
| 245 find_next_button_->SetEnabled(true); |
| 246 } |
| 239 } | 247 } |
| 240 | 248 |
| 241 /////////////////////////////////////////////////////////////////////////////// | 249 /////////////////////////////////////////////////////////////////////////////// |
| 242 // FindBarView, views::View overrides: | 250 // FindBarView, views::View overrides: |
| 243 | 251 |
| 244 void FindBarView::Paint(ChromeCanvas* canvas) { | 252 void FindBarView::Paint(ChromeCanvas* canvas) { |
| 245 SkPaint paint; | 253 SkPaint paint; |
| 246 | 254 |
| 247 // Get the local bounds so that we now how much to stretch the background. | 255 // Get the local bounds so that we now how much to stretch the background. |
| 248 gfx::Rect lb = GetLocalBounds(true); | 256 gfx::Rect lb = GetLocalBounds(true); |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 } | 496 } |
| 489 | 497 |
| 490 bool FindBarView::FocusForwarderView::OnMousePressed( | 498 bool FindBarView::FocusForwarderView::OnMousePressed( |
| 491 const views::MouseEvent& event) { | 499 const views::MouseEvent& event) { |
| 492 if (view_to_focus_on_mousedown_) { | 500 if (view_to_focus_on_mousedown_) { |
| 493 view_to_focus_on_mousedown_->ClearSelection(); | 501 view_to_focus_on_mousedown_->ClearSelection(); |
| 494 view_to_focus_on_mousedown_->RequestFocus(); | 502 view_to_focus_on_mousedown_->RequestFocus(); |
| 495 } | 503 } |
| 496 return true; | 504 return true; |
| 497 } | 505 } |
| OLD | NEW |