blob: 21b7fbb6f995cc462d99b4a12d42a279564e182d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/apps/native_app_window_views_win.h"
#include "apps/shell_window.h"
#include "apps/shell_window_registry.h"
#include "ash/shell.h"
#include "chrome/browser/apps/per_app_settings_service.h"
#include "chrome/browser/apps/per_app_settings_service_factory.h"
#include "chrome/browser/metro_utils/metro_chrome_win.h"
#include "extensions/common/extension.h"
#include "ui/aura/remote_root_window_host_win.h"
#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
NativeAppWindowViewsWin::NativeAppWindowViewsWin() {
}
void NativeAppWindowViewsWin::ActivateParentDesktopIfNecessary() {
if (!ash::Shell::HasInstance())
return;
views::Widget* widget =
implicit_cast<views::WidgetDelegate*>(this)->GetWidget();
chrome::HostDesktopType host_desktop_type =
chrome::GetHostDesktopTypeForNativeWindow(widget->GetNativeWindow());
// Only switching into Ash from Native is supported. Tearing the user out of
// Metro mode can only be done by launching a process from Metro mode itself.
// This is done for launching apps, but not regular activations.
if (host_desktop_type == chrome::HOST_DESKTOP_TYPE_ASH &&
chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_NATIVE) {
chrome::ActivateMetroChrome();
}
}
void NativeAppWindowViewsWin::OnBeforeWidgetInit(
views::Widget::InitParams* init_params, views::Widget* widget) {
// If an app has any existing windows, ensure new ones are created on the
// same desktop.
apps::ShellWindow* any_existing_window =
apps::ShellWindowRegistry::Get(browser_context())
->GetCurrentShellWindowForApp(extension()->id());
chrome::HostDesktopType desktop_type;
if (any_existing_window) {
desktop_type = chrome::GetHostDesktopTypeForNativeWindow(
any_existing_window->GetNativeWindow());
} else {
PerAppSettingsService* settings =
PerAppSettingsServiceFactory::GetForBrowserContext(browser_context());
if (settings->HasDesktopLastLaunchedFrom(extension()->id())) {
desktop_type = settings->GetDesktopLastLaunchedFrom(extension()->id());
} else {
// We don't know what desktop this app was last launched from, so take our
// best guess as to what desktop the user is on.
desktop_type = chrome::GetActiveDesktop();
}
}
if (desktop_type == chrome::HOST_DESKTOP_TYPE_ASH)
init_params->context = ash::Shell::GetPrimaryRootWindow();
else
init_params->native_widget = new views::DesktopNativeWidgetAura(widget);
}
void NativeAppWindowViewsWin::Show() {
ActivateParentDesktopIfNecessary();
NativeAppWindowViews::Show();
}
void NativeAppWindowViewsWin::Activate() {
ActivateParentDesktopIfNecessary();
NativeAppWindowViews::Activate();
}
|