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" |
11 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 11 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
12 #include "chrome/browser/ui/zoom/zoom_controller.h" | 12 #include "chrome/browser/ui/zoom/zoom_controller.h" |
13 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
14 #include "content/public/browser/render_view_host.h" | 14 #include "content/public/browser/render_view_host.h" |
15 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
16 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
17 #include "ui/base/gtk/gtk_hig_constants.h" | 17 #include "ui/base/gtk/gtk_hig_constants.h" |
18 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
19 #include "ui/gfx/rect.h" | 19 #include "ui/gfx/rect.h" |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 // Pointer to singleton object (NULL if no bubble is open). | |
24 ZoomBubbleGtk* g_bubble = NULL; | |
25 | |
26 // Number of milliseconds the bubble should stay open for if it will auto-close. | 23 // Number of milliseconds the bubble should stay open for if it will auto-close. |
27 const int kBubbleCloseDelay = 1500; | 24 const int kBubbleCloseDelay = 1500; |
28 | 25 |
29 // Need to manually set anchor width and height to ensure that the bubble shows | 26 // Need to manually set anchor width and height to ensure that the bubble shows |
30 // in the correct spot the first time it is displayed when no icon is present. | 27 // in the correct spot the first time it is displayed when no icon is present. |
31 const int kBubbleAnchorWidth = 20; | 28 const int kBubbleAnchorWidth = 20; |
32 const int kBubbleAnchorHeight = 25; | 29 const int kBubbleAnchorHeight = 25; |
33 | 30 |
34 } // namespace | 31 } // namespace |
35 | 32 |
36 // static | 33 // static |
| 34 ZoomBubbleGtk* ZoomBubbleGtk::g_bubble = NULL; |
| 35 |
| 36 // static |
37 void ZoomBubbleGtk::Show(GtkWidget* anchor, | 37 void ZoomBubbleGtk::Show(GtkWidget* anchor, |
38 TabContents* tab_contents, | 38 TabContents* tab_contents, |
39 bool auto_close) { | 39 bool auto_close) { |
40 // If the bubble is already showing and its |auto_close_| value is equal to | 40 // If the bubble is already showing and its |auto_close_| value is equal to |
41 // |auto_close|, the bubble can be reused and only the label text needs to | 41 // |auto_close|, the bubble can be reused and only the label text needs to |
42 // be updated. | 42 // be updated. |
43 if (g_bubble && | 43 if (g_bubble && |
44 g_bubble->auto_close_ == auto_close && | 44 g_bubble->auto_close_ == auto_close && |
45 g_bubble->bubble_->anchor_widget() == anchor) { | 45 g_bubble->bubble_->anchor_widget() == anchor) { |
46 g_bubble->Refresh(); | 46 g_bubble->Refresh(); |
47 } else { | 47 } else { |
48 // If the bubble is already showing but its |auto_close_| value is not equal | 48 // If the bubble is already showing but its |auto_close_| value is not equal |
49 // to |auto_close|, the bubble's focus properties must change, so the | 49 // to |auto_close|, the bubble's focus properties must change, so the |
50 // current bubble must be closed and a new one created. | 50 // current bubble must be closed and a new one created. |
51 Close(); | 51 Close(); |
52 DCHECK(!g_bubble); | 52 DCHECK(!g_bubble); |
53 | 53 |
54 g_bubble = new ZoomBubbleGtk(anchor, tab_contents, auto_close); | 54 g_bubble = new ZoomBubbleGtk(anchor, tab_contents, auto_close); |
55 } | 55 } |
56 } | 56 } |
57 | 57 |
58 // static | 58 // static |
59 void ZoomBubbleGtk::Close() { | 59 void ZoomBubbleGtk::Close() { |
60 if (g_bubble) | 60 if (g_bubble) |
61 g_bubble->CloseBubble(); | 61 g_bubble->CloseBubble(); |
62 } | 62 } |
63 | 63 |
| 64 // static |
| 65 bool ZoomBubbleGtk::IsShowing() { |
| 66 return g_bubble != NULL; |
| 67 } |
| 68 |
64 ZoomBubbleGtk::ZoomBubbleGtk(GtkWidget* anchor, | 69 ZoomBubbleGtk::ZoomBubbleGtk(GtkWidget* anchor, |
65 TabContents* tab_contents, | 70 TabContents* tab_contents, |
66 bool auto_close) | 71 bool auto_close) |
67 : auto_close_(auto_close), | 72 : auto_close_(auto_close), |
68 mouse_inside_(false), | 73 mouse_inside_(false), |
69 tab_contents_(tab_contents) { | 74 tab_contents_(tab_contents) { |
70 GtkThemeService* theme_service = | 75 GtkThemeService* theme_service = |
71 GtkThemeService::GetFrom(Profile::FromBrowserContext( | 76 GtkThemeService::GetFrom(Profile::FromBrowserContext( |
72 tab_contents->web_contents()->GetBrowserContext())); | 77 tab_contents->web_contents()->GetBrowserContext())); |
73 | 78 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 StopTimerIfNecessary(); | 207 StopTimerIfNecessary(); |
203 return FALSE; | 208 return FALSE; |
204 } | 209 } |
205 | 210 |
206 gboolean ZoomBubbleGtk::OnMouseLeave(GtkWidget* widget, | 211 gboolean ZoomBubbleGtk::OnMouseLeave(GtkWidget* widget, |
207 GdkEventCrossing* event) { | 212 GdkEventCrossing* event) { |
208 mouse_inside_ = false; | 213 mouse_inside_ = false; |
209 StartTimerIfNecessary(); | 214 StartTimerIfNecessary(); |
210 return FALSE; | 215 return FALSE; |
211 } | 216 } |
OLD | NEW |