mode_indicator_observer.cc 1002 B

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright 2018 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/ime/mode_indicator_observer.h"
  5. #include "ui/views/widget/widget.h"
  6. namespace ash {
  7. ModeIndicatorObserver::ModeIndicatorObserver() : active_widget_(nullptr) {}
  8. ModeIndicatorObserver::~ModeIndicatorObserver() {
  9. if (active_widget_)
  10. active_widget_->RemoveObserver(this);
  11. CHECK(!IsInObserverList());
  12. }
  13. void ModeIndicatorObserver::AddModeIndicatorWidget(views::Widget* widget) {
  14. // If other active mode indicator widget is shown, close it immediately
  15. // without fading animation. Then store this widget as the active widget.
  16. DCHECK(widget);
  17. if (active_widget_)
  18. active_widget_->Close();
  19. active_widget_ = widget;
  20. widget->AddObserver(this);
  21. }
  22. void ModeIndicatorObserver::OnWidgetDestroying(views::Widget* widget) {
  23. if (widget == active_widget_)
  24. active_widget_ = nullptr;
  25. }
  26. } // namespace ash