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

Unified Diff: ui/app_list/views/page_switcher_horizontal.cc

Issue 2938563002: Vertically centered app list page switcher (Closed)
Patch Set: Clean up code Created 3 years, 6 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/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..52f6f63a1ec2cc5ac37c557f25f323031f83d00f 100644
--- a/ui/app_list/views/page_switcher.cc
+++ b/ui/app_list/views/page_switcher_horizontal.cc
@@ -2,7 +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"
#include <algorithm>
@@ -36,8 +36,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 +94,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 +129,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 +138,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 +158,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 +176,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 +190,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 +205,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 +226,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 +236,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 +247,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;

Powered by Google App Engine
This is Rietveld 408576698