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 @@ ...@@ -13,6 +13,7 @@
#include "ui/native_theme/overlay_scrollbar_constants_aura.h" #include "ui/native_theme/overlay_scrollbar_constants_aura.h"
#include "ui/views/background.h" #include "ui/views/background.h"
#include "ui/views/border.h" #include "ui/views/border.h"
#include "ui/views/layout/fill_layout.h"
namespace views { namespace views {
namespace { namespace {
...@@ -125,52 +126,45 @@ void OverlayScrollBar::Thumb::OnStateChanged() { ...@@ -125,52 +126,45 @@ void OverlayScrollBar::Thumb::OnStateChanged() {
} }
OverlayScrollBar::OverlayScrollBar(bool horizontal) : ScrollBar(horizontal) { OverlayScrollBar::OverlayScrollBar(bool horizontal) : ScrollBar(horizontal) {
auto* thumb = new Thumb(this);
SetThumb(thumb);
thumb->Init();
set_notify_enter_exit_on_child(true); set_notify_enter_exit_on_child(true);
SetPaintToLayer(); SetPaintToLayer();
layer()->SetMasksToBounds(true); layer()->SetMasksToBounds(true);
layer()->SetFillsBoundsOpaquely(false); 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; OverlayScrollBar::~OverlayScrollBar() = default;
gfx::Rect OverlayScrollBar::GetTrackBounds() const { gfx::Insets OverlayScrollBar::GetInsets() const {
gfx::Rect local = GetLocalBounds(); return IsHorizontal() ? gfx::Insets(-kThumbHoverOffset, 0, 0, 0)
// The track has to be wide enough for the thumb. : gfx::Insets(0, -kThumbHoverOffset, 0, 0);
local.Inset(gfx::Insets(IsHorizontal() ? -kThumbHoverOffset : 0,
IsHorizontal() ? 0 : -kThumbHoverOffset, 0, 0));
return local;
} }
int OverlayScrollBar::GetThickness() const { void OverlayScrollBar::OnMouseEntered(const ui::MouseEvent& event) {
return kThumbThickness; Show();
} }
bool OverlayScrollBar::OverlapsContent() const { void OverlayScrollBar::OnMouseExited(const ui::MouseEvent& event) {
return true; StartHideCountdown();
} }
void OverlayScrollBar::Layout() { bool OverlayScrollBar::OverlapsContent() const {
gfx::Rect thumb_bounds = GetTrackBounds(); return true;
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);
} }
void OverlayScrollBar::OnMouseEntered(const ui::MouseEvent& event) { gfx::Rect OverlayScrollBar::GetTrackBounds() const {
Show(); return GetContentsBounds();
} }
void OverlayScrollBar::OnMouseExited(const ui::MouseEvent& event) { int OverlayScrollBar::GetThickness() const {
StartHideCountdown(); return kThumbThickness;
} }
void OverlayScrollBar::Show() { void OverlayScrollBar::Show() {
......
...@@ -20,18 +20,13 @@ class VIEWS_EXPORT OverlayScrollBar : public ScrollBar { ...@@ -20,18 +20,13 @@ class VIEWS_EXPORT OverlayScrollBar : public ScrollBar {
explicit OverlayScrollBar(bool horizontal); explicit OverlayScrollBar(bool horizontal);
~OverlayScrollBar() override; ~OverlayScrollBar() override;
protected: // ScrollBar:
// ScrollBar overrides: gfx::Insets GetInsets() const override;
gfx::Rect GetTrackBounds() const override;
// ScrollBar overrides:
int GetThickness() const override;
bool OverlapsContent() const override;
// View overrides:
void Layout() override;
void OnMouseEntered(const ui::MouseEvent& event) override; void OnMouseEntered(const ui::MouseEvent& event) override;
void OnMouseExited(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: private:
class Thumb : public BaseScrollBarThumb { 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