Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(296)

Side by Side Diff: chrome/browser/gtk/page_info_window_gtk.cc

Issue 159521: Implementation of the page info dialog on Linux Gtk. (Closed)
Patch Set: Fix build Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/gtk/location_bar_view_gtk.cc ('k') | chrome/browser/page_info_model.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <gtk/gtk.h>
6
7 #include "build/build_config.h"
8
9 #include "app/l10n_util.h"
10 #include "app/resource_bundle.h"
11 #include "base/compiler_specific.h"
12 #include "base/string_util.h"
13 #include "chrome/browser/page_info_model.h"
14 #include "chrome/browser/page_info_window.h"
15 #include "chrome/common/gtk_util.h"
16 #include "grit/locale_settings.h"
17 #include "grit/generated_resources.h"
18
19
20 namespace {
21
22 class PageInfoWindowGtk : public PageInfoModel::PageInfoModelObserver {
23 public:
24 PageInfoWindowGtk(gfx::NativeWindow parent,
25 Profile* profile,
26 const GURL& url,
27 const NavigationEntry::SSLStatus& ssl,
28 bool show_history);
29 ~PageInfoWindowGtk();
30
31 // PageInfoModelObserver implementation:
32 virtual void ModelChanged();
33
34 // Shows the page info window.
35 void Show();
36
37 private:
38 // Layouts the different sections retrieved from the model.
39 void InitContents();
40
41 // Returns a widget that contains the UI for the passed |section|.
42 GtkWidget* CreateSection(const PageInfoModel::SectionInfo& section);
43
44 // The model containing the different sections to display.
45 PageInfoModel model_;
46
47 // The page info dialog.
48 GtkWidget* dialog_;
49
50 // The virtual box containing the sections.
51 GtkWidget* contents_;
52
53 DISALLOW_COPY_AND_ASSIGN(PageInfoWindowGtk);
54 };
55
56 // Close button callback.
57 void OnDialogResponse(GtkDialog* dialog, gpointer data) {
58 // "Close" was clicked.
59 gtk_widget_destroy(GTK_WIDGET(dialog));
60 }
61
62 void OnDestroy(GtkDialog* dialog, PageInfoWindowGtk* page_info) {
63 delete page_info;
64 }
65
66 ////////////////////////////////////////////////////////////////////////////////
67 // PageInfoWindowGtk, public:
68 PageInfoWindowGtk::PageInfoWindowGtk(gfx::NativeWindow parent,
69 Profile* profile,
70 const GURL& url,
71 const NavigationEntry::SSLStatus& ssl,
72 bool show_history)
73 : ALLOW_THIS_IN_INITIALIZER_LIST(model_(profile, url, ssl,
74 show_history, this)),
75 contents_(NULL) {
76 dialog_ = gtk_dialog_new_with_buttons(
77 l10n_util::GetStringUTF8(IDS_PAGEINFO_WINDOW_TITLE).c_str(),
78 parent,
79 // Non-modal.
80 GTK_DIALOG_NO_SEPARATOR,
81 GTK_STOCK_CLOSE,
82 GTK_RESPONSE_CLOSE,
83 NULL);
84 gtk_window_set_default_size(GTK_WINDOW(dialog_), 500, -1);
85 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog_)->vbox),
86 GtkUtil::kContentAreaSpacing);
87 GtkUtil::SetWindowIcon(GTK_WINDOW(dialog_));
88 g_signal_connect(dialog_, "response", G_CALLBACK(OnDialogResponse), NULL);
89 g_signal_connect(dialog_, "destroy", G_CALLBACK(OnDestroy), this);
90
91 InitContents();
92 }
93
94 PageInfoWindowGtk::~PageInfoWindowGtk() {}
95
96 void PageInfoWindowGtk::ModelChanged() {
97 InitContents();
98 }
99
100 GtkWidget* PageInfoWindowGtk::CreateSection(
101 const PageInfoModel::SectionInfo& section) {
102 GtkWidget* vbox = gtk_vbox_new(FALSE, GtkUtil::kControlSpacing);
103 GtkWidget* label = gtk_label_new(UTF16ToUTF8(section.title).c_str());
104
105 PangoAttrList* attributes = pango_attr_list_new();
106 pango_attr_list_insert(attributes,
107 pango_attr_weight_new(PANGO_WEIGHT_BOLD));
108 gtk_label_set_attributes(GTK_LABEL(label), attributes);
109 pango_attr_list_unref(attributes);
110 gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
111 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
112
113 GtkWidget* section_box = gtk_hbox_new(FALSE, 0);
114 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
115 GtkWidget* image = gtk_image_new_from_pixbuf(section.state ?
116 rb.GetPixbufNamed(IDR_PAGEINFO_GOOD) :
117 rb.GetPixbufNamed(IDR_PAGEINFO_BAD));
118 gtk_box_pack_start(GTK_BOX(section_box), image, FALSE, FALSE,
119 GtkUtil::kControlSpacing);
120 gtk_misc_set_alignment(GTK_MISC(image), 0, 0);
121
122 GtkWidget* text_box = gtk_vbox_new(FALSE, GtkUtil::kControlSpacing);
123 if (!section.head_line.empty()) {
124 label = gtk_label_new(UTF16ToUTF8(section.head_line).c_str());
125 gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
126 gtk_box_pack_start(GTK_BOX(text_box), label , FALSE, FALSE, 0);
127 }
128 label = gtk_label_new(UTF16ToUTF8(section.description).c_str());
129 gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
130 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
131 gtk_box_pack_start(GTK_BOX(text_box), label , FALSE, FALSE, 0);
132
133 gtk_box_pack_start(GTK_BOX(section_box), text_box , TRUE, TRUE, 0);
134 gtk_box_pack_start(GTK_BOX(vbox), section_box , TRUE, TRUE, 0);
135
136 return vbox;
137 }
138
139 void PageInfoWindowGtk::InitContents() {
140 if (contents_)
141 gtk_widget_destroy(contents_);
142 contents_ = gtk_vbox_new(FALSE, GtkUtil::kContentAreaSpacing);
143 for (int i = 0; i < model_.GetSectionCount(); i++) {
144 gtk_box_pack_start(GTK_BOX(contents_),
145 CreateSection(model_.GetSectionInfo(i)),
146 FALSE, FALSE, 0);
147 }
148 gtk_widget_show_all(contents_);
149 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog_)->vbox), contents_);
150 }
151
152 void PageInfoWindowGtk::Show() {
153 gtk_widget_show(dialog_);
154 }
155
156 } // namespace
157
158 namespace browser {
159
160 void ShowPageInfo(gfx::NativeWindow parent,
161 Profile* profile,
162 const GURL& url,
163 const NavigationEntry::SSLStatus& ssl,
164 bool show_history) {
165 PageInfoWindowGtk* window = new PageInfoWindowGtk(parent, profile, url,
166 ssl, show_history);
167 window->Show();
168 }
169
170 } // namespace browser
OLDNEW
« no previous file with comments | « chrome/browser/gtk/location_bar_view_gtk.cc ('k') | chrome/browser/page_info_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698