blob: 73f77350172bf3f3ac47fc2573ea5089bea29ee5 [file] [log] [blame]
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/exo/notification_surface.h"
#include "components/exo/notification_surface_manager.h"
#include "components/exo/surface.h"
#include "ui/aura/window.h"
#include "ui/gfx/geometry/rect.h"
namespace exo {
NotificationSurface::NotificationSurface(NotificationSurfaceManager* manager,
Surface* surface,
const std::string& notification_key)
: SurfaceTreeHost("ExoNotificationSurface", nullptr),
manager_(manager),
notification_key_(notification_key) {
surface->AddSurfaceObserver(this);
SetRootSurface(surface);
host_window()->Show();
}
NotificationSurface::~NotificationSurface() {
if (added_to_manager_)
manager_->RemoveSurface(this);
if (root_surface())
root_surface()->RemoveSurfaceObserver(this);
}
const gfx::Size& NotificationSurface::GetContentSize() const {
return root_surface()->content_size();
}
void NotificationSurface::OnSurfaceCommit() {
SurfaceTreeHost::OnSurfaceCommit();
gfx::Rect bounds = host_window()->bounds();
auto& size = host_window()->bounds().size();
if (bounds.size() != size) {
bounds.set_size(size);
host_window()->SetBounds(bounds);
}
// Defer AddSurface until there are contents to show.
if (!added_to_manager_ && !size.IsEmpty()) {
added_to_manager_ = true;
manager_->AddSurface(this);
}
}
void NotificationSurface::OnSurfaceDestroying(Surface* surface) {
DCHECK_EQ(surface, root_surface());
surface->RemoveSurfaceObserver(this);
SetRootSurface(nullptr);
}
} // namespace exo