Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ui / views / widget / tooltip_manager_aura.cc
blob99ae9e6be57df00b3c3a8b10bed9a0b672fa7989
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 // static
20 int TooltipManager::GetTooltipHeight() {
21 // Not used for linux and chromeos.
22 NOTIMPLEMENTED();
23 return 0;
26 ////////////////////////////////////////////////////////////////////////////////
27 // TooltipManagerAura public:
29 TooltipManagerAura::TooltipManagerAura(Widget* widget) : widget_(widget) {
30 aura::client::SetTooltipText(GetWindow(), &tooltip_text_);
33 TooltipManagerAura::~TooltipManagerAura() {
34 aura::client::SetTooltipText(GetWindow(), NULL);
37 // static
38 const gfx::FontList& TooltipManagerAura::GetDefaultFontList() {
39 return ui::ResourceBundle::GetSharedInstance().GetFontList(
40 ui::ResourceBundle::BaseFont);
43 // static
44 void TooltipManagerAura::UpdateTooltipManagerForCapture(Widget* source) {
45 if (!source->HasCapture())
46 return;
48 aura::Window* root_window = source->GetNativeView()->GetRootWindow();
49 if (!root_window)
50 return;
52 gfx::Point screen_loc(
53 root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot());
54 aura::client::ScreenPositionClient* screen_position_client =
55 aura::client::GetScreenPositionClient(root_window);
56 if (!screen_position_client)
57 return;
58 screen_position_client->ConvertPointToScreen(root_window, &screen_loc);
59 gfx::Screen* screen = gfx::Screen::GetScreenFor(root_window);
60 aura::Window* target = screen->GetWindowAtScreenPoint(screen_loc);
61 if (!target)
62 return;
63 gfx::Point target_loc(screen_loc);
64 screen_position_client =
65 aura::client::GetScreenPositionClient(target->GetRootWindow());
66 if (!screen_position_client)
67 return;
68 screen_position_client->ConvertPointFromScreen(target, &target_loc);
69 target = target->GetEventHandlerForPoint(target_loc);
70 while (target) {
71 Widget* target_widget = Widget::GetWidgetForNativeView(target);
72 if (target_widget == source)
73 return;
75 if (target_widget) {
76 if (target_widget->GetTooltipManager())
77 target_widget->GetTooltipManager()->UpdateTooltip();
78 return;
80 target = target->parent();
84 ////////////////////////////////////////////////////////////////////////////////
85 // TooltipManagerAura, TooltipManager implementation:
87 const gfx::FontList& TooltipManagerAura::GetFontList() const {
88 return GetDefaultFontList();
91 void TooltipManagerAura::UpdateTooltip() {
92 aura::Window* root_window = GetWindow()->GetRootWindow();
93 if (aura::client::GetTooltipClient(root_window)) {
94 gfx::Point view_point =
95 root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot();
96 aura::Window::ConvertPointToTarget(root_window, GetWindow(), &view_point);
97 View* view = GetViewUnderPoint(view_point);
98 UpdateTooltipForTarget(view, view_point, root_window);
102 void TooltipManagerAura::TooltipTextChanged(View* view) {
103 aura::Window* root_window = GetWindow()->GetRootWindow();
104 if (aura::client::GetTooltipClient(root_window)) {
105 gfx::Point view_point =
106 root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot();
107 aura::Window::ConvertPointToTarget(root_window, GetWindow(), &view_point);
108 View* target = GetViewUnderPoint(view_point);
109 if (target != view)
110 return;
111 UpdateTooltipForTarget(view, view_point, root_window);
115 View* TooltipManagerAura::GetViewUnderPoint(const gfx::Point& point) {
116 View* root_view = widget_->GetRootView();
117 if (root_view)
118 return root_view->GetTooltipHandlerForPoint(point);
119 return NULL;
122 void TooltipManagerAura::UpdateTooltipForTarget(View* target,
123 const gfx::Point& point,
124 aura::Window* root_window) {
125 if (target) {
126 gfx::Point view_point = point;
127 View::ConvertPointFromWidget(target, &view_point);
128 base::string16 new_tooltip_text;
129 if (!target->GetTooltipText(view_point, &new_tooltip_text))
130 tooltip_text_.clear();
131 else
132 tooltip_text_ = new_tooltip_text;
133 } else {
134 tooltip_text_.clear();
137 aura::client::SetTooltipId(GetWindow(), target);
139 aura::client::GetTooltipClient(root_window)->UpdateTooltip(GetWindow());
142 aura::Window* TooltipManagerAura::GetWindow() {
143 return widget_->GetNativeView();
146 } // namespace views.