diff options
| author | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-30 22:51:54 +0000 |
|---|---|---|
| committer | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-30 22:51:54 +0000 |
| commit | b232fc0b33f3c21a90918be4b646ccef388c9e63 (patch) | |
| tree | 78f53df2e06f8873cc6a5ad80a23e5ff2c981428 /chrome/browser/gtk | |
| parent | 1cb660eceb9de5b7d1ea7b97be06034c0cae8ae0 (diff) | |
| download | chromium_src-b232fc0b33f3c21a90918be4b646ccef388c9e63.zip chromium_src-b232fc0b33f3c21a90918be4b646ccef388c9e63.tar.gz chromium_src-b232fc0b33f3c21a90918be4b646ccef388c9e63.tar.bz2 | |
Relanding the page info on Gtk Linux.
Review URL: http://codereview.chromium.org/159657
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22112 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk')
| -rw-r--r-- | chrome/browser/gtk/browser_window_gtk.cc | 4 | ||||
| -rw-r--r-- | chrome/browser/gtk/location_bar_view_gtk.cc | 27 | ||||
| -rw-r--r-- | chrome/browser/gtk/location_bar_view_gtk.h | 5 | ||||
| -rw-r--r-- | chrome/browser/gtk/page_info_window_gtk.cc | 170 |
4 files changed, 203 insertions, 3 deletions
diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc index c5786dda..fff5eb7 100644 --- a/chrome/browser/gtk/browser_window_gtk.cc +++ b/chrome/browser/gtk/browser_window_gtk.cc @@ -53,6 +53,7 @@ #include "chrome/browser/gtk/task_manager_gtk.h" #include "chrome/browser/gtk/toolbar_star_toggle_gtk.h" #include "chrome/browser/location_bar.h" +#include "chrome/browser/page_info_window.h" #include "chrome/browser/renderer_host/render_widget_host_view_gtk.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_view.h" @@ -908,8 +909,7 @@ void BrowserWindowGtk::ShowPageInfo(Profile* profile, const GURL& url, const NavigationEntry::SSLStatus& ssl, bool show_history) { - // TODO(port): port PageInfoWindow. - NOTIMPLEMENTED() << "IDS_CONTENT_CONTEXT_VIEWFRAMEINFO"; + browser::ShowPageInfo(window_, profile, url, ssl, show_history); } void BrowserWindowGtk::ConfirmBrowserCloseWithPendingDownloads() { diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc index 8682c5a..f3a2618 100644 --- a/chrome/browser/gtk/location_bar_view_gtk.cc +++ b/chrome/browser/gtk/location_bar_view_gtk.cc @@ -15,6 +15,7 @@ #include "chrome/app/chrome_dll_resource.h" #include "chrome/browser/alternate_nav_url_fetcher.h" #include "chrome/browser/autocomplete/autocomplete_edit_view_gtk.h" +#include "chrome/browser/browser_list.h" #include "chrome/browser/command_updater.h" #include "chrome/browser/gtk/first_run_bubble.h" #include "chrome/browser/gtk/gtk_theme_provider.h" @@ -236,7 +237,16 @@ void LocationBarViewGtk::Init(bool popup_window_mode) { kBottomMargin + kBorderThickness, kSecurityIconPaddingLeft, kSecurityIconPaddingRight); - gtk_container_add(GTK_CONTAINER(security_icon_align_), security_icon_box); + // GtkImage is a "no window" widget and requires a GtkEventBox to receive + // events. + GtkWidget* event_box = gtk_event_box_new(); + // Make the event box not visible so it does not paint a background. + gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box), FALSE); + g_signal_connect(event_box, "button-press-event", + G_CALLBACK(&OnSecurityIconPressed), this); + + gtk_container_add(GTK_CONTAINER(event_box), security_icon_box); + gtk_container_add(GTK_CONTAINER(security_icon_align_), event_box); gtk_box_pack_end(GTK_BOX(hbox_.get()), security_icon_align_, FALSE, FALSE, 0); } @@ -554,3 +564,18 @@ void LocationBarViewGtk::ShowFirstRunBubbleInternal(bool use_OEM_bubble) { GTK_WINDOW(gtk_widget_get_toplevel(widget())), gfx::Rect(x, y, 0, 0), use_OEM_bubble); } + +// static +gboolean LocationBarViewGtk::OnSecurityIconPressed( + GtkWidget* sender, + GdkEventButton* event, + LocationBarViewGtk* location_bar) { + TabContents* tab = BrowserList::GetLastActive()->GetSelectedTabContents(); + NavigationEntry* nav_entry = tab->controller().GetActiveEntry(); + if (!nav_entry) { + NOTREACHED(); + return true; + } + tab->ShowPageInfo(nav_entry->url(), nav_entry->ssl(), true); + return true; +} diff --git a/chrome/browser/gtk/location_bar_view_gtk.h b/chrome/browser/gtk/location_bar_view_gtk.h index 1ac1fa4..b5731a2 100644 --- a/chrome/browser/gtk/location_bar_view_gtk.h +++ b/chrome/browser/gtk/location_bar_view_gtk.h @@ -87,8 +87,13 @@ class LocationBarViewGtk : public AutocompleteEditController, return reinterpret_cast<LocationBarViewGtk*>(userdata)-> HandleExpose(widget, event); } + gboolean HandleExpose(GtkWidget* widget, GdkEventExpose* event); + static gboolean OnSecurityIconPressed(GtkWidget* sender, + GdkEventButton* event, + LocationBarViewGtk* location_bar); + // Set the SSL icon we should be showing. void SetSecurityIcon(ToolbarModel::Icon icon); diff --git a/chrome/browser/gtk/page_info_window_gtk.cc b/chrome/browser/gtk/page_info_window_gtk.cc new file mode 100644 index 0000000..68b05b2f --- /dev/null +++ b/chrome/browser/gtk/page_info_window_gtk.cc @@ -0,0 +1,170 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include <gtk/gtk.h> + +#include "build/build_config.h" + +#include "app/l10n_util.h" +#include "app/resource_bundle.h" +#include "base/compiler_specific.h" +#include "base/string_util.h" +#include "chrome/browser/page_info_model.h" +#include "chrome/browser/page_info_window.h" +#include "chrome/common/gtk_util.h" +#include "grit/locale_settings.h" +#include "grit/generated_resources.h" + + +namespace { + +class PageInfoWindowGtk : public PageInfoModel::PageInfoModelObserver { + public: + PageInfoWindowGtk(gfx::NativeWindow parent, + Profile* profile, + const GURL& url, + const NavigationEntry::SSLStatus& ssl, + bool show_history); + ~PageInfoWindowGtk(); + + // PageInfoModelObserver implementation: + virtual void ModelChanged(); + + // Shows the page info window. + void Show(); + + private: + // Layouts the different sections retrieved from the model. + void InitContents(); + + // Returns a widget that contains the UI for the passed |section|. + GtkWidget* CreateSection(const PageInfoModel::SectionInfo& section); + + // The model containing the different sections to display. + PageInfoModel model_; + + // The page info dialog. + GtkWidget* dialog_; + + // The virtual box containing the sections. + GtkWidget* contents_; + + DISALLOW_COPY_AND_ASSIGN(PageInfoWindowGtk); +}; + +// Close button callback. +void OnDialogResponse(GtkDialog* dialog, gpointer data) { + // "Close" was clicked. + gtk_widget_destroy(GTK_WIDGET(dialog)); +} + +void OnDestroy(GtkDialog* dialog, PageInfoWindowGtk* page_info) { + delete page_info; +} + +//////////////////////////////////////////////////////////////////////////////// +// PageInfoWindowGtk, public: +PageInfoWindowGtk::PageInfoWindowGtk(gfx::NativeWindow parent, + Profile* profile, + const GURL& url, + const NavigationEntry::SSLStatus& ssl, + bool show_history) + : ALLOW_THIS_IN_INITIALIZER_LIST(model_(profile, url, ssl, + show_history, this)), + contents_(NULL) { + dialog_ = gtk_dialog_new_with_buttons( + l10n_util::GetStringUTF8(IDS_PAGEINFO_WINDOW_TITLE).c_str(), + parent, + // Non-modal. + GTK_DIALOG_NO_SEPARATOR, + GTK_STOCK_CLOSE, + GTK_RESPONSE_CLOSE, + NULL); + gtk_window_set_default_size(GTK_WINDOW(dialog_), 500, -1); + gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog_)->vbox), + GtkUtil::kContentAreaSpacing); + GtkUtil::SetWindowIcon(GTK_WINDOW(dialog_)); + g_signal_connect(dialog_, "response", G_CALLBACK(OnDialogResponse), NULL); + g_signal_connect(dialog_, "destroy", G_CALLBACK(OnDestroy), this); + + InitContents(); +} + +PageInfoWindowGtk::~PageInfoWindowGtk() {} + +void PageInfoWindowGtk::ModelChanged() { + InitContents(); +} + +GtkWidget* PageInfoWindowGtk::CreateSection( + const PageInfoModel::SectionInfo& section) { + GtkWidget* vbox = gtk_vbox_new(FALSE, GtkUtil::kControlSpacing); + GtkWidget* label = gtk_label_new(UTF16ToUTF8(section.title).c_str()); + + PangoAttrList* attributes = pango_attr_list_new(); + pango_attr_list_insert(attributes, + pango_attr_weight_new(PANGO_WEIGHT_BOLD)); + gtk_label_set_attributes(GTK_LABEL(label), attributes); + pango_attr_list_unref(attributes); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); + + GtkWidget* section_box = gtk_hbox_new(FALSE, 0); + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + GtkWidget* image = gtk_image_new_from_pixbuf(section.state ? + rb.GetPixbufNamed(IDR_PAGEINFO_GOOD) : + rb.GetPixbufNamed(IDR_PAGEINFO_BAD)); + gtk_box_pack_start(GTK_BOX(section_box), image, FALSE, FALSE, + GtkUtil::kControlSpacing); + gtk_misc_set_alignment(GTK_MISC(image), 0, 0); + + GtkWidget* text_box = gtk_vbox_new(FALSE, GtkUtil::kControlSpacing); + if (!section.head_line.empty()) { + label = gtk_label_new(UTF16ToUTF8(section.head_line).c_str()); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_box_pack_start(GTK_BOX(text_box), label , FALSE, FALSE, 0); + } + label = gtk_label_new(UTF16ToUTF8(section.description).c_str()); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); + gtk_box_pack_start(GTK_BOX(text_box), label , FALSE, FALSE, 0); + + gtk_box_pack_start(GTK_BOX(section_box), text_box , TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(vbox), section_box , TRUE, TRUE, 0); + + return vbox; +} + +void PageInfoWindowGtk::InitContents() { + if (contents_) + gtk_widget_destroy(contents_); + contents_ = gtk_vbox_new(FALSE, GtkUtil::kContentAreaSpacing); + for (int i = 0; i < model_.GetSectionCount(); i++) { + gtk_box_pack_start(GTK_BOX(contents_), + CreateSection(model_.GetSectionInfo(i)), + FALSE, FALSE, 0); + } + gtk_widget_show_all(contents_); + gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog_)->vbox), contents_); +} + +void PageInfoWindowGtk::Show() { + gtk_widget_show(dialog_); +} + +} // namespace + +namespace browser { + +void ShowPageInfo(gfx::NativeWindow parent, + Profile* profile, + const GURL& url, + const NavigationEntry::SSLStatus& ssl, + bool show_history) { + PageInfoWindowGtk* window = new PageInfoWindowGtk(parent, profile, url, + ssl, show_history); + window->Show(); +} + +} // namespace browser |
