Chromium Code Reviews| 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_) { |
|
Evan Stade
2012/09/11 08:28:56
prefer
if (!auto_close_ || mouse_inside_)
retur
Dan Beam
2012/09/11 16:33:41
Done.
| |
| 160 if (timer_.IsRunning()) { | 161 if (timer_.IsRunning()) { |
| 161 timer_.Reset(); | 162 timer_.Reset(); |
| 162 } else { | 163 } else { |
| 163 timer_.Start( | 164 timer_.Start( |
| 164 FROM_HERE, | 165 FROM_HERE, |
| 165 base::TimeDelta::FromMilliseconds(kBubbleCloseDelay), | 166 base::TimeDelta::FromMilliseconds(kBubbleCloseDelay), |
| 166 this, | 167 this, |
| 167 &ZoomBubbleGtk::CloseBubble); | 168 &ZoomBubbleGtk::CloseBubble); |
| 168 } | 169 } |
| 169 } | 170 } |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 188 double default_zoom_level = Profile::FromBrowserContext( | 189 double default_zoom_level = Profile::FromBrowserContext( |
| 189 tab_contents_->web_contents()->GetBrowserContext())-> | 190 tab_contents_->web_contents()->GetBrowserContext())-> |
| 190 GetPrefs()->GetDouble(prefs::kDefaultZoomLevel); | 191 GetPrefs()->GetDouble(prefs::kDefaultZoomLevel); |
| 191 tab_contents_->web_contents()->GetRenderViewHost()-> | 192 tab_contents_->web_contents()->GetRenderViewHost()-> |
| 192 SetZoomLevel(default_zoom_level); | 193 SetZoomLevel(default_zoom_level); |
| 193 } | 194 } |
| 194 | 195 |
| 195 gboolean ZoomBubbleGtk::OnMouseEnter(GtkWidget* widget, | 196 gboolean ZoomBubbleGtk::OnMouseEnter(GtkWidget* widget, |
| 196 GdkEventCrossing* event) { | 197 GdkEventCrossing* event) { |
| 197 StopTimerIfNecessary(); | 198 StopTimerIfNecessary(); |
| 199 mouse_inside_ = true; | |
| 198 return FALSE; | 200 return FALSE; |
| 199 } | 201 } |
| 200 | 202 |
| 201 gboolean ZoomBubbleGtk::OnMouseLeave(GtkWidget* widget, | 203 gboolean ZoomBubbleGtk::OnMouseLeave(GtkWidget* widget, |
| 202 GdkEventCrossing* event) { | 204 GdkEventCrossing* event) { |
| 203 StartTimerIfNecessary(); | 205 StartTimerIfNecessary(); |
| 206 mouse_inside_ = false; | |
|
Evan Stade
2012/09/11 08:28:56
wouldn't you need to put this before StartTimerIfN
Dan Beam
2012/09/11 16:33:41
Done.
| |
| 204 return FALSE; | 207 return FALSE; |
| 205 } | 208 } |
| OLD | NEW |