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"
20 int TooltipManager::GetTooltipHeight() {
21 // Not used for linux and chromeos.
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
);
38 const gfx::FontList
& TooltipManagerAura::GetDefaultFontList() {
39 return ui::ResourceBundle::GetSharedInstance().GetFontList(
40 ui::ResourceBundle::BaseFont
);
44 void TooltipManagerAura::UpdateTooltipManagerForCapture(Widget
* source
) {
45 if (!source
->HasCapture())
48 aura::Window
* root_window
= source
->GetNativeView()->GetRootWindow();
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
)
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
);
63 gfx::Point
target_loc(screen_loc
);
64 screen_position_client
=
65 aura::client::GetScreenPositionClient(target
->GetRootWindow());
66 if (!screen_position_client
)
68 screen_position_client
->ConvertPointFromScreen(target
, &target_loc
);
69 target
= target
->GetEventHandlerForPoint(target_loc
);
71 Widget
* target_widget
= Widget::GetWidgetForNativeView(target
);
72 if (target_widget
== source
)
76 if (target_widget
->GetTooltipManager())
77 target_widget
->GetTooltipManager()->UpdateTooltip();
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
);
111 UpdateTooltipForTarget(view
, view_point
, root_window
);
115 View
* TooltipManagerAura::GetViewUnderPoint(const gfx::Point
& point
) {
116 View
* root_view
= widget_
->GetRootView();
118 return root_view
->GetTooltipHandlerForPoint(point
);
122 void TooltipManagerAura::UpdateTooltipForTarget(View
* target
,
123 const gfx::Point
& point
,
124 aura::Window
* root_window
) {
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();
132 tooltip_text_
= new_tooltip_text
;
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.