glanceables_controller.cc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2022 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/glanceables/glanceables_controller.h"
  5. #include <memory>
  6. #include "ash/ambient/ambient_controller.h"
  7. #include "ash/ambient/ambient_weather_controller.h"
  8. #include "ash/glanceables/glanceables_view.h"
  9. #include "ash/public/cpp/shell_window_ids.h"
  10. #include "ash/shell.h"
  11. #include "base/logging.h"
  12. #include "ui/base/ui_base_types.h"
  13. #include "ui/views/widget/widget.h"
  14. #include "ui/views/widget/widget_delegate.h"
  15. namespace ash {
  16. GlanceablesController::GlanceablesController() = default;
  17. GlanceablesController::~GlanceablesController() = default;
  18. void GlanceablesController::CreateUi() {
  19. widget_ = std::make_unique<views::Widget>();
  20. views::Widget::InitParams params;
  21. params.delegate = new views::WidgetDelegate; // Takes ownership.
  22. params.delegate->SetOwnedByWidget(true);
  23. // Allow maximize so the glanceable container's FillLayoutManager can fill the
  24. // screen with the widget. This is required even for fullscreen widgets.
  25. params.delegate->SetCanMaximize(true);
  26. params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS;
  27. params.name = "GlanceablesWidget";
  28. params.show_state = ui::SHOW_STATE_FULLSCREEN;
  29. // Create the glanceables widget on the primary display.
  30. params.parent = Shell::GetContainer(Shell::GetPrimaryRootWindow(),
  31. kShellWindowId_GlanceablesContainer);
  32. params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
  33. params.opacity = views::Widget::InitParams::WindowOpacity::kTranslucent;
  34. widget_->Init(std::move(params));
  35. view_ = widget_->SetContentsView(std::make_unique<GlanceablesView>());
  36. widget_->Show();
  37. }
  38. void GlanceablesController::DestroyUi() {
  39. widget_.reset();
  40. view_ = nullptr;
  41. }
  42. void GlanceablesController::FetchData() {
  43. // GlanceablesWeatherView observes the weather model for updates.
  44. Shell::Get()
  45. ->ambient_controller()
  46. ->ambient_weather_controller()
  47. ->FetchWeather();
  48. }
  49. } // namespace ash