Chromium Code Reviews| Index: ui/app_list/views/page_switcher_horizontal.cc |
| diff --git a/ui/app_list/views/page_switcher.cc b/ui/app_list/views/page_switcher_horizontal.cc |
| similarity index 83% |
| copy from ui/app_list/views/page_switcher.cc |
| copy to ui/app_list/views/page_switcher_horizontal.cc |
| index a2c427f3e0fd35739cbf3c54a6be1be8539cb937..b374fc85f777aa95ed48f9199646cc30f5fc0213 100644 |
| --- a/ui/app_list/views/page_switcher.cc |
| +++ b/ui/app_list/views/page_switcher_horizontal.cc |
| @@ -2,8 +2,7 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "ui/app_list/views/page_switcher.h" |
| - |
| +#include <ui/app_list/views/page_switcher_horizontal.h> |
|
xiyuan
2017/06/13 18:29:55
Use " for chromium headers and use angle bracket <
weidongg
2017/06/13 21:25:00
Done.
|
| #include <algorithm> |
| #include "base/macros.h" |
| @@ -36,8 +35,7 @@ class PageSwitcherButton : public views::CustomButton { |
| explicit PageSwitcherButton(views::ButtonListener* listener) |
| : views::CustomButton(listener), |
| button_width_(kMaxButtonWidth), |
| - selected_range_(0) { |
| - } |
| + selected_range_(0) {} |
| ~PageSwitcherButton() override {} |
| void SetSelectedRange(double selected_range) { |
| @@ -95,7 +93,7 @@ class PageSwitcherButton : public views::CustomButton { |
| if (selected_range_ > 0) { |
| selected_width = selected_range_ * rect.width(); |
| } else if (selected_range_ < 0) { |
| - selected_width = -selected_range_ * rect.width(); |
| + selected_width = -selected_range_ * rect.width(); |
| selected_start_x = rect.right() - selected_width; |
| } |
| @@ -130,9 +128,8 @@ PageSwitcherButton* GetButtonByIndex(views::View* buttons, int index) { |
| } // namespace |
| -PageSwitcher::PageSwitcher(PaginationModel* model) |
| - : model_(model), |
| - buttons_(new views::View) { |
| +PageSwitcherHorizontal::PageSwitcherHorizontal(PaginationModel* model) |
| + : model_(model), buttons_(new views::View) { |
| AddChildView(buttons_); |
| TotalPagesChanged(); |
| @@ -140,11 +137,11 @@ PageSwitcher::PageSwitcher(PaginationModel* model) |
| model_->AddObserver(this); |
| } |
| -PageSwitcher::~PageSwitcher() { |
| +PageSwitcherHorizontal::~PageSwitcherHorizontal() { |
| model_->RemoveObserver(this); |
| } |
| -int PageSwitcher::GetPageForPoint(const gfx::Point& point) const { |
| +int PageSwitcherHorizontal::GetPageForPoint(const gfx::Point& point) const { |
| if (!buttons_->bounds().Contains(point)) |
| return -1; |
| @@ -160,7 +157,7 @@ int PageSwitcher::GetPageForPoint(const gfx::Point& point) const { |
| return -1; |
| } |
| -void PageSwitcher::UpdateUIForDragPoint(const gfx::Point& point) { |
| +void PageSwitcherHorizontal::UpdateUIForDragPoint(const gfx::Point& point) { |
| int page = GetPageForPoint(point); |
| const int button_count = buttons_->child_count(); |
| @@ -178,14 +175,13 @@ void PageSwitcher::UpdateUIForDragPoint(const gfx::Point& point) { |
| } |
| } |
| -gfx::Size PageSwitcher::CalculatePreferredSize() const { |
| +gfx::Size PageSwitcherHorizontal::CalculatePreferredSize() const { |
| // Always return a size with correct height so that container resize is not |
| // needed when more pages are added. |
| - return gfx::Size(buttons_->GetPreferredSize().width(), |
| - kPreferredHeight); |
| + return gfx::Size(buttons_->GetPreferredSize().width(), kPreferredHeight); |
| } |
| -void PageSwitcher::Layout() { |
| +void PageSwitcherHorizontal::Layout() { |
| gfx::Rect rect(GetContentsBounds()); |
| CalculateButtonWidthAndSpacing(rect.width()); |
| @@ -193,13 +189,12 @@ void PageSwitcher::Layout() { |
| // Makes |buttons_| horizontally center and vertically fill. |
| gfx::Size buttons_size(buttons_->GetPreferredSize()); |
| gfx::Rect buttons_bounds(rect.CenterPoint().x() - buttons_size.width() / 2, |
| - rect.y(), |
| - buttons_size.width(), |
| - rect.height()); |
| + rect.y(), buttons_size.width(), rect.height()); |
| buttons_->SetBoundsRect(gfx::IntersectRects(rect, buttons_bounds)); |
| } |
| -void PageSwitcher::CalculateButtonWidthAndSpacing(int contents_width) { |
| +void PageSwitcherHorizontal::CalculateButtonWidthAndSpacing( |
| + int contents_width) { |
| const int button_count = buttons_->child_count(); |
| if (!button_count) |
| return; |
| @@ -209,16 +204,16 @@ void PageSwitcher::CalculateButtonWidthAndSpacing(int contents_width) { |
| int button_width = kMinButtonWidth; |
| int button_spacing = kMinButtonSpacing; |
| if (button_count > 1) { |
| - button_spacing = (contents_width - button_width * button_count) / |
| - (button_count - 1); |
| + button_spacing = |
| + (contents_width - button_width * button_count) / (button_count - 1); |
| button_spacing = std::min(kMaxButtonSpacing, |
| std::max(kMinButtonSpacing, button_spacing)); |
| } |
| - button_width = (contents_width - (button_count - 1) * button_spacing) / |
| - button_count; |
| - button_width = std::min(kMaxButtonWidth, |
| - std::max(kMinButtonWidth, button_width)); |
| + button_width = |
| + (contents_width - (button_count - 1) * button_spacing) / button_count; |
| + button_width = |
| + std::min(kMaxButtonWidth, std::max(kMinButtonWidth, button_width)); |
| buttons_->SetLayoutManager(new views::BoxLayout( |
| views::BoxLayout::kHorizontal, gfx::Insets(0, kButtonStripPadding), |
| @@ -230,8 +225,8 @@ void PageSwitcher::CalculateButtonWidthAndSpacing(int contents_width) { |
| } |
| } |
| -void PageSwitcher::ButtonPressed(views::Button* sender, |
| - const ui::Event& event) { |
| +void PageSwitcherHorizontal::ButtonPressed(views::Button* sender, |
| + const ui::Event& event) { |
| for (int i = 0; i < buttons_->child_count(); ++i) { |
| if (sender == static_cast<views::Button*>(buttons_->child_at(i))) { |
| model_->SelectPage(i, true /* animate */); |
| @@ -240,7 +235,7 @@ void PageSwitcher::ButtonPressed(views::Button* sender, |
| } |
| } |
| -void PageSwitcher::TotalPagesChanged() { |
| +void PageSwitcherHorizontal::TotalPagesChanged() { |
| buttons_->RemoveAllChildViews(true); |
| for (int i = 0; i < model_->total_pages(); ++i) { |
| PageSwitcherButton* button = new PageSwitcherButton(this); |
| @@ -251,17 +246,17 @@ void PageSwitcher::TotalPagesChanged() { |
| Layout(); |
| } |
| -void PageSwitcher::SelectedPageChanged(int old_selected, int new_selected) { |
| +void PageSwitcherHorizontal::SelectedPageChanged(int old_selected, |
| + int new_selected) { |
| if (old_selected >= 0 && old_selected < buttons_->child_count()) |
| GetButtonByIndex(buttons_, old_selected)->SetSelectedRange(0); |
| if (new_selected >= 0 && new_selected < buttons_->child_count()) |
| GetButtonByIndex(buttons_, new_selected)->SetSelectedRange(1); |
| } |
| -void PageSwitcher::TransitionStarted() { |
| -} |
| +void PageSwitcherHorizontal::TransitionStarted() {} |
| -void PageSwitcher::TransitionChanged() { |
| +void PageSwitcherHorizontal::TransitionChanged() { |
| const int current_page = model_->selected_page(); |
| const int target_page = model_->transition().target_page; |