views_delegate.cc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // Copyright (c) 2014 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-CHROMIUM file.
  4. #include "brightray/browser/views/views_delegate.h"
  5. #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
  6. #include "ui/views/widget/native_widget_aura.h"
  7. #if defined(OS_LINUX)
  8. #include "base/environment.h"
  9. #include "base/nix/xdg_util.h"
  10. #include "ui/views/linux_ui/linux_ui.h"
  11. #endif
  12. namespace {
  13. #if defined(OS_LINUX)
  14. bool IsDesktopEnvironmentUnity() {
  15. std::unique_ptr<base::Environment> env(base::Environment::Create());
  16. base::nix::DesktopEnvironment desktop_env =
  17. base::nix::GetDesktopEnvironment(env.get());
  18. return desktop_env == base::nix::DESKTOP_ENVIRONMENT_UNITY;
  19. }
  20. #endif
  21. } // namespace
  22. namespace brightray {
  23. ViewsDelegate::ViewsDelegate() {}
  24. ViewsDelegate::~ViewsDelegate() {}
  25. void ViewsDelegate::SaveWindowPlacement(const views::Widget* window,
  26. const std::string& window_name,
  27. const gfx::Rect& bounds,
  28. ui::WindowShowState show_state) {}
  29. bool ViewsDelegate::GetSavedWindowPlacement(
  30. const views::Widget* widget,
  31. const std::string& window_name,
  32. gfx::Rect* bounds,
  33. ui::WindowShowState* show_state) const {
  34. return false;
  35. }
  36. void ViewsDelegate::NotifyAccessibilityEvent(views::View* view,
  37. ui::AXEvent event_type) {}
  38. void ViewsDelegate::NotifyMenuItemFocused(const base::string16& menu_name,
  39. const base::string16& menu_item_name,
  40. int item_index,
  41. int item_count,
  42. bool has_submenu) {}
  43. #if defined(OS_WIN)
  44. HICON ViewsDelegate::GetDefaultWindowIcon() const {
  45. // Use current exe's icon as default window icon.
  46. return LoadIcon(GetModuleHandle(NULL),
  47. MAKEINTRESOURCE(1 /* IDR_MAINFRAME */));
  48. }
  49. HICON ViewsDelegate::GetSmallWindowIcon() const {
  50. return GetDefaultWindowIcon();
  51. }
  52. bool ViewsDelegate::IsWindowInMetro(gfx::NativeWindow window) const {
  53. return false;
  54. }
  55. #elif defined(OS_LINUX) && !defined(OS_CHROMEOS)
  56. gfx::ImageSkia* ViewsDelegate::GetDefaultWindowIcon() const {
  57. return NULL;
  58. }
  59. #endif
  60. views::NonClientFrameView* ViewsDelegate::CreateDefaultNonClientFrameView(
  61. views::Widget* widget) {
  62. return NULL;
  63. }
  64. void ViewsDelegate::AddRef() {}
  65. void ViewsDelegate::ReleaseRef() {}
  66. content::WebContents* ViewsDelegate::CreateWebContents(
  67. content::BrowserContext* browser_context,
  68. content::SiteInstance* site_instance) {
  69. return NULL;
  70. }
  71. void ViewsDelegate::OnBeforeWidgetInit(
  72. views::Widget::InitParams* params,
  73. views::internal::NativeWidgetDelegate* delegate) {
  74. // If we already have a native_widget, we don't have to try to come
  75. // up with one.
  76. if (params->native_widget)
  77. return;
  78. if (params->parent && params->type != views::Widget::InitParams::TYPE_MENU &&
  79. params->type != views::Widget::InitParams::TYPE_TOOLTIP) {
  80. params->native_widget = new views::NativeWidgetAura(delegate);
  81. } else {
  82. params->native_widget = new views::DesktopNativeWidgetAura(delegate);
  83. }
  84. }
  85. bool ViewsDelegate::WindowManagerProvidesTitleBar(bool maximized) {
  86. #if defined(OS_LINUX)
  87. // On Ubuntu Unity, the system always provides a title bar for maximized
  88. // windows.
  89. if (!maximized)
  90. return false;
  91. static bool is_desktop_environment_unity = IsDesktopEnvironmentUnity();
  92. return is_desktop_environment_unity;
  93. #else
  94. return false;
  95. #endif
  96. }
  97. } // namespace brightray