Commit c71c2c14 authored by Tommy Martino's avatar Tommy Martino Committed by Commit Bot

Reverting 2 Autofill CLs

This CL reverts the following 2 CLs:
----
Revert "[Autofill Views] Reimplement Scrolling"

This reverts commit c53515cd.

Revert "[af] Adjust dropdown so it doesn't look so close to the input element"

This reverts commit f1c12e66.
----

The former increased the frequency of a crash on Canary.

The latter is a one-line change which was blocking us from landing a clean
revert of the former. I have an OK from ftirelo to revert it at the same time.


Change-Id: Ief96e2e8902477f83b3999b6c7fdcb2dfbd73035
Bug: 854183

TBR=estade@chromium.org

Change-Id: Ief96e2e8902477f83b3999b6c7fdcb2dfbd73035
Reviewed-on: https://chromium-review.googlesource.com/1110577Reviewed-by: default avatarTommy Martino <tmartino@chromium.org>
Reviewed-by: default avatarFabio Tirelo <ftirelo@chromium.org>
Commit-Queue: Tommy Martino <tmartino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569438}
parent 46004137
......@@ -64,8 +64,10 @@ AutofillPopupControllerImpl::AutofillPopupControllerImpl(
const gfx::RectF& element_bounds,
base::i18n::TextDirection text_direction)
: controller_common_(element_bounds, text_direction, container_view),
view_(NULL),
layout_model_(this, delegate->GetPopupType() == PopupType::kCreditCards),
delegate_(delegate) {
delegate_(delegate),
weak_ptr_factory_(this) {
ClearState();
delegate->RegisterDeletionCallback(base::BindOnce(
&AutofillPopupControllerImpl::HideViewAndDie, GetWeakPtr()));
......
......@@ -134,7 +134,9 @@ class AutofillPopupControllerImpl : public AutofillPopupController {
base::WeakPtr<AutofillPopupControllerImpl> GetWeakPtr();
AutofillPopupLayoutModel& LayoutModelForTesting() { return layout_model_; }
// Contains common popup functionality such as popup layout. Protected for
// testing.
PopupControllerCommon controller_common_;
private:
#if !defined(OS_ANDROID)
......@@ -155,8 +157,7 @@ class AutofillPopupControllerImpl : public AutofillPopupController {
friend class AutofillPopupControllerUnitTest;
void SetViewForTesting(AutofillPopupView* view) { view_ = view; }
PopupControllerCommon controller_common_;
AutofillPopupView* view_ = nullptr; // Weak reference.
AutofillPopupView* view_; // Weak reference.
AutofillPopupLayoutModel layout_model_;
base::WeakPtr<AutofillPopupDelegate> delegate_;
......@@ -179,7 +180,7 @@ class AutofillPopupControllerImpl : public AutofillPopupController {
// is drawn by Cocoa on macOS.
gfx::Typesetter typesetter_ = gfx::Typesetter::HARFBUZZ;
base::WeakPtrFactory<AutofillPopupControllerImpl> weak_ptr_factory_{this};
base::WeakPtrFactory<AutofillPopupControllerImpl> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(AutofillPopupControllerImpl);
};
......
......@@ -13,8 +13,6 @@
#include "build/build_config.h"
#include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h"
#include "chrome/browser/ui/autofill/autofill_popup_view.h"
#include "chrome/browser/ui/autofill/popup_view_common.h"
#include "chrome/browser/ui/autofill/popup_view_test_helpers.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_profile.h"
#include "components/autofill/content/browser/content_autofill_driver.h"
......@@ -98,10 +96,7 @@ class TestAutofillPopupController : public AutofillPopupControllerImpl {
NULL,
NULL,
element_bounds,
base::i18n::UNKNOWN_DIRECTION) {
LayoutModelForTesting().SetUpForTesting(
std::make_unique<MockPopupViewCommonForUnitTesting>());
}
base::i18n::UNKNOWN_DIRECTION) {}
~TestAutofillPopupController() override {}
// Making protected functions public for testing
......
......@@ -95,7 +95,6 @@ AutofillPopupLayoutModel::AutofillPopupLayoutModel(
smaller_font_list_ =
normal_font_list_.DeriveWithSizeDelta(kSmallerFontSizeDelta);
bold_font_list_ = normal_font_list_.DeriveWithWeight(gfx::Font::Weight::BOLD);
view_common_ = std::make_unique<PopupViewCommon>();
#endif
}
......@@ -153,7 +152,7 @@ void AutofillPopupLayoutModel::UpdatePopupBounds() {
int popup_width = GetDesiredPopupWidth();
int popup_height = GetDesiredPopupHeight();
popup_bounds_ = view_common_->CalculatePopupBounds(
popup_bounds_ = view_common_.CalculatePopupBounds(
popup_width, popup_height, RoundedElementBounds(),
delegate_->container_view(), delegate_->IsRTL());
}
......@@ -285,11 +284,6 @@ int AutofillPopupLayoutModel::GetIconAccessibleNameResourceId(
return kResourceNotFoundId;
}
void AutofillPopupLayoutModel::SetUpForTesting(
std::unique_ptr<PopupViewCommon> view_common) {
view_common_ = std::move(view_common);
}
const gfx::Rect AutofillPopupLayoutModel::RoundedElementBounds() const {
return gfx::ToEnclosingRect(delegate_->element_bounds());
}
......
......@@ -99,10 +99,6 @@ class AutofillPopupLayoutModel {
bool is_credit_card_popup() const { return is_credit_card_popup_; }
// Allows the provision of another implementation of view_common, for use in
// unit tests where using the real thing could cause crashes.
void SetUpForTesting(std::unique_ptr<PopupViewCommon> view_common);
private:
// Returns the enclosing rectangle for the element_bounds.
const gfx::Rect RoundedElementBounds() const;
......@@ -120,7 +116,7 @@ class AutofillPopupLayoutModel {
// The bounds of the Autofill popup.
gfx::Rect popup_bounds_;
std::unique_ptr<PopupViewCommon> view_common_;
PopupViewCommon view_common_;
AutofillPopupViewDelegate* delegate_; // Weak reference.
......
......@@ -7,18 +7,12 @@
#include <algorithm>
#include <utility>
#include "build/build_config.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/vector2d.h"
#if defined(OS_ANDROID)
#include "ui/android/view_android.h"
#include "ui/android/window_android.h"
#else // defined(OS_ANDROID)
#include "chrome/browser/platform_util.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
#endif // !defined(OS_ANDROID)
namespace autofill {
namespace {
......@@ -27,23 +21,26 @@ namespace {
// the starting point and the width of the popup, taking into account the
// direction it's supposed to grow (either to the left or to the right).
// Components |y| and |height| of |popup_bounds| are not changed.
void CalculatePopupXAndWidth(int leftmost_available_x,
int rightmost_available_x,
void CalculatePopupXAndWidth(const display::Display& left_display,
const display::Display& right_display,
int popup_required_width,
const gfx::Rect& element_bounds,
bool is_rtl,
gfx::Rect* popup_bounds) {
int leftmost_display_x = left_display.bounds().x();
int rightmost_display_x =
right_display.GetSizeInPixel().width() + right_display.bounds().x();
// Calculate the start coordinates for the popup if it is growing right or
// the end position if it is growing to the left, capped to screen space.
int right_growth_start =
std::max(leftmost_available_x,
std::min(rightmost_available_x, element_bounds.x()));
int right_growth_start = std::max(
leftmost_display_x, std::min(rightmost_display_x, element_bounds.x()));
int left_growth_end =
std::max(leftmost_available_x,
std::min(rightmost_available_x, element_bounds.right()));
std::max(leftmost_display_x,
std::min(rightmost_display_x, element_bounds.right()));
int right_available = rightmost_available_x - right_growth_start;
int left_available = left_growth_end - leftmost_available_x;
int right_available = rightmost_display_x - right_growth_start;
int left_available = left_growth_end - leftmost_display_x;
int popup_width =
std::min(popup_required_width, std::max(right_available, left_available));
......@@ -69,92 +66,77 @@ void CalculatePopupXAndWidth(int leftmost_available_x,
// the starting point and the height of the popup, taking into account the
// direction it's supposed to grow (either up or down). Components |x| and
// |width| of |popup_bounds| are not changed.
void CalculatePopupYAndHeight(int topmost_available_y,
int bottommost_available_y,
void CalculatePopupYAndHeight(const display::Display& top_display,
const display::Display& bottom_display,
int popup_required_height,
const gfx::Rect& element_bounds,
gfx::Rect* popup_bounds) {
int topmost_display_y = top_display.bounds().y();
int bottommost_display_y =
bottom_display.GetSizeInPixel().height() + bottom_display.bounds().y();
// Calculate the start coordinates for the popup if it is growing down or
// the end position if it is growing up, capped to screen space.
int top_growth_end =
std::max(topmost_available_y,
std::min(bottommost_available_y, element_bounds.y()));
int top_growth_end = std::max(
topmost_display_y, std::min(bottommost_display_y, element_bounds.y()));
int bottom_growth_start =
std::max(topmost_available_y,
std::min(bottommost_available_y, element_bounds.bottom()));
std::max(topmost_display_y,
std::min(bottommost_display_y, element_bounds.bottom()));
int top_available = top_growth_end - topmost_available_y;
int bottom_available = bottommost_available_y - bottom_growth_start;
int top_available = bottom_growth_start - topmost_display_y;
int bottom_available = bottommost_display_y - top_growth_end;
// TODO(csharp): Restrict the popup height to what is available.
popup_bounds->set_height(popup_required_height);
if (bottom_available >= popup_required_height ||
bottom_available >= top_available) {
// The popup can appear below the field.
popup_bounds->set_height(std::min(bottom_available, popup_required_height));
popup_bounds->set_y(bottom_growth_start);
} else {
// The popup must appear above the field.
popup_bounds->set_height(std::min(top_available, popup_required_height));
popup_bounds->set_y(top_growth_end - popup_bounds->height());
popup_bounds->set_y(top_growth_end - popup_required_height);
}
}
} // namespace
void PopupViewCommon::CalculatePopupHorizontalBounds(
int desired_width,
const gfx::Rect& element_bounds,
gfx::NativeView container_view,
bool is_rtl,
gfx::Rect* popup_bounds) {
const gfx::Rect bounds = GetWindowBounds(container_view);
CalculatePopupXAndWidth(/*leftmost_available_x=*/bounds.x(),
/*rightmost_available_x=*/bounds.x() + bounds.width(),
desired_width, element_bounds, is_rtl, popup_bounds);
}
void PopupViewCommon::CalculatePopupVerticalBounds(
int desired_height,
const gfx::Rect& element_bounds,
gfx::NativeView container_view,
gfx::Rect* popup_bounds) {
const gfx::Rect window_bounds = GetWindowBounds(container_view);
CalculatePopupYAndHeight(
/*topmost_available_y=*/window_bounds.y(),
/*bottommost_available_y=*/window_bounds.y() + window_bounds.height(),
desired_height, element_bounds, popup_bounds);
}
gfx::Rect PopupViewCommon::CalculatePopupBounds(int desired_width,
int desired_height,
const gfx::Rect& element_bounds,
gfx::NativeView container_view,
bool is_rtl) {
const gfx::Rect window_bounds = GetWindowBounds(container_view);
// This is the top left point of the popup if the popup is above the element
// and grows to the left (since that is the highest and furthest left the
// popup go could).
gfx::Point top_left_corner_of_popup =
element_bounds.origin() +
gfx::Vector2d(element_bounds.width() - desired_width, -desired_height);
// This is the bottom right point of the popup if the popup is below the
// element and grows to the right (since the is the lowest and furthest right
// the popup could go).
gfx::Point bottom_right_corner_of_popup =
element_bounds.origin() +
gfx::Vector2d(desired_width, element_bounds.height() + desired_height);
display::Display top_left_display =
GetDisplayNearestPoint(top_left_corner_of_popup, container_view);
display::Display bottom_right_display =
GetDisplayNearestPoint(bottom_right_corner_of_popup, container_view);
gfx::Rect popup_bounds;
CalculatePopupXAndWidth(
/*leftmost_available_x=*/window_bounds.x(),
/*rightmost_available_x=*/window_bounds.x() + window_bounds.width(),
desired_width, element_bounds, is_rtl, &popup_bounds);
CalculatePopupYAndHeight(
/*topmost_available_y=*/window_bounds.y(),
/*bottommost_available_y=*/window_bounds.y() + window_bounds.height(),
desired_height, element_bounds, &popup_bounds);
CalculatePopupXAndWidth(top_left_display, bottom_right_display, desired_width,
element_bounds, is_rtl, &popup_bounds);
CalculatePopupYAndHeight(top_left_display, bottom_right_display,
desired_height, element_bounds, &popup_bounds);
return popup_bounds;
}
gfx::Rect PopupViewCommon::GetWindowBounds(gfx::NativeView container_view) {
// The call to FindBrowserWithWindow will fail on Android, so we use
// platform-specific calls.
#if defined(OS_ANDROID)
return container_view->GetWindowAndroid()->bounds();
#else
gfx::NativeWindow window = platform_util::GetTopLevel(container_view);
Browser* browser = chrome::FindBrowserWithWindow(window);
DCHECK(browser);
return browser->window()->GetBounds();
#endif
display::Display PopupViewCommon::GetDisplayNearestPoint(
const gfx::Point& point,
gfx::NativeView container_view) {
return display::Screen::GetScreen()->GetDisplayNearestPoint(point);
}
} // namespace autofill
......@@ -6,37 +6,25 @@
#define CHROME_BROWSER_UI_AUTOFILL_POPUP_VIEW_COMMON_H_
#include "base/macros.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/native_widget_types.h"
namespace display {
class Display;
}
namespace gfx {
class Point;
class Rect;
} // namespace gfx
namespace autofill {
// Provides utility functions for popup-style views.
class PopupViewCommon {
public:
virtual ~PopupViewCommon() = default;
// Writes the |x| and |width| properties to |popup_bounds| for the popup's
// placement based on the element's location, the desired width, whether or
// not this is RTL, and the space available in the window to the left/right
// of the element.
void CalculatePopupHorizontalBounds(int desired_width,
const gfx::Rect& element_bounds,
gfx::NativeView container_view,
bool is_rtl,
gfx::Rect* popup_bounds);
// Writes the |y| and |height| properties to |popup_bounds| for the popup's
// placement based on the element's location, the desired height, and the
// space available in the window above/below the element. The popup will be
// placed below the element as long as there is sufficient space.
void CalculatePopupVerticalBounds(int desired_height,
const gfx::Rect& element_bounds,
gfx::NativeView container_view,
gfx::Rect* popup_bounds);
// Convenience method which handles both the vertical and horizontal bounds
// and returns a new Rect.
// Returns the bounds that the popup should be placed at, given the desired
// width and height. By default this places the popup below |element_bounds|
// but it will be placed above if there isn't enough space.
gfx::Rect CalculatePopupBounds(int desired_width,
int desired_height,
const gfx::Rect& element_bounds,
......@@ -44,9 +32,11 @@ class PopupViewCommon {
bool is_rtl);
protected:
// Returns the bounds of the containing window in screen space. Virtual for
// testing.
virtual gfx::Rect GetWindowBounds(gfx::NativeView container_view);
// A helper function to get the display closest to the given point (virtual
// for testing).
virtual display::Display GetDisplayNearestPoint(
const gfx::Point& point,
gfx::NativeView container_view);
};
} // namespace autofill
......
......@@ -9,7 +9,6 @@
#include <memory>
#include "base/macros.h"
#include "chrome/browser/ui/autofill/popup_view_test_helpers.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "content/public/browser/web_contents.h"
#include "ui/display/display.h"
......@@ -17,6 +16,26 @@
namespace autofill {
namespace {
// Test class which overrides specific behavior for testing.
class TestPopupViewCommon : public PopupViewCommon {
public:
explicit TestPopupViewCommon(const display::Display& display)
: display_(display) {}
display::Display GetDisplayNearestPoint(
const gfx::Point& point,
gfx::NativeView container_view) override {
return display_;
}
private:
display::Display display_;
};
} // namespace
class PopupViewCommonTest : public ChromeRenderViewHostTestHarness {
public:
PopupViewCommonTest() {}
......@@ -30,8 +49,10 @@ TEST_F(PopupViewCommonTest, CalculatePopupBounds) {
int desired_width = 40;
int desired_height = 16;
gfx::Rect window_bounds(0, 0, 2 * desired_width, 2 * desired_height);
MockPopupViewCommonForUnitTesting view_common(window_bounds);
// Set up the visible screen space.
display::Display display(
0, gfx::Rect(0, 0, 2 * desired_width, 2 * desired_height));
TestPopupViewCommon view_common(display);
struct {
gfx::Rect element_bounds;
......@@ -55,12 +76,12 @@ TEST_F(PopupViewCommonTest, CalculatePopupBounds) {
{gfx::Rect(2 * desired_width, 2 * desired_height, 5, 0),
gfx::Rect(desired_width, desired_height, desired_width, desired_height)},
// The popup would be partial off the top and left side of the window.
// The popup would be partial off the top and left side of the screen.
{gfx::Rect(-desired_width / 2, -desired_height / 2, 5, 0),
gfx::Rect(0, 0, desired_width, desired_height)},
// The popup would be partially off the bottom and the right side of
// the window.
// the screen.
{gfx::Rect(desired_width * 1.5, desired_height * 1.5, 5, 0),
gfx::Rect((desired_width * 1.5 + 5 - desired_width),
(desired_height * 1.5 - desired_height), desired_width,
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/autofill/popup_view_test_helpers.h"
namespace autofill {
gfx::Rect MockPopupViewCommonForUnitTesting::GetWindowBounds(
gfx::NativeView container_view) {
return window_bounds_;
}
} // namespace autofill
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_AUTOFILL_POPUP_VIEW_TEST_HELPERS_H_
#define CHROME_BROWSER_UI_AUTOFILL_POPUP_VIEW_TEST_HELPERS_H_
#include "chrome/browser/ui/autofill/popup_view_common.h"
namespace autofill {
// Attmepting to find the window's bounds in screen space will break in unit
// tests, so this safe version of the class must be used instead. The
// "interesting" geometry logic which calculates the bounds, determines the
// direction, etc. will still run.
class MockPopupViewCommonForUnitTesting : public PopupViewCommon {
public:
// Initializes with arbitrary default window bounds.
MockPopupViewCommonForUnitTesting()
: window_bounds_(gfx::Rect(0, 0, 1000, 1000)) {}
~MockPopupViewCommonForUnitTesting() override = default;
// Initializes with the given window bounds.
explicit MockPopupViewCommonForUnitTesting(const gfx::Rect& window_bounds)
: window_bounds_(window_bounds) {}
gfx::Rect GetWindowBounds(gfx::NativeView container_view) override;
private:
gfx::Rect window_bounds_;
DISALLOW_COPY_AND_ASSIGN(MockPopupViewCommonForUnitTesting);
};
} // namespace autofill
#endif // CHROME_BROWSER_UI_AUTOFILL_POPUP_VIEW_TEST_HELPERS_H_
......@@ -30,7 +30,6 @@
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/menu/menu_config.h"
#include "ui/views/controls/scroll_view.h"
#include "ui/views/controls/separator.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/fill_layout.h"
......@@ -53,10 +52,6 @@ const SkColor kSelectedBackgroundColor = gfx::kGoogleGrey200;
const SkColor kFooterBackgroundColor = gfx::kGoogleGrey050;
const SkColor kSeparatorColor = gfx::kGoogleGrey200;
// A space between the input element and the dropdown, so that the dropdown's
// border doesn't look too close to the element.
constexpr int kElementBorderPadding = 1;
int GetCornerRadius() {
return ChromeLayoutProvider::Get()->GetCornerRadiusMetric(
views::EMPHASIS_MEDIUM);
......@@ -384,9 +379,9 @@ AutofillPopupViewNativeViews::AutofillPopupViewNativeViews(
views::Widget* parent_widget)
: AutofillPopupBaseView(controller, parent_widget),
controller_(controller) {
layout_ = SetLayoutManager(
views::BoxLayout* layout = SetLayoutManager(
std::make_unique<views::BoxLayout>(views::BoxLayout::kVertical));
layout_->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START);
layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START);
CreateChildViews();
SetBackground(views::CreateSolidBackground(kAutofillBackgroundColor));
......@@ -405,6 +400,31 @@ void AutofillPopupViewNativeViews::Hide() {
DoHide();
}
gfx::Size AutofillPopupViewNativeViews::CalculatePreferredSize() const {
// The border of the input element should be aligned with the border of the
// dropdown when suggestions are not too wide.
int contents_width =
gfx::ToEnclosingRect(controller_->element_bounds()).width();
// Allow the dropdown to grow beyond the element width if it requires more
// horizontal space to render the suggestions.
gfx::Size size = AutofillPopupBaseView::CalculatePreferredSize();
if (contents_width < size.width()) {
contents_width = size.width();
// Use multiples of |kDropdownWidthMultiple| if the required width is larger
// than the element width.
if (contents_width % kDropdownWidthMultiple) {
contents_width +=
kDropdownWidthMultiple - (contents_width % kDropdownWidthMultiple);
}
}
// Notwithstanding all the above rules, enforce a hard minimum so the dropdown
// is not too small to interact with.
size.set_width(std::max(kDropdownMinWidth, contents_width));
return size;
}
void AutofillPopupViewNativeViews::VisibilityChanged(View* starting_from,
bool is_visible) {
if (is_visible) {
......@@ -487,12 +507,7 @@ void AutofillPopupViewNativeViews::CreateChildViews() {
line_number++;
}
scroll_view_ = new views::ScrollView();
scroll_view_->set_hide_horizontal_scrollbar(true);
scroll_view_->SetContents(body_container);
AddChildView(scroll_view_);
layout_->SetFlexForView(scroll_view_, 1);
scroll_view_->ClipHeightTo(0, body_container->GetPreferredSize().height());
AddChildView(body_container);
// All the remaining rows (where index >= |line_number|) are part of the
// footer. This needs to be in its own container because it should not be
......@@ -516,32 +531,7 @@ void AutofillPopupViewNativeViews::CreateChildViews() {
}
AddChildView(footer_container);
layout_->SetFlexForView(footer_container, 0);
}
}
int AutofillPopupViewNativeViews::AdjustWidth(int width) const {
// The border of the input element should be aligned with the border of the
// dropdown when suggestions are not too wide.
int adjusted_width =
gfx::ToEnclosingRect(controller_->element_bounds()).width();
// Allow the dropdown to grow beyond the element width if it requires more
// horizontal space to render the suggestions.
if (adjusted_width < width) {
adjusted_width = width;
// Use multiples of |kDropdownWidthMultiple| if the required width is larger
// than the element width.
if (adjusted_width % kDropdownWidthMultiple) {
adjusted_width +=
kDropdownWidthMultiple - (adjusted_width % kDropdownWidthMultiple);
}
}
// Notwithstanding all the above rules, enforce a hard minimum so the dropdown
// is not too small to interact with.
adjusted_width = std::max(kDropdownMinWidth, adjusted_width);
return adjusted_width;
}
void AutofillPopupViewNativeViews::AddExtraInitParams(
......@@ -574,42 +564,16 @@ std::unique_ptr<views::Border> AutofillPopupViewNativeViews::CreateBorder() {
}
void AutofillPopupViewNativeViews::DoUpdateBoundsAndRedrawPopup() {
gfx::Size size = CalculatePreferredSize();
gfx::Rect popup_bounds;
SizeToPreferredSize();
// When a bubble border is shown, the contents area (inside the shadow) is
// supposed to be aligned with input element boundaries.
gfx::Rect element_bounds =
gfx::ToEnclosingRect(controller_->element_bounds());
// Consider the element is |kElementBorderPadding| pixels larger at the top
// and at the bottom in order to reposition the dropdown, so that it doesn't
// look too close to the element.
element_bounds.Inset(/*horizontal=*/0, /*vertical=*/-kElementBorderPadding);
PopupViewCommon().CalculatePopupVerticalBounds(size.height(), element_bounds,
controller_->container_view(),
&popup_bounds);
// Adjust the width to compensate for a scroll bar, if necessary, and for
// other rules.
int scroll_width = 0;
if (size.height() > popup_bounds.height()) {
size.set_height(popup_bounds.height());
// Because the preferred size is greater than the bounds available, the
// contents will have to scroll. The scroll bar will steal width from the
// content and smoosh everything together. Instead, add to the width to
// compensate.
scroll_width = scroll_view_->GetScrollBarLayoutWidth();
}
size.set_width(AdjustWidth(size.width() + scroll_width));
PopupViewCommon().CalculatePopupHorizontalBounds(
size.width(), element_bounds, controller_->container_view(),
controller_->IsRTL(), &popup_bounds);
SetSize(size);
gfx::Rect popup_bounds = PopupViewCommon().CalculatePopupBounds(
size().width(), size().height(),
gfx::ToEnclosingRect(controller_->element_bounds()),
controller_->container_view(), controller_->IsRTL());
// Expand the widget bounds to include the border.
popup_bounds.Inset(-bubble_border_->GetInsets());
GetWidget()->SetBounds(popup_bounds);
......
......@@ -17,10 +17,6 @@
#include <memory>
#include <vector>
namespace views {
class BoxLayout;
}
namespace autofill {
class AutofillPopupController;
......@@ -80,6 +76,9 @@ class AutofillPopupViewNativeViews : public AutofillPopupBaseView,
void Show() override;
void Hide() override;
// views::View:
gfx::Size CalculatePreferredSize() const override;
// AutofillPopupBaseView:
// TODO(crbug.com/831603): Remove these overrides and the corresponding
// methods in AutofillPopupBaseView once deprecation of
......@@ -97,10 +96,6 @@ class AutofillPopupViewNativeViews : public AutofillPopupBaseView,
// Creates child views based on the suggestions given by |controller_|.
void CreateChildViews();
// Applies certain rounding rules to the given width, such as matching the
// element width when possible.
int AdjustWidth(int width) const;
// AutofillPopupBaseView:
void AddExtraInitParams(views::Widget::InitParams* params) override;
std::unique_ptr<views::View> CreateWrapperView() override;
......@@ -109,10 +104,10 @@ class AutofillPopupViewNativeViews : public AutofillPopupBaseView,
// Controller for this view.
AutofillPopupController* controller_;
std::vector<AutofillPopupRowView*> rows_;
views::BubbleBorder* bubble_border_;
views::BoxLayout* layout_;
views::ScrollView* scroll_view_;
DISALLOW_COPY_AND_ASSIGN(AutofillPopupViewNativeViews);
};
......
......@@ -233,12 +233,7 @@ TEST_P(AutofillPopupViewNativeViewsForEveryTypeTest, ShowClickTest) {
EXPECT_CALL(autofill_popup_controller_, AcceptSuggestion(::testing::_))
.Times(click.click);
gfx::Point center =
view()->GetRowsForTesting()[0]->GetBoundsInScreen().CenterPoint();
// Because we use GetBoundsInScreen above, and because macOS may reposition
// the window, we need to turn this bit off or the clicks will miss their
// targets.
generator_->set_assume_window_at_origin(false);
view()->GetRowsForTesting()[0]->GetLocalBounds().CenterPoint();
generator_->set_current_location(center);
generator_->ClickLeftButton();
view()->RemoveAllChildViews(true /* delete_children */);
......
......@@ -2619,8 +2619,6 @@ test("unit_tests") {
"../browser/ui/autofill/autofill_dialog_models_unittest.cc",
"../browser/ui/autofill/autofill_popup_layout_model_unittest.cc",
"../browser/ui/autofill/popup_view_common_unittest.cc",
"../browser/ui/autofill/popup_view_test_helpers.cc",
"../browser/ui/autofill/popup_view_test_helpers.h",
"../browser/ui/bloated_renderer/bloated_renderer_tab_helper_unittest.cc",
"../browser/ui/blocked_content/popup_opener_tab_helper_unittest.cc",
"../browser/ui/blocked_content/safe_browsing_triggered_popup_blocker_unittest.cc",
......
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