atom_desktop_native_widget_aura.cc 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright (c) 2017 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #include "atom/browser/ui/win/atom_desktop_native_widget_aura.h"
  5. #include "ui/views/corewm/tooltip_controller.h"
  6. #include "ui/wm/public/tooltip_client.h"
  7. namespace atom {
  8. AtomDesktopNativeWidgetAura::AtomDesktopNativeWidgetAura(
  9. views::internal::NativeWidgetDelegate* delegate)
  10. : views::DesktopNativeWidgetAura(delegate) {
  11. // This is to enable the override of OnWindowActivated
  12. wm::SetActivationChangeObserver(GetNativeWindow(), this);
  13. }
  14. void AtomDesktopNativeWidgetAura::Activate() {
  15. // Activate can cause the focused window to be blurred so only
  16. // call when the window being activated is visible. This prevents
  17. // hidden windows from blurring the focused window when created.
  18. if (IsVisible())
  19. views::DesktopNativeWidgetAura::Activate();
  20. }
  21. void AtomDesktopNativeWidgetAura::OnWindowActivated(
  22. wm::ActivationChangeObserver::ActivationReason reason,
  23. aura::Window* gained_active,
  24. aura::Window* lost_active) {
  25. views::DesktopNativeWidgetAura::OnWindowActivated(reason, gained_active,
  26. lost_active);
  27. if (lost_active != nullptr) {
  28. auto* tooltip_controller = static_cast<views::corewm::TooltipController*>(
  29. wm::GetTooltipClient(lost_active->GetRootWindow()));
  30. // This will cause the tooltip to be hidden when a window is deactivated,
  31. // as it should be.
  32. // TODO(brenca): Remove this fix when the chromium issue is fixed.
  33. // crbug.com/724538
  34. if (tooltip_controller != nullptr)
  35. tooltip_controller->OnCancelMode(nullptr);
  36. }
  37. }
  38. } // namespace atom