Explicitly add python-numpy dependency to install-build-deps.
[chromium-blink-merge.git] / ui / views / widget / tooltip_manager_aura.cc
blobccfa438c3ae002203a5c65eee94d8d8708cdeebe
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 #include "ui/views/widget/tooltip_manager_aura.h"
7 #include "base/logging.h"
8 #include "ui/aura/client/screen_position_client.h"
9 #include "ui/aura/window_event_dispatcher.h"
10 #include "ui/aura/window_tree_host.h"
11 #include "ui/base/resource/resource_bundle.h"
12 #include "ui/gfx/rect.h"
13 #include "ui/gfx/screen.h"
14 #include "ui/views/widget/widget.h"
15 #include "ui/wm/public/tooltip_client.h"
17 namespace views {
19 ////////////////////////////////////////////////////////////////////////////////
20 // TooltipManagerAura public:
22 TooltipManagerAura::TooltipManagerAura(Widget* widget) : widget_(widget) {
23 aura::client::SetTooltipText(GetWindow(), &tooltip_text_);
26 TooltipManagerAura::~TooltipManagerAura() {
27 aura::client::SetTooltipText(GetWindow(), NULL);
30 // static
31 const gfx::FontList& TooltipManagerAura::GetDefaultFontList() {
32 return ui::ResourceBundle::GetSharedInstance().GetFontList(
33 ui::ResourceBundle::BaseFont);
36 // static
37 void TooltipManagerAura::UpdateTooltipManagerForCapture(Widget* source) {
38 if (!source->HasCapture())
39 return;
41 aura::Window* root_window = source->GetNativeView()->GetRootWindow();
42 if (!root_window)
43 return;
45 gfx::Point screen_loc(
46 root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot());
47 aura::client::ScreenPositionClient* screen_position_client =
48 aura::client::GetScreenPositionClient(root_window);
49 if (!screen_position_client)
50 return;
51 screen_position_client->ConvertPointToScreen(root_window, &screen_loc);
52 gfx::Screen* screen = gfx::Screen::GetScreenFor(root_window);
53 aura::Window* target = screen->GetWindowAtScreenPoint(screen_loc);
54 if (!target)
55 return;
56 gfx::Point target_loc(screen_loc);
57 screen_position_client =
58 aura::client::GetScreenPositionClient(target->GetRootWindow());
59 if (!screen_position_client)
60 return;
61 screen_position_client->ConvertPointFromScreen(target, &target_loc);
62 target = target->GetEventHandlerForPoint(target_loc);
63 while (target) {
64 Widget* target_widget = Widget::GetWidgetForNativeView(target);
65 if (target_widget == source)
66 return;
68 if (target_widget) {
69 if (target_widget->GetTooltipManager())
70 target_widget->GetTooltipManager()->UpdateTooltip();
71 return;
73 target = target->parent();
77 ////////////////////////////////////////////////////////////////////////////////
78 // TooltipManagerAura, TooltipManager implementation:
80 const gfx::FontList& TooltipManagerAura::GetFontList() const {
81 return GetDefaultFontList();
84 void TooltipManagerAura::UpdateTooltip() {
85 aura::Window* root_window = GetWindow()->GetRootWindow();
86 if (aura::client::GetTooltipClient(root_window)) {
87 gfx::Point view_point =
88 root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot();
89 aura::Window::ConvertPointToTarget(root_window, GetWindow(), &view_point);
90 View* view = GetViewUnderPoint(view_point);
91 UpdateTooltipForTarget(view, view_point, root_window);
95 void TooltipManagerAura::TooltipTextChanged(View* view) {
96 aura::Window* root_window = GetWindow()->GetRootWindow();
97 if (aura::client::GetTooltipClient(root_window)) {
98 gfx::Point view_point =
99 root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot();
100 aura::Window::ConvertPointToTarget(root_window, GetWindow(), &view_point);
101 View* target = GetViewUnderPoint(view_point);
102 if (target != view)
103 return;
104 UpdateTooltipForTarget(view, view_point, root_window);
108 View* TooltipManagerAura::GetViewUnderPoint(const gfx::Point& point) {
109 View* root_view = widget_->GetRootView();
110 if (root_view)
111 return root_view->GetTooltipHandlerForPoint(point);
112 return NULL;
115 void TooltipManagerAura::UpdateTooltipForTarget(View* target,
116 const gfx::Point& point,
117 aura::Window* root_window) {
118 if (target) {
119 gfx::Point view_point = point;
120 View::ConvertPointFromWidget(target, &view_point);
121 base::string16 new_tooltip_text;
122 if (!target->GetTooltipText(view_point, &new_tooltip_text))
123 tooltip_text_.clear();
124 else
125 tooltip_text_ = new_tooltip_text;
126 } else {
127 tooltip_text_.clear();
130 aura::client::SetTooltipId(GetWindow(), target);
132 aura::client::GetTooltipClient(root_window)->UpdateTooltip(GetWindow());
135 aura::Window* TooltipManagerAura::GetWindow() {
136 return widget_->GetNativeView();
139 } // namespace views.