| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/notifications/balloon_view_gtk.h" | 5 #include "chrome/browser/ui/gtk/notifications/balloon_view_gtk.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 G_CALLBACK(OnOptionsMenuButtonThunk), this); | 306 G_CALLBACK(OnOptionsMenuButtonThunk), this); |
| 307 gtk_widget_set_can_focus(options_menu_button_->widget(), FALSE); | 307 gtk_widget_set_can_focus(options_menu_button_->widget(), FALSE); |
| 308 GtkWidget* options_alignment = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); | 308 GtkWidget* options_alignment = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); |
| 309 gtk_alignment_set_padding(GTK_ALIGNMENT(options_alignment), | 309 gtk_alignment_set_padding(GTK_ALIGNMENT(options_alignment), |
| 310 kShelfVerticalMargin, kShelfVerticalMargin, | 310 kShelfVerticalMargin, kShelfVerticalMargin, |
| 311 0, kButtonSpacing); | 311 0, kButtonSpacing); |
| 312 gtk_container_add(GTK_CONTAINER(options_alignment), | 312 gtk_container_add(GTK_CONTAINER(options_alignment), |
| 313 options_menu_button_->widget()); | 313 options_menu_button_->widget()); |
| 314 gtk_box_pack_end(GTK_BOX(hbox_), options_alignment, FALSE, FALSE, 0); | 314 gtk_box_pack_end(GTK_BOX(hbox_), options_alignment, FALSE, FALSE, 0); |
| 315 | 315 |
| 316 notification_registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, | 316 notification_registrar_.Add(this, chrome::BROWSER_THEME_CHANGED, |
| 317 Source<ThemeService>(theme_service_)); | 317 Source<ThemeService>(theme_service_)); |
| 318 | 318 |
| 319 // We don't do InitThemesFor() because it just forces a redraw. | 319 // We don't do InitThemesFor() because it just forces a redraw. |
| 320 gtk_util::ActAsRoundedWindow(frame_container_, gtk_util::kGdkBlack, 3, | 320 gtk_util::ActAsRoundedWindow(frame_container_, gtk_util::kGdkBlack, 3, |
| 321 gtk_util::ROUNDED_ALL, | 321 gtk_util::ROUNDED_ALL, |
| 322 gtk_util::BORDER_ALL); | 322 gtk_util::BORDER_ALL); |
| 323 | 323 |
| 324 // Realize the frame container so we can do size calculations. | 324 // Realize the frame container so we can do size calculations. |
| 325 gtk_widget_realize(frame_container_); | 325 gtk_widget_realize(frame_container_); |
| 326 | 326 |
| 327 // Update to make sure we have everything sized properly and then move our | 327 // Update to make sure we have everything sized properly and then move our |
| 328 // window offscreen for its initial animation. | 328 // window offscreen for its initial animation. |
| 329 html_contents_->UpdateActualSize(balloon_->content_size()); | 329 html_contents_->UpdateActualSize(balloon_->content_size()); |
| 330 int window_width; | 330 int window_width; |
| 331 gtk_window_get_size(GTK_WINDOW(frame_container_), &window_width, NULL); | 331 gtk_window_get_size(GTK_WINDOW(frame_container_), &window_width, NULL); |
| 332 | 332 |
| 333 int pos_x = gdk_screen_width() - window_width - kScreenBorder; | 333 int pos_x = gdk_screen_width() - window_width - kScreenBorder; |
| 334 int pos_y = gdk_screen_height(); | 334 int pos_y = gdk_screen_height(); |
| 335 gtk_window_move(GTK_WINDOW(frame_container_), pos_x, pos_y); | 335 gtk_window_move(GTK_WINDOW(frame_container_), pos_x, pos_y); |
| 336 balloon_->SetPosition(gfx::Point(pos_x, pos_y), false); | 336 balloon_->SetPosition(gfx::Point(pos_x, pos_y), false); |
| 337 gtk_widget_show_all(frame_container_); | 337 gtk_widget_show_all(frame_container_); |
| 338 | 338 |
| 339 notification_registrar_.Add(this, | 339 notification_registrar_.Add(this, |
| 340 NotificationType::NOTIFY_BALLOON_DISCONNECTED, Source<Balloon>(balloon)); | 340 chrome::NOTIFY_BALLOON_DISCONNECTED, Source<Balloon>(balloon)); |
| 341 } | 341 } |
| 342 | 342 |
| 343 void BalloonViewImpl::Update() { | 343 void BalloonViewImpl::Update() { |
| 344 DCHECK(html_contents_.get()) << "BalloonView::Update called before Show"; | 344 DCHECK(html_contents_.get()) << "BalloonView::Update called before Show"; |
| 345 if (html_contents_->render_view_host()) | 345 if (html_contents_->render_view_host()) |
| 346 html_contents_->render_view_host()->NavigateToURL( | 346 html_contents_->render_view_host()->NavigateToURL( |
| 347 balloon_->notification().content_url()); | 347 balloon_->notification().content_url()); |
| 348 } | 348 } |
| 349 | 349 |
| 350 gfx::Point BalloonViewImpl::GetContentsOffset() const { | 350 gfx::Point BalloonViewImpl::GetContentsOffset() const { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 376 gfx::Point offset = GetContentsOffset(); | 376 gfx::Point offset = GetContentsOffset(); |
| 377 int x = 0, y = 0; | 377 int x = 0, y = 0; |
| 378 gtk_window_get_position(GTK_WINDOW(frame_container_), &x, &y); | 378 gtk_window_get_position(GTK_WINDOW(frame_container_), &x, &y); |
| 379 return gfx::Rect(x + offset.x(), y + offset.y(), | 379 return gfx::Rect(x + offset.x(), y + offset.y(), |
| 380 content_size.width(), content_size.height()); | 380 content_size.width(), content_size.height()); |
| 381 } | 381 } |
| 382 | 382 |
| 383 void BalloonViewImpl::Observe(NotificationType type, | 383 void BalloonViewImpl::Observe(NotificationType type, |
| 384 const NotificationSource& source, | 384 const NotificationSource& source, |
| 385 const NotificationDetails& details) { | 385 const NotificationDetails& details) { |
| 386 if (type == NotificationType::NOTIFY_BALLOON_DISCONNECTED) { | 386 if (type == chrome::NOTIFY_BALLOON_DISCONNECTED) { |
| 387 // If the renderer process attached to this balloon is disconnected | 387 // If the renderer process attached to this balloon is disconnected |
| 388 // (e.g., because of a crash), we want to close the balloon. | 388 // (e.g., because of a crash), we want to close the balloon. |
| 389 notification_registrar_.Remove(this, | 389 notification_registrar_.Remove(this, |
| 390 NotificationType::NOTIFY_BALLOON_DISCONNECTED, | 390 chrome::NOTIFY_BALLOON_DISCONNECTED, |
| 391 Source<Balloon>(balloon_)); | 391 Source<Balloon>(balloon_)); |
| 392 Close(false); | 392 Close(false); |
| 393 } else if (type == NotificationType::BROWSER_THEME_CHANGED) { | 393 } else if (type == chrome::BROWSER_THEME_CHANGED) { |
| 394 // Since all the buttons change their own properties, and our expose does | 394 // Since all the buttons change their own properties, and our expose does |
| 395 // all the real differences, we'll need a redraw. | 395 // all the real differences, we'll need a redraw. |
| 396 gtk_widget_queue_draw(frame_container_); | 396 gtk_widget_queue_draw(frame_container_); |
| 397 } else { | 397 } else { |
| 398 NOTREACHED(); | 398 NOTREACHED(); |
| 399 } | 399 } |
| 400 } | 400 } |
| 401 | 401 |
| 402 void BalloonViewImpl::OnCloseButton(GtkWidget* widget) { | 402 void BalloonViewImpl::OnCloseButton(GtkWidget* widget) { |
| 403 Close(true); | 403 Close(true); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 method_factory_.NewRunnableMethod( | 471 method_factory_.NewRunnableMethod( |
| 472 &BalloonViewImpl::DelayedClose, false)); | 472 &BalloonViewImpl::DelayedClose, false)); |
| 473 } | 473 } |
| 474 } | 474 } |
| 475 | 475 |
| 476 gboolean BalloonViewImpl::OnDestroy(GtkWidget* widget) { | 476 gboolean BalloonViewImpl::OnDestroy(GtkWidget* widget) { |
| 477 frame_container_ = NULL; | 477 frame_container_ = NULL; |
| 478 Close(false); | 478 Close(false); |
| 479 return FALSE; // Propagate. | 479 return FALSE; // Propagate. |
| 480 } | 480 } |
| OLD | NEW |