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 "ash/system/tray/system_tray_bubble.h" | 5 #include "ash/system/tray/system_tray_bubble.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/shell_window_ids.h" | 8 #include "ash/shell_window_ids.h" |
9 #include "ash/system/tray/system_tray.h" | 9 #include "ash/system/tray/system_tray.h" |
10 #include "ash/system/tray/system_tray_delegate.h" | 10 #include "ash/system/tray/system_tray_delegate.h" |
11 #include "ash/system/tray/system_tray_item.h" | 11 #include "ash/system/tray/system_tray_item.h" |
12 #include "ash/system/tray/tray_constants.h" | 12 #include "ash/system/tray/tray_constants.h" |
13 #include "ash/wm/shelf_layout_manager.h" | 13 #include "ash/wm/shelf_layout_manager.h" |
14 #include "ash/wm/window_animations.h" | 14 #include "ash/wm/window_animations.h" |
| 15 #include "base/message_loop.h" |
15 #include "grit/ash_strings.h" | 16 #include "grit/ash_strings.h" |
16 #include "third_party/skia/include/core/SkCanvas.h" | 17 #include "third_party/skia/include/core/SkCanvas.h" |
17 #include "third_party/skia/include/core/SkColor.h" | 18 #include "third_party/skia/include/core/SkColor.h" |
18 #include "third_party/skia/include/core/SkPaint.h" | 19 #include "third_party/skia/include/core/SkPaint.h" |
19 #include "third_party/skia/include/core/SkPath.h" | 20 #include "third_party/skia/include/core/SkPath.h" |
20 #include "third_party/skia/include/effects/SkBlurImageFilter.h" | 21 #include "third_party/skia/include/effects/SkBlurImageFilter.h" |
21 #include "ui/base/accessibility/accessible_view_state.h" | 22 #include "ui/base/accessibility/accessible_view_state.h" |
22 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
23 #include "ui/compositor/layer.h" | 24 #include "ui/compositor/layer.h" |
24 #include "ui/gfx/canvas.h" | 25 #include "ui/gfx/canvas.h" |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 : tray_(tray), | 350 : tray_(tray), |
350 bubble_view_(NULL), | 351 bubble_view_(NULL), |
351 bubble_widget_(NULL), | 352 bubble_widget_(NULL), |
352 items_(items), | 353 items_(items), |
353 bubble_type_(bubble_type), | 354 bubble_type_(bubble_type), |
354 anchor_type_(ANCHOR_TYPE_TRAY), | 355 anchor_type_(ANCHOR_TYPE_TRAY), |
355 autoclose_delay_(0) { | 356 autoclose_delay_(0) { |
356 } | 357 } |
357 | 358 |
358 SystemTrayBubble::~SystemTrayBubble() { | 359 SystemTrayBubble::~SystemTrayBubble() { |
| 360 // The bubble may be closing without having been hidden first. So it may still |
| 361 // be in the message-loop's observer list. |
| 362 MessageLoopForUI::current()->RemoveObserver(this); |
| 363 |
359 DestroyItemViews(); | 364 DestroyItemViews(); |
360 // Reset the host pointer in bubble_view_ in case its destruction is deferred. | 365 // Reset the host pointer in bubble_view_ in case its destruction is deferred. |
361 if (bubble_view_) | 366 if (bubble_view_) |
362 bubble_view_->reset_host(); | 367 bubble_view_->reset_host(); |
363 if (bubble_widget_) { | 368 if (bubble_widget_) { |
364 bubble_widget_->RemoveObserver(this); | 369 bubble_widget_->RemoveObserver(this); |
365 // This triggers the destruction of bubble_view_. | 370 // This triggers the destruction of bubble_view_. |
366 bubble_widget_->Close(); | 371 bubble_widget_->Close(); |
367 } | 372 } |
368 } | 373 } |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 break; | 507 break; |
503 case BUBBLE_TYPE_NOTIFICATION: | 508 case BUBBLE_TYPE_NOTIFICATION: |
504 view = (*it)->CreateNotificationView(login_status); | 509 view = (*it)->CreateNotificationView(login_status); |
505 break; | 510 break; |
506 } | 511 } |
507 if (view) | 512 if (view) |
508 bubble_view_->AddChildView(new TrayPopupItemContainer(view)); | 513 bubble_view_->AddChildView(new TrayPopupItemContainer(view)); |
509 } | 514 } |
510 } | 515 } |
511 | 516 |
| 517 base::EventStatus SystemTrayBubble::WillProcessEvent( |
| 518 const base::NativeEvent& event) { |
| 519 // Check if the user clicked outside of the bubble and close it if they did. |
| 520 if (bubble_type_ != BUBBLE_TYPE_NOTIFICATION && |
| 521 ui::EventTypeFromNative(event) == ui::ET_MOUSE_PRESSED) { |
| 522 gfx::Point cursor_in_view = ui::EventLocationFromNative(event); |
| 523 views::View::ConvertPointFromScreen(bubble_view_, &cursor_in_view); |
| 524 if (!bubble_view_->HitTest(cursor_in_view)) { |
| 525 bubble_widget_->Close(); |
| 526 } |
| 527 } |
| 528 return base::EVENT_CONTINUE; |
| 529 } |
| 530 |
| 531 void SystemTrayBubble::DidProcessEvent(const base::NativeEvent& event) { |
| 532 } |
| 533 |
512 void SystemTrayBubble::OnWidgetClosing(views::Widget* widget) { | 534 void SystemTrayBubble::OnWidgetClosing(views::Widget* widget) { |
513 CHECK_EQ(bubble_widget_, widget); | 535 CHECK_EQ(bubble_widget_, widget); |
| 536 MessageLoopForUI::current()->RemoveObserver(this); |
514 bubble_widget_ = NULL; | 537 bubble_widget_ = NULL; |
515 tray_->RemoveBubble(this); | 538 tray_->RemoveBubble(this); |
516 } | 539 } |
517 | 540 |
| 541 void SystemTrayBubble::OnWidgetVisibilityChanged(views::Widget* widget, |
| 542 bool visible) { |
| 543 if (!visible) |
| 544 MessageLoopForUI::current()->RemoveObserver(this); |
| 545 else |
| 546 MessageLoopForUI::current()->AddObserver(this); |
| 547 } |
| 548 |
518 } // namespace internal | 549 } // namespace internal |
519 } // namespace ash | 550 } // namespace ash |
OLD | NEW |