| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui/views/find_bar_view.h" | 5 #include "chrome/browser/ui/views/find_bar_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 | 160 |
| 161 string16 FindBarView::GetFindText() const { | 161 string16 FindBarView::GetFindText() const { |
| 162 return find_text_->text(); | 162 return find_text_->text(); |
| 163 } | 163 } |
| 164 | 164 |
| 165 string16 FindBarView::GetFindSelectedText() const { | 165 string16 FindBarView::GetFindSelectedText() const { |
| 166 return find_text_->GetSelectedText(); | 166 return find_text_->GetSelectedText(); |
| 167 } | 167 } |
| 168 | 168 |
| 169 string16 FindBarView::GetMatchCountText() const { | 169 string16 FindBarView::GetMatchCountText() const { |
| 170 return match_count_text_->GetText(); | 170 return WideToUTF16Hack(match_count_text_->GetText()); |
| 171 } | 171 } |
| 172 | 172 |
| 173 void FindBarView::UpdateForResult(const FindNotificationDetails& result, | 173 void FindBarView::UpdateForResult(const FindNotificationDetails& result, |
| 174 const string16& find_text) { | 174 const string16& find_text) { |
| 175 bool have_valid_range = | 175 bool have_valid_range = |
| 176 result.number_of_matches() != -1 && result.active_match_ordinal() != -1; | 176 result.number_of_matches() != -1 && result.active_match_ordinal() != -1; |
| 177 | 177 |
| 178 // http://crbug.com/34970: some IMEs get confused if we change the text | 178 // http://crbug.com/34970: some IMEs get confused if we change the text |
| 179 // composed by them. To avoid this problem, we should check the IME status and | 179 // composed by them. To avoid this problem, we should check the IME status and |
| 180 // update the text only when the IME is not composing text. | 180 // update the text only when the IME is not composing text. |
| 181 if (find_text_->text() != find_text && !find_text_->IsIMEComposing()) { | 181 if (find_text_->text() != find_text && !find_text_->IsIMEComposing()) { |
| 182 find_text_->SetText(find_text); | 182 find_text_->SetText(find_text); |
| 183 find_text_->SelectAll(); | 183 find_text_->SelectAll(); |
| 184 } | 184 } |
| 185 | 185 |
| 186 if (!find_text.empty() && have_valid_range) { | 186 if (!find_text.empty() && have_valid_range) { |
| 187 match_count_text_->SetText( | 187 match_count_text_->SetText(UTF16ToWide( |
| 188 l10n_util::GetStringFUTF16(IDS_FIND_IN_PAGE_COUNT, | 188 l10n_util::GetStringFUTF16(IDS_FIND_IN_PAGE_COUNT, |
| 189 base::IntToString16(result.active_match_ordinal()), | 189 base::IntToString16(result.active_match_ordinal()), |
| 190 base::IntToString16(result.number_of_matches()))); | 190 base::IntToString16(result.number_of_matches())))); |
| 191 | 191 |
| 192 UpdateMatchCountAppearance(result.number_of_matches() == 0 && | 192 UpdateMatchCountAppearance(result.number_of_matches() == 0 && |
| 193 result.final_update()); | 193 result.final_update()); |
| 194 } else { | 194 } else { |
| 195 // If there was no text entered, we don't show anything in the result count | 195 // If there was no text entered, we don't show anything in the result count |
| 196 // area. | 196 // area. |
| 197 match_count_text_->SetText(string16()); | 197 match_count_text_->SetText(std::wstring()); |
| 198 | 198 |
| 199 UpdateMatchCountAppearance(false); | 199 UpdateMatchCountAppearance(false); |
| 200 } | 200 } |
| 201 | 201 |
| 202 // The match_count label may have increased/decreased in size so we need to | 202 // The match_count label may have increased/decreased in size so we need to |
| 203 // do a layout and repaint the dialog so that the find text field doesn't | 203 // do a layout and repaint the dialog so that the find text field doesn't |
| 204 // partially overlap the match-count label when it increases on no matches. | 204 // partially overlap the match-count label when it increases on no matches. |
| 205 Layout(); | 205 Layout(); |
| 206 SchedulePaint(); | 206 SchedulePaint(); |
| 207 } | 207 } |
| 208 | 208 |
| 209 void FindBarView::ClearMatchCount() { | 209 void FindBarView::ClearMatchCount() { |
| 210 match_count_text_->SetText(string16()); | 210 match_count_text_->SetText(L""); |
| 211 UpdateMatchCountAppearance(false); | 211 UpdateMatchCountAppearance(false); |
| 212 Layout(); | 212 Layout(); |
| 213 SchedulePaint(); | 213 SchedulePaint(); |
| 214 } | 214 } |
| 215 | 215 |
| 216 void FindBarView::SetFocusAndSelection(bool select_all) { | 216 void FindBarView::SetFocusAndSelection(bool select_all) { |
| 217 find_text_->RequestFocus(); | 217 find_text_->RequestFocus(); |
| 218 if (select_all && !find_text_->text().empty()) | 218 if (select_all && !find_text_->text().empty()) |
| 219 find_text_->SelectAll(); | 219 find_text_->SelectAll(); |
| 220 } | 220 } |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 | 490 |
| 491 void FindBarView::OnThemeChanged() { | 491 void FindBarView::OnThemeChanged() { |
| 492 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 492 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 493 if (GetThemeProvider()) { | 493 if (GetThemeProvider()) { |
| 494 close_button_->SetBackground( | 494 close_button_->SetBackground( |
| 495 GetThemeProvider()->GetColor(ThemeService::COLOR_TAB_TEXT), | 495 GetThemeProvider()->GetColor(ThemeService::COLOR_TAB_TEXT), |
| 496 rb.GetBitmapNamed(IDR_CLOSE_BAR), | 496 rb.GetBitmapNamed(IDR_CLOSE_BAR), |
| 497 rb.GetBitmapNamed(IDR_CLOSE_BAR_MASK)); | 497 rb.GetBitmapNamed(IDR_CLOSE_BAR_MASK)); |
| 498 } | 498 } |
| 499 } | 499 } |
| OLD | NEW |