Merge lp:~azzar1/unity/fix-1053047 into lp:unity

Proposed by Andrea Azzarone
Status: Merged
Approved by: Andrea Azzarone
Approved revision: no longer in the source branch.
Merged at revision: 2812
Proposed branch: lp:~azzar1/unity/fix-1053047
Merge into: lp:unity
Diff against target: 328 lines (+178/-16)
7 files modified
dash/LensView.cpp (+1/-1)
dash/PlacesGroup.cpp (+9/-13)
dash/PlacesGroup.h (+4/-1)
tests/CMakeLists.txt (+5/-0)
tests/test_places_group.cpp (+103/-0)
unity-shared/DashStyle.h (+3/-1)
unity-shared/DashStyleInterface.h (+53/-0)
To merge this branch: bzr merge lp:~azzar1/unity/fix-1053047
Reviewer Review Type Date Requested Status
Nick Dedekind (community) Approve
Review via email: mp+126067@code.launchpad.net

Commit message

Use expand icon by default.

Description of the change

== Problem ==
Dash - Category expander arrow is in expanded mode no metter if category is actually expanded.

== Test ==
Unit test added.

To post a comment you must log in.
Revision history for this message
Stephen M. Webb (bregma) wrote :

Any reason why the accessor member functions of your StyleInterface ABC are not all const?

Revision history for this message
Andrea Azzarone (azzar1) wrote :

They were not-const and I kept not const.

Revision history for this message
Andrea Azzarone (azzar1) wrote :

*kept them

Revision history for this message
Nick Dedekind (nick-dedekind) wrote :

LGTM.

Dash style textures are loaded lazily, so it shouldn't be const; even though it's working on private data and technically could be.

I like the idea of style interfaces. We should do it for all the styles! Then we could have a style manager and be able to switch them.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'dash/LensView.cpp'
2--- dash/LensView.cpp 2012-09-19 18:45:56 +0000
3+++ dash/LensView.cpp 2012-09-24 18:05:42 +0000
4@@ -298,7 +298,7 @@
5 if (existing_group->GetCategoryIndex() == index) return;
6 }
7
8- PlacesGroup* group = new PlacesGroup();
9+ PlacesGroup* group = new PlacesGroup(dash::Style::Instance());
10 AddChild(group);
11 group->SetName(name);
12 group->SetIcon(icon_hint);
13
14=== modified file 'dash/PlacesGroup.cpp'
15--- dash/PlacesGroup.cpp 2012-09-19 18:45:56 +0000
16+++ dash/PlacesGroup.cpp 2012-09-24 18:05:42 +0000
17@@ -31,8 +31,6 @@
18 #include <UnityCore/GLibWrapper.h>
19
20 #include "unity-shared/StaticCairoText.h"
21-#include "unity-shared/DashStyle.h"
22-#include "unity-shared/LineSeparator.h"
23 #include "unity-shared/ubus-server.h"
24 #include "unity-shared/UBusMessages.h"
25
26@@ -112,8 +110,9 @@
27
28 NUX_IMPLEMENT_OBJECT_TYPE(PlacesGroup);
29
30-PlacesGroup::PlacesGroup()
31+PlacesGroup::PlacesGroup(dash::StyleInterface& style)
32 : nux::View(NUX_TRACKER_LOCATION),
33+ _style(style),
34 _child_view(nullptr),
35 _is_expanded(false),
36 _n_visible_items_in_unexpand_mode(0),
37@@ -122,15 +121,13 @@
38 _coverflow_enabled(false),
39 disabled_header_count_(false)
40 {
41- dash::Style& style = dash::Style::Instance();
42-
43 SetAcceptKeyNavFocusOnMouseDown(false);
44 SetAcceptKeyNavFocusOnMouseEnter(false);
45
46- nux::BaseTexture* arrow = style.GetGroupUnexpandIcon();
47+ nux::BaseTexture* arrow = _style.GetGroupExpandIcon();
48
49- _background = style.GetCategoryBackground();
50- _background_nofilters = style.GetCategoryBackgroundNoFilters();
51+ _background = _style.GetCategoryBackground();
52+ _background_nofilters = _style.GetCategoryBackgroundNoFilters();
53
54 nux::ROPConfig rop;
55 rop.Blend = true;
56@@ -154,7 +151,7 @@
57 _group_layout->AddView(_header_view, 0, nux::MINOR_POSITION_TOP, nux::MINOR_SIZE_FULL);
58
59 _header_layout = new nux::HLayout(NUX_TRACKER_LOCATION);
60- _header_layout->SetLeftAndRightPadding(style.GetCategoryHeaderLeftPadding(), 0);
61+ _header_layout->SetLeftAndRightPadding(_style.GetCategoryHeaderLeftPadding(), 0);
62 _header_layout->SetSpaceBetweenChildren(10);
63 _header_view->SetLayout(_header_layout);
64
65@@ -449,7 +446,7 @@
66 // only the width matters
67 if (_cached_geometry.GetWidth() != geo.GetWidth())
68 {
69- _focus_layer.reset(dash::Style::Instance().FocusOverlay(geo.width - kHighlightLeftPadding - kHighlightRightPadding, kHighlightHeight));
70+ _focus_layer.reset(_style.FocusOverlay(geo.width - kHighlightLeftPadding - kHighlightRightPadding, kHighlightHeight));
71 _cached_geometry = geo;
72 }
73 return ret;
74@@ -557,11 +554,10 @@
75
76 Refresh();
77
78- dash::Style& style = dash::Style::Instance();
79 if (_is_expanded)
80- _expand_icon->SetTexture(style.GetGroupUnexpandIcon());
81+ _expand_icon->SetTexture(_style.GetGroupUnexpandIcon());
82 else
83- _expand_icon->SetTexture(style.GetGroupExpandIcon());
84+ _expand_icon->SetTexture(_style.GetGroupExpandIcon());
85
86 expanded.emit(this);
87 }
88
89=== modified file 'dash/PlacesGroup.h'
90--- dash/PlacesGroup.h 2012-09-19 18:45:56 +0000
91+++ dash/PlacesGroup.h 2012-09-24 18:05:42 +0000
92@@ -28,6 +28,7 @@
93
94 #include <sigc++/sigc++.h>
95
96+#include "unity-shared/DashStyleInterface.h"
97 #include "unity-shared/IconTexture.h"
98 #include "unity-shared/Introspectable.h"
99 #include "unity-shared/StaticCairoText.h"
100@@ -53,7 +54,7 @@
101 NUX_DECLARE_OBJECT_TYPE(PlacesGroup, nux::View);
102 public:
103
104- PlacesGroup();
105+ PlacesGroup(dash::StyleInterface& style);
106
107 void SetIcon(std::string const& icon);
108 void SetName(std::string const& name);
109@@ -115,6 +116,8 @@
110 void RefreshLabel();
111
112 private:
113+ dash::StyleInterface& _style;
114+
115 nux::VLayout* _group_layout;
116 nux::View* _header_view;
117 nux::HLayout* _header_layout;
118
119=== modified file 'tests/CMakeLists.txt'
120--- tests/CMakeLists.txt 2012-09-20 20:49:51 +0000
121+++ tests/CMakeLists.txt 2012-09-24 18:05:42 +0000
122@@ -219,6 +219,7 @@
123 test_launcher_icon.cpp
124 test_keyboard_util.cpp
125 test_panel_style.cpp
126+ test_places_group.cpp
127 test_previews_application.cpp
128 test_previews_generic.cpp
129 test_previews_movie.cpp
130@@ -243,6 +244,10 @@
131 gmockvolume.c
132 ${CMAKE_SOURCE_DIR}/dash/DashViewPrivate.cpp
133 ${CMAKE_SOURCE_DIR}/dash/ResultRenderer.cpp
134+ ${CMAKE_SOURCE_DIR}/dash/PlacesGroup.cpp
135+ ${CMAKE_SOURCE_DIR}/dash/ResultRenderer.cpp
136+ ${CMAKE_SOURCE_DIR}/dash/ResultRendererHorizontalTile.cpp
137+ ${CMAKE_SOURCE_DIR}/dash/ResultRendererTile.cpp
138 ${CMAKE_SOURCE_DIR}/dash/ResultView.cpp
139 ${CMAKE_SOURCE_DIR}/dash/ResultViewGrid.cpp
140 ${CMAKE_SOURCE_DIR}/dash/previews/ActionButton.cpp
141
142=== added file 'tests/test_places_group.cpp'
143--- tests/test_places_group.cpp 1970-01-01 00:00:00 +0000
144+++ tests/test_places_group.cpp 2012-09-24 18:05:42 +0000
145@@ -0,0 +1,103 @@
146+/*
147+ * Copyright 2012 Canonical Ltd.
148+ *
149+ * This program is free software: you can redistribute it and/or modify it
150+ * under the terms of the GNU General Public License version 3, as published
151+ * by the Free Software Foundation.
152+ *
153+ * This program is distributed in the hope that it will be useful, but
154+ * WITHOUT ANY WARRANTY; without even the implied warranties of
155+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
156+ * PURPOSE. See the GNU General Public License for more details.
157+ *
158+ * You should have received a copy of the GNU General Public License
159+ * version 3 along with this program. If not, see
160+ * <http://www.gnu.org/licenses/>
161+ *
162+ * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com>
163+ *
164+ */
165+
166+#include "config.h"
167+#include <gmock/gmock.h>
168+using namespace testing;
169+
170+#include <Nux/Nux.h>
171+#include <Nux/PaintLayer.h>
172+
173+#include "PlacesGroup.h"
174+using namespace unity;
175+
176+namespace {
177+
178+class MockDashStyle : public dash::StyleInterface
179+{
180+public:
181+ MockDashStyle()
182+ {
183+ std::string full_path = PKGDATADIR "album_missing.png";
184+ glib::Object<GdkPixbuf> pixbuf(gdk_pixbuf_new_from_file_at_size(full_path.c_str(), 20, 20, nullptr));
185+ base_texture_.Adopt(nux::CreateTexture2DFromPixbuf(pixbuf, true));
186+ }
187+
188+ MOCK_METHOD2(FocusOverlay, nux::AbstractPaintLayer*(int width, int height));
189+ MOCK_METHOD0(GetCategoryBackground, nux::BaseTexture*());
190+ MOCK_METHOD0(GetCategoryBackgroundNoFilters, nux::BaseTexture*());
191+
192+ MOCK_METHOD0(GetGroupExpandIcon, nux::BaseTexture*());
193+ MOCK_METHOD0(GetGroupUnexpandIcon, nux::BaseTexture*());
194+
195+ MOCK_CONST_METHOD0(GetCategoryHeaderLeftPadding, int());
196+ MOCK_CONST_METHOD0(GetPlacesGroupTopSpace, int());
197+
198+ nux::ObjectPtr<nux::BaseTexture> base_texture_;
199+};
200+
201+
202+class TestPlacesGroup : public Test
203+{
204+public:
205+ void SetUp()
206+ {
207+ SetupMockDashStyle();
208+
209+ places_group_ = new PlacesGroup(dash_style_);
210+ }
211+
212+ void SetupMockDashStyle()
213+ {
214+ ON_CALL(dash_style_, FocusOverlay(_, _))
215+ .WillByDefault(Return(new nux::ColorLayer(nux::color::White)));
216+
217+ ON_CALL(dash_style_, GetCategoryBackground())
218+ .WillByDefault(Return(dash_style_.base_texture_.GetPointer()));
219+
220+ ON_CALL(dash_style_, GetCategoryBackgroundNoFilters())
221+ .WillByDefault(Return(dash_style_.base_texture_.GetPointer()));
222+
223+ ON_CALL(dash_style_, GetGroupExpandIcon())
224+ .WillByDefault(Return(dash_style_.base_texture_.GetPointer()));
225+
226+ ON_CALL(dash_style_, GetGroupUnexpandIcon())
227+ .WillByDefault(Return(dash_style_.base_texture_.GetPointer()));
228+ }
229+
230+ NiceMock<MockDashStyle> dash_style_;
231+ nux::ObjectPtr<PlacesGroup> places_group_;
232+};
233+
234+
235+TEST_F(TestPlacesGroup, Constructor)
236+{
237+ EXPECT_CALL(dash_style_, GetGroupExpandIcon())
238+ .Times(1);
239+
240+ EXPECT_CALL(dash_style_, GetGroupUnexpandIcon())
241+ .Times(0);
242+
243+ PlacesGroup places_group(dash_style_);
244+
245+ EXPECT_FALSE(places_group.GetExpanded());
246+}
247+
248+}
249
250=== modified file 'unity-shared/DashStyle.h'
251--- unity-shared/DashStyle.h 2012-09-20 12:52:02 +0000
252+++ unity-shared/DashStyle.h 2012-09-24 18:05:42 +0000
253@@ -20,6 +20,8 @@
254 #ifndef DASH_STYLE_H
255 #define DASH_STYLE_H
256
257+#include "DashStyleInterface.h"
258+
259 #include <Nux/Nux.h>
260 #include <Nux/View.h>
261 #include <Nux/AbstractButton.h>
262@@ -83,7 +85,7 @@
263 };
264
265
266-class Style
267+class Style : public StyleInterface
268 {
269 public:
270 Style ();
271
272=== added file 'unity-shared/DashStyleInterface.h'
273--- unity-shared/DashStyleInterface.h 1970-01-01 00:00:00 +0000
274+++ unity-shared/DashStyleInterface.h 2012-09-24 18:05:42 +0000
275@@ -0,0 +1,53 @@
276+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
277+/*
278+ * Copyright (C) 2012 Canonical Ltd
279+ *
280+ * This program is free software: you can redistribute it and/or modify
281+ * it under the terms of the GNU General Public License version 3 as
282+ * published by the Free Software Foundation.
283+ *
284+ * This program is distributed in the hope that it will be useful,
285+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
286+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
287+ * GNU General Public License for more details.
288+ *
289+ * You should have received a copy of the GNU General Public License
290+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
291+ *
292+ * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com>
293+ */
294+
295+#ifndef UNITYSHELL_DASH_STYLE_INTERFACE_H
296+#define UNITYSHELL_DASH_STYLE_INTERFACE_H
297+
298+#include <memory>
299+
300+namespace nux {
301+ class AbstractPaintLayer;
302+ class BaseTexture;
303+}
304+
305+namespace unity {
306+namespace dash {
307+
308+class StyleInterface
309+{
310+public:
311+ virtual ~StyleInterface() {};
312+
313+ virtual nux::AbstractPaintLayer* FocusOverlay(int width, int height) = 0;
314+
315+ virtual nux::BaseTexture* GetCategoryBackground() = 0;
316+ virtual nux::BaseTexture* GetCategoryBackgroundNoFilters() = 0;
317+
318+ virtual nux::BaseTexture* GetGroupUnexpandIcon() = 0;
319+ virtual nux::BaseTexture* GetGroupExpandIcon() = 0;
320+
321+ virtual int GetCategoryHeaderLeftPadding() const = 0;
322+ virtual int GetPlacesGroupTopSpace() const = 0;
323+};
324+
325+}
326+}
327+
328+#endif