OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/views/contents_switcher_view.h" | 5 #include "ui/app_list/views/contents_switcher_view.h" |
6 | 6 |
7 #include "ui/app_list/app_list_constants.h" | 7 #include "ui/app_list/app_list_constants.h" |
8 #include "ui/app_list/views/contents_view.h" | 8 #include "ui/app_list/views/contents_view.h" |
9 #include "ui/views/background.h" | 9 #include "ui/views/background.h" |
10 #include "ui/views/controls/button/custom_button.h" | 10 #include "ui/views/controls/button/custom_button.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id)); | 54 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id)); |
55 } | 55 } |
56 button->set_tag(page_index); | 56 button->set_tag(page_index); |
57 | 57 |
58 // Add an indicator for the current launcher page. | 58 // Add an indicator for the current launcher page. |
59 app_list::ContentsPageIndicatorView* indicator = | 59 app_list::ContentsPageIndicatorView* indicator = |
60 new app_list::ContentsPageIndicatorView(); | 60 new app_list::ContentsPageIndicatorView(); |
61 indicator->set_background( | 61 indicator->set_background( |
62 views::Background::CreateSolidBackground(app_list::kPagerSelectedColor)); | 62 views::Background::CreateSolidBackground(app_list::kPagerSelectedColor)); |
63 indicator->SetVisible(false); | 63 indicator->SetVisible(false); |
64 page_active_indicators_.push_back(indicator); | 64 page_active_indicators_[page_index] = indicator; |
65 | 65 |
66 // A container view that will consume space when its child is not visible. | 66 // A container view that will consume space when its child is not visible. |
67 // TODO(calamity): Remove this once BoxLayout supports space-consuming | 67 // TODO(calamity): Remove this once BoxLayout supports space-consuming |
68 // invisible views. | 68 // invisible views. |
69 views::View* indicator_container = new views::View(); | 69 views::View* indicator_container = new views::View(); |
70 indicator_container->SetLayoutManager(new views::FillLayout()); | 70 indicator_container->SetLayoutManager(new views::FillLayout()); |
71 indicator_container->AddChildView(indicator); | 71 indicator_container->AddChildView(indicator); |
72 | 72 |
73 // View containing the indicator view and image button. | 73 // View containing the indicator view and image button. |
74 views::View* button_container = new views::View(); | 74 views::View* button_container = new views::View(); |
(...skipping 10 matching lines...) Expand all Loading... |
85 contents_view_->SetActivePage(sender->tag()); | 85 contents_view_->SetActivePage(sender->tag()); |
86 } | 86 } |
87 | 87 |
88 void ContentsSwitcherView::TotalPagesChanged() { | 88 void ContentsSwitcherView::TotalPagesChanged() { |
89 } | 89 } |
90 | 90 |
91 void ContentsSwitcherView::SelectedPageChanged(int old_selected, | 91 void ContentsSwitcherView::SelectedPageChanged(int old_selected, |
92 int new_selected) { | 92 int new_selected) { |
93 // Makes the indicator visible when it is first drawn and when the | 93 // Makes the indicator visible when it is first drawn and when the |
94 // selected page is changed. | 94 // selected page is changed. |
95 int num_indicators = static_cast<int>(page_active_indicators_.size()); | 95 std::map<int, views::View*>::const_iterator it = |
96 if (old_selected >= 0 && old_selected < num_indicators) | 96 page_active_indicators_.find(old_selected); |
97 page_active_indicators_[old_selected]->SetVisible(false); | 97 if (it != page_active_indicators_.end()) |
| 98 it->second->SetVisible(false); |
98 | 99 |
99 if (new_selected >= 0 && new_selected < num_indicators) | 100 it = page_active_indicators_.find(new_selected); |
100 page_active_indicators_[new_selected]->SetVisible(true); | 101 if (it != page_active_indicators_.end()) |
| 102 it->second->SetVisible(true); |
101 } | 103 } |
102 | 104 |
103 void ContentsSwitcherView::TransitionStarted() { | 105 void ContentsSwitcherView::TransitionStarted() { |
104 } | 106 } |
105 | 107 |
106 void ContentsSwitcherView::TransitionChanged() { | 108 void ContentsSwitcherView::TransitionChanged() { |
107 // Change the indicator during a launcher page transition. | 109 // Change the indicator during a launcher page transition. |
108 const PaginationModel& pm = contents_view_->pagination_model(); | 110 const PaginationModel& pm = contents_view_->pagination_model(); |
109 int old_selected = pm.selected_page(); | 111 int old_selected = pm.selected_page(); |
110 int new_selected = pm.transition().target_page; | 112 int new_selected = pm.transition().target_page; |
111 if (pm.IsRevertingCurrentTransition()) { | 113 if (pm.IsRevertingCurrentTransition()) { |
112 // Swap the direction if the transition is reversed. | 114 // Swap the direction if the transition is reversed. |
113 old_selected = pm.transition().target_page; | 115 old_selected = pm.transition().target_page; |
114 new_selected = pm.selected_page(); | 116 new_selected = pm.selected_page(); |
115 } | 117 } |
116 | 118 |
117 SelectedPageChanged(old_selected, new_selected); | 119 SelectedPageChanged(old_selected, new_selected); |
118 } | 120 } |
119 | 121 |
120 } // namespace app_list | 122 } // namespace app_list |
OLD | NEW |