Chromium Code Reviews| Index: chrome/browser/ui/views/validation_message_bubble_view.cc |
| diff --git a/chrome/browser/ui/views/validation_message_bubble_view.cc b/chrome/browser/ui/views/validation_message_bubble_view.cc |
| index 9eea2bae47255ee80a433d5282df44846519a041..3f7e6e1f5ad68203cb14e7713f58b2c59275d730 100644 |
| --- a/chrome/browser/ui/views/validation_message_bubble_view.cc |
| +++ b/chrome/browser/ui/views/validation_message_bubble_view.cc |
| @@ -7,38 +7,98 @@ |
| #include "content/public/browser/render_widget_host.h" |
| #include "content/public/browser/render_widget_host_view.h" |
| #include "content/public/browser/web_contents.h" |
| +#include "grit/theme_resources.h" |
| +#include "ui/base/resource/resource_bundle.h" |
| +#include "ui/views/controls/image_view.h" |
| +#include "ui/views/controls/label.h" |
| #include "ui/views/widget/widget.h" |
| +// static |
| +const int ValidationMessageBubbleView::kWindowMinWidth = 64; |
| +// static |
| +const int ValidationMessageBubbleView::kWindowMaxWidth = 256; |
| +static const int kPadding = 0; |
|
msw
2016/04/14 01:51:38
nit: Remove this and inline 0 as needed?
Evan Stade
2016/04/18 01:16:43
Done.
|
| +static const int kIconTextMargin = 8; |
| +static const int kTextVerticalMargin = 4; |
| + |
| ValidationMessageBubbleView::ValidationMessageBubbleView( |
| content::WebContents* web_contents, |
| const gfx::Rect& anchor_in_root_view, |
| const base::string16& main_text, |
| - const base::string16& sub_text) { |
| + const base::string16& sub_text) |
| + : width_(0), height_(0) { |
| content::RenderWidgetHostView* rwhv = web_contents->GetRenderWidgetHostView(); |
| + set_parent_window(rwhv->GetNativeView()); |
| + |
| + set_can_activate(false); |
| + set_arrow(views::BubbleBorder::TOP_LEFT); |
| const gfx::Rect anchor_in_screen = |
| anchor_in_root_view + rwhv->GetViewBounds().origin().OffsetFromOrigin(); |
| - delegate_ = new ValidationMessageBubbleDelegate( |
| - anchor_in_screen, main_text, sub_text, this); |
| - delegate_->set_parent_window(rwhv->GetNativeView()); |
| - views::BubbleDelegateView::CreateBubble(delegate_); |
| - delegate_->GetWidget()->ShowInactive(); |
| + SetAnchorRect(anchor_in_screen); |
| + |
| + ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| + views::ImageView* icon = new views::ImageView(); |
| + icon->SetImage(*bundle.GetImageSkiaNamed(IDR_INPUT_ALERT)); |
| + gfx::Size size = icon->GetPreferredSize(); |
| + icon->SetBounds(kPadding, kPadding, size.width(), size.height()); |
|
msw
2016/04/14 01:51:38
Can we use a LayoutManager here?
Evan Stade
2016/04/18 01:16:43
I'd rather just not touch it (this is just a refac
|
| + AddChildView(icon); |
| + |
| + views::Label* label = new views::Label( |
| + main_text, bundle.GetFontList(ui::ResourceBundle::MediumFont)); |
| + label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| + int text_start_x = kPadding + size.width() + kIconTextMargin; |
| + int min_available = kWindowMinWidth - text_start_x - kPadding; |
| + int max_available = kWindowMaxWidth - text_start_x - kPadding; |
| + int label_width = label->GetPreferredSize().width(); |
| + label->SetMultiLine(true); |
| + AddChildView(label); |
| + |
| + views::Label* sub_label = NULL; |
|
msw
2016/04/14 01:51:38
nit: nullptr
Evan Stade
2016/04/18 01:16:43
Done.
|
| + if (!sub_text.empty()) { |
| + sub_label = new views::Label(sub_text); |
| + sub_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| + label_width = std::max(label_width, sub_label->GetPreferredSize().width()); |
| + sub_label->SetMultiLine(true); |
| + AddChildView(sub_label); |
| + } |
| + |
| + label_width = std::min(std::max(label_width, min_available), max_available); |
| + label->SetBounds(text_start_x, kPadding, |
| + label_width, label->GetHeightForWidth(label_width)); |
| + int content_bottom = kPadding + label->height(); |
| + |
| + if (sub_label) { |
| + sub_label->SetBounds(text_start_x, |
| + content_bottom + kTextVerticalMargin, |
| + label_width, |
| + sub_label->GetHeightForWidth(label_width)); |
| + content_bottom += kTextVerticalMargin + sub_label->height(); |
| + } |
| + |
| + width_ = text_start_x + label_width + kPadding; |
| + height_ = content_bottom + kPadding; |
| + |
| + views::BubbleDialogDelegateView::CreateBubble(this)->ShowInactive(); |
| } |
| ValidationMessageBubbleView::~ValidationMessageBubbleView() { |
| - if (delegate_) |
| - delegate_->Close(); |
| +} |
| + |
| +gfx::Size ValidationMessageBubbleView::GetPreferredSize() const { |
| + return gfx::Size(width_, height_); |
| +} |
| + |
| +int ValidationMessageBubbleView::GetDialogButtons() const { |
| + return ui::DIALOG_BUTTON_NONE; |
| } |
| void ValidationMessageBubbleView::SetPositionRelativeToAnchor( |
| content::RenderWidgetHost* widget_host, |
| const gfx::Rect& anchor_in_root_view) { |
| - if (!delegate_) |
| - return; |
| - delegate_->SetPositionRelativeToAnchor( |
| - anchor_in_root_view + |
| + SetAnchorRect(anchor_in_root_view + |
| widget_host->GetView()->GetViewBounds().origin().OffsetFromOrigin()); |
| } |
| -void ValidationMessageBubbleView::WindowClosing() { |
| - delegate_ = NULL; |
| +void ValidationMessageBubbleView::CloseValidationMessage() { |
| + GetWidget()->Close(); |
| } |