OLD | NEW |
(Empty) | |
| 1 // Copyright 2012 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 file. |
| 4 |
| 5 #include "chrome/browser/ui/host_desktop.h" |
| 6 |
| 7 #include "chrome/browser/ui/ash/ash_util.h" |
| 8 #include "chrome/browser/ui/browser_list_impl.h" |
| 9 |
| 10 namespace chrome { |
| 11 |
| 12 namespace { |
| 13 |
| 14 bool force_ = false; |
| 15 HostDesktopType force_type_ = HOST_DESKTOP_TYPE_COUNT; |
| 16 |
| 17 } // namespace |
| 18 |
| 19 ScopedForceDesktopType::ScopedForceDesktopType(HostDesktopType type) |
| 20 : previous_type_(force_type_), |
| 21 previous_force_(force_) { |
| 22 force_type_ = type; |
| 23 force_ = true; |
| 24 } |
| 25 |
| 26 ScopedForceDesktopType::~ScopedForceDesktopType() { |
| 27 force_type_ = previous_type_; |
| 28 force_ = previous_force_; |
| 29 } |
| 30 |
| 31 HostDesktopType GetHostDesktopTypeForNativeView(gfx::NativeView native_view) { |
| 32 if (force_) |
| 33 return force_type_; |
| 34 return IsNativeViewInAsh(native_view) ? |
| 35 HOST_DESKTOP_TYPE_ASH : |
| 36 HOST_DESKTOP_TYPE_NATIVE; |
| 37 } |
| 38 |
| 39 HostDesktopType GetHostDesktopTypeForNativeWindow( |
| 40 gfx::NativeWindow native_window) { |
| 41 if (force_) |
| 42 return force_type_; |
| 43 return IsNativeWindowInAsh(native_window) ? |
| 44 HOST_DESKTOP_TYPE_ASH : |
| 45 HOST_DESKTOP_TYPE_NATIVE; |
| 46 } |
| 47 |
| 48 HostDesktopType GetHostDesktopTypeForBrowser(const Browser* browser) { |
| 49 if (force_) |
| 50 return force_type_; |
| 51 for (HostDesktopType type = HOST_DESKTOP_TYPE_FIRST; |
| 52 type < HOST_DESKTOP_TYPE_COUNT; |
| 53 type = static_cast<HostDesktopType>(type + 1)) { |
| 54 BrowserListImpl::const_iterator begin = |
| 55 BrowserListImpl::GetInstance(type)->begin(); |
| 56 BrowserListImpl::const_iterator end = |
| 57 BrowserListImpl::GetInstance(type)->end(); |
| 58 if (find(begin, end, browser) != end) |
| 59 return type; |
| 60 } |
| 61 return HOST_DESKTOP_TYPE_NATIVE; |
| 62 } |
| 63 |
| 64 } |
OLD | NEW |