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

Unified Diff: chrome/browser/views/infobars/infobars.cc

Issue 1037006: Finish implementing the geolocation infobar; adds a Learn more link pointing ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/views/infobars/infobars.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/views/infobars/infobars.cc
===================================================================
--- chrome/browser/views/infobars/infobars.cc (revision 41849)
+++ chrome/browser/views/infobars/infobars.cc (working copy)
@@ -310,8 +310,9 @@
icon_ps.height());
gfx::Size text_ps = label_->GetPreferredSize();
- int text_width =
- GetAvailableWidth() - icon_->bounds().right() - kIconLabelSpacing;
+ int text_width = std::min(
+ text_ps.width(),
+ GetAvailableWidth() - icon_->bounds().right() - kIconLabelSpacing);
label_->SetBounds(icon_->bounds().right() + kIconLabelSpacing,
OffsetY(this, text_ps), text_width, text_ps.height());
}
@@ -431,6 +432,7 @@
: AlertInfoBar(delegate),
ok_button_(NULL),
cancel_button_(NULL),
+ link_(NULL),
initialized_(false) {
ok_button_ = new views::NativeButton(
this, delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK));
@@ -438,16 +440,51 @@
ok_button_->SetAppearsAsDefault(true);
cancel_button_ = new views::NativeButton(
this, delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL));
+
+ // Set up the link.
+ link_ = new views::Link;
+ const std::wstring link_text(delegate->GetLinkText());
+ if (!link_text.empty()) {
+ link_->SetText(link_text);
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ link_->SetFont(rb.GetFont(ResourceBundle::MediumFont));
+ link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
+ link_->SetController(this);
+ link_->MakeReadableOverBackgroundColor(background()->get_color());
+ }
}
ConfirmInfoBar::~ConfirmInfoBar() {
+ if (!initialized_) {
+ delete ok_button_;
+ delete cancel_button_;
+ delete link_;
+ }
}
+// ConfirmInfoBar, views::LinkController implementation: -----------------------
+
+void ConfirmInfoBar::LinkActivated(views::Link* source, int event_flags) {
+ DCHECK(source == link_);
+ DCHECK(link_->IsVisible());
+ DCHECK(!link_->GetText().empty());
+ if (GetDelegate()->LinkClicked(
+ event_utils::DispositionFromEventFlags(event_flags))) {
+ RemoveInfoBar();
+ }
+}
+
// ConfirmInfoBar, views::View overrides: --------------------------------------
void ConfirmInfoBar::Layout() {
+ // First layout right aligned items (from right to left) in order to determine
+ // the space avalable, then layout the left aligned items.
+
+ // Layout the close button.
InfoBar::Layout();
- int available_width = InfoBar::GetAvailableWidth();
+
+ // Layout the cancel and OK buttons.
+ int available_width = AlertInfoBar::GetAvailableWidth();
int ok_button_width = 0;
int cancel_button_width = 0;
gfx::Size ok_ps = ok_button_->GetPreferredSize();
@@ -470,7 +507,16 @@
int spacing = cancel_button_width > 0 ? kButtonButtonSpacing : 0;
ok_button_->SetBounds(cancel_button_->x() - spacing - ok_button_width,
OffsetY(this, ok_ps), ok_ps.width(), ok_ps.height());
+
+ // Layout the icon and label.
AlertInfoBar::Layout();
+
+ // Now append the link to the label's right edge.
+ link_->SetVisible(!link_->GetText().empty());
+ gfx::Size link_ps = link_->GetPreferredSize();
+ int link_x = label()->bounds().right() + kEndOfLabelSpacing;
+ int link_w = std::min(GetAvailableWidth() - link_x, link_ps.width());
+ link_->SetBounds(link_x, OffsetY(this, link_ps), link_w, link_ps.height());
}
void ConfirmInfoBar::ViewHierarchyChanged(bool is_add,
@@ -500,11 +546,7 @@
// ConfirmInfoBar, InfoBar overrides: ------------------------------------------
int ConfirmInfoBar::GetAvailableWidth() const {
- if (ok_button_)
- return ok_button_->x() - kEndOfLabelSpacing;
- if (cancel_button_)
- return cancel_button_->x() - kEndOfLabelSpacing;
- return InfoBar::GetAvailableWidth();
+ return ok_button_->x() - kEndOfLabelSpacing;
}
// ConfirmInfoBar, private: ----------------------------------------------------
@@ -516,6 +558,7 @@
void ConfirmInfoBar::Init() {
AddChildView(ok_button_);
AddChildView(cancel_button_);
+ AddChildView(link_);
}
// AlertInfoBarDelegate, InfoBarDelegate overrides: ----------------------------
« no previous file with comments | « chrome/browser/views/infobars/infobars.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698