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

Side by Side Diff: ui/views/controls/scroll_view.cc

Issue 2509783002: Don't reset scroll position of contents on every ScrollView layout. (Closed)
Patch Set: Created 4 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « ash/common/system/tray/tray_details_view.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/controls/scroll_view.h" 5 #include "ui/views/controls/scroll_view.h"
6 6
7 #include "base/feature_list.h" 7 #include "base/feature_list.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "ui/events/event.h" 10 #include "ui/events/event.h"
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 focus_ring_->Layout(); 306 focus_ring_->Layout();
307 307
308 gfx::Rect available_rect = GetContentsBounds(); 308 gfx::Rect available_rect = GetContentsBounds();
309 if (is_bounded()) { 309 if (is_bounded()) {
310 int content_width = available_rect.width(); 310 int content_width = available_rect.width();
311 int content_height = contents()->GetHeightForWidth(content_width); 311 int content_height = contents()->GetHeightForWidth(content_width);
312 if (content_height > height()) { 312 if (content_height > height()) {
313 content_width = std::max(content_width - GetScrollBarWidth(), 0); 313 content_width = std::max(content_width - GetScrollBarWidth(), 0);
314 content_height = contents()->GetHeightForWidth(content_width); 314 content_height = contents()->GetHeightForWidth(content_width);
315 } 315 }
316 if (contents()->bounds().size() != gfx::Size(content_width, content_height)) 316 contents()->SetSize(gfx::Size(content_width, content_height));
sky 2016/11/16 20:12:57 It would be nice if we were consistent and used co
Evan Stade 2016/11/17 01:14:00 (also done)
317 contents()->SetBounds(0, 0, content_width, content_height);
318 } 317 }
319 318
320 // Most views will want to auto-fit the available space. Most of them want to 319 // Most views will want to auto-fit the available space. Most of them want to
321 // use all available width (without overflowing) and only overflow in 320 // use all available width (without overflowing) and only overflow in
322 // height. Examples are HistoryView, MostVisitedView, DownloadTabView, etc. 321 // height. Examples are HistoryView, MostVisitedView, DownloadTabView, etc.
323 // Other views want to fit in both ways. An example is PrintView. To make both 322 // Other views want to fit in both ways. An example is PrintView. To make both
324 // happy, assume a vertical scrollbar but no horizontal scrollbar. To override 323 // happy, assume a vertical scrollbar but no horizontal scrollbar. To override
325 // this default behavior, the inner view has to calculate the available space, 324 // this default behavior, the inner view has to calculate the available space,
326 // used ComputeScrollBarsVisibility() to use the same calculation that is done 325 // used ComputeScrollBarsVisibility() to use the same calculation that is done
327 // here and sets its bound to fit within. 326 // here and sets its bound to fit within.
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 781
783 VariableRowHeightScrollHelper::RowInfo 782 VariableRowHeightScrollHelper::RowInfo
784 FixedRowHeightScrollHelper::GetRowInfo(int y) { 783 FixedRowHeightScrollHelper::GetRowInfo(int y) {
785 if (y < top_margin_) 784 if (y < top_margin_)
786 return RowInfo(0, top_margin_); 785 return RowInfo(0, top_margin_);
787 return RowInfo((y - top_margin_) / row_height_ * row_height_ + top_margin_, 786 return RowInfo((y - top_margin_) / row_height_ * row_height_ + top_margin_,
788 row_height_); 787 row_height_);
789 } 788 }
790 789
791 } // namespace views 790 } // namespace views
OLDNEW
« no previous file with comments | « ash/common/system/tray/tray_details_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698