Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ui / views / corewm / tooltip_controller.h
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef UI_VIEWS_COREWM_TOOLTIP_CONTROLLER_H_
6 #define UI_VIEWS_COREWM_TOOLTIP_CONTROLLER_H_
7
8 #include <map>
9
10 #include "base/memory/scoped_ptr.h"
11 #include "base/strings/string16.h"
12 #include "base/timer/timer.h"
13 #include "ui/aura/window_observer.h"
14 #include "ui/events/event_handler.h"
15 #include "ui/gfx/point.h"
16 #include "ui/views/views_export.h"
17 #include "ui/wm/public/tooltip_client.h"
18
19 namespace aura {
20 class Window;
21 }
22
23 namespace views {
24 namespace corewm {
25
26 class Tooltip;
27
28 namespace test {
29 class TooltipControllerTestHelper;
30 }  // namespace test
31
32 // TooltipController provides tooltip functionality for aura.
33 class VIEWS_EXPORT TooltipController : public aura::client::TooltipClient,
34                                        public ui::EventHandler,
35                                        public aura::WindowObserver {
36  public:
37   explicit TooltipController(scoped_ptr<Tooltip> tooltip);
38   ~TooltipController() override;
39
40   // Overridden from aura::client::TooltipClient.
41   void UpdateTooltip(aura::Window* target) override;
42   void SetTooltipShownTimeout(aura::Window* target, int timeout_in_ms) override;
43   void SetTooltipsEnabled(bool enable) override;
44
45   // Overridden from ui::EventHandler.
46   void OnKeyEvent(ui::KeyEvent* event) override;
47   void OnMouseEvent(ui::MouseEvent* event) override;
48   void OnTouchEvent(ui::TouchEvent* event) override;
49   void OnCancelMode(ui::CancelModeEvent* event) override;
50
51   // Overridden from aura::WindowObserver.
52   void OnWindowDestroyed(aura::Window* window) override;
53
54   const gfx::Point& mouse_location() const { return curr_mouse_loc_; }
55
56  private:
57   friend class test::TooltipControllerTestHelper;
58
59   void TooltipTimerFired();
60   void TooltipShownTimerFired();
61
62   // Updates the tooltip if required (if there is any change in the tooltip
63   // text, tooltip id or the aura::Window).
64   void UpdateIfRequired();
65
66   // Only used in tests.
67   bool IsTooltipVisible();
68
69   bool IsDragDropInProgress();
70
71   // Returns true if the cursor is visible.
72   bool IsCursorVisible();
73
74   int GetTooltipShownTimeout();
75
76   // Sets tooltip window to |target| if it is different from existing window.
77   // Calls RemoveObserver on the existing window if it is not NULL.
78   // Calls AddObserver on the new window if it is not NULL.
79   void SetTooltipWindow(aura::Window* target);
80
81   aura::Window* tooltip_window_;
82   base::string16 tooltip_text_;
83   const void* tooltip_id_;
84
85   // These fields are for tracking state when the user presses a mouse button.
86   aura::Window* tooltip_window_at_mouse_press_;
87   base::string16 tooltip_text_at_mouse_press_;
88
89   scoped_ptr<Tooltip> tooltip_;
90
91   base::RepeatingTimer<TooltipController> tooltip_timer_;
92
93   // Timer to timeout the life of an on-screen tooltip. We hide the tooltip when
94   // this timer fires.
95   base::OneShotTimer<TooltipController> tooltip_shown_timer_;
96
97   // Location of the last event in |tooltip_window_|'s coordinates.
98   gfx::Point curr_mouse_loc_;
99
100   bool tooltips_enabled_;
101
102   std::map<aura::Window*, int> tooltip_shown_timeout_map_;
103
104   DISALLOW_COPY_AND_ASSIGN(TooltipController);
105 };
106
107 }  // namespace corewm
108 }  // namespace views
109
110 #endif  // UI_VIEWS_COREWM_TOOLTIP_CONTROLLER_H_