Merge lp:~mandel/unity/fix-static-cairo-text into lp:unity

Proposed by Manuel de la Peña
Status: Merged
Approved by: Nick Dedekind
Approved revision: no longer in the source branch.
Merged at revision: 2971
Proposed branch: lp:~mandel/unity/fix-static-cairo-text
Merge into: lp:unity
Diff against target: 367 lines (+182/-34)
7 files modified
launcher/LauncherIcon.cpp (+3/-3)
launcher/Tooltip.cpp (+19/-14)
launcher/Tooltip.h (+7/-6)
tests/CMakeLists.txt (+1/-0)
tests/test_launcher_tooltip.cpp (+109/-0)
tests/test_static_cairo_text.cpp (+33/-5)
unity-shared/StaticCairoText.cpp (+10/-6)
To merge this branch: bzr merge lp:~mandel/unity/fix-static-cairo-text
Reviewer Review Type Date Requested Status
Marco Trevisan (Treviño) Approve
Nick Dedekind (community) Needs Fixing
Brandon Schaefer (community) Approve
Tim Penhey Pending
PS Jenkins bot continuous-integration Pending
Review via email: mp+138966@code.launchpad.net

This proposal supersedes a proposal from 2012-12-05.

Description of the change

Fixes #1071327 by ensuring that the PreLayoutManagement method does not call SetBaseSize unless is really needed else (if it is called) the method will be called again making the nux layout get into an infinite loop.

Tests can be ran doing ./tests/test-gtest --gtest_filter=*TestStaticCairoText* from the build dir. In order to run the launcher tooltip tests please do ./tests/test-gtest --gtest_filter=*Tooltip* and run the launcher to assert that tooltips work as expected.

To post a comment you must log in.
Revision history for this message
Nick Dedekind (nick-dedekind) wrote : Posted in a previous version of this proposal

LGTM.
Tests provided succeed.

review: Approve
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote : Posted in a previous version of this proposal

Waiting for a proper fix in nux, this is fine.

review: Approve
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote : Posted in a previous version of this proposal

This causes a regression in the tooltips...

http://i.imgur.com/cVZUb.jpg

review: Needs Fixing
Revision history for this message
Tim Penhey (thumper) wrote : Posted in a previous version of this proposal
Revision history for this message
Tim Penhey (thumper) wrote : Posted in a previous version of this proposal

A test should be added to work out why tooltip rendering broke, and make the tests pass.

review: Needs Fixing
Revision history for this message
Manuel de la Peña (mandel) wrote : Posted in a previous version of this proposal

Sorry, I did not check that the launcher would work correctly and I just focused on the Dash. Is a very simple fix will push asap (The min height of the label has to be the one returned by extend).

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Fix works ok and test passes, but since you're there... Could you please get rid of the _labelText variable (you can just use the StaticCairoText::GetText where needed)? It looks like a duplication to me.

150 + Settings* settings;

No need a pointer here... Just add Settings settings;

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

Looks good to me now. Tooltip renders correctly.

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

57 + text.SetSetterFunction([this](std::string newText)
58 + {
59 + this->_tooltip_text->SetText(newText);
60 + return true;
61 + }
62 + );c

You can't just return true; otherwise the property changed signal gets emitted every time you call set. It should only return true if the value of the text has changed, otherwise false.

48 + _tooltip_text = new nux::StaticCairoText(TEXT("Unity"), NUX_TRACKER_LOCATION);
271 + EXPECT_NE(new_tip, tooltip->_tooltip_text->GetText());

Don't know why tool-tips are being initialised to TEXT("Unity"). They should be blank by default.
And then you can change the test to:
271 + EXPECT_EQ("", tooltip->_tooltip_text->GetText());

Otherwise, LGTM.
Builds OK for me, runs and passes test.

review: Approve
Revision history for this message
Nick Dedekind (nick-dedekind) :
review: Needs Fixing
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Thanks for the property fixes, it looks ok now.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'launcher/LauncherIcon.cpp'
--- launcher/LauncherIcon.cpp 2012-12-03 15:34:23 +0000
+++ launcher/LauncherIcon.cpp 2012-12-11 15:48:21 +0000
@@ -147,7 +147,7 @@
147 _tooltip = new Tooltip();147 _tooltip = new Tooltip();
148 AddChild(_tooltip.GetPointer());148 AddChild(_tooltip.GetPointer());
149149
150 _tooltip->SetText(tooltip_text());150 _tooltip->text = tooltip_text();
151}151}
152152
153void LauncherIcon::LoadQuicklist()153void LauncherIcon::LoadQuicklist()
@@ -475,7 +475,7 @@
475 {475 {
476 target = escaped;476 target = escaped;
477 if (_tooltip)477 if (_tooltip)
478 _tooltip->SetText(target);478 _tooltip->text = target;
479 result = true;479 result = true;
480 }480 }
481481
@@ -520,7 +520,7 @@
520520
521 if (!_tooltip)521 if (!_tooltip)
522 LoadTooltip();522 LoadTooltip();
523 _tooltip->SetText(tooltip_text());523 _tooltip->text = tooltip_text();
524 _tooltip->ShowTooltipWithTipAt(tip_x, tip_y);524 _tooltip->ShowTooltipWithTipAt(tip_x, tip_y);
525 _tooltip->ShowWindow(!tooltip_text().empty());525 _tooltip->ShowWindow(!tooltip_text().empty());
526 tooltip_visible.emit(_tooltip);526 tooltip_visible.emit(_tooltip);
527527
=== modified file 'launcher/Tooltip.cpp'
--- launcher/Tooltip.cpp 2012-11-06 18:19:09 +0000
+++ launcher/Tooltip.cpp 2012-12-11 15:48:21 +0000
@@ -47,7 +47,6 @@
47Tooltip::Tooltip() :47Tooltip::Tooltip() :
48 _anchorX(0),48 _anchorX(0),
49 _anchorY(0),49 _anchorY(0),
50 _labelText(TEXT("Unity")),
51 _cairo_text_has_changed(true)50 _cairo_text_has_changed(true)
52{51{
53 _hlayout = new nux::HLayout(TEXT(""), NUX_TRACKER_LOCATION);52 _hlayout = new nux::HLayout(TEXT(""), NUX_TRACKER_LOCATION);
@@ -61,7 +60,7 @@
6160
62 _vlayout->AddLayout(_top_space, 0);61 _vlayout->AddLayout(_top_space, 0);
6362
64 _tooltip_text = new nux::StaticCairoText(_labelText, NUX_TRACKER_LOCATION);63 _tooltip_text = new nux::StaticCairoText(TEXT(""), NUX_TRACKER_LOCATION);
65 _tooltip_text->SetTextAlignment(nux::StaticCairoText::AlignState::NUX_ALIGN_CENTRE);64 _tooltip_text->SetTextAlignment(nux::StaticCairoText::AlignState::NUX_ALIGN_CENTRE);
66 _tooltip_text->SetTextVerticalAlignment(nux::StaticCairoText::AlignState::NUX_ALIGN_CENTRE);65 _tooltip_text->SetTextVerticalAlignment(nux::StaticCairoText::AlignState::NUX_ALIGN_CENTRE);
67 _tooltip_text->SetMinimumWidth(MINIMUM_TEXT_WIDTH);66 _tooltip_text->SetMinimumWidth(MINIMUM_TEXT_WIDTH);
@@ -69,6 +68,22 @@
69 _tooltip_text->sigTextChanged.connect(sigc::mem_fun(this, &Tooltip::RecvCairoTextChanged));68 _tooltip_text->sigTextChanged.connect(sigc::mem_fun(this, &Tooltip::RecvCairoTextChanged));
70 _tooltip_text->sigFontChanged.connect(sigc::mem_fun(this, &Tooltip::RecvCairoTextChanged));69 _tooltip_text->sigFontChanged.connect(sigc::mem_fun(this, &Tooltip::RecvCairoTextChanged));
7170
71 // getter and setter for the property
72 text.SetSetterFunction([this](std::string newText)
73 {
74 if(_tooltip_text->GetText() == newText)
75 return false;
76
77 _tooltip_text->SetText(newText);
78 return true;
79 }
80 );
81 text.SetGetterFunction([this]()
82 {
83 return _tooltip_text->GetText();
84 }
85 );
86
72 _vlayout->AddView(_tooltip_text.GetPointer(), 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);87 _vlayout->AddView(_tooltip_text.GetPointer(), 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
7388
74 _vlayout->AddLayout(_bottom_space, 0);89 _vlayout->AddLayout(_bottom_space, 0);
@@ -129,6 +144,7 @@
129 }144 }
130145
131 _tooltip_text->SetMinimumWidth(text_min_width);146 _tooltip_text->SetMinimumWidth(text_min_width);
147 _tooltip_text->SetMinimumHeight(text_height);
132148
133 if (text_height < ANCHOR_HEIGHT)149 if (text_height < ANCHOR_HEIGHT)
134 {150 {
@@ -539,17 +555,6 @@
539{555{
540}556}
541557
542void Tooltip::SetText(std::string const& text)
543{
544 if (_labelText == text)
545 return;
546
547 _labelText = text;
548 _tooltip_text->SetText(_labelText);
549
550 QueueRelayout();
551}
552
553// Introspection558// Introspection
554559
555std::string Tooltip::GetName() const560std::string Tooltip::GetName() const
@@ -560,7 +565,7 @@
560void Tooltip::AddProperties(GVariantBuilder* builder)565void Tooltip::AddProperties(GVariantBuilder* builder)
561{566{
562 variant::BuilderWrapper(builder)567 variant::BuilderWrapper(builder)
563 .add("text", _labelText)568 .add("text", text)
564 .add("x", GetBaseX())569 .add("x", GetBaseX())
565 .add("y", GetBaseY())570 .add("y", GetBaseY())
566 .add("width", GetBaseWidth())571 .add("width", GetBaseWidth())
567572
=== modified file 'launcher/Tooltip.h'
--- launcher/Tooltip.h 2012-07-09 13:34:41 +0000
+++ launcher/Tooltip.h 2012-12-11 15:48:21 +0000
@@ -39,11 +39,11 @@
39public:39public:
40 Tooltip();40 Tooltip();
4141
42 nux::RWProperty<std::string> text;
43
42 void Draw(nux::GraphicsEngine& gfxContext, bool forceDraw);44 void Draw(nux::GraphicsEngine& gfxContext, bool forceDraw);
43 void DrawContent(nux::GraphicsEngine& gfxContext, bool forceDraw);45 void DrawContent(nux::GraphicsEngine& gfxContext, bool forceDraw);
4446
45 void SetText(std::string const& text);
46
47 void ShowTooltipWithTipAt(int anchor_tip_x, int anchor_tip_y);47 void ShowTooltipWithTipAt(int anchor_tip_x, int anchor_tip_y);
4848
49 // Introspection49 // Introspection
@@ -52,11 +52,15 @@
5252
53 virtual nux::Area* FindAreaUnderMouse(const nux::Point& mouse_position, nux::NuxEventType event_type);53 virtual nux::Area* FindAreaUnderMouse(const nux::Point& mouse_position, nux::NuxEventType event_type);
5454
55private:55protected:
56 // protected to simplify testing
57 nux::ObjectPtr<nux::StaticCairoText> _tooltip_text;
58
56 void RecvCairoTextChanged(nux::StaticCairoText* cairo_text);59 void RecvCairoTextChanged(nux::StaticCairoText* cairo_text);
5760
58 void PreLayoutManagement();61 void PreLayoutManagement();
5962
63private:
60 long PostLayoutManagement(long layoutResult);64 long PostLayoutManagement(long layoutResult);
6165
62 void PositionChildLayout(float offsetX,66 void PositionChildLayout(float offsetX,
@@ -69,9 +73,6 @@
6973
70 int _anchorX;74 int _anchorX;
71 int _anchorY;75 int _anchorY;
72 std::string _labelText;
73
74 nux::ObjectPtr<nux::StaticCairoText> _tooltip_text;
7576
76 nux::HLayout* _hlayout;77 nux::HLayout* _hlayout;
77 nux::VLayout* _vlayout;78 nux::VLayout* _vlayout;
7879
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2012-12-11 02:33:06 +0000
+++ tests/CMakeLists.txt 2012-12-11 15:48:21 +0000
@@ -219,6 +219,7 @@
219 test_launcher_hide_machine.cpp219 test_launcher_hide_machine.cpp
220 test_launcher_hover_machine.cpp220 test_launcher_hover_machine.cpp
221 test_launcher_icon.cpp221 test_launcher_icon.cpp
222 test_launcher_tooltip.cpp
222 test_keyboard_util.cpp223 test_keyboard_util.cpp
223 test_panel_style.cpp224 test_panel_style.cpp
224 test_panel_menu_view.cpp225 test_panel_menu_view.cpp
225226
=== added file 'tests/test_launcher_tooltip.cpp'
--- tests/test_launcher_tooltip.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_launcher_tooltip.cpp 2012-12-11 15:48:21 +0000
@@ -0,0 +1,109 @@
1/*
2 * Copyright 2012 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3, as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the applicable version of the GNU Lesser General Public
12 * License for more details.
13 *
14 * You should have received a copy of both the GNU Lesser General Public
15 * License version 3 along with this program. If not, see
16 * <http://www.gnu.org/licenses/>
17 *
18 * Authored by: Manuel de la Pena <manuel.delapena@canonical.com>
19 *
20 */
21
22#include <gmock/gmock.h>
23#include <gtest/gtest.h>
24
25#include "unity-shared/StaticCairoText.h"
26#include "launcher/Tooltip.h"
27
28#include <unity-shared/UnitySettings.h>
29#include "test_utils.h"
30
31namespace unity
32{
33
34class MockStaticCairoText : public nux::StaticCairoText
35{
36public:
37 MOCK_METHOD1(SetMinimumWidth, void(int));
38 MOCK_METHOD1(SetMinimumHeight, void(int));
39
40 MockStaticCairoText(std::string const& text):StaticCairoText(text) {}
41
42}; // StaticCairoText
43
44class TooltipMock : public Tooltip
45{
46public:
47
48 TooltipMock() : Tooltip()
49 {
50 // change the text and reconnect it as it should
51 std::string old_text = _tooltip_text->GetText();
52 _tooltip_text = new MockStaticCairoText(old_text);
53 _tooltip_text->SetTextAlignment(
54 nux::StaticCairoText::AlignState::NUX_ALIGN_CENTRE);
55 _tooltip_text->SetTextVerticalAlignment(
56 nux::StaticCairoText::AlignState::NUX_ALIGN_CENTRE);
57
58 _tooltip_text->sigTextChanged.connect(
59 sigc::mem_fun(this, &TooltipMock::RecvCairoTextChanged));
60 _tooltip_text->sigFontChanged.connect(
61 sigc::mem_fun(this, &TooltipMock::RecvCairoTextChanged));
62 }
63
64 using Tooltip::_tooltip_text;
65 using Tooltip::RecvCairoTextChanged;
66 using Tooltip::PreLayoutManagement;
67
68}; // TooltipMock
69
70
71class TestTooltip : public ::testing::Test
72{
73protected:
74 TestTooltip() : Test()
75 {
76 Settings settings;
77 tooltip = new TooltipMock();
78 }
79
80 nux::ObjectPtr<TooltipMock> tooltip;
81}; // TestTooltip
82
83TEST_F(TestTooltip, StaticCairoTextCorrectSize)
84{
85 int text_width;
86 int text_height;
87 tooltip->_tooltip_text->GetTextExtents(text_width, text_height);
88
89 // do assert that the methods are called with at least the min size provided
90 // by the GetTextExtents method
91 MockStaticCairoText* text = dynamic_cast<MockStaticCairoText*>(
92 tooltip->_tooltip_text.GetPointer());
93
94 EXPECT_CALL(*text, SetMinimumWidth(testing::Ge(text_width)));
95 EXPECT_CALL(*text, SetMinimumHeight(testing::Ge(text_height)));
96
97 tooltip->PreLayoutManagement();
98}
99
100TEST_F(TestTooltip, TestSetTooltipText)
101{
102 std::string new_tip = "My tooltip";
103 EXPECT_EQ("", tooltip->_tooltip_text->GetText());
104
105 tooltip->text.Set(new_tip);
106 EXPECT_EQ(new_tip, tooltip->_tooltip_text->GetText());
107}
108
109} // unity
0110
=== modified file 'tests/test_static_cairo_text.cpp'
--- tests/test_static_cairo_text.cpp 2012-12-10 00:32:30 +0000
+++ tests/test_static_cairo_text.cpp 2012-12-11 15:48:21 +0000
@@ -33,17 +33,33 @@
33class MockStaticCairoText : public nux::StaticCairoText33class MockStaticCairoText : public nux::StaticCairoText
34{34{
35public:35public:
36 MOCK_METHOD2(SetBaseSize, void(int, int));
37
36 MockStaticCairoText():StaticCairoText("") {}38 MockStaticCairoText():StaticCairoText("") {}
3739
38 using StaticCairoText::GetTextureStartIndices;40 using StaticCairoText::GetTextureStartIndices;
39 using StaticCairoText::GetTextureEndIndices;41 using StaticCairoText::GetTextureEndIndices;
40};42 using StaticCairoText::PreLayoutManagement;
4143};
42TEST(TestStaticCairoText, TextTextureSize)44
43{45class TestStaticCairoText : public ::testing::Test
46{
47
48protected:
49 TestStaticCairoText() : Test()
50 {
51 text = new MockStaticCairoText();
52 }
53
54 nux::ObjectPtr<MockStaticCairoText> text;
55
56};
57
58TEST_F(TestStaticCairoText, TextTextureSize)
59{
60 EXPECT_CALL(*text.GetPointer(), SetBaseSize(_, _)).Times(AnyNumber());
44 // Test multi-texture stitching support.61 // Test multi-texture stitching support.
4562
46 nux::ObjectPtr<MockStaticCairoText> text(new MockStaticCairoText());
47 text->SetLines(-2000);63 text->SetLines(-2000);
48 text->SetMaximumWidth(100);64 text->SetMaximumWidth(100);
4965
@@ -70,4 +86,16 @@
70 }86 }
71}87}
7288
89TEST_F(TestStaticCairoText, TextPreLayoutManagementMultipleCalls)
90{
91 EXPECT_CALL(*text.GetPointer(), SetBaseSize(_, _)).Times(2);
92 text->PreLayoutManagement();
93
94 // the first prelayout methods should have called set base size and therefore
95 // we should not call it again
96
97 EXPECT_CALL(*text.GetPointer(), SetBaseSize(_, _)).Times(0);
98 text->PreLayoutManagement();
99}
100
73}101}
74102
=== modified file 'unity-shared/StaticCairoText.cpp'
--- unity-shared/StaticCairoText.cpp 2012-12-10 00:32:30 +0000
+++ unity-shared/StaticCairoText.cpp 2012-12-11 15:48:21 +0000
@@ -229,12 +229,16 @@
229void StaticCairoText::PreLayoutManagement()229void StaticCairoText::PreLayoutManagement()
230{230{
231 Geometry geo = GetGeometry();231 Geometry geo = GetGeometry();
232 pimpl->pre_layout_size_.width = geo.width;232
233 pimpl->pre_layout_size_.height = geo.height;233 if(pimpl->pre_layout_size_.width != geo.width
234234 || pimpl->pre_layout_size_.height != geo.height)
235 SetBaseSize(pimpl->cached_extent_.width,235 {
236 pimpl->cached_extent_.height);236 pimpl->pre_layout_size_.width = geo.width;
237237 pimpl->pre_layout_size_.height = geo.height;
238
239 SetBaseSize(pimpl->cached_extent_.width,
240 pimpl->cached_extent_.height);
241 }
238 if (pimpl->textures2D_.empty())242 if (pimpl->textures2D_.empty())
239 {243 {
240 pimpl->UpdateTexture();244 pimpl->UpdateTexture();