| 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::Widget* parent, SkBitmap* image, | 22 MessageBubble::MessageBubble(views::WidgetGtk::Type type, views::Widget* parent, |
| 23 const std::wstring& text) : parent_(parent) { | 23 SkBitmap* image, const std::wstring& text, bool grab_enabled) |
| 24 : InfoBubble(type), |
| 25 parent_(parent), |
| 26 grab_enabled_(grab_enabled) { |
| 24 using views::GridLayout; | 27 using views::GridLayout; |
| 25 | 28 |
| 26 views::View* control_view = new views::View(); | 29 views::View* control_view = new views::View(); |
| 27 GridLayout* layout = new GridLayout(control_view); | 30 GridLayout* layout = new GridLayout(control_view); |
| 28 control_view->SetLayoutManager(layout); | 31 control_view->SetLayoutManager(layout); |
| 29 views::ColumnSet* column_set = layout->AddColumnSet(0); | 32 views::ColumnSet* column_set = layout->AddColumnSet(0); |
| 30 column_set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, | 33 column_set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, |
| 31 GridLayout::USE_PREF, 0, 0); | 34 GridLayout::USE_PREF, 0, 0); |
| 32 column_set->AddPaddingColumn(0, kBorderSize); | 35 column_set->AddPaddingColumn(0, kBorderSize); |
| 33 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, | 36 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 } | 72 } |
| 70 | 73 |
| 71 // static | 74 // static |
| 72 MessageBubble* MessageBubble::Show(views::Widget* parent, | 75 MessageBubble* MessageBubble::Show(views::Widget* parent, |
| 73 const gfx::Rect& position_relative_to, | 76 const gfx::Rect& position_relative_to, |
| 74 BubbleBorder::ArrowLocation arrow_location, | 77 BubbleBorder::ArrowLocation arrow_location, |
| 75 SkBitmap* image, | 78 SkBitmap* image, |
| 76 const std::wstring& text, | 79 const std::wstring& text, |
| 77 InfoBubbleDelegate* delegate) { | 80 InfoBubbleDelegate* delegate) { |
| 78 // The bubble will be destroyed when it is closed. | 81 // The bubble will be destroyed when it is closed. |
| 79 MessageBubble* bubble = new MessageBubble(parent, image, text); | 82 MessageBubble* bubble = new MessageBubble( |
| 83 views::WidgetGtk::TYPE_WINDOW, parent, image, text, true); |
| 80 bubble->Init(parent, position_relative_to, arrow_location, | 84 bubble->Init(parent, position_relative_to, arrow_location, |
| 81 bubble->text_->GetParent(), delegate); | 85 bubble->text_->GetParent(), delegate); |
| 82 return bubble; | 86 return bubble; |
| 87 } |
| 88 |
| 89 // static |
| 90 MessageBubble* MessageBubble::ShowNoGrab( |
| 91 views::Widget* parent, |
| 92 const gfx::Rect& position_relative_to, |
| 93 BubbleBorder::ArrowLocation arrow_location, |
| 94 SkBitmap* image, |
| 95 const std::wstring& text, |
| 96 InfoBubbleDelegate* delegate) { |
| 97 // The bubble will be destroyed when it is closed. |
| 98 MessageBubble* bubble = new MessageBubble( |
| 99 views::WidgetGtk::TYPE_CHILD, parent, image, text, false); |
| 100 bubble->Init(parent, position_relative_to, arrow_location, |
| 101 bubble->text_->GetParent(), delegate); |
| 102 return bubble; |
| 83 } | 103 } |
| 84 | 104 |
| 85 void MessageBubble::IsActiveChanged() { | 105 void MessageBubble::IsActiveChanged() { |
| 86 // Active parent instead. | 106 // Active parent instead. |
| 87 if (parent_ && IsActive()) { | 107 if (parent_ && IsActive()) { |
| 88 gtk_window_present_with_time( | 108 gtk_window_present_with_time( |
| 89 GTK_WINDOW(static_cast<WidgetGtk*>(parent_)->GetNativeView()), | 109 GTK_WINDOW(static_cast<WidgetGtk*>(parent_)->GetNativeView()), |
| 90 gtk_get_current_event_time()); | 110 gtk_get_current_event_time()); |
| 91 } | 111 } |
| 92 } | 112 } |
| 93 | 113 |
| 114 void MessageBubble::DoGrab() { |
| 115 if (grab_enabled_) |
| 116 WidgetGtk::DoGrab(); |
| 117 } |
| 118 |
| 94 void MessageBubble::Close() { | 119 void MessageBubble::Close() { |
| 95 parent_ = NULL; | 120 parent_ = NULL; |
| 96 InfoBubble::Close(); | 121 InfoBubble::Close(); |
| 97 } | 122 } |
| 98 | 123 |
| 99 } // namespace chromeos | 124 } // namespace chromeos |
| OLD | NEW |