Make castv2 performance test work.
[chromium-blink-merge.git] / ui / views / corewm / tooltip_controller.h
blob2f8c7ef6b23bc6d1775b2111718aa5eb17f4a67d
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.
5 #ifndef UI_VIEWS_COREWM_TOOLTIP_CONTROLLER_H_
6 #define UI_VIEWS_COREWM_TOOLTIP_CONTROLLER_H_
8 #include <map>
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/geometry/point.h"
16 #include "ui/views/views_export.h"
17 #include "ui/wm/public/tooltip_client.h"
19 namespace aura {
20 class Window;
23 namespace views {
24 namespace corewm {
26 class Tooltip;
28 namespace test {
29 class TooltipControllerTestHelper;
30 } // namespace test
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;
40 // Overridden from aura::client::TooltipClient.
41 int GetMaxWidth(const gfx::Point& location,
42 aura::Window* context) const override;
43 void UpdateTooltip(aura::Window* target) override;
44 void SetTooltipShownTimeout(aura::Window* target, int timeout_in_ms) override;
45 void SetTooltipsEnabled(bool enable) override;
47 // Overridden from ui::EventHandler.
48 void OnKeyEvent(ui::KeyEvent* event) override;
49 void OnMouseEvent(ui::MouseEvent* event) override;
50 void OnTouchEvent(ui::TouchEvent* event) override;
51 void OnCancelMode(ui::CancelModeEvent* event) override;
53 // Overridden from aura::WindowObserver.
54 void OnWindowDestroyed(aura::Window* window) override;
56 const gfx::Point& mouse_location() const { return curr_mouse_loc_; }
58 private:
59 friend class test::TooltipControllerTestHelper;
61 void TooltipTimerFired();
62 void TooltipShownTimerFired();
64 // Updates the tooltip if required (if there is any change in the tooltip
65 // text, tooltip id or the aura::Window).
66 void UpdateIfRequired();
68 // Only used in tests.
69 bool IsTooltipVisible();
71 bool IsDragDropInProgress();
73 // Returns true if the cursor is visible.
74 bool IsCursorVisible();
76 int GetTooltipShownTimeout();
78 // Sets tooltip window to |target| if it is different from existing window.
79 // Calls RemoveObserver on the existing window if it is not NULL.
80 // Calls AddObserver on the new window if it is not NULL.
81 void SetTooltipWindow(aura::Window* target);
83 aura::Window* tooltip_window_;
84 base::string16 tooltip_text_;
85 const void* tooltip_id_;
87 // These fields are for tracking state when the user presses a mouse button.
88 aura::Window* tooltip_window_at_mouse_press_;
89 base::string16 tooltip_text_at_mouse_press_;
91 scoped_ptr<Tooltip> tooltip_;
93 base::RepeatingTimer<TooltipController> tooltip_timer_;
95 // Timer to timeout the life of an on-screen tooltip. We hide the tooltip when
96 // this timer fires.
97 base::OneShotTimer<TooltipController> tooltip_shown_timer_;
99 // Location of the last event in |tooltip_window_|'s coordinates.
100 gfx::Point curr_mouse_loc_;
102 bool tooltips_enabled_;
104 std::map<aura::Window*, int> tooltip_shown_timeout_map_;
106 DISALLOW_COPY_AND_ASSIGN(TooltipController);
109 } // namespace corewm
110 } // namespace views
112 #endif // UI_VIEWS_COREWM_TOOLTIP_CONTROLLER_H_