Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: chrome/browser/gtk/infobar_gtk.cc

Issue 507022: Fix issue 11258: Linux: gracefully handle small browser window... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/gtk/infobar_gtk.h" 5 #include "chrome/browser/gtk/infobar_gtk.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include "app/gfx/gtk_util.h" 9 #include "app/gfx/gtk_util.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 } 181 }
182 182
183 // AlertInfoBar ---------------------------------------------------------------- 183 // AlertInfoBar ----------------------------------------------------------------
184 184
185 class AlertInfoBar : public InfoBar { 185 class AlertInfoBar : public InfoBar {
186 public: 186 public:
187 explicit AlertInfoBar(AlertInfoBarDelegate* delegate) 187 explicit AlertInfoBar(AlertInfoBarDelegate* delegate)
188 : InfoBar(delegate) { 188 : InfoBar(delegate) {
189 std::wstring text = delegate->GetMessageText(); 189 std::wstring text = delegate->GetMessageText();
190 GtkWidget* label = gtk_label_new(WideToUTF8(text).c_str()); 190 GtkWidget* label = gtk_label_new(WideToUTF8(text).c_str());
191 // We want the label to be horizontally shrinkable, so that the Chrome
192 // window can be resized freely even with a very long message.
193 gtk_widget_set_size_request(label, 0, -1);
194 gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_END);
195 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
191 gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &gfx::kGdkBlack); 196 gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &gfx::kGdkBlack);
192 gtk_box_pack_start(GTK_BOX(hbox_), label, FALSE, FALSE, 0); 197 gtk_box_pack_start(GTK_BOX(hbox_), label, TRUE, TRUE, 0);
193 198
194 gtk_widget_show_all(border_bin_.get()); 199 gtk_widget_show_all(border_bin_.get());
195 } 200 }
196 }; 201 };
197 202
198 // LinkInfoBar ----------------------------------------------------------------- 203 // LinkInfoBar -----------------------------------------------------------------
199 204
200 class LinkInfoBar : public InfoBar { 205 class LinkInfoBar : public InfoBar {
201 public: 206 public:
202 explicit LinkInfoBar(LinkInfoBarDelegate* delegate) 207 explicit LinkInfoBar(LinkInfoBarDelegate* delegate)
203 : InfoBar(delegate) { 208 : InfoBar(delegate) {
204 size_t link_offset; 209 size_t link_offset;
205 std::wstring display_text = 210 std::wstring display_text =
206 delegate->GetMessageTextWithOffset(&link_offset); 211 delegate->GetMessageTextWithOffset(&link_offset);
207 std::wstring link_text = delegate->GetLinkText(); 212 std::wstring link_text = delegate->GetLinkText();
208 213
209 // Create the link button. 214 // Create the link button.
210 GtkWidget* link_button = 215 GtkWidget* link_button =
211 gtk_chrome_link_button_new(WideToUTF8(link_text).c_str()); 216 gtk_chrome_link_button_new(WideToUTF8(link_text).c_str());
212 gtk_chrome_link_button_set_use_gtk_theme( 217 gtk_chrome_link_button_set_use_gtk_theme(
213 GTK_CHROME_LINK_BUTTON(link_button), FALSE); 218 GTK_CHROME_LINK_BUTTON(link_button), FALSE);
214 g_signal_connect(link_button, "clicked", 219 g_signal_connect(link_button, "clicked",
215 G_CALLBACK(OnLinkClick), this); 220 G_CALLBACK(OnLinkClick), this);
216 gtk_util::SetButtonTriggersNavigation(link_button); 221 gtk_util::SetButtonTriggersNavigation(link_button);
217 222
223 GtkWidget* hbox = gtk_hbox_new(FALSE, 0);
224 // We want the link to be horizontally shrinkable, so that the Chrome
225 // window can be resized freely even with a very long link.
226 gtk_widget_set_size_request(hbox, 0, -1);
227 gtk_box_pack_start(GTK_BOX(hbox_), hbox, TRUE, TRUE, 0);
218 // If link_offset is npos, we right-align the link instead of embedding it 228 // If link_offset is npos, we right-align the link instead of embedding it
219 // in the text. 229 // in the text.
220 if (link_offset == std::wstring::npos) { 230 if (link_offset == std::wstring::npos) {
221 gtk_box_pack_end(GTK_BOX(hbox_), link_button, FALSE, FALSE, 0); 231 gtk_box_pack_end(GTK_BOX(hbox), link_button, FALSE, FALSE, 0);
222 GtkWidget* label = gtk_label_new(WideToUTF8(display_text).c_str()); 232 GtkWidget* label = gtk_label_new(WideToUTF8(display_text).c_str());
233 // In order to avoid the link_button and the label overlapping with each
234 // other, we make the label shrinkable.
235 gtk_widget_set_size_request(label, 0, -1);
236 gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_END);
237 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
223 gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &gfx::kGdkBlack); 238 gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &gfx::kGdkBlack);
224 gtk_box_pack_start(GTK_BOX(hbox_), label, FALSE, FALSE, 0); 239 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
225 } else { 240 } else {
226 GtkWidget* initial_label = gtk_label_new( 241 GtkWidget* initial_label = gtk_label_new(
227 WideToUTF8(display_text.substr(0, link_offset)).c_str()); 242 WideToUTF8(display_text.substr(0, link_offset)).c_str());
228 GtkWidget* trailing_label = gtk_label_new( 243 GtkWidget* trailing_label = gtk_label_new(
229 WideToUTF8(display_text.substr(link_offset)).c_str()); 244 WideToUTF8(display_text.substr(link_offset)).c_str());
230 245
231 gtk_widget_modify_fg(initial_label, GTK_STATE_NORMAL, &gfx::kGdkBlack); 246 gtk_widget_modify_fg(initial_label, GTK_STATE_NORMAL, &gfx::kGdkBlack);
232 gtk_widget_modify_fg(trailing_label, GTK_STATE_NORMAL, &gfx::kGdkBlack); 247 gtk_widget_modify_fg(trailing_label, GTK_STATE_NORMAL, &gfx::kGdkBlack);
233 248
234 // We don't want any spacing between the elements, so we pack them into 249 // We don't want any spacing between the elements, so we pack them into
235 // this hbox that doesn't use kElementPadding. 250 // this hbox that doesn't use kElementPadding.
236 GtkWidget* hbox = gtk_hbox_new(FALSE, 0);
237 gtk_box_pack_start(GTK_BOX(hbox), initial_label, FALSE, FALSE, 0); 251 gtk_box_pack_start(GTK_BOX(hbox), initial_label, FALSE, FALSE, 0);
238 gtk_util::CenterWidgetInHBox(hbox, link_button, false, 0); 252 gtk_util::CenterWidgetInHBox(hbox, link_button, false, 0);
239 gtk_box_pack_start(GTK_BOX(hbox), trailing_label, FALSE, FALSE, 0); 253 gtk_box_pack_start(GTK_BOX(hbox), trailing_label, FALSE, FALSE, 0);
240 gtk_box_pack_start(GTK_BOX(hbox_), hbox, FALSE, FALSE, 0);
241 } 254 }
242 255
243 gtk_widget_show_all(border_bin_.get()); 256 gtk_widget_show_all(border_bin_.get());
244 } 257 }
245 258
246 private: 259 private:
247 static void OnLinkClick(GtkWidget* button, LinkInfoBar* link_info_bar) { 260 static void OnLinkClick(GtkWidget* button, LinkInfoBar* link_info_bar) {
248 const GdkEventButton* button_click_event = 261 const GdkEventButton* button_click_event =
249 reinterpret_cast<GdkEventButton*>(gtk_get_current_event()); 262 reinterpret_cast<GdkEventButton*>(gtk_get_current_event());
250 WindowOpenDisposition disposition = CURRENT_TAB; 263 WindowOpenDisposition disposition = CURRENT_TAB;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 321
309 InfoBar* LinkInfoBarDelegate::CreateInfoBar() { 322 InfoBar* LinkInfoBarDelegate::CreateInfoBar() {
310 return new LinkInfoBar(this); 323 return new LinkInfoBar(this);
311 } 324 }
312 325
313 // ConfirmInfoBarDelegate, InfoBarDelegate overrides: -------------------------- 326 // ConfirmInfoBarDelegate, InfoBarDelegate overrides: --------------------------
314 327
315 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() { 328 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() {
316 return new ConfirmInfoBar(this); 329 return new ConfirmInfoBar(this);
317 } 330 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/gtk_expanded_container_unittest.cc ('k') | chrome/browser/gtk/slide_animator_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698