Commit 649aa432 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Convert MenuScrollViewContainer to use LayoutManager.

Bug: 1005568
Change-Id: I2843b0da4c1e343f1493f0892cad2c7ddfc5a56c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1836669
Commit-Queue: Peter Boström <pbos@chromium.org>
Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#702491}
parent 84c8b188
......@@ -994,7 +994,7 @@ class BookmarkBarViewTest9 : public BookmarkBarViewEventTestBase {
ASSERT_TRUE(scroll_container != NULL);
scroll_container = scroll_container->parent();
ASSERT_TRUE(scroll_container != NULL);
views::View* scroll_down_button = scroll_container->children()[1];
views::View* scroll_down_button = scroll_container->children()[2];
ASSERT_TRUE(scroll_down_button);
gfx::Point loc(scroll_down_button->width() / 2,
scroll_down_button->height() / 2);
......
......@@ -17,7 +17,9 @@
#include "ui/views/controls/menu/menu_controller.h"
#include "ui/views/controls/menu/menu_item_view.h"
#include "ui/views/controls/menu/submenu_view.h"
#include "ui/views/layout/flex_layout.h"
#include "ui/views/round_rect_painter.h"
#include "ui/views/view_class_properties.h"
using ui::NativeTheme;
......@@ -172,13 +174,20 @@ class MenuScrollViewContainer::MenuScrollView : public View {
MenuScrollViewContainer::MenuScrollViewContainer(SubmenuView* content_view)
: content_view_(content_view) {
scroll_up_button_ = new MenuScrollButton(content_view, true);
scroll_down_button_ = new MenuScrollButton(content_view, false);
AddChildView(scroll_up_button_);
AddChildView(scroll_down_button_);
auto* layout = SetLayoutManager(std::make_unique<views::FlexLayout>());
layout->SetOrientation(views::LayoutOrientation::kVertical);
scroll_view_ = new MenuScrollView(content_view);
AddChildView(scroll_view_);
scroll_up_button_ =
AddChildView(std::make_unique<MenuScrollButton>(content_view, true));
scroll_view_ = AddChildView(std::make_unique<MenuScrollView>(content_view));
scroll_view_->SetProperty(views::kFlexBehaviorKey,
views::FlexSpecification::ForSizeRule(
views::MinimumFlexSizeRule::kScaleToMinimum,
views::MaximumFlexSizeRule::kUnbounded));
scroll_down_button_ =
AddChildView(std::make_unique<MenuScrollButton>(content_view, false));
arrow_ = BubbleBorderTypeFromAnchor(
content_view_->GetMenuItem()->GetMenuController()->GetAnchorPosition());
......@@ -191,10 +200,10 @@ bool MenuScrollViewContainer::HasBubbleBorder() const {
}
MenuItemView* MenuScrollViewContainer::GetFootnote() const {
MenuItemView* footnote = content_view_->GetLastItem();
if (!footnote || footnote->GetType() != MenuItemView::HIGHLIGHTED)
return nullptr;
return footnote;
MenuItemView* const footnote = content_view_->GetLastItem();
return (footnote && footnote->GetType() == MenuItemView::HIGHLIGHTED)
? footnote
: nullptr;
}
gfx::Size MenuScrollViewContainer::CalculatePreferredSize() const {
......@@ -208,42 +217,6 @@ gfx::Size MenuScrollViewContainer::CalculatePreferredSize() const {
return prefsize;
}
void MenuScrollViewContainer::Layout() {
gfx::Insets insets = GetInsets();
int x = insets.left();
int y = insets.top();
int width = View::width() - insets.width();
int content_height = height() - insets.height();
MenuItemView* footnote = GetFootnote();
if (!scroll_up_button_->GetVisible()) {
if (footnote)
footnote->SetCornerRadius(corner_radius_);
scroll_view_->SetBounds(x, y, width, content_height);
scroll_view_->Layout();
return;
}
// Don't round the footnote when the scroll button is visible.
if (footnote) {
footnote->SetCornerRadius(0);
content_height -= corner_radius_;
}
gfx::Size pref = scroll_up_button_->GetPreferredSize();
scroll_up_button_->SetBounds(x, y, width, pref.height());
content_height -= pref.height();
const int scroll_view_y = y + pref.height();
pref = scroll_down_button_->GetPreferredSize();
scroll_down_button_->SetBounds(x, height() - pref.height() - insets.top(),
width, pref.height());
content_height -= pref.height();
scroll_view_->SetBounds(x, scroll_view_y, width, content_height);
scroll_view_->Layout();
}
void MenuScrollViewContainer::OnThemeChanged() {
if (!HasBubbleBorder())
CreateDefaultBorder();
......@@ -272,9 +245,13 @@ void MenuScrollViewContainer::GetAccessibleNodeData(ui::AXNodeData* node_data) {
void MenuScrollViewContainer::OnBoundsChanged(
const gfx::Rect& previous_bounds) {
gfx::Size content_pref = scroll_view_->GetContents()->GetPreferredSize();
scroll_up_button_->SetVisible(content_pref.height() > height());
scroll_down_button_->SetVisible(content_pref.height() > height());
const bool scroll_buttons_visible =
scroll_view_->GetContents()->GetPreferredSize().height() > height();
scroll_up_button_->SetVisible(scroll_buttons_visible);
scroll_down_button_->SetVisible(scroll_buttons_visible);
MenuItemView* const footnote = GetFootnote();
if (footnote)
footnote->SetCornerRadius(scroll_buttons_visible ? 0 : corner_radius_);
InvalidateLayout();
}
......@@ -291,12 +268,11 @@ void MenuScrollViewContainer::CreateDefaultBorder() {
const MenuConfig& menu_config = MenuConfig::instance();
const ui::NativeTheme* native_theme = GetNativeTheme();
MenuController* controller =
content_view_->GetMenuItem()->GetMenuController();
bool use_outer_border =
menu_config.use_outer_border ||
(native_theme && native_theme->UsesHighContrastColors());
corner_radius_ = menu_config.CornerRadiusForMenu(controller);
corner_radius_ = menu_config.CornerRadiusForMenu(
content_view_->GetMenuItem()->GetMenuController());
int padding = use_outer_border && corner_radius_ > 0
? kBorderPaddingDueToRoundedCorners
: 0;
......
......@@ -35,7 +35,6 @@ class MenuScrollViewContainer : public View {
// View overrides.
gfx::Size CalculatePreferredSize() const override;
void Layout() override;
void OnPaintBackground(gfx::Canvas* canvas) override;
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
void OnThemeChanged() 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