Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: views/widget/tooltip_manager_gtk.cc

Issue 7015051: Re-land: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « views/widget/native_widget_test_utils_win.cc ('k') | views/widget/widget.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "views/widget/tooltip_manager_gtk.h" 5 #include "views/widget/tooltip_manager_gtk.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "ui/gfx/font.h" 9 #include "ui/gfx/font.h"
10 #include "views/focus/focus_manager.h" 10 #include "views/focus/focus_manager.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 } 78 }
79 79
80 bool TooltipManagerGtk::ShowTooltip(int x, int y, bool for_keyboard, 80 bool TooltipManagerGtk::ShowTooltip(int x, int y, bool for_keyboard,
81 GtkTooltip* tooltip) { 81 GtkTooltip* tooltip) {
82 View* view = NULL; 82 View* view = NULL;
83 gfx::Point view_loc; 83 gfx::Point view_loc;
84 if (keyboard_view_) { 84 if (keyboard_view_) {
85 view = keyboard_view_; 85 view = keyboard_view_;
86 view_loc.SetPoint(view->width() / 2, view->height() / 2); 86 view_loc.SetPoint(view->width() / 2, view->height() / 2);
87 } else if (!for_keyboard) { 87 } else if (!for_keyboard) {
88 RootView* root_view = widget_->GetRootView(); 88 RootView* root_view = widget_->GetWidget()->GetRootView();
89 view = root_view->GetEventHandlerForPoint(gfx::Point(x, y)); 89 view = root_view->GetEventHandlerForPoint(gfx::Point(x, y));
90 view_loc.SetPoint(x, y); 90 view_loc.SetPoint(x, y);
91 View::ConvertPointFromWidget(view, &view_loc); 91 View::ConvertPointFromWidget(view, &view_loc);
92 } else { 92 } else {
93 FocusManager* focus_manager = widget_->GetFocusManager(); 93 FocusManager* focus_manager = widget_->GetWidget()->GetFocusManager();
94 if (focus_manager) { 94 if (focus_manager) {
95 view = focus_manager->GetFocusedView(); 95 view = focus_manager->GetFocusedView();
96 if (view) 96 if (view)
97 view_loc.SetPoint(view->width() / 2, view->height() / 2); 97 view_loc.SetPoint(view->width() / 2, view->height() / 2);
98 } 98 }
99 } 99 }
100 100
101 if (!view) 101 if (!view)
102 return false; 102 return false;
103 103
104 std::wstring text; 104 std::wstring text;
105 if (!view->GetTooltipText(view_loc, &text)) 105 if (!view->GetTooltipText(view_loc, &text))
106 return false; 106 return false;
107 107
108 // Sets the area of the tooltip. This way if different views in the same 108 // Sets the area of the tooltip. This way if different views in the same
109 // widget have tooltips the tooltip doesn't get stuck at the same location. 109 // widget have tooltips the tooltip doesn't get stuck at the same location.
110 gfx::Rect vis_bounds = view->GetVisibleBounds(); 110 gfx::Rect vis_bounds = view->GetVisibleBounds();
111 gfx::Point widget_loc(vis_bounds.origin()); 111 gfx::Point widget_loc(vis_bounds.origin());
112 View::ConvertPointToWidget(view, &widget_loc); 112 View::ConvertPointToWidget(view, &widget_loc);
113 GdkRectangle tip_area = { widget_loc.x(), widget_loc.y(), 113 GdkRectangle tip_area = { widget_loc.x(), widget_loc.y(),
114 vis_bounds.width(), vis_bounds.height() }; 114 vis_bounds.width(), vis_bounds.height() };
115 gtk_tooltip_set_tip_area(tooltip, &tip_area); 115 gtk_tooltip_set_tip_area(tooltip, &tip_area);
116 116
117 int max_width, line_count; 117 int max_width, line_count;
118 gfx::Point screen_loc(x, y); 118 gfx::Point screen_loc(x, y);
119 View::ConvertPointToScreen(widget_->GetRootView(), &screen_loc); 119 View::ConvertPointToScreen(widget_->GetWidget()->GetRootView(), &screen_loc);
120 TrimTooltipToFit(&text, &max_width, &line_count, screen_loc.x(), 120 TrimTooltipToFit(&text, &max_width, &line_count, screen_loc.x(),
121 screen_loc.y()); 121 screen_loc.y());
122 tooltip_window_.SetTooltipText(text); 122 tooltip_window_.SetTooltipText(text);
123 123
124 return true; 124 return true;
125 } 125 }
126 126
127 void TooltipManagerGtk::UpdateTooltip() { 127 void TooltipManagerGtk::UpdateTooltip() {
128 // UpdateTooltip may be invoked after the widget has been destroyed. 128 // UpdateTooltip may be invoked after the widget has been destroyed.
129 GtkWidget* widget = widget_->GetNativeView(); 129 GtkWidget* widget = widget_->GetNativeView();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 if (!g_signal_parse_name("show_help", itype, &signal_id, &detail, FALSE)) { 173 if (!g_signal_parse_name("show_help", itype, &signal_id, &detail, FALSE)) {
174 NOTREACHED(); 174 NOTREACHED();
175 return false; 175 return false;
176 } 176 }
177 gboolean result; 177 gboolean result;
178 g_signal_emit(widget, signal_id, 0, GTK_WIDGET_HELP_TOOLTIP, &result); 178 g_signal_emit(widget, signal_id, 0, GTK_WIDGET_HELP_TOOLTIP, &result);
179 return true; 179 return true;
180 } 180 }
181 181
182 } // namespace views 182 } // namespace views
OLDNEW
« no previous file with comments | « views/widget/native_widget_test_utils_win.cc ('k') | views/widget/widget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698