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 8a4251717670066345dcfad6d0771faca05d1c31..20554f7bcf05b5869d84da9fb481326457f6169d 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,56 @@ |
#include "views/controls/link.h" |
#include "views/widget/widget.h" |
+namespace { |
+ |
+// TODO(msw): Get color from theme/window color. |
+const SkColor kColor = SK_ColorWHITE; |
+ |
+const int kBorderSize = 4; |
+const int kMaxLabelWidth = 250; |
+ |
+} // namespace |
+ |
namespace chromeos { |
-static const int kBorderSize = 4; |
-static const int kMaxLabelWidth = 250; |
+MessageBubble::MessageBubble(views::View* anchor_view, |
+ views::BubbleBorder::ArrowLocation arrow_location, |
+ SkBitmap* image, |
+ const string16& text, |
+ const string16& link) |
+ : BubbleDelegateView(anchor_view, arrow_location, kColor), |
+ image_(image), |
+ text_(text), |
+ close_button_(NULL), |
+ link_listener_(NULL) { |
+ help_links_.push_back(new views::Link(link)); |
+} |
-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) { |
+ // TODO(msw): views::Widget::InitParams::TYPE_POPUP??? |
+ views::BubbleDelegateView::CreateBubble(bubble); |
alicet1
2011/11/20 01:46:22
I think this bubble wants to be "focusless", check
msw
2011/11/21 20:34:43
Done.
I also added some temp code for chromeos::W
|
+ bubble->Show(); |
+} |
+ |
+MessageBubble::~MessageBubble() { |
+} |
+ |
+void MessageBubble::Init() { |
using views::GridLayout; |
views::View* control_view = new views::View(); |
@@ -49,9 +82,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 +92,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 +111,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) |
alicet1
2011/11/20 01:46:22
is there anything on touch that you need to exclud
msw
2011/11/21 20:34:43
I'm not sure the new bubble needs this mouse butto
|
-gboolean MessageBubble::OnButtonPress(GtkWidget* widget, |
- GdkEventButton* event) { |
- NativeWidgetGtk::OnButtonPress(widget, event); |
- // Never propagate event to parent. |
- return true; |
-} |
-#endif |
- |
} // namespace chromeos |