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