| 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 // Draws the view for the balloons. | 5 // Draws the view for the balloons. |
| 6 | 6 |
| 7 #include "chrome/browser/chromeos/notifications/notification_panel.h" | 7 #include "chrome/browser/chromeos/notifications/notification_panel.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| 11 #include "base/bind.h" |
| 11 #include "chrome/browser/chromeos/notifications/balloon_collection_impl.h" | 12 #include "chrome/browser/chromeos/notifications/balloon_collection_impl.h" |
| 12 #include "chrome/browser/chromeos/notifications/balloon_view.h" | 13 #include "chrome/browser/chromeos/notifications/balloon_view.h" |
| 13 #include "chrome/common/chrome_notification_types.h" | 14 #include "chrome/common/chrome_notification_types.h" |
| 14 #include "content/public/browser/notification_details.h" | 15 #include "content/public/browser/notification_details.h" |
| 15 #include "content/public/browser/notification_source.h" | 16 #include "content/public/browser/notification_source.h" |
| 16 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
| 17 #include "third_party/cros_system_api/window_manager/chromeos_wm_ipc_enums.h" | 18 #include "third_party/cros_system_api/window_manager/chromeos_wm_ipc_enums.h" |
| 18 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 19 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
| 20 #include "ui/gfx/canvas.h" | 21 #include "ui/gfx/canvas.h" |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 gfx::Size preferred_size_; | 415 gfx::Size preferred_size_; |
| 415 | 416 |
| 416 DISALLOW_COPY_AND_ASSIGN(BalloonContainer); | 417 DISALLOW_COPY_AND_ASSIGN(BalloonContainer); |
| 417 }; | 418 }; |
| 418 | 419 |
| 419 NotificationPanel::NotificationPanel() | 420 NotificationPanel::NotificationPanel() |
| 420 : balloon_container_(NULL), | 421 : balloon_container_(NULL), |
| 421 panel_widget_(NULL), | 422 panel_widget_(NULL), |
| 422 container_host_(NULL), | 423 container_host_(NULL), |
| 423 state_(CLOSED), | 424 state_(CLOSED), |
| 424 task_factory_(this), | |
| 425 min_bounds_(0, 0, kBalloonMinWidth, kBalloonMinHeight), | 425 min_bounds_(0, 0, kBalloonMinWidth, kBalloonMinHeight), |
| 426 stale_timeout_(1000 * kStaleTimeoutInSeconds), | 426 stale_timeout_(1000 * kStaleTimeoutInSeconds), |
| 427 active_(NULL), | 427 active_(NULL), |
| 428 scroll_to_(NULL) { | 428 scroll_to_(NULL) { |
| 429 Init(); | 429 Init(); |
| 430 } | 430 } |
| 431 | 431 |
| 432 NotificationPanel::~NotificationPanel() { | 432 NotificationPanel::~NotificationPanel() { |
| 433 Hide(); | 433 Hide(); |
| 434 } | 434 } |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 // Adjust the width to avoid showing a horizontal scroll bar. | 805 // Adjust the width to avoid showing a horizontal scroll bar. |
| 806 if (new_height != pref_size.height()) | 806 if (new_height != pref_size.height()) |
| 807 new_width += scroll_view_->GetScrollBarWidth(); | 807 new_width += scroll_view_->GetScrollBarWidth(); |
| 808 return gfx::Rect(0, 0, new_width, new_height).Union(min_bounds_); | 808 return gfx::Rect(0, 0, new_width, new_height).Union(min_bounds_); |
| 809 } | 809 } |
| 810 | 810 |
| 811 void NotificationPanel::StartStaleTimer(Balloon* balloon) { | 811 void NotificationPanel::StartStaleTimer(Balloon* balloon) { |
| 812 BalloonViewImpl* view = GetBalloonViewOf(balloon); | 812 BalloonViewImpl* view = GetBalloonViewOf(balloon); |
| 813 MessageLoop::current()->PostDelayedTask( | 813 MessageLoop::current()->PostDelayedTask( |
| 814 FROM_HERE, | 814 FROM_HERE, |
| 815 task_factory_.NewRunnableMethod( | 815 base::Bind(&NotificationPanel::OnStale, AsWeakPtr(), view), |
| 816 &NotificationPanel::OnStale, view), | |
| 817 stale_timeout_); | 816 stale_timeout_); |
| 818 } | 817 } |
| 819 | 818 |
| 820 void NotificationPanel::OnStale(BalloonViewImpl* view) { | 819 void NotificationPanel::OnStale(BalloonViewImpl* view) { |
| 821 // Note: |view| may point to deleted memory. | 820 // Note: |view| may point to deleted memory. |
| 822 if (balloon_container_->HasBalloonView(view) && !view->stale()) { | 821 if (balloon_container_->HasBalloonView(view) && !view->stale()) { |
| 823 view->set_stale(); | 822 view->set_stale(); |
| 824 // don't update panel on stale | 823 // don't update panel on stale |
| 825 if (state_ == KEEP_SIZE) | 824 if (state_ == KEEP_SIZE) |
| 826 return; | 825 return; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 889 &origin); | 888 &origin); |
| 890 return rect.Contains(gfx::Rect(origin, view->size())); | 889 return rect.Contains(gfx::Rect(origin, view->size())); |
| 891 } | 890 } |
| 892 | 891 |
| 893 | 892 |
| 894 bool NotificationPanelTester::IsActive(const BalloonViewImpl* view) const { | 893 bool NotificationPanelTester::IsActive(const BalloonViewImpl* view) const { |
| 895 return panel_->active_ == view; | 894 return panel_->active_ == view; |
| 896 } | 895 } |
| 897 | 896 |
| 898 } // namespace chromeos | 897 } // namespace chromeos |
| OLD | NEW |