Chromium Code Reviews| 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/autocomplete/autocomplete_popup_view_gtk.h" | 5 #include "chrome/browser/autocomplete/autocomplete_popup_view_gtk.h" |
| 6 | 6 |
| 7 #include "base/gfx/gtk_util.h" | 7 #include "base/gfx/gtk_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 window_(gtk_window_new(GTK_WINDOW_POPUP)), | 34 window_(gtk_window_new(GTK_WINDOW_POPUP)), |
| 35 vbox_(NULL), | 35 vbox_(NULL), |
| 36 opened_(false) { | 36 opened_(false) { |
| 37 GTK_WIDGET_UNSET_FLAGS(window_, GTK_CAN_FOCUS); | 37 GTK_WIDGET_UNSET_FLAGS(window_, GTK_CAN_FOCUS); |
| 38 // Don't allow the window to be resized. This also forces the window to | 38 // Don't allow the window to be resized. This also forces the window to |
| 39 // shrink down to the size of its child contents. | 39 // shrink down to the size of its child contents. |
| 40 gtk_window_set_resizable(GTK_WINDOW(window_), FALSE); | 40 gtk_window_set_resizable(GTK_WINDOW(window_), FALSE); |
| 41 // Set up a 1 pixel border around the popup. | 41 // Set up a 1 pixel border around the popup. |
| 42 gtk_container_set_border_width(GTK_CONTAINER(window_), 1); | 42 gtk_container_set_border_width(GTK_CONTAINER(window_), 1); |
| 43 gtk_widget_modify_bg(window_, GTK_STATE_NORMAL, &kPopupBorderColor); | 43 gtk_widget_modify_bg(window_, GTK_STATE_NORMAL, &kPopupBorderColor); |
| 44 gtk_widget_modify_base(window_, GTK_STATE_NORMAL, &kPopupBorderColor); | |
| 45 } | 44 } |
| 46 | 45 |
| 47 AutocompletePopupViewGtk::~AutocompletePopupViewGtk() { | 46 AutocompletePopupViewGtk::~AutocompletePopupViewGtk() { |
| 48 // Explicitly destroy our model here, before we destroy our GTK widgets. | 47 // Explicitly destroy our model here, before we destroy our GTK widgets. |
| 49 // This is because the model destructor can call back into us, and we need | 48 // This is because the model destructor can call back into us, and we need |
| 50 // to make sure everything is still valid when it does. | 49 // to make sure everything is still valid when it does. |
| 51 model_.reset(); | 50 model_.reset(); |
| 52 if (vbox_) | 51 if (vbox_) |
| 53 gtk_widget_destroy(vbox_); | 52 gtk_widget_destroy(vbox_); |
| 54 gtk_widget_destroy(window_); | 53 gtk_widget_destroy(window_); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 66 } | 65 } |
| 67 | 66 |
| 68 // TODO(deanm): This could be done better, but the code is temporary | 67 // TODO(deanm): This could be done better, but the code is temporary |
| 69 // and will need to be replaced with custom drawing and not widgets. | 68 // and will need to be replaced with custom drawing and not widgets. |
| 70 if (vbox_) | 69 if (vbox_) |
| 71 gtk_widget_destroy(vbox_); | 70 gtk_widget_destroy(vbox_); |
| 72 | 71 |
| 73 vbox_ = gtk_vbox_new(FALSE, 0); | 72 vbox_ = gtk_vbox_new(FALSE, 0); |
| 74 | 73 |
| 75 for (size_t i = 0; i < result.size(); ++i) { | 74 for (size_t i = 0; i < result.size(); ++i) { |
| 76 std::string utf8; | 75 GtkWidget* label = gtk_label_new(NULL); |
| 77 utf8.append(WideToUTF8(result.match_at(i).contents)); | 76 char* markup = g_markup_printf_escaped( |
| 78 utf8.append(" - "); | 77 "%s <span weight=\"light\" size=\"small\">%s</span>", |
| 79 utf8.append(WideToUTF8(result.match_at(i).description)); | 78 WideToUTF8(result.match_at(i).contents).c_str(), |
| 80 GtkWidget* label = gtk_label_new(utf8.c_str()); | 79 WideToUTF8(result.match_at(i).description).c_str()); |
| 80 gtk_label_set_markup(GTK_LABEL(label), markup); | |
| 81 g_free (markup); | |
|
Evan Martin
2009/03/13 16:33:29
extra space
| |
| 82 | |
| 81 // We need to put the labels in an event box for background painting. | 83 // We need to put the labels in an event box for background painting. |
| 82 GtkWidget* ebox = gtk_event_box_new(); | 84 GtkWidget* ebox = gtk_event_box_new(); |
| 83 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | 85 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); |
| 84 gtk_container_add(GTK_CONTAINER(ebox), label); | 86 gtk_container_add(GTK_CONTAINER(ebox), label); |
| 85 gtk_box_pack_start(GTK_BOX(vbox_), ebox, FALSE, FALSE, 0); | 87 gtk_box_pack_start(GTK_BOX(vbox_), ebox, FALSE, FALSE, 0); |
| 86 gtk_widget_show(label); | 88 gtk_widget_show(label); |
| 87 gtk_widget_show(ebox); | 89 gtk_widget_show(ebox); |
| 88 if (i == model_->selected_line()) { | 90 if (i == model_->selected_line()) { |
| 89 gtk_widget_modify_bg(ebox, GTK_STATE_NORMAL, &kHighlightColor); | 91 gtk_widget_modify_bg(ebox, GTK_STATE_NORMAL, &kHighlightColor); |
| 90 } else { | 92 } else { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 111 gtk_window_move(GTK_WINDOW(window_), x, y); | 113 gtk_window_move(GTK_WINDOW(window_), x, y); |
| 112 gtk_widget_set_size_request(window_, width, -1); | 114 gtk_widget_set_size_request(window_, width, -1); |
| 113 gtk_widget_show(window_); | 115 gtk_widget_show(window_); |
| 114 opened_ = true; | 116 opened_ = true; |
| 115 } | 117 } |
| 116 | 118 |
| 117 void AutocompletePopupViewGtk::Hide() { | 119 void AutocompletePopupViewGtk::Hide() { |
| 118 gtk_widget_hide(window_); | 120 gtk_widget_hide(window_); |
| 119 opened_ = false; | 121 opened_ = false; |
| 120 } | 122 } |
| OLD | NEW |