Commit e17bd787 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Use LayoutManager for OverlayScrollBar.

As with ScrollBarViews, this can just size the thumb extra-large and rely on
ScrollBar::Update() to do the real sizing.  To facilitate this, override
GetInsets() to convert GetContentsBounds() into the same thing as
GetTrackBounds(), then use a FillLayout.

Also reorders functions to match superclass order and access level.

Bug: 1005568
Change-Id: Iad7fed5501adcf301ac66f9390c2545a6e00c827
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1824028
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Robert Liao <robliao@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699584}
parent 98ba2124
......@@ -13,6 +13,7 @@
#include "ui/native_theme/overlay_scrollbar_constants_aura.h"
#include "ui/views/background.h"
#include "ui/views/border.h"
#include "ui/views/layout/fill_layout.h"
namespace views {
namespace {
......@@ -125,52 +126,45 @@ void OverlayScrollBar::Thumb::OnStateChanged() {
}
OverlayScrollBar::OverlayScrollBar(bool horizontal) : ScrollBar(horizontal) {
auto* thumb = new Thumb(this);
SetThumb(thumb);
thumb->Init();
set_notify_enter_exit_on_child(true);
SetPaintToLayer();
layer()->SetMasksToBounds(true);
layer()->SetFillsBoundsOpaquely(false);
// Allow the thumb to take up the whole size of the scrollbar. Layout need
// only set the thumb cross-axis coordinate; ScrollBar::Update() will set the
// thumb size/offset.
SetLayoutManager(std::make_unique<views::FillLayout>());
auto* thumb = new Thumb(this);
SetThumb(thumb);
thumb->Init();
}
OverlayScrollBar::~OverlayScrollBar() = default;
gfx::Rect OverlayScrollBar::GetTrackBounds() const {
gfx::Rect local = GetLocalBounds();
// The track has to be wide enough for the thumb.
local.Inset(gfx::Insets(IsHorizontal() ? -kThumbHoverOffset : 0,
IsHorizontal() ? 0 : -kThumbHoverOffset, 0, 0));
return local;
gfx::Insets OverlayScrollBar::GetInsets() const {
return IsHorizontal() ? gfx::Insets(-kThumbHoverOffset, 0, 0, 0)
: gfx::Insets(0, -kThumbHoverOffset, 0, 0);
}
int OverlayScrollBar::GetThickness() const {
return kThumbThickness;
void OverlayScrollBar::OnMouseEntered(const ui::MouseEvent& event) {
Show();
}
bool OverlayScrollBar::OverlapsContent() const {
return true;
void OverlayScrollBar::OnMouseExited(const ui::MouseEvent& event) {
StartHideCountdown();
}
void OverlayScrollBar::Layout() {
gfx::Rect thumb_bounds = GetTrackBounds();
BaseScrollBarThumb* thumb = GetThumb();
if (IsHorizontal()) {
thumb_bounds.set_x(thumb->x());
thumb_bounds.set_width(thumb->width());
} else {
thumb_bounds.set_y(thumb->y());
thumb_bounds.set_height(thumb->height());
}
thumb->SetBoundsRect(thumb_bounds);
bool OverlayScrollBar::OverlapsContent() const {
return true;
}
void OverlayScrollBar::OnMouseEntered(const ui::MouseEvent& event) {
Show();
gfx::Rect OverlayScrollBar::GetTrackBounds() const {
return GetContentsBounds();
}
void OverlayScrollBar::OnMouseExited(const ui::MouseEvent& event) {
StartHideCountdown();
int OverlayScrollBar::GetThickness() const {
return kThumbThickness;
}
void OverlayScrollBar::Show() {
......
......@@ -20,18 +20,13 @@ class VIEWS_EXPORT OverlayScrollBar : public ScrollBar {
explicit OverlayScrollBar(bool horizontal);
~OverlayScrollBar() override;
protected:
// ScrollBar overrides:
gfx::Rect GetTrackBounds() const override;
// ScrollBar overrides:
int GetThickness() const override;
bool OverlapsContent() const override;
// View overrides:
void Layout() override;
// ScrollBar:
gfx::Insets GetInsets() const override;
void OnMouseEntered(const ui::MouseEvent& event) override;
void OnMouseExited(const ui::MouseEvent& event) override;
bool OverlapsContent() const override;
gfx::Rect GetTrackBounds() const override;
int GetThickness() const override;
private:
class Thumb : public BaseScrollBarThumb {
......
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