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

Unified Diff: ui/views/controls/scroll_view.cc

Issue 2324043002: Bug Fix: Scroll View Shows Unnecessary Scrollbar (Closed)
Patch Set: Unittest Created 4 years, 3 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
Index: ui/views/controls/scroll_view.cc
diff --git a/ui/views/controls/scroll_view.cc b/ui/views/controls/scroll_view.cc
index 8cdb69ba0db0bb486f299b0f67761c5191bc6d41..e9dbdac9fdd94cb6a246668d3329c8108b4b89e3 100644
--- a/ui/views/controls/scroll_view.cc
+++ b/ui/views/controls/scroll_view.cc
@@ -294,8 +294,9 @@ int ScrollView::GetHeightForWidth(int width) const {
}
void ScrollView::Layout() {
+ gfx::Rect available_rect = GetContentsBounds();
if (is_bounded()) {
- int content_width = width();
+ int content_width = available_rect.width();
int content_height = contents()->GetHeightForWidth(content_width);
if (content_height > height()) {
content_width = std::max(content_width - GetScrollBarWidth(), 0);
@@ -313,7 +314,7 @@ void ScrollView::Layout() {
// this default behavior, the inner view has to calculate the available space,
// used ComputeScrollBarsVisibility() to use the same calculation that is done
// here and sets its bound to fit within.
- gfx::Rect viewport_bounds = GetContentsBounds();
+ gfx::Rect viewport_bounds = available_rect;
const int contents_x = viewport_bounds.x();
const int contents_y = viewport_bounds.y();
if (viewport_bounds.IsEmpty()) {
@@ -591,6 +592,12 @@ void ScrollView::ComputeScrollBarsVisibility(const gfx::Size& vp_size,
const gfx::Size& content_size,
bool* horiz_is_shown,
bool* vert_is_shown) const {
+ if (hide_horizontal_scrollbar_) {
+ *horiz_is_shown = false;
+ *vert_is_shown = content_size.height() > vp_size.height();
+ return;
+ }
+
// Try to fit both ways first, then try vertical bar only, then horizontal
// bar only, then defaults to both shown.
if (content_size.width() <= vp_size.width() &&
@@ -607,9 +614,6 @@ void ScrollView::ComputeScrollBarsVisibility(const gfx::Size& vp_size,
*horiz_is_shown = true;
*vert_is_shown = true;
}
-
- if (hide_horizontal_scrollbar_)
- *horiz_is_shown = false;
}
// Make sure that a single scrollbar is created and visible as needed
« no previous file with comments | « chrome/browser/ui/views/desktop_capture/desktop_media_list_view.cc ('k') | ui/views/controls/scroll_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698