| 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/zoom_bubble_gtk.h" | 5 #include "chrome/browser/ui/gtk/zoom_bubble_gtk.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/prefs/pref_service.h" | 8 #include "chrome/browser/prefs/pref_service.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 10 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 // static | 62 // static |
| 63 void ZoomBubbleGtk::Close() { | 63 void ZoomBubbleGtk::Close() { |
| 64 if (g_bubble) | 64 if (g_bubble) |
| 65 g_bubble->CloseBubble(); | 65 g_bubble->CloseBubble(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 ZoomBubbleGtk::ZoomBubbleGtk(GtkWidget* anchor, | 68 ZoomBubbleGtk::ZoomBubbleGtk(GtkWidget* anchor, |
| 69 TabContents* tab_contents, | 69 TabContents* tab_contents, |
| 70 bool auto_close) | 70 bool auto_close) |
| 71 : auto_close_(auto_close), | 71 : auto_close_(auto_close), |
| 72 mouse_inside_(false), |
| 72 tab_contents_(tab_contents) { | 73 tab_contents_(tab_contents) { |
| 73 GtkThemeService* theme_service = | 74 GtkThemeService* theme_service = |
| 74 GtkThemeService::GetFrom(Profile::FromBrowserContext( | 75 GtkThemeService::GetFrom(Profile::FromBrowserContext( |
| 75 tab_contents->web_contents()->GetBrowserContext())); | 76 tab_contents->web_contents()->GetBrowserContext())); |
| 76 | 77 |
| 77 event_box_ = gtk_event_box_new(); | 78 event_box_ = gtk_event_box_new(); |
| 78 GtkWidget* container = gtk_vbox_new(FALSE, 0); | 79 GtkWidget* container = gtk_vbox_new(FALSE, 0); |
| 79 gtk_container_add(GTK_CONTAINER(event_box_), container); | 80 gtk_container_add(GTK_CONTAINER(event_box_), container); |
| 80 | 81 |
| 81 int zoom_percent = tab_contents->zoom_controller()->zoom_percent(); | 82 int zoom_percent = tab_contents->zoom_controller()->zoom_percent(); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 | 150 |
| 150 void ZoomBubbleGtk::Refresh() { | 151 void ZoomBubbleGtk::Refresh() { |
| 151 int zoom_percent = tab_contents_->zoom_controller()->zoom_percent(); | 152 int zoom_percent = tab_contents_->zoom_controller()->zoom_percent(); |
| 152 string16 text = | 153 string16 text = |
| 153 l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, zoom_percent); | 154 l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, zoom_percent); |
| 154 gtk_label_set_text(GTK_LABEL(g_bubble->label_), UTF16ToUTF8(text).c_str()); | 155 gtk_label_set_text(GTK_LABEL(g_bubble->label_), UTF16ToUTF8(text).c_str()); |
| 155 StartTimerIfNecessary(); | 156 StartTimerIfNecessary(); |
| 156 } | 157 } |
| 157 | 158 |
| 158 void ZoomBubbleGtk::StartTimerIfNecessary() { | 159 void ZoomBubbleGtk::StartTimerIfNecessary() { |
| 159 if (auto_close_) { | 160 if (!auto_close_ || mouse_inside_) |
| 160 if (timer_.IsRunning()) { | 161 return; |
| 161 timer_.Reset(); | 162 |
| 162 } else { | 163 if (timer_.IsRunning()) { |
| 163 timer_.Start( | 164 timer_.Reset(); |
| 164 FROM_HERE, | 165 } else { |
| 165 base::TimeDelta::FromMilliseconds(kBubbleCloseDelay), | 166 timer_.Start( |
| 166 this, | 167 FROM_HERE, |
| 167 &ZoomBubbleGtk::CloseBubble); | 168 base::TimeDelta::FromMilliseconds(kBubbleCloseDelay), |
| 168 } | 169 this, |
| 170 &ZoomBubbleGtk::CloseBubble); |
| 169 } | 171 } |
| 170 } | 172 } |
| 171 | 173 |
| 172 void ZoomBubbleGtk::StopTimerIfNecessary() { | 174 void ZoomBubbleGtk::StopTimerIfNecessary() { |
| 173 if (timer_.IsRunning()) | 175 if (timer_.IsRunning()) |
| 174 timer_.Stop(); | 176 timer_.Stop(); |
| 175 } | 177 } |
| 176 | 178 |
| 177 void ZoomBubbleGtk::CloseBubble() { | 179 void ZoomBubbleGtk::CloseBubble() { |
| 178 DCHECK(bubble_); | 180 DCHECK(bubble_); |
| 179 bubble_->Close(); | 181 bubble_->Close(); |
| 180 } | 182 } |
| 181 | 183 |
| 182 void ZoomBubbleGtk::OnDestroy(GtkWidget* widget) { | 184 void ZoomBubbleGtk::OnDestroy(GtkWidget* widget) { |
| 183 // Listen to the destroy signal and delete this instance when it is caught. | 185 // Listen to the destroy signal and delete this instance when it is caught. |
| 184 delete this; | 186 delete this; |
| 185 } | 187 } |
| 186 | 188 |
| 187 void ZoomBubbleGtk::OnSetDefaultLinkClick(GtkWidget* widget) { | 189 void ZoomBubbleGtk::OnSetDefaultLinkClick(GtkWidget* widget) { |
| 188 double default_zoom_level = Profile::FromBrowserContext( | 190 double default_zoom_level = Profile::FromBrowserContext( |
| 189 tab_contents_->web_contents()->GetBrowserContext())-> | 191 tab_contents_->web_contents()->GetBrowserContext())-> |
| 190 GetPrefs()->GetDouble(prefs::kDefaultZoomLevel); | 192 GetPrefs()->GetDouble(prefs::kDefaultZoomLevel); |
| 191 tab_contents_->web_contents()->GetRenderViewHost()-> | 193 tab_contents_->web_contents()->GetRenderViewHost()-> |
| 192 SetZoomLevel(default_zoom_level); | 194 SetZoomLevel(default_zoom_level); |
| 193 } | 195 } |
| 194 | 196 |
| 195 gboolean ZoomBubbleGtk::OnMouseEnter(GtkWidget* widget, | 197 gboolean ZoomBubbleGtk::OnMouseEnter(GtkWidget* widget, |
| 196 GdkEventCrossing* event) { | 198 GdkEventCrossing* event) { |
| 199 mouse_inside_ = true; |
| 197 StopTimerIfNecessary(); | 200 StopTimerIfNecessary(); |
| 198 return FALSE; | 201 return FALSE; |
| 199 } | 202 } |
| 200 | 203 |
| 201 gboolean ZoomBubbleGtk::OnMouseLeave(GtkWidget* widget, | 204 gboolean ZoomBubbleGtk::OnMouseLeave(GtkWidget* widget, |
| 202 GdkEventCrossing* event) { | 205 GdkEventCrossing* event) { |
| 206 mouse_inside_ = false; |
| 203 StartTimerIfNecessary(); | 207 StartTimerIfNecessary(); |
| 204 return FALSE; | 208 return FALSE; |
| 205 } | 209 } |
| OLD | NEW |