diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-29 23:00:25 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-29 23:00:25 +0000 |
commit | d46dccd915503b397f775bd5332e27c0b0a8e114 (patch) | |
tree | 4c70944cbec6417e4bbd7ca49ea0e191c3f132d2 /chrome/browser/find_bar_controller.cc | |
parent | 25e08e4911b7f49ad7fbaa7bacbd45d601ad6dee (diff) | |
download | chromium_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/find_bar_controller.cc')
-rw-r--r-- | chrome/browser/find_bar_controller.cc | 44 |
1 files changed, 44 insertions, 0 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(); |