summaryrefslogtreecommitdiffstats
path: root/views/widget/tooltip_manager_views.h
blob: ced0ea26a66bac30bbc15d104a4938808dc81a16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef VIEWS_WIDGET_TOOLTIP_MANAGER_VIEWS_H_
#define VIEWS_WIDGET_TOOLTIP_MANAGER_VIEWS_H_
#pragma once

#include "base/message_loop.h"
#include "base/timer.h"
#include "views/controls/label.h"
#include "views/widget/native_widget.h"
#include "views/widget/tooltip_manager.h"
#include "views/widget/widget_delegate.h"
#include "views/view.h"

#if defined(USE_X11)
typedef union _XEvent XEvent;
namespace ui {
union WaylandEvent;
}
#endif

namespace views {

namespace internal {
class RootView;
}

class Widget;

// TooltipManager implementation for Views.
class TooltipManagerViews : public TooltipManager,
                            public MessageLoopForUI::Observer {
 public:
  explicit TooltipManagerViews(internal::RootView* root_view);
  virtual ~TooltipManagerViews();

  // TooltipManager.
  virtual void UpdateTooltip() OVERRIDE;
  virtual void TooltipTextChanged(View* view) OVERRIDE;
  virtual void ShowKeyboardTooltip(View* view) OVERRIDE;
  virtual void HideKeyboardTooltip() OVERRIDE;

#if defined(USE_WAYLAND)
  virtual base::MessagePumpObserver::EventStatus WillProcessEvent(
      ui::WaylandEvent* event) OVERRIDE;
#elif defined(USE_X11)
  // MessageLoopForUI::Observer
  virtual base::MessagePumpObserver::EventStatus WillProcessXEvent(
      XEvent* xevent) OVERRIDE;
#elif defined(OS_WIN)
  virtual void WillProcessMessage(const MSG& msg) OVERRIDE;
  virtual void DidProcessMessage(const MSG& msg) OVERRIDE;
#endif

 private:
  void TooltipTimerFired();
  View* GetViewForTooltip(int x, int y, bool for_keyboard);

  // Updates the tooltip if required (if there is any change in the tooltip
  // text or the view.
  void UpdateIfRequired(int x, int y, bool for_keyboard);

  // Updates the tooltip. Gets the tooltip text from tooltip_view_ and displays
  // it at the current mouse position.
  void Update();

  // Adjusts the bounds given by the arguments to fit inside the parent view
  // and applies the adjusted bounds to the tooltip_label_.
  void SetTooltipBounds(gfx::Point mouse_pos, int tooltip_width,
                        int tooltip_height);

  // Creates a widget of type TYPE_TOOLTIP
  Widget* CreateTooltip();

  // Invoked when the mose moves.
  void OnMouseMoved(int x, int y);

  scoped_ptr<Widget> tooltip_widget_;
  internal::RootView* root_view_;
  View* tooltip_view_;
  string16 tooltip_text_;
  Label tooltip_label_;

  gfx::Point curr_mouse_pos_;
  base::RepeatingTimer<TooltipManagerViews> tooltip_timer_;

  DISALLOW_COPY_AND_ASSIGN(TooltipManagerViews);
};

}  // namespace views

#endif // VIEWS_WIDGET_TOOLTIP_MANAGER_VIEWS_H_