OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/gtk/global_error_bubble.h" | 5 #include "chrome/browser/ui/gtk/global_error_bubble.h" |
6 | 6 |
7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
8 | 8 |
9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 } // namespace | 31 } // namespace |
32 | 32 |
33 GlobalErrorBubble::GlobalErrorBubble(Browser* browser, | 33 GlobalErrorBubble::GlobalErrorBubble(Browser* browser, |
34 const base::WeakPtr<GlobalError>& error, | 34 const base::WeakPtr<GlobalError>& error, |
35 GtkWidget* anchor) | 35 GtkWidget* anchor) |
36 : browser_(browser), | 36 : browser_(browser), |
37 bubble_(NULL), | 37 bubble_(NULL), |
38 error_(error), | 38 error_(error), |
39 message_width_(kMinMessageLabelWidth) { | 39 message_width_(kMinMessageLabelWidth) { |
40 DCHECK(browser_); | 40 DCHECK(browser_); |
41 DCHECK(error_); | 41 DCHECK(error_.get()); |
42 GtkWidget* content = gtk_vbox_new(FALSE, ui::kControlSpacing); | 42 GtkWidget* content = gtk_vbox_new(FALSE, ui::kControlSpacing); |
43 gtk_container_set_border_width(GTK_CONTAINER(content), | 43 gtk_container_set_border_width(GTK_CONTAINER(content), |
44 ui::kContentAreaBorder); | 44 ui::kContentAreaBorder); |
45 g_signal_connect(content, "destroy", G_CALLBACK(OnDestroyThunk), this); | 45 g_signal_connect(content, "destroy", G_CALLBACK(OnDestroyThunk), this); |
46 | 46 |
47 GtkThemeService* theme_service = | 47 GtkThemeService* theme_service = |
48 GtkThemeService::GetFrom(browser_->profile()); | 48 GtkThemeService::GetFrom(browser_->profile()); |
49 | 49 |
50 gfx::Image image = error_->GetBubbleViewIcon(); | 50 gfx::Image image = error_->GetBubbleViewIcon(); |
51 CHECK(!image.IsEmpty()); | 51 CHECK(!image.IsEmpty()); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 BubbleGtk::GRAB_INPUT, | 115 BubbleGtk::GRAB_INPUT, |
116 theme_service, | 116 theme_service, |
117 this); // error_ | 117 this); // error_ |
118 } | 118 } |
119 | 119 |
120 GlobalErrorBubble::~GlobalErrorBubble() { | 120 GlobalErrorBubble::~GlobalErrorBubble() { |
121 } | 121 } |
122 | 122 |
123 void GlobalErrorBubble::BubbleClosing(BubbleGtk* bubble, | 123 void GlobalErrorBubble::BubbleClosing(BubbleGtk* bubble, |
124 bool closed_by_escape) { | 124 bool closed_by_escape) { |
125 if (error_) | 125 if (error_.get()) |
126 error_->BubbleViewDidClose(browser_); | 126 error_->BubbleViewDidClose(browser_); |
127 } | 127 } |
128 | 128 |
129 void GlobalErrorBubble::OnDestroy(GtkWidget* sender) { | 129 void GlobalErrorBubble::OnDestroy(GtkWidget* sender) { |
130 delete this; | 130 delete this; |
131 } | 131 } |
132 | 132 |
133 void GlobalErrorBubble::OnAcceptButton(GtkWidget* sender) { | 133 void GlobalErrorBubble::OnAcceptButton(GtkWidget* sender) { |
134 if (error_) | 134 if (error_.get()) |
135 error_->BubbleViewAcceptButtonPressed(browser_); | 135 error_->BubbleViewAcceptButtonPressed(browser_); |
136 bubble_->Close(); | 136 bubble_->Close(); |
137 } | 137 } |
138 | 138 |
139 void GlobalErrorBubble::OnCancelButton(GtkWidget* sender) { | 139 void GlobalErrorBubble::OnCancelButton(GtkWidget* sender) { |
140 if (error_) | 140 if (error_.get()) |
141 error_->BubbleViewCancelButtonPressed(browser_); | 141 error_->BubbleViewCancelButtonPressed(browser_); |
142 bubble_->Close(); | 142 bubble_->Close(); |
143 } | 143 } |
144 | 144 |
145 void GlobalErrorBubble::OnRealize(GtkWidget* sender) { | 145 void GlobalErrorBubble::OnRealize(GtkWidget* sender) { |
146 int width = gtk_util::GetWidgetSize(sender).width(); | 146 int width = gtk_util::GetWidgetSize(sender).width(); |
147 message_width_ = std::max(message_width_, width); | 147 message_width_ = std::max(message_width_, width); |
148 for (size_t i = 0; i < message_labels_.size(); ++i) | 148 for (size_t i = 0; i < message_labels_.size(); ++i) |
149 gtk_util::SetLabelWidth(message_labels_[i], message_width_); | 149 gtk_util::SetLabelWidth(message_labels_[i], message_width_); |
150 } | 150 } |
151 | 151 |
152 void GlobalErrorBubble::CloseBubbleView() { | 152 void GlobalErrorBubble::CloseBubbleView() { |
153 bubble_->Close(); | 153 bubble_->Close(); |
154 } | 154 } |
155 | 155 |
156 GlobalErrorBubbleViewBase* GlobalErrorBubbleViewBase::ShowBubbleView( | 156 GlobalErrorBubbleViewBase* GlobalErrorBubbleViewBase::ShowBubbleView( |
157 Browser* browser, | 157 Browser* browser, |
158 const base::WeakPtr<GlobalError>& error) { | 158 const base::WeakPtr<GlobalError>& error) { |
159 BrowserWindowGtk* browser_window = | 159 BrowserWindowGtk* browser_window = |
160 BrowserWindowGtk::GetBrowserWindowForNativeWindow( | 160 BrowserWindowGtk::GetBrowserWindowForNativeWindow( |
161 browser->window()->GetNativeWindow()); | 161 browser->window()->GetNativeWindow()); |
162 GtkWidget* anchor = browser_window->GetToolbar()->GetAppMenuButton(); | 162 GtkWidget* anchor = browser_window->GetToolbar()->GetAppMenuButton(); |
163 | 163 |
164 // The bubble will be automatically deleted when it's closed. | 164 // The bubble will be automatically deleted when it's closed. |
165 return new GlobalErrorBubble(browser, error, anchor); | 165 return new GlobalErrorBubble(browser, error, anchor); |
166 } | 166 } |
OLD | NEW |