OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/ui/gtk/tabs/tab_gtk.h" | 5 #include "chrome/browser/ui/gtk/tabs/tab_gtk.h" |
6 | 6 |
7 #include <gdk/gdkkeysyms.h> | 7 #include <gdk/gdkkeysyms.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 | 291 |
292 /////////////////////////////////////////////////////////////////////////////// | 292 /////////////////////////////////////////////////////////////////////////////// |
293 // TabGtk, private: | 293 // TabGtk, private: |
294 | 294 |
295 void TabGtk::ContextMenuClosed() { | 295 void TabGtk::ContextMenuClosed() { |
296 delegate()->StopAllHighlighting(); | 296 delegate()->StopAllHighlighting(); |
297 menu_controller_.reset(); | 297 menu_controller_.reset(); |
298 } | 298 } |
299 | 299 |
300 void TabGtk::UpdateTooltipState() { | 300 void TabGtk::UpdateTooltipState() { |
| 301 // Note: This method can be called several times per second for various |
| 302 // reasons (e.g., navigation/loading state changes, tab media indicator |
| 303 // updates, and so on). However, we must avoid calling the |
| 304 // gtk_widget_set_XXX() methods if there is no actual change in state. |
| 305 // Otherwise, GTK will continuously re-hide *all* tooltips throughout the |
| 306 // browser in response! http://crbug.com/333002 |
| 307 |
301 // Only show the tooltip if the title is truncated. | 308 // Only show the tooltip if the title is truncated. |
302 if (title_width_ > title_bounds().width()) { | 309 if (title_width_ > title_bounds().width()) { |
303 gtk_widget_set_tooltip_text(widget(), | 310 const std::string utf8_title = base::UTF16ToUTF8(GetTitle()); |
304 base::UTF16ToUTF8(GetTitle()).c_str()); | 311 if (gtk_widget_get_has_tooltip(widget())) { |
| 312 gchar* const current_tooltip = gtk_widget_get_tooltip_text(widget()); |
| 313 if (current_tooltip) { |
| 314 const bool title_unchanged = (utf8_title == current_tooltip); |
| 315 g_free(current_tooltip); |
| 316 if (title_unchanged) |
| 317 return; |
| 318 } |
| 319 } |
| 320 gtk_widget_set_tooltip_text(widget(), utf8_title.c_str()); |
305 } else { | 321 } else { |
306 gtk_widget_set_has_tooltip(widget(), FALSE); | 322 if (gtk_widget_get_has_tooltip(widget())) |
| 323 gtk_widget_set_has_tooltip(widget(), FALSE); |
307 } | 324 } |
308 } | 325 } |
309 | 326 |
310 void TabGtk::CreateDragWidget() { | 327 void TabGtk::CreateDragWidget() { |
311 DCHECK(!drag_widget_); | 328 DCHECK(!drag_widget_); |
312 drag_widget_ = gtk_invisible_new(); | 329 drag_widget_ = gtk_invisible_new(); |
313 g_signal_connect(drag_widget_, "drag-failed", | 330 g_signal_connect(drag_widget_, "drag-failed", |
314 G_CALLBACK(OnDragFailedThunk), this); | 331 G_CALLBACK(OnDragFailedThunk), this); |
315 g_signal_connect(drag_widget_, "button-release-event", | 332 g_signal_connect(drag_widget_, "button-release-event", |
316 G_CALLBACK(OnDragButtonReleasedThunk), this); | 333 G_CALLBACK(OnDragButtonReleasedThunk), this); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 gdk_event_free(last_mouse_down_); | 375 gdk_event_free(last_mouse_down_); |
359 last_mouse_down_ = NULL; | 376 last_mouse_down_ = NULL; |
360 } | 377 } |
361 | 378 |
362 // Notify the drag helper that we're done with any potential drag operations. | 379 // Notify the drag helper that we're done with any potential drag operations. |
363 // Clean up the drag helper, which is re-created on the next mouse press. | 380 // Clean up the drag helper, which is re-created on the next mouse press. |
364 delegate_->EndDrag(canceled); | 381 delegate_->EndDrag(canceled); |
365 | 382 |
366 observer_.reset(); | 383 observer_.reset(); |
367 } | 384 } |
OLD | NEW |