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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 // Background images for the Find edit box. | 161 // Background images for the Find edit box. |
162 kBackground = rb.GetBitmapNamed(IDR_FIND_BOX_BACKGROUND); | 162 kBackground = rb.GetBitmapNamed(IDR_FIND_BOX_BACKGROUND); |
163 if (UILayoutIsRightToLeft()) | 163 if (UILayoutIsRightToLeft()) |
164 kBackground_left = rb.GetBitmapNamed(IDR_FIND_BOX_BACKGROUND_LEFT_RTL); | 164 kBackground_left = rb.GetBitmapNamed(IDR_FIND_BOX_BACKGROUND_LEFT_RTL); |
165 else | 165 else |
166 kBackground_left = rb.GetBitmapNamed(IDR_FIND_BOX_BACKGROUND_LEFT); | 166 kBackground_left = rb.GetBitmapNamed(IDR_FIND_BOX_BACKGROUND_LEFT); |
167 } | 167 } |
168 } | 168 } |
169 | 169 |
170 FindBarView::~FindBarView() { | 170 FindBarView::~FindBarView() { |
171 // We are going away so we don't want to be notified about further updates | |
172 // to the text field. Otherwise, it can lead to crashes, as exposed by | |
173 // automation testing in issue 8048. | |
174 find_text_->SetController(NULL); | |
175 } | 171 } |
176 | 172 |
177 void FindBarView::SetFindText(const std::wstring& find_text) { | 173 void FindBarView::SetFindText(const std::wstring& find_text) { |
178 find_text_->SetText(find_text); | 174 find_text_->SetText(find_text); |
179 } | 175 } |
180 | 176 |
181 void FindBarView::UpdateForResult(const FindNotificationDetails& result, | 177 void FindBarView::UpdateForResult(const FindNotificationDetails& result, |
182 const std::wstring& find_text) { | 178 const std::wstring& find_text) { |
183 bool have_valid_range = | 179 bool have_valid_range = |
184 result.number_of_matches() != -1 && result.active_match_ordinal() != -1; | 180 result.number_of_matches() != -1 && result.active_match_ordinal() != -1; |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 NOTREACHED() << L"Unknown button"; | 433 NOTREACHED() << L"Unknown button"; |
438 break; | 434 break; |
439 } | 435 } |
440 } | 436 } |
441 | 437 |
442 //////////////////////////////////////////////////////////////////////////////// | 438 //////////////////////////////////////////////////////////////////////////////// |
443 // FindBarView, views::TextField::Controller implementation: | 439 // FindBarView, views::TextField::Controller implementation: |
444 | 440 |
445 void FindBarView::ContentsChanged(views::TextField* sender, | 441 void FindBarView::ContentsChanged(views::TextField* sender, |
446 const std::wstring& new_contents) { | 442 const std::wstring& new_contents) { |
| 443 // We must guard against a NULL web_contents, which can happen if the text |
| 444 // in the Find box is changed right after the tab is destroyed. Otherwise, it |
| 445 // can lead to crashes, as exposed by automation testing in issue 8048. |
| 446 if (!container_->web_contents()) |
| 447 return; |
| 448 |
447 // When the user changes something in the text box we check the contents and | 449 // When the user changes something in the text box we check the contents and |
448 // if the textbox contains something we set it as the new search string and | 450 // if the textbox contains something we set it as the new search string and |
449 // initiate search (even though old searches might be in progress). | 451 // initiate search (even though old searches might be in progress). |
450 if (new_contents.length() > 0) { | 452 if (new_contents.length() > 0) { |
451 container_->web_contents()->StartFinding(new_contents, true); | 453 container_->web_contents()->StartFinding(new_contents, true); |
452 } else { | 454 } else { |
453 // The textbox is empty so we reset. | 455 // The textbox is empty so we reset. |
454 container_->web_contents()->StopFinding(true); // true = clear selection on | 456 container_->web_contents()->StopFinding(true); // true = clear selection on |
455 // page. | 457 // page. |
456 UpdateForResult(container_->web_contents()->find_result(), | 458 UpdateForResult(container_->web_contents()->find_result(), |
(...skipping 29 matching lines...) Expand all Loading... |
486 } | 488 } |
487 | 489 |
488 bool FindBarView::FocusForwarderView::OnMousePressed( | 490 bool FindBarView::FocusForwarderView::OnMousePressed( |
489 const views::MouseEvent& event) { | 491 const views::MouseEvent& event) { |
490 if (view_to_focus_on_mousedown_) { | 492 if (view_to_focus_on_mousedown_) { |
491 view_to_focus_on_mousedown_->ClearSelection(); | 493 view_to_focus_on_mousedown_->ClearSelection(); |
492 view_to_focus_on_mousedown_->RequestFocus(); | 494 view_to_focus_on_mousedown_->RequestFocus(); |
493 } | 495 } |
494 return true; | 496 return true; |
495 } | 497 } |
OLD | NEW |