| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/login/message_bubble.h" | 5 #include "chrome/browser/chromeos/login/message_bubble.h" |
| 6 | 6 |
| 7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "grit/generated_resources.h" | 9 #include "grit/generated_resources.h" |
| 10 #include "grit/theme_resources.h" | 10 #include "grit/theme_resources.h" |
| 11 #include "views/controls/button/image_button.h" | 11 #include "views/controls/button/image_button.h" |
| 12 #include "views/controls/image_view.h" | 12 #include "views/controls/image_view.h" |
| 13 #include "views/controls/label.h" | 13 #include "views/controls/label.h" |
| 14 #include "views/grid_layout.h" | 14 #include "views/grid_layout.h" |
| 15 #include "views/widget/widget.h" | 15 #include "views/widget/widget.h" |
| 16 | 16 |
| 17 namespace chromeos { | 17 namespace chromeos { |
| 18 | 18 |
| 19 static const int kBorderSize = 4; | 19 static const int kBorderSize = 4; |
| 20 static const int kMaxLabelWidth = 250; | 20 static const int kMaxLabelWidth = 250; |
| 21 | 21 |
| 22 MessageBubble::MessageBubble(views::WidgetGtk::Type type, views::Widget* parent, | 22 MessageBubble::MessageBubble(views::WidgetGtk::Type type, |
| 23 SkBitmap* image, const std::wstring& text, bool grab_enabled) | 23 views::Widget* parent, |
| 24 SkBitmap* image, |
| 25 const std::wstring& text, |
| 26 const std::wstring& help, |
| 27 bool grab_enabled, |
| 28 MessageBubbleDelegate* delegate) |
| 24 : InfoBubble(type), | 29 : InfoBubble(type), |
| 25 parent_(parent), | 30 parent_(parent), |
| 31 help_link_(NULL), |
| 32 message_delegate_(delegate), |
| 26 grab_enabled_(grab_enabled) { | 33 grab_enabled_(grab_enabled) { |
| 27 using views::GridLayout; | 34 using views::GridLayout; |
| 28 | 35 |
| 29 views::View* control_view = new views::View(); | 36 views::View* control_view = new views::View(); |
| 30 GridLayout* layout = new GridLayout(control_view); | 37 GridLayout* layout = new GridLayout(control_view); |
| 31 control_view->SetLayoutManager(layout); | 38 control_view->SetLayoutManager(layout); |
| 32 views::ColumnSet* column_set = layout->AddColumnSet(0); | 39 views::ColumnSet* column_set = layout->AddColumnSet(0); |
| 33 column_set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, | 40 column_set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, |
| 34 GridLayout::USE_PREF, 0, 0); | 41 GridLayout::USE_PREF, 0, 0); |
| 35 column_set->AddPaddingColumn(0, kBorderSize); | 42 column_set->AddPaddingColumn(0, kBorderSize); |
| 36 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, | 43 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, |
| 37 GridLayout::USE_PREF, 0, 0); | 44 GridLayout::USE_PREF, 0, 0); |
| 38 column_set->AddPaddingColumn(0, kBorderSize); | 45 column_set->AddPaddingColumn(0, kBorderSize); |
| 39 column_set->AddColumn(GridLayout::TRAILING, GridLayout::LEADING, 0, | 46 column_set->AddColumn(GridLayout::TRAILING, GridLayout::LEADING, 0, |
| 40 GridLayout::USE_PREF, 0, 0); | 47 GridLayout::USE_PREF, 0, 0); |
| 48 if (!help.empty()) { |
| 49 column_set = layout->AddColumnSet(1); |
| 50 column_set->AddPaddingColumn(0, kBorderSize + image->width()); |
| 51 column_set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 1, |
| 52 GridLayout::USE_PREF, 0, 0); |
| 53 } |
| 41 | 54 |
| 42 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 55 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 43 | 56 |
| 44 layout->StartRow(0, 0); | 57 layout->StartRow(0, 0); |
| 45 icon_ = new views::ImageView(); | 58 icon_ = new views::ImageView(); |
| 46 icon_->SetImage(*image); | 59 icon_->SetImage(*image); |
| 47 layout->AddView(icon_); | 60 layout->AddView(icon_); |
| 48 | 61 |
| 49 text_ = new views::Label(text); | 62 text_ = new views::Label(text); |
| 50 text_->SetMultiLine(true); | 63 text_->SetMultiLine(true); |
| 51 text_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 64 text_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 52 text_->SizeToFit(kMaxLabelWidth); | 65 text_->SizeToFit(kMaxLabelWidth); |
| 53 layout->AddView(text_); | 66 layout->AddView(text_); |
| 54 | 67 |
| 55 close_button_ = new views::ImageButton(this); | 68 close_button_ = new views::ImageButton(this); |
| 56 close_button_->SetImage(views::CustomButton::BS_NORMAL, | 69 close_button_->SetImage(views::CustomButton::BS_NORMAL, |
| 57 rb.GetBitmapNamed(IDR_CLOSE_BAR)); | 70 rb.GetBitmapNamed(IDR_CLOSE_BAR)); |
| 58 close_button_->SetImage(views::CustomButton::BS_HOT, | 71 close_button_->SetImage(views::CustomButton::BS_HOT, |
| 59 rb.GetBitmapNamed(IDR_CLOSE_BAR_H)); | 72 rb.GetBitmapNamed(IDR_CLOSE_BAR_H)); |
| 60 close_button_->SetImage(views::CustomButton::BS_PUSHED, | 73 close_button_->SetImage(views::CustomButton::BS_PUSHED, |
| 61 rb.GetBitmapNamed(IDR_CLOSE_BAR_P)); | 74 rb.GetBitmapNamed(IDR_CLOSE_BAR_P)); |
| 62 layout->AddView(close_button_); | 75 layout->AddView(close_button_); |
| 76 |
| 77 if (!help.empty()) { |
| 78 layout->StartRowWithPadding(0, 1, 0, kBorderSize); |
| 79 help_link_ = new views::Link(help); |
| 80 help_link_->SetController(this); |
| 81 layout->AddView(help_link_); |
| 82 } |
| 63 } | 83 } |
| 64 | 84 |
| 65 void MessageBubble::ButtonPressed(views::Button* sender, | 85 void MessageBubble::ButtonPressed(views::Button* sender, |
| 66 const views::Event& event) { | 86 const views::Event& event) { |
| 67 if (sender == close_button_) { | 87 if (sender == close_button_) { |
| 68 Close(); | 88 Close(); |
| 69 } else { | 89 } else { |
| 70 NOTREACHED() << "Unknown view"; | 90 NOTREACHED() << "Unknown view"; |
| 71 } | 91 } |
| 72 } | 92 } |
| 73 | 93 |
| 94 void MessageBubble::LinkActivated(views::Link* source, int event_flags) { |
| 95 if (source == help_link_) { |
| 96 if (message_delegate_) |
| 97 message_delegate_->OnHelpLinkActivated(); |
| 98 } else { |
| 99 NOTREACHED() << "Unknown view"; |
| 100 } |
| 101 } |
| 102 |
| 74 // static | 103 // static |
| 75 MessageBubble* MessageBubble::Show(views::Widget* parent, | 104 MessageBubble* MessageBubble::Show(views::Widget* parent, |
| 76 const gfx::Rect& position_relative_to, | 105 const gfx::Rect& position_relative_to, |
| 77 BubbleBorder::ArrowLocation arrow_location, | 106 BubbleBorder::ArrowLocation arrow_location, |
| 78 SkBitmap* image, | 107 SkBitmap* image, |
| 79 const std::wstring& text, | 108 const std::wstring& text, |
| 80 InfoBubbleDelegate* delegate) { | 109 const std::wstring& help, |
| 110 MessageBubbleDelegate* delegate) { |
| 81 // The bubble will be destroyed when it is closed. | 111 // The bubble will be destroyed when it is closed. |
| 82 MessageBubble* bubble = new MessageBubble( | 112 MessageBubble* bubble = new MessageBubble( |
| 83 views::WidgetGtk::TYPE_WINDOW, parent, image, text, true); | 113 views::WidgetGtk::TYPE_WINDOW, parent, image, text, help, true, delegate); |
| 84 bubble->Init(parent, position_relative_to, arrow_location, | 114 bubble->Init(parent, position_relative_to, arrow_location, |
| 85 bubble->text_->GetParent(), delegate); | 115 bubble->text_->GetParent(), delegate); |
| 86 return bubble; | 116 return bubble; |
| 87 } | 117 } |
| 88 | 118 |
| 89 // static | 119 // static |
| 90 MessageBubble* MessageBubble::ShowNoGrab( | 120 MessageBubble* MessageBubble::ShowNoGrab( |
| 91 views::Widget* parent, | 121 views::Widget* parent, |
| 92 const gfx::Rect& position_relative_to, | 122 const gfx::Rect& position_relative_to, |
| 93 BubbleBorder::ArrowLocation arrow_location, | 123 BubbleBorder::ArrowLocation arrow_location, |
| 94 SkBitmap* image, | 124 SkBitmap* image, |
| 95 const std::wstring& text, | 125 const std::wstring& text, |
| 96 InfoBubbleDelegate* delegate) { | 126 const std::wstring& help, |
| 127 MessageBubbleDelegate* delegate) { |
| 97 // The bubble will be destroyed when it is closed. | 128 // The bubble will be destroyed when it is closed. |
| 98 MessageBubble* bubble = new MessageBubble( | 129 MessageBubble* bubble = new MessageBubble( |
| 99 views::WidgetGtk::TYPE_CHILD, parent, image, text, false); | 130 views::WidgetGtk::TYPE_CHILD, parent, image, text, help, false, delegate); |
| 100 bubble->Init(parent, position_relative_to, arrow_location, | 131 bubble->Init(parent, position_relative_to, arrow_location, |
| 101 bubble->text_->GetParent(), delegate); | 132 bubble->text_->GetParent(), delegate); |
| 102 return bubble; | 133 return bubble; |
| 103 } | 134 } |
| 104 | 135 |
| 105 void MessageBubble::IsActiveChanged() { | 136 void MessageBubble::IsActiveChanged() { |
| 106 // Active parent instead. | 137 // Active parent instead. |
| 107 if (parent_ && IsActive()) { | 138 if (parent_ && IsActive()) { |
| 108 gtk_window_present_with_time( | 139 gtk_window_present_with_time( |
| 109 GTK_WINDOW(static_cast<WidgetGtk*>(parent_)->GetNativeView()), | 140 GTK_WINDOW(static_cast<WidgetGtk*>(parent_)->GetNativeView()), |
| 110 gtk_get_current_event_time()); | 141 gtk_get_current_event_time()); |
| 111 } | 142 } |
| 112 } | 143 } |
| 113 | 144 |
| 114 void MessageBubble::DoGrab() { | 145 void MessageBubble::DoGrab() { |
| 115 if (grab_enabled_) | 146 if (grab_enabled_) |
| 116 WidgetGtk::DoGrab(); | 147 WidgetGtk::DoGrab(); |
| 117 } | 148 } |
| 118 | 149 |
| 119 void MessageBubble::Close() { | 150 void MessageBubble::Close() { |
| 120 parent_ = NULL; | 151 parent_ = NULL; |
| 121 InfoBubble::Close(); | 152 InfoBubble::Close(); |
| 122 } | 153 } |
| 123 | 154 |
| 124 } // namespace chromeos | 155 } // namespace chromeos |
| OLD | NEW |