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_entry.h" | 16 #include "content/browser/tab_contents/navigation_entry.h" |
17 #include "content/browser/tab_contents/tab_contents.h" | 17 #include "content/browser/tab_contents/tab_contents.h" |
18 #include "content/public/browser/navigation_details.h" | 18 #include "content/public/browser/navigation_details.h" |
19 #include "content/public/browser/notification_details.h" | 19 #include "content/public/browser/notification_details.h" |
20 #include "content/public/browser/notification_source.h" | 20 #include "content/public/browser/notification_source.h" |
21 #include "ui/gfx/rect.h" | 21 #include "ui/gfx/rect.h" |
22 | 22 |
| 23 using content::WebContents; |
| 24 |
23 // The minimum space between the FindInPage window and the search result. | 25 // The minimum space between the FindInPage window and the search result. |
24 static const int kMinFindWndDistanceFromSelection = 5; | 26 static const int kMinFindWndDistanceFromSelection = 5; |
25 | 27 |
26 FindBarController::FindBarController(FindBar* find_bar) | 28 FindBarController::FindBarController(FindBar* find_bar) |
27 : find_bar_(find_bar), | 29 : find_bar_(find_bar), |
28 tab_contents_(NULL), | 30 tab_contents_(NULL), |
29 last_reported_matchcount_(0) { | 31 last_reported_matchcount_(0) { |
30 } | 32 } |
31 | 33 |
32 FindBarController::~FindBarController() { | 34 FindBarController::~FindBarController() { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 if (find_bar_->IsFindBarVisible() && | 83 if (find_bar_->IsFindBarVisible() && |
82 (!tab_contents_ || !tab_contents_->find_tab_helper()->find_ui_active())) { | 84 (!tab_contents_ || !tab_contents_->find_tab_helper()->find_ui_active())) { |
83 find_bar_->Hide(false); | 85 find_bar_->Hide(false); |
84 } | 86 } |
85 | 87 |
86 if (!tab_contents_) | 88 if (!tab_contents_) |
87 return; | 89 return; |
88 | 90 |
89 registrar_.Add(this, | 91 registrar_.Add(this, |
90 chrome::NOTIFICATION_FIND_RESULT_AVAILABLE, | 92 chrome::NOTIFICATION_FIND_RESULT_AVAILABLE, |
91 content::Source<TabContents>(tab_contents_->tab_contents())); | 93 content::Source<WebContents>(tab_contents_->tab_contents())); |
92 registrar_.Add( | 94 registrar_.Add( |
93 this, | 95 this, |
94 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 96 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
95 content::Source<NavigationController>( | 97 content::Source<NavigationController>( |
96 &tab_contents_->tab_contents()->GetController())); | 98 &tab_contents_->tab_contents()->GetController())); |
97 | 99 |
98 MaybeSetPrepopulateText(); | 100 MaybeSetPrepopulateText(); |
99 | 101 |
100 if (tab_contents_->find_tab_helper()->find_ui_active()) { | 102 if (tab_contents_->find_tab_helper()->find_ui_active()) { |
101 // A tab with a visible find bar just got selected and we need to show the | 103 // A tab with a visible find bar just got selected and we need to show the |
(...skipping 10 matching lines...) Expand all Loading... |
112 //////////////////////////////////////////////////////////////////////////////// | 114 //////////////////////////////////////////////////////////////////////////////// |
113 // FindBarHost, content::NotificationObserver implementation: | 115 // FindBarHost, content::NotificationObserver implementation: |
114 | 116 |
115 void FindBarController::Observe(int type, | 117 void FindBarController::Observe(int type, |
116 const content::NotificationSource& source, | 118 const content::NotificationSource& source, |
117 const content::NotificationDetails& details) { | 119 const content::NotificationDetails& details) { |
118 FindTabHelper* find_tab_helper = tab_contents_->find_tab_helper(); | 120 FindTabHelper* find_tab_helper = tab_contents_->find_tab_helper(); |
119 if (type == chrome::NOTIFICATION_FIND_RESULT_AVAILABLE) { | 121 if (type == chrome::NOTIFICATION_FIND_RESULT_AVAILABLE) { |
120 // Don't update for notifications from TabContentses other than the one we | 122 // Don't update for notifications from TabContentses other than the one we |
121 // are actively tracking. | 123 // are actively tracking. |
122 if (content::Source<TabContents>(source).ptr() == | 124 if (content::Source<WebContents>(source).ptr() == |
123 tab_contents_->tab_contents()) { | 125 tab_contents_->tab_contents()) { |
124 UpdateFindBarForCurrentResult(); | 126 UpdateFindBarForCurrentResult(); |
125 if (find_tab_helper->find_result().final_update() && | 127 if (find_tab_helper->find_result().final_update() && |
126 find_tab_helper->find_result().number_of_matches() == 0) { | 128 find_tab_helper->find_result().number_of_matches() == 0) { |
127 const string16& last_search = find_tab_helper->previous_find_text(); | 129 const string16& last_search = find_tab_helper->previous_find_text(); |
128 const string16& current_search = find_tab_helper->find_text(); | 130 const string16& current_search = find_tab_helper->find_text(); |
129 if (last_search.find(current_search) != 0) | 131 if (last_search.find(current_search) != 0) |
130 find_bar_->AudibleAlert(); | 132 find_bar_->AudibleAlert(); |
131 } | 133 } |
132 } | 134 } |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 // shown it is showing the right state for this tab. We update the find text | 237 // shown it is showing the right state for this tab. We update the find text |
236 // _first_ since the FindBarView checks its emptiness to see if it should | 238 // _first_ since the FindBarView checks its emptiness to see if it should |
237 // clear the result count display when there's nothing in the box. | 239 // clear the result count display when there's nothing in the box. |
238 find_bar_->SetFindText(find_string); | 240 find_bar_->SetFindText(find_string); |
239 #else | 241 #else |
240 // Having a per-tab find_string is not compatible with OS X's find pasteboard, | 242 // Having a per-tab find_string is not compatible with OS X's find pasteboard, |
241 // so we always have the same find text in all find bars. This is done through | 243 // so we always have the same find text in all find bars. This is done through |
242 // the find pasteboard mechanism, so don't set the text here. | 244 // the find pasteboard mechanism, so don't set the text here. |
243 #endif | 245 #endif |
244 } | 246 } |
OLD | NEW |