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

Unified Diff: ui/arc/notification/arc_notification_content_view.cc

Issue 2723143002: Add unittests of ArcCustomNotificationView (Closed)
Patch Set: wip Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/arc/notification/arc_notification_content_view.h ('k') | ui/arc/notification/arc_notification_surface.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/arc/notification/arc_notification_content_view.cc
diff --git a/ui/arc/notification/arc_notification_content_view.cc b/ui/arc/notification/arc_notification_content_view.cc
index 312dcb97f903e63d66ce622d45743429f8169721..d7d12f5953cfd8ed846646688c763b261737319e 100644
--- a/ui/arc/notification/arc_notification_content_view.cc
+++ b/ui/arc/notification/arc_notification_content_view.cc
@@ -11,6 +11,7 @@
#include "components/exo/surface.h"
#include "ui/accessibility/ax_action_data.h"
#include "ui/accessibility/ax_node_data.h"
+#include "ui/arc/notification/arc_notification_surface.h"
#include "ui/arc/notification/arc_notification_view.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
@@ -111,8 +112,8 @@ class ArcNotificationContentView::SlideHelper
// Reset opacity to 1 to handle to case when the surface is sliding before
// getting managed by this class, e.g. sliding in a popup before showing
// in a message center view.
- if (owner_->surface_ && owner_->surface_->window())
- owner_->surface_->window()->layer()->SetOpacity(1.0f);
+ if (owner_->surface_ && owner_->surface_->GetWindow())
+ owner_->surface_->GetWindow()->layer()->SetOpacity(1.0f);
}
~SlideHelper() override {
if (GetSlideOutLayer())
@@ -143,19 +144,19 @@ class ArcNotificationContentView::SlideHelper
}
void OnSlideStart() {
- if (!owner_->surface_ || !owner_->surface_->window())
+ if (!owner_->surface_ || !owner_->surface_->GetWindow())
return;
- surface_copy_ = ::wm::RecreateLayers(owner_->surface_->window());
+ surface_copy_ = ::wm::RecreateLayers(owner_->surface_->GetWindow());
// |surface_copy_| is at (0, 0) in owner_->layer().
surface_copy_->root()->SetBounds(gfx::Rect(surface_copy_->root()->size()));
owner_->layer()->Add(surface_copy_->root());
- owner_->surface_->window()->layer()->SetOpacity(0.0f);
+ owner_->surface_->GetWindow()->layer()->SetOpacity(0.0f);
}
void OnSlideEnd() {
- if (!owner_->surface_ || !owner_->surface_->window())
+ if (!owner_->surface_ || !owner_->surface_->GetWindow())
return;
- owner_->surface_->window()->layer()->SetOpacity(1.0f);
+ owner_->surface_->GetWindow()->layer()->SetOpacity(1.0f);
owner_->Layout();
surface_copy_.reset();
}
@@ -231,6 +232,14 @@ void ArcNotificationContentView::ControlButton::OnBlur() {
owner_->UpdateControlButtonsVisibility();
}
+// static
+const char ArcNotificationContentView::kViewClassName[] =
+ "ArcNotificationContentView";
+
+// static
+ArcNotificationSurfaceManager*
+ ArcNotificationContentView::surface_manager_for_testing_ = nullptr;
+
ArcNotificationContentView::ArcNotificationContentView(
ArcNotificationItem* item)
: item_(item),
@@ -241,11 +250,11 @@ ArcNotificationContentView::ArcNotificationContentView(
item_->IncrementWindowRefCount();
item_->AddObserver(this);
- auto* surface_manager = ArcNotificationSurfaceManager::Get();
+ auto* surface_manager = GetSurfaceManager();
if (surface_manager) {
surface_manager->AddObserver(this);
- exo::NotificationSurface* surface =
- surface_manager->GetSurface(notification_key_);
+ ArcNotificationSurface* surface =
+ surface_manager->GetArcSurface(notification_key_);
if (surface)
OnNotificationSurfaceAdded(surface);
}
@@ -259,7 +268,7 @@ ArcNotificationContentView::ArcNotificationContentView(
ArcNotificationContentView::~ArcNotificationContentView() {
SetSurface(nullptr);
- auto* surface_manager = ArcNotificationSurfaceManager::Get();
+ auto* surface_manager = GetSurfaceManager();
if (surface_manager)
surface_manager->RemoveObserver(this);
if (item_) {
@@ -268,12 +277,23 @@ ArcNotificationContentView::~ArcNotificationContentView() {
}
}
+const char* ArcNotificationContentView::GetClassName() const {
+ return kViewClassName;
+}
+
std::unique_ptr<ArcNotificationContentViewDelegate>
ArcNotificationContentView::CreateContentViewDelegate() {
return base::MakeUnique<ArcNotificationContentView::ContentViewDelegate>(
this);
}
+ArcNotificationSurfaceManager* ArcNotificationContentView::GetSurfaceManager()
+ const {
+ if (surface_manager_for_testing_)
+ return surface_manager_for_testing_;
+ return ArcNotificationSurfaceManager::Get();
+}
+
void ArcNotificationContentView::CreateCloseButton() {
DCHECK(control_buttons_view_);
DCHECK(item_);
@@ -325,7 +345,7 @@ void ArcNotificationContentView::MaybeCreateFloatingControlButtons() {
views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL);
params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
- params.parent = surface_->window();
+ params.parent = surface_->GetWindow();
floating_control_buttons_widget_.reset(new views::Widget);
floating_control_buttons_widget_->Init(params);
@@ -339,7 +359,7 @@ void ArcNotificationContentView::MaybeCreateFloatingControlButtons() {
Layout();
}
-void ArcNotificationContentView::SetSurface(exo::NotificationSurface* surface) {
+void ArcNotificationContentView::SetSurface(ArcNotificationSurface* surface) {
if (surface_ == surface)
return;
@@ -349,16 +369,16 @@ void ArcNotificationContentView::SetSurface(exo::NotificationSurface* surface) {
settings_button_ = nullptr;
close_button_.reset();
- if (surface_ && surface_->window()) {
- surface_->window()->RemoveObserver(this);
- surface_->window()->RemovePreTargetHandler(event_forwarder_.get());
+ if (surface_ && surface_->GetWindow()) {
+ surface_->GetWindow()->RemoveObserver(this);
+ surface_->GetWindow()->RemovePreTargetHandler(event_forwarder_.get());
}
surface_ = surface;
- if (surface_ && surface_->window()) {
- surface_->window()->AddObserver(this);
- surface_->window()->AddPreTargetHandler(event_forwarder_.get());
+ if (surface_ && surface_->GetWindow()) {
+ surface_->GetWindow()->AddObserver(this);
+ surface_->GetWindow()->AddPreTargetHandler(event_forwarder_.get());
MaybeCreateFloatingControlButtons();
@@ -444,12 +464,12 @@ void ArcNotificationContentView::AttachSurface() {
return;
UpdatePreferredSize();
- Attach(surface_->window());
+ surface_->AttachWindow(this);
// The texture for this window can be placed at subpixel position
// with fractional scale factor. Force to align it at the pixel
// boundary here, and when layout is updated in Layout().
- ash::wm::SnapWindowToPixelBoundary(surface_->window());
+ ash::wm::SnapWindowToPixelBoundary(surface_->GetWindow());
// Creates slide helper after this view is added to its parent.
slide_helper_.reset(new SlideHelper(this));
@@ -542,7 +562,7 @@ void ArcNotificationContentView::Layout() {
// Apply the transform to the surface content so that close button can
// be positioned without the need to consider the transform.
- surface_->window()->children()[0]->SetTransform(transform);
+ surface_->GetWindow()->children()[0]->SetTransform(transform);
if (!floating_control_buttons_widget_)
return;
@@ -568,7 +588,7 @@ void ArcNotificationContentView::Layout() {
UpdateControlButtonsVisibility();
- ash::wm::SnapWindowToPixelBoundary(surface_->window());
+ ash::wm::SnapWindowToPixelBoundary(surface_->GetWindow());
}
void ArcNotificationContentView::OnPaint(gfx::Canvas* canvas) {
@@ -685,16 +705,16 @@ void ArcNotificationContentView::OnItemUpdated() {
}
void ArcNotificationContentView::OnNotificationSurfaceAdded(
- exo::NotificationSurface* surface) {
- if (surface->notification_id() != notification_key_)
+ ArcNotificationSurface* surface) {
+ if (surface->GetNotificationId() != notification_key_)
return;
SetSurface(surface);
}
void ArcNotificationContentView::OnNotificationSurfaceRemoved(
- exo::NotificationSurface* surface) {
- if (surface->notification_id() != notification_key_)
+ ArcNotificationSurface* surface) {
+ if (surface->GetNotificationId() != notification_key_)
return;
SetSurface(nullptr);
« no previous file with comments | « ui/arc/notification/arc_notification_content_view.h ('k') | ui/arc/notification/arc_notification_surface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698