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