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

Proposed by Andrea Azzarone on 2012-04-10
Status: Merged
Approved by: Gord Allott on 2012-04-11
Approved revision: 2266
Merged at revision: 2271
Proposed branch: lp:~azzar1/unity/fix-977961
Merge into: lp:unity
Diff against target: 286 lines (+78/-49)
6 files modified
plugins/unityshell/src/LensBar.cpp (+2/-42)
plugins/unityshell/src/LensBar.h (+0/-2)
plugins/unityshell/src/LensBarIcon.cpp (+40/-5)
plugins/unityshell/src/LensBarIcon.h (+7/-0)
tests/autopilot/autopilot/emulators/unity/dash.py (+9/-0)
tests/autopilot/autopilot/tests/test_dash.py (+20/-0)
To merge this branch: bzr merge lp:~azzar1/unity/fix-977961
Reviewer Review Type Date Requested Status
Alex Launi (community) quality 2012-04-10 Needs Fixing on 2012-04-10
Review via email: mp+101397@code.launchpad.net

Commit message

Lens selection should work when clicking in the rectangle outside of the icon.

Description of the change

UNBLOCK

== Problem ==
Lens selection should work when clicking in the rectangle outside of the icon.

== Fix ==
Now lens bar icons have the same size of the focus highlights.

== Test ==
AP test added.

To post a comment you must log in.
Alex Launi (alexlauni) wrote :

Please rename the DashLensBar(DashTestCase) class to DashLensBarTests(DashTestCase):

review: Approve (quality)
Alex Launi (alexlauni) wrote :

Sorry I hit save too quick/by accident.

Please rename the DashLensBar(DashTestCase) class to DashLensBarTests(DashTestCase):
Move the dash ensure_visible() and the getting of the lensbar into a setUp method. Every other lensbar test will need to do the same thing. Keep tests as clean as possible.

review: Needs Fixing (quality)
lp:~azzar1/unity/fix-977961 updated on 2012-04-10
2265. By Andrea Azzarone on 2012-04-10

Rename DashLensBar to DashLensBarTests.

2266. By Andrea Azzarone on 2012-04-10

Fix test style.

Andrea Azzarone (azzar1) wrote :

