Commit 0597e2b8 authored by Dana Fried's avatar Dana Fried Committed by Commit Bot

Improvements to support scrollable tabstrip.

Creates a mode that allows scrolling without a scrollbar in either
direction as well as the ability to treat scroll-specific events (e.g.
mousewheel events) as horizontal scroll inputs.

Changes:
* Adds a third scrollbar state: visible but not enabled
* Allows enabled/disabled/invisible state for vertical scrollbar as well
as horizontal (previously only horizontal scrollbar could be hidden/
disabled).
* Adds the option to treat vertical scroll events as horizontal, so that
for example a mousewheel or vertical scroll gesture can allow a
horizontal-scroll-only pane to scroll.

Bug: 1122214
Change-Id: I7f01b26b33ede76e1903ee37a493a2818b7b1103
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2433254
Commit-Queue: Dana Fried <dfried@chromium.org>
Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
Reviewed-by: default avatarCharlene Yan <cyan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#813839}
parent 6e104a7d
......@@ -1163,7 +1163,8 @@ void AutofillPopupViewNativeViews::CreateChildViews() {
}
scroll_view_ = new views::ScrollView();
scroll_view_->SetHideHorizontalScrollBar(true);
scroll_view_->SetHorizontalScrollBarMode(
views::ScrollView::ScrollBarMode::kDisabled);
body_container_ = scroll_view_->SetContents(std::move(body_container));
scroll_view_->SetDrawOverflowIndicator(false);
scroll_view_->ClipHeightTo(0, body_container_->GetPreferredSize().height());
......
......@@ -160,7 +160,8 @@ std::unique_ptr<views::ScrollView> CreateCardList(
}
auto card_list_scroll_view = std::make_unique<views::ScrollView>();
card_list_scroll_view->SetHideHorizontalScrollBar(true);
card_list_scroll_view->SetHorizontalScrollBarMode(
views::ScrollView::ScrollBarMode::kDisabled);
card_list_scroll_view->SetContents(std::move(card_list_view));
card_list_scroll_view->SetDrawOverflowIndicator(false);
constexpr int kCardListScrollViewHeight = 140;
......
......@@ -126,7 +126,8 @@ DesktopMediaPickerDialogView::DesktopMediaPickerDialogView(
screen_scroll_view->ClipHeightTo(
kGenericScreenStyle.item_size.height(),
kGenericScreenStyle.item_size.height() * 2);
screen_scroll_view->SetHideHorizontalScrollBar(true);
screen_scroll_view->SetHorizontalScrollBarMode(
views::ScrollView::ScrollBarMode::kDisabled);
panes.push_back(
std::make_pair(screen_title_text, std::move(screen_scroll_view)));
......@@ -156,7 +157,8 @@ DesktopMediaPickerDialogView::DesktopMediaPickerDialogView(
window_scroll_view->ClipHeightTo(kWindowStyle.item_size.height(),
kWindowStyle.item_size.height() * 2);
window_scroll_view->SetHideHorizontalScrollBar(true);
window_scroll_view->SetHorizontalScrollBarMode(
views::ScrollView::ScrollBarMode::kDisabled);
panes.push_back(
std::make_pair(window_title_text, std::move(window_scroll_view)));
......
......@@ -121,7 +121,8 @@ void ExtensionInstallBlockedDialogView::AddCustomMessageContents(
header_label->SizeToFit(content_width);
auto* scroll_view = AddChildView(std::make_unique<views::ScrollView>());
scroll_view->SetHideHorizontalScrollBar(true);
scroll_view->SetHorizontalScrollBarMode(
views::ScrollView::ScrollBarMode::kDisabled);
scroll_view->SetContents(std::move(extension_info_container));
scroll_view->ClipHeightTo(
0, provider->GetDistanceMetric(
......
......@@ -520,7 +520,8 @@ void ExtensionInstallDialogView::CreateContents() {
}
scroll_view_ = new views::ScrollView();
scroll_view_->SetHideHorizontalScrollBar(true);
scroll_view_->SetHorizontalScrollBarMode(
views::ScrollView::ScrollBarMode::kDisabled);
scroll_view_->SetContents(std::move(extension_info_container));
scroll_view_->ClipHeightTo(
0, provider->GetDistanceMetric(
......
......@@ -132,7 +132,8 @@ void ExtensionsMenuView::Populate() {
auto scroll_view = std::make_unique<views::ScrollView>();
scroll_view->ClipHeightTo(0, kMaxExtensionButtonsHeightDp);
scroll_view->SetDrawOverflowIndicator(false);
scroll_view->SetHideHorizontalScrollBar(true);
scroll_view->SetHorizontalScrollBarMode(
views::ScrollView::ScrollBarMode::kDisabled);
scroll_view->SetContents(std::move(extension_buttons));
AddChildView(std::move(scroll_view));
......
......@@ -17,6 +17,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/views/frame/browser_frame.h"
#include "chrome/browser/ui/views/tabs/tab_strip.h"
#include "chrome/browser/ui/views/tabs/tab_strip_controller.h"
......@@ -259,7 +260,13 @@ const char* BrowserRootView::GetClassName() const {
}
bool BrowserRootView::OnMouseWheel(const ui::MouseWheelEvent& event) {
if (browser_defaults::kScrollEventChangesTab) {
// TODO(dfried): See if it's possible to move this logic deeper into the view
// hierarchy - ideally to TabStripRegionView.
// Scroll-event-changes-tab is incompatible with scrolling tabstrip, so
// disable it if the latter feature is enabled.
if (browser_defaults::kScrollEventChangesTab &&
!base::FeatureList::IsEnabled(features::kScrollableTabStrip)) {
// Switch to the left/right tab if the wheel-scroll happens over the
// tabstrip, or the empty space beside the tabstrip.
views::View* hit_view = GetEventHandlerForPoint(event.location());
......
......@@ -31,7 +31,8 @@ TabStripRegionView::TabStripRegionView(std::unique_ptr<TabStrip> tab_strip) {
AddChildView(std::make_unique<views::ScrollView>(
views::ScrollView::ScrollWithLayers::kEnabled));
tab_strip_scroll_container->SetBackgroundColor(base::nullopt);
tab_strip_scroll_container->SetHideHorizontalScrollBar(true);
tab_strip_scroll_container->SetHorizontalScrollBarMode(
views::ScrollView::ScrollBarMode::kDisabled);
tab_strip_container_ = tab_strip_scroll_container;
tab_strip_scroll_container->SetContents(std::move(tab_strip));
} else {
......
......@@ -253,7 +253,8 @@ std::unique_ptr<views::View> PaymentRequestSheetController::CreateView() {
scroll_ = layout->AddView(DisplayDynamicBorderForHiddenContents()
? std::make_unique<BorderedScrollView>()
: std::make_unique<views::ScrollView>());
scroll_->SetHideHorizontalScrollBar(true);
scroll_->SetHorizontalScrollBarMode(
views::ScrollView::ScrollBarMode::kDisabled);
pane_ = scroll_->SetContents(std::make_unique<views::View>());
views::GridLayout* pane_layout =
pane_->SetLayoutManager(std::make_unique<views::GridLayout>());
......
......@@ -913,7 +913,8 @@ void ProfileMenuViewBase::Reset() {
// Create a scroll view to hold the components.
auto scroll_view = std::make_unique<views::ScrollView>();
scroll_view->SetHideHorizontalScrollBar(true);
scroll_view->SetHorizontalScrollBarMode(
views::ScrollView::ScrollBarMode::kDisabled);
// TODO(https://crbug.com/871762): it's a workaround for the crash.
scroll_view->SetDrawOverflowIndicator(false);
scroll_view->ClipHeightTo(0, GetMaxHeight());
......
......@@ -460,7 +460,8 @@ void ParentPermissionDialogView::CreateContents() {
// Add section container to an enclosing scroll view.
auto scroll_view = std::make_unique<views::ScrollView>();
scroll_view->SetHideHorizontalScrollBar(true);
scroll_view->SetHorizontalScrollBarMode(
views::ScrollView::ScrollBarMode::kDisabled);
scroll_view->SetContents(std::move(install_permissions_section_container));
scroll_view->ClipHeightTo(
0, provider->GetDistanceMetric(
......
This diff is collapsed.
......@@ -50,6 +50,19 @@ class VIEWS_EXPORT ScrollView : public View, public ScrollBarController {
// Indicates whether or not scroll view is initialized with layer-scrolling.
enum class ScrollWithLayers { kDisabled, kEnabled };
// Controls how a scroll bar appears and functions.
enum class ScrollBarMode {
// The scrollbar is hidden, and the pane will not respond to e.g. mousewheel
// events even if the contents are larger than the viewport.
kDisabled,
// The scrollbar is hidden whether or not the contents are larger than the
// viewport, but the pane will respond to scroll events.
kHiddenButEnabled,
// The scrollbar will be visible if the contents are larger than the
// viewport and the pane will respond to scroll events.
kEnabled
};
ScrollView();
// Additional constructor for overriding scrolling as defined by
......@@ -110,8 +123,19 @@ class VIEWS_EXPORT ScrollView : public View, public ScrollBarController {
bool GetUseColorId() const { return !!background_color_id_; }
bool GetHideHorizontalScrollBar() const { return hide_horizontal_scrollbar_; }
void SetHideHorizontalScrollBar(bool visible);
ScrollBarMode GetHorizontalScrollBarMode() const {
return horizontal_scroll_bar_mode_;
}
ScrollBarMode GetVerticalScrollBarMode() const {
return vertical_scroll_bar_mode_;
}
bool GetTreatAllScrollEventsAsHorizontal() const {
return treat_all_scroll_events_as_horizontal_;
}
void SetHorizontalScrollBarMode(ScrollBarMode horizontal_scroll_bar_mode);
void SetVerticalScrollBarMode(ScrollBarMode vertical_scroll_bar_mode);
void SetTreatAllScrollEventsAsHorizontal(
bool treat_all_scroll_events_as_horizontal);
bool GetDrawOverflowIndicator() const { return draw_overflow_indicator_; }
void SetDrawOverflowIndicator(bool draw_overflow_indicator);
......@@ -165,6 +189,9 @@ class VIEWS_EXPORT ScrollView : public View, public ScrollBarController {
class Viewport;
bool IsHorizontalScrollEnabled() const;
bool IsVerticalScrollEnabled() const;
// Forces |contents_viewport_| to have a Layer (assuming it doesn't already).
void EnableViewportLayer();
......@@ -269,9 +296,14 @@ class VIEWS_EXPORT ScrollView : public View, public ScrollBarController {
base::Optional<ui::NativeTheme::ColorId> background_color_id_ =
ui::NativeTheme::kColorId_DialogBackground;
// If true, never show the horizontal scrollbar (even if the contents is wider
// than the viewport).
bool hide_horizontal_scrollbar_ = false;
// How to handle the case when the contents overflow the viewport.
ScrollBarMode horizontal_scroll_bar_mode_ = ScrollBarMode::kEnabled;
ScrollBarMode vertical_scroll_bar_mode_ = ScrollBarMode::kEnabled;
// Causes vertical scroll events (e.g. scrolling with the mousewheel) as
// horizontal events, to make scrolling in horizontal-only scroll situations
// easier for the user.
bool treat_all_scroll_events_as_horizontal_ = false;
// In Harmony, the indicator is a focus ring. Pre-Harmony, the indicator is a
// different border painter.
......@@ -298,7 +330,9 @@ VIEW_BUILDER_VIEW_TYPE_PROPERTY(View, Contents)
VIEW_BUILDER_VIEW_TYPE_PROPERTY(View, Header)
VIEW_BUILDER_PROPERTY(base::Optional<ui::NativeTheme::ColorId>,
BackgroundThemeColorId)
VIEW_BUILDER_PROPERTY(bool, HideHorizontalScrollBar)
VIEW_BUILDER_PROPERTY(ScrollView::ScrollBarMode, HorizontalScrollBarMode)
VIEW_BUILDER_PROPERTY(ScrollView::ScrollBarMode, VerticalScrollBarMode)
VIEW_BUILDER_PROPERTY(bool, TreatAllScrollEventsAsHorizontal)
VIEW_BUILDER_PROPERTY(bool, DrawOverflowIndicator)
VIEW_BUILDER_PROPERTY(base::Optional<SkColor>, BackgroundColor)
VIEW_BUILDER_VIEW_PROPERTY(ScrollBar, HorizontalScrollBar)
......
This diff is collapsed.
......@@ -14,6 +14,7 @@
#include "ui/base/ime/text_input_type.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/native_theme/native_theme.h"
#include "ui/views/controls/scroll_view.h"
namespace views {
namespace metadata {
......@@ -354,6 +355,14 @@ DEFINE_ENUM_CONVERTERS(ui::MenuSeparatorType,
{ui::MenuSeparatorType::PADDED_SEPARATOR,
base::ASCIIToUTF16("PADDED_SEPARATOR")})
DEFINE_ENUM_CONVERTERS(views::ScrollView::ScrollBarMode,
{views::ScrollView::ScrollBarMode::kDisabled,
base::ASCIIToUTF16("kDisabled")},
{views::ScrollView::ScrollBarMode::kHiddenButEnabled,
base::ASCIIToUTF16("kHiddenButEnabled")},
{views::ScrollView::ScrollBarMode::kEnabled,
base::ASCIIToUTF16("kEnabled")})
#define OP(enum_name) \
{ ui::NativeTheme::enum_name, base::ASCIIToUTF16(#enum_name) }
DEFINE_ENUM_CONVERTERS(ui::NativeTheme::ColorId, NATIVE_THEME_COLOR_IDS)
......
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