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> |
11 | 11 |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "chrome/browser/extensions/extension_host.h" | 14 #include "chrome/browser/extensions/extension_host.h" |
15 #include "chrome/browser/extensions/extension_process_manager.h" | 15 #include "chrome/browser/extensions/extension_process_manager.h" |
16 #include "chrome/browser/notifications/balloon.h" | 16 #include "chrome/browser/notifications/balloon.h" |
17 #include "chrome/browser/notifications/desktop_notification_service.h" | 17 #include "chrome/browser/notifications/desktop_notification_service.h" |
18 #include "chrome/browser/notifications/notification.h" | 18 #include "chrome/browser/notifications/notification.h" |
19 #include "chrome/browser/notifications/notification_options_menu_model.h" | 19 #include "chrome/browser/notifications/notification_options_menu_model.h" |
20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/browser/themes/theme_service.h" | 21 #include "chrome/browser/themes/theme_service.h" |
22 #include "chrome/browser/ui/browser_list.h" | 22 #include "chrome/browser/ui/browser_list.h" |
23 #include "chrome/browser/ui/browser_window.h" | 23 #include "chrome/browser/ui/browser_window.h" |
24 #include "chrome/browser/ui/gtk/custom_button.h" | 24 #include "chrome/browser/ui/gtk/custom_button.h" |
25 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 25 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
26 #include "chrome/browser/ui/gtk/gtk_util.h" | 26 #include "chrome/browser/ui/gtk/gtk_util.h" |
27 #include "chrome/browser/ui/gtk/menu_gtk.h" | 27 #include "chrome/browser/ui/gtk/menu_gtk.h" |
28 #include "chrome/browser/ui/gtk/notifications/balloon_view_host_gtk.h" | 28 #include "chrome/browser/ui/gtk/notifications/balloon_view_host_gtk.h" |
29 #include "chrome/browser/ui/gtk/rounded_window.h" | 29 #include "chrome/browser/ui/gtk/rounded_window.h" |
| 30 #include "chrome/common/chrome_notification_types.h" |
30 #include "chrome/common/extensions/extension.h" | 31 #include "chrome/common/extensions/extension.h" |
31 #include "content/browser/renderer_host/render_view_host.h" | 32 #include "content/browser/renderer_host/render_view_host.h" |
32 #include "content/browser/renderer_host/render_widget_host_view.h" | 33 #include "content/browser/renderer_host/render_widget_host_view.h" |
33 #include "content/common/notification_details.h" | 34 #include "content/common/notification_details.h" |
34 #include "content/common/notification_service.h" | 35 #include "content/common/notification_service.h" |
35 #include "content/common/notification_source.h" | 36 #include "content/common/notification_source.h" |
36 #include "content/common/notification_type.h" | |
37 #include "grit/generated_resources.h" | 37 #include "grit/generated_resources.h" |
38 #include "grit/theme_resources.h" | 38 #include "grit/theme_resources.h" |
39 #include "grit/theme_resources_standard.h" | 39 #include "grit/theme_resources_standard.h" |
40 #include "ui/base/animation/slide_animation.h" | 40 #include "ui/base/animation/slide_animation.h" |
41 #include "ui/base/l10n/l10n_util.h" | 41 #include "ui/base/l10n/l10n_util.h" |
42 #include "ui/base/resource/resource_bundle.h" | 42 #include "ui/base/resource/resource_bundle.h" |
43 #include "ui/gfx/canvas.h" | 43 #include "ui/gfx/canvas.h" |
44 #include "ui/gfx/insets.h" | 44 #include "ui/gfx/insets.h" |
45 #include "ui/gfx/native_widget_types.h" | 45 #include "ui/gfx/native_widget_types.h" |
46 | 46 |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 G_CALLBACK(OnOptionsMenuButtonThunk), this); | 306 G_CALLBACK(OnOptionsMenuButtonThunk), this); |
307 GTK_WIDGET_UNSET_FLAGS(options_menu_button_->widget(), GTK_CAN_FOCUS); | 307 GTK_WIDGET_UNSET_FLAGS(options_menu_button_->widget(), GTK_CAN_FOCUS); |
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::NOTIFICATION_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 22 matching lines...) Expand all Loading... |
373 return gfx::Rect(); | 373 return gfx::Rect(); |
374 | 374 |
375 gfx::Size content_size = balloon_->content_size(); | 375 gfx::Size content_size = balloon_->content_size(); |
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(int 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::NOTIFICATION_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 |