| OLD | NEW |
| 1 // Copyright (c) 2012 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/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/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 } | 165 } |
| 166 | 166 |
| 167 void FindBarView::SetFindTextAndSelectedRange( | 167 void FindBarView::SetFindTextAndSelectedRange( |
| 168 const base::string16& find_text, | 168 const base::string16& find_text, |
| 169 const gfx::Range& selected_range) { | 169 const gfx::Range& selected_range) { |
| 170 find_text_->SetText(find_text); | 170 find_text_->SetText(find_text); |
| 171 find_text_->SelectRange(selected_range); | 171 find_text_->SelectRange(selected_range); |
| 172 } | 172 } |
| 173 | 173 |
| 174 base::string16 FindBarView::GetFindText() const { | 174 base::string16 FindBarView::GetFindText() const { |
| 175 return find_text_->text(); | 175 return find_text_->GetText(); |
| 176 } | 176 } |
| 177 | 177 |
| 178 gfx::Range FindBarView::GetSelectedRange() const { | 178 gfx::Range FindBarView::GetSelectedRange() const { |
| 179 return find_text_->GetSelectedRange(); | 179 return find_text_->GetSelectedRange(); |
| 180 } | 180 } |
| 181 | 181 |
| 182 base::string16 FindBarView::GetFindSelectedText() const { | 182 base::string16 FindBarView::GetFindSelectedText() const { |
| 183 return find_text_->GetSelectedText(); | 183 return find_text_->GetSelectedText(); |
| 184 } | 184 } |
| 185 | 185 |
| 186 base::string16 FindBarView::GetMatchCountText() const { | 186 base::string16 FindBarView::GetMatchCountText() const { |
| 187 return match_count_text_->text(); | 187 return match_count_text_->text(); |
| 188 } | 188 } |
| 189 | 189 |
| 190 void FindBarView::UpdateForResult(const FindNotificationDetails& result, | 190 void FindBarView::UpdateForResult(const FindNotificationDetails& result, |
| 191 const base::string16& find_text) { | 191 const base::string16& find_text) { |
| 192 bool have_valid_range = | 192 bool have_valid_range = |
| 193 result.number_of_matches() != -1 && result.active_match_ordinal() != -1; | 193 result.number_of_matches() != -1 && result.active_match_ordinal() != -1; |
| 194 | 194 |
| 195 // http://crbug.com/34970: some IMEs get confused if we change the text | 195 // http://crbug.com/34970: some IMEs get confused if we change the text |
| 196 // composed by them. To avoid this problem, we should check the IME status and | 196 // composed by them. To avoid this problem, we should check the IME status and |
| 197 // update the text only when the IME is not composing text. | 197 // update the text only when the IME is not composing text. |
| 198 if (find_text_->text() != find_text && !find_text_->IsIMEComposing()) { | 198 if (find_text_->GetText() != find_text && !find_text_->IsIMEComposing()) { |
| 199 find_text_->SetText(find_text); | 199 find_text_->SetText(find_text); |
| 200 find_text_->SelectAll(true); | 200 find_text_->SelectAll(true); |
| 201 } | 201 } |
| 202 | 202 |
| 203 if (find_text.empty() || !have_valid_range) { | 203 if (find_text.empty() || !have_valid_range) { |
| 204 // If there was no text entered, we don't show anything in the result count | 204 // If there was no text entered, we don't show anything in the result count |
| 205 // area. | 205 // area. |
| 206 ClearMatchCount(); | 206 ClearMatchCount(); |
| 207 return; | 207 return; |
| 208 } | 208 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 223 | 223 |
| 224 void FindBarView::ClearMatchCount() { | 224 void FindBarView::ClearMatchCount() { |
| 225 match_count_text_->SetText(base::string16()); | 225 match_count_text_->SetText(base::string16()); |
| 226 UpdateMatchCountAppearance(false); | 226 UpdateMatchCountAppearance(false); |
| 227 Layout(); | 227 Layout(); |
| 228 SchedulePaint(); | 228 SchedulePaint(); |
| 229 } | 229 } |
| 230 | 230 |
| 231 void FindBarView::SetFocusAndSelection(bool select_all) { | 231 void FindBarView::SetFocusAndSelection(bool select_all) { |
| 232 find_text_->RequestFocus(); | 232 find_text_->RequestFocus(); |
| 233 if (select_all && !find_text_->text().empty()) | 233 if (select_all && !find_text_->GetText().empty()) |
| 234 find_text_->SelectAll(true); | 234 find_text_->SelectAll(true); |
| 235 } | 235 } |
| 236 | 236 |
| 237 /////////////////////////////////////////////////////////////////////////////// | 237 /////////////////////////////////////////////////////////////////////////////// |
| 238 // FindBarView, views::View overrides: | 238 // FindBarView, views::View overrides: |
| 239 | 239 |
| 240 void FindBarView::OnPaint(gfx::Canvas* canvas) { | 240 void FindBarView::OnPaint(gfx::Canvas* canvas) { |
| 241 // Paint drop down bar border and background. | 241 // Paint drop down bar border and background. |
| 242 DropdownBarView::OnPaint(canvas); | 242 DropdownBarView::OnPaint(canvas); |
| 243 | 243 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 } | 362 } |
| 363 | 363 |
| 364 //////////////////////////////////////////////////////////////////////////////// | 364 //////////////////////////////////////////////////////////////////////////////// |
| 365 // FindBarView, views::ButtonListener implementation: | 365 // FindBarView, views::ButtonListener implementation: |
| 366 | 366 |
| 367 void FindBarView::ButtonPressed( | 367 void FindBarView::ButtonPressed( |
| 368 views::Button* sender, const ui::Event& event) { | 368 views::Button* sender, const ui::Event& event) { |
| 369 switch (sender->tag()) { | 369 switch (sender->tag()) { |
| 370 case FIND_PREVIOUS_TAG: | 370 case FIND_PREVIOUS_TAG: |
| 371 case FIND_NEXT_TAG: | 371 case FIND_NEXT_TAG: |
| 372 if (!find_text_->text().empty()) { | 372 if (!find_text_->GetText().empty()) { |
| 373 FindTabHelper* find_tab_helper = FindTabHelper::FromWebContents( | 373 FindTabHelper* find_tab_helper = FindTabHelper::FromWebContents( |
| 374 find_bar_host()->GetFindBarController()->web_contents()); | 374 find_bar_host()->GetFindBarController()->web_contents()); |
| 375 find_tab_helper->StartFinding(find_text_->text(), | 375 find_tab_helper->StartFinding(find_text_->GetText(), |
| 376 sender->tag() == FIND_NEXT_TAG, | 376 sender->tag() == FIND_NEXT_TAG, |
| 377 false); // Not case sensitive. | 377 false); // Not case sensitive. |
| 378 } | 378 } |
| 379 if (event.IsMouseEvent()) { | 379 if (event.IsMouseEvent()) { |
| 380 // If mouse event, we move the focus back to the text-field, so that the | 380 // If mouse event, we move the focus back to the text-field, so that the |
| 381 // user doesn't have to click on the text field to change the search. We | 381 // user doesn't have to click on the text field to change the search. We |
| 382 // don't want to do this for keyboard clicks on the button, since the | 382 // don't want to do this for keyboard clicks on the button, since the |
| 383 // user is more likely to press FindNext again than change the search | 383 // user is more likely to press FindNext again than change the search |
| 384 // query. | 384 // query. |
| 385 find_text_->RequestFocus(); | 385 find_text_->RequestFocus(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 403 const ui::KeyEvent& key_event) { | 403 const ui::KeyEvent& key_event) { |
| 404 // If the dialog is not visible, there is no reason to process keyboard input. | 404 // If the dialog is not visible, there is no reason to process keyboard input. |
| 405 if (!host()->IsVisible()) | 405 if (!host()->IsVisible()) |
| 406 return false; | 406 return false; |
| 407 | 407 |
| 408 if (find_bar_host()->MaybeForwardKeyEventToWebpage(key_event)) | 408 if (find_bar_host()->MaybeForwardKeyEventToWebpage(key_event)) |
| 409 return true; // Handled, we are done! | 409 return true; // Handled, we are done! |
| 410 | 410 |
| 411 if (key_event.key_code() == ui::VKEY_RETURN) { | 411 if (key_event.key_code() == ui::VKEY_RETURN) { |
| 412 // Pressing Return/Enter starts the search (unless text box is empty). | 412 // Pressing Return/Enter starts the search (unless text box is empty). |
| 413 base::string16 find_string = find_text_->text(); | 413 base::string16 find_string = find_text_->GetText(); |
| 414 if (!find_string.empty()) { | 414 if (!find_string.empty()) { |
| 415 FindBarController* controller = find_bar_host()->GetFindBarController(); | 415 FindBarController* controller = find_bar_host()->GetFindBarController(); |
| 416 FindTabHelper* find_tab_helper = | 416 FindTabHelper* find_tab_helper = |
| 417 FindTabHelper::FromWebContents(controller->web_contents()); | 417 FindTabHelper::FromWebContents(controller->web_contents()); |
| 418 // Search forwards for enter, backwards for shift-enter. | 418 // Search forwards for enter, backwards for shift-enter. |
| 419 find_tab_helper->StartFinding(find_string, | 419 find_tab_helper->StartFinding(find_string, |
| 420 !key_event.IsShiftDown(), | 420 !key_event.IsShiftDown(), |
| 421 false); // Not case sensitive. | 421 false); // Not case sensitive. |
| 422 } | 422 } |
| 423 return true; | 423 return true; |
| 424 } | 424 } |
| 425 | 425 |
| 426 return false; | 426 return false; |
| 427 } | 427 } |
| 428 | 428 |
| 429 void FindBarView::OnAfterUserAction(views::Textfield* sender) { | 429 void FindBarView::OnAfterUserAction(views::Textfield* sender) { |
| 430 // The composition text wouldn't be what the user is really looking for. | 430 // The composition text wouldn't be what the user is really looking for. |
| 431 // We delay the search until the user commits the composition text. | 431 // We delay the search until the user commits the composition text. |
| 432 if (!sender->IsIMEComposing() && sender->text() != last_searched_text_) | 432 if (!sender->IsIMEComposing() && sender->GetText() != last_searched_text_) |
| 433 Find(sender->text()); | 433 Find(sender->GetText()); |
| 434 } | 434 } |
| 435 | 435 |
| 436 void FindBarView::OnAfterPaste() { | 436 void FindBarView::OnAfterPaste() { |
| 437 // Clear the last search text so we always search for the user input after | 437 // Clear the last search text so we always search for the user input after |
| 438 // a paste operation, even if the pasted text is the same as before. | 438 // a paste operation, even if the pasted text is the same as before. |
| 439 // See http://crbug.com/79002 | 439 // See http://crbug.com/79002 |
| 440 last_searched_text_.clear(); | 440 last_searched_text_.clear(); |
| 441 } | 441 } |
| 442 | 442 |
| 443 void FindBarView::Find(const base::string16& search_text) { | 443 void FindBarView::Find(const base::string16& search_text) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 | 499 |
| 500 void FindBarView::OnThemeChanged() { | 500 void FindBarView::OnThemeChanged() { |
| 501 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 501 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 502 if (GetThemeProvider()) { | 502 if (GetThemeProvider()) { |
| 503 close_button_->SetBackground( | 503 close_button_->SetBackground( |
| 504 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TAB_TEXT), | 504 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TAB_TEXT), |
| 505 rb.GetImageSkiaNamed(IDR_CLOSE_1), | 505 rb.GetImageSkiaNamed(IDR_CLOSE_1), |
| 506 rb.GetImageSkiaNamed(IDR_CLOSE_1_MASK)); | 506 rb.GetImageSkiaNamed(IDR_CLOSE_1_MASK)); |
| 507 } | 507 } |
| 508 } | 508 } |
| OLD | NEW |