OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/chrome_views_delegate.h" | 5 #include "chrome/browser/ui/views/chrome_views_delegate.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/event_disposition.h" | 12 #include "chrome/browser/event_disposition.h" |
13 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
14 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 14 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
15 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
16 #include "chrome/browser/ui/views/accessibility/accessibility_event_router_views
.h" | 16 #include "chrome/browser/ui/views/accessibility/accessibility_event_router_views
.h" |
17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
18 #include "ui/gfx/rect.h" | 18 #include "ui/gfx/rect.h" |
19 #include "ui/gfx/screen.h" | 19 #include "ui/gfx/screen.h" |
20 #include "ui/views/widget/native_widget.h" | 20 #include "ui/views/widget/native_widget.h" |
21 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
22 | 22 |
23 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
24 #include "chrome/browser/app_icon_win.h" | 24 #include "chrome/browser/app_icon_win.h" |
25 #endif | 25 #endif |
26 | 26 |
27 #if defined(USE_AURA) && !defined(OS_CHROMEOS) | 27 #if defined(USE_AURA) && !defined(OS_CHROMEOS) |
| 28 #include "chrome/browser/ui/host_desktop.h" |
| 29 #include "ui/aura/root_window.h" |
28 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 30 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
29 #include "ui/views/widget/native_widget_aura.h" | 31 #include "ui/views/widget/native_widget_aura.h" |
30 #endif | 32 #endif |
31 | 33 |
32 #if defined(USE_ASH) | 34 #if defined(USE_ASH) |
33 #include "ash/shell.h" | 35 #include "ash/shell.h" |
34 #include "chrome/browser/ui/ash/ash_init.h" | 36 #include "chrome/browser/ui/ash/ash_init.h" |
35 #include "chrome/browser/ui/ash/ash_util.h" | 37 #include "chrome/browser/ui/ash/ash_util.h" |
36 #endif | 38 #endif |
37 | 39 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 int ChromeViewsDelegate::GetDispositionForEvent(int event_flags) { | 168 int ChromeViewsDelegate::GetDispositionForEvent(int event_flags) { |
167 return chrome::DispositionFromEventFlags(event_flags); | 169 return chrome::DispositionFromEventFlags(event_flags); |
168 } | 170 } |
169 | 171 |
170 content::WebContents* ChromeViewsDelegate::CreateWebContents( | 172 content::WebContents* ChromeViewsDelegate::CreateWebContents( |
171 content::BrowserContext* browser_context, | 173 content::BrowserContext* browser_context, |
172 content::SiteInstance* site_instance) { | 174 content::SiteInstance* site_instance) { |
173 return NULL; | 175 return NULL; |
174 } | 176 } |
175 | 177 |
176 views::NativeWidget* ChromeViewsDelegate::CreateNativeWidget( | 178 void ChromeViewsDelegate::OnBeforeWidgetInit( |
177 views::Widget::InitParams::Type type, | 179 views::Widget::InitParams* params, |
178 views::internal::NativeWidgetDelegate* delegate, | 180 views::internal::NativeWidgetDelegate* delegate) { |
179 gfx::NativeView parent, | |
180 gfx::NativeView context) { | |
181 #if defined(USE_AURA) && !defined(OS_CHROMEOS) | 181 #if defined(USE_AURA) && !defined(OS_CHROMEOS) |
182 if (parent && type != views::Widget::InitParams::TYPE_MENU) | 182 // While the majority of the time, context wasn't plumbed through due to the |
183 return new views::NativeWidgetAura(delegate); | 183 // existence of a global StackingClient, if this window is a toplevel, it's |
184 // TODO(erg): Once we've threaded context to everywhere that needs it, we | 184 // possible that there is no contextual state that we can use. |
185 // should remove this check here. | 185 if (params->parent == NULL && params->context == NULL && params->top_level) { |
186 gfx::NativeView to_check = context ? context : parent; | 186 // We need to make a decision about where to place this window based on the |
187 if (chrome::GetHostDesktopTypeForNativeView(to_check) == | 187 // desktop type. |
188 chrome::HOST_DESKTOP_TYPE_NATIVE) | 188 switch (chrome::GetActiveDesktop()) { |
189 return new views::DesktopNativeWidgetAura(delegate); | 189 case chrome::HOST_DESKTOP_TYPE_NATIVE: |
| 190 // If we're native, we should give this window its own toplevel desktop |
| 191 // widget. |
| 192 params->native_widget = new views::DesktopNativeWidgetAura(delegate); |
| 193 break; |
| 194 #if defined(USE_ASH) |
| 195 case chrome::HOST_DESKTOP_TYPE_ASH: |
| 196 // If we're in ash, give this window the context of the main monitor. |
| 197 params->context = ash::Shell::GetPrimaryRootWindow(); |
| 198 break; |
190 #endif | 199 #endif |
191 return NULL; | 200 default: |
| 201 NOTREACHED(); |
| 202 } |
| 203 } else if (params->parent && |
| 204 params->type != views::Widget::InitParams::TYPE_MENU) { |
| 205 params->native_widget = new views::NativeWidgetAura(delegate); |
| 206 } else { |
| 207 // TODO(erg): Once we've threaded context to everywhere that needs it, we |
| 208 // should remove this check here. |
| 209 gfx::NativeView to_check = |
| 210 params->context ? params->context : params->parent; |
| 211 if (chrome::GetHostDesktopTypeForNativeView(to_check) == |
| 212 chrome::HOST_DESKTOP_TYPE_NATIVE) { |
| 213 params->native_widget = new views::DesktopNativeWidgetAura(delegate); |
| 214 } |
| 215 } |
| 216 #endif |
192 } | 217 } |
OLD | NEW |