Merge lp:~brandontschaefer/unity/lp.1131646-fix into lp:unity

Proposed by Brandon Schaefer
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
Merged at revision: 3378
Proposed branch: lp:~brandontschaefer/unity/lp.1131646-fix
Merge into: lp:unity
Diff against target: 734 lines (+484/-24)
13 files modified
launcher/SwitcherController.cpp (+72/-0)
launcher/SwitcherController.h (+3/-0)
launcher/SwitcherControllerImpl.h (+5/-0)
launcher/SwitcherModel.cpp (+97/-0)
launcher/SwitcherModel.h (+13/-0)
launcher/SwitcherView.cpp (+1/-0)
plugins/unityshell/src/unityshell.cpp (+6/-18)
plugins/unityshell/src/unityshell.h (+2/-2)
tests/test_layout_system.cpp (+48/-0)
tests/test_switcher_controller.cpp (+71/-0)
tests/test_switcher_model.cpp (+150/-0)
unity-shared/LayoutSystem.cpp (+13/-2)
unity-shared/LayoutSystem.h (+3/-2)
To merge this branch: bzr merge lp:~brandontschaefer/unity/lp.1131646-fix
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Marco Trevisan (Treviño) Approve
Review via email: mp+169475@code.launchpad.net

Commit message

When in detail mode, you are now allowed to use UP/DOWN keys to move around.

Description of the change

When in detail mode, you are now allowed to use UP/DOWN keys to move around.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Nice work, overall it looks fine, just few things:

143 - if (detail_selection_index >= (unsigned int) 1)
232 + return (detail_selection_index > 0);

doesn't compile on raring g++... Probably we should wait a little.

478 + std::vector<LayoutWindow::Vector> rows = GetRows(windows, max_bounds);
235 +void SwitcherModel::SetRowSizes(std::vector<int> row_sizes)

Use const& please.

174 + for (unsigned int i = 0; i <= n; i++)

++i is nicer. Also you should make sure that n is < row_sizes_.size().

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

+bool Controller::HandleStartInitiateEvent()
+bool Controller::HandleStopInitiateEvent()

What about using different naming? Such {Start,Stop}DetailMode or better?

Probably it would be better to change the compiz option names also, since they generates functions that doesn't represent anymore what they say. Don't you agree?

Would be now possible to test the controller also?

133 + void NextDetailRow();
134 + void PrevDetailRow();
135 + bool HasNextDetailRow() const;
136 + bool HasPrevDetailRow() const;

Are probably not needed anymore, right (also in the impl)?

Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

