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

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

Issue 2935893004: Add unittest for ArcNotificationContentView (Closed)
Patch Set: . Created 3 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 side-by-side diff with in-line comments
Download patch
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 c55e22f0e0e94676fd308586bce5b8e2e96acf8a..20d1b016e047e7df890967d798abc1460261fc74 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"
@@ -118,8 +119,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())
@@ -150,19 +151,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();
}
@@ -238,6 +239,10 @@ void ArcNotificationContentView::ControlButton::OnBlur() {
owner_->UpdateControlButtonsVisibility();
}
+// static, for ArcNotificationContentView::GetClassName().
+const char ArcNotificationContentView::kViewClassName[] =
+ "ArcNotificationContentView";
+
ArcNotificationContentView::ArcNotificationContentView(
ArcNotificationItem* item)
: item_(item),
@@ -252,8 +257,8 @@ ArcNotificationContentView::ArcNotificationContentView(
auto* surface_manager = ArcNotificationSurfaceManager::Get();
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);
}
@@ -276,6 +281,10 @@ ArcNotificationContentView::~ArcNotificationContentView() {
}
}
+const char* ArcNotificationContentView::GetClassName() const {
+ return kViewClassName;
+}
+
std::unique_ptr<ArcNotificationContentViewDelegate>
ArcNotificationContentView::CreateContentViewDelegate() {
return base::MakeUnique<ArcNotificationContentView::ContentViewDelegate>(
@@ -333,7 +342,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);
@@ -347,7 +356,7 @@ void ArcNotificationContentView::MaybeCreateFloatingControlButtons() {
Layout();
}
-void ArcNotificationContentView::SetSurface(exo::NotificationSurface* surface) {
+void ArcNotificationContentView::SetSurface(ArcNotificationSurface* surface) {
if (surface_ == surface)
return;
@@ -357,19 +366,19 @@ 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());
- if (GetWidget())
- Detach();
+ if (GetWidget() && surface_->IsAttached())
+ surface_->Detach();
}
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());
if (GetWidget())
AttachSurface();
@@ -446,12 +455,12 @@ void ArcNotificationContentView::AttachSurface() {
return;
UpdatePreferredSize();
- Attach(surface_->window());
+ surface_->Attach(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));
@@ -517,8 +526,8 @@ void ArcNotificationContentView::ViewHierarchyChanged(
if (!widget || !surface_ || !details.is_add)
return;
- if (native_view())
- Detach();
+ if (surface_->IsAttached())
+ surface_->Detach();
AttachSurface();
}
@@ -544,7 +553,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_->GetContentWindow()->SetTransform(transform);
if (!floating_control_buttons_widget_)
return;
@@ -570,7 +579,7 @@ void ArcNotificationContentView::Layout() {
UpdateControlButtonsVisibility();
- ash::wm::SnapWindowToPixelBoundary(surface_->window());
+ ash::wm::SnapWindowToPixelBoundary(surface_->GetWindow());
}
void ArcNotificationContentView::OnPaint(gfx::Canvas* canvas) {
@@ -687,16 +696,16 @@ void ArcNotificationContentView::OnItemUpdated() {
}
void ArcNotificationContentView::OnNotificationSurfaceAdded(
- exo::NotificationSurface* surface) {
- if (surface->notification_key() != notification_key_)
+ ArcNotificationSurface* surface) {
+ if (surface->GetNotificationKey() != notification_key_)
return;
SetSurface(surface);
}
void ArcNotificationContentView::OnNotificationSurfaceRemoved(
- exo::NotificationSurface* surface) {
- if (surface->notification_key() != notification_key_)
+ ArcNotificationSurface* surface) {
+ if (surface->GetNotificationKey() != notification_key_)
return;
SetSurface(nullptr);
« no previous file with comments | « ui/arc/notification/arc_notification_content_view.h ('k') | ui/arc/notification/arc_notification_content_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698