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/app_list/page_switcher.h" | 5 #include "ui/app_list/page_switcher.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "third_party/skia/include/core/SkPath.h" | 9 #include "third_party/skia/include/core/SkPath.h" |
10 #include "ui/app_list/pagination_model.h" | 10 #include "ui/app_list/pagination_model.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 if (state() == BS_HOT) { | 60 if (state() == BS_HOT) { |
61 PaintButton(canvas, kHoverColor); | 61 PaintButton(canvas, kHoverColor); |
62 } else { | 62 } else { |
63 PaintButton(canvas, kNormalColor); | 63 PaintButton(canvas, kNormalColor); |
64 } | 64 } |
65 } | 65 } |
66 | 66 |
67 private: | 67 private: |
68 // Paints a button that has two rounded corner at bottom. | 68 // Paints a button that has two rounded corner at bottom. |
69 void PaintButton(gfx::Canvas* canvas, SkColor base_color) { | 69 void PaintButton(gfx::Canvas* canvas, SkColor base_color) { |
70 gfx::Rect rect(GetContentsBounds().Center( | 70 gfx::Rect rect(GetContentsBounds()); |
71 gfx::Size(button_width_, kButtonHeight))); | 71 rect.ClampToCenteredSize(gfx::Size(button_width_, kButtonHeight)); |
72 | 72 |
73 SkPath path; | 73 SkPath path; |
74 path.addRoundRect(gfx::RectToSkRect(rect), | 74 path.addRoundRect(gfx::RectToSkRect(rect), |
75 SkIntToScalar(kButtonCornerRadius), | 75 SkIntToScalar(kButtonCornerRadius), |
76 SkIntToScalar(kButtonCornerRadius)); | 76 SkIntToScalar(kButtonCornerRadius)); |
77 | 77 |
78 SkPaint paint; | 78 SkPaint paint; |
79 paint.setAntiAlias(true); | 79 paint.setAntiAlias(true); |
80 paint.setStyle(SkPaint::kFill_Style); | 80 paint.setStyle(SkPaint::kFill_Style); |
81 paint.setColor(base_color); | 81 paint.setColor(base_color); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 gfx::Rect rect(GetContentsBounds()); | 182 gfx::Rect rect(GetContentsBounds()); |
183 | 183 |
184 CalculateButtonWidthAndSpacing(rect.width()); | 184 CalculateButtonWidthAndSpacing(rect.width()); |
185 | 185 |
186 // Makes |buttons_| horizontally center and vertically fill. | 186 // Makes |buttons_| horizontally center and vertically fill. |
187 gfx::Size buttons_size(buttons_->GetPreferredSize()); | 187 gfx::Size buttons_size(buttons_->GetPreferredSize()); |
188 gfx::Rect buttons_bounds(rect.CenterPoint().x() - buttons_size.width() / 2, | 188 gfx::Rect buttons_bounds(rect.CenterPoint().x() - buttons_size.width() / 2, |
189 rect.y(), | 189 rect.y(), |
190 buttons_size.width(), | 190 buttons_size.width(), |
191 rect.height()); | 191 rect.height()); |
192 buttons_->SetBoundsRect(rect.Intersect(buttons_bounds)); | 192 rect.Intersect(buttons_bounds); |
| 193 buttons_->SetBoundsRect(rect); |
193 } | 194 } |
194 | 195 |
195 void PageSwitcher::CalculateButtonWidthAndSpacing(int contents_width) { | 196 void PageSwitcher::CalculateButtonWidthAndSpacing(int contents_width) { |
196 const int button_count = buttons_->child_count(); | 197 const int button_count = buttons_->child_count(); |
197 if (!button_count) | 198 if (!button_count) |
198 return; | 199 return; |
199 | 200 |
200 contents_width -= 2 * kButtonStripPadding; | 201 contents_width -= 2 * kButtonStripPadding; |
201 | 202 |
202 int button_width = kMinButtonWidth; | 203 int button_width = kMinButtonWidth; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 remaining = -remaining; | 262 remaining = -remaining; |
262 progress = -progress; | 263 progress = -progress; |
263 } | 264 } |
264 | 265 |
265 GetButtonByIndex(buttons_, current_page)->SetSelectedRange(remaining); | 266 GetButtonByIndex(buttons_, current_page)->SetSelectedRange(remaining); |
266 if (model_->is_valid_page(target_page)) | 267 if (model_->is_valid_page(target_page)) |
267 GetButtonByIndex(buttons_, target_page)->SetSelectedRange(progress); | 268 GetButtonByIndex(buttons_, target_page)->SetSelectedRange(progress); |
268 } | 269 } |
269 | 270 |
270 } // namespace app_list | 271 } // namespace app_list |
OLD | NEW |