Yeeah, but it still starts/stops detail mode. Ill try to think of a different name :). Yes, I don't have to expose those function publicily anymore, and yes it will be possible to get tests on that 2 new function. What I was going to do this morning :)

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Great, I think we're fine for trunk now! :)

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'launcher/SwitcherController.cpp'
--- launcher/SwitcherController.cpp 2013-06-14 16:10:26 +0000
+++ launcher/SwitcherController.cpp 2013-06-18 19:07:26 +0000
@@ -124,6 +124,46 @@
124 return visible_;124 return visible_;
125}125}
126126
127bool Controller::StartDetailMode()
128{
129 if (visible_)
130 {
131 if (IsDetailViewShown() &&
132 impl_->HasNextDetailRow())
133 {
134 impl_->NextDetailRow();
135 }
136 else
137 {
138 SetDetail(true);
139 }
140
141 return true;
142 }
143
144 return false;
145}
146
147bool Controller::StopDetailMode()
148{
149 if (visible_)
150 {
151 if (IsDetailViewShown() &&
152 impl_->HasPrevDetailRow())
153 {
154 impl_->PrevDetailRow();
155 }
156 else
157 {
158 SetDetail(false);
159 }
160
161 return true;
162 }
163
164 return false;
165}
166
127void Controller::Next()167void Controller::Next()
128{168{
129 impl_->Next();169 impl_->Next();
@@ -586,6 +626,38 @@
586 model_->PrevDetail();626 model_->PrevDetail();
587}627}
588628
629void Controller::Impl::NextDetailRow()
630{
631 if (!model_)
632 return;
633
634 model_->NextDetailRow();
635}
636
637void Controller::Impl::PrevDetailRow()
638{
639 if (!model_)
640 return;
641
642 model_->PrevDetailRow();
643}
644
645bool Controller::Impl::HasNextDetailRow() const
646{
647 if (!model_)
648 return false;
649
650 return model_->HasNextDetailRow();
651}
652
653bool Controller::Impl::HasPrevDetailRow() const
654{
655 if (!model_)
656 return false;
657
658 return model_->HasPrevDetailRow();
659}
660
589LayoutWindow::Vector Controller::Impl::ExternalRenderTargets()661LayoutWindow::Vector Controller::Impl::ExternalRenderTargets()
590{662{
591 if (!view_)663 if (!view_)
592664
=== modified file 'launcher/SwitcherController.h'
--- launcher/SwitcherController.h 2013-02-26 16:27:23 +0000
+++ launcher/SwitcherController.h 2013-06-18 19:07:26 +0000
@@ -89,6 +89,9 @@
8989
90 bool Visible();90 bool Visible();
9191
92 bool StartDetailMode();
93 bool StopDetailMode();
94
92 void Next();95 void Next();
93 void Prev();96 void Prev();
9497
9598
=== modified file 'launcher/SwitcherControllerImpl.h'
--- launcher/SwitcherControllerImpl.h 2013-02-26 16:27:23 +0000
+++ launcher/SwitcherControllerImpl.h 2013-06-18 19:07:26 +0000
@@ -56,6 +56,11 @@
56 void NextDetail();56 void NextDetail();
57 void PrevDetail();57 void PrevDetail();
5858
59 void NextDetailRow();
60 void PrevDetailRow();
61 bool HasNextDetailRow() const;
62 bool HasPrevDetailRow() const;
63
59 bool IsDetailViewShown();64 bool IsDetailViewShown();
60 void SetDetail(bool detail, unsigned int min_windows = 1);65 void SetDetail(bool detail, unsigned int min_windows = 1);
6166
6267
=== modified file 'launcher/SwitcherModel.cpp'
--- launcher/SwitcherModel.cpp 2013-02-14 16:26:13 +0000
+++ launcher/SwitcherModel.cpp 2013-06-18 19:07:26 +0000
@@ -38,6 +38,7 @@
38 , applications_(icons)38 , applications_(icons)
39 , index_(0)39 , index_(0)
40 , last_index_(0)40 , last_index_(0)
41 , row_index_(0)
41{42{
42 // When using Webapps, there are more than one active icon, so let's just pick43 // When using Webapps, there are more than one active icon, so let's just pick
43 // up the first one found which is the web browser.44 // up the first one found which is the web browser.
@@ -183,6 +184,7 @@
183184
184 detail_selection = false;185 detail_selection = false;
185 detail_selection_index = 0;186 detail_selection_index = 0;
187 row_index_ = 0;
186 selection_changed.emit(Selection());188 selection_changed.emit(Selection());
187}189}
188190
@@ -197,6 +199,7 @@
197199
198 detail_selection = false;200 detail_selection = false;
199 detail_selection_index = 0;201 detail_selection_index = 0;
202 row_index_ = 0;
200 selection_changed.emit(Selection());203 selection_changed.emit(Selection());
201}204}
202205
@@ -209,6 +212,8 @@
209 detail_selection_index = detail_selection_index + 1;212 detail_selection_index = detail_selection_index + 1;
210 else213 else
211 detail_selection_index = 0;214 detail_selection_index = 0;
215
216 UpdateRowIndex();
212}217}
213218
214void SwitcherModel::PrevDetail()219void SwitcherModel::PrevDetail()
@@ -220,6 +225,98 @@
220 detail_selection_index = detail_selection_index - 1;225 detail_selection_index = detail_selection_index - 1;
221 else226 else
222 detail_selection_index = DetailXids().size() - 1;227 detail_selection_index = DetailXids().size() - 1;
228
229 UpdateRowIndex();
230}
231
232void SwitcherModel::UpdateRowIndex()
233{
234 int current_index = detail_selection_index;
235 unsigned int current_row = 0;
236
237 for (auto r : row_sizes_)
238 {
239 current_index -= r;
240
241 if (current_index < 0)
242 {
243 row_index_ = current_row;
244 return;
245 }
246
247 current_row++;
248 }
249}
250
251unsigned int SwitcherModel::SumNRows(unsigned int n) const
252{
253 unsigned int total = 0;
254
255 if (n < row_sizes_.size())
256 for (unsigned int i = 0; i <= n; ++i)
257 total += row_sizes_[i];
258
259 return total;
260}
261
262bool SwitcherModel::DetailIndexInLeftHalfOfRow() const
263{
264 unsigned int half = row_sizes_[row_index_]/2;
265 unsigned int total_above = (row_index_ > 0 ? SumNRows(row_index_ - 1) : 0);
266 unsigned int diff = detail_selection_index - total_above;
267
268 return (diff < half);
269}
270
271void SwitcherModel::NextDetailRow()
272{
273 if (HasNextDetailRow())
274 {
275 unsigned int current_row = row_sizes_[row_index_];
276 unsigned int next_row = row_sizes_[row_index_ + 1];
277 unsigned int increment = current_row;
278
279 if (!DetailIndexInLeftHalfOfRow())
280 increment = next_row;
281
282 detail_selection_index = detail_selection_index + increment;
283 row_index_++;
284 }
285}
286
287void SwitcherModel::PrevDetailRow()
288{
289 if (row_index_ > 0)
290 {
291 unsigned int current_row = row_sizes_[row_index_];
292 unsigned int prev_row = row_sizes_[row_index_ - 1];
293 unsigned int decrement = current_row;
294
295 if (DetailIndexInLeftHalfOfRow())
296 decrement = prev_row;
297
298 detail_selection_index = detail_selection_index - decrement;
299 row_index_--;
300 }
301 else
302 {
303 detail_selection_index = detail_selection_index - 1;
304 }
305}
306
307bool SwitcherModel::HasNextDetailRow() const
308{
309 return (row_sizes_.size() && row_index_ < row_sizes_.size() - 1);
310}
311
312bool SwitcherModel::HasPrevDetailRow() const
313{
314 return (detail_selection_index > (unsigned int) 0);
315}
316
317void SwitcherModel::SetRowSizes(std::vector<int> const& row_sizes)
318{
319 row_sizes_ = row_sizes;
223}320}
224321
225void SwitcherModel::Select(AbstractLauncherIcon::Ptr const& selection)322void SwitcherModel::Select(AbstractLauncherIcon::Ptr const& selection)
226323
=== modified file 'launcher/SwitcherModel.h'
--- launcher/SwitcherModel.h 2013-02-05 01:38:11 +0000
+++ launcher/SwitcherModel.h 2013-06-18 19:07:26 +0000
@@ -90,6 +90,13 @@
90 void NextDetail();90 void NextDetail();
91 void PrevDetail();91 void PrevDetail();
9292
93 void NextDetailRow();
94 void PrevDetailRow();
95 bool HasNextDetailRow() const;
96 bool HasPrevDetailRow() const;
97
98 void SetRowSizes(std::vector<int> const& row_sizes);
99
93 void Select(launcher::AbstractLauncherIcon::Ptr const& selection);100 void Select(launcher::AbstractLauncherIcon::Ptr const& selection);
94 void Select(unsigned int index);101 void Select(unsigned int index);
95102
@@ -101,10 +108,16 @@
101 void AddProperties(GVariantBuilder* builder);108 void AddProperties(GVariantBuilder* builder);
102109
103private:110private:
111 void UpdateRowIndex();
112 unsigned int SumNRows(unsigned int n) const;
113 bool DetailIndexInLeftHalfOfRow() const;
114
104 Applications applications_;115 Applications applications_;
105 unsigned int index_;116 unsigned int index_;
106 unsigned int last_index_;117 unsigned int last_index_;
118 unsigned int row_index_;
107 launcher::AbstractLauncherIcon::Ptr last_active_application_;119 launcher::AbstractLauncherIcon::Ptr last_active_application_;
120 std::vector<int> row_sizes_;
108};121};
109122
110}123}
111124
=== modified file 'launcher/SwitcherView.cpp'
--- launcher/SwitcherView.cpp 2013-04-12 22:48:37 +0000
+++ launcher/SwitcherView.cpp 2013-06-18 19:07:26 +0000
@@ -277,6 +277,7 @@
277277
278 nux::Geometry layout_geo;278 nux::Geometry layout_geo;
279 layout_system_.LayoutWindows(render_targets_, max_bounds, layout_geo);279 layout_system_.LayoutWindows(render_targets_, max_bounds, layout_geo);
280 model_->SetRowSizes(layout_system_.GetRowSizes(render_targets_, max_bounds));
280281
281 return layout_geo;282 return layout_geo;
282}283}
283284
=== modified file 'plugins/unityshell/src/unityshell.cpp'
--- plugins/unityshell/src/unityshell.cpp 2013-05-29 14:52:11 +0000
+++ plugins/unityshell/src/unityshell.cpp 2013-06-18 19:07:26 +0000
@@ -321,8 +321,8 @@
321 optionSetAltTabPrevAllInitiate(boost::bind(&UnityScreen::altTabPrevAllInitiate, this, _1, _2, _3));321 optionSetAltTabPrevAllInitiate(boost::bind(&UnityScreen::altTabPrevAllInitiate, this, _1, _2, _3));
322 optionSetAltTabPrevInitiate(boost::bind(&UnityScreen::altTabPrevInitiate, this, _1, _2, _3));322 optionSetAltTabPrevInitiate(boost::bind(&UnityScreen::altTabPrevInitiate, this, _1, _2, _3));
323323
324 optionSetAltTabDetailStartInitiate(boost::bind(&UnityScreen::altTabDetailStartInitiate, this, _1, _2, _3));324 optionSetAltTabDetailStartInitiate(boost::bind(&UnityScreen::altTabDetailStart, this, _1, _2, _3));
325 optionSetAltTabDetailStopInitiate(boost::bind(&UnityScreen::altTabDetailStopInitiate, this, _1, _2, _3));325 optionSetAltTabDetailStopInitiate(boost::bind(&UnityScreen::altTabDetailStop, this, _1, _2, _3));
326326
327 optionSetAltTabNextWindowInitiate(boost::bind(&UnityScreen::altTabNextWindowInitiate, this, _1, _2, _3));327 optionSetAltTabNextWindowInitiate(boost::bind(&UnityScreen::altTabNextWindowInitiate, this, _1, _2, _3));
328 optionSetAltTabNextWindowTerminate(boost::bind(&UnityScreen::altTabTerminateCommon, this, _1, _2, _3));328 optionSetAltTabNextWindowTerminate(boost::bind(&UnityScreen::altTabTerminateCommon, this, _1, _2, _3));
@@ -1997,26 +1997,14 @@
1997 return false;1997 return false;
1998}1998}
19991999
2000bool UnityScreen::altTabDetailStartInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options)2000bool UnityScreen::altTabDetailStart(CompAction* action, CompAction::State state, CompOption::Vector& options)
2001{2001{
2002 if (switcher_controller_->Visible())2002 return switcher_controller_->StartDetailMode();
2003 {
2004 switcher_controller_->SetDetail(true);
2005 return true;
2006 }
2007
2008 return false;
2009}2003}
20102004
2011bool UnityScreen::altTabDetailStopInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options)2005bool UnityScreen::altTabDetailStop(CompAction* action, CompAction::State state, CompOption::Vector& options)
2012{2006{
2013 if (switcher_controller_->Visible())2007 return switcher_controller_->StopDetailMode();
2014 {
2015 switcher_controller_->SetDetail(false);
2016 return true;
2017 }
2018
2019 return false;
2020}2008}
20212009
2022bool UnityScreen::altTabNextWindowInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options)2010bool UnityScreen::altTabNextWindowInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options)
20232011
=== modified file 'plugins/unityshell/src/unityshell.h'
--- plugins/unityshell/src/unityshell.h 2013-05-17 22:53:57 +0000
+++ plugins/unityshell/src/unityshell.h 2013-06-18 19:07:26 +0000
@@ -152,8 +152,8 @@
152 bool altTabPrevInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);152 bool altTabPrevInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
153 bool altTabForwardAllInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);153 bool altTabForwardAllInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
154 bool altTabPrevAllInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);154 bool altTabPrevAllInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
155 bool altTabDetailStartInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);155 bool altTabDetailStart(CompAction* action, CompAction::State state, CompOption::Vector& options);
156 bool altTabDetailStopInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);156 bool altTabDetailStop(CompAction* action, CompAction::State state, CompOption::Vector& options);
157 bool altTabNextWindowInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);157 bool altTabNextWindowInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
158 bool altTabPrevWindowInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);158 bool altTabPrevWindowInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
159159
160160
=== modified file 'tests/test_layout_system.cpp'
--- tests/test_layout_system.cpp 2013-01-25 21:06:34 +0000
+++ tests/test_layout_system.cpp 2013-06-18 19:07:26 +0000
@@ -21,6 +21,8 @@
21#include "LayoutSystem.h"21#include "LayoutSystem.h"
22#include "StandaloneWindowManager.h"22#include "StandaloneWindowManager.h"
2323
24#include <vector>
25
24namespace unity26namespace unity
25{27{
26namespace ui28namespace ui
@@ -153,6 +155,52 @@
153 EXPECT_EQ(final_bounds.Intersect(windows_area), windows_area);155 EXPECT_EQ(final_bounds.Intersect(windows_area), windows_area);
154}156}
155157
158TEST_F(TestLayoutSystem, GetRowSizesEven)
159{
160 nux::Geometry max_bounds(0, 0, 200, 100);
161 nux::Geometry final_bounds;
162
163 Window xid = 3;
164 AddFakeWindowToWM(xid, nux::Geometry(4, 5, 200, 200));
165 lwindows.push_back(std::make_shared<LayoutWindow>(xid));
166
167 xid = 4;
168 AddFakeWindowToWM(xid, nux::Geometry(10, 20, 200, 200));
169 lwindows.push_back(std::make_shared<LayoutWindow>(xid));
170
171 ls.LayoutWindows(lwindows, max_bounds, final_bounds);
172
173 std::vector<int> const& row_sizes = ls.GetRowSizes(lwindows, max_bounds);
174 EXPECT_EQ(row_sizes.size(), 2);
175 EXPECT_EQ(row_sizes[0], 2);
176 EXPECT_EQ(row_sizes[1], 2);
177}
178
179TEST_F(TestLayoutSystem, GetRowSizesUnEven)
180{
181 nux::Geometry max_bounds(0, 0, 200, 100);
182 nux::Geometry final_bounds;
183
184 Window xid = 3;
185 AddFakeWindowToWM(xid, nux::Geometry(4, 5, 200, 200));
186 lwindows.push_back(std::make_shared<LayoutWindow>(xid));
187
188 xid = 4;
189 AddFakeWindowToWM(xid, nux::Geometry(10, 20, 200, 200));
190 lwindows.push_back(std::make_shared<LayoutWindow>(xid));
191
192 xid = 5;
193 AddFakeWindowToWM(xid, nux::Geometry(10, 20, 200, 200));
194 lwindows.push_back(std::make_shared<LayoutWindow>(xid));
195
196 ls.LayoutWindows(lwindows, max_bounds, final_bounds);
197
198 std::vector<int> const& row_sizes = ls.GetRowSizes(lwindows, max_bounds);
199 EXPECT_EQ(row_sizes.size(), 2);
200 EXPECT_EQ(row_sizes[0], 2);
201 EXPECT_EQ(row_sizes[1], 3);
202}
203
156}204}
157}205}
158}206}
159207
=== modified file 'tests/test_switcher_controller.cpp'
--- tests/test_switcher_controller.cpp 2013-06-14 16:10:26 +0000
+++ tests/test_switcher_controller.cpp 2013-06-18 19:07:26 +0000
@@ -77,6 +77,77 @@
77 EXPECT_FALSE(model->detail_selection());77 EXPECT_FALSE(model->detail_selection());
78}78}
7979
80TEST_F(TestSwitcherController, StartDetailMode)
81{
82 controller_->Show(ShowMode::ALL, SortMode::LAUNCHER_ORDER, icons_);
83 controller_->InitiateDetail();
84 controller_->StartDetailMode();
85
86 EXPECT_TRUE(controller_->IsDetailViewShown());
87}
88
89TEST_F(TestSwitcherController, StopDetailMode)
90{
91 controller_->Show(ShowMode::ALL, SortMode::LAUNCHER_ORDER, icons_);
92 controller_->InitiateDetail();
93
94 controller_->StartDetailMode();
95 EXPECT_TRUE(controller_->IsDetailViewShown());
96
97 controller_->StopDetailMode();
98 EXPECT_FALSE(controller_->IsDetailViewShown());
99}
100
101TEST_F(TestSwitcherController, StartDetailModeMovesNextRows)
102{
103 controller_->Show(ShowMode::ALL, SortMode::LAUNCHER_ORDER, icons_);
104 controller_->Select(2);
105 controller_->InitiateDetail();
106
107 controller_->StartDetailMode();
108 EXPECT_TRUE(controller_->IsDetailViewShown());
109
110 auto view = controller_->GetView();
111 auto model = view->GetModel();
112 model->SetRowSizes({2,2});
113
114 controller_->StartDetailMode();
115
116 // Grid: Assert we have gone down a row from index 0 -> 2
117 // 0, 1,
118 // 2, 3
119 EXPECT_FALSE(model->HasNextDetailRow());
120 EXPECT_TRUE(model->HasPrevDetailRow());
121 EXPECT_EQ(static_cast<unsigned int>(model->detail_selection_index), 2);
122}
123
124TEST_F(TestSwitcherController, StopDetailModeMovesPrevRows)
125{
126 controller_->Show(ShowMode::ALL, SortMode::LAUNCHER_ORDER, icons_);
127 controller_->Select(2);
128 controller_->InitiateDetail();
129
130 controller_->StartDetailMode();
131 EXPECT_TRUE(controller_->IsDetailViewShown());
132
133 auto view = controller_->GetView();
134 auto model = view->GetModel();
135 model->SetRowSizes({2,2});
136
137 controller_->StartDetailMode();
138 controller_->StopDetailMode();
139
140 // Assert we have gone up a row from index 2 -> 0
141 // 0, 1,
142 // 2, 3
143 EXPECT_TRUE(model->HasNextDetailRow());
144 EXPECT_FALSE(model->HasPrevDetailRow());
145 EXPECT_EQ(static_cast<unsigned int>(model->detail_selection_index), 0);
146
147 // Now we are in index 0, stoping detail mode must exit detail mode
148 controller_->StopDetailMode();
149 EXPECT_FALSE(controller_->IsDetailViewShown());
150}
80151
81TEST_F(TestSwitcherController, ShowSwitcher)152TEST_F(TestSwitcherController, ShowSwitcher)
82{153{
83154
=== modified file 'tests/test_switcher_model.cpp'
--- tests/test_switcher_model.cpp 2013-02-15 15:32:11 +0000
+++ tests/test_switcher_model.cpp 2013-06-18 19:07:26 +0000
@@ -80,6 +80,7 @@
80 EXPECT_EQ(model->LastSelection(), icons_.front());80 EXPECT_EQ(model->LastSelection(), icons_.front());
81 EXPECT_EQ(model->SelectionIndex(), 0);81 EXPECT_EQ(model->SelectionIndex(), 0);
82 EXPECT_EQ(model->LastSelectionIndex(), 0);82 EXPECT_EQ(model->LastSelectionIndex(), 0);
83 EXPECT_EQ(static_cast<unsigned int>(model->detail_selection_index), 0);
83}84}
8485
8586
@@ -178,4 +179,153 @@
178 EXPECT_NE(model->DetailXids().front(), base_model->DetailXids().front());179 EXPECT_NE(model->DetailXids().front(), base_model->DetailXids().front());
179}180}
180181
182TEST_F(TestSwitcherModel, TestHasNextDetailRow)
183{
184 SwitcherModel::Ptr model(new SwitcherModel(icons_));
185 model->detail_selection = true;
186 model->SetRowSizes({2,2});
187
188 EXPECT_TRUE(model->HasNextDetailRow());
189
190 model->NextDetailRow();
191 EXPECT_FALSE(model->HasNextDetailRow());
192}
193
194TEST_F(TestSwitcherModel, TestHasPrevDetailRow)
195{
196 SwitcherModel::Ptr model(new SwitcherModel(icons_));
197 model->detail_selection = true;
198 model->SetRowSizes({2,2});
199
200 model->NextDetail();
201 EXPECT_TRUE(model->HasPrevDetailRow());
202
203 model->PrevDetailRow();
204 EXPECT_FALSE(model->HasPrevDetailRow());
205}
206
207TEST_F(TestSwitcherModel, TestHasNextThenPrevDetailRow)
208{
209 SwitcherModel::Ptr model(new SwitcherModel(icons_));
210 model->detail_selection = true;
211 model->SetRowSizes({2,2});
212
213 EXPECT_TRUE(model->HasNextDetailRow());
214
215 model->NextDetailRow();
216 EXPECT_FALSE(model->HasNextDetailRow());
217
218 EXPECT_TRUE(model->HasPrevDetailRow());
219 model->PrevDetailRow();
220 EXPECT_FALSE(model->HasPrevDetailRow());
221}
222
223TEST_F(TestSwitcherModel, TestNextDetailRow)
224{
225 SwitcherModel::Ptr model(new SwitcherModel(icons_));
226 model->detail_selection = true;
227 model->SetRowSizes({2,2});
228
229 model->NextDetailRow();
230
231 // Expect going form index 0 -> 2
232 // 0, 1
233 // 2, 3
234 EXPECT_EQ(static_cast<unsigned int>(model->detail_selection_index), 2);
235}
236
237TEST_F(TestSwitcherModel, TestNextDetailThenNextDetailRow)
238{
239 SwitcherModel::Ptr model(new SwitcherModel(icons_));
240 model->detail_selection = true;
241 model->SetRowSizes({2,2});
242
243 model->NextDetail();
244 model->NextDetailRow();
245
246 // Expect going form index 1 -> 3
247 // 0, 1
248 // 2, 3
249 EXPECT_EQ(static_cast<unsigned int>(model->detail_selection_index), 3);
250}
251
252TEST_F(TestSwitcherModel, TestPrevDetailRow)
253{
254 SwitcherModel::Ptr model(new SwitcherModel(icons_));
255 model->detail_selection = true;
256 model->SetRowSizes({2,2});
257
258 model->NextDetailRow();
259 model->PrevDetailRow();
260
261 // Expect going form index 0 -> 2, then index 2 -> 0
262 // 0, 1
263 // 2, 3
264 EXPECT_EQ(static_cast<unsigned int>(model->detail_selection_index), 0);
265}
266
267TEST_F(TestSwitcherModel, TestNextDetailThenPrevDetailRow)
268{
269 SwitcherModel::Ptr model(new SwitcherModel(icons_));
270 model->detail_selection = true;
271 model->SetRowSizes({2,2});
272
273 model->NextDetail();
274 model->NextDetailRow();
275
276 model->PrevDetailRow();
277
278 // Expect going form index 1 -> 3, then index 3 -> 1
279 // 0, 1
280 // 2, 3
281 EXPECT_EQ(static_cast<unsigned int>(model->detail_selection_index), 1);
282}
283
284TEST_F(TestSwitcherModel, TestUnEvenNextDetailRow)
285{
286 SwitcherModel::Ptr model(new SwitcherModel(icons_));
287 model->detail_selection = true;
288 model->SetRowSizes({3,2});
289
290 model->NextDetailRow();
291
292 // Expect going form index 0 -> 3
293 // 0, 1, 2,
294 // 3, 4
295 EXPECT_EQ(static_cast<unsigned int>(model->detail_selection_index), 3);
296}
297
298TEST_F(TestSwitcherModel, TestUnEvenPrevDetailRow)
299{
300 SwitcherModel::Ptr model(new SwitcherModel(icons_));
301 model->detail_selection = true;
302 model->SetRowSizes({3,2});
303
304 model->NextDetailRow();
305 model->PrevDetailRow();
306
307 // Expect going form index 0 -> 3, then 3 -> 0
308 // 0, 1, 2,
309 // 3, 4
310 EXPECT_EQ(static_cast<unsigned int>(model->detail_selection_index), 0);
311}
312
313TEST_F(TestSwitcherModel, TestNextPrevDetailRowMovesLeftInTopRow)
314{
315 SwitcherModel::Ptr model(new SwitcherModel(icons_));
316 model->detail_selection = true;
317 model->SetRowSizes({3,2});
318
319 model->NextDetail();
320 model->NextDetail();
321 model->PrevDetailRow();
322 model->PrevDetailRow();
323
324 // Expect going form index 0 -> 1, then 1 -> 2, then 2 -> 1, 1 -> 0
325 // since PrevDetailRow must go to the index 0 of at the top of the row
326 // 0, 1, 2,
327 // 3, 4
328 EXPECT_EQ(static_cast<unsigned int>(model->detail_selection_index), 0);
329}
330
181}331}
182332
=== modified file 'unity-shared/LayoutSystem.cpp'
--- unity-shared/LayoutSystem.cpp 2013-02-20 21:40:31 +0000
+++ unity-shared/LayoutSystem.cpp 2013-06-18 19:07:26 +0000
@@ -35,7 +35,7 @@
35 LayoutGridWindows(windows, max_bounds, final_bounds);35 LayoutGridWindows(windows, max_bounds, final_bounds);
36}36}
3737
38nux::Size LayoutSystem::GridSizeForWindows(LayoutWindow::Vector const& windows, nux::Geometry const& max_bounds)38nux::Size LayoutSystem::GridSizeForWindows(LayoutWindow::Vector const& windows, nux::Geometry const& max_bounds) const
39{39{
40 unsigned count = windows.size();40 unsigned count = windows.size();
4141
@@ -138,7 +138,18 @@
138 return CompressAndPadRow (row, row_bounds);138 return CompressAndPadRow (row, row_bounds);
139}139}
140140
141std::vector<LayoutWindow::Vector> LayoutSystem::GetRows(LayoutWindow::Vector const& windows, nux::Geometry const& max_bounds)141std::vector<int> LayoutSystem::GetRowSizes(LayoutWindow::Vector const& windows, nux::Geometry const& max_bounds) const
142{
143 std::vector<LayoutWindow::Vector> const& rows = GetRows(windows, max_bounds);
144 std::vector<int> row_sizes;
145
146 for (auto r : rows)
147 row_sizes.push_back(r.size());
148
149 return row_sizes;
150}
151
152std::vector<LayoutWindow::Vector> LayoutSystem::GetRows(LayoutWindow::Vector const& windows, nux::Geometry const& max_bounds) const
142{153{
143 std::vector<LayoutWindow::Vector> rows;154 std::vector<LayoutWindow::Vector> rows;
144155
145156
=== modified file 'unity-shared/LayoutSystem.h'
--- unity-shared/LayoutSystem.h 2012-11-13 19:16:59 +0000
+++ unity-shared/LayoutSystem.h 2013-06-18 19:07:26 +0000
@@ -56,6 +56,7 @@
56 LayoutSystem();56 LayoutSystem();
5757
58 void LayoutWindows(LayoutWindow::Vector const& windows, nux::Geometry const& max_bounds, nux::Geometry& final_bounds);58 void LayoutWindows(LayoutWindow::Vector const& windows, nux::Geometry const& max_bounds, nux::Geometry& final_bounds);
59 std::vector<int> GetRowSizes(LayoutWindow::Vector const& windows, nux::Geometry const& max_bounds) const;
5960
60protected:61protected:
61 void LayoutGridWindows(LayoutWindow::Vector const& windows, nux::Geometry const& max_bounds, nux::Geometry& final_bounds);62 void LayoutGridWindows(LayoutWindow::Vector const& windows, nux::Geometry const& max_bounds, nux::Geometry& final_bounds);
@@ -63,9 +64,9 @@
63 nux::Geometry LayoutRow(LayoutWindow::Vector const& row, nux::Geometry const& row_bounds);64 nux::Geometry LayoutRow(LayoutWindow::Vector const& row, nux::Geometry const& row_bounds);
64 nux::Geometry CompressAndPadRow(LayoutWindow::Vector const& windows, nux::Geometry const& max_bounds);65 nux::Geometry CompressAndPadRow(LayoutWindow::Vector const& windows, nux::Geometry const& max_bounds);
6566
66 std::vector<LayoutWindow::Vector> GetRows(LayoutWindow::Vector const& windows, nux::Geometry const& max_bounds);67 nux::Size GridSizeForWindows(LayoutWindow::Vector const& windows, nux::Geometry const& max_bounds) const;
6768
68 nux::Size GridSizeForWindows(LayoutWindow::Vector const& windows, nux::Geometry const& max_bounds);69 std::vector<LayoutWindow::Vector> GetRows(LayoutWindow::Vector const& windows, nux::Geometry const& max_bounds) const;
6970
70 nux::Geometry ScaleBoxIntoBox(nux::Geometry const& bounds, nux::Geometry const& box);71 nux::Geometry ScaleBoxIntoBox(nux::Geometry const& bounds, nux::Geometry const& box);
71};72};