OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/bookmark_bubble_gtk.h" | 5 #include "chrome/browser/gtk/bookmark_bubble_gtk.h" |
6 | 6 |
7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "chrome/browser/gtk/info_bubble_gtk.h" | 11 #include "chrome/browser/gtk/info_bubble_gtk.h" |
12 | 12 |
| 13 namespace { |
| 14 |
| 15 // We basically have a singleton, since a bubble is sort of app-modal. This |
| 16 // keeps track of the currently open bubble, or NULL if none is open. |
| 17 BookmarkBubbleGtk* g_bubble = NULL; |
| 18 |
| 19 // TODO(deanm): Just a temporary state to keep track of the last entry in the |
| 20 // combo box. This makes sure we are catching the closing events right and |
| 21 // saving the state. |
| 22 gint g_last_active = 0; |
| 23 |
| 24 } // namespace |
| 25 |
13 // static | 26 // static |
14 void BookmarkBubbleGtk::Show(const gfx::Rect& rect, | 27 void BookmarkBubbleGtk::Show(const gfx::Rect& rect, |
15 Profile* profile, | 28 Profile* profile, |
16 const GURL& url, | 29 const GURL& url, |
17 bool newly_bookmarked) { | 30 bool newly_bookmarked) { |
| 31 // TODO(deanm): The Views code deals with the possibility of a bubble already |
| 32 // being open, and then it just does nothing. I am not sure how this could |
| 33 // happen with the style of our GTK bubble since it has a grab. I would also |
| 34 // think that closing the previous bubble and opening the new one would make |
| 35 // more sense, but I guess then you would commit the bubble's changes. |
| 36 DCHECK(!g_bubble); |
| 37 g_bubble = new BookmarkBubbleGtk(rect, profile, url, newly_bookmarked); |
| 38 } |
| 39 |
| 40 void BookmarkBubbleGtk::InfoBubbleClosing(InfoBubbleGtk* info_bubble, |
| 41 bool closed_by_escape) { |
| 42 // Possibly commit any bookmark changes here... |
| 43 g_last_active = gtk_combo_box_get_active(GTK_COMBO_BOX(combo_)); |
| 44 } |
| 45 |
| 46 BookmarkBubbleGtk::BookmarkBubbleGtk(const gfx::Rect& rect, |
| 47 Profile* profile, |
| 48 const GURL& url, |
| 49 bool newly_bookmarked) |
| 50 : profile_(profile), |
| 51 newly_bookmarked_(newly_bookmarked), |
| 52 content_(NULL), |
| 53 combo_(NULL) { |
18 // TODO(deanm): Implement the real bookmark bubble. For now we just have | 54 // TODO(deanm): Implement the real bookmark bubble. For now we just have |
19 // a placeholder for testing that input and focus works correctly. | 55 // a placeholder for testing that input and focus works correctly. |
20 GtkWidget* content = gtk_vbox_new(FALSE, 5); | 56 GtkWidget* content = gtk_vbox_new(FALSE, 5); |
21 gtk_box_pack_start(GTK_BOX(content), gtk_label_new("Hej!"), TRUE, TRUE, 0); | 57 gtk_box_pack_start(GTK_BOX(content), gtk_label_new("Hej!"), TRUE, TRUE, 0); |
22 gtk_box_pack_start(GTK_BOX(content), gtk_entry_new(), TRUE, TRUE, 0); | 58 gtk_box_pack_start(GTK_BOX(content), gtk_entry_new(), TRUE, TRUE, 0); |
23 gtk_box_pack_start(GTK_BOX(content), gtk_entry_new(), TRUE, TRUE, 0); | 59 // Use a combo box just to make sure popup windows work in the bubble content |
24 InfoBubbleGtk* bubble = InfoBubbleGtk::Show(rect, content); | 60 // and we're not fighting with the bubble for the grab. |
25 DCHECK(bubble); | 61 combo_ = gtk_combo_box_new_text(); |
| 62 gtk_combo_box_append_text(GTK_COMBO_BOX(combo_), "entry 1"); |
| 63 gtk_combo_box_append_text(GTK_COMBO_BOX(combo_), "entry 2"); |
| 64 gtk_combo_box_append_text(GTK_COMBO_BOX(combo_), "entry 3"); |
| 65 gtk_combo_box_set_active(GTK_COMBO_BOX(combo_), g_last_active); |
| 66 gtk_box_pack_start(GTK_BOX(content), combo_, TRUE, TRUE, 0); |
| 67 |
| 68 g_signal_connect(content, "destroy", |
| 69 G_CALLBACK(&HandleDestroyThunk), this); |
| 70 |
| 71 // TODO(deanm): In the future we might want to hang on to the returned |
| 72 // InfoBubble so that we can call Close() on it. |
| 73 if (!InfoBubbleGtk::Show(rect, content, this)) { |
| 74 NOTREACHED(); |
| 75 } |
26 } | 76 } |
| 77 |
| 78 BookmarkBubbleGtk::~BookmarkBubbleGtk() { |
| 79 DCHECK(!content_); // |content_| should have already been destroyed. |
| 80 |
| 81 DCHECK(g_bubble); |
| 82 g_bubble = NULL; |
| 83 } |
| 84 |
| 85 gboolean BookmarkBubbleGtk::HandleDestroy() { |
| 86 // We are self deleting, we have a destroy signal setup to catch when we |
| 87 // destroyed (via the InfoBubble being destroyed), and delete ourself. |
| 88 content_ = NULL; // We are being destroyed. |
| 89 delete this; |
| 90 return FALSE; // Propagate. |
| 91 } |
OLD | NEW |