OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 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. | |
4 | |
5 #include "base/logging.h" | |
6 #include "ui/aura/client/aura_constants.h" | |
7 #include "ui/aura/client/tooltip_client.h" | |
8 #include "ui/aura/desktop.h" | |
9 #include "ui/base/resource/resource_bundle.h" | |
10 #include "ui/gfx/font.h" | |
11 #include "ui/gfx/rect.h" | |
12 #include "ui/gfx/screen.h" | |
13 #include "ui/views/widget/native_widget_aura.h" | |
14 #include "ui/views/widget/tooltip_manager_aura.h" | |
15 | |
16 namespace views { | |
17 | |
18 // static | |
19 int TooltipManager::GetTooltipHeight() { | |
20 // Not used for linux and chromeos. | |
21 NOTIMPLEMENTED(); | |
22 return 0; | |
23 } | |
24 | |
25 // static | |
26 gfx::Font TooltipManager::GetDefaultFont() { | |
27 return ui::ResourceBundle::GetSharedInstance().GetFont( | |
Ben Goodger (Google)
2011/11/30 22:52:20
You should be able to replace this function and Ge
varunjain
2011/11/30 23:25:52
Done.
| |
28 ui::ResourceBundle::BaseFont); | |
29 } | |
30 | |
31 // static | |
32 int TooltipManager::GetMaxWidth(int x, int y) { | |
33 // FIXME: change this. This is for now just copied from TooltipManagerGtk. | |
34 | |
35 // We always display the tooltip inside the root view. So the max width is | |
36 // the width of the view. | |
37 gfx::Rect monitor_bounds = | |
38 gfx::Screen::GetMonitorAreaNearestPoint(gfx::Point(x, y)); | |
39 // GtkLabel (gtk_label_ensure_layout) forces wrapping at this size. We mirror | |
40 // the size here otherwise tooltips wider than the size used by gtklabel end | |
41 // up with extraneous empty lines. | |
42 return monitor_bounds.width() == 0 ? 800 : (monitor_bounds.width() + 1) / 2; | |
43 } | |
44 | |
45 //////////////////////////////////////////////////////////////////////////////// | |
46 // TooltipManagerAura public: | |
47 | |
48 TooltipManagerAura::TooltipManagerAura(NativeWidgetAura* native_widget_aura) | |
49 : native_widget_aura_(native_widget_aura) { | |
50 native_widget_aura_->GetNativeView()->SetProperty(aura::kTooltipTextKey, | |
51 &tooltip_text_); | |
52 } | |
53 | |
54 TooltipManagerAura::~TooltipManagerAura() { | |
55 native_widget_aura_->GetNativeView()->SetProperty(aura::kTooltipTextKey, | |
56 NULL); | |
57 } | |
58 | |
59 //////////////////////////////////////////////////////////////////////////////// | |
60 // TooltipManagerAura, TooltipManager implementation: | |
61 | |
62 void TooltipManagerAura::UpdateTooltip() { | |
63 void* property = aura::Desktop::GetInstance()->GetProperty( | |
64 aura::kDesktopTooltipClientKey); | |
65 if (property) { | |
66 gfx::Point view_point = aura::Desktop::GetInstance()->last_mouse_location(); | |
67 aura::Window::ConvertPointToWindow(aura::Desktop::GetInstance(), | |
68 native_widget_aura_->GetNativeView(), &view_point); | |
69 View* view = GetViewUnderPoint(view_point); | |
70 if (view) { | |
71 View::ConvertPointFromWidget(view, &view_point); | |
72 if (!view->GetTooltipText(view_point, &tooltip_text_)) | |
73 tooltip_text_.clear(); | |
74 } else { | |
75 tooltip_text_.clear(); | |
76 } | |
77 aura::TooltipClient* tc = static_cast<aura::TooltipClient*>(property); | |
78 tc->UpdateTooltip(native_widget_aura_->GetNativeView()); | |
79 } | |
80 } | |
81 | |
82 void TooltipManagerAura::TooltipTextChanged(View* view) { | |
83 void* property = aura::Desktop::GetInstance()->GetProperty( | |
84 aura::kDesktopTooltipClientKey); | |
85 if (property) { | |
86 gfx::Point view_point = aura::Desktop::GetInstance()->last_mouse_location(); | |
87 aura::Window::ConvertPointToWindow(aura::Desktop::GetInstance(), | |
88 native_widget_aura_->GetNativeView(), &view_point); | |
89 View* target = GetViewUnderPoint(view_point); | |
90 if (target != view) | |
91 return; | |
92 if (target) { | |
93 View::ConvertPointFromWidget(view, &view_point); | |
94 if (!view->GetTooltipText(view_point, &tooltip_text_)) | |
95 tooltip_text_.clear(); | |
96 } else { | |
97 tooltip_text_.clear(); | |
98 } | |
99 aura::TooltipClient* tc = static_cast<aura::TooltipClient*>(property); | |
100 tc->UpdateTooltip(native_widget_aura_->GetNativeView()); | |
101 } | |
102 } | |
103 | |
104 void TooltipManagerAura::ShowKeyboardTooltip(View* view) { | |
105 NOTREACHED(); | |
106 } | |
107 | |
108 void TooltipManagerAura::HideKeyboardTooltip() { | |
109 NOTREACHED(); | |
110 } | |
111 | |
112 View* TooltipManagerAura::GetViewUnderPoint(const gfx::Point& point) { | |
113 View* root_view = native_widget_aura_->GetWidget()->GetRootView(); | |
114 return root_view->GetEventHandlerForPoint(point); | |
115 } | |
116 | |
117 } // namespace views. | |
OLD | NEW |