Done.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/unityshell/src/LensBar.cpp'
2--- plugins/unityshell/src/LensBar.cpp 2012-04-06 10:50:00 +0000
3+++ plugins/unityshell/src/LensBar.cpp 2012-04-10 18:39:25 +0000
4@@ -20,7 +20,6 @@
5 #include "config.h"
6
7 #include "CairoTexture.h"
8-#include "DashStyle.h"
9 #include "LensBar.h"
10 #include "UBusMessages.h"
11 #include "UBusWrapper.h"
12@@ -34,8 +33,6 @@
13
14 nux::logging::Logger logger("unity.dash.lensbar");
15
16-const int FOCUS_OVERLAY_WIDTH = 60;
17-const int FOCUS_OVERLAY_HEIGHT = 44;
18 const int LENSBAR_HEIGHT = 44;
19
20 }
21@@ -45,20 +42,11 @@
22 LensBar::LensBar()
23 : nux::View(NUX_TRACKER_LOCATION)
24 {
25- InitTheme();
26 SetupBackground();
27 SetupLayout();
28 SetupHomeLens();
29 }
30
31-void LensBar::InitTheme()
32-{
33- if (!focus_layer_)
34- {
35- focus_layer_.reset(Style::Instance().FocusOverlay(FOCUS_OVERLAY_WIDTH, FOCUS_OVERLAY_HEIGHT));
36- }
37-}
38-
39 void LensBar::SetupBackground()
40 {
41 nux::ROPConfig rop;
42@@ -72,7 +60,6 @@
43 {
44 layout_ = new nux::HLayout(NUX_TRACKER_LOCATION);
45 layout_->SetContentDistribution(nux::MAJOR_POSITION_CENTER);
46- layout_->SetSpaceBetweenChildren(40);
47 SetLayout(layout_);
48
49 SetMinimumHeight(LENSBAR_HEIGHT);
50@@ -86,6 +73,7 @@
51 icon->active = true;
52 icons_.push_back(icon);
53 layout_->AddView(icon, 0, nux::eCenter, nux::MINOR_SIZE_FULL);
54+ AddChild(icon);
55
56 icon->mouse_click.connect([&, icon] (int x, int y, unsigned long button, unsigned long keyboard) { SetActive(icon); QueueDraw(); });
57 icon->mouse_down.connect([&] (int x, int y, unsigned long button, unsigned long keyboard) { QueueDraw(); });
58@@ -100,6 +88,7 @@
59 lens->visible.changed.connect([icon](bool visible) { icon->SetVisible(visible); } );
60 icons_.push_back(icon);
61 layout_->AddView(icon, 0, nux::eCenter, nux::eFix);
62+ AddChild(icon);
63
64 icon->mouse_click.connect([&, icon] (int x, int y, unsigned long button, unsigned long keyboard) { SetActive(icon); QueueDraw(); });
65 icon->mouse_down.connect([&] (int x, int y, unsigned long button, unsigned long keyboard) { QueueDraw(); });
66@@ -129,25 +118,6 @@
67 bg_layer_->SetGeometry(base);
68 nux::GetPainter().RenderSinglePaintLayer(gfx_context, base, bg_layer_.get());
69
70- for (auto icon : icons_)
71- {
72- if (icon->HasKeyFocus() && focus_layer_)
73- {
74- nux::Geometry geo(icon->GetGeometry());
75-
76- // Center it
77- geo.x -= (FOCUS_OVERLAY_WIDTH - geo.width) / 2;
78- geo.y -= (FOCUS_OVERLAY_HEIGHT - geo.height) / 2;
79- geo.width = FOCUS_OVERLAY_WIDTH;
80- geo.height = FOCUS_OVERLAY_HEIGHT;
81-
82- nux::AbstractPaintLayer* layer = focus_layer_.get();
83-
84- layer->SetGeometry(geo);
85- layer->Renderlayer(gfx_context);
86- }
87- }
88-
89 gfx_context.PopClippingRectangle();
90
91 // trigger a redraw of the decoration, as the special masking of the
92@@ -166,16 +136,6 @@
93 if (!IsFullRedraw())
94 nux::GetPainter().PushLayer(gfx_context, bg_layer_->GetGeometry(), bg_layer_.get());
95
96- for (auto icon: icons_)
97- {
98- if (icon->HasKeyFocus() && !IsFullRedraw() && focus_layer_)
99- {
100- nux::AbstractPaintLayer* layer = focus_layer_.get();
101-
102- nux::GetPainter().PushLayer(gfx_context, focus_layer_->GetGeometry(), layer);
103- }
104- }
105-
106 layout_->ProcessDraw(gfx_context, force_draw);
107
108 if (!IsFullRedraw())
109
110=== modified file 'plugins/unityshell/src/LensBar.h'
111--- plugins/unityshell/src/LensBar.h 2012-04-02 21:04:46 +0000
112+++ plugins/unityshell/src/LensBar.h 2012-04-10 18:39:25 +0000
113@@ -59,7 +59,6 @@
114 sigc::signal<void, std::string const&> lens_activated;
115
116 private:
117- void InitTheme();
118 void SetupBackground();
119 void SetupLayout();
120 void SetupHomeLens();
121@@ -81,7 +80,6 @@
122
123 nux::HLayout* layout_;
124 LayerPtr bg_layer_;
125- LayerPtr focus_layer_;
126 };
127
128 } // namespace dash
129
130=== modified file 'plugins/unityshell/src/LensBarIcon.cpp'
131--- plugins/unityshell/src/LensBarIcon.cpp 2012-03-26 22:43:48 +0000
132+++ plugins/unityshell/src/LensBarIcon.cpp 2012-04-10 18:39:25 +0000
133@@ -16,6 +16,9 @@
134 * Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
135 */
136
137+#include <UnityCore/Variant.h>
138+
139+#include "DashStyle.h"
140 #include "LensBarIcon.h"
141
142 #include "config.h"
143@@ -24,6 +27,13 @@
144 {
145 namespace dash
146 {
147+namespace
148+{
149+
150+const int FOCUS_OVERLAY_HEIGHT = 44;
151+const int FOCUS_OVERLAY_WIDTH = 60;
152+
153+}
154
155 NUX_IMPLEMENT_OBJECT_TYPE(LensBarIcon);
156
157@@ -33,10 +43,13 @@
158 , active(false)
159 , inactive_opacity_(0.4f)
160 {
161- SetMinimumWidth(24);
162- SetMaximumWidth(24);
163- SetMinimumHeight(24);
164- SetMaximumHeight(24);
165+ SetMinimumWidth(FOCUS_OVERLAY_WIDTH);
166+ SetMaximumWidth(FOCUS_OVERLAY_WIDTH);
167+ SetMinimumHeight(FOCUS_OVERLAY_HEIGHT);
168+ SetMaximumHeight(FOCUS_OVERLAY_HEIGHT);
169+
170+ focus_layer_.reset(Style::Instance().FocusOverlay(FOCUS_OVERLAY_WIDTH, FOCUS_OVERLAY_HEIGHT));
171+
172 SetOpacity(inactive_opacity_);
173
174 SetAcceptKeyNavFocus(true);
175@@ -54,7 +67,6 @@
176 nux::Geometry const& geo = GetGeometry();
177
178 gfx_context.PushClippingRectangle(geo);
179-
180 nux::GetPainter().PaintBackground(gfx_context, geo);
181
182 if (!texture())
183@@ -63,6 +75,15 @@
184 return;
185 }
186
187+ if (HasKeyFocus() && focus_layer_)
188+ {
189+ nux::Geometry geo(GetGeometry());
190+ nux::AbstractPaintLayer* layer = focus_layer_.get();
191+
192+ layer->SetGeometry(geo);
193+ layer->Renderlayer(gfx_context);
194+ }
195+
196 float opacity = active ? 1.0f : inactive_opacity_;
197 int width = 0, height = 0;
198 GetTextureSize(&width, &height);
199@@ -88,5 +109,19 @@
200 QueueDraw();
201 }
202
203+// Introspectable
204+std::string LensBarIcon::GetName() const
205+{
206+ return "LensBarIcon";
207+}
208+
209+void LensBarIcon::AddProperties(GVariantBuilder* builder)
210+{
211+ unity::variant::BuilderWrapper wrapper(builder);
212+
213+ wrapper.add(GetAbsoluteGeometry());
214+ wrapper.add("name", id);
215+}
216+
217 }
218 }
219
220=== modified file 'plugins/unityshell/src/LensBarIcon.h'
221--- plugins/unityshell/src/LensBarIcon.h 2011-08-22 17:02:48 +0000
222+++ plugins/unityshell/src/LensBarIcon.h 2012-04-10 18:39:25 +0000
223@@ -47,8 +47,15 @@
224 void Draw(nux::GraphicsEngine& gfx_context, bool force_draw);
225 void OnActiveChanged(bool is_active);
226
227+ // Introspectable
228+ std::string GetName() const;
229+ void AddProperties(GVariantBuilder* builder);
230+
231 private:
232+ typedef std::unique_ptr<nux::AbstractPaintLayer> LayerPtr;
233+
234 const float inactive_opacity_;
235+ LayerPtr focus_layer_;
236 };
237
238 }
239
240=== modified file 'tests/autopilot/autopilot/emulators/unity/dash.py'
241--- tests/autopilot/autopilot/emulators/unity/dash.py 2012-04-05 13:42:53 +0000
242+++ tests/autopilot/autopilot/emulators/unity/dash.py 2012-04-10 18:39:25 +0000
243@@ -176,6 +176,15 @@
244
245 class LensBar(UnityIntrospectionObject):
246 """The bar of lens icons at the bottom of the dash."""
247+ def get_icon_by_name(self, name):
248+ """Get a LensBarIcon child object by it's name. For example, 'home.lens'."""
249+ icons = self.get_children_by_type(LensBarIcon)
250+ for icon in icons:
251+ if icon.name == name:
252+ return icon
253+
254+class LensBarIcon(UnityIntrospectionObject):
255+ """A lens icon at the bottom of the dash."""
256
257
258 class LensView(UnityIntrospectionObject):
259
260=== modified file 'tests/autopilot/autopilot/tests/test_dash.py'
261--- tests/autopilot/autopilot/tests/test_dash.py 2012-04-02 20:18:58 +0000
262+++ tests/autopilot/autopilot/tests/test_dash.py 2012-04-10 18:39:25 +0000
263@@ -496,3 +496,23 @@
264 expand_label_y = group.expand_label_y + group.expand_label_baseline
265 name_label_y = group.name_label_y + group.name_label_baseline
266 self.assertThat(expand_label_y, Equals(name_label_y))
267+
268+class DashLensBarTests(DashTestCase):
269+ """Tests that the lensbar works well."""
270+ def setUp(self):
271+ super(DashLensBarTests, self).setUp()
272+ self.dash.ensure_visible()
273+ self.lensbar = self.dash.view.get_lensbar()
274+
275+ def test_click_inside_highlight(self):
276+ """Lens selection should work when clicking in
277+ the rectangle outside of the icon.
278+ """
279+ app_icon = self.lensbar.get_icon_by_name(u'applications.lens')
280+
281+ self.mouse.move(app_icon.x, app_icon.y)
282+ self.mouse.click()
283+
284+ sleep(1)
285+
286+ self.assertEqual(self.lensbar.active_lens, u'applications.lens')