| 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 "chrome/browser/ui/views/notifications/balloon_view_views.h" | 5 #include "chrome/browser/ui/views/notifications/balloon_view_views.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/browser/notifications/balloon_collection.h" | 14 #include "chrome/browser/notifications/balloon_collection.h" |
| 15 #include "chrome/browser/notifications/desktop_notification_service.h" | 15 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 16 #include "chrome/browser/notifications/notification.h" | 16 #include "chrome/browser/notifications/notification.h" |
| 17 #include "chrome/browser/notifications/notification_options_menu_model.h" | 17 #include "chrome/browser/notifications/notification_options_menu_model.h" |
| 18 #include "content/public/browser/notification_details.h" | 18 #include "content/public/browser/notification_details.h" |
| 19 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
| 20 #include "content/public/browser/notification_types.h" | 20 #include "content/public/browser/notification_types.h" |
| 21 #include "content/public/browser/render_view_host.h" | 21 #include "content/public/browser/render_view_host.h" |
| 22 #include "content/public/browser/render_widget_host_view.h" | 22 #include "content/public/browser/render_widget_host_view.h" |
| 23 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| 24 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
| 25 #include "grit/theme_resources.h" | 25 #include "grit/theme_resources.h" |
| 26 #include "ui/base/animation/slide_animation.h" | |
| 27 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 28 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
| 28 #include "ui/gfx/animation/slide_animation.h" |
| 29 #include "ui/gfx/canvas.h" | 29 #include "ui/gfx/canvas.h" |
| 30 #include "ui/gfx/native_widget_types.h" | 30 #include "ui/gfx/native_widget_types.h" |
| 31 #include "ui/gfx/path.h" | 31 #include "ui/gfx/path.h" |
| 32 #include "ui/views/bubble/bubble_border.h" | 32 #include "ui/views/bubble/bubble_border.h" |
| 33 #include "ui/views/controls/button/image_button.h" | 33 #include "ui/views/controls/button/image_button.h" |
| 34 #include "ui/views/controls/button/menu_button.h" | 34 #include "ui/views/controls/button/menu_button.h" |
| 35 #include "ui/views/controls/button/text_button.h" | 35 #include "ui/views/controls/button/text_button.h" |
| 36 #include "ui/views/controls/label.h" | 36 #include "ui/views/controls/label.h" |
| 37 #include "ui/views/controls/menu/menu_item_view.h" | 37 #include "ui/views/controls/menu/menu_item_view.h" |
| 38 #include "ui/views/controls/menu/menu_runner.h" | 38 #include "ui/views/controls/menu/menu_runner.h" |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 html_contents_->SetPreferredSize(contents_rect.size()); | 205 html_contents_->SetPreferredSize(contents_rect.size()); |
| 206 content::RenderWidgetHostView* view = | 206 content::RenderWidgetHostView* view = |
| 207 html_contents_->web_contents()->GetRenderWidgetHostView(); | 207 html_contents_->web_contents()->GetRenderWidgetHostView(); |
| 208 if (view) | 208 if (view) |
| 209 view->SetSize(contents_rect.size()); | 209 view->SetSize(contents_rect.size()); |
| 210 return; | 210 return; |
| 211 } | 211 } |
| 212 | 212 |
| 213 anim_frame_end_ = GetBoundsForFrameContainer(); | 213 anim_frame_end_ = GetBoundsForFrameContainer(); |
| 214 anim_frame_start_ = frame_container_->GetClientAreaBoundsInScreen(); | 214 anim_frame_start_ = frame_container_->GetClientAreaBoundsInScreen(); |
| 215 animation_.reset(new ui::SlideAnimation(this)); | 215 animation_.reset(new gfx::SlideAnimation(this)); |
| 216 animation_->Show(); | 216 animation_->Show(); |
| 217 } | 217 } |
| 218 | 218 |
| 219 void BalloonViewImpl::Update() { | 219 void BalloonViewImpl::Update() { |
| 220 // Tls might get called before html_contents_ is set in Show() if more than | 220 // Tls might get called before html_contents_ is set in Show() if more than |
| 221 // one update with the same replace_id occurs, or if an update occurs after | 221 // one update with the same replace_id occurs, or if an update occurs after |
| 222 // the ballon has been closed (e.g. during shutdown) but before this has been | 222 // the ballon has been closed (e.g. during shutdown) but before this has been |
| 223 // destroyed. | 223 // destroyed. |
| 224 if (!html_contents_.get() || !html_contents_->web_contents()) | 224 if (!html_contents_.get() || !html_contents_->web_contents()) |
| 225 return; | 225 return; |
| 226 html_contents_->web_contents()->GetController().LoadURL( | 226 html_contents_->web_contents()->GetController().LoadURL( |
| 227 balloon_->notification().content_url(), content::Referrer(), | 227 balloon_->notification().content_url(), content::Referrer(), |
| 228 content::PAGE_TRANSITION_LINK, std::string()); | 228 content::PAGE_TRANSITION_LINK, std::string()); |
| 229 } | 229 } |
| 230 | 230 |
| 231 void BalloonViewImpl::AnimationProgressed(const ui::Animation* animation) { | 231 void BalloonViewImpl::AnimationProgressed(const gfx::Animation* animation) { |
| 232 DCHECK_EQ(animation_.get(), animation); | 232 DCHECK_EQ(animation_.get(), animation); |
| 233 | 233 |
| 234 // Linear interpolation from start to end position. | 234 // Linear interpolation from start to end position. |
| 235 gfx::Rect frame_position(animation_->CurrentValueBetween( | 235 gfx::Rect frame_position(animation_->CurrentValueBetween( |
| 236 anim_frame_start_, anim_frame_end_)); | 236 anim_frame_start_, anim_frame_end_)); |
| 237 frame_container_->SetBounds(frame_position); | 237 frame_container_->SetBounds(frame_position); |
| 238 | 238 |
| 239 gfx::Path path; | 239 gfx::Path path; |
| 240 gfx::Rect contents_rect = GetContentsRectangle(); | 240 gfx::Rect contents_rect = GetContentsRectangle(); |
| 241 html_container_->SetBounds(contents_rect); | 241 html_container_->SetBounds(contents_rect); |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 return; | 523 return; |
| 524 } | 524 } |
| 525 | 525 |
| 526 // If the renderer process attached to this balloon is disconnected | 526 // If the renderer process attached to this balloon is disconnected |
| 527 // (e.g., because of a crash), we want to close the balloon. | 527 // (e.g., because of a crash), we want to close the balloon. |
| 528 notification_registrar_.Remove( | 528 notification_registrar_.Remove( |
| 529 this, chrome::NOTIFICATION_NOTIFY_BALLOON_DISCONNECTED, | 529 this, chrome::NOTIFICATION_NOTIFY_BALLOON_DISCONNECTED, |
| 530 content::Source<Balloon>(balloon_)); | 530 content::Source<Balloon>(balloon_)); |
| 531 Close(false); | 531 Close(false); |
| 532 } | 532 } |
| OLD | NEW |