Chromium Code Reviews| 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 |
| 72 // Show the tooltip. | |
| 73 void ShowTooltip(); | |
| 74 | |
| 64 // Updates the tooltip if required (if there is any change in the tooltip | 75 // Updates the tooltip if required (if there is any change in the tooltip |
| 65 // text, tooltip id or the aura::Window). | 76 // text, tooltip id or the aura::Window). |
| 66 void UpdateIfRequired(); | 77 void UpdateIfRequired(); |
| 67 | 78 |
| 68 // Only used in tests. | 79 // Only used in tests. |
| 69 bool IsTooltipVisible(); | 80 bool IsTooltipVisible(); |
| 70 | 81 |
| 71 bool IsDragDropInProgress(); | 82 bool IsDragDropInProgress(); |
| 72 | 83 |
| 73 // Returns true if the cursor is visible. | 84 // Returns true if the cursor is visible. |
| 74 bool IsCursorVisible(); | 85 bool IsCursorVisible(); |
| 75 | 86 |
| 76 int GetTooltipShownTimeout(); | 87 int GetTooltipShownTimeout(); |
| 77 | 88 |
| 78 // Sets tooltip window to |target| if it is different from existing window. | 89 // Sets tooltip window to |target| if it is different from existing window. |
| 79 // Calls RemoveObserver on the existing window if it is not NULL. | 90 // Calls RemoveObserver on the existing window if it is not NULL. |
| 80 // Calls AddObserver on the new window if it is not NULL. | 91 // Calls AddObserver on the new window if it is not NULL. |
| 81 void SetTooltipWindow(aura::Window* target); | 92 void SetTooltipWindow(aura::Window* target); |
| 82 | 93 |
| 94 void DisableTooltipShowDelay() { tooltip_show_delayed_ = false; } | |
| 95 | |
| 83 aura::Window* tooltip_window_; | 96 aura::Window* tooltip_window_; |
| 84 base::string16 tooltip_text_; | 97 base::string16 tooltip_text_; |
| 98 base::string16 tooltip_text_whitespace_trimmed_; | |
| 85 const void* tooltip_id_; | 99 const void* tooltip_id_; |
| 86 | 100 |
| 87 // These fields are for tracking state when the user presses a mouse button. | 101 // These fields are for tracking state when the user presses a mouse button. |
| 88 aura::Window* tooltip_window_at_mouse_press_; | 102 aura::Window* tooltip_window_at_mouse_press_; |
| 89 base::string16 tooltip_text_at_mouse_press_; | 103 base::string16 tooltip_text_at_mouse_press_; |
| 90 | 104 |
| 91 std::unique_ptr<Tooltip> tooltip_; | 105 std::unique_ptr<Tooltip> tooltip_; |
| 92 | 106 |
| 93 base::RepeatingTimer tooltip_timer_; | 107 // Timer for requesting delayed updates of the tooltip. |
| 108 base::OneShotTimer tooltip_defer_timer_; | |
| 94 | 109 |
| 95 // Timer to timeout the life of an on-screen tooltip. We hide the tooltip when | 110 // Timer to timeout the life of an on-screen tooltip. We hide the tooltip when |
| 96 // this timer fires. | 111 // this timer fires. |
| 97 base::OneShotTimer tooltip_shown_timer_; | 112 base::OneShotTimer tooltip_shown_timer_; |
| 98 | 113 |
| 99 // Location of the last event in |tooltip_window_|'s coordinates. | 114 // Location of the last event in |tooltip_window_|'s coordinates. |
| 100 gfx::Point curr_mouse_loc_; | 115 gfx::Point curr_mouse_loc_; |
| 101 | 116 |
| 102 bool tooltips_enabled_; | 117 bool tooltips_enabled_; |
| 103 | 118 |
| 119 bool tooltip_show_delayed_; | |
|
sky
2017/01/24 22:13:39
Document what this means.
chengx
2017/01/25 01:25:52
Done.
| |
| 120 | |
| 104 std::map<aura::Window*, int> tooltip_shown_timeout_map_; | 121 std::map<aura::Window*, int> tooltip_shown_timeout_map_; |
| 105 | 122 |
| 106 DISALLOW_COPY_AND_ASSIGN(TooltipController); | 123 DISALLOW_COPY_AND_ASSIGN(TooltipController); |
| 107 }; | 124 }; |
| 108 | 125 |
| 109 } // namespace corewm | 126 } // namespace corewm |
| 110 } // namespace views | 127 } // namespace views |
| 111 | 128 |
| 112 #endif // UI_VIEWS_COREWM_TOOLTIP_CONTROLLER_H_ | 129 #endif // UI_VIEWS_COREWM_TOOLTIP_CONTROLLER_H_ |
| OLD | NEW |