| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "views/controls/scroll_view.h" | 5 #include "views/controls/scroll_view.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "views/controls/scrollbar/native_scroll_bar.h" | 8 #include "views/controls/scrollbar/native_scroll_bar.h" |
| 9 #include "views/widget/root_view.h" | 9 #include "views/widget/root_view.h" |
| 10 | 10 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 | 140 |
| 141 void ScrollView::Layout() { | 141 void ScrollView::Layout() { |
| 142 // Most views will want to auto-fit the available space. Most of them want to | 142 // Most views will want to auto-fit the available space. Most of them want to |
| 143 // use the all available width (without overflowing) and only overflow in | 143 // use the all available width (without overflowing) and only overflow in |
| 144 // height. Examples are HistoryView, MostVisitedView, DownloadTabView, etc. | 144 // height. Examples are HistoryView, MostVisitedView, DownloadTabView, etc. |
| 145 // Other views want to fit in both ways. An example is PrintView. To make both | 145 // Other views want to fit in both ways. An example is PrintView. To make both |
| 146 // happy, assume a vertical scrollbar but no horizontal scrollbar. To | 146 // happy, assume a vertical scrollbar but no horizontal scrollbar. To |
| 147 // override this default behavior, the inner view has to calculate the | 147 // override this default behavior, the inner view has to calculate the |
| 148 // available space, used ComputeScrollBarsVisibility() to use the same | 148 // available space, used ComputeScrollBarsVisibility() to use the same |
| 149 // calculation that is done here and sets its bound to fit within. | 149 // calculation that is done here and sets its bound to fit within. |
| 150 gfx::Rect viewport_bounds = GetContentsBounds(); | 150 gfx::Rect viewport_bounds = GetLocalBounds(); |
| 151 // Realign it to 0 so it can be used as-is for SetBounds(). | 151 // Realign it to 0 so it can be used as-is for SetBounds(). |
| 152 viewport_bounds.set_origin(gfx::Point(0, 0)); | 152 viewport_bounds.set_origin(gfx::Point(0, 0)); |
| 153 // viewport_size is the total client space available. | 153 // viewport_size is the total client space available. |
| 154 gfx::Size viewport_size = viewport_bounds.size(); | 154 gfx::Size viewport_size = viewport_bounds.size(); |
| 155 if (viewport_bounds.IsEmpty()) { | 155 if (viewport_bounds.IsEmpty()) { |
| 156 // There's nothing to layout. | 156 // There's nothing to layout. |
| 157 return; | 157 return; |
| 158 } | 158 } |
| 159 | 159 |
| 160 // Assumes a vertical scrollbar since most the current views are designed for | 160 // Assumes a vertical scrollbar since most the current views are designed for |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 | 501 |
| 502 VariableRowHeightScrollHelper::RowInfo | 502 VariableRowHeightScrollHelper::RowInfo |
| 503 FixedRowHeightScrollHelper::GetRowInfo(int y) { | 503 FixedRowHeightScrollHelper::GetRowInfo(int y) { |
| 504 if (y < top_margin_) | 504 if (y < top_margin_) |
| 505 return RowInfo(0, top_margin_); | 505 return RowInfo(0, top_margin_); |
| 506 return RowInfo((y - top_margin_) / row_height_ * row_height_ + top_margin_, | 506 return RowInfo((y - top_margin_) / row_height_ * row_height_ + top_margin_, |
| 507 row_height_); | 507 row_height_); |
| 508 } | 508 } |
| 509 | 509 |
| 510 } // namespace views | 510 } // namespace views |
| OLD | NEW |