summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/views/find_bar_host.cc165
-rw-r--r--chrome/browser/views/find_bar_host.h8
2 files changed, 91 insertions, 82 deletions
diff --git a/chrome/browser/views/find_bar_host.cc b/chrome/browser/views/find_bar_host.cc
index 3dc26a3..26a0db0 100644
--- a/chrome/browser/views/find_bar_host.cc
+++ b/chrome/browser/views/find_bar_host.cc
@@ -40,18 +40,62 @@ FindBarHost::FindBarHost(BrowserView* browser_view)
FindBarHost::~FindBarHost() {
}
-void FindBarHost::Show(bool animate) {
- DropdownBarHost::Show(animate);
+bool FindBarHost::MaybeForwardKeystrokeToWebpage(
+ const views::Textfield::Keystroke& key_stroke) {
+ if (!ShouldForwardKeystrokeToWebpageNative(key_stroke)) {
+ // Native implementation says not to forward these events.
+ return false;
+ }
+
+ switch (key_stroke.GetKeyboardCode()) {
+ case base::VKEY_DOWN:
+ case base::VKEY_UP:
+ case base::VKEY_PRIOR:
+ case base::VKEY_NEXT:
+ break;
+ case base::VKEY_HOME:
+ case base::VKEY_END:
+ if (key_stroke.IsControlHeld())
+ break;
+ // Fall through.
+ default:
+ return false;
+ }
+
+ TabContents* contents = find_bar_controller_->tab_contents();
+ if (!contents)
+ return false;
+
+ RenderViewHost* render_view_host = contents->render_view_host();
+
+ // Make sure we don't have a text field element interfering with keyboard
+ // input. Otherwise Up and Down arrow key strokes get eaten. "Nom Nom Nom".
+ render_view_host->ClearFocusedNode();
+ NativeWebKeyboardEvent event = GetKeyboardEvent(contents, key_stroke);
+ render_view_host->ForwardKeyboardEvent(event);
+ return true;
}
-void FindBarHost::SetFocusAndSelection() {
- DropdownBarHost::SetFocusAndSelection();
+FindBarController* FindBarHost::GetFindBarController() const {
+ return find_bar_controller_;
+}
+
+void FindBarHost::SetFindBarController(FindBarController* find_bar_controller) {
+ find_bar_controller_ = find_bar_controller;
+}
+
+void FindBarHost::Show(bool animate) {
+ DropdownBarHost::Show(animate);
}
void FindBarHost::Hide(bool animate) {
DropdownBarHost::Hide(animate);
}
+void FindBarHost::SetFocusAndSelection() {
+ DropdownBarHost::SetFocusAndSelection();
+}
+
void FindBarHost::ClearResults(const FindNotificationDetails& results) {
find_bar_view()->UpdateForResult(results, string16());
}
@@ -60,14 +104,6 @@ void FindBarHost::StopAnimation() {
DropdownBarHost::StopAnimation();
}
-void FindBarHost::SetFindText(const string16& find_text) {
- find_bar_view()->SetFindText(find_text);
-}
-
-bool FindBarHost::IsFindBarVisible() {
- return DropdownBarHost::IsVisible();
-}
-
void FindBarHost::MoveWindowIfNecessary(const gfx::Rect& selection_rect,
bool no_redraw) {
// We only move the window if one is active for the current TabContents. If we
@@ -85,6 +121,42 @@ void FindBarHost::MoveWindowIfNecessary(const gfx::Rect& selection_rect,
view()->SchedulePaint();
}
+void FindBarHost::SetFindText(const string16& find_text) {
+ find_bar_view()->SetFindText(find_text);
+}
+
+void FindBarHost::UpdateUIForFindResult(const FindNotificationDetails& result,
+ const string16& find_text) {
+ if (!find_text.empty())
+ find_bar_view()->UpdateForResult(result, find_text);
+
+ // We now need to check if the window is obscuring the search results.
+ if (!result.selection_rect().IsEmpty())
+ MoveWindowIfNecessary(result.selection_rect(), false);
+
+ // Once we find a match we no longer want to keep track of what had
+ // focus. EndFindSession will then set the focus to the page content.
+ if (result.number_of_matches() > 0)
+ ResetFocusTracker();
+}
+
+bool FindBarHost::IsFindBarVisible() {
+ return DropdownBarHost::IsVisible();
+}
+
+void FindBarHost::RestoreSavedFocus() {
+ if (focus_tracker() == NULL) {
+ // TODO(brettw) Focus() should be on TabContentsView.
+ find_bar_controller_->tab_contents()->Focus();
+ } else {
+ focus_tracker()->FocusLastFocusedExternalView();
+ }
+}
+
+FindBarTesting* FindBarHost::GetFindBarTesting() {
+ return this;
+}
+
////////////////////////////////////////////////////////////////////////////////
// FindBarWin, views::AcceleratorTarget implementation:
@@ -139,6 +211,9 @@ string16 FindBarHost::GetFindText() {
return find_bar_view()->GetFindText();
}
+////////////////////////////////////////////////////////////////////////////////
+// Overridden from DropdownBarHost:
+
gfx::Rect FindBarHost::GetDialogPosition(gfx::Rect avoid_overlapping_rect) {
// Find the area we have to work with (after accounting for scrollbars, etc).
gfx::Rect widget_bounds;
@@ -213,70 +288,8 @@ void FindBarHost::UnregisterAccelerators() {
DropdownBarHost::UnregisterAccelerators();
}
-void FindBarHost::RestoreSavedFocus() {
- if (focus_tracker() == NULL) {
- // TODO(brettw) Focus() should be on TabContentsView.
- find_bar_controller_->tab_contents()->Focus();
- } else {
- focus_tracker()->FocusLastFocusedExternalView();
- }
-}
-
-FindBarTesting* FindBarHost::GetFindBarTesting() {
- return this;
-}
-
-void FindBarHost::UpdateUIForFindResult(const FindNotificationDetails& result,
- const string16& find_text) {
- if (!find_text.empty())
- find_bar_view()->UpdateForResult(result, find_text);
-
- // We now need to check if the window is obscuring the search results.
- if (!result.selection_rect().IsEmpty())
- MoveWindowIfNecessary(result.selection_rect(), false);
-
- // Once we find a match we no longer want to keep track of what had
- // focus. EndFindSession will then set the focus to the page content.
- if (result.number_of_matches() > 0)
- ResetFocusTracker();
-}
-
-
-bool FindBarHost::MaybeForwardKeystrokeToWebpage(
- const views::Textfield::Keystroke& key_stroke) {
- if (!ShouldForwardKeystrokeToWebpageNative(key_stroke)) {
- // Native implementation says not to forward these events.
- return false;
- }
-
- switch (key_stroke.GetKeyboardCode()) {
- case base::VKEY_DOWN:
- case base::VKEY_UP:
- case base::VKEY_PRIOR:
- case base::VKEY_NEXT:
- break;
- case base::VKEY_HOME:
- case base::VKEY_END:
- if (key_stroke.IsControlHeld())
- break;
- // Fall through.
- default:
- return false;
- }
-
- TabContents* contents = find_bar_controller_->tab_contents();
- if (!contents)
- return false;
-
- RenderViewHost* render_view_host = contents->render_view_host();
-
- // Make sure we don't have a text field element interfering with keyboard
- // input. Otherwise Up and Down arrow key strokes get eaten. "Nom Nom Nom".
- render_view_host->ClearFocusedNode();
- NativeWebKeyboardEvent event = GetKeyboardEvent(contents, key_stroke);
- render_view_host->ForwardKeyboardEvent(event);
- return true;
-}
+////////////////////////////////////////////////////////////////////////////////
+// private:
FindBarView* FindBarHost::find_bar_view() {
return static_cast<FindBarView*>(view());
diff --git a/chrome/browser/views/find_bar_host.h b/chrome/browser/views/find_bar_host.h
index f611596..d675b3c8 100644
--- a/chrome/browser/views/find_bar_host.h
+++ b/chrome/browser/views/find_bar_host.h
@@ -48,12 +48,8 @@ class FindBarHost : public DropdownBarHost,
const views::Textfield::Keystroke& key_stroke);
// FindBar implementation:
- virtual FindBarController* GetFindBarController() const {
- return find_bar_controller_;
- }
- virtual void SetFindBarController(FindBarController* find_bar_controller) {
- find_bar_controller_ = find_bar_controller;
- }
+ virtual FindBarController* GetFindBarController() const;
+ virtual void SetFindBarController(FindBarController* find_bar_controller);
virtual void Show(bool animate);
virtual void Hide(bool animate);
virtual void SetFocusAndSelection();