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/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/prefs/scoped_user_pref_update.h" | 9 #include "base/prefs/scoped_user_pref_update.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 if (params->opacity == views::Widget::InitParams::INFER_OPACITY) | 254 if (params->opacity == views::Widget::InitParams::INFER_OPACITY) |
255 params->opacity = GetOpacityForInitParams(*params); | 255 params->opacity = GetOpacityForInitParams(*params); |
256 | 256 |
257 // If we already have a native_widget, we don't have to try to come | 257 // If we already have a native_widget, we don't have to try to come |
258 // up with one. | 258 // up with one. |
259 if (params->native_widget) | 259 if (params->native_widget) |
260 return; | 260 return; |
261 | 261 |
262 #if defined(USE_AURA) && !defined(OS_CHROMEOS) | 262 #if defined(USE_AURA) && !defined(OS_CHROMEOS) |
263 bool use_non_toplevel_window = | 263 bool use_non_toplevel_window = |
264 params->parent && params->type != views::Widget::InitParams::TYPE_MENU; | 264 params->parent && |
| 265 params->type != views::Widget::InitParams::TYPE_MENU && |
| 266 params->type != views::Widget::InitParams::TYPE_TOOLTIP; |
265 | 267 |
266 #if defined(OS_WIN) | 268 #if defined(OS_WIN) |
267 // On desktop Linux Chrome must run in an environment that supports a variety | 269 // On desktop Linux Chrome must run in an environment that supports a variety |
268 // of window managers, some of which do not play nicely with parts of our UI | 270 // of window managers, some of which do not play nicely with parts of our UI |
269 // that have specific expectations about window sizing and placement. For this | 271 // that have specific expectations about window sizing and placement. For this |
270 // reason windows opened as top level (!params.child) are always constrained | 272 // reason windows opened as top level (!params.child) are always constrained |
271 // by the browser frame, so we can position them correctly. This has some | 273 // by the browser frame, so we can position them correctly. This has some |
272 // negative side effects, like dialogs being clipped by the browser frame, but | 274 // negative side effects, like dialogs being clipped by the browser frame, but |
273 // the side effects are not as bad as the poor window manager interactions. On | 275 // the side effects are not as bad as the poor window manager interactions. On |
274 // Windows however these WM interactions are not an issue, so we open windows | 276 // Windows however these WM interactions are not an issue, so we open windows |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 if (params->context) | 315 if (params->context) |
314 params->context = params->context->GetRootWindow(); | 316 params->context = params->context->GetRootWindow(); |
315 DCHECK(params->parent || params->context || !params->child); | 317 DCHECK(params->parent || params->context || !params->child); |
316 << "Please provide a parent or context for this widget."; | 318 << "Please provide a parent or context for this widget."; |
317 if (!params->parent && !params->context) | 319 if (!params->parent && !params->context) |
318 params->context = ash::Shell::GetPrimaryRootWindow(); | 320 params->context = ash::Shell::GetPrimaryRootWindow(); |
319 #elif defined(USE_AURA) | 321 #elif defined(USE_AURA) |
320 // While the majority of the time, context wasn't plumbed through due to the | 322 // While the majority of the time, context wasn't plumbed through due to the |
321 // existence of a global WindowTreeClient, if this window is a toplevel, it's | 323 // existence of a global WindowTreeClient, if this window is a toplevel, it's |
322 // possible that there is no contextual state that we can use. | 324 // possible that there is no contextual state that we can use. |
323 if (params->parent == NULL && | 325 if (params->parent == NULL && params->context == NULL && !params->child) { |
324 params->context == NULL && | |
325 !params->child && | |
326 params->type != views::Widget::InitParams::TYPE_TOOLTIP) { | |
327 // We need to make a decision about where to place this window based on the | 326 // We need to make a decision about where to place this window based on the |
328 // desktop type. | 327 // desktop type. |
329 switch (chrome::GetActiveDesktop()) { | 328 switch (chrome::GetActiveDesktop()) { |
330 case chrome::HOST_DESKTOP_TYPE_NATIVE: | 329 case chrome::HOST_DESKTOP_TYPE_NATIVE: |
331 // If we're native, we should give this window its own toplevel desktop | 330 // If we're native, we should give this window its own toplevel desktop |
332 // widget. | 331 // widget. |
333 params->native_widget = new views::DesktopNativeWidgetAura(delegate); | 332 params->native_widget = new views::DesktopNativeWidgetAura(delegate); |
334 break; | 333 break; |
335 #if defined(USE_ASH) | 334 #if defined(USE_ASH) |
336 case chrome::HOST_DESKTOP_TYPE_ASH: | 335 case chrome::HOST_DESKTOP_TYPE_ASH: |
337 // If we're in ash, give this window the context of the main monitor. | 336 // If we're in ash, give this window the context of the main monitor. |
338 params->context = ash::Shell::GetPrimaryRootWindow(); | 337 params->context = ash::Shell::GetPrimaryRootWindow(); |
339 break; | 338 break; |
340 #endif | 339 #endif |
341 default: | 340 default: |
342 NOTREACHED(); | 341 NOTREACHED(); |
343 } | 342 } |
344 } else if (use_non_toplevel_window) { | 343 } else if (use_non_toplevel_window) { |
345 views::NativeWidgetAura* native_widget = | 344 views::NativeWidgetAura* native_widget = |
346 new views::NativeWidgetAura(delegate); | 345 new views::NativeWidgetAura(delegate); |
347 if (params->parent) { | 346 if (params->parent) { |
348 Profile* parent_profile = reinterpret_cast<Profile*>( | 347 Profile* parent_profile = reinterpret_cast<Profile*>( |
349 params->parent->GetNativeWindowProperty(Profile::kProfileKey)); | 348 params->parent->GetNativeWindowProperty(Profile::kProfileKey)); |
350 native_widget->SetNativeWindowProperty(Profile::kProfileKey, | 349 native_widget->SetNativeWindowProperty(Profile::kProfileKey, |
351 parent_profile); | 350 parent_profile); |
352 } | 351 } |
353 params->native_widget = native_widget; | 352 params->native_widget = native_widget; |
354 } else if (params->type != views::Widget::InitParams::TYPE_TOOLTIP) { | 353 } else { |
355 // TODO(erg): Once we've threaded context to everywhere that needs it, we | 354 // TODO(erg): Once we've threaded context to everywhere that needs it, we |
356 // should remove this check here. | 355 // should remove this check here. |
357 gfx::NativeView to_check = | 356 gfx::NativeView to_check = |
358 params->context ? params->context : params->parent; | 357 params->context ? params->context : params->parent; |
359 if (chrome::GetHostDesktopTypeForNativeView(to_check) == | 358 if (chrome::GetHostDesktopTypeForNativeView(to_check) == |
360 chrome::HOST_DESKTOP_TYPE_NATIVE) { | 359 chrome::HOST_DESKTOP_TYPE_NATIVE) { |
361 params->native_widget = new views::DesktopNativeWidgetAura(delegate); | 360 params->native_widget = new views::DesktopNativeWidgetAura(delegate); |
362 } | 361 } |
363 } | 362 } |
364 #endif | 363 #endif |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 } | 412 } |
414 #endif | 413 #endif |
415 | 414 |
416 #if !defined(USE_AURA) && !defined(USE_CHROMEOS) | 415 #if !defined(USE_AURA) && !defined(USE_CHROMEOS) |
417 views::Widget::InitParams::WindowOpacity | 416 views::Widget::InitParams::WindowOpacity |
418 ChromeViewsDelegate::GetOpacityForInitParams( | 417 ChromeViewsDelegate::GetOpacityForInitParams( |
419 const views::Widget::InitParams& params) { | 418 const views::Widget::InitParams& params) { |
420 return views::Widget::InitParams::OPAQUE_WINDOW; | 419 return views::Widget::InitParams::OPAQUE_WINDOW; |
421 } | 420 } |
422 #endif | 421 #endif |
OLD | NEW |