| 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/find_bar/find_bar_controller.h" | 5 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 11 #include "chrome/browser/ui/find_bar/find_bar.h" | 11 #include "chrome/browser/ui/find_bar/find_bar.h" |
| 12 #include "chrome/browser/ui/find_bar/find_bar_state.h" | 12 #include "chrome/browser/ui/find_bar/find_bar_state.h" |
| 13 #include "chrome/browser/ui/find_bar/find_tab_helper.h" | 13 #include "chrome/browser/ui/find_bar/find_tab_helper.h" |
| 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 15 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
| 16 #include "content/browser/tab_contents/navigation_details.h" | 16 #include "content/browser/tab_contents/navigation_details.h" |
| 17 #include "content/browser/tab_contents/navigation_entry.h" | 17 #include "content/browser/tab_contents/navigation_entry.h" |
| 18 #include "content/browser/tab_contents/tab_contents.h" |
| 18 #include "content/public/browser/notification_details.h" | 19 #include "content/public/browser/notification_details.h" |
| 19 #include "content/public/browser/notification_source.h" | 20 #include "content/public/browser/notification_source.h" |
| 20 #include "ui/gfx/rect.h" | 21 #include "ui/gfx/rect.h" |
| 21 | 22 |
| 22 // The minimum space between the FindInPage window and the search result. | 23 // The minimum space between the FindInPage window and the search result. |
| 23 static const int kMinFindWndDistanceFromSelection = 5; | 24 static const int kMinFindWndDistanceFromSelection = 5; |
| 24 | 25 |
| 25 FindBarController::FindBarController(FindBar* find_bar) | 26 FindBarController::FindBarController(FindBar* find_bar) |
| 26 : find_bar_(find_bar), | 27 : find_bar_(find_bar), |
| 27 tab_contents_(NULL), | 28 tab_contents_(NULL), |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 // Hide any visible find window from the previous tab if NULL |tab_contents| | 79 // Hide any visible find window from the previous tab if NULL |tab_contents| |
| 79 // is passed in or if the find UI is not active in the new tab. | 80 // is passed in or if the find UI is not active in the new tab. |
| 80 if (find_bar_->IsFindBarVisible() && | 81 if (find_bar_->IsFindBarVisible() && |
| 81 (!tab_contents_ || !tab_contents_->find_tab_helper()->find_ui_active())) { | 82 (!tab_contents_ || !tab_contents_->find_tab_helper()->find_ui_active())) { |
| 82 find_bar_->Hide(false); | 83 find_bar_->Hide(false); |
| 83 } | 84 } |
| 84 | 85 |
| 85 if (!tab_contents_) | 86 if (!tab_contents_) |
| 86 return; | 87 return; |
| 87 | 88 |
| 88 registrar_.Add(this, chrome::NOTIFICATION_FIND_RESULT_AVAILABLE, | 89 registrar_.Add(this, |
| 90 chrome::NOTIFICATION_FIND_RESULT_AVAILABLE, |
| 89 content::Source<TabContents>(tab_contents_->tab_contents())); | 91 content::Source<TabContents>(tab_contents_->tab_contents())); |
| 90 registrar_.Add( | 92 registrar_.Add( |
| 91 this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 93 this, |
| 92 content::Source<NavigationController>(&tab_contents_->controller())); | 94 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 95 content::Source<NavigationController>( |
| 96 &tab_contents_->tab_contents()->controller())); |
| 93 | 97 |
| 94 MaybeSetPrepopulateText(); | 98 MaybeSetPrepopulateText(); |
| 95 | 99 |
| 96 if (tab_contents_->find_tab_helper()->find_ui_active()) { | 100 if (tab_contents_->find_tab_helper()->find_ui_active()) { |
| 97 // A tab with a visible find bar just got selected and we need to show the | 101 // A tab with a visible find bar just got selected and we need to show the |
| 98 // find bar but without animation since it was already animated into its | 102 // find bar but without animation since it was already animated into its |
| 99 // visible state. We also want to reset the window location so that | 103 // visible state. We also want to reset the window location so that |
| 100 // we don't surprise the user by popping up to the left for no apparent | 104 // we don't surprise the user by popping up to the left for no apparent |
| 101 // reason. | 105 // reason. |
| 102 find_bar_->Show(false); | 106 find_bar_->Show(false); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 122 find_tab_helper->find_result().number_of_matches() == 0) { | 126 find_tab_helper->find_result().number_of_matches() == 0) { |
| 123 const string16& last_search = find_tab_helper->previous_find_text(); | 127 const string16& last_search = find_tab_helper->previous_find_text(); |
| 124 const string16& current_search = find_tab_helper->find_text(); | 128 const string16& current_search = find_tab_helper->find_text(); |
| 125 if (last_search.find(current_search) != 0) | 129 if (last_search.find(current_search) != 0) |
| 126 find_bar_->AudibleAlert(); | 130 find_bar_->AudibleAlert(); |
| 127 } | 131 } |
| 128 } | 132 } |
| 129 } else if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) { | 133 } else if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) { |
| 130 NavigationController* source_controller = | 134 NavigationController* source_controller = |
| 131 content::Source<NavigationController>(source).ptr(); | 135 content::Source<NavigationController>(source).ptr(); |
| 132 if (source_controller == &tab_contents_->controller()) { | 136 if (source_controller == &tab_contents_->tab_contents()->controller()) { |
| 133 content::LoadCommittedDetails* commit_details = | 137 content::LoadCommittedDetails* commit_details = |
| 134 content::Details<content::LoadCommittedDetails>(details).ptr(); | 138 content::Details<content::LoadCommittedDetails>(details).ptr(); |
| 135 content::PageTransition transition_type = | 139 content::PageTransition transition_type = |
| 136 commit_details->entry->transition_type(); | 140 commit_details->entry->transition_type(); |
| 137 // We hide the FindInPage window when the user navigates away, except on | 141 // We hide the FindInPage window when the user navigates away, except on |
| 138 // reload. | 142 // reload. |
| 139 if (find_bar_->IsFindBarVisible()) { | 143 if (find_bar_->IsFindBarVisible()) { |
| 140 if (content::PageTransitionStripQualifier(transition_type) != | 144 if (content::PageTransitionStripQualifier(transition_type) != |
| 141 content::PAGE_TRANSITION_RELOAD) { | 145 content::PAGE_TRANSITION_RELOAD) { |
| 142 EndFindSession(kKeepSelection); | 146 EndFindSession(kKeepSelection); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 // shown it is showing the right state for this tab. We update the find text | 235 // shown it is showing the right state for this tab. We update the find text |
| 232 // _first_ since the FindBarView checks its emptiness to see if it should | 236 // _first_ since the FindBarView checks its emptiness to see if it should |
| 233 // clear the result count display when there's nothing in the box. | 237 // clear the result count display when there's nothing in the box. |
| 234 find_bar_->SetFindText(find_string); | 238 find_bar_->SetFindText(find_string); |
| 235 #else | 239 #else |
| 236 // Having a per-tab find_string is not compatible with OS X's find pasteboard, | 240 // Having a per-tab find_string is not compatible with OS X's find pasteboard, |
| 237 // so we always have the same find text in all find bars. This is done through | 241 // so we always have the same find text in all find bars. This is done through |
| 238 // the find pasteboard mechanism, so don't set the text here. | 242 // the find pasteboard mechanism, so don't set the text here. |
| 239 #endif | 243 #endif |
| 240 } | 244 } |
| OLD | NEW |