Commit f0fa8872 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Move FindBarController::GetLocationForFindbarView to find_bar_host.cc

This is the only place it's used, and it's view-specific logic so it
belongs closer to the view.

Bug: 1038415
Change-Id: I10bedda65753cff0b883efdff072afc683a7bc7b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1989884
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#730004}
parent 97b03b1c
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include <algorithm> #include <algorithm>
#include "base/i18n/rtl.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/no_destructor.h" #include "base/no_destructor.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
...@@ -25,19 +24,11 @@ ...@@ -25,19 +24,11 @@
#include "content/public/browser/notification_types.h" #include "content/public/browser/notification_types.h"
#include "content/public/browser/render_widget_host_view.h" #include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/range/range.h" #include "ui/gfx/range/range.h"
using content::NavigationController; using content::NavigationController;
using content::WebContents; using content::WebContents;
namespace {
// The minimum space between the FindInPage window and the search result.
constexpr int kMinFindWndDistanceFromSelection = 5;
} // namespace
FindBarController::FindBarController(std::unique_ptr<FindBar> find_bar, FindBarController::FindBarController(std::unique_ptr<FindBar> find_bar,
Browser* browser) Browser* browser)
: find_bar_(std::move(find_bar)), : find_bar_(std::move(find_bar)),
...@@ -196,46 +187,6 @@ void FindBarController::Observe(int type, ...@@ -196,46 +187,6 @@ void FindBarController::Observe(int type,
} }
} }
// static
gfx::Rect FindBarController::GetLocationForFindbarView(
gfx::Rect view_location,
const gfx::Rect& dialog_bounds,
const gfx::Rect& avoid_overlapping_rect) {
if (base::i18n::IsRTL()) {
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 (base::i18n::IsRTL()) {
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::OnFindResultAvailable( void FindBarController::OnFindResultAvailable(
content::WebContents* web_contents) { content::WebContents* web_contents) {
DCHECK_EQ(web_contents, web_contents_); DCHECK_EQ(web_contents, web_contents_);
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <algorithm> #include <algorithm>
#include "base/i18n/rtl.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/ui/find_bar/find_bar_controller.h" #include "chrome/browser/ui/find_bar/find_bar_controller.h"
#include "chrome/browser/ui/find_bar/find_tab_helper.h" #include "chrome/browser/ui/find_bar/find_tab_helper.h"
...@@ -21,6 +22,7 @@ ...@@ -21,6 +22,7 @@
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/events/event.h" #include "ui/events/event.h"
#include "ui/events/keycodes/keyboard_codes.h" #include "ui/events/keycodes/keyboard_codes.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/views/border.h" #include "ui/views/border.h"
#include "ui/views/focus/external_focus_tracker.h" #include "ui/views/focus/external_focus_tracker.h"
#include "ui/views/widget/root_view.h" #include "ui/views/widget/root_view.h"
...@@ -29,6 +31,51 @@ ...@@ -29,6 +31,51 @@
using content::NativeWebKeyboardEvent; using content::NativeWebKeyboardEvent;
namespace {
gfx::Rect GetLocationForFindBarView(gfx::Rect view_location,
const gfx::Rect& dialog_bounds,
const gfx::Rect& avoid_overlapping_rect) {
if (base::i18n::IsRTL()) {
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;
// The minimum space between the FindInPage window and the search result.
constexpr int kMinFindWndDistanceFromSelection = 5;
// 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 (base::i18n::IsRTL()) {
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;
}
} // namespace
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// FindBarHost, public: // FindBarHost, public:
...@@ -285,10 +332,8 @@ gfx::Rect FindBarHost::GetDialogPosition(gfx::Rect avoid_overlapping_rect) { ...@@ -285,10 +332,8 @@ gfx::Rect FindBarHost::GetDialogPosition(gfx::Rect avoid_overlapping_rect) {
GetWidgetPositionNative(&avoid_overlapping_rect); GetWidgetPositionNative(&avoid_overlapping_rect);
} }
gfx::Rect new_pos = FindBarController::GetLocationForFindbarView( return GetLocationForFindBarView(view_location, widget_bounds,
view_location, widget_bounds, avoid_overlapping_rect); avoid_overlapping_rect);
return new_pos;
} }
void FindBarHost::SetDialogPosition(const gfx::Rect& new_pos) { void FindBarHost::SetDialogPosition(const gfx::Rect& new_pos) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment