Commit fa5eb5d1 authored by Thomas Lukaszewicz's avatar Thomas Lukaszewicz Committed by Commit Bot

Fixed layout of the find bar.

Fixed logic governing bounding box of the find bar in the browser
layout view. Removed unnecessary insetting and fixed comments to
better reflect its function.

Bug: 871419
Change-Id: I89a341825508b1e088b0f10f449eb2c3a91fcc38
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1866969
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#711355}
parent b77e727f
...@@ -56,10 +56,10 @@ class FindBar { ...@@ -56,10 +56,10 @@ class FindBar {
const gfx::Range& selected_range) = 0; const gfx::Range& selected_range) = 0;
// Gets the search string currently visible in the find box. // Gets the search string currently visible in the find box.
virtual base::string16 GetFindText() = 0; virtual base::string16 GetFindText() const = 0;
// Gets the selection. // Gets the selection.
virtual gfx::Range GetSelectedRange() = 0; virtual gfx::Range GetSelectedRange() const = 0;
// Updates the FindBar with the find result details contained within the // Updates the FindBar with the find result details contained within the
// specified |result|. // specified |result|.
...@@ -69,21 +69,21 @@ class FindBar { ...@@ -69,21 +69,21 @@ class FindBar {
// No match was found; play an audible alert. // No match was found; play an audible alert.
virtual void AudibleAlert() = 0; virtual void AudibleAlert() = 0;
virtual bool IsFindBarVisible() = 0; virtual bool IsFindBarVisible() const = 0;
// Upon dismissing the window, restore focus to the last focused view which is // Upon dismissing the window, restore focus to the last focused view which is
// not FindBarView or any of its children. // not FindBarView or any of its children.
virtual void RestoreSavedFocus() = 0; virtual void RestoreSavedFocus() = 0;
// Returns true if all tabs use a single find pasteboard. // Returns true if all tabs use a single find pasteboard.
virtual bool HasGlobalFindPasteboard() = 0; virtual bool HasGlobalFindPasteboard() const = 0;
// Called when the web contents associated with the find bar changes. // Called when the web contents associated with the find bar changes.
virtual void UpdateFindBarForChangedWebContents() = 0; virtual void UpdateFindBarForChangedWebContents() = 0;
// Returns a pointer to the testing interface to the FindBar, or NULL // Returns a pointer to the testing interface to the FindBar, or NULL
// if there is none. // if there is none.
virtual FindBarTesting* GetFindBarTesting() = 0; virtual const FindBarTesting* GetFindBarTesting() const = 0;
}; };
class FindBarTesting { class FindBarTesting {
...@@ -97,19 +97,19 @@ class FindBarTesting { ...@@ -97,19 +97,19 @@ class FindBarTesting {
// This is used for UI tests of the find bar. If the find bar is not currently // 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}. // shown (return value of false), the out params will be {(0, 0), false}.
virtual bool GetFindBarWindowInfo(gfx::Point* position, virtual bool GetFindBarWindowInfo(gfx::Point* position,
bool* fully_visible) = 0; bool* fully_visible) const = 0;
// Gets the search string currently selected in the Find box. // Gets the search string currently selected in the Find box.
virtual base::string16 GetFindSelectedText() = 0; virtual base::string16 GetFindSelectedText() const = 0;
// Gets the match count text (ie. 1 of 3) visible in the Find box. // Gets the match count text (ie. 1 of 3) visible in the Find box.
virtual base::string16 GetMatchCountText() = 0; virtual base::string16 GetMatchCountText() const = 0;
// Gets the pixel width of the FindBar. // Gets the pixel width of the FindBar contents.
virtual int GetWidth() = 0; virtual int GetContentsWidth() const = 0;
// Gets the number of audible alerts that have been issued by this bar. // Gets the number of audible alerts that have been issued by this bar.
virtual size_t GetAudibleAlertCount() = 0; virtual size_t GetAudibleAlertCount() const = 0;
}; };
#endif // CHROME_BROWSER_UI_FIND_BAR_FIND_BAR_H_ #endif // CHROME_BROWSER_UI_FIND_BAR_FIND_BAR_H_
...@@ -90,7 +90,7 @@ class FindInPageControllerTest : public InProcessBrowserTest { ...@@ -90,7 +90,7 @@ class FindInPageControllerTest : public InProcessBrowserTest {
protected: protected:
bool GetFindBarWindowInfoForBrowser( bool GetFindBarWindowInfoForBrowser(
Browser* browser, gfx::Point* position, bool* fully_visible) { Browser* browser, gfx::Point* position, bool* fully_visible) {
FindBarTesting* find_bar = const FindBarTesting* find_bar =
browser->GetFindBarController()->find_bar()->GetFindBarTesting(); browser->GetFindBarController()->find_bar()->GetFindBarTesting();
return find_bar->GetFindBarWindowInfo(position, fully_visible); return find_bar->GetFindBarWindowInfo(position, fully_visible);
} }
...@@ -109,7 +109,7 @@ class FindInPageControllerTest : public InProcessBrowserTest { ...@@ -109,7 +109,7 @@ class FindInPageControllerTest : public InProcessBrowserTest {
} }
base::string16 GetFindBarMatchCountTextForBrowser(Browser* browser) { base::string16 GetFindBarMatchCountTextForBrowser(Browser* browser) {
FindBarTesting* find_bar = const FindBarTesting* find_bar =
browser->GetFindBarController()->find_bar()->GetFindBarTesting(); browser->GetFindBarController()->find_bar()->GetFindBarTesting();
return find_bar->GetMatchCountText(); return find_bar->GetMatchCountText();
} }
...@@ -119,13 +119,13 @@ class FindInPageControllerTest : public InProcessBrowserTest { ...@@ -119,13 +119,13 @@ class FindInPageControllerTest : public InProcessBrowserTest {
} }
int GetFindBarWidthForBrowser(Browser* browser) { int GetFindBarWidthForBrowser(Browser* browser) {
FindBarTesting* find_bar = const FindBarTesting* find_bar =
browser->GetFindBarController()->find_bar()->GetFindBarTesting(); browser->GetFindBarController()->find_bar()->GetFindBarTesting();
return find_bar->GetWidth(); return find_bar->GetContentsWidth();
} }
size_t GetFindBarAudibleAlertsForBrowser(Browser* browser) { size_t GetFindBarAudibleAlertsForBrowser(Browser* browser) {
FindBarTesting* find_bar = const FindBarTesting* find_bar =
browser->GetFindBarController()->find_bar()->GetFindBarTesting(); browser->GetFindBarController()->find_bar()->GetFindBarTesting();
return find_bar->GetAudibleAlertCount(); return find_bar->GetAudibleAlertCount();
} }
......
...@@ -115,7 +115,8 @@ class DropdownBarHost : public ui::AcceleratorTarget, ...@@ -115,7 +115,8 @@ class DropdownBarHost : public ui::AcceleratorTarget,
virtual void OnVisibilityChanged(); virtual void OnVisibilityChanged();
// Returns the dropdown bar view. // Returns the dropdown bar view.
views::View* view() const { return view_; } views::View* view() { return view_; }
const views::View* view() const { return view_; }
// Returns the focus tracker. // Returns the focus tracker.
views::ExternalFocusTracker* focus_tracker() const { views::ExternalFocusTracker* focus_tracker() const {
......
...@@ -112,11 +112,11 @@ void FindBarHost::SetFindTextAndSelectedRange( ...@@ -112,11 +112,11 @@ void FindBarHost::SetFindTextAndSelectedRange(
find_bar_view()->SetFindTextAndSelectedRange(find_text, selected_range); find_bar_view()->SetFindTextAndSelectedRange(find_text, selected_range);
} }
base::string16 FindBarHost::GetFindText() { base::string16 FindBarHost::GetFindText() const {
return find_bar_view()->GetFindText(); return find_bar_view()->GetFindText();
} }
gfx::Range FindBarHost::GetSelectedRange() { gfx::Range FindBarHost::GetSelectedRange() const {
return find_bar_view()->GetSelectedRange(); return find_bar_view()->GetSelectedRange();
} }
...@@ -143,7 +143,7 @@ void FindBarHost::AudibleAlert() { ...@@ -143,7 +143,7 @@ void FindBarHost::AudibleAlert() {
#endif #endif
} }
bool FindBarHost::IsFindBarVisible() { bool FindBarHost::IsFindBarVisible() const {
return DropdownBarHost::IsVisible(); return DropdownBarHost::IsVisible();
} }
...@@ -156,7 +156,7 @@ void FindBarHost::RestoreSavedFocus() { ...@@ -156,7 +156,7 @@ void FindBarHost::RestoreSavedFocus() {
} }
} }
bool FindBarHost::HasGlobalFindPasteboard() { bool FindBarHost::HasGlobalFindPasteboard() const {
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
return true; return true;
#else #else
...@@ -167,7 +167,7 @@ bool FindBarHost::HasGlobalFindPasteboard() { ...@@ -167,7 +167,7 @@ bool FindBarHost::HasGlobalFindPasteboard() {
void FindBarHost::UpdateFindBarForChangedWebContents() { void FindBarHost::UpdateFindBarForChangedWebContents() {
} }
FindBarTesting* FindBarHost::GetFindBarTesting() { const FindBarTesting* FindBarHost::GetFindBarTesting() const {
return this; return this;
} }
...@@ -203,7 +203,7 @@ bool FindBarHost::CanHandleAccelerators() const { ...@@ -203,7 +203,7 @@ bool FindBarHost::CanHandleAccelerators() const {
// FindBarTesting implementation: // FindBarTesting implementation:
bool FindBarHost::GetFindBarWindowInfo(gfx::Point* position, bool FindBarHost::GetFindBarWindowInfo(gfx::Point* position,
bool* fully_visible) { bool* fully_visible) const {
if (!find_bar_controller_ || if (!find_bar_controller_ ||
#if defined(OS_WIN) && !defined(USE_AURA) #if defined(OS_WIN) && !defined(USE_AURA)
!::IsWindow(host()->GetNativeView())) { !::IsWindow(host()->GetNativeView())) {
...@@ -228,19 +228,19 @@ bool FindBarHost::GetFindBarWindowInfo(gfx::Point* position, ...@@ -228,19 +228,19 @@ bool FindBarHost::GetFindBarWindowInfo(gfx::Point* position,
return true; return true;
} }
base::string16 FindBarHost::GetFindSelectedText() { base::string16 FindBarHost::GetFindSelectedText() const {
return find_bar_view()->GetFindSelectedText(); return find_bar_view()->GetFindSelectedText();
} }
base::string16 FindBarHost::GetMatchCountText() { base::string16 FindBarHost::GetMatchCountText() const {
return find_bar_view()->GetMatchCountText(); return find_bar_view()->GetMatchCountText();
} }
int FindBarHost::GetWidth() { int FindBarHost::GetContentsWidth() const {
return view()->width(); return view()->GetContentsBounds().width();
} }
size_t FindBarHost::GetAudibleAlertCount() { size_t FindBarHost::GetAudibleAlertCount() const {
return audible_alerts_; return audible_alerts_;
} }
...@@ -258,17 +258,17 @@ gfx::Rect FindBarHost::GetDialogPosition(gfx::Rect avoid_overlapping_rect) { ...@@ -258,17 +258,17 @@ gfx::Rect FindBarHost::GetDialogPosition(gfx::Rect avoid_overlapping_rect) {
gfx::Size prefsize = view()->GetPreferredSize(); gfx::Size prefsize = view()->GetPreferredSize();
// Limit width to the available area. // Limit width to the available area.
if (widget_bounds.width() < prefsize.width()) gfx::Insets insets = view()->GetInsets();
prefsize.set_width(widget_bounds.width()); prefsize.set_width(
std::min(prefsize.width(), widget_bounds.width() + insets.width()));
// Don't show the find bar if |widget_bounds| is not tall enough. // Don't show the find bar if |widget_bounds| is not tall enough to fit.
if (widget_bounds.height() < prefsize.height()) if (widget_bounds.height() < prefsize.height() - insets.height())
return gfx::Rect(); return gfx::Rect();
// Place the view in the top right corner of the widget boundaries (top left // Place the view in the top right corner of the widget boundaries (top left
// for RTL languages). Adjust for the view insets to ensure the border lines // for RTL languages). Adjust for the view insets to ensure the border lines
// up with the location bar. // up with the location bar.
gfx::Insets insets = view()->border()->GetInsets();
int x = widget_bounds.x() - insets.left(); int x = widget_bounds.x() - insets.left();
if (!base::i18n::IsRTL()) if (!base::i18n::IsRTL())
x += widget_bounds.width() - prefsize.width() + insets.width(); x += widget_bounds.width() - prefsize.width() + insets.width();
......
...@@ -57,27 +57,28 @@ class FindBarHost : public DropdownBarHost, ...@@ -57,27 +57,28 @@ class FindBarHost : public DropdownBarHost,
void MoveWindowIfNecessary() 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() const override;
gfx::Range GetSelectedRange() override; gfx::Range GetSelectedRange() const override;
void UpdateUIForFindResult(const FindNotificationDetails& result, void UpdateUIForFindResult(const FindNotificationDetails& result,
const base::string16& find_text) override; const base::string16& find_text) override;
void AudibleAlert() override; void AudibleAlert() override;
bool IsFindBarVisible() override; bool IsFindBarVisible() const override;
void RestoreSavedFocus() override; void RestoreSavedFocus() override;
bool HasGlobalFindPasteboard() override; bool HasGlobalFindPasteboard() const override;
void UpdateFindBarForChangedWebContents() override; void UpdateFindBarForChangedWebContents() override;
FindBarTesting* GetFindBarTesting() override; const FindBarTesting* GetFindBarTesting() const override;
// Overridden from ui::AcceleratorTarget in DropdownBarHost class: // Overridden from ui::AcceleratorTarget in DropdownBarHost class:
bool AcceleratorPressed(const ui::Accelerator& accelerator) override; bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
bool CanHandleAccelerators() const override; bool CanHandleAccelerators() const override;
// FindBarTesting implementation: // FindBarTesting implementation:
bool GetFindBarWindowInfo(gfx::Point* position, bool* fully_visible) override; bool GetFindBarWindowInfo(gfx::Point* position,
base::string16 GetFindSelectedText() override; bool* fully_visible) const override;
base::string16 GetMatchCountText() override; base::string16 GetFindSelectedText() const override;
int GetWidth() override; base::string16 GetMatchCountText() const override;
size_t GetAudibleAlertCount() override; int GetContentsWidth() const override;
size_t GetAudibleAlertCount() const override;
// Overridden from DropdownBarHost: // Overridden from DropdownBarHost:
// Returns the rectangle representing where to position the find bar. It uses // Returns the rectangle representing where to position the find bar. It uses
...@@ -139,6 +140,9 @@ class FindBarHost : public DropdownBarHost, ...@@ -139,6 +140,9 @@ class FindBarHost : public DropdownBarHost,
// Returns the FindBarView. // Returns the FindBarView.
FindBarView* find_bar_view() { return static_cast<FindBarView*>(view()); } FindBarView* find_bar_view() { return static_cast<FindBarView*>(view()); }
const FindBarView* find_bar_view() const {
return static_cast<const FindBarView*>(view());
}
// A pointer back to the owning controller. // A pointer back to the owning controller.
FindBarController* find_bar_controller_; FindBarController* find_bar_controller_;
......
...@@ -164,6 +164,7 @@ ...@@ -164,6 +164,7 @@
#include "ui/gfx/color_utils.h" #include "ui/gfx/color_utils.h"
#include "ui/gfx/geometry/rect_conversions.h" #include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/scoped_canvas.h" #include "ui/gfx/scoped_canvas.h"
#include "ui/gfx/scrollbar_size.h"
#include "ui/native_theme/native_theme_dark_aura.h" #include "ui/native_theme/native_theme_dark_aura.h"
#include "ui/views/accessibility/view_accessibility_utils.h" #include "ui/views/accessibility/view_accessibility_utils.h"
#include "ui/views/controls/button/menu_button.h" #include "ui/views/controls/button/menu_button.h"
...@@ -515,7 +516,22 @@ void BrowserView::InitStatusBubble() { ...@@ -515,7 +516,22 @@ void BrowserView::InitStatusBubble() {
} }
gfx::Rect BrowserView::GetFindBarBoundingBox() const { gfx::Rect BrowserView::GetFindBarBoundingBox() const {
return GetBrowserViewLayout()->GetFindBarBoundingBox(); gfx::Rect contents_bounds = contents_container_->ConvertRectToWidget(
contents_container_->GetLocalBounds());
// If the location bar is visible use it to position the bounding box,
// otherwise use the contents container.
if (!immersive_mode_controller_->IsEnabled() ||
immersive_mode_controller_->IsRevealed()) {
const gfx::Rect bounding_box =
toolbar_button_provider_->GetFindBarBoundingBox(
contents_bounds.bottom());
if (!bounding_box.IsEmpty())
return bounding_box;
}
contents_bounds.Inset(0, 0, gfx::scrollbar_size(), 0);
return contents_container_->GetMirroredRect(contents_bounds);
} }
int BrowserView::GetTabStripHeight() const { int BrowserView::GetTabStripHeight() const {
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#include "ui/gfx/geometry/point.h" #include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
#include "ui/gfx/scrollbar_size.h"
#include "ui/views/controls/webview/webview.h" #include "ui/views/controls/webview/webview.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
#include "ui/views/window/client_view.h" #include "ui/views/window/client_view.h"
...@@ -206,46 +205,6 @@ gfx::Size BrowserViewLayout::GetMinimumSize(const views::View* host) const { ...@@ -206,46 +205,6 @@ gfx::Size BrowserViewLayout::GetMinimumSize(const views::View* host) const {
return gfx::Size(min_width, min_height); return gfx::Size(min_width, min_height);
} }
gfx::Rect BrowserViewLayout::GetFindBarBoundingBox() const {
// This function returns the area the Find Bar can be laid out within. When
// the location bar/OmniBox is visible, the bounding box is the area extending
// from the bottom edge of the location bar/OmniBox to the bottom of the
// "user-perceived content area" of the browser window. The width matches the
// width of the location bar/OmniBox. If the location bar/OmniBox is not
// visible, the returned area is the full "user-perceived content area",
// excluding any vertical scrollbar.
// The "user-perceived content area" excludes the detached bookmark bar (in
// the New Tab case) and any infobars since they are not _visually_ connected
// to the Toolbar.
gfx::Rect bounding_box;
if (!immersive_mode_controller_->IsEnabled() ||
immersive_mode_controller_->IsRevealed()) {
bounding_box =
browser_view_->toolbar_button_provider()->GetFindBarBoundingBox(
contents_container_->height());
}
if (!bounding_box.IsEmpty())
return bounding_box;
// Otherwise, use the contents container minus any infobars and detached
// bookmark bar from the top and a scrollbar width from the appropriate edge.
bounding_box = contents_container_->ConvertRectToWidget(
contents_container_->GetLocalBounds());
// Under ChromeOS, the top_container_ may include the title bar for hosted
// apps. Just make sure something of consequence is visible before it's height
// is used.
const int top_container_height = (browser_view_->tabstrip()->GetVisible() ||
browser_view_->toolbar()->GetVisible() ||
browser_view_->IsBookmarkBarVisible())
? top_container_->height()
: 0;
if (base::i18n::IsRTL())
bounding_box.Inset(gfx::scrollbar_size(), top_container_height, 0, 0);
else
bounding_box.Inset(0, top_container_height, gfx::scrollbar_size(), 0);
return bounding_box;
}
gfx::NativeView BrowserViewLayout::GetHostView() { gfx::NativeView BrowserViewLayout::GetHostView() {
return delegate_->GetHostView(); return delegate_->GetHostView();
} }
......
...@@ -78,9 +78,6 @@ class BrowserViewLayout : public views::LayoutManager { ...@@ -78,9 +78,6 @@ class BrowserViewLayout : public views::LayoutManager {
web_modal::WebContentsModalDialogHost* GetWebContentsModalDialogHost(); web_modal::WebContentsModalDialogHost* GetWebContentsModalDialogHost();
// Returns the bounding box, in widget coordinates, for the find bar.
gfx::Rect GetFindBarBoundingBox() const;
// Returns the view against which the dialog is positioned and parented. // Returns the view against which the dialog is positioned and parented.
gfx::NativeView GetHostView(); gfx::NativeView GetHostView();
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "content/public/test/test_service_manager_context.h" #include "content/public/test/test_service_manager_context.h"
#include "ui/base/accelerators/accelerator.h" #include "ui/base/accelerators/accelerator.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/scrollbar_size.h"
#include "ui/views/controls/webview/webview.h" #include "ui/views/controls/webview/webview.h"
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
...@@ -189,6 +190,46 @@ TEST_F(BrowserViewTest, DISABLED_BrowserViewLayout) { ...@@ -189,6 +190,46 @@ TEST_F(BrowserViewTest, DISABLED_BrowserViewLayout) {
BookmarkBarView::DisableAnimationsForTesting(false); BookmarkBarView::DisableAnimationsForTesting(false);
} }
// Test the find bar's bounding box when the location bar is visible.
TEST_F(BrowserViewTest, FindBarBoundingBoxLocationBar) {
ASSERT_FALSE(base::i18n::IsRTL());
const views::View* location_bar = browser_view()->GetLocationBarView();
const views::View* contents_container =
browser_view()->GetContentsContainerForTest();
// Make sure we are testing the case where the location bar is visible.
EXPECT_TRUE(location_bar->GetVisible());
const gfx::Rect find_bar_bounds = browser_view()->GetFindBarBoundingBox();
const gfx::Rect location_bar_bounds =
location_bar->ConvertRectToWidget(location_bar->GetLocalBounds());
const gfx::Rect contents_bounds = contents_container->ConvertRectToWidget(
contents_container->GetLocalBounds());
const gfx::Rect target(
location_bar_bounds.x(), location_bar_bounds.bottom(),
location_bar_bounds.width(),
contents_bounds.bottom() - location_bar_bounds.bottom());
EXPECT_EQ(target.ToString(), find_bar_bounds.ToString());
}
// Test the find bar's bounding box when the location bar is not visible.
TEST_F(BrowserViewTest, FindBarBoundingBoxNoLocationBar) {
ASSERT_FALSE(base::i18n::IsRTL());
const views::View* location_bar = browser_view()->GetLocationBarView();
const views::View* contents_container =
browser_view()->GetContentsContainerForTest();
// Make sure we are testing the case where the location bar is absent.
browser_view()->GetLocationBarView()->SetVisible(false);
EXPECT_FALSE(location_bar->GetVisible());
const gfx::Rect find_bar_bounds = browser_view()->GetFindBarBoundingBox();
gfx::Rect contents_bounds = contents_container->ConvertRectToWidget(
contents_container->GetLocalBounds());
contents_bounds.Inset(0, 0, gfx::scrollbar_size(), 0);
EXPECT_EQ(contents_bounds.ToString(), find_bar_bounds.ToString());
}
// On macOS, most accelerators are handled by CommandDispatcher. // On macOS, most accelerators are handled by CommandDispatcher.
#if !defined(OS_MACOSX) #if !defined(OS_MACOSX)
// Test that repeated accelerators are processed or ignored depending on the // Test that repeated accelerators are processed or ignored depending on the
......
...@@ -47,10 +47,9 @@ class ToolbarButtonProvider { ...@@ -47,10 +47,9 @@ class ToolbarButtonProvider {
// Gets the app menu button. // Gets the app menu button.
virtual AppMenuButton* GetAppMenuButton() = 0; virtual AppMenuButton* GetAppMenuButton() = 0;
// Gets the area available for the find bar in widget space where // Returns a bounding box for the find bar in widget coordinates given the
// |contents_height| is the amount of vertical space available, otherwise if // bottom of the contents container.
// there is no appropriate anchor point returns empty gfx::Rect. virtual gfx::Rect GetFindBarBoundingBox(int contents_bottom) const = 0;
virtual gfx::Rect GetFindBarBoundingBox(int contents_height) const = 0;
// Gives the toolbar focus. // Gives the toolbar focus.
virtual void FocusToolbar() = 0; virtual void FocusToolbar() = 0;
......
...@@ -782,7 +782,7 @@ AppMenuButton* ToolbarView::GetAppMenuButton() { ...@@ -782,7 +782,7 @@ AppMenuButton* ToolbarView::GetAppMenuButton() {
return app_menu_button_; return app_menu_button_;
} }
gfx::Rect ToolbarView::GetFindBarBoundingBox(int contents_height) const { gfx::Rect ToolbarView::GetFindBarBoundingBox(int contents_bottom) const {
if (!browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)) if (!browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR))
return gfx::Rect(); return gfx::Rect();
...@@ -792,7 +792,7 @@ gfx::Rect ToolbarView::GetFindBarBoundingBox(int contents_height) const { ...@@ -792,7 +792,7 @@ gfx::Rect ToolbarView::GetFindBarBoundingBox(int contents_height) const {
gfx::Rect bounds = gfx::Rect bounds =
location_bar_->ConvertRectToWidget(location_bar_->GetLocalBounds()); location_bar_->ConvertRectToWidget(location_bar_->GetLocalBounds());
return gfx::Rect(bounds.x(), bounds.bottom(), bounds.width(), return gfx::Rect(bounds.x(), bounds.bottom(), bounds.width(),
contents_height); contents_bottom - bounds.bottom());
} }
void ToolbarView::FocusToolbar() { void ToolbarView::FocusToolbar() {
......
...@@ -232,7 +232,7 @@ class ToolbarView : public views::AccessiblePaneView, ...@@ -232,7 +232,7 @@ class ToolbarView : public views::AccessiblePaneView,
views::View* GetDefaultExtensionDialogAnchorView() override; views::View* GetDefaultExtensionDialogAnchorView() override;
PageActionIconView* GetPageActionIconView(PageActionIconType type) override; PageActionIconView* GetPageActionIconView(PageActionIconType type) override;
AppMenuButton* GetAppMenuButton() override; AppMenuButton* GetAppMenuButton() override;
gfx::Rect GetFindBarBoundingBox(int contents_height) const override; gfx::Rect GetFindBarBoundingBox(int contents_bottom) const override;
void FocusToolbar() override; void FocusToolbar() override;
views::AccessiblePaneView* GetAsAccessiblePaneView() override; views::AccessiblePaneView* GetAsAccessiblePaneView() override;
views::View* GetAnchorView(PageActionIconType type) override; views::View* GetAnchorView(PageActionIconType type) override;
......
...@@ -480,21 +480,23 @@ AppMenuButton* WebAppFrameToolbarView::GetAppMenuButton() { ...@@ -480,21 +480,23 @@ AppMenuButton* WebAppFrameToolbarView::GetAppMenuButton() {
} }
gfx::Rect WebAppFrameToolbarView::GetFindBarBoundingBox( gfx::Rect WebAppFrameToolbarView::GetFindBarBoundingBox(
int contents_height) const { int contents_bottom) const {
if (!IsDrawn()) if (!IsDrawn())
return gfx::Rect(); return gfx::Rect();
// If LTR find bar will be right aligned so align to right edge of app menu
// button. Otherwise it will be left aligned so align to the left edge of the
// app menu button.
gfx::Rect anchor_bounds = web_app_menu_button_->ConvertRectToWidget( gfx::Rect anchor_bounds = web_app_menu_button_->ConvertRectToWidget(
web_app_menu_button_->GetLocalBounds()); web_app_menu_button_->GetLocalBounds());
int x_pos = 0;
int width = anchor_bounds.right();
if (base::i18n::IsRTL()) { if (base::i18n::IsRTL()) {
// Find bar will be left aligned so align to left edge of app menu button. x_pos = anchor_bounds.x();
int widget_width = GetWidget()->GetRootView()->width(); width = GetWidget()->GetRootView()->width() - anchor_bounds.x();
return gfx::Rect(anchor_bounds.x(), anchor_bounds.bottom(),
widget_width - anchor_bounds.x(), contents_height);
} }
// Find bar will be right aligned so align to right edge of app menu button. return gfx::Rect(x_pos, anchor_bounds.bottom(), width,
return gfx::Rect(0, anchor_bounds.bottom(), contents_bottom - anchor_bounds.bottom());
anchor_bounds.x() + anchor_bounds.width(), contents_height);
} }
void WebAppFrameToolbarView::FocusToolbar() { void WebAppFrameToolbarView::FocusToolbar() {
......
...@@ -129,7 +129,7 @@ class WebAppFrameToolbarView : public views::AccessiblePaneView, ...@@ -129,7 +129,7 @@ class WebAppFrameToolbarView : public views::AccessiblePaneView,
views::View* GetDefaultExtensionDialogAnchorView() override; views::View* GetDefaultExtensionDialogAnchorView() override;
PageActionIconView* GetPageActionIconView(PageActionIconType type) override; PageActionIconView* GetPageActionIconView(PageActionIconType type) override;
AppMenuButton* GetAppMenuButton() override; AppMenuButton* GetAppMenuButton() override;
gfx::Rect GetFindBarBoundingBox(int contents_height) const override; gfx::Rect GetFindBarBoundingBox(int contents_bottom) const override;
void FocusToolbar() override; void FocusToolbar() override;
views::AccessiblePaneView* GetAsAccessiblePaneView() override; views::AccessiblePaneView* GetAsAccessiblePaneView() override;
views::View* GetAnchorView(PageActionIconType type) override; views::View* GetAnchorView(PageActionIconType type) override;
......
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