summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorukai@chromium.org <ukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-25 03:06:28 +0000
committerukai@chromium.org <ukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-25 03:06:28 +0000
commitd4cafafac04f16475b30346609c21dca6a8906d0 (patch)
tree222c3ead2eb74d7120be8b08356996003bf53b8d /chrome
parente9aac796f9c73762f82b79cdb49682383058b054 (diff)
downloadchromium_src-d4cafafac04f16475b30346609c21dca6a8906d0.zip
chromium_src-d4cafafac04f16475b30346609c21dca6a8906d0.tar.gz
chromium_src-d4cafafac04f16475b30346609c21dca6a8906d0.tar.bz2
Show EV cert info text next to security icon.
Use hbox to pack location entry, security icons and EV cert info text. Change ToolbarModel::GetInfoText not return SkColor. BUG=none TEST=none Review URL: http://codereview.chromium.org/126117 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19224 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/gtk/location_bar_view_gtk.cc122
-rw-r--r--chrome/browser/gtk/location_bar_view_gtk.h22
-rw-r--r--chrome/browser/toolbar_model.cc20
-rw-r--r--chrome/browser/toolbar_model.h14
-rw-r--r--chrome/browser/views/location_bar_view.cc15
-rw-r--r--chrome/browser/views/location_bar_view.h2
6 files changed, 114 insertions, 81 deletions
diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc
index 2ba90f1..86aa173 100644
--- a/chrome/browser/gtk/location_bar_view_gtk.cc
+++ b/chrome/browser/gtk/location_bar_view_gtk.cc
@@ -39,6 +39,8 @@ const int kSecurityIconPaddingRight = 2;
// image, but for now we get pretty close by just drawing a solid border.
const GdkColor kBorderColor = GDK_COLOR_RGB(0xbe, 0xc8, 0xd4);
+const GdkColor kEvTextColor = GDK_COLOR_RGB(0x00, 0x96, 0x14); // Green.
+
} // namespace
// static
@@ -50,7 +52,9 @@ const GdkColor LocationBarViewGtk::kBackgroundColorByLevel[3] = {
LocationBarViewGtk::LocationBarViewGtk(CommandUpdater* command_updater,
ToolbarModel* toolbar_model, AutocompletePopupPositioner* popup_positioner)
- : security_icon_(NULL),
+ : security_lock_icon_view_(NULL),
+ security_warning_icon_view_(NULL),
+ info_label_(NULL),
profile_(NULL),
command_updater_(command_updater),
toolbar_model_(toolbar_model),
@@ -61,7 +65,7 @@ LocationBarViewGtk::LocationBarViewGtk(CommandUpdater* command_updater,
LocationBarViewGtk::~LocationBarViewGtk() {
// All of our widgets should have be children of / owned by the alignment.
- alignment_.Destroy();
+ hbox_.Destroy();
}
void LocationBarViewGtk::Init() {
@@ -72,20 +76,58 @@ void LocationBarViewGtk::Init() {
popup_positioner_));
location_entry_->Init();
- alignment_.Own(gtk_alignment_new(0.0, 0.0, 1.0, 1.0));
- UpdateAlignmentPadding();
+ hbox_.Own(gtk_hbox_new(FALSE, 0));
// We will paint for the alignment, to paint the background and border.
- gtk_widget_set_app_paintable(alignment_.get(), TRUE);
+ gtk_widget_set_app_paintable(hbox_.get(), TRUE);
// Have GTK double buffer around the expose signal.
- gtk_widget_set_double_buffered(alignment_.get(), TRUE);
+ gtk_widget_set_double_buffered(hbox_.get(), TRUE);
// Redraw the whole location bar when it changes size (e.g., when toggling
// the home button on/off.
- gtk_widget_set_redraw_on_allocate(alignment_.get(), TRUE);
- g_signal_connect(alignment_.get(), "expose-event",
+ gtk_widget_set_redraw_on_allocate(hbox_.get(), TRUE);
+
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ security_lock_icon_view_ = gtk_image_new_from_pixbuf(
+ rb.GetPixbufNamed(IDR_LOCK));
+ gtk_widget_hide(GTK_WIDGET(security_lock_icon_view_));
+ security_warning_icon_view_ = gtk_image_new_from_pixbuf(
+ rb.GetPixbufNamed(IDR_WARNING));
+ gtk_widget_hide(GTK_WIDGET(security_warning_icon_view_));
+
+ info_label_ = gtk_label_new(NULL);
+ gtk_widget_modify_base(info_label_, GTK_STATE_NORMAL,
+ &LocationBarViewGtk::kBackgroundColorByLevel[0]);
+
+ g_signal_connect(hbox_.get(), "expose-event",
G_CALLBACK(&HandleExposeThunk), this);
- gtk_container_add(GTK_CONTAINER(alignment_.get()),
- location_entry_->widget());
+ GtkWidget* align = gtk_alignment_new(0.0, 0.0, 1.0, 1.0);
+ gtk_alignment_set_padding(GTK_ALIGNMENT(align),
+ kTopMargin + kBorderThickness,
+ kBottomMargin + kBorderThickness,
+ kEditLeftRightPadding, kEditLeftRightPadding);
+ gtk_container_add(GTK_CONTAINER(align), location_entry_->widget());
+ gtk_box_pack_start(GTK_BOX(hbox_.get()), align, TRUE, TRUE, 0);
+
+ // Pack info_label_ and security icons in hbox. We hide/show them
+ // by SetSecurityIcon() and SetInfoText().
+ align = gtk_alignment_new(0.0, 0.0, 1.0, 1.0);
+ gtk_alignment_set_padding(GTK_ALIGNMENT(align),
+ kTopMargin + kBorderThickness,
+ kBottomMargin + kBorderThickness,
+ 0, 0);
+ gtk_container_add(GTK_CONTAINER(align), info_label_);
+ gtk_box_pack_end(GTK_BOX(hbox_.get()), align, FALSE, FALSE, 0);
+
+ gtk_misc_set_alignment(GTK_MISC(security_lock_icon_view_), 0.0, 0.5);
+ gtk_misc_set_padding(GTK_MISC(security_lock_icon_view_),
+ kSecurityIconPaddingRight, 0);
+ gtk_box_pack_end(GTK_BOX(hbox_.get()),
+ security_lock_icon_view_, FALSE, FALSE, 0);
+ gtk_misc_set_alignment(GTK_MISC(security_warning_icon_view_), 0.0, 0.5);
+ gtk_misc_set_padding(GTK_MISC(security_warning_icon_view_),
+ kSecurityIconPaddingRight, 0);
+ gtk_box_pack_end(GTK_BOX(hbox_.get()),
+ security_warning_icon_view_, FALSE, FALSE, 0);
}
void LocationBarViewGtk::SetProfile(Profile* profile) {
@@ -94,9 +136,10 @@ void LocationBarViewGtk::SetProfile(Profile* profile) {
void LocationBarViewGtk::Update(const TabContents* contents) {
SetSecurityIcon(toolbar_model_->GetIcon());
+ SetInfoText();
location_entry_->Update(contents);
// The security level (background color) could have changed, etc.
- gtk_widget_queue_draw(alignment_.get());
+ gtk_widget_queue_draw(hbox_.get());
}
void LocationBarViewGtk::OnAutocompleteAccept(const GURL& url,
@@ -211,7 +254,7 @@ gboolean LocationBarViewGtk::HandleExpose(GtkWidget* widget,
GdkDrawable* drawable = GDK_DRAWABLE(event->window);
GdkGC* gc = gdk_gc_new(drawable);
- GdkRectangle* alloc_rect = &alignment_->allocation;
+ GdkRectangle* alloc_rect = &hbox_->allocation;
// The area outside of our margin, which includes the border.
GdkRectangle inner_rect = {
@@ -247,57 +290,42 @@ gboolean LocationBarViewGtk::HandleExpose(GtkWidget* widget,
inner_rect.width,
inner_rect.height - (kBorderThickness * 2));
- // If we have an SSL icon, draw it vertically centered on the right side.
- if (security_icon_) {
- int icon_width = gdk_pixbuf_get_width(security_icon_);
- int icon_height = gdk_pixbuf_get_height(security_icon_);
- int icon_x = inner_rect.x + inner_rect.width -
- kBorderThickness - icon_width - kSecurityIconPaddingRight;
- int icon_y = inner_rect.y +
- ((inner_rect.height - icon_height) / 2);
- gdk_draw_pixbuf(drawable, gc, security_icon_,
- 0, 0, icon_x, icon_y, -1, -1,
- GDK_RGB_DITHER_NONE, 0, 0);
- }
-
g_object_unref(gc);
return FALSE; // Continue propagating the expose.
}
-void LocationBarViewGtk::UpdateAlignmentPadding() {
- // When we have an icon, increase our right padding to make space for it.
- int right_padding = security_icon_ ? gdk_pixbuf_get_width(security_icon_) +
- kSecurityIconPaddingLeft + kSecurityIconPaddingRight :
- kEditLeftRightPadding;
-
- gtk_alignment_set_padding(GTK_ALIGNMENT(alignment_.get()),
- kTopMargin + kBorderThickness,
- kBottomMargin + kBorderThickness,
- kEditLeftRightPadding, right_padding);
-}
-
void LocationBarViewGtk::SetSecurityIcon(ToolbarModel::Icon icon) {
- static ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- static GdkPixbuf* kLockIcon = rb.GetPixbufNamed(IDR_LOCK);
- static GdkPixbuf* kWarningIcon = rb.GetPixbufNamed(IDR_WARNING);
-
+ gtk_widget_hide(GTK_WIDGET(security_lock_icon_view_));
+ gtk_widget_hide(GTK_WIDGET(security_warning_icon_view_));
switch (icon) {
case ToolbarModel::LOCK_ICON:
- security_icon_ = kLockIcon;
+ gtk_widget_show(GTK_WIDGET(security_lock_icon_view_));
break;
case ToolbarModel::WARNING_ICON:
- security_icon_ = kWarningIcon;
+ gtk_widget_show(GTK_WIDGET(security_warning_icon_view_));
break;
case ToolbarModel::NO_ICON:
- security_icon_ = NULL;
break;
default:
NOTREACHED();
- security_icon_ = NULL;
break;
}
+}
- // Make sure there is room for the icon.
- UpdateAlignmentPadding();
+void LocationBarViewGtk::SetInfoText() {
+ std::wstring info_text, info_tooltip;
+ ToolbarModel::InfoTextType info_text_type =
+ toolbar_model_->GetInfoText(&info_text, &info_tooltip);
+ if (info_text_type == ToolbarModel::INFO_EV_TEXT) {
+ gtk_widget_modify_fg(GTK_WIDGET(info_label_), GTK_STATE_NORMAL,
+ &kEvTextColor);
+ } else {
+ DCHECK_EQ(info_text_type, ToolbarModel::INFO_NO_INFO);
+ DCHECK(info_text.empty());
+ // Clear info_text. Should we reset the fg here?
+ }
+ gtk_label_set_text(GTK_LABEL(info_label_), WideToUTF8(info_text).c_str());
+ gtk_widget_set_tooltip_text(GTK_WIDGET(info_label_),
+ WideToUTF8(info_tooltip).c_str());
}
diff --git a/chrome/browser/gtk/location_bar_view_gtk.h b/chrome/browser/gtk/location_bar_view_gtk.h
index 355044a..3c95b31 100644
--- a/chrome/browser/gtk/location_bar_view_gtk.h
+++ b/chrome/browser/gtk/location_bar_view_gtk.h
@@ -32,14 +32,14 @@ class LocationBarViewGtk : public AutocompleteEditController,
LocationBarViewGtk(CommandUpdater* command_updater,
ToolbarModel* toolbar_model,
AutocompletePopupPositioner* popup_positioner);
- ~LocationBarViewGtk();
+ virtual ~LocationBarViewGtk();
void Init();
void SetProfile(Profile* profile);
// Returns the widget the caller should host. You must call Init() first.
- GtkWidget* widget() { return alignment_.get(); }
+ GtkWidget* widget() { return hbox_.get(); }
// Updates the location bar. We also reset the bar's permanent text and
// security style, and, if |tab_for_state_restoring| is non-NULL, also
@@ -84,18 +84,22 @@ class LocationBarViewGtk : public AutocompleteEditController,
}
gboolean HandleExpose(GtkWidget* widget, GdkEventExpose* event);
- // Calculate and set what the padding should be around the location entry.
- // For example, we will increase the right padding to make room for an icon.
- void UpdateAlignmentPadding();
-
// Set the SSL icon we should be showing.
void SetSecurityIcon(ToolbarModel::Icon icon);
+ // Sets the text that should be displayed in the info label and its associated
+ // tooltip text. Call with an empty string if the info label should be
+ // hidden.
+ void SetInfoText();
+
// The outermost widget we want to be hosted.
- OwnedWidgetGtk alignment_;
+ OwnedWidgetGtk hbox_;
- // The current SSL icon we are showing, or NULL.
- GdkPixbuf* security_icon_;
+ // SSL icons.
+ GtkWidget* security_lock_icon_view_;
+ GtkWidget* security_warning_icon_view_;
+ // Toolbar info text (EV cert info).
+ GtkWidget* info_label_;
scoped_ptr<AutocompleteEditViewGtk> location_entry_;
diff --git a/chrome/browser/toolbar_model.cc b/chrome/browser/toolbar_model.cc
index 66f03f0..9107ec2 100644
--- a/chrome/browser/toolbar_model.cc
+++ b/chrome/browser/toolbar_model.cc
@@ -157,36 +157,32 @@ void ToolbarModel::GetIconHoverText(std::wstring* text, SkColor* text_color) {
}
}
-void ToolbarModel::GetInfoText(std::wstring* text,
- SkColor* text_color,
- std::wstring* tooltip) {
- static const SkColor kEVTextColor =
- SkColorSetRGB(0, 150, 20); // Green.
-
+ToolbarModel::InfoTextType ToolbarModel::GetInfoText(std::wstring* text,
+ std::wstring* tooltip) {
DCHECK(text && tooltip);
text->clear();
tooltip->clear();
NavigationController* navigation_controller = GetNavigationController();
if (!navigation_controller) // We might not have a controller on init.
- return;
+ return INFO_NO_INFO;
NavigationEntry* entry = navigation_controller->GetActiveEntry();
const NavigationEntry::SSLStatus& ssl = entry->ssl();
if (!entry || ssl.has_mixed_content() ||
net::IsCertStatusError(ssl.cert_status()) ||
((ssl.cert_status() & net::CERT_STATUS_IS_EV) == 0))
- return;
+ return INFO_NO_INFO;
scoped_refptr<net::X509Certificate> cert;
CertStore::GetSharedInstance()->RetrieveCert(ssl.cert_id(), &cert);
if (!cert.get()) {
NOTREACHED();
- return;
+ return INFO_NO_INFO;
}
- *text_color = kEVTextColor;
SSLManager::GetEVCertNames(*cert, text, tooltip);
+ return INFO_EV_TEXT;
}
void ToolbarModel::CreateErrorText(NavigationEntry* entry, std::wstring* text) {
@@ -201,8 +197,8 @@ void ToolbarModel::CreateErrorText(NavigationEntry* entry, std::wstring* text) {
NULL, GURL::EmptyGURL()));
}
if (ssl.has_unsafe_content()) {
- errors.push_back(SSLErrorInfo::CreateError(SSLErrorInfo::UNSAFE_CONTENTS,
- NULL, GURL::EmptyGURL()));
+ errors.push_back(SSLErrorInfo::CreateError(SSLErrorInfo::UNSAFE_CONTENTS,
+ NULL, GURL::EmptyGURL()));
}
int error_count = static_cast<int>(errors.size());
diff --git a/chrome/browser/toolbar_model.h b/chrome/browser/toolbar_model.h
index e0935fd..357f7d2 100644
--- a/chrome/browser/toolbar_model.h
+++ b/chrome/browser/toolbar_model.h
@@ -31,8 +31,13 @@ class ToolbarModel {
WARNING_ICON
};
+ enum InfoTextType {
+ INFO_NO_INFO = 0,
+ INFO_EV_TEXT,
+ };
+
ToolbarModel();
- ~ToolbarModel();
+ virtual ~ToolbarModel();
// Returns the text that should be displayed in the location bar.
// Default value: empty string.
@@ -60,10 +65,9 @@ class ToolbarModel {
// Sets |text| to contain the text that should be displayed on the right of
// the location bar, and |tooltip| to the tooltip text that should be shown
// when the mouse hover over that info label.
- // Default value: empty string.
- virtual void GetInfoText(std::wstring* text,
- SkColor* text_color,
- std::wstring* tooltip);
+ // Default value: NO_INFO and empty string for |text| and |tooltip|.
+ virtual InfoTextType GetInfoText(std::wstring* text,
+ std::wstring* tooltip);
// Getter/setter of whether the text in location bar is currently being
// edited.
diff --git a/chrome/browser/views/location_bar_view.cc b/chrome/browser/views/location_bar_view.cc
index 59fbe37..7530dee 100644
--- a/chrome/browser/views/location_bar_view.cc
+++ b/chrome/browser/views/location_bar_view.cc
@@ -4,12 +4,12 @@
#include "chrome/browser/views/location_bar_view.h"
-#include "build/build_config.h"
-
#if defined(OS_LINUX)
#include <gtk/gtk.h>
#endif
+#include "build/build_config.h"
+
#include "app/gfx/canvas.h"
#include "app/gfx/favicon_size.h"
#include "app/l10n_util.h"
@@ -228,9 +228,9 @@ void LocationBarView::Update(const TabContents* tab_for_state_restoring) {
SetSecurityIcon(model_->GetIcon());
RefreshPageActionViews();
std::wstring info_text, info_tooltip;
- SkColor text_color;
- model_->GetInfoText(&info_text, &text_color, &info_tooltip);
- SetInfoText(info_text, text_color, info_tooltip);
+ ToolbarModel::InfoTextType info_text_type =
+ model_->GetInfoText(&info_text, &info_tooltip);
+ SetInfoText(info_text, info_text_type, info_tooltip);
location_entry_->Update(tab_for_state_restoring);
Layout();
SchedulePaint();
@@ -649,11 +649,12 @@ void LocationBarView::RefreshPageActionViews() {
}
void LocationBarView::SetInfoText(const std::wstring& text,
- SkColor text_color,
+ ToolbarModel::InfoTextType text_type,
const std::wstring& tooltip_text) {
info_label_.SetVisible(!text.empty());
info_label_.SetText(text);
- info_label_.SetColor(text_color);
+ if (text_type == ToolbarModel::INFO_EV_TEXT)
+ info_label_.SetColor(SkColorSetRGB(0, 150, 20)); // Green.
info_label_.SetTooltipText(tooltip_text);
}
diff --git a/chrome/browser/views/location_bar_view.h b/chrome/browser/views/location_bar_view.h
index 434fbed..b90693f 100644
--- a/chrome/browser/views/location_bar_view.h
+++ b/chrome/browser/views/location_bar_view.h
@@ -415,7 +415,7 @@ class LocationBarView : public LocationBar,
// tooltip text. Call with an empty string if the info label should be
// hidden.
void SetInfoText(const std::wstring& text,
- SkColor text_color,
+ ToolbarModel::InfoTextType text_type,
const std::wstring& tooltip_text);
// Sets the visibility of view to new_vis. Returns whether the visibility