| 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" |
| 11 #include "app/resource_bundle.h" | 11 #include "app/resource_bundle.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "chrome/browser/browser_theme_provider.h" | 13 #include "chrome/browser/browser_theme_provider.h" |
| 14 #include "chrome/browser/find_bar_controller.h" | 14 #include "chrome/browser/find_bar_controller.h" |
| 15 #include "chrome/browser/tab_contents/tab_contents.h" | 15 #include "chrome/browser/tab_contents/tab_contents.h" |
| 16 #include "chrome/browser/views/find_bar_win.h" | 16 #include "chrome/browser/views/find_bar_host.h" |
| 17 #include "chrome/browser/view_ids.h" | 17 #include "chrome/browser/view_ids.h" |
| 18 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
| 19 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" |
| 20 #include "third_party/skia/include/effects/SkGradientShader.h" | 20 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 21 #include "views/background.h" | 21 #include "views/background.h" |
| 22 #include "views/controls/button/image_button.h" | 22 #include "views/controls/button/image_button.h" |
| 23 #include "views/controls/label.h" | 23 #include "views/controls/label.h" |
| 24 | 24 |
| 25 // The amount of whitespace to have before the find button. | 25 // The amount of whitespace to have before the find button. |
| 26 static const int kWhiteSpaceAfterMatchCountLabel = 1; | 26 static const int kWhiteSpaceAfterMatchCountLabel = 1; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 // The rounded edge on the left side of the Find text box. | 69 // The rounded edge on the left side of the Find text box. |
| 70 static const SkBitmap* kBackground_left = NULL; | 70 static const SkBitmap* kBackground_left = NULL; |
| 71 | 71 |
| 72 // The default number of average characters that the text box will be. This | 72 // The default number of average characters that the text box will be. This |
| 73 // number brings the width on a "regular fonts" system to about 300px. | 73 // number brings the width on a "regular fonts" system to about 300px. |
| 74 static const int kDefaultCharWidth = 43; | 74 static const int kDefaultCharWidth = 43; |
| 75 | 75 |
| 76 //////////////////////////////////////////////////////////////////////////////// | 76 //////////////////////////////////////////////////////////////////////////////// |
| 77 // FindBarView, public: | 77 // FindBarView, public: |
| 78 | 78 |
| 79 FindBarView::FindBarView(FindBarWin* container) | 79 FindBarView::FindBarView(FindBarHost* container) |
| 80 : container_(container), | 80 : container_(container), |
| 81 find_text_(NULL), | 81 find_text_(NULL), |
| 82 match_count_text_(NULL), | 82 match_count_text_(NULL), |
| 83 focus_forwarder_view_(NULL), | 83 focus_forwarder_view_(NULL), |
| 84 find_previous_button_(NULL), | 84 find_previous_button_(NULL), |
| 85 find_next_button_(NULL), | 85 find_next_button_(NULL), |
| 86 close_button_(NULL), | 86 close_button_(NULL), |
| 87 animation_offset_(0) { | 87 animation_offset_(0) { |
| 88 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 88 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 89 | 89 |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 UpdateForResult(controller->tab_contents()->find_result(), string16()); | 460 UpdateForResult(controller->tab_contents()->find_result(), string16()); |
| 461 } | 461 } |
| 462 } | 462 } |
| 463 | 463 |
| 464 bool FindBarView::HandleKeystroke(views::Textfield* sender, | 464 bool FindBarView::HandleKeystroke(views::Textfield* sender, |
| 465 const views::Textfield::Keystroke& key) { | 465 const views::Textfield::Keystroke& key) { |
| 466 // If the dialog is not visible, there is no reason to process keyboard input. | 466 // If the dialog is not visible, there is no reason to process keyboard input. |
| 467 if (!container_->IsVisible()) | 467 if (!container_->IsVisible()) |
| 468 return false; | 468 return false; |
| 469 | 469 |
| 470 // TODO(port): Handle this for other platforms. | 470 if (container_->MaybeForwardKeystrokeToWebpage(key)) |
| 471 #if defined(OS_WIN) | |
| 472 if (container_->MaybeForwardKeystrokeToWebpage(key.message, key.key, | |
| 473 key.flags)) | |
| 474 return true; // Handled, we are done! | 471 return true; // Handled, we are done! |
| 475 | 472 |
| 476 if (views::Textfield::IsKeystrokeEnter(key)) { | 473 if (key.GetKeyboardCode() == base::VKEY_RETURN) { |
| 477 // Pressing Return/Enter starts the search (unless text box is empty). | 474 // Pressing Return/Enter starts the search (unless text box is empty). |
| 478 std::wstring find_string = find_text_->text(); | 475 string16 find_string = find_text_->text(); |
| 479 if (!find_string.empty()) { | 476 if (!find_string.empty()) { |
| 480 // Search forwards for enter, backwards for shift-enter. | 477 // Search forwards for enter, backwards for shift-enter. |
| 481 container_->GetFindBarController()->tab_contents()->StartFinding( | 478 container_->GetFindBarController()->tab_contents()->StartFinding( |
| 482 find_string, | 479 find_string, |
| 483 GetKeyState(VK_SHIFT) >= 0, | 480 key.IsShiftHeld(), |
| 484 false); // Not case sensitive. | 481 false); // Not case sensitive. |
| 485 } | 482 } |
| 486 } | 483 } |
| 487 #endif | |
| 488 | 484 |
| 489 return false; | 485 return false; |
| 490 } | 486 } |
| 491 | 487 |
| 492 void FindBarView::ResetMatchCountBackground() { | 488 void FindBarView::ResetMatchCountBackground() { |
| 493 match_count_text_->set_background( | 489 match_count_text_->set_background( |
| 494 views::Background::CreateSolidBackground(kBackgroundColorMatch)); | 490 views::Background::CreateSolidBackground(kBackgroundColorMatch)); |
| 495 match_count_text_->SetColor(kTextColorMatchCount); | 491 match_count_text_->SetColor(kTextColorMatchCount); |
| 496 } | 492 } |
| 497 | 493 |
| 498 bool FindBarView::FocusForwarderView::OnMousePressed( | 494 bool FindBarView::FocusForwarderView::OnMousePressed( |
| 499 const views::MouseEvent& event) { | 495 const views::MouseEvent& event) { |
| 500 if (view_to_focus_on_mousedown_) { | 496 if (view_to_focus_on_mousedown_) { |
| 501 view_to_focus_on_mousedown_->ClearSelection(); | 497 view_to_focus_on_mousedown_->ClearSelection(); |
| 502 view_to_focus_on_mousedown_->RequestFocus(); | 498 view_to_focus_on_mousedown_->RequestFocus(); |
| 503 } | 499 } |
| 504 return true; | 500 return true; |
| 505 } | 501 } |
| OLD | NEW |