| OLD | NEW |
| 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 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 if (!header_) | 708 if (!header_) |
| 709 return; | 709 return; |
| 710 | 710 |
| 711 int x_offset = CurrentOffset().x(); | 711 int x_offset = CurrentOffset().x(); |
| 712 if (header_->x() != -x_offset) { | 712 if (header_->x() != -x_offset) { |
| 713 header_->SetX(-x_offset); | 713 header_->SetX(-x_offset); |
| 714 header_->SchedulePaintInRect(header_->GetVisibleBounds()); | 714 header_->SchedulePaintInRect(header_->GetVisibleBounds()); |
| 715 } | 715 } |
| 716 } | 716 } |
| 717 | 717 |
| 718 // VariableRowHeightScrollHelper ---------------------------------------------- | |
| 719 | |
| 720 VariableRowHeightScrollHelper::VariableRowHeightScrollHelper( | |
| 721 Controller* controller) : controller_(controller) { | |
| 722 } | |
| 723 | |
| 724 VariableRowHeightScrollHelper::~VariableRowHeightScrollHelper() { | |
| 725 } | |
| 726 | |
| 727 int VariableRowHeightScrollHelper::GetPageScrollIncrement( | |
| 728 ScrollView* scroll_view, bool is_horizontal, bool is_positive) { | |
| 729 if (is_horizontal) | |
| 730 return 0; | |
| 731 // y coordinate is most likely negative. | |
| 732 int y = abs(scroll_view->contents()->y()); | |
| 733 int vis_height = scroll_view->contents()->parent()->height(); | |
| 734 if (is_positive) { | |
| 735 // Align the bottom most row to the top of the view. | |
| 736 int bottom = std::min(scroll_view->contents()->height() - 1, | |
| 737 y + vis_height); | |
| 738 RowInfo bottom_row_info = GetRowInfo(bottom); | |
| 739 // If 0, ScrollView will provide a default value. | |
| 740 return std::max(0, bottom_row_info.origin - y); | |
| 741 } else { | |
| 742 // Align the row on the previous page to to the top of the view. | |
| 743 int last_page_y = y - vis_height; | |
| 744 RowInfo last_page_info = GetRowInfo(std::max(0, last_page_y)); | |
| 745 if (last_page_y != last_page_info.origin) | |
| 746 return std::max(0, y - last_page_info.origin - last_page_info.height); | |
| 747 return std::max(0, y - last_page_info.origin); | |
| 748 } | |
| 749 } | |
| 750 | |
| 751 int VariableRowHeightScrollHelper::GetLineScrollIncrement( | |
| 752 ScrollView* scroll_view, bool is_horizontal, bool is_positive) { | |
| 753 if (is_horizontal) | |
| 754 return 0; | |
| 755 // y coordinate is most likely negative. | |
| 756 int y = abs(scroll_view->contents()->y()); | |
| 757 RowInfo row = GetRowInfo(y); | |
| 758 if (is_positive) { | |
| 759 return row.height - (y - row.origin); | |
| 760 } else if (y == row.origin) { | |
| 761 row = GetRowInfo(std::max(0, row.origin - 1)); | |
| 762 return y - row.origin; | |
| 763 } else { | |
| 764 return y - row.origin; | |
| 765 } | |
| 766 } | |
| 767 | |
| 768 VariableRowHeightScrollHelper::RowInfo | |
| 769 VariableRowHeightScrollHelper::GetRowInfo(int y) { | |
| 770 return controller_->GetRowInfo(y); | |
| 771 } | |
| 772 | |
| 773 // FixedRowHeightScrollHelper ----------------------------------------------- | |
| 774 | |
| 775 FixedRowHeightScrollHelper::FixedRowHeightScrollHelper(int top_margin, | |
| 776 int row_height) | |
| 777 : VariableRowHeightScrollHelper(NULL), | |
| 778 top_margin_(top_margin), | |
| 779 row_height_(row_height) { | |
| 780 DCHECK_GT(row_height, 0); | |
| 781 } | |
| 782 | |
| 783 VariableRowHeightScrollHelper::RowInfo | |
| 784 FixedRowHeightScrollHelper::GetRowInfo(int y) { | |
| 785 if (y < top_margin_) | |
| 786 return RowInfo(0, top_margin_); | |
| 787 return RowInfo((y - top_margin_) / row_height_ * row_height_ + top_margin_, | |
| 788 row_height_); | |
| 789 } | |
| 790 | |
| 791 } // namespace views | 718 } // namespace views |
| OLD | NEW |