Merge lp:~jjed/unity/tooltips-redux into lp:unity

Proposed by Jjed
Status: Merged
Approved by: Stephen M. Webb
Approved revision: no longer in the source branch.
Merged at revision: 3191
Proposed branch: lp:~jjed/unity/tooltips-redux
Merge into: lp:unity
Diff against target: 564 lines (+356/-36)
11 files modified
launcher/AbstractLauncherIcon.h (+1/-0)
launcher/CMakeLists.txt (+1/-0)
launcher/Launcher.cpp (+21/-24)
launcher/Launcher.h (+3/-0)
launcher/LauncherIcon.cpp (+0/-11)
launcher/MockLauncherIcon.h (+5/-1)
launcher/TooltipManager.cpp (+126/-0)
launcher/TooltipManager.h (+57/-0)
tests/CMakeLists.txt (+1/-0)
tests/autopilot/unity/tests/launcher/test_tooltips.py (+87/-0)
tests/test_tooltip_manager.cpp (+54/-0)
To merge this branch: bzr merge lp:~jjed/unity/tooltips-redux
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Stephen M. Webb (community) Approve
Marco Trevisan (Treviño) Approve
Jjed (community) Needs Resubmitting
Thomi Richards Pending
Review via email: mp+150942@code.launchpad.net

Commit message

Add a 1s delay between hovering on a launcher icon and showing its tooltip.
Further tooltips before clicking or unhovering launcher will appear instantly.

Description of the change

== Problem

There is currently no delay between hovering on a Launcher icon and displaying its tooltip.

This proposal supercedes the (long defunct) lp:~j-johan-edwards/unity/tooltip-delay/ merge proposal.

== Fix implementation

I've removed the ability of `LauncherIcon` to prompt its own tooltip display. Instead, a new object `TooltipManager`
(notified of events by a monitor's `Launcher`) controls launcher tooltip logic according to a `_hover_timer` which resets on mouse movement. A `LauncherIcon` may refuse to display based on its local condition (eg if it is the BFB and active, or being dragged).

Clicking an icon causes its tooltip to disappear, and the `_hover_clock` to be "locked" until the mouse moves to another icon. This behavior feels right to me (as otherwise tooltips appear while you hover over an app you just clicked, waiting for it to open) but I'm open to changing it.

Tooltip delay is 1s per lp:#687956. Let me know if the design has changed.

== Testing

There are three new autopilot tests in `test_tooltips`. Dash tooltip behavior is further tested in `test_icon_behavior`.

`autopilot run unity.tests.launcher` passes. I have only one monitor.

== Old feedback

I'm using `assertTrue` in my tooltips test because the behavior tested is time-specific, and `assertThat(.... Eventually(Equals(bool))` doesn't distinguish between instantaneous and delayed tooltip display. Maybe there's some other way...?

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

(1) Please fix the copyright dates in the new source files.
(2) Please do not prepend an underscore wart to indicate a member variable: the Unity style is to use appended underscore warts.
(3) You need to add a commit message to this MP.

Other than that, this seems OK.

review: Needs Fixing
Revision history for this message
Jjed (jjed) wrote :

I believe that should fix them. Thanks for the quick review!

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

+#define NULL_ICON (AbstractLauncherIcon::Ptr)nullptr

Don't do this please :)

314 +void TooltipManager::StopTimer() {
315 + hover_timer_.reset(new glib::Timeout(TOOLTIPS_SHOW_TIMEOUT_LENGTH));
316 +}

Is this the right way to stop the timeout?

Also I think you can unit test the new class ;)

Revision history for this message
Jjed (jjed) wrote :

> Don't do this please :)

Okay, removed.

> Is this the right way to stop the timeout?

It seems to be (you can `grep -R "reset(new glib::Timeout" to see similar uses). `hover_timer_->Remove() would also stop it, but then I'd just need add the same line afterwards to set a new timeout.

> Also I think you can unit test the new class

Okay, added. There's not much to test, as the modules only interaction with the outside world is calling `icon_->ShowTooltip()` and `icon_->HideTooltip()`. Tell me if there are any other test cases you'd like to see.

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

324 +void TooltipManager::StopTimer() {
325 + hover_timer_.reset(new glib::Timeout(TOOLTIPS_SHOW_TIMEOUT_LENGTH));
326 +}

Please just call hover_timer_.reset();

Then when you need to start it again, reset it to a new one.

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

> > Don't do this please :)
>
> Okay, removed.
>
> > Is this the right way to stop the timeout?
>
> It seems to be (you can `grep -R "reset(new glib::Timeout" to see similar
> uses). `hover_timer_->Remove() would also stop it, but then I'd just need add
> the same line afterwards to set a new timeout.

hover_timer_->reset() should just work.

>
> > Also I think you can unit test the new class
>
> Okay, added. There's not much to test, as the modules only interaction with
> the outside world is calling `icon_->ShowTooltip()` and
> `icon_->HideTooltip()`. Tell me if there are any other test cases you'd like
> to see.

Revision history for this message
Jjed (jjed) wrote :

Okay, that works (and does fewer glib::Timeout allocations too).

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

81 + SetIconUnderMouse((AbstractLauncherIcon::Ptr)nullptr);

Please pass an empty icon PTR to the function as it expects:
SetIconUnderMouse(AbstractLauncherIcon::Ptr());

245 + : show_tooltips_(false)
246 + , hovered_(false)
247 + , icon_(nullptr)
248 + , icon_clicked_(false)

This is pure style, but we use 2-spaces to indent initialization list, also you don't need to initialize the icon_ at all.

366 +class TooltipManager : public sigc::trackable

You don't need sigc::trackable, but you probably want this to be non-copyable instead.

371 + void SetHover(bool on_launcher);

What about a nux::Property<bool> for this?

258 + if (show_tooltips_) {

Please add a space after the if statements (so that the brace is on the new line)

539 + tm.SetIcon((AbstractLauncherIcon::Ptr)icon);

Pass to it an icon ptr: tm.SetIcon(AbstractLauncherIcon::Ptr(icon));

Revision history for this message
Jjed (jjed) wrote :

Okay, changed most of that.

> 371 + void SetHover(bool on_launcher);
>
> What about a nux::Property<bool> for this?

I don't think that makes sense, given that `hover_` is private and the TooltipMannager doesn't need any internal hooks for when it changes. LauncherHoverMachine already has a signal for changing hover-state as well.

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

Cool, this is fine now..

Stephen, are you ok now with removing the "Needs fixing" flag? :)

review: Approve
Revision history for this message
Stephen M. Webb (bregma) wrote :

Looks good.

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

As Launcher icons don't visually change at all when hovered with the mouse, Unity again feels so sluggish/unresponsive, that I have to wonder if it has freezed. I reported that as bug 1152390.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'launcher/AbstractLauncherIcon.h'
--- launcher/AbstractLauncherIcon.h 2013-02-22 10:55:18 +0000
+++ launcher/AbstractLauncherIcon.h 2013-03-05 21:56:20 +0000
@@ -135,6 +135,7 @@
135 nux::Property<Position> position;135 nux::Property<Position> position;
136 nux::Property<bool> removed;136 nux::Property<bool> removed;
137137
138 virtual void ShowTooltip() = 0;
138 virtual void HideTooltip() = 0;139 virtual void HideTooltip() = 0;
139140
140 virtual void SetShortcut(guint64 shortcut) = 0;141 virtual void SetShortcut(guint64 shortcut) = 0;
141142
=== modified file 'launcher/CMakeLists.txt'
--- launcher/CMakeLists.txt 2012-12-19 20:53:12 +0000
+++ launcher/CMakeLists.txt 2013-03-05 21:56:20 +0000
@@ -57,6 +57,7 @@
57 SoftwareCenterLauncherIcon.cpp57 SoftwareCenterLauncherIcon.cpp
58 SpacerLauncherIcon.cpp58 SpacerLauncherIcon.cpp
59 Tooltip.cpp59 Tooltip.cpp
60 TooltipManager.cpp
60 TrashLauncherIcon.cpp61 TrashLauncherIcon.cpp
61 VolumeImp.cpp62 VolumeImp.cpp
62 VolumeLauncherIcon.cpp63 VolumeLauncherIcon.cpp
6364
=== modified file 'launcher/Launcher.cpp'
--- launcher/Launcher.cpp 2013-03-05 15:59:56 +0000
+++ launcher/Launcher.cpp 2013-03-05 21:56:20 +0000
@@ -286,6 +286,21 @@
286 _hide_machine.SetQuirk(LauncherHideMachine::MOUSE_OVER_LAUNCHER, over_launcher);286 _hide_machine.SetQuirk(LauncherHideMachine::MOUSE_OVER_LAUNCHER, over_launcher);
287 _hide_machine.SetQuirk(LauncherHideMachine::REVEAL_PRESSURE_PASS, false);287 _hide_machine.SetQuirk(LauncherHideMachine::REVEAL_PRESSURE_PASS, false);
288 _hover_machine.SetQuirk(LauncherHoverMachine::MOUSE_OVER_LAUNCHER, over_launcher);288 _hover_machine.SetQuirk(LauncherHoverMachine::MOUSE_OVER_LAUNCHER, over_launcher);
289 tooltip_manager_.SetHover(over_launcher);
290}
291
292void Launcher::SetIconUnderMouse(AbstractLauncherIcon::Ptr const& icon)
293{
294 if (_icon_under_mouse == icon)
295 return;
296
297 if (_icon_under_mouse)
298 _icon_under_mouse->mouse_leave.emit(monitor);
299 if (icon)
300 icon->mouse_enter.emit(monitor);
301
302 _icon_under_mouse = icon;
303 tooltip_manager_.SetIcon(icon);
289}304}
290305
291bool Launcher::MouseBeyondDragThreshold() const306bool Launcher::MouseBeyondDragThreshold() const
@@ -1603,8 +1618,7 @@
1603 if (icon->needs_redraw_connection.connected())1618 if (icon->needs_redraw_connection.connected())
1604 icon->needs_redraw_connection.disconnect();1619 icon->needs_redraw_connection.disconnect();
16051620
1606 if (icon == _icon_under_mouse)1621 SetIconUnderMouse(AbstractLauncherIcon::Ptr());
1607 _icon_under_mouse = nullptr;
1608 if (icon == _icon_mouse_down)1622 if (icon == _icon_mouse_down)
1609 _icon_mouse_down = nullptr;1623 _icon_mouse_down = nullptr;
1610 if (icon == _drag_icon)1624 if (icon == _drag_icon)
@@ -1923,11 +1937,7 @@
1923 // if we are still waiting…1937 // if we are still waiting…
1924 if (GetActionState() == ACTION_NONE)1938 if (GetActionState() == ACTION_NONE)
1925 {1939 {
1926 if (_icon_under_mouse)1940 SetIconUnderMouse(AbstractLauncherIcon::Ptr());
1927 {
1928 _icon_under_mouse->mouse_leave.emit(monitor);
1929 _icon_under_mouse = nullptr;
1930 }
1931 _initial_drag_animation = true;1941 _initial_drag_animation = true;
1932 StartIconDragRequest(x, y);1942 StartIconDragRequest(x, y);
1933 }1943 }
@@ -2166,11 +2176,7 @@
2166 GetActionState() == ACTION_NONE)2176 GetActionState() == ACTION_NONE)
2167 return;2177 return;
21682178
2169 if (_icon_under_mouse)2179 SetIconUnderMouse(AbstractLauncherIcon::Ptr());
2170 {
2171 _icon_under_mouse->mouse_leave.emit(monitor);
2172 _icon_under_mouse = nullptr;
2173 }
21742180
2175 if (GetActionState() == ACTION_NONE)2181 if (GetActionState() == ACTION_NONE)
2176 {2182 {
@@ -2222,6 +2228,7 @@
2222void Launcher::RecvMouseMove(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags)2228void Launcher::RecvMouseMove(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags)
2223{2229{
2224 SetMousePosition(x, y);2230 SetMousePosition(x, y);
2231 tooltip_manager_.MouseMoved();
22252232
2226 if (!_hidden)2233 if (!_hidden)
2227 UpdateChangeInMousePosition(dx, dy);2234 UpdateChangeInMousePosition(dx, dy);
@@ -2370,18 +2377,7 @@
2370 launcher_icon = MouseIconIntersection(_mouse_position.x, _mouse_position.y);2377 launcher_icon = MouseIconIntersection(_mouse_position.x, _mouse_position.y);
2371 }2378 }
23722379
23732380 SetIconUnderMouse(launcher_icon);
2374 if (_icon_under_mouse && (_icon_under_mouse != launcher_icon))
2375 {
2376 _icon_under_mouse->mouse_leave.emit(monitor);
2377 _icon_under_mouse = nullptr;
2378 }
2379
2380 if (launcher_icon && (_icon_under_mouse != launcher_icon))
2381 {
2382 launcher_icon->mouse_enter.emit(monitor);
2383 _icon_under_mouse = launcher_icon;
2384 }
2385}2381}
23862382
2387void Launcher::MouseDownLogic(int x, int y, unsigned long button_flags, unsigned long key_flags)2383void Launcher::MouseDownLogic(int x, int y, unsigned long button_flags, unsigned long key_flags)
@@ -2396,6 +2392,7 @@
2396 sources_.AddTimeout(START_DRAGICON_DURATION, cb_func, START_DRAGICON_TIMEOUT);2392 sources_.AddTimeout(START_DRAGICON_DURATION, cb_func, START_DRAGICON_TIMEOUT);
23972393
2398 launcher_icon->mouse_down.emit(nux::GetEventButton(button_flags), monitor, key_flags);2394 launcher_icon->mouse_down.emit(nux::GetEventButton(button_flags), monitor, key_flags);
2395 tooltip_manager_.IconClicked();
2399 }2396 }
2400}2397}
24012398
24022399
=== modified file 'launcher/Launcher.h'
--- launcher/Launcher.h 2013-03-05 14:30:46 +0000
+++ launcher/Launcher.h 2013-03-05 21:56:20 +0000
@@ -42,6 +42,7 @@
42#include "unity-shared/MockableBaseWindow.h"42#include "unity-shared/MockableBaseWindow.h"
43#include "unity-shared/UBusWrapper.h"43#include "unity-shared/UBusWrapper.h"
44#include "SoftwareCenterLauncherIcon.h"44#include "SoftwareCenterLauncherIcon.h"
45#include "TooltipManager.h"
4546
46#ifdef USE_X1147#ifdef USE_X11
47# include "PointerBarrier.h"48# include "PointerBarrier.h"
@@ -223,6 +224,7 @@
223 bool OnScrollTimeout();224 bool OnScrollTimeout();
224225
225 void SetMousePosition(int x, int y);226 void SetMousePosition(int x, int y);
227 void SetIconUnderMouse(AbstractLauncherIcon::Ptr const& icon);
226228
227 void SetStateMouseOverLauncher(bool over_launcher);229 void SetStateMouseOverLauncher(bool over_launcher);
228230
@@ -389,6 +391,7 @@
389 nux::ObjectPtr<LauncherDragWindow> _drag_window;391 nux::ObjectPtr<LauncherDragWindow> _drag_window;
390 LauncherHideMachine _hide_machine;392 LauncherHideMachine _hide_machine;
391 LauncherHoverMachine _hover_machine;393 LauncherHoverMachine _hover_machine;
394 TooltipManager tooltip_manager_;
392395
393 unity::DndData _dnd_data;396 unity::DndData _dnd_data;
394 nux::DndAction _drag_action;397 nux::DndAction _drag_action;
395398
=== modified file 'launcher/LauncherIcon.cpp'
--- launcher/LauncherIcon.cpp 2013-02-22 10:55:18 +0000
+++ launcher/LauncherIcon.cpp 2013-03-05 21:56:20 +0000
@@ -528,23 +528,12 @@
528LauncherIcon::RecvMouseEnter(int monitor)528LauncherIcon::RecvMouseEnter(int monitor)
529{529{
530 _last_monitor = monitor;530 _last_monitor = monitor;
531 if (QuicklistManager::Default()->Current())
532 {
533 // A quicklist is active
534 return;
535 }
536
537 ShowTooltip();
538}531}
539532
540void LauncherIcon::RecvMouseLeave(int monitor)533void LauncherIcon::RecvMouseLeave(int monitor)
541{534{
542 _last_monitor = -1;535 _last_monitor = -1;
543 _allow_quicklist_to_show = true;536 _allow_quicklist_to_show = true;
544
545 if (_tooltip)
546 _tooltip->ShowWindow(false);
547 tooltip_visible.emit(nux::ObjectPtr<nux::View>(nullptr));
548}537}
549538
550bool LauncherIcon::OpenQuicklist(bool select_first_item, int monitor)539bool LauncherIcon::OpenQuicklist(bool select_first_item, int monitor)
551540
=== modified file 'launcher/MockLauncherIcon.h'
--- launcher/MockLauncherIcon.h 2012-11-28 22:00:12 +0000
+++ launcher/MockLauncherIcon.h 2013-03-05 21:56:20 +0000
@@ -68,6 +68,7 @@
68 , type_(type)68 , type_(type)
69 , sort_priority_(DefaultPriority(type))69 , sort_priority_(DefaultPriority(type))
70 , remote_uri_("fake")70 , remote_uri_("fake")
71 , is_tooltip_visible_(false)
71 {72 {
72 tooltip_text = "Mock Icon";73 tooltip_text = "Mock Icon";
73 position = Position::FLOATING;74 position = Position::FLOATING;
@@ -80,7 +81,9 @@
8081
81 void AddProperties(GVariantBuilder* builder) {}82 void AddProperties(GVariantBuilder* builder) {}
8283
83 void HideTooltip() {}84 void ShowTooltip() { is_tooltip_visible_ = true; }
85 void HideTooltip() { is_tooltip_visible_ = false; }
86 bool IsTooltipVisible() { return is_tooltip_visible_; }
8487
85 void SetShortcut(guint64 shortcut) {}88 void SetShortcut(guint64 shortcut) {}
8689
@@ -366,6 +369,7 @@
366 timespec quirk_times_[unsigned(Quirk::LAST)];369 timespec quirk_times_[unsigned(Quirk::LAST)];
367 std::map<int, nux::Point3> center_;370 std::map<int, nux::Point3> center_;
368 std::string remote_uri_;371 std::string remote_uri_;
372 bool is_tooltip_visible_;
369};373};
370374
371}375}
372376
=== added file 'launcher/TooltipManager.cpp'
--- launcher/TooltipManager.cpp 1970-01-01 00:00:00 +0000
+++ launcher/TooltipManager.cpp 2013-03-05 21:56:20 +0000
@@ -0,0 +1,126 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2013 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Jacob Edwards <j.johan.edwards@gmail.com>
18 */
19
20#include "TooltipManager.h"
21
22namespace unity
23{
24namespace launcher
25{
26
27namespace
28{
29const unsigned int TOOLTIPS_SHOW_TIMEOUT_LENGTH = 1000;
30}
31
32TooltipManager::TooltipManager()
33 : show_tooltips_(false)
34 , hovered_(false)
35 , timer_locked_(false)
36{}
37
38void TooltipManager::SetIcon(AbstractLauncherIcon::Ptr const& newIcon)
39{
40 if (icon_ == newIcon)
41 return;
42
43 // Unlock hover timer, in case the previous icon had no valid tooltip
44 timer_locked_ = false;
45
46 if (show_tooltips_)
47 {
48 // Show new tooltip, get rid of the old olne
49 if (icon_)
50 icon_->HideTooltip();
51 if (newIcon)
52 newIcon->ShowTooltip();
53 }
54 else if (!newIcon)
55 {
56 // Stop the hover timer for null launcher space
57 StopTimer();
58 }
59 else
60 {
61 AbstractLauncherIcon::IconType type = newIcon->GetIconType();
62 if ((type == AbstractLauncherIcon::IconType::HOME ||
63 type == AbstractLauncherIcon::IconType::HUD) &&
64 newIcon->GetQuirk(AbstractLauncherIcon::Quirk::ACTIVE))
65 {
66 // Lock the hover timer for no valid tooltip cases
67 timer_locked_ = true;
68 StopTimer();
69 }
70 }
71
72 icon_ = newIcon;
73}
74
75void TooltipManager::SetHover(bool on_launcher)
76{
77 if (hovered_ == on_launcher)
78 return;
79 hovered_ = on_launcher;
80
81 if (show_tooltips_ && !hovered_)
82 {
83 show_tooltips_ = false;
84 if (icon_)
85 icon_->HideTooltip();
86 }
87}
88
89void TooltipManager::MouseMoved()
90{
91 if (!icon_ || show_tooltips_)
92 return;
93
94 ResetTimer();
95}
96
97void TooltipManager::IconClicked()
98{
99 StopTimer();
100 if (show_tooltips_ && icon_)
101 icon_->HideTooltip();
102
103 show_tooltips_ = false;
104 timer_locked_ = true;
105}
106
107void TooltipManager::ResetTimer()
108{
109 if (timer_locked_)
110 return;
111
112 hover_timer_.reset(new glib::Timeout(TOOLTIPS_SHOW_TIMEOUT_LENGTH));
113 hover_timer_->Run([&] () {
114 show_tooltips_ = true;
115 icon_->ShowTooltip();
116 return false;
117 });
118}
119
120void TooltipManager::StopTimer()
121{
122 hover_timer_.reset();
123}
124
125} // namespace launcher
126} // namespace unity
0127
=== added file 'launcher/TooltipManager.h'
--- launcher/TooltipManager.h 1970-01-01 00:00:00 +0000
+++ launcher/TooltipManager.h 2013-03-05 21:56:20 +0000
@@ -0,0 +1,57 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2013 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Jacob Edwards <j.johan.edwards@gmail.com>
18 */
19
20#ifndef TOOLTIPMANAGER
21#define TOOLTIPMANAGER
22
23#include <boost/noncopyable.hpp>
24#include <UnityCore/GLibSource.h>
25
26#include "AbstractLauncherIcon.h"
27
28namespace unity
29{
30namespace launcher
31{
32
33class TooltipManager : public boost::noncopyable
34{
35public:
36 TooltipManager();
37
38 void SetHover(bool on_launcher);
39 void SetIcon(AbstractLauncherIcon::Ptr const& newIcon);
40 void MouseMoved();
41 void IconClicked();
42
43private:
44 void ResetTimer();
45 void StopTimer();
46
47 bool show_tooltips_;
48 bool hovered_;
49 AbstractLauncherIcon::Ptr icon_;
50 glib::Source::UniquePtr hover_timer_;
51 bool timer_locked_;
52};
53
54} // namespace launcher
55} // namespace unity
56
57#endif
058
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2013-03-05 03:21:11 +0000
+++ tests/CMakeLists.txt 2013-03-05 21:56:20 +0000
@@ -250,6 +250,7 @@
250 test_texture_cache.cpp250 test_texture_cache.cpp
251 test_text_input.cpp251 test_text_input.cpp
252 test_thumbnail_generator.cpp252 test_thumbnail_generator.cpp
253 test_tooltip_manager.cpp
253 test_trash_launcher_icon.cpp254 test_trash_launcher_icon.cpp
254 test_launcher_minimize_speed.cpp255 test_launcher_minimize_speed.cpp
255 test_unity_settings.cpp256 test_unity_settings.cpp
256257
=== added file 'tests/autopilot/unity/tests/launcher/test_tooltips.py'
--- tests/autopilot/unity/tests/launcher/test_tooltips.py 1970-01-01 00:00:00 +0000
+++ tests/autopilot/unity/tests/launcher/test_tooltips.py 2013-03-05 21:56:20 +0000
@@ -0,0 +1,87 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2# Copyright 2013 Canonical
3# Authors: Jacob Edwards
4#
5# This program is free software: you can redistribute it and/or modify it
6# under the terms of the GNU General Public License version 3, as published
7# by the Free Software Foundation.
8
9from autopilot.matchers import Eventually
10from testtools.matchers import Equals
11from time import sleep
12
13from unity.tests.launcher import LauncherTestCase, _make_scenarios
14
15class LauncherTooltipTests(LauncherTestCase):
16 """Tests whether tooltips display only at appropriate times."""
17
18 def setUp(self):
19 super(LauncherTooltipTests, self).setUp()
20 self.set_unity_option('launcher_hide_mode', 0)
21 self.launcher_instance.move_mouse_to_right_of_launcher()
22 self.icons = self.unity.launcher.model.get_launcher_icons(visible_only=True)
23
24 def test_launcher_tooltip_show(self):
25 """Tests whether icon tooltips delay showing themselves and,
26 once shown, whether subsequent icons show them instantly."""
27 for i in self.icons:
28 tooltip = i.get_tooltip()
29 if not tooltip:
30 continue
31 self.assertThat(tooltip.active, Eventually(Equals(False)))
32
33 # only reveal tooltips after short wait
34 self.assertEqual(self.get_reveal_behavior(self.icons[0]), self.DELAYED)
35
36 # subsequent tooltips reveal instantly, but hide on exit
37 a, b = 0, 1
38 while b < len(self.icons):
39 self.mouse.move(self.icons[b].center_x, self.icons[b].center_y)
40 self.assertTrue(self.icons[b].get_tooltip().active)
41 self.assertFalse(self.icons[a].get_tooltip().active)
42 a, b = a + 1, b + 1
43 b -= 1
44
45 # leaving launcher clears tooltips, and instant reveal
46 self.launcher_instance.move_mouse_to_right_of_launcher()
47 self.assertEqual(self.get_reveal_behavior(self.icons[b]), self.DELAYED)
48
49 def test_launcher_tooltip_disabling(self):
50 """Tests whether clicking on an icon hides its tooltip."""
51 bfb, other = self.icons[0], self.icons[1]
52 self.assertEqual(self.get_reveal_behavior(bfb), self.DELAYED)
53
54 # clicking icon hides its launcher until further input
55 self.mouse.click()
56 self.assertEqual(self.get_reveal_behavior(bfb), self.NEVER)
57 self.mouse.click()
58
59 # normal behavior resumes on moving away from icon
60 self.assertEqual(self.get_reveal_behavior(other), self.DELAYED)
61 self.assertEqual(self.get_reveal_behavior(bfb), self.INSTANT)
62
63 def test_launcher_bfb_tooltip_when_open(self):
64 """Tests whether hovering over the active BFB starts a tooltip timer"""
65 self.unity.dash.ensure_visible()
66 self.addCleanup(self.unity.dash.ensure_hidden)
67 bfb, other = self.icons[0], self.icons[1]
68
69 # hovering an open dash's BFB does not show a tooltip ...
70 self.assertEqual(self.get_reveal_behavior(bfb), self.NEVER)
71
72 # ... nor did it timeout instant tooltips for other icons
73 self.assertEqual(self.get_reveal_behavior(other), self.DELAYED)
74
75 # Tooltip reveal types
76 (INSTANT, DELAYED, NEVER) = range(3)
77
78 def get_reveal_behavior(self, icon):
79 self.mouse.move(icon.center_x, icon.center_y)
80 tooltip = icon.get_tooltip()
81 if tooltip and tooltip.active:
82 return self.INSTANT
83 sleep(1.2)
84 tooltip = icon.get_tooltip()
85 if tooltip and tooltip.active:
86 return self.DELAYED
87 return self.NEVER
088
=== added file 'tests/test_tooltip_manager.cpp'
--- tests/test_tooltip_manager.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_tooltip_manager.cpp 2013-03-05 21:56:20 +0000
@@ -0,0 +1,54 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2013 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Jacob Edwards <j.johan.edwards@gmail.com>
18 */
19
20#include <gtest/gtest.h>
21using namespace testing;
22
23#include "launcher/TooltipManager.h"
24#include "launcher/MockLauncherIcon.h"
25#include "test_utils.h"
26
27namespace unity
28{
29namespace launcher
30{
31
32namespace
33{
34
35TEST(TestTooltipManager, TestHideAndShowTooltip)
36{
37 // Makes sure that TooltipManager calls icon->ShowTooltip() when the mouse
38 // hovers it, and icon->HideTooltip() after the mouse dehovers it.
39 TooltipManager tm;
40 MockLauncherIcon* icon = new MockLauncherIcon();
41
42 tm.SetIcon(AbstractLauncherIcon::Ptr(icon));
43 tm.MouseMoved();
44 Utils::WaitForTimeoutMSec(1050);
45
46 EXPECT_TRUE(icon->IsTooltipVisible());
47 tm.SetIcon(AbstractLauncherIcon::Ptr());
48 EXPECT_FALSE(icon->IsTooltipVisible());
49}
50
51}
52
53} // launcher
54} // unity