1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
// Copyright 2011 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_VIEWS_CONTROLS_MENU_MENU_SCROLL_VIEW_CONTAINER_H_
#define UI_VIEWS_CONTROLS_MENU_MENU_SCROLL_VIEW_CONTAINER_H_
#include "base/memory/raw_ptr.h"
#include "ui/views/bubble/bubble_border.h"
#include "ui/views/controls/menu/menu_types.h"
#include "ui/views/view.h"
#include "ui/views/views_export.h"
namespace gfx {
class RoundedCornersF;
} // namespace gfx
namespace views {
class MenuItemView;
class SubmenuView;
// MenuScrollViewContainer contains the SubmenuView (through a MenuScrollView)
// and two scroll buttons. The scroll buttons are only visible and enabled if
// the preferred height of the SubmenuView is bigger than our bounds.
class VIEWS_EXPORT MenuScrollViewContainer : public View {
METADATA_HEADER(MenuScrollViewContainer, View)
public:
explicit MenuScrollViewContainer(SubmenuView* content_view);
MenuScrollViewContainer(const MenuScrollViewContainer&) = delete;
MenuScrollViewContainer& operator=(const MenuScrollViewContainer&) = delete;
// Returns the buttons for scrolling up/down.
View* scroll_down_button() const { return scroll_down_button_; }
View* scroll_up_button() const { return scroll_up_button_; }
// External function to check if the bubble border is used.
bool HasBubbleBorder() const;
// View:
gfx::Insets GetInsets() const override;
gfx::Size CalculatePreferredSize(
const SizeBounds& available_size) const override;
void OnPaintBackground(gfx::Canvas* canvas) override;
void OnThemeChanged() override;
void SetBorderColorId(std::optional<ui::ColorId> border_color_id) {
border_color_id_ = border_color_id;
}
gfx::Insets outside_border_insets() const { return outside_border_insets_; }
protected:
// View override.
void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
private:
friend class MenuScrollView;
void DidScrollToTop();
void DidScrollToBottom();
void DidScrollAwayFromTop();
void DidScrollAwayFromBottom();
// Create a default border or bubble border, as appropriate.
void CreateBorder();
// Create the default border.
void CreateDefaultBorder();
// Create the bubble border.
void CreateBubbleBorder();
BubbleBorder::Arrow BubbleBorderTypeFromAnchor(MenuAnchorPosition anchor);
// Returns the last item in the menu if it is of type HIGHLIGHTED.
MenuItemView* GetFootnote() const;
// Returns the corner radius according to the `MenuConfig`.
int GetCornerRadius() const;
// Calculates the rounded corners of the view based on either
// `rounded_corners()` if it's set in `MenuController`, or else
// `GetCornerRadius()`.
gfx::RoundedCornersF GetRoundedCorners() const;
class MenuScrollView;
// The background view.
raw_ptr<View> background_view_ = nullptr;
// The scroll buttons.
raw_ptr<View> scroll_up_button_;
raw_ptr<View> scroll_down_button_;
// The scroll view.
raw_ptr<MenuScrollView> scroll_view_;
// The content view.
raw_ptr<SubmenuView> content_view_;
// If set the currently set border is a bubble border.
BubbleBorder::Arrow arrow_ = BubbleBorder::NONE;
gfx::RoundedCornersF background_rounded_corners_;
// The portion of GetInsets() that represent the region outside the border
// (e.g. any shadows).
gfx::Insets outside_border_insets_;
// Any additional insets to add inside the border.
gfx::Insets additional_insets_;
// Whether the menu uses ash system UI layout.
const bool use_ash_system_ui_layout_;
std::optional<ui::ColorId> border_color_id_;
};
} // namespace views
#endif // UI_VIEWS_CONTROLS_MENU_MENU_SCROLL_VIEW_CONTAINER_H_
|