Make castv2 performance test work.
[chromium-blink-merge.git] / ui / views / widget / tooltip_manager_aura.cc
blob1c5bd26c32e600e7e00f7013c15001777c9ce0a6
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/geometry/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 int TooltipManagerAura::GetMaxWidth(const gfx::Point& point,
85 aura::Window* context) const {
86 return aura::client::GetTooltipClient(context->GetRootWindow())->
87 GetMaxWidth(point, context);
90 void TooltipManagerAura::UpdateTooltip() {
91 aura::Window* root_window = GetWindow()->GetRootWindow();
92 if (aura::client::GetTooltipClient(root_window)) {
93 if (!widget_->IsVisible()) {
94 UpdateTooltipForTarget(NULL, gfx::Point(), root_window);
95 return;
97 gfx::Point view_point =
98 root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot();
99 aura::Window::ConvertPointToTarget(root_window, GetWindow(), &view_point);
100 View* view = GetViewUnderPoint(view_point);
101 UpdateTooltipForTarget(view, view_point, root_window);
105 void TooltipManagerAura::TooltipTextChanged(View* view) {
106 aura::Window* root_window = GetWindow()->GetRootWindow();
107 if (aura::client::GetTooltipClient(root_window)) {
108 gfx::Point view_point =
109 root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot();
110 aura::Window::ConvertPointToTarget(root_window, GetWindow(), &view_point);
111 View* target = GetViewUnderPoint(view_point);
112 if (target != view)
113 return;
114 UpdateTooltipForTarget(view, view_point, root_window);
118 View* TooltipManagerAura::GetViewUnderPoint(const gfx::Point& point) {
119 View* root_view = widget_->GetRootView();
120 if (root_view)
121 return root_view->GetTooltipHandlerForPoint(point);
122 return NULL;
125 void TooltipManagerAura::UpdateTooltipForTarget(View* target,
126 const gfx::Point& point,
127 aura::Window* root_window) {
128 if (target) {
129 gfx::Point view_point = point;
130 View::ConvertPointFromWidget(target, &view_point);
131 base::string16 new_tooltip_text;
132 if (!target->GetTooltipText(view_point, &new_tooltip_text))
133 tooltip_text_.clear();
134 else
135 tooltip_text_ = new_tooltip_text;
136 } else {
137 tooltip_text_.clear();
140 aura::client::SetTooltipId(GetWindow(), target);
142 aura::client::GetTooltipClient(root_window)->UpdateTooltip(GetWindow());
145 aura::Window* TooltipManagerAura::GetWindow() {
146 return widget_->GetNativeView();
149 } // namespace views.