OLD | NEW |
---|---|
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 "chrome/browser/gtk/hover_controller_gtk.h" | 5 #include "chrome/browser/gtk/hover_controller_gtk.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "chrome/browser/gtk/gtk_chrome_button.h" | 8 #include "chrome/browser/gtk/gtk_chrome_button.h" |
9 | 9 |
10 static const gchar* kHoverControllerGtkKey = "__HOVER_CONTROLLER_GTK__"; | 10 static const gchar* kHoverControllerGtkKey = "__HOVER_CONTROLLER_GTK__"; |
11 | 11 |
12 HoverControllerGtk::HoverControllerGtk(GtkWidget* button) | 12 HoverControllerGtk::HoverControllerGtk(GtkWidget* button) |
13 : throb_animation_(this), | 13 : throb_animation_(this), |
14 hover_animation_(this), | 14 hover_animation_(this), |
15 button_(button) { | 15 button_(button) { |
16 g_object_ref(button_); | 16 g_object_ref(button_); |
17 gtk_chrome_button_set_hover_state(GTK_CHROME_BUTTON(button_), 0); | 17 gtk_chrome_button_set_hover_state(GTK_CHROME_BUTTON(button_), 0); |
18 | 18 |
19 g_signal_connect(button_, "enter-notify-event", | 19 signals_.Connect(button_, "enter-notify-event", |
20 G_CALLBACK(OnEnterThunk), this); | 20 G_CALLBACK(OnEnterThunk), this); |
21 g_signal_connect(button_, "leave-notify-event", | 21 signals_.Connect(button_, "leave-notify-event", |
22 G_CALLBACK(OnLeaveThunk), this); | 22 G_CALLBACK(OnLeaveThunk), this); |
23 g_signal_connect(button_, "destroy", | 23 signals_.Connect(button_, "destroy", |
24 G_CALLBACK(OnButtonDestroyThunk), this); | 24 G_CALLBACK(OnDestroyThunk), this); |
25 | 25 |
26 #ifndef NDEBUG | 26 #ifndef NDEBUG |
27 if (g_object_get_data(G_OBJECT(button_), kHoverControllerGtkKey)) | 27 if (g_object_get_data(G_OBJECT(button_), kHoverControllerGtkKey)) |
28 NOTREACHED(); | 28 NOTREACHED(); |
29 #endif // !NDEBUG | 29 #endif // !NDEBUG |
30 | 30 |
31 g_object_set_data(G_OBJECT(button), kHoverControllerGtkKey, this); | 31 g_object_set_data(G_OBJECT(button), kHoverControllerGtkKey, this); |
32 } | 32 } |
33 | 33 |
34 HoverControllerGtk::~HoverControllerGtk() { | 34 HoverControllerGtk::~HoverControllerGtk() { |
(...skipping 12 matching lines...) Expand all Loading... | |
47 | 47 |
48 // static | 48 // static |
49 HoverControllerGtk* HoverControllerGtk::GetHoverControllerGtk( | 49 HoverControllerGtk* HoverControllerGtk::GetHoverControllerGtk( |
50 GtkWidget* button) { | 50 GtkWidget* button) { |
51 return reinterpret_cast<HoverControllerGtk*>( | 51 return reinterpret_cast<HoverControllerGtk*>( |
52 g_object_get_data(G_OBJECT(button), kHoverControllerGtkKey)); | 52 g_object_get_data(G_OBJECT(button), kHoverControllerGtkKey)); |
53 } | 53 } |
54 | 54 |
55 void HoverControllerGtk::Destroy() { | 55 void HoverControllerGtk::Destroy() { |
56 gtk_chrome_button_set_hover_state(GTK_CHROME_BUTTON(button_), -1.0); | 56 gtk_chrome_button_set_hover_state(GTK_CHROME_BUTTON(button_), -1.0); |
57 g_signal_handlers_disconnect_by_func( | 57 |
58 button_, | |
59 reinterpret_cast<gpointer>(OnButtonDestroyThunk), | |
60 this); | |
Elliot Glaysher
2010/04/28 16:39:13
I'm not so sure that these are equivalent. Previou
Evan Stade
2010/04/28 19:00:51
it's not equivalent, but I believe the new code to
| |
61 g_object_set_data(G_OBJECT(button_), kHoverControllerGtkKey, NULL); | 58 g_object_set_data(G_OBJECT(button_), kHoverControllerGtkKey, NULL); |
62 g_object_unref(button_); | 59 g_object_unref(button_); |
63 button_ = NULL; | 60 button_ = NULL; |
64 | 61 |
65 delete this; | 62 delete this; |
66 } | 63 } |
67 | 64 |
68 void HoverControllerGtk::AnimationProgressed(const Animation* animation) { | 65 void HoverControllerGtk::AnimationProgressed(const Animation* animation) { |
69 if (!button_) | 66 if (!button_) |
70 return; | 67 return; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 if (event->state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK)) { | 101 if (event->state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK)) { |
105 hover_animation_.Reset(); | 102 hover_animation_.Reset(); |
106 gtk_chrome_button_set_hover_state(GTK_CHROME_BUTTON(button_), 0); | 103 gtk_chrome_button_set_hover_state(GTK_CHROME_BUTTON(button_), 0); |
107 } else { | 104 } else { |
108 hover_animation_.Hide(); | 105 hover_animation_.Hide(); |
109 } | 106 } |
110 | 107 |
111 return FALSE; | 108 return FALSE; |
112 } | 109 } |
113 | 110 |
114 void HoverControllerGtk::OnButtonDestroy(GtkWidget* widget) { | 111 void HoverControllerGtk::OnDestroy(GtkWidget* widget) { |
115 Destroy(); | 112 Destroy(); |
116 } | 113 } |
OLD | NEW |