Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(410)

Unified Diff: ui/views/controls/scrollbar/base_scroll_bar.cc

Issue 1769553003: Guard against division by zero for useless scroll bars. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/controls/scrollbar/base_scroll_bar.h ('k') | ui/views/controls/scrollbar/scrollbar_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/scrollbar/base_scroll_bar.cc
diff --git a/ui/views/controls/scrollbar/base_scroll_bar.cc b/ui/views/controls/scrollbar/base_scroll_bar.cc
index be0740f6b2cb3b8c6edefefd317ea0e11fac0346..e9333e1458c81e97e8522c04364e4177fc1b0ab7 100644
--- a/ui/views/controls/scrollbar/base_scroll_bar.cc
+++ b/ui/views/controls/scrollbar/base_scroll_bar.cc
@@ -413,7 +413,8 @@ void BaseScrollBar::Update(int viewport_size,
// Thumb Height and Thumb Pos.
// The height of the thumb is the ratio of the Viewport height to the
// content size multiplied by the height of the thumb track.
- double ratio = static_cast<double>(viewport_size) / contents_size_;
+ double ratio =
+ std::min(1.0, static_cast<double>(viewport_size) / contents_size_);
int thumb_size = static_cast<int>(ratio * GetTrackSize());
thumb_->SetSize(thumb_size);
@@ -505,10 +506,13 @@ int BaseScrollBar::CalculateThumbPosition(int contents_scroll_offset) const {
int BaseScrollBar::CalculateContentsOffset(int thumb_position,
bool scroll_to_middle) const {
int thumb_size = thumb_->GetSize();
+ int track_size = GetTrackSize();
+ if (track_size == thumb_size)
+ return 0;
if (scroll_to_middle)
thumb_position = thumb_position - (thumb_size / 2);
return (thumb_position * (contents_size_ - viewport_size_)) /
- (GetTrackSize() - thumb_size);
+ (track_size - thumb_size);
}
void BaseScrollBar::SetThumbTrackState(CustomButton::ButtonState state) {
« no previous file with comments | « ui/views/controls/scrollbar/base_scroll_bar.h ('k') | ui/views/controls/scrollbar/scrollbar_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698