Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(524)

Side by Side Diff: ui/message_center/views/toast_contents_view.cc

Issue 2075953003: mash: Convert WebNotificationTray to wm common types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@statusarea
Patch Set: rebase Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/message_center/views/toast_contents_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "ui/message_center/views/toast_contents_view.h" 5 #include "ui/message_center/views/toast_contents_view.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "ui/accessibility/ax_view_state.h" 14 #include "ui/accessibility/ax_view_state.h"
15 #include "ui/display/display.h" 15 #include "ui/display/display.h"
16 #include "ui/display/screen.h" 16 #include "ui/display/screen.h"
17 #include "ui/gfx/animation/animation_delegate.h" 17 #include "ui/gfx/animation/animation_delegate.h"
18 #include "ui/gfx/animation/slide_animation.h" 18 #include "ui/gfx/animation/slide_animation.h"
19 #include "ui/message_center/message_center_style.h" 19 #include "ui/message_center/message_center_style.h"
20 #include "ui/message_center/notification.h" 20 #include "ui/message_center/notification.h"
21 #include "ui/message_center/views/message_popup_collection.h" 21 #include "ui/message_center/views/message_popup_collection.h"
22 #include "ui/message_center/views/message_view.h" 22 #include "ui/message_center/views/message_view.h"
23 #include "ui/message_center/views/popup_alignment_delegate.h"
23 #include "ui/views/background.h" 24 #include "ui/views/background.h"
24 #include "ui/views/view.h" 25 #include "ui/views/view.h"
25 #include "ui/views/widget/widget.h" 26 #include "ui/views/widget/widget.h"
26 #include "ui/views/widget/widget_delegate.h" 27 #include "ui/views/widget/widget_delegate.h"
27 28
28 #if defined(OS_WIN) 29 #if defined(OS_WIN)
29 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" 30 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
30 #endif 31 #endif
31 32
32 using display::Screen; 33 using display::Screen;
(...skipping 10 matching lines...) Expand all
43 } // namespace. 44 } // namespace.
44 45
45 // static 46 // static
46 gfx::Size ToastContentsView::GetToastSizeForView(const views::View* view) { 47 gfx::Size ToastContentsView::GetToastSizeForView(const views::View* view) {
47 int width = kNotificationWidth + view->GetInsets().width(); 48 int width = kNotificationWidth + view->GetInsets().width();
48 return gfx::Size(width, view->GetHeightForWidth(width)); 49 return gfx::Size(width, view->GetHeightForWidth(width));
49 } 50 }
50 51
51 ToastContentsView::ToastContentsView( 52 ToastContentsView::ToastContentsView(
52 const std::string& notification_id, 53 const std::string& notification_id,
54 PopupAlignmentDelegate* alignment_delegate,
53 base::WeakPtr<MessagePopupCollection> collection) 55 base::WeakPtr<MessagePopupCollection> collection)
54 : collection_(collection), 56 : collection_(collection),
55 id_(notification_id), 57 id_(notification_id),
56 is_closing_(false), 58 is_closing_(false),
57 closing_animation_(NULL) { 59 closing_animation_(NULL) {
60 DCHECK(alignment_delegate);
58 set_notify_enter_exit_on_child(true); 61 set_notify_enter_exit_on_child(true);
59 // Sets the transparent background. Then, when the message view is slid out, 62 // Sets the transparent background. Then, when the message view is slid out,
60 // the whole toast seems to slide although the actual bound of the widget 63 // the whole toast seems to slide although the actual bound of the widget
61 // remains. This is hacky but easier to keep the consistency. 64 // remains. This is hacky but easier to keep the consistency.
62 set_background(views::Background::CreateSolidBackground(0, 0, 0, 0)); 65 set_background(views::Background::CreateSolidBackground(0, 0, 0, 0));
63 66
64 fade_animation_.reset(new gfx::SlideAnimation(this)); 67 fade_animation_.reset(new gfx::SlideAnimation(this));
65 fade_animation_->SetSlideDuration(kFadeInOutDuration); 68 fade_animation_->SetSlideDuration(kFadeInOutDuration);
66 69
67 CreateWidget(collection->parent()); 70 CreateWidget(alignment_delegate);
68 } 71 }
69 72
70 // This is destroyed when the toast window closes. 73 // This is destroyed when the toast window closes.
71 ToastContentsView::~ToastContentsView() { 74 ToastContentsView::~ToastContentsView() {
72 if (collection_) 75 if (collection_)
73 collection_->ForgetToast(this); 76 collection_->ForgetToast(this);
74 } 77 }
75 78
76 void ToastContentsView::SetContents(MessageView* view, 79 void ToastContentsView::SetContents(MessageView* view,
77 bool a11y_feedback_for_updates) { 80 bool a11y_feedback_for_updates) {
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 return collection_->HasClickedListener(notification_id); 354 return collection_->HasClickedListener(notification_id);
352 } 355 }
353 356
354 void ToastContentsView::ClickOnNotificationButton( 357 void ToastContentsView::ClickOnNotificationButton(
355 const std::string& notification_id, 358 const std::string& notification_id,
356 int button_index) { 359 int button_index) {
357 if (collection_) 360 if (collection_)
358 collection_->ClickOnNotificationButton(notification_id, button_index); 361 collection_->ClickOnNotificationButton(notification_id, button_index);
359 } 362 }
360 363
361 void ToastContentsView::CreateWidget(gfx::NativeView parent) { 364 void ToastContentsView::CreateWidget(
365 PopupAlignmentDelegate* alignment_delegate) {
362 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); 366 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
363 params.keep_on_top = true; 367 params.keep_on_top = true;
364 if (parent)
365 params.parent = parent;
366 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; 368 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
367 params.delegate = this; 369 params.delegate = this;
368 views::Widget* widget = new views::Widget(); 370 views::Widget* widget = new views::Widget();
371 alignment_delegate->ConfigureWidgetInitParamsForContainer(widget, &params);
369 widget->set_focus_on_creation(false); 372 widget->set_focus_on_creation(false);
370 373
371 #if defined(OS_WIN) 374 #if defined(OS_WIN)
372 // We want to ensure that this toast always goes to the native desktop, 375 // We want to ensure that this toast always goes to the native desktop,
373 // not the Ash desktop (since there is already another toast contents view 376 // not the Ash desktop (since there is already another toast contents view
374 // there. 377 // there.
375 if (!params.parent) 378 if (!params.parent)
376 params.native_widget = new views::DesktopNativeWidgetAura(widget); 379 params.native_widget = new views::DesktopNativeWidgetAura(widget);
377 #endif 380 #endif
378 381
379 widget->Init(params); 382 widget->Init(params);
380 } 383 }
381 384
382 gfx::Rect ToastContentsView::GetClosedToastBounds(gfx::Rect bounds) { 385 gfx::Rect ToastContentsView::GetClosedToastBounds(gfx::Rect bounds) {
383 return gfx::Rect(bounds.x() + bounds.width() - kClosedToastWidth, 386 return gfx::Rect(bounds.x() + bounds.width() - kClosedToastWidth,
384 bounds.y(), 387 bounds.y(),
385 kClosedToastWidth, 388 kClosedToastWidth,
386 bounds.height()); 389 bounds.height());
387 } 390 }
388 391
389 } // namespace message_center 392 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/views/toast_contents_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698