| Index: chrome/browser/chromeos/login/message_bubble.cc
|
| diff --git a/chrome/browser/chromeos/login/message_bubble.cc b/chrome/browser/chromeos/login/message_bubble.cc
|
| index 275816688398f5547b67aac96b59935684b99c71..183070c9250974dc5af155a75e71fc5bcf69772c 100644
|
| --- a/chrome/browser/chromeos/login/message_bubble.cc
|
| +++ b/chrome/browser/chromeos/login/message_bubble.cc
|
| @@ -7,7 +7,6 @@
|
| #include <vector>
|
|
|
| #include "base/logging.h"
|
| -#include "base/utf_string_conversions.h"
|
| #include "chrome/browser/chromeos/login/helper.h"
|
| #include "grit/generated_resources.h"
|
| #include "grit/theme_resources_standard.h"
|
| @@ -19,22 +18,34 @@
|
| #include "ui/views/layout/grid_layout.h"
|
| #include "ui/views/widget/widget.h"
|
|
|
| -namespace chromeos {
|
| +namespace {
|
| +
|
| +const int kBorderSize = 4;
|
| +const int kMaxLabelWidth = 250;
|
|
|
| -static const int kBorderSize = 4;
|
| -static const int kMaxLabelWidth = 250;
|
| +} // namespace
|
| +
|
| +namespace chromeos {
|
|
|
| -MessageBubble::MessageBubble(views::Widget::InitParams::Type type,
|
| - views::Widget* parent,
|
| +MessageBubble::MessageBubble(views::View* anchor_view,
|
| + views::BubbleBorder::ArrowLocation arrow_location,
|
| SkBitmap* image,
|
| - const std::wstring& text,
|
| - const std::vector<std::wstring>& links,
|
| - bool grab_enabled,
|
| - MessageBubbleDelegate* delegate)
|
| - : Bubble(type, false), // don't show while screen is locked
|
| - parent_(parent),
|
| - message_delegate_(delegate),
|
| - grab_enabled_(grab_enabled) {
|
| + const string16& text,
|
| + const std::vector<string16>& links)
|
| + : BubbleDelegateView(anchor_view, arrow_location, kBackgroundColor),
|
| + image_(image),
|
| + text_(text),
|
| + close_button_(NULL),
|
| + link_listener_(NULL) {
|
| + set_use_focusless(true);
|
| + for (size_t i = 0; i < links.size(); ++i)
|
| + help_links_.push_back(new views::Link(links[i]));
|
| +}
|
| +
|
| +MessageBubble::~MessageBubble() {
|
| +}
|
| +
|
| +void MessageBubble::Init() {
|
| using views::GridLayout;
|
|
|
| views::View* control_view = new views::View();
|
| @@ -49,9 +60,9 @@ MessageBubble::MessageBubble(views::Widget::InitParams::Type type,
|
| column_set->AddPaddingColumn(0, kBorderSize);
|
| column_set->AddColumn(GridLayout::TRAILING, GridLayout::LEADING, 0,
|
| GridLayout::USE_PREF, 0, 0);
|
| - if (!links.empty()) {
|
| + if (!help_links_.empty()) {
|
| column_set = layout->AddColumnSet(1);
|
| - column_set->AddPaddingColumn(0, kBorderSize + image->width());
|
| + column_set->AddPaddingColumn(0, kBorderSize + image_->width());
|
| column_set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 1,
|
| GridLayout::USE_PREF, 0, 0);
|
| }
|
| @@ -59,16 +70,15 @@ MessageBubble::MessageBubble(views::Widget::InitParams::Type type,
|
| ResourceBundle& rb = ResourceBundle::GetSharedInstance();
|
|
|
| layout->StartRow(0, 0);
|
| - icon_ = new views::ImageView();
|
| - icon_->SetImage(*image);
|
| - layout->AddView(icon_);
|
| + views::ImageView* icon = new views::ImageView();
|
| + icon->SetImage(*image_);
|
| + layout->AddView(icon);
|
|
|
| - text_ = new views::Label(WideToUTF16Hack(text));
|
| - text_->SetMultiLine(true);
|
| - text_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
|
| - text_->SetBackgroundColor(Bubble::kBackgroundColor);
|
| - text_->SizeToFit(kMaxLabelWidth);
|
| - layout->AddView(text_);
|
| + views::Label* label = new views::Label(text_);
|
| + label->SetMultiLine(true);
|
| + label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
|
| + label->SizeToFit(kMaxLabelWidth);
|
| + layout->AddView(label);
|
|
|
| close_button_ = new views::ImageButton(this);
|
| close_button_->SetImage(views::CustomButton::BS_NORMAL,
|
| @@ -79,132 +89,35 @@ MessageBubble::MessageBubble(views::Widget::InitParams::Type type,
|
| rb.GetBitmapNamed(IDR_CLOSE_BAR_P));
|
| layout->AddView(close_button_);
|
|
|
| - for (size_t i = 0; i < links.size(); ++i) {
|
| + for (size_t i = 0; i < help_links_.size(); ++i) {
|
| layout->StartRowWithPadding(0, 1, 0, kBorderSize);
|
| - views::Link* help_link_ = new views::Link(WideToUTF16Hack(links[i]));
|
| - help_links_.push_back(help_link_);
|
| - help_link_->set_listener(this);
|
| - help_link_->SetBackgroundColor(Bubble::kBackgroundColor);
|
| - help_link_->SetEnabledColor(login::kLinkColor);
|
| - help_link_->SetPressedColor(login::kLinkColor);
|
| - layout->AddView(help_link_);
|
| + views::Link* help_link = help_links_[i];
|
| + help_link->set_listener(this);
|
| + help_link->SetEnabledColor(login::kLinkColor);
|
| + help_link->SetPressedColor(login::kLinkColor);
|
| + layout->AddView(help_link);
|
| }
|
| }
|
|
|
| -MessageBubble::~MessageBubble() {
|
| -}
|
| -
|
| void MessageBubble::ButtonPressed(views::Button* sender,
|
| const views::Event& event) {
|
| if (sender == close_button_) {
|
| - Close();
|
| + GetWidget()->Close();
|
| } else {
|
| NOTREACHED() << "Unknown view";
|
| }
|
| }
|
|
|
| void MessageBubble::LinkClicked(views::Link* source, int event_flags) {
|
| - if (!message_delegate_)
|
| + if (!link_listener_)
|
| return;
|
| for (size_t i = 0; i < help_links_.size(); ++i) {
|
| if (source == help_links_[i]) {
|
| - message_delegate_->OnLinkActivated(i);
|
| + link_listener_->OnLinkActivated(i);
|
| return;
|
| }
|
| }
|
| NOTREACHED() << "Unknown view";
|
| }
|
|
|
| -// static
|
| -MessageBubble* MessageBubble::Show(
|
| - views::Widget* parent,
|
| - const gfx::Rect& position_relative_to,
|
| - views::BubbleBorder::ArrowLocation arrow_location,
|
| - SkBitmap* image,
|
| - const std::wstring& text,
|
| - const std::wstring& help,
|
| - MessageBubbleDelegate* delegate) {
|
| - std::vector<std::wstring> links;
|
| - if (!help.empty())
|
| - links.push_back(help);
|
| - return MessageBubble::ShowWithLinks(parent,
|
| - position_relative_to,
|
| - arrow_location,
|
| - image,
|
| - text,
|
| - links,
|
| - delegate);
|
| -}
|
| -
|
| -// static
|
| -MessageBubble* MessageBubble::ShowWithLinks(
|
| - views::Widget* parent,
|
| - const gfx::Rect& position_relative_to,
|
| - views::BubbleBorder::ArrowLocation arrow_location,
|
| - SkBitmap* image,
|
| - const std::wstring& text,
|
| - const std::vector<std::wstring>& links,
|
| - MessageBubbleDelegate* delegate) {
|
| - // The bubble will be destroyed when it is closed.
|
| - MessageBubble* bubble = new MessageBubble(
|
| - views::Widget::InitParams::TYPE_POPUP, parent, image, text, links,
|
| - true, delegate);
|
| - bubble->InitBubble(parent, position_relative_to, arrow_location,
|
| - views::BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR,
|
| - bubble->text_->parent(), delegate);
|
| - return bubble;
|
| -}
|
| -
|
| -// static
|
| -MessageBubble* MessageBubble::ShowNoGrab(
|
| - views::Widget* parent,
|
| - const gfx::Rect& position_relative_to,
|
| - views::BubbleBorder::ArrowLocation arrow_location,
|
| - SkBitmap* image,
|
| - const std::wstring& text,
|
| - const std::wstring& help,
|
| - MessageBubbleDelegate* delegate) {
|
| - std::vector<std::wstring> links;
|
| - if (!help.empty())
|
| - links.push_back(help);
|
| - // The bubble will be destroyed when it is closed.
|
| - MessageBubble* bubble = new MessageBubble(
|
| - views::Widget::InitParams::TYPE_CONTROL, parent, image, text, links,
|
| - false, delegate);
|
| - bubble->InitBubble(parent, position_relative_to, arrow_location,
|
| - views::BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR,
|
| - bubble->text_->parent(), delegate);
|
| - return bubble;
|
| -}
|
| -
|
| -#if defined(TOOLKIT_USES_GTK)
|
| -// TODO(saintlou): Unclear if we need this for the !gtk case.
|
| -void MessageBubble::OnActiveChanged() {
|
| - if (parent_ && IsActive()) {
|
| - // Show the parent.
|
| - gtk_window_present_with_time(parent_->GetNativeWindow(),
|
| - gtk_get_current_event_time());
|
| - }
|
| -}
|
| -
|
| -void MessageBubble::SetMouseCapture() {
|
| - if (grab_enabled_)
|
| - NativeWidgetGtk::SetMouseCapture();
|
| -}
|
| -#endif
|
| -
|
| -void MessageBubble::Close() {
|
| - parent_ = NULL;
|
| - Bubble::Close();
|
| -}
|
| -
|
| -#if defined(TOOLKIT_USES_GTK)
|
| -gboolean MessageBubble::OnButtonPress(GtkWidget* widget,
|
| - GdkEventButton* event) {
|
| - NativeWidgetGtk::OnButtonPress(widget, event);
|
| - // Never propagate event to parent.
|
| - return true;
|
| -}
|
| -#endif
|
| -
|
| } // namespace chromeos
|
|
|