Commit 623ed3c9 authored by Thomas Lukaszewicz's avatar Thomas Lukaszewicz Committed by Commit Bot

Added default param call find bar's MoveWindowIfNecessary method

Updated the find bar interface to specify a MoveWindowIfNecessary
method without the need for an explicit selection_rect if not necessary
given the context of the method call.

Bug: 871419
Change-Id: Ia7dae9a1517a17fc0649885deca4aa223461b81a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1880076
Commit-Queue: Thomas Lukaszewicz <tluk@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709662}
parent 355b6bf0
...@@ -641,7 +641,7 @@ FindBarController* Browser::GetFindBarController() { ...@@ -641,7 +641,7 @@ FindBarController* Browser::GetFindBarController() {
find_bar_controller_.get()); find_bar_controller_.get());
find_bar_controller_->ChangeWebContents( find_bar_controller_->ChangeWebContents(
tab_strip_model_->GetActiveWebContents()); tab_strip_model_->GetActiveWebContents());
find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect()); find_bar_controller_->find_bar()->MoveWindowIfNecessary();
} }
return find_bar_controller_.get(); return find_bar_controller_.get();
} }
...@@ -2244,7 +2244,7 @@ void Browser::OnActiveTabChanged(WebContents* old_contents, ...@@ -2244,7 +2244,7 @@ void Browser::OnActiveTabChanged(WebContents* old_contents,
if (HasFindBarController()) { if (HasFindBarController()) {
find_bar_controller_->ChangeWebContents(new_contents); find_bar_controller_->ChangeWebContents(new_contents);
find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect()); find_bar_controller_->find_bar()->MoveWindowIfNecessary();
} }
// Update sessions (selected tab index and last active time). Don't force // Update sessions (selected tab index and last active time). Don't force
......
...@@ -46,13 +46,9 @@ class FindBar { ...@@ -46,13 +46,9 @@ class FindBar {
// Stop the animation. // Stop the animation.
virtual void StopAnimation() = 0; virtual void StopAnimation() = 0;
// If the find bar obscures the search results we need to move the window. To // Repaints and lays out the find bar window relative to the view layout state
// do that we need to know what is selected on the page. We simply calculate // of the current browser window.
// where it would be if we place it on the left of the selection and if it virtual void MoveWindowIfNecessary() = 0;
// 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.
virtual void MoveWindowIfNecessary(const gfx::Rect& selection_rect) = 0;
// Set the text in the find box. // Set the text in the find box.
virtual void SetFindTextAndSelectedRange( virtual void SetFindTextAndSelectedRange(
......
...@@ -102,24 +102,8 @@ void FindBarHost::StopAnimation() { ...@@ -102,24 +102,8 @@ void FindBarHost::StopAnimation() {
DropdownBarHost::StopAnimation(); DropdownBarHost::StopAnimation();
} }
void FindBarHost::MoveWindowIfNecessary(const gfx::Rect& selection_rect) { void FindBarHost::MoveWindowIfNecessary() {
// We only move the window if one is active for the current WebContents. If we MoveWindowIfNecessaryWithRect(gfx::Rect());
// don't check this, then SetDialogPosition below will end up making the Find
// Bar visible.
content::WebContents* web_contents = find_bar_controller_->web_contents();
if (!web_contents)
return;
FindTabHelper* find_tab_helper = FindTabHelper::FromWebContents(web_contents);
if (!find_tab_helper || !find_tab_helper->find_ui_active())
return;
gfx::Rect new_pos = GetDialogPosition(selection_rect);
SetDialogPosition(new_pos);
// May need to redraw our frame to accommodate bookmark bar styles.
view()->Layout(); // Bounds may have changed.
view()->SchedulePaint();
} }
void FindBarHost::SetFindTextAndSelectedRange( void FindBarHost::SetFindTextAndSelectedRange(
...@@ -144,7 +128,7 @@ void FindBarHost::UpdateUIForFindResult(const FindNotificationDetails& result, ...@@ -144,7 +128,7 @@ void FindBarHost::UpdateUIForFindResult(const FindNotificationDetails& result,
find_bar_view()->ClearMatchCount(); find_bar_view()->ClearMatchCount();
// We now need to check if the window is obscuring the search results. // We now need to check if the window is obscuring the search results.
MoveWindowIfNecessary(result.selection_rect()); MoveWindowIfNecessaryWithRect(result.selection_rect());
// Once we find a match we no longer want to keep track of what had // 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. // focus. EndFindSession will then set the focus to the page content.
...@@ -384,3 +368,24 @@ void FindBarHost::GetWidgetPositionNative(gfx::Rect* avoid_overlapping_rect) { ...@@ -384,3 +368,24 @@ void FindBarHost::GetWidgetPositionNative(gfx::Rect* avoid_overlapping_rect) {
find_bar_controller_->web_contents()->GetViewBounds(); find_bar_controller_->web_contents()->GetViewBounds();
avoid_overlapping_rect->Offset(0, webcontents_rect.y() - frame_rect.y()); avoid_overlapping_rect->Offset(0, webcontents_rect.y() - frame_rect.y());
} }
void FindBarHost::MoveWindowIfNecessaryWithRect(
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.
content::WebContents* web_contents = find_bar_controller_->web_contents();
if (!web_contents)
return;
FindTabHelper* find_tab_helper = FindTabHelper::FromWebContents(web_contents);
if (!find_tab_helper || !find_tab_helper->find_ui_active())
return;
gfx::Rect new_pos = GetDialogPosition(selection_rect);
SetDialogPosition(new_pos);
// May need to redraw our frame to accommodate bookmark bar styles.
view()->Layout(); // Bounds may have changed.
view()->SchedulePaint();
}
...@@ -54,7 +54,7 @@ class FindBarHost : public DropdownBarHost, ...@@ -54,7 +54,7 @@ class FindBarHost : public DropdownBarHost,
void SetFocusAndSelection() override; void SetFocusAndSelection() override;
void ClearResults(const FindNotificationDetails& results) override; void ClearResults(const FindNotificationDetails& results) override;
void StopAnimation() override; void StopAnimation() override;
void MoveWindowIfNecessary(const gfx::Rect& selection_rect) override; void MoveWindowIfNecessary() override;
void SetFindTextAndSelectedRange(const base::string16& find_text, void SetFindTextAndSelectedRange(const base::string16& find_text,
const gfx::Range& selected_range) override; const gfx::Range& selected_range) override;
base::string16 GetFindText() override; base::string16 GetFindText() override;
...@@ -129,6 +129,14 @@ class FindBarHost : public DropdownBarHost, ...@@ -129,6 +129,14 @@ class FindBarHost : public DropdownBarHost,
// Allows implementation to tweak widget position. // Allows implementation to tweak widget position.
void GetWidgetPositionNative(gfx::Rect* avoid_overlapping_rect); void GetWidgetPositionNative(gfx::Rect* avoid_overlapping_rect);
// 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.
void MoveWindowIfNecessaryWithRect(const gfx::Rect& selection_rect);
// Returns the FindBarView. // Returns the FindBarView.
FindBarView* find_bar_view() { return static_cast<FindBarView*>(view()); } FindBarView* find_bar_view() { return static_cast<FindBarView*>(view()); }
......
...@@ -422,7 +422,7 @@ void FindBarView::Find(const base::string16& search_text) { ...@@ -422,7 +422,7 @@ void FindBarView::Find(const base::string16& search_text) {
} else { } else {
find_tab_helper->StopFinding(FindOnPageSelectionAction::kClear); find_tab_helper->StopFinding(FindOnPageSelectionAction::kClear);
UpdateForResult(find_tab_helper->find_result(), base::string16()); UpdateForResult(find_tab_helper->find_result(), base::string16());
find_bar_host_->MoveWindowIfNecessary(gfx::Rect()); find_bar_host_->MoveWindowIfNecessary();
// Clearing the text box should clear the prepopulate state so that when // Clearing the text box should clear the prepopulate state so that when
// we close and reopen the Find box it doesn't show the search we just // we close and reopen the Find box it doesn't show the search we just
......
...@@ -359,10 +359,8 @@ void BrowserViewLayout::Layout(views::View* browser_view) { ...@@ -359,10 +359,8 @@ void BrowserViewLayout::Layout(views::View* browser_view) {
// code calls back into us to find the bounding box the find bar // code calls back into us to find the bounding box the find bar
// must be laid out within, and that code depends on the // must be laid out within, and that code depends on the
// TabContentsContainer's bounds being up to date. // TabContentsContainer's bounds being up to date.
if (browser()->HasFindBarController()) { if (browser()->HasFindBarController())
browser()->GetFindBarController()->find_bar()->MoveWindowIfNecessary( browser()->GetFindBarController()->find_bar()->MoveWindowIfNecessary();
gfx::Rect());
}
// Adjust the fullscreen exit bubble bounds for |top_container_|'s new bounds. // Adjust the fullscreen exit bubble bounds for |top_container_|'s new bounds.
// This makes the fullscreen exit bubble look like it animates with // This makes the fullscreen exit bubble look like it animates with
......
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