summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-29 23:00:25 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-29 23:00:25 +0000
commitd46dccd915503b397f775bd5332e27c0b0a8e114 (patch)
tree4c70944cbec6417e4bbd7ca49ea0e191c3f132d2 /chrome/browser
parent25e08e4911b7f49ad7fbaa7bacbd45d601ad6dee (diff)
downloadchromium_src-d46dccd915503b397f775bd5332e27c0b0a8e114.zip
chromium_src-d46dccd915503b397f775bd5332e27c0b0a8e114.tar.gz
chromium_src-d46dccd915503b397f775bd5332e27c0b0a8e114.tar.bz2
GTK: move the findbar out of the way when it covers a find result.
BUG=15875 Review URL: http://codereview.chromium.org/160350 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22012 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/find_bar_controller.cc44
-rw-r--r--chrome/browser/find_bar_controller.h8
-rw-r--r--chrome/browser/gtk/find_bar_gtk.cc25
-rw-r--r--chrome/browser/gtk/find_bar_gtk.h4
-rw-r--r--chrome/browser/views/find_bar_win.cc38
5 files changed, 69 insertions, 50 deletions
diff --git a/chrome/browser/find_bar_controller.cc b/chrome/browser/find_bar_controller.cc
index 173cedc..4f8af9a 100644
--- a/chrome/browser/find_bar_controller.cc
+++ b/chrome/browser/find_bar_controller.cc
@@ -4,12 +4,16 @@
#include "chrome/browser/find_bar_controller.h"
+#include "app/l10n_util.h"
#include "build/build_config.h"
#include "chrome/browser/find_bar.h"
#include "chrome/browser/tab_contents/navigation_entry.h"
#include "chrome/common/notification_service.h"
#include "chrome/browser/tab_contents/tab_contents.h"
+// The minimum space between the FindInPage window and the search result.
+static const int kMinFindWndDistanceFromSelection = 5;
+
FindBarController::FindBarController(FindBar* find_bar)
: find_bar_(find_bar),
tab_contents_(NULL),
@@ -142,6 +146,46 @@ void FindBarController::Observe(NotificationType type,
}
}
+// static
+gfx::Rect FindBarController::GetLocationForFindbarView(
+ gfx::Rect view_location,
+ const gfx::Rect& dialog_bounds,
+ const gfx::Rect& avoid_overlapping_rect) {
+ if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) {
+ int boundary = dialog_bounds.width() - view_location.width();
+ view_location.set_x(std::min(view_location.x(), boundary));
+ } else {
+ view_location.set_x(std::max(view_location.x(), dialog_bounds.x()));
+ }
+
+ gfx::Rect new_pos = view_location;
+
+ // If the selection rectangle intersects the current position on screen then
+ // we try to move our dialog to the left (right for RTL) of the selection
+ // rectangle.
+ if (!avoid_overlapping_rect.IsEmpty() &&
+ avoid_overlapping_rect.Intersects(new_pos)) {
+ if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) {
+ new_pos.set_x(avoid_overlapping_rect.x() +
+ avoid_overlapping_rect.width() +
+ (2 * kMinFindWndDistanceFromSelection));
+
+ // If we moved it off-screen to the right, we won't move it at all.
+ if (new_pos.x() + new_pos.width() > dialog_bounds.width())
+ new_pos = view_location; // Reset.
+ } else {
+ new_pos.set_x(avoid_overlapping_rect.x() - new_pos.width() -
+ kMinFindWndDistanceFromSelection);
+
+ // If we moved it off-screen to the left, we won't move it at all.
+ if (new_pos.x() < 0)
+ new_pos = view_location; // Reset.
+ }
+ }
+
+ return new_pos;
+}
+
void FindBarController::UpdateFindBarForCurrentResult() {
const FindNotificationDetails& find_result = tab_contents_->find_result();
diff --git a/chrome/browser/find_bar_controller.h b/chrome/browser/find_bar_controller.h
index 82c1640..93c8185 100644
--- a/chrome/browser/find_bar_controller.h
+++ b/chrome/browser/find_bar_controller.h
@@ -6,6 +6,7 @@
#define CHROME_BROWSER_FIND_BAR_CONTROLLER_H_
#include "base/basictypes.h"
+#include "base/gfx/rect.h"
#include "base/scoped_ptr.h"
#include "chrome/common/notification_registrar.h"
@@ -39,6 +40,13 @@ class FindBarController : public NotificationObserver {
FindBar* find_bar() const { return find_bar_.get(); }
+ // Reposition |view_location| such that it avoids |avoid_overlapping_rect|,
+ // and return the new location.
+ static gfx::Rect GetLocationForFindbarView(
+ gfx::Rect view_location,
+ const gfx::Rect& dialog_bounds,
+ const gfx::Rect& avoid_overlapping_rect);
+
private:
// Sents an update to the find bar with the tab contents' current result. The
// tab_contents_ must be non-NULL before this call. Theis handles
diff --git a/chrome/browser/gtk/find_bar_gtk.cc b/chrome/browser/gtk/find_bar_gtk.cc
index 4436455..a0179d0 100644
--- a/chrome/browser/gtk/find_bar_gtk.cc
+++ b/chrome/browser/gtk/find_bar_gtk.cc
@@ -88,7 +88,8 @@ FindBarGtk::FindBarGtk(Browser* browser)
window_(static_cast<BrowserWindowGtk*>(browser->window())),
theme_provider_(GtkThemeProvider::GetFrom(browser->profile())),
container_shaped_(false),
- ignore_changed_signal_(false) {
+ ignore_changed_signal_(false),
+ current_fixed_width_(-1) {
InitWidgets();
dialog_background_.reset(new NineBox(browser->profile()->GetThemeProvider(),
@@ -356,15 +357,10 @@ gfx::Rect FindBarGtk::GetDialogPosition(gfx::Rect avoid_overlapping_rect) {
gfx::Rect view_location(
ltr ? dialog_bounds.width() - prefsize.width() : dialog_bounds.x(),
dialog_bounds.y(), prefsize.width(), prefsize.height());
+ gfx::Rect new_pos = FindBarController::GetLocationForFindbarView(
+ view_location, dialog_bounds, avoid_overlapping_rect);
- if (!avoid_overlapping_rect.IsEmpty()) {
- // TODO(estade): move out of the way if need be.
- }
-
- if (view_location.x() < 0)
- view_location.set_x(0);
-
- return view_location;
+ return new_pos;
}
void FindBarGtk::SetDialogPosition(const gfx::Rect& new_pos, bool no_redraw) {
@@ -512,17 +508,18 @@ void FindBarGtk::OnClicked(GtkWidget* button, FindBarGtk* find_bar) {
void FindBarGtk::OnFixedSizeAllocate(GtkWidget* fixed,
GtkAllocation* allocation,
FindBarGtk* findbar) {
+ // Do nothing if our width hasn't changed.
+ if (findbar->current_fixed_width_ == allocation->width)
+ return;
+ findbar->current_fixed_width_ = allocation->width;
+
// Set the background widget to the size of |fixed|.
gtk_widget_set_size_request(findbar->border_,
allocation->width, allocation->height);
// Reposition the dialog.
- GtkWidget* dialog = findbar->slide_widget();
- if (!GTK_WIDGET_VISIBLE(dialog))
- return;
-
int xposition = findbar->GetDialogPosition(gfx::Rect()).x();
- if (xposition == dialog->allocation.x) {
+ if (xposition == findbar->slide_widget()->allocation.x) {
return;
} else {
gtk_fixed_move(GTK_FIXED(fixed), findbar->slide_widget(), xposition, 0);
diff --git a/chrome/browser/gtk/find_bar_gtk.h b/chrome/browser/gtk/find_bar_gtk.h
index 81de33a..020b814 100644
--- a/chrome/browser/gtk/find_bar_gtk.h
+++ b/chrome/browser/gtk/find_bar_gtk.h
@@ -164,6 +164,10 @@ class FindBarGtk : public FindBar,
// If true, the change signal for the text entry is ignored.
bool ignore_changed_signal_;
+ // This is the width of widget(). We cache it so we can recognize whether
+ // allocate signals have changed it, and if so take appropriate actions.
+ int current_fixed_width_;
+
scoped_ptr<NineBox> dialog_background_;
DISALLOW_COPY_AND_ASSIGN(FindBarGtk);
diff --git a/chrome/browser/views/find_bar_win.cc b/chrome/browser/views/find_bar_win.cc
index fe78784..fd6680e 100644
--- a/chrome/browser/views/find_bar_win.cc
+++ b/chrome/browser/views/find_bar_win.cc
@@ -25,9 +25,6 @@
#include "views/widget/widget_gtk.h"
#endif
-// The minimum space between the FindInPage window and the search result.
-static const int kMinFindWndDistanceFromSelection = 5;
-
// static
bool FindBarWin::disable_animations_during_testing_ = false;
@@ -483,17 +480,6 @@ gfx::Rect FindBarWin::GetDialogPosition(gfx::Rect avoid_overlapping_rect) {
int y = dialog_bounds.y();
view_location.SetRect(x, y, prefsize.width(), prefsize.height());
- // Make sure we don't go out of bounds to the left (right in RTL) if the
- // window is too small to fit our dialog.
- if (view_->UILayoutIsRightToLeft()) {
- int boundary = dialog_bounds.width() - prefsize.width();
- view_location.set_x(std::min(view_location.x(), boundary));
- } else {
- view_location.set_x(std::max(view_location.x(), dialog_bounds.x()));
- }
-
- gfx::Rect new_pos = view_location;
-
// When we get Find results back, we specify a selection rect, which we
// should strive to avoid overlapping. But first, we need to offset the
// selection rect (if one was provided).
@@ -513,28 +499,8 @@ gfx::Rect FindBarWin::GetDialogPosition(gfx::Rect avoid_overlapping_rect) {
#endif
}
- // If the selection rectangle intersects the current position on screen then
- // we try to move our dialog to the left (right for RTL) of the selection
- // rectangle.
- if (!avoid_overlapping_rect.IsEmpty() &&
- avoid_overlapping_rect.Intersects(new_pos)) {
- if (view_->UILayoutIsRightToLeft()) {
- new_pos.set_x(avoid_overlapping_rect.x() +
- avoid_overlapping_rect.width() +
- (2 * kMinFindWndDistanceFromSelection));
-
- // If we moved it off-screen to the right, we won't move it at all.
- if (new_pos.x() + new_pos.width() > dialog_bounds.width())
- new_pos = view_location; // Reset.
- } else {
- new_pos.set_x(avoid_overlapping_rect.x() - new_pos.width() -
- kMinFindWndDistanceFromSelection);
-
- // If we moved it off-screen to the left, we won't move it at all.
- if (new_pos.x() < 0)
- new_pos = view_location; // Reset.
- }
- }
+ gfx::Rect new_pos = FindBarController::GetLocationForFindbarView(
+ view_location, dialog_bounds, avoid_overlapping_rect);
// While we are animating, the Find window will grow bottoms up so we need to
// re-position the dialog so that it appears to grow out of the toolbar.