summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-05 04:52:58 +0000
committerfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-05 04:52:58 +0000
commit4801ecc5ce684ec8556769cb173506b4645c618b (patch)
tree526495f64269f04390ff3ef7f313513495fc36e9 /chrome/browser
parent19e7dbd299d4b4281ade12550870b0cb15f0193d (diff)
downloadchromium_src-4801ecc5ce684ec8556769cb173506b4645c618b.zip
chromium_src-4801ecc5ce684ec8556769cb173506b4645c618b.tar.gz
chromium_src-4801ecc5ce684ec8556769cb173506b4645c618b.tar.bz2
Moving the Find bar ownership to the Browser object for portability and testability purposes.BUG=None.TEST=No new functionality, just moving stuff around and as such it is covered by pre-existing tests.
Review URL: http://codereview.chromium.org/60105 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13134 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/automation/automation_provider.cc26
-rw-r--r--chrome/browser/browser.cc25
-rw-r--r--chrome/browser/browser.h9
-rw-r--r--chrome/browser/browser_window.h18
-rw-r--r--chrome/browser/browser_window_factory.mm7
-rw-r--r--chrome/browser/find_bar.h35
-rw-r--r--chrome/browser/find_bar_controller.h4
-rw-r--r--chrome/browser/gtk/browser_window_gtk.cc2
-rw-r--r--chrome/browser/gtk/find_bar_gtk.cc15
-rw-r--r--chrome/browser/gtk/find_bar_gtk.h20
-rw-r--r--chrome/browser/views/find_bar_view.cc10
-rw-r--r--chrome/browser/views/find_bar_win.cc33
-rw-r--r--chrome/browser/views/find_bar_win.h35
-rw-r--r--chrome/browser/views/frame/browser_view.cc51
-rw-r--r--chrome/browser/views/frame/browser_view.h10
15 files changed, 178 insertions, 122 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc
index 24179f39..9a25046 100644
--- a/chrome/browser/automation/automation_provider.cc
+++ b/chrome/browser/automation/automation_provider.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -16,6 +16,8 @@
#include "chrome/browser/browser_window.h"
#include "chrome/browser/dom_operation_notification_details.h"
#include "chrome/browser/download/download_manager.h"
+#include "chrome/browser/find_bar.h"
+#include "chrome/browser/find_bar_controller.h"
#include "chrome/browser/find_notification_details.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/ssl/ssl_manager.h"
@@ -1959,33 +1961,23 @@ void AutomationProvider::GetFindWindowVisibility(int handle, bool* visible) {
gfx::Point position;
*visible = false;
if (browser_tracker_->ContainsHandle(handle)) {
-#if defined(OS_WIN)
Browser* browser = browser_tracker_->GetResource(handle);
- BrowserWindowTesting* testing =
- browser->window()->GetBrowserWindowTesting();
- testing->GetFindBarWindowInfo(&position, visible);
-#else
- // TODO(port): Depends on BrowserWindowTesting::GetFindBarWindowInfo.
- NOTIMPLEMENTED();
-#endif
+ FindBarTesting* find_bar =
+ browser->find_bar()->find_bar()->GetFindBarTesting();
+ find_bar->GetFindBarWindowInfo(&position, visible);
}
}
void AutomationProvider::HandleFindWindowLocationRequest(int handle, int* x,
int* y) {
gfx::Point position(0, 0);
-#if defined(OS_WIN)
bool visible = false;
if (browser_tracker_->ContainsHandle(handle)) {
Browser* browser = browser_tracker_->GetResource(handle);
- BrowserWindowTesting* testing =
- browser->window()->GetBrowserWindowTesting();
- testing->GetFindBarWindowInfo(&position, &visible);
+ FindBarTesting* find_bar =
+ browser->find_bar()->find_bar()->GetFindBarTesting();
+ find_bar->GetFindBarWindowInfo(&position, &visible);
}
-#else
- // TODO(port): Depends on BrowserWindowTesting::GetFindBarWindowInfo.
- NOTIMPLEMENTED();
-#endif
*x = position.x();
*y = position.y();
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index 16544fd..119c5aa 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -16,6 +16,8 @@
#include "chrome/browser/browser_window.h"
#include "chrome/browser/character_encoding.h"
#include "chrome/browser/debugger/devtools_manager.h"
+#include "chrome/browser/find_bar.h"
+#include "chrome/browser/find_bar_controller.h"
#include "chrome/browser/location_bar.h"
#include "chrome/browser/metrics/user_metrics.h"
#include "chrome/browser/net/url_fixer_upper.h"
@@ -279,6 +281,12 @@ void Browser::CreateBrowserWindow() {
local_state->ClearPref(prefs::kShouldShowFirstRunBubble);
window_->GetLocationBar()->ShowFirstRunBubble();
}
+
+#if defined(OS_WIN)
+ FindBar* find_bar = BrowserWindow::CreateFindBar(this);
+ find_bar_controller_.reset(new FindBarController(find_bar));
+ find_bar->SetFindBarController(find_bar_controller_.get());
+#endif
}
///////////////////////////////////////////////////////////////////////////////
@@ -779,6 +787,10 @@ void Browser::ViewSource() {
}
}
+void Browser::ShowFindBar() {
+ find_bar_controller_->Show();
+}
+
bool Browser::SupportsWindowFeature(WindowFeature feature) const {
unsigned int features = FEATURE_INFOBAR | FEATURE_DOWNLOADSHELF;
if (type() == TYPE_NORMAL)
@@ -1495,6 +1507,9 @@ void Browser::TabDetachedAt(TabContents* contents, int index) {
RemoveScheduledUpdatesFor(contents);
+ if (find_bar_controller_.get() && index == tabstrip_model_.selected_index())
+ find_bar_controller_->ChangeWebContents(NULL);
+
NotificationService::current()->RemoveObserver(
this,
NotificationType::WEB_CONTENTS_DISCONNECTED,
@@ -1539,6 +1554,12 @@ void Browser::TabSelectedAt(TabContents* old_contents,
status_bubble->SetStatus(GetSelectedTabContents()->GetStatusText());
}
+ if (find_bar_controller_.get()) {
+ find_bar_controller_->ChangeWebContents(new_contents->AsWebContents());
+ find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect(),
+ true);
+ }
+
// Update sessions. Don't force creation of sessions. If sessions doesn't
// exist, the change will be picked up by sessions when created.
if (profile_->HasSessionService()) {
@@ -2487,7 +2508,7 @@ GURL Browser::GetHomePage() const {
}
void Browser::FindInPage(bool find_next, bool forward_direction) {
- window_->ShowFindBar();
+ ShowFindBar();
if (find_next) {
GetSelectedTabContents()->AsWebContents()->StartFinding(
string16(),
diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h
index 48fceca..89fb4ef 100644
--- a/chrome/browser/browser.h
+++ b/chrome/browser/browser.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -37,6 +37,7 @@
class BrowserIdleTimer;
class BrowserWindow;
class DebuggerWindow;
+class FindBarController;
class GoButton;
class LocationBar;
class PrefService;
@@ -133,6 +134,7 @@ class Browser : public TabStripModelDelegate,
ToolbarModel* toolbar_model() { return &toolbar_model_; }
const SessionID& session_id() const { return session_id_; }
CommandUpdater* command_updater() { return &command_updater_; }
+ FindBarController* find_bar() { return find_bar_controller_.get(); }
// Setters /////////////////////////////////////////////////////////////////
@@ -277,6 +279,7 @@ class Browser : public TabStripModelDelegate,
void BookmarkCurrentPage();
void SavePage();
void ViewSource();
+ void ShowFindBar();
// Returns true if the Browser supports the specified feature.
bool SupportsWindowFeature(WindowFeature feature) const;
@@ -667,6 +670,10 @@ class Browser : public TabStripModelDelegate,
// The following factory is used to close the frame at a later time.
ScopedRunnableMethodFactory<Browser> method_factory_;
+ // The Find Bar. This may be NULL if there is no Find Bar, and if it is
+ // non-NULL, it may or may not be visible.
+ scoped_ptr<FindBarController> find_bar_controller_;
+
// Debugger Window, created lazily
scoped_refptr<DebuggerWindow> debugger_window_;
diff --git a/chrome/browser/browser_window.h b/chrome/browser/browser_window.h
index b6b6e12..50d3dda 100644
--- a/chrome/browser/browser_window.h
+++ b/chrome/browser/browser_window.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -10,6 +10,7 @@
class Browser;
class BrowserList;
class BrowserWindowTesting;
+class FindBar;
class GURL;
class LocationBar;
class HtmlDialogUIDelegate;
@@ -132,9 +133,6 @@ class BrowserWindow {
// Shows or hides the bookmark bar depending on its current visibility.
virtual void ToggleBookmarkBar() = 0;
- // Shows the Find Bar.
- virtual void ShowFindBar() = 0;
-
// Shows the About Chrome dialog box.
virtual void ShowAboutChromeDialog() = 0;
@@ -175,6 +173,9 @@ class BrowserWindow {
// Construct a BrowserWindow implementation for the specified |browser|.
static BrowserWindow* CreateBrowserWindow(Browser* browser);
+ // Construct a FindBar implementation for the specified |browser|.
+ static FindBar* CreateFindBar(Browser* browser_window);
+
protected:
friend class BrowserList;
friend class BrowserView;
@@ -194,15 +195,6 @@ class BrowserWindowTesting {
// Returns the LocationBarView.
virtual LocationBarView* GetLocationBarView() const = 0;
-
- // Computes the location of the find bar and whether it is fully visible in
- // its parent window. The return value indicates if the window is visible at
- // all. Both out arguments are required.
- //
- // This is used for UI tests of the find bar. If the find bar is not currently
- // shown (return value of false), the out params will be {(0, 0), false}.
- virtual bool GetFindBarWindowInfo(gfx::Point* position,
- bool* fully_visible) const = 0;
#endif
};
diff --git a/chrome/browser/browser_window_factory.mm b/chrome/browser/browser_window_factory.mm
index 0453169..33d0070 100644
--- a/chrome/browser/browser_window_factory.mm
+++ b/chrome/browser/browser_window_factory.mm
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/logging.h"
#include "chrome/browser/browser_window.h"
#include "chrome/browser/cocoa/browser_window_controller.h"
@@ -17,3 +18,9 @@ BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) {
[[BrowserWindowController alloc] initWithBrowser:browser];
return [controller browserWindow];
}
+
+// static
+FindBar* BrowserWindow::CreateFindBar(Browser* browser_window) {
+ NOTIMPLEMENTED();
+ return NULL;
+}
diff --git a/chrome/browser/find_bar.h b/chrome/browser/find_bar.h
index 4b4ee715..d0ebe3a 100644
--- a/chrome/browser/find_bar.h
+++ b/chrome/browser/find_bar.h
@@ -12,6 +12,8 @@
#include "base/gfx/rect.h"
#include "base/string16.h"
+class FindBarController;
+class FindBarTesting;
class FindNotificationDetails;
class WebContents;
@@ -19,6 +21,11 @@ class FindBar {
public:
virtual ~FindBar() { }
+ // Accessor and setter for the FindBarController.
+ virtual FindBarController* GetFindBarController() const = 0;
+ virtual void SetFindBarController(
+ FindBarController* find_bar_controller) = 0;
+
// Shows the find bar. Any previous search string will again be visible.
virtual void Show() = 0;
@@ -35,6 +42,16 @@ class FindBar {
// Stop the animation.
virtual void StopAnimation() = 0;
+ // If the find bar obscures the search results we need to move the window. To
+ // do that we need to know what is selected on the page. We simply calculate
+ // where it would be if we place it on the left of the selection and if it
+ // doesn't fit on the screen we try the right side. The parameter
+ // |selection_rect| is expected to have coordinates relative to the top of
+ // the web page area. If |no_redraw| is true, the window will be moved without
+ // redrawing siblings.
+ virtual void MoveWindowIfNecessary(const gfx::Rect& selection_rect,
+ bool no_redraw) = 0;
+
// Set the text in the find box.
virtual void SetFindText(const string16& find_text) = 0;
@@ -68,6 +85,24 @@ class FindBar {
// Upon dismissing the window, restore focus to the last focused view which is
// not FindBarView or any of its children.
virtual void RestoreSavedFocus() = 0;
+
+ // Returns a pointer to the testing interface to the FindBar, or NULL
+ // if there is none.
+ virtual FindBarTesting* GetFindBarTesting() = 0;
+};
+
+class FindBarTesting {
+ public:
+ virtual ~FindBarTesting() { }
+
+ // Computes the location of the find bar and whether it is fully visible in
+ // its parent window. The return value indicates if the window is visible at
+ // all. Both out arguments are required.
+ //
+ // This is used for UI tests of the find bar. If the find bar is not currently
+ // shown (return value of false), the out params will be {(0, 0), false}.
+ virtual bool GetFindBarWindowInfo(gfx::Point* position,
+ bool* fully_visible) = 0;
};
#endif // CHROME_BROWSER_FIND_BAR_H_
diff --git a/chrome/browser/find_bar_controller.h b/chrome/browser/find_bar_controller.h
index 7551239..5cdabda 100644
--- a/chrome/browser/find_bar_controller.h
+++ b/chrome/browser/find_bar_controller.h
@@ -15,7 +15,7 @@ class WebContents;
class FindBarController : public NotificationObserver {
public:
// FindBar takes ownership of |find_bar_view|.
- FindBarController(FindBar* find_bar);
+ explicit FindBarController(FindBar* find_bar);
virtual ~FindBarController();
@@ -37,7 +37,7 @@ class FindBarController : public NotificationObserver {
const NotificationSource& source,
const NotificationDetails& details);
- FindBar* get_find_bar() const { return find_bar_.get(); }
+ FindBar* find_bar() const { return find_bar_.get(); }
private:
scoped_ptr<FindBar> find_bar_;
diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc
index d4e0928..6bd4367 100644
--- a/chrome/browser/gtk/browser_window_gtk.cc
+++ b/chrome/browser/gtk/browser_window_gtk.cc
@@ -197,7 +197,7 @@ BrowserWindowGtk::BrowserWindowGtk(Browser* browser)
FindBarGtk* find_bar_gtk = new FindBarGtk();
find_bar_controller_.reset(new FindBarController(find_bar_gtk));
- find_bar_gtk->set_find_bar_controller(find_bar_controller_.get());
+ find_bar_gtk->SetFindBarController(find_bar_controller_.get());
contents_container_.reset(
new TabContentsContainerGtk(find_bar_gtk->widget()));
diff --git a/chrome/browser/gtk/find_bar_gtk.cc b/chrome/browser/gtk/find_bar_gtk.cc
index 2fdc9f85..6ad363d 100644
--- a/chrome/browser/gtk/find_bar_gtk.cc
+++ b/chrome/browser/gtk/find_bar_gtk.cc
@@ -129,6 +129,11 @@ void FindBarGtk::StopAnimation() {
// No animation yet, so do nothing.
}
+void FindBarGtk::MoveWindowIfNecessary(const gfx::Rect& selection_rect,
+ bool no_redraw) {
+ // Not moving the window on demand, so do nothing.
+}
+
void FindBarGtk::SetFindText(const string16& find_text) {
std::string find_text_utf8 = UTF16ToUTF8(find_text);
gtk_entry_set_text(GTK_ENTRY(find_text_), find_text_utf8.c_str());
@@ -152,6 +157,16 @@ bool FindBarGtk::IsFindBarVisible() {
void FindBarGtk::RestoreSavedFocus() {
}
+FindBarTesting* FindBarGtk::GetFindBarTesting() {
+ return this;
+}
+
+bool FindBarGtk::GetFindBarWindowInfo(gfx::Point* position,
+ bool* fully_visible) {
+ NOTIMPLEMENTED();
+ return false;
+}
+
void FindBarGtk::ContentsChanged() {
WebContents* web_contents = find_bar_controller_->web_contents();
if (!web_contents)
diff --git a/chrome/browser/gtk/find_bar_gtk.h b/chrome/browser/gtk/find_bar_gtk.h
index bf79d50..1dba7fb 100644
--- a/chrome/browser/gtk/find_bar_gtk.h
+++ b/chrome/browser/gtk/find_bar_gtk.h
@@ -19,15 +19,12 @@ class WebContents;
// Currently this class contains both a model and a view. We may want to
// eventually pull out the model specific bits and share with Windows.
-class FindBarGtk : public FindBar {
+class FindBarGtk : public FindBar,
+ public FindBarTesting {
public:
FindBarGtk();
virtual ~FindBarGtk();
- void set_find_bar_controller(FindBarController* find_bar_controller) {
- find_bar_controller_ = find_bar_controller;
- }
-
// Callback when the text in the find box changes.
void ContentsChanged();
@@ -37,11 +34,19 @@ class FindBarGtk : public FindBar {
GtkWidget* widget() const { return container_.get(); }
// Methods from FindBar.
+ virtual FindBarController* GetFindBarController() const {
+ return find_bar_controller_;
+ }
+ virtual void SetFindBarController(FindBarController* find_bar_controller) {
+ find_bar_controller_ = find_bar_controller;
+ }
virtual void Show();
virtual void Hide(bool animate);
virtual void SetFocusAndSelection();
virtual void ClearResults(const FindNotificationDetails& results);
virtual void StopAnimation();
+ virtual void MoveWindowIfNecessary(const gfx::Rect& selection_rect,
+ bool no_redraw);
virtual void SetFindText(const string16& find_text);
virtual void UpdateUIForFindResult(const FindNotificationDetails& result,
const string16& find_text);
@@ -49,6 +54,11 @@ class FindBarGtk : public FindBar {
virtual void SetDialogPosition(const gfx::Rect& new_pos, bool no_redraw);
virtual bool IsFindBarVisible();
virtual void RestoreSavedFocus();
+ virtual FindBarTesting* GetFindBarTesting();
+
+ // Methods from FindBarTesting.
+ virtual bool GetFindBarWindowInfo(gfx::Point* position,
+ bool* fully_visible);
private:
void InitWidgets();
diff --git a/chrome/browser/views/find_bar_view.cc b/chrome/browser/views/find_bar_view.cc
index 646b49c..bfaf958 100644
--- a/chrome/browser/views/find_bar_view.cc
+++ b/chrome/browser/views/find_bar_view.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -429,13 +429,13 @@ void FindBarView::ButtonPressed(views::Button* sender) {
case FIND_PREVIOUS_TAG:
case FIND_NEXT_TAG:
if (find_text_->GetText().length() > 0) {
- container_->find_bar_controller()->web_contents()->StartFinding(
+ container_->GetFindBarController()->web_contents()->StartFinding(
find_text_->GetText(),
sender->tag() == FIND_NEXT_TAG);
}
break;
case CLOSE_TAG:
- container_->find_bar_controller()->EndFindSession();
+ container_->GetFindBarController()->EndFindSession();
break;
default:
NOTREACHED() << L"Unknown button";
@@ -448,7 +448,7 @@ void FindBarView::ButtonPressed(views::Button* sender) {
void FindBarView::ContentsChanged(views::TextField* sender,
const std::wstring& new_contents) {
- FindBarController* controller = container_->find_bar_controller();
+ FindBarController* controller = container_->GetFindBarController();
DCHECK(controller);
// We must guard against a NULL web_contents, which can happen if the text
// in the Find box is changed right after the tab is destroyed. Otherwise, it
@@ -480,7 +480,7 @@ void FindBarView::HandleKeystroke(views::TextField* sender, UINT message,
std::wstring find_string = find_text_->GetText();
if (find_string.length() > 0) {
// Search forwards for enter, backwards for shift-enter.
- container_->find_bar_controller()->web_contents()->StartFinding(
+ container_->GetFindBarController()->web_contents()->StartFinding(
find_string,
GetKeyState(VK_SHIFT) >= 0);
}
diff --git a/chrome/browser/views/find_bar_win.cc b/chrome/browser/views/find_bar_win.cc
index 3a9fe05..5e1ed79 100644
--- a/chrome/browser/views/find_bar_win.cc
+++ b/chrome/browser/views/find_bar_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -220,8 +220,8 @@ void FindBarWin::MoveWindowIfNecessary(const gfx::Rect& selection_rect,
// We only move the window if one is active for the current WebContents. If we
// don't check this, then SetDialogPosition below will end up making the Find
// Bar visible.
- if (!find_bar_controller()->web_contents() ||
- !find_bar_controller()->web_contents()->find_ui_active()) {
+ if (!find_bar_controller_->web_contents() ||
+ !find_bar_controller_->web_contents()->find_ui_active()) {
return;
}
@@ -321,6 +321,25 @@ void FindBarWin::AnimationEnded(const Animation* animation) {
}
}
+////////////////////////////////////////////////////////////////////////////////
+// FindBarTesting implementation:
+
+bool FindBarWin::GetFindBarWindowInfo(gfx::Point* position,
+ bool* fully_visible) {
+ CRect window_rect;
+ if (!find_bar_controller_ ||
+ !::IsWindow(GetNativeView()) ||
+ !::GetWindowRect(GetNativeView(), &window_rect)) {
+ *position = gfx::Point(0, 0);
+ *fully_visible = false;
+ return false;
+ }
+
+ *position = gfx::Point(window_rect.TopLeft().x, window_rect.TopLeft().y);
+ *fully_visible = IsVisible() && !IsAnimating();
+ return true;
+}
+
void FindBarWin::GetDialogBounds(gfx::Rect* bounds) {
DCHECK(bounds);
// The BrowserView does Layout for the components that we care about
@@ -369,7 +388,7 @@ gfx::Rect FindBarWin::GetDialogPosition(gfx::Rect avoid_overlapping_rect) {
RECT frame_rect = {0}, webcontents_rect = {0};
::GetWindowRect(GetParent(), &frame_rect);
::GetWindowRect(
- find_bar_controller()->web_contents()->view()->GetNativeView(),
+ find_bar_controller_->web_contents()->view()->GetNativeView(),
&webcontents_rect);
avoid_overlapping_rect.Offset(0, webcontents_rect.top - frame_rect.top);
}
@@ -447,12 +466,16 @@ void FindBarWin::SetFocusChangeListener(HWND parent_hwnd) {
void FindBarWin::RestoreSavedFocus() {
if (focus_tracker_.get() == NULL) {
// TODO(brettw) Focus() should be on WebContentsView.
- find_bar_controller()->web_contents()->Focus();
+ find_bar_controller_->web_contents()->Focus();
} else {
focus_tracker_->FocusLastFocusedExternalView();
}
}
+FindBarTesting* FindBarWin::GetFindBarTesting() {
+ return this;
+}
+
void FindBarWin::RegisterEscAccelerator() {
views::Accelerator escape(VK_ESCAPE, false, false, false);
diff --git a/chrome/browser/views/find_bar_win.h b/chrome/browser/views/find_bar_win.h
index 99eb1cb..3fb4f75 100644
--- a/chrome/browser/views/find_bar_win.h
+++ b/chrome/browser/views/find_bar_win.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -40,29 +40,12 @@ class View;
class FindBarWin : public views::FocusChangeListener,
public views::WidgetWin,
public AnimationDelegate,
- public FindBar {
+ public FindBar,
+ public FindBarTesting {
public:
explicit FindBarWin(BrowserView* browser_view);
virtual ~FindBarWin();
- // Accessor for find_bar_controller so FindBarView can get back to
- // FindBarController.
- FindBarController* find_bar_controller() const {
- return find_bar_controller_;
- }
- void set_find_bar_controller(FindBarController* find_bar_controller) {
- find_bar_controller_ = find_bar_controller;
- }
-
- // If the find bar obscures the search results we need to move the window. To
- // do that we need to know what is selected on the page. We simply calculate
- // where it would be if we place it on the left of the selection and if it
- // doesn't fit on the screen we try the right side. The parameter
- // |selection_rect| is expected to have coordinates relative to the top of
- // the web page area. If |no_redraw| is true, the window will be moved without
- // redrawing siblings.
- void MoveWindowIfNecessary(const gfx::Rect& selection_rect, bool no_redraw);
-
// Moves the window according to the new window size.
void RespondToResize(const gfx::Size& new_size);
@@ -77,11 +60,19 @@ class FindBarWin : public views::FocusChangeListener,
void SetFocusChangeListener(HWND parent_hwnd);
// FindBar implementation:
+ virtual FindBarController* GetFindBarController() const {
+ return find_bar_controller_;
+ }
+ virtual void SetFindBarController(FindBarController* find_bar_controller) {
+ find_bar_controller_ = find_bar_controller;
+ }
virtual void Show();
virtual void Hide(bool animate);
virtual void SetFocusAndSelection();
virtual void ClearResults(const FindNotificationDetails& results);
virtual void StopAnimation();
+ virtual void MoveWindowIfNecessary(const gfx::Rect& selection_rect,
+ bool no_redraw);
virtual void SetFindText(const string16& find_text);
virtual void UpdateUIForFindResult(const FindNotificationDetails& result,
const string16& find_text);
@@ -89,6 +80,7 @@ class FindBarWin : public views::FocusChangeListener,
virtual void SetDialogPosition(const gfx::Rect& new_pos, bool no_redraw);
virtual bool IsFindBarVisible();
virtual void RestoreSavedFocus();
+ virtual FindBarTesting* GetFindBarTesting();
// Overridden from views::WidgetWin:
virtual void OnFinalMessage(HWND window);
@@ -104,6 +96,9 @@ class FindBarWin : public views::FocusChangeListener,
virtual void AnimationProgressed(const Animation* animation);
virtual void AnimationEnded(const Animation* animation);
+ // FindBarTesting implementation:
+ virtual bool GetFindBarWindowInfo(gfx::Point* position,
+ bool* fully_visible);
private:
// Retrieves the boundaries that the find bar has to work with within the
// Chrome frame window. The resulting rectangle will be a rectangle that
diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc
index f5341d6..be51672 100644
--- a/chrome/browser/views/frame/browser_view.cc
+++ b/chrome/browser/views/frame/browser_view.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -735,10 +735,6 @@ void BrowserView::ToggleBookmarkBar() {
bookmark_utils::ToggleWhenVisible(browser_->profile());
}
-void BrowserView::ShowFindBar() {
- find_bar_controller_->Show();
-}
-
void BrowserView::ShowAboutChromeDialog() {
views::Window::CreateChromeWindow(
GetWidget()->GetNativeView(), gfx::Rect(),
@@ -845,29 +841,6 @@ LocationBarView* BrowserView::GetLocationBarView() const {
return toolbar_->GetLocationBarView();
}
-bool BrowserView::GetFindBarWindowInfo(gfx::Point* position,
- bool* fully_visible) const {
- FindBarWin* find_bar_win = NULL;
- if (find_bar_controller_.get()) {
- find_bar_win = static_cast<FindBarWin*>(
- find_bar_controller_->get_find_bar());
- DCHECK(find_bar_win);
- }
-
- CRect window_rect;
- if (!find_bar_controller_.get() ||
- !::IsWindow(find_bar_win->GetNativeView()) ||
- !::GetWindowRect(find_bar_win->GetNativeView(), &window_rect)) {
- *position = gfx::Point(0, 0);
- *fully_visible = false;
- return false;
- }
-
- *position = gfx::Point(window_rect.TopLeft().x, window_rect.TopLeft().y);
- *fully_visible = find_bar_win->IsVisible() && !find_bar_win->IsAnimating();
- return true;
-}
-
///////////////////////////////////////////////////////////////////////////////
// BrowserView, NotificationObserver implementation:
@@ -896,10 +869,6 @@ void BrowserView::TabDetachedAt(TabContents* contents, int index) {
// on the selected TabContents when it is removed.
infobar_container_->ChangeTabContents(NULL);
contents_container_->SetTabContents(NULL);
- // When dragging the last TabContents out of a window there is no selection
- // notification that causes the find bar for that window to be un-registered
- // for notifications from this TabContents.
- find_bar_controller_->ChangeWebContents(NULL);
}
}
@@ -936,9 +905,6 @@ void BrowserView::TabSelectedAt(TabContents* old_contents,
toolbar_->SetProfile(new_contents->profile());
UpdateToolbar(new_contents, true);
UpdateUIForContents(new_contents);
-
- if (find_bar_controller_.get())
- find_bar_controller_->ChangeWebContents(new_contents->AsWebContents());
}
void BrowserView::TabStripEmpty() {
@@ -1202,8 +1168,9 @@ void BrowserView::Layout() {
// back into us to find the bounding box the find bar must be laid out within,
// and that code depends on the TabContentsContainer's bounds being up to
// date.
- static_cast<FindBarWin*>(find_bar_controller_->get_find_bar())->
- MoveWindowIfNecessary(gfx::Rect(), true);
+ FindBarController* find_controller = browser_->find_bar();
+ if (find_controller)
+ find_controller->find_bar()->MoveWindowIfNecessary(gfx::Rect(), true);
LayoutStatusBubble(bottom);
#ifdef CHROME_PERSONALIZATION
if (IsPersonalizationEnabled()) {
@@ -1254,11 +1221,6 @@ void BrowserView::Init() {
infobar_container_ = new InfoBarContainer(this);
AddChildView(infobar_container_);
- FindBarWin* find_bar_win = new FindBarWin(this);
-
- find_bar_controller_.reset(new FindBarController(find_bar_win));
- find_bar_win->set_find_bar_controller(find_bar_controller_.get());
-
contents_container_ = new TabContentsContainerView;
set_contents_view(contents_container_);
AddChildView(contents_container_);
@@ -1638,3 +1600,8 @@ BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) {
(new BrowserFrame(browser_view))->Init();
return browser_view;
}
+
+// static
+FindBar* BrowserWindow::CreateFindBar(Browser* browser) {
+ return new FindBarWin(static_cast<BrowserView*>(browser->window()));
+}
diff --git a/chrome/browser/views/frame/browser_view.h b/chrome/browser/views/frame/browser_view.h
index d23b76d..c7f0c33 100644
--- a/chrome/browser/views/frame/browser_view.h
+++ b/chrome/browser/views/frame/browser_view.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -24,7 +24,6 @@ class BookmarkBarView;
class Browser;
class BrowserToolbarView;
class EncodingMenuControllerDelegate;
-class FindBarController;
class FullscreenExitBubble;
class HtmlDialogUIDelegate;
class InfoBarContainer;
@@ -190,7 +189,6 @@ class BrowserView : public BrowserWindow,
virtual gfx::Rect GetRootWindowResizerRect() const;
virtual void DisableInactiveFrame();
virtual void ToggleBookmarkBar();
- virtual void ShowFindBar();
virtual void ShowAboutChromeDialog();
virtual void ShowBookmarkManager();
virtual void ShowBookmarkBubble(const GURL& url, bool already_bookmarked);
@@ -203,8 +201,6 @@ class BrowserView : public BrowserWindow,
virtual void ShowNewProfileDialog();
virtual void ShowHTMLDialog(HtmlDialogUIDelegate* delegate,
void* parent_window);
- virtual bool GetFindBarWindowInfo(gfx::Point* position,
- bool* fully_visible) const;
// Overridden from BrowserWindowTesting:
virtual BookmarkBarView* GetBookmarkBarView() const;
@@ -373,10 +369,6 @@ class BrowserView : public BrowserWindow,
// The InfoBarContainer that contains InfoBars for the current tab.
InfoBarContainer* infobar_container_;
- // The Find Bar. This may be NULL if there is no Find Bar, and if it is
- // non-NULL, it may or may not be visible.
- scoped_ptr<FindBarController> find_bar_controller_;
-
// The distance the FindBar is from the top of the window, in pixels.
int find_bar_y_;