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