Chromium Code Reviews| 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 d118905fc878a41e84fd32fefca12a25c57b8b3b..ad8da31f6f13b06f65203e2508a0c130d438ebf7 100644 |
| --- a/chrome/browser/chromeos/login/message_bubble.cc |
| +++ b/chrome/browser/chromeos/login/message_bubble.cc |
| @@ -7,8 +7,8 @@ |
| #include <vector> |
| #include "base/logging.h" |
| -#include "base/utf_string_conversions.h" |
| #include "chrome/browser/chromeos/login/helper.h" |
| +#include "chrome/browser/ui/views/window.h" |
| #include "grit/generated_resources.h" |
| #include "grit/theme_resources_standard.h" |
| #include "ui/base/resource/resource_bundle.h" |
| @@ -19,27 +19,47 @@ |
| #include "views/controls/label.h" |
| #include "views/controls/link.h" |
| -namespace chromeos { |
| +namespace { |
| + |
| +// TODO(msw): Get color from theme/window color. |
| +const SkColor kColor = SK_ColorWHITE; |
|
Dmitry Polukhin
2011/11/23 12:44:35
I would put default color into Bubble class as it
msw
2011/11/29 00:11:07
Done (moved default constant to BubbleDelegateView
|
| + |
| +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, kColor), |
| + image_(image), |
| + text_(text), |
| + close_button_(NULL), |
| + link_listener_(NULL) { |
| + for (size_t i = 0; i < links.size(); ++i) |
| + help_links_.push_back(new views::Link(links[i])); |
| +} |
| + |
| +// static |
| +void MessageBubble::ShowBubble(MessageBubble* bubble) { |
| + bubble->set_use_focusless(true); |
| + browser::CreateViewsBubbleAboveLockScreen(bubble); |
| + bubble->Show(); |
| +} |
| + |
| +MessageBubble::~MessageBubble() { |
| +} |
| + |
| +void MessageBubble::Init() { |
| using views::GridLayout; |
| - views::View* control_view = new views::View(); |
| - GridLayout* layout = new GridLayout(control_view); |
| - control_view->SetLayoutManager(layout); |
| + GridLayout* layout = new GridLayout(this); |
| + SetLayoutManager(layout); |
| views::ColumnSet* column_set = layout->AddColumnSet(0); |
| column_set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, |
| GridLayout::USE_PREF, 0, 0); |
| @@ -49,9 +69,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 +79,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 +98,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(TOUCH_UI) && 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(TOUCH_UI) && 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 |