Commit 5a703633 authored by Jun Mukai's avatar Jun Mukai Committed by Commit Bot

Remove ash_shell

ash_shell (and ash_shell_with_content) were introduced for
quick-checking of ash behaviors, as it's fast to build. However,
it's not used by many people, and I've noticed that it's broken
in many ways.

I believe no one is using it actually, so I think it's the time
to remove it at all.

ash_ui_perftests, which depends on ash_shell_lib_with_content,
is also removed, as it was introduced for a purpose but isn't
used actually.

Bug: none
Test: build passes
Change-Id: I68d4de5b0172f51240a99e61facbe4f7ee606ed4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2307909Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Jun Mukai <mukai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790124}
parent d845f3e7
......@@ -439,7 +439,6 @@ group("gn_all") {
if (is_chromeos) {
deps += [
"//ash:ash_shell_with_content",
"//ash:ash_unittests",
"//ash/app_list:app_list_demo",
"//ash/app_list:app_list_unittests",
......
......@@ -1686,125 +1686,6 @@ component("ash") {
}
}
static_library("ash_shell_lib") {
testonly = true
sources = [
"../ui/views/test/test_views_delegate_aura.cc",
"shell/bubble.cc",
"shell/example_app_list_client.cc",
"shell/example_app_list_client.h",
"shell/example_factory.h",
"shell/example_session_controller_client.cc",
"shell/example_session_controller_client.h",
"shell/lock_view.cc",
"shell/shell_delegate_impl.cc",
"shell/shell_delegate_impl.h",
"shell/shell_views_delegate.cc",
"shell/shell_views_delegate.h",
"shell/toplevel_window.cc",
"shell/toplevel_window.h",
"shell/widgets.cc",
"shell/window_type_launcher.cc",
"shell/window_type_launcher.h",
"shell/window_watcher.cc",
"shell/window_watcher.h",
"shell/window_watcher_shelf_item_delegate.cc",
"shell/window_watcher_shelf_item_delegate.h",
]
# Usage of content should be in ash_shell_lib_with_content.
assert_no_deps = [
"//ash/public/cpp/external_arc",
"//components/arc",
"//components/exo",
"//content/public/browser",
"//content/public/common",
]
deps = [
":ash",
":test_support",
"//ash/app_list",
"//ash/public/cpp",
"//base",
"//base:i18n",
"//components/user_manager",
"//skia",
"//ui/aura",
"//ui/base",
"//ui/gfx",
"//ui/gfx/geometry",
"//ui/message_center",
"//ui/views",
"//ui/views:test_support",
"//ui/views/examples:views_examples_lib",
"//ui/wm",
]
}
static_library("ash_shell_lib_with_content") {
testonly = true
sources = [
"shell/content/client/shell_browser_main_parts.cc",
"shell/content/client/shell_browser_main_parts.h",
"shell/content/client/shell_content_browser_client.cc",
"shell/content/client/shell_content_browser_client.h",
"shell/content/client/shell_main_delegate.cc",
"shell/content/client/shell_main_delegate.h",
"shell/content/client/shell_new_window_delegate.cc",
"shell/content/client/shell_new_window_delegate.h",
"shell/content/embedded_browser.cc",
"shell/content/embedded_browser.h",
]
deps = [
":test_support",
"//ash/public/cpp",
"//ash/shortcut_viewer",
"//base:i18n",
"//chrome:packed_resources",
# TODO(https://crbug.com/644336): Make CrasAudioHandler Chrome or Ash only.
"//chromeos/audio",
"//chromeos/constants",
"//chromeos/dbus/biod",
"//chromeos/dbus/power",
"//chromeos/dbus/shill",
"//chromeos/network",
"//chromeos/services/network_config",
"//chromeos/services/network_config/public/mojom",
"//chromeos/system",
"//components/discardable_memory/public/mojom",
"//components/services/font:lib",
"//components/services/font/public/mojom",
"//content",
"//content/shell:content_shell_lib",
"//device/bluetooth",
"//net",
"//services/device/public/mojom",
"//skia",
"//ui/aura",
"//ui/base",
"//ui/base/ime/chromeos",
"//ui/base/ime/init",
"//ui/chromeos/events",
"//ui/compositor",
"//ui/display",
"//ui/events/devices",
"//ui/message_center",
"//ui/views:test_support",
"//ui/views/controls/webview",
"//ui/views/examples:views_examples_with_content_lib",
"//ui/wm",
]
public_deps = [ ":ash_shell_lib" ]
data_deps = [
"//ash/resources:ash_test_resources_200_percent",
"//ash/resources:ash_test_resources_with_content_100_percent",
"//ash/strings:ash_test_strings",
]
}
action("dbus_service_files") {
sources = [
"dbus/org.chromium.DisplayService.conf",
......@@ -2369,53 +2250,6 @@ test("ash_perftests") {
]
}
test("ash_ui_perftests") {
defines = [ "HAS_OUT_OF_PROC_TEST_RUNNER" ]
sources = [
"perftests/overview_animations_preftest.cc",
"shell/content/test/ash_content_perf_test_launcher.cc",
"shell/content/test/ash_content_test.cc",
"shell/content/test/ash_content_test.h",
]
deps = [
":ash_shell_lib_with_content",
":test_support",
"//ash/public/cpp",
"//base/test:test_support",
"//cc/base",
"//chromeos/constants:constants",
"//content/shell:content_shell_app",
"//content/shell:content_shell_lib",
"//content/test:browsertest_support",
"//content/test:test_support",
"//mojo/core/embedder",
"//testing/gtest",
"//testing/perf",
"//ui/aura",
"//ui/base",
"//ui/base:test_support",
"//ui/compositor:test_support",
"//ui/events:test_support",
"//ui/gl:test_support",
]
}
executable("ash_shell_with_content") {
testonly = true
sources = [ "shell/content/shell_with_content_main.cc" ]
deps = [
":ash_shell_lib_with_content",
"//base",
"//components/user_manager",
"//content",
"//content/public/app",
"//device/bluetooth",
]
}
static_library("test_support") {
testonly = true
friend = [
......@@ -2499,8 +2333,6 @@ static_library("test_support") {
"shelf/shelf_view_test_api.h",
"shelf/test/widget_animation_waiter.cc",
"shelf/test/widget_animation_waiter.h",
"shell/toplevel_window.cc",
"shell/toplevel_window.h",
"shell_test_api.cc",
"system/message_center/test_notifier_settings_controller.cc",
"system/message_center/test_notifier_settings_controller.h",
......@@ -2527,6 +2359,8 @@ static_library("test_support") {
"test/ash_test_views_delegate.h",
"test/fake_android_intent_helper.cc",
"test/fake_android_intent_helper.h",
"test/toplevel_window.cc",
"test/toplevel_window.h",
"test/ui_controls_factory_ash.cc",
"test/ui_controls_factory_ash.h",
"test_media_client.cc",
......
// Copyright 2019 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 "ash/public/cpp/test/shell_test_api.h"
#include "ash/shell/content/test/ash_content_test.h"
#include "base/macros.h"
#include "base/run_loop.h"
#include "base/system/sys_info.h"
#include "base/threading/thread_task_runner_handle.h"
#include "ui/base/test/ui_controls.h"
// Test overview enter/exit animations with following conditions
// int: number of windows : 2, 8
// bool: the window type (browser window with content, or non browser window)
// bool: tablet mode, if true.
// TODO(oshima): Add Tablet/SplitView mode.
class OverviewAnimationsTest
: public AshContentTest,
public testing::WithParamInterface<::testing::tuple<int, bool, bool>> {
public:
OverviewAnimationsTest() = default;
~OverviewAnimationsTest() override = default;
// AshContentTest:
void SetUpOnMainThread() override {
AshContentTest::SetUpOnMainThread();
int n_browsers = std::get<0>(GetParam());
bool browser = std::get<1>(GetParam());
tablet_mode_ = std::get<2>(GetParam());
if (tablet_mode_)
ash::ShellTestApi().SetTabletModeEnabledForTest(true);
const GURL google_url("https://www.google.com");
for (int i = 0; i < n_browsers; ++i) {
auto* window = browser ? CreateBrowserWindow(google_url)
: CreateBrowserWindow(GURL());
if (!window_)
window_ = window;
}
float cost_per_browser = browser ? 0.5 : 0.1;
int wait_seconds = (base::SysInfo::IsRunningOnChromeOS() ? 5 : 0) +
n_browsers * cost_per_browser;
base::RunLoop run_loop;
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, run_loop.QuitClosure(),
base::TimeDelta::FromSeconds(wait_seconds));
run_loop.Run();
}
// UIPerformanceTest:
std::vector<std::string> GetUMAHistogramNames() const override {
if (tablet_mode_) {
return {"Ash.Overview.AnimationSmoothness.Enter.TabletMode",
"Ash.Overview.AnimationSmoothness.Exit.TabletMode"};
}
return {"Ash.Overview.AnimationSmoothness.Enter.ClamshellMode",
"Ash.Overview.AnimationSmoothness.Exit.ClamshellMode"};
}
aura::Window* window() { return window_; }
private:
aura::Window* window_ = nullptr;
bool tablet_mode_ = false;
DISALLOW_COPY_AND_ASSIGN(OverviewAnimationsTest);
};
ASH_CONTENT_TEST_P(OverviewAnimationsTest, EnterExit) {
TRACE_EVENT_NESTABLE_ASYNC_BEGIN0("ui", "Interaction.ui_Overview", this);
// Browser window is used just to identify display.
ui_controls::SendKeyPress(window(), ui::VKEY_MEDIA_LAUNCH_APP1,
/*control=*/false,
/*shift=*/false,
/*alt=*/false,
/*command=*/false);
ash::ShellTestApi().WaitForOverviewAnimationState(
ash::OverviewAnimationState::kEnterAnimationComplete);
// TODO(oshima): Wait until frame animation ends.
ui_controls::SendKeyPress(window(), ui::VKEY_MEDIA_LAUNCH_APP1,
/*control=*/false,
/*shift=*/false,
/*alt=*/false,
/*command=*/false);
ash::ShellTestApi().WaitForOverviewAnimationState(
ash::OverviewAnimationState::kExitAnimationComplete);
TRACE_EVENT_NESTABLE_ASYNC_END0("ui", "Interaction.ui_Overview", this);
}
INSTANTIATE_TEST_SUITE_P(All,
OverviewAnimationsTest,
::testing::Combine(::testing::Values(2, 8),
/*blank=*/testing::Bool(),
/*tablet=*/testing::Bool()));
include_rules = [
"+content/public",
"+content/shell",
"+gin",
"+sandbox",
]
per-file *app_list*=xiyuan@chromium.org
// Copyright (c) 2011 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 "base/strings/utf_string_conversions.h"
#include "ui/views/bubble/bubble_border.h"
#include "ui/views/bubble/bubble_dialog_delegate_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/widget/widget.h"
namespace ash {
namespace shell {
struct BubbleConfig {
base::string16 label;
views::View* anchor_view;
views::BubbleBorder::Arrow arrow;
};
class ExampleBubbleDialogDelegateView : public views::BubbleDialogDelegateView {
public:
explicit ExampleBubbleDialogDelegateView(const BubbleConfig& config);
~ExampleBubbleDialogDelegateView() override;
void Init() override {
SetLayoutManager(std::make_unique<views::FillLayout>());
views::Label* label = new views::Label(label_);
AddChildView(label);
}
private:
base::string16 label_;
};
ExampleBubbleDialogDelegateView::ExampleBubbleDialogDelegateView(
const BubbleConfig& config)
: BubbleDialogDelegateView(config.anchor_view, config.arrow),
label_(config.label) {}
ExampleBubbleDialogDelegateView::~ExampleBubbleDialogDelegateView() = default;
void CreatePointyBubble(views::View* anchor_view) {
BubbleConfig config;
config.label = base::ASCIIToUTF16("Pointy Dialog Bubble");
config.anchor_view = anchor_view;
config.arrow = views::BubbleBorder::TOP_LEFT;
ExampleBubbleDialogDelegateView* bubble =
new ExampleBubbleDialogDelegateView(config);
views::BubbleDialogDelegateView::CreateBubble(bubble)->Show();
}
} // namespace shell
} // namespace ash
include_rules = [
"+ash/components/shortcut_viewer",
"+chromeos/dbus/biod",
"+chromeos/services/network_config",
"+components/discardable_memory/public/interfaces",
"+content/public",
"+content/shell",
"+storage/browser/quota",
"+services/device/public",
]
// Copyright (c) 2012 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 "ash/shell/content/client/shell_browser_main_parts.h"
#include <memory>
#include <utility>
#include "ash/display/privacy_screen_controller.h"
#include "ash/login_status.h"
#include "ash/public/cpp/event_rewriter_controller.h"
#include "ash/session/test_pref_service_provider.h"
#include "ash/shell.h"
#include "ash/shell/content/client/shell_new_window_delegate.h"
#include "ash/shell/content/embedded_browser.h"
#include "ash/shell/example_app_list_client.h"
#include "ash/shell/example_session_controller_client.h"
#include "ash/shell/shell_delegate_impl.h"
#include "ash/shell/shell_views_delegate.h"
#include "ash/shell/window_type_launcher.h"
#include "ash/shell/window_watcher.h"
#include "ash/sticky_keys/sticky_keys_controller.h"
#include "ash/test/ash_test_helper.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/run_loop.h"
#include "chromeos/dbus/biod/biod_client.h"
#include "chromeos/dbus/shill/shill_clients.h"
#include "chromeos/network/network_handler.h"
#include "components/exo/file_helper.h"
#include "content/public/browser/context_factory.h"
#include "content/public/common/content_switches.h"
#include "content/shell/browser/shell_browser_context.h"
#include "net/base/net_module.h"
#include "ui/base/ui_base_features.h"
#include "ui/chromeos/events/event_rewriter_chromeos.h"
#include "ui/views/examples/examples_window_with_content.h"
namespace ash {
namespace shell {
namespace {
ShellBrowserMainParts* main_parts = nullptr;
}
// static
content::BrowserContext* ShellBrowserMainParts::GetBrowserContext() {
DCHECK(main_parts);
return main_parts->browser_context();
}
ShellBrowserMainParts::ShellBrowserMainParts(
const content::MainFunctionParams& parameters)
: parameters_(parameters) {
DCHECK(!main_parts);
main_parts = this;
}
ShellBrowserMainParts::~ShellBrowserMainParts() {
DCHECK(main_parts);
main_parts = nullptr;
}
void ShellBrowserMainParts::PostEarlyInitialization() {
content::BrowserMainParts::PostEarlyInitialization();
chromeos::shill_clients::InitializeFakes();
chromeos::NetworkHandler::Initialize();
}
void ShellBrowserMainParts::PreMainMessageLoopStart() {}
void ShellBrowserMainParts::PostMainMessageLoopStart() {
chromeos::BiodClient::InitializeFake();
}
void ShellBrowserMainParts::ToolkitInitialized() {
// A ViewsDelegate is required.
views_delegate_ = std::make_unique<ShellViewsDelegate>();
}
void ShellBrowserMainParts::PreMainMessageLoopRun() {
browser_context_.reset(new content::ShellBrowserContext(false));
if (!parameters_.ui_task)
new_window_delegate_ = std::make_unique<ShellNewWindowDelegate>();
// TODO(oshima): Separate the class for ash_shell to reduce the test binary
// size.
ash_test_helper_ = std::make_unique<AshTestHelper>(
parameters_.ui_task ? AshTestHelper::kPerfTest : AshTestHelper::kShell,
content::GetContextFactory());
AshTestHelper::InitParams init_params;
init_params.delegate = std::make_unique<ShellDelegateImpl>();
ash_test_helper_->SetUp(std::move(init_params));
window_watcher_ = std::make_unique<WindowWatcher>();
if (!parameters_.ui_task) {
// Install Rewriter so that function keys are properly re-mapped.
auto* event_rewriter_controller = EventRewriterController::Get();
bool privacy_screen_supported = false;
if (Shell::Get()->privacy_screen_controller() &&
Shell::Get()->privacy_screen_controller()->IsSupported()) {
privacy_screen_supported = true;
}
event_rewriter_controller->AddEventRewriter(
std::make_unique<ui::EventRewriterChromeOS>(
nullptr, Shell::Get()->sticky_keys_controller(),
privacy_screen_supported));
// Initialize session controller client and create fake user sessions. The
// fake user sessions makes ash into the logged in state.
example_session_controller_client_ =
std::make_unique<ExampleSessionControllerClient>(
Shell::Get()->session_controller(),
ash_test_helper_->prefs_provider());
example_session_controller_client_->Initialize();
example_app_list_client_ = std::make_unique<ExampleAppListClient>(
Shell::Get()->app_list_controller());
InitWindowTypeLauncher(
base::BindRepeating(views::examples::ShowExamplesWindowWithContent,
base::Passed(base::OnceClosure()),
base::Unretained(browser_context_.get()), nullptr),
base::BindRepeating(base::IgnoreResult(&EmbeddedBrowser::Create),
base::Unretained(browser_context_.get()),
GURL("https://www.google.com"), base::nullopt));
}
}
bool ShellBrowserMainParts::MainMessageLoopRun(int* result_code) {
if (parameters_.ui_task) {
std::move(*parameters_.ui_task).Run();
delete parameters_.ui_task;
} else {
base::RunLoop run_loop;
example_session_controller_client_->set_quit_closure(
run_loop.QuitWhenIdleClosure());
run_loop.Run();
}
return true;
}
void ShellBrowserMainParts::PostMainMessageLoopRun() {
window_watcher_.reset();
example_app_list_client_.reset();
example_session_controller_client_.reset();
ash_test_helper_.reset();
views_delegate_.reset();
// The keyboard may have created a WebContents. The WebContents is destroyed
// with the UI, and it needs the BrowserContext to be alive during its
// destruction. So destroy all of the UI elements before destroying the
// browser context.
browser_context_.reset();
}
void ShellBrowserMainParts::PostDestroyThreads() {
chromeos::NetworkHandler::Shutdown();
chromeos::shill_clients::Shutdown();
content::BrowserMainParts::PostDestroyThreads();
}
} // namespace shell
} // namespace ash
// Copyright (c) 2012 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.
#ifndef ASH_SHELL_CONTENT_CLIENT_SHELL_BROWSER_MAIN_PARTS_H_
#define ASH_SHELL_CONTENT_CLIENT_SHELL_BROWSER_MAIN_PARTS_H_
#include <memory>
#include "base/macros.h"
#include "content/public/browser/browser_main_parts.h"
#include "content/public/common/main_function_params.h"
#include "mojo/public/cpp/system/message_pipe.h"
namespace content {
class BrowserContext;
struct MainFunctionParams;
} // namespace content
namespace views {
class ViewsDelegate;
}
namespace ash {
class AshTestHelper;
namespace shell {
class ExampleAppListClient;
class ExampleSessionControllerClient;
class ShellNewWindowDelegate;
class WindowWatcher;
class ShellBrowserMainParts : public content::BrowserMainParts {
public:
static content::BrowserContext* GetBrowserContext();
explicit ShellBrowserMainParts(const content::MainFunctionParams& parameters);
~ShellBrowserMainParts() override;
// Overridden from content::BrowserMainParts:
void PostEarlyInitialization() override;
void PreMainMessageLoopStart() override;
void PostMainMessageLoopStart() override;
void ToolkitInitialized() override;
void PreMainMessageLoopRun() override;
bool MainMessageLoopRun(int* result_code) override;
void PostMainMessageLoopRun() override;
void PostDestroyThreads() override;
content::BrowserContext* browser_context() { return browser_context_.get(); }
private:
std::unique_ptr<content::BrowserContext> browser_context_;
std::unique_ptr<views::ViewsDelegate> views_delegate_;
std::unique_ptr<WindowWatcher> window_watcher_;
std::unique_ptr<ExampleSessionControllerClient>
example_session_controller_client_;
std::unique_ptr<ExampleAppListClient> example_app_list_client_;
std::unique_ptr<ash::AshTestHelper> ash_test_helper_;
std::unique_ptr<ShellNewWindowDelegate> new_window_delegate_;
content::MainFunctionParams parameters_;
DISALLOW_COPY_AND_ASSIGN(ShellBrowserMainParts);
};
} // namespace shell
} // namespace ash
#endif // ASH_SHELL_CONTENT_CLIENT_SHELL_BROWSER_MAIN_PARTS_H_
// Copyright (c) 2012 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 "ash/shell/content/client/shell_content_browser_client.h"
#include <memory>
#include <utility>
#include "ash/public/cpp/window_properties.h"
#include "ash/shell.h"
#include "ash/shell/content/client/shell_browser_main_parts.h"
#include "base/base_switches.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/no_destructor.h"
#include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h"
#include "content/public/browser/browser_context.h"
#include "content/public/utility/content_utility_client.h"
#include "third_party/skia/include/core/SkBitmap.h"
namespace ash {
namespace shell {
ShellContentBrowserClient::ShellContentBrowserClient() = default;
ShellContentBrowserClient::~ShellContentBrowserClient() = default;
std::unique_ptr<content::BrowserMainParts>
ShellContentBrowserClient::CreateBrowserMainParts(
const content::MainFunctionParams& parameters) {
return std::make_unique<ShellBrowserMainParts>(parameters);
}
} // namespace shell
} // namespace ash
// Copyright (c) 2012 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.
#ifndef ASH_SHELL_CONTENT_CLIENT_SHELL_CONTENT_BROWSER_CLIENT_H_
#define ASH_SHELL_CONTENT_CLIENT_SHELL_CONTENT_BROWSER_CLIENT_H_
#include <memory>
#include <string>
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "content/public/browser/content_browser_client.h"
namespace ash {
namespace shell {
class ShellContentBrowserClient : public content::ContentBrowserClient {
public:
ShellContentBrowserClient();
~ShellContentBrowserClient() override;
// Overridden from content::ContentBrowserClient:
std::unique_ptr<content::BrowserMainParts> CreateBrowserMainParts(
const content::MainFunctionParams& parameters) override;
private:
DISALLOW_COPY_AND_ASSIGN(ShellContentBrowserClient);
};
} // namespace shell
} // namespace ash
#endif // ASH_SHELL_CONTENT_CLIENT_SHELL_CONTENT_BROWSER_CLIENT_H_
// Copyright (c) 2012 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 "ash/shell/content/client/shell_main_delegate.h"
#include "ash/shell/content/client/shell_content_browser_client.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "content/public/utility/utility_thread.h"
#include "ui/base/ime/init/input_method_initializer.h"
#include "ui/base/resource/resource_bundle.h"
namespace ash {
namespace shell {
ShellMainDelegate::ShellMainDelegate() = default;
ShellMainDelegate::~ShellMainDelegate() = default;
void ShellMainDelegate::PreSandboxStartup() {
InitializeResourceBundle();
ui::InitializeInputMethodForTesting();
}
content::ContentClient* ShellMainDelegate::CreateContentClient() {
return &content_client_;
}
content::ContentBrowserClient* ShellMainDelegate::CreateContentBrowserClient() {
browser_client_.reset(new ShellContentBrowserClient);
return browser_client_.get();
}
void ShellMainDelegate::InitializeResourceBundle() {
// Load ash resources and strings; not 'common' (Chrome) resources.
base::FilePath path;
base::PathService::Get(base::DIR_MODULE, &path);
base::FilePath ash_test_strings =
path.Append(FILE_PATH_LITERAL("ash_test_strings.pak"));
ui::ResourceBundle::InitSharedInstanceWithPakPath(ash_test_strings);
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
if (ui::ResourceBundle::IsScaleFactorSupported(ui::SCALE_FACTOR_100P)) {
base::FilePath ash_test_resources_100 = path.Append(
FILE_PATH_LITERAL("ash_test_resources_with_content_100_percent.pak"));
rb.AddDataPackFromPath(ash_test_resources_100, ui::SCALE_FACTOR_100P);
}
if (ui::ResourceBundle::IsScaleFactorSupported(ui::SCALE_FACTOR_200P)) {
base::FilePath ash_test_resources_200 =
path.Append(FILE_PATH_LITERAL("ash_test_resources_200_percent.pak"));
rb.AddDataPackFromPath(ash_test_resources_200, ui::SCALE_FACTOR_200P);
}
}
} // namespace shell
} // namespace ash
// Copyright (c) 2012 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.
#ifndef ASH_SHELL_CONTENT_CLIENT_SHELL_MAIN_DELEGATE_H_
#define ASH_SHELL_CONTENT_CLIENT_SHELL_MAIN_DELEGATE_H_
#include <memory>
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "content/public/app/content_main_delegate.h"
#include "content/shell/common/shell_content_client.h"
namespace ash {
namespace shell {
class ShellContentBrowserClient;
class ShellMainDelegate : public content::ContentMainDelegate {
public:
ShellMainDelegate();
~ShellMainDelegate() override;
void PreSandboxStartup() override;
content::ContentClient* CreateContentClient() override;
content::ContentBrowserClient* CreateContentBrowserClient() override;
private:
void InitializeResourceBundle();
std::unique_ptr<ShellContentBrowserClient> browser_client_;
content::ShellContentClient content_client_;
DISALLOW_COPY_AND_ASSIGN(ShellMainDelegate);
};
} // namespace shell
} // namespace ash
#endif // ASH_SHELL_CONTENT_CLIENT_SHELL_MAIN_DELEGATE_H_
// Copyright 2019 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 "ash/shell/content/client/shell_new_window_delegate.h"
#include "ash/public/cpp/keyboard_shortcut_viewer.h"
#include "ash/shell/content/client/shell_browser_main_parts.h"
#include "ash/shell/content/embedded_browser.h"
namespace ash {
namespace shell {
ShellNewWindowDelegate::ShellNewWindowDelegate() = default;
ShellNewWindowDelegate::~ShellNewWindowDelegate() = default;
void ShellNewWindowDelegate::NewTab() {
EmbeddedBrowser::Create(
ash::shell::ShellBrowserMainParts::GetBrowserContext(),
GURL("https://www.google.com"));
}
void ShellNewWindowDelegate::NewTabWithUrl(const GURL& url,
bool from_user_interaction) {
EmbeddedBrowser::Create(
ash::shell::ShellBrowserMainParts::GetBrowserContext(), url);
}
void ShellNewWindowDelegate::NewWindow(bool incognito) {
EmbeddedBrowser::Create(
ash::shell::ShellBrowserMainParts::GetBrowserContext(),
GURL("https://www.google.com"));
}
void ShellNewWindowDelegate::OpenFileManager() {}
void ShellNewWindowDelegate::OpenCrosh() {}
void ShellNewWindowDelegate::OpenGetHelp() {}
void ShellNewWindowDelegate::RestoreTab() {}
void ShellNewWindowDelegate::ShowKeyboardShortcutViewer() {
ash::ToggleKeyboardShortcutViewer();
}
void ShellNewWindowDelegate::ShowTaskManager() {}
void ShellNewWindowDelegate::OpenFeedbackPage(bool from_assistant) {}
} // namespace shell
} // namespace ash
// Copyright 2019 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.
#ifndef ASH_SHELL_CONTENT_CLIENT_SHELL_NEW_WINDOW_DELEGATE_H_
#define ASH_SHELL_CONTENT_CLIENT_SHELL_NEW_WINDOW_DELEGATE_H_
#include <memory>
#include <string>
#include "ash/public/cpp/new_window_delegate.h"
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "content/public/browser/content_browser_client.h"
namespace ash {
namespace shell {
class ShellNewWindowDelegate : public ash::NewWindowDelegate {
public:
ShellNewWindowDelegate();
~ShellNewWindowDelegate() override;
// ash::NewWindowDelegate:
void NewTab() override;
void NewTabWithUrl(const GURL& url, bool from_user_interaction) override;
void NewWindow(bool incognito) override;
void OpenFileManager() override;
void OpenCrosh() override;
void OpenGetHelp() override;
void RestoreTab() override;
void ShowKeyboardShortcutViewer() override;
void ShowTaskManager() override;
void OpenFeedbackPage(bool from_assistant) override;
private:
DISALLOW_COPY_AND_ASSIGN(ShellNewWindowDelegate);
};
} // namespace shell
} // namespace ash
#endif // ASH_SHELL_CONTENT_CLIENT_SHELL_NEW_WINDOW_DELEGATE_H_
// Copyright 2019 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 "ash/shell/content/embedded_browser.h"
#include "ash/public/cpp/app_types.h"
#include "ash/wm/window_state.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/views/controls/webview/webview.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
#include "url/gurl.h"
namespace ash {
namespace shell {
namespace {
class BrowserWidgetDelegateView : public views::WidgetDelegateView {
public:
BrowserWidgetDelegateView(content::BrowserContext* context, const GURL& url) {
SetCanMaximize(true);
SetCanMinimize(true);
SetCanResize(true);
SetTitle(base::ASCIIToUTF16("WebView Browser"));
SetLayoutManager(std::make_unique<views::FillLayout>());
auto* webview = new views::WebView(context);
AddChildView(webview);
Layout();
webview->LoadInitialURL(url);
}
~BrowserWidgetDelegateView() override = default;
private:
DISALLOW_COPY_AND_ASSIGN(BrowserWidgetDelegateView);
};
} // namespace
EmbeddedBrowser::EmbeddedBrowser(content::BrowserContext* context,
const GURL& url,
const gfx::Rect& bounds)
: widget_(new views::Widget) {
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.bounds = bounds;
params.delegate = new BrowserWidgetDelegateView(context, url);
widget_->Init(std::move(params));
WindowState::Get(widget_->GetNativeWindow())->SetWindowPositionManaged(true);
widget_->Show();
}
EmbeddedBrowser::~EmbeddedBrowser() = default;
aura::Window* EmbeddedBrowser::GetWindow() {
return widget_->GetNativeView();
}
// static
aura::Window* EmbeddedBrowser::Create(content::BrowserContext* context,
const GURL& url,
base::Optional<gfx::Rect> bounds) {
static const gfx::Rect default_bounds(20, 20, 800, 600);
// EmbeddedBrowser deletes itself when the widget is closed.
aura::Window* browser_window =
(new EmbeddedBrowser(context, url, bounds ? *bounds : default_bounds))
->GetWindow();
browser_window->SetProperty(aura::client::kAppType,
static_cast<int>(ash::AppType::BROWSER));
return browser_window;
}
void EmbeddedBrowser::OnUnembed() {
delete this;
}
} // namespace shell
} // namespace ash
// Copyright 2019 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.
#ifndef ASH_SHELL_CONTENT_EMBEDDED_BROWSER_H_
#define ASH_SHELL_CONTENT_EMBEDDED_BROWSER_H_
#include <memory>
#include "base/macros.h"
#include "base/optional.h"
#include "ui/gfx/geometry/rect.h"
class GURL;
namespace aura {
class Window;
}
namespace content {
class BrowserContext;
}
namespace views {
class Widget;
}
namespace ash {
namespace shell {
// Exercises ServerRemoteViewHost to embed a content::WebContents.
class EmbeddedBrowser {
public:
aura::Window* GetWindow();
// Factory.
static aura::Window* Create(content::BrowserContext* context,
const GURL& url,
base::Optional<gfx::Rect> bounds = base::nullopt);
private:
EmbeddedBrowser(content::BrowserContext* context,
const GURL& url,
const gfx::Rect& bounds);
~EmbeddedBrowser();
// Callback invoked when the embedding is broken.
void OnUnembed();
views::Widget* widget_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(EmbeddedBrowser);
};
} // namespace shell
} // namespace ash
#endif // ASH_SHELL_CONTENT_EMBEDDED_BROWSER_H_
// Copyright (c) 2012 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 "ash/shell/content/client/shell_main_delegate.h"
#include "base/at_exit.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "content/public/app/content_main.h"
int main(int argc, const char** argv) {
base::CommandLine::Init(argc, argv);
base::AtExitManager exit_manager;
base::FilePath log_filename;
base::PathService::Get(base::DIR_EXE, &log_filename);
log_filename = log_filename.AppendASCII("ash_shell.log");
logging::LoggingSettings settings;
settings.logging_dest = logging::LOG_TO_ALL;
settings.log_file_path = log_filename.value().c_str();
settings.delete_old = logging::DELETE_OLD_LOG_FILE;
logging::InitLogging(settings);
logging::SetLogItems(true /* process_id */, true /* thread_id */,
true /* timestamp */, false /* tick_count */);
ash::shell::ShellMainDelegate delegate;
content::ContentMainParams params(&delegate);
params.argc = argc;
params.argv = argv;
return content::ContentMain(params);
}
include_rules = [
"+services/tracing/public/cpp"
]
// Copyright 2019 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 "content/public/test/test_launcher.h"
#include "ash/shell/content/client/shell_main_delegate.h"
#include "ash/test/ui_controls_factory_ash.h"
#include "base/base_paths.h"
#include "base/command_line.h"
#include "base/i18n/icu_util.h"
#include "base/macros.h"
#include "base/system/sys_info.h"
#include "base/test/launcher/test_launcher.h"
#include "base/test/test_suite.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/content_test_suite_base.h"
#include "content/shell/app/shell_main_delegate.h"
#include "content/shell/common/shell_switches.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/test/ui_controls.h"
namespace {
class AshContentTestSuite : public content::ContentTestSuiteBase {
public:
AshContentTestSuite(int argc, char** argv)
: ContentTestSuiteBase(argc, argv) {}
~AshContentTestSuite() override {}
protected:
// content::ContentTestSuiteBase:
void Initialize() override {
// Browser tests are expected not to tear-down various globals.
base::TestSuite::DisableCheckForLeakedGlobals();
ContentTestSuiteBase::Initialize();
ui_controls::InstallUIControlsAura(ash::test::CreateAshUIControls());
}
DISALLOW_COPY_AND_ASSIGN(AshContentTestSuite);
};
class AshContentPerfTestLauncherDelegate : public content::TestLauncherDelegate {
public:
AshContentPerfTestLauncherDelegate() {}
~AshContentPerfTestLauncherDelegate() override {}
// content::TestLancherDelegate:
int RunTestSuite(int argc, char** argv) override {
return AshContentTestSuite(argc, argv).Run();
}
std::string GetUserDataDirectoryCommandLineSwitch() override {
return switches::kContentShellDataPath;
}
protected:
content::ContentMainDelegate* CreateContentMainDelegate() override {
return new ash::shell::ShellMainDelegate();
}
private:
DISALLOW_COPY_AND_ASSIGN(AshContentPerfTestLauncherDelegate);
};
} // namespace
int main(int argc, char** argv) {
base::CommandLine::Init(argc, argv);
AshContentPerfTestLauncherDelegate launcher_delegate;
// Perf tests should run all tests sequentially.
return LaunchTests(&launcher_delegate, 1, argc, argv);
}
// Copyright 2019 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 "ash/shell/content/test/ash_content_test.h"
#include <utility>
#include <vector>
#include "ash/public/cpp/shelf_config.h"
#include "ash/shell.h"
#include "ash/shell/content/client/shell_browser_main_parts.h"
#include "ash/shell/content/embedded_browser.h"
#include "ash/shell/window_type_launcher.h"
#include "ash/wm/mru_window_tracker.h"
#include "base/auto_reset.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/location.h"
#include "base/macros.h"
#include "base/metrics/histogram_samples.h"
#include "base/metrics/statistics_recorder.h"
#include "base/no_destructor.h"
#include "base/run_loop.h"
#include "base/system/sys_info.h"
#include "base/task/post_task.h"
#include "base/test/test_file_util.h"
#include "base/threading/thread_restrictions.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "chromeos/constants/chromeos_switches.h"
#include "components/user_manager/user_names.h"
#include "content/public/browser/tracing_controller.h"
#include "content/public/test/browser_test_utils.h"
#include "services/tracing/public/cpp/trace_event_agent.h"
#include "testing/perf/luci_test_result.h"
#include "ui/aura/window_tracker.h"
#include "ui/compositor/compositor_switches.h"
#include "ui/display/display_switches.h"
#include "ui/gl/gl_switches.h"
#include "ui/views/widget/widget.h"
namespace {
constexpr char kTraceDir[] = "trace-dir";
constexpr char kPerfTestPrintUmaMeans[] = "perf-test-print-uma-means";
float GetHistogramMean(const std::string& name) {
auto* histogram = base::StatisticsRecorder::FindHistogram(name);
if (!histogram)
return 0;
// Use SnapshotFinalDelta() so that it won't contain the samples before the
// subclass invokes SnapshotDelta() during the test.
auto samples = histogram->SnapshotFinalDelta();
DCHECK_NE(0, samples->TotalCount());
return static_cast<float>(samples->sum()) / samples->TotalCount();
}
perf_test::LuciTestResult CreateTestResult(
const base::FilePath& trace_file,
const std::vector<std::string>& tbm_metrics) {
perf_test::LuciTestResult result =
perf_test::LuciTestResult::CreateForGTest();
result.AddOutputArtifactFile("trace/1.json", trace_file, "application/json");
for (auto& metric : tbm_metrics)
result.AddTag("tbmv2", metric);
return result;
}
} // namespace
class AshContentTest::Tracer {
public:
Tracer(base::FilePath trace_dir,
std::string tracing_categories,
std::vector<std::string> histograms,
std::vector<std::string> tbm_metrics)
: trace_dir_(std::move(trace_dir)),
tracing_categories_(std::move(tracing_categories)),
tbm_metrics_(std::move(tbm_metrics)) {
auto* controller = content::TracingController::GetInstance();
base::trace_event::TraceConfig config(
tracing_categories_, base::trace_event::RECORD_CONTINUOUSLY);
for (const auto& histogram : histograms)
config.EnableHistogram(histogram);
base::RunLoop runloop;
bool result = controller->StartTracing(config, runloop.QuitClosure());
runloop.Run();
CHECK(result);
}
~Tracer() {
base::ScopedAllowBlockingForTesting allow_io;
CreateTmp();
{
base::RunLoop runloop;
auto trace_data_endpoint = content::TracingController::CreateFileEndpoint(
trace_file_, runloop.QuitClosure());
auto* controller = content::TracingController::GetInstance();
bool result = controller->StopTracing(trace_data_endpoint);
runloop.Run();
CHECK(result);
}
base::FilePath report_file =
trace_file_.AddExtension(FILE_PATH_LITERAL("test_result.json"));
CreateTestResult(trace_file_, tbm_metrics_).WriteToFile(report_file);
}
void CreateTmp() {
CHECK(base::CreateTemporaryFileInDir(trace_dir_, &trace_file_));
}
base::FilePath trace_dir_;
base::FilePath trace_file_;
std::string tracing_categories_;
std::vector<std::string> tbm_metrics_;
};
AshContentTest::AshContentTest()
: enable_trace_(
base::CommandLine::ForCurrentProcess()->HasSwitch(kTraceDir)) {
auto* cmd = base::CommandLine::ForCurrentProcess();
if (enable_trace_) {
cmd->AppendSwitch(switches::kUseGpuInTests);
cmd->AppendSwitch(switches::kEnablePixelOutputInTests);
}
}
AshContentTest::~AshContentTest() = default;
void AshContentTest::SetUp() {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
// Add command line arguments that are used by all AshContentTests.
if (!command_line->HasSwitch(switches::kHostWindowBounds) &&
!base::SysInfo::IsRunningOnChromeOS()) {
// Adjusting window location & size so that the ash desktop window fits
// inside the Xvfb's default resolution. Only do that when not running
// on device. Otherwise, device display is not properly configured.
command_line->AppendSwitchASCII(switches::kHostWindowBounds,
"0+0-1280x800");
}
content::ContentBrowserTest::SetUp();
}
void AshContentTest::SetUpOnMainThread() {
content::ContentBrowserTest::SetUpOnMainThread();
if (enable_trace_) {
base::FilePath dir =
base::CommandLine::ForCurrentProcess()->GetSwitchValuePath(kTraceDir);
tracer_ = std::make_unique<Tracer>(
std::move(dir),
std::move(
"benchmark,cc,viz,input,latency,gpu,rail,toplevel,ui,views,viz"),
GetUMAHistogramNames(), GetTimelineBasedMetrics());
}
gfx::Size display_size = ash::Shell::GetPrimaryRootWindow()->bounds().size();
test_window_size_.set_height(
(display_size.height() - ash::ShelfConfig::Get()->shelf_size()) * 0.95f);
test_window_size_.set_width(display_size.width() * 0.7f);
}
void AshContentTest::TearDownOnMainThread() {
tracer_.reset();
auto* command_line = base::CommandLine::ForCurrentProcess();
const bool print = command_line->HasSwitch(kPerfTestPrintUmaMeans);
LOG_IF(INFO, print) << "=== Histogram Means ===";
for (auto name : GetUMAHistogramNames()) {
EXPECT_TRUE(!!base::StatisticsRecorder::FindHistogram(name))
<< " missing histogram:" << name;
LOG_IF(INFO, print) << name << ": " << GetHistogramMean(name);
}
LOG_IF(INFO, print) << "=== End Histogram Means ===";
content::ContentBrowserTest::TearDownOnMainThread();
}
aura::Window* AshContentTest::CreateBrowserWindow(const GURL& url) {
return ash::shell::EmbeddedBrowser::Create(
ash::shell::ShellBrowserMainParts::GetBrowserContext(), url,
gfx::Rect(test_window_size_));
}
aura::Window* AshContentTest::CreateTestWindow() {
views::Widget* widget = views::Widget::CreateWindowWithContext(
new ash::shell::WindowTypeLauncher(base::NullCallback(),
base::NullCallback()),
ash::Shell::GetPrimaryRootWindow(), gfx::Rect(test_window_size_));
widget->GetNativeView()->SetName("WindowTypeLauncher");
widget->Show();
return widget->GetNativeWindow();
}
void AshContentTest::PreRunTestOnMainThread() {
// We're not calling ContentBrowserTest's method because it performs content
// shell initialization. Same in PostRunTestOnMainThread.
// Pump startup related events.
base::RunLoop().RunUntilIdle();
}
void AshContentTest::PostRunTestOnMainThread() {
// Cleanup all application windows.
aura::WindowTracker tracker(
ash::Shell::Get()->mru_window_tracker()->BuildWindowForCycleList(
ash::kAllDesks));
while (!tracker.windows().empty()) {
auto* widget = views::Widget::GetWidgetForNativeWindow(tracker.Pop());
widget->Close();
}
// Sometimes tests leave Quit tasks in the MessageLoop (for shame), so let's
// run all pending messages here to avoid preempting the QuitBrowsers tasks.
// TODO(https://crbug.com/922118): Remove this once it is no longer possible
// to post QuitCurrent* tasks.
base::RunLoop().RunUntilIdle();
}
std::vector<std::string> AshContentTest::GetUMAHistogramNames() const {
return {};
}
std::vector<std::string> AshContentTest::GetTimelineBasedMetrics() const {
return {"renderingMetric", "umaMetric"};
}
// Copyright 2019 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.
#ifndef ASH_SHELL_CONTENT_TEST_ASH_CONTENT_TEST_H_
#define ASH_SHELL_CONTENT_TEST_ASH_CONTENT_TEST_H_
#include <memory>
#include <string>
#include <vector>
#include "base/macros.h"
#include "content/public/test/content_browser_test.h"
// A base class for ash test with content. The test will run with multi process
// with gpu/viz process, much closer to real environment than ash_unittests.
class AshContentTest : public content::ContentBrowserTest {
public:
AshContentTest();
~AshContentTest() override;
// contnet::ContentBrowserTest:
void SetUp() override;
void SetUpOnMainThread() override;
void TearDownOnMainThread() override;
void PreRunTestOnMainThread() override;
void PostRunTestOnMainThread() override;
protected:
aura::Window* CreateBrowserWindow(const GURL& url);
aura::Window* CreateTestWindow();
virtual std::vector<std::string> GetUMAHistogramNames() const;
// Returns the names of timeline based metrics (TBM) to be extracted from
// the generated trace. The metrics must be defined in telemetry
// third_party/catapult/tracing/tracing/metrics/
// so that third_party/catapult/tracing/bin/run_metric could handle them.
// Default is "renderingMetric", "umaMetric".
virtual std::vector<std::string> GetTimelineBasedMetrics() const;
private:
class Tracer;
gfx::Size test_window_size_;
bool enable_trace_;
std::unique_ptr<Tracer> tracer_;
DISALLOW_COPY_AND_ASSIGN(AshContentTest);
};
#define ASH_CONTENT_TEST_F(test_fixture, test_name) \
IN_PROC_BROWSER_TEST_F(test_fixture, test_name)
#define ASH_CONTENT_TEST_P(test_fixture, test_name) \
IN_PROC_BROWSER_TEST_P(test_fixture, test_name)
#endif // ASH_SHELL_CONTENT_TEST_ASH_CONTENT_TEST_H_
// Copyright (c) 2012 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 "ash/shell/example_app_list_client.h"
#include <algorithm>
#include <utility>
#include "ash/app_list/app_list_controller_impl.h"
#include "ash/app_list/model/app_list_item.h"
#include "ash/app_list/model/search/search_result.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shell.h"
#include "ash/shell/example_factory.h"
#include "ash/shell/toplevel_window.h"
#include "base/bind_helpers.h"
#include "base/i18n/case_conversion.h"
#include "base/i18n/string_search.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/views/examples/example_base.h"
#include "ui/views/examples/examples_window.h"
namespace ash {
namespace shell {
// WindowTypeShelfItem is an app item of app list. It carries a window
// launch type and launches corresponding example window when activated.
class WindowTypeShelfItem : public AppListItem {
public:
enum Type {
TOPLEVEL_WINDOW = 0,
NON_RESIZABLE_WINDOW,
LOCK_SCREEN,
WIDGETS_WINDOW,
EXAMPLES_WINDOW,
LAST_TYPE,
};
WindowTypeShelfItem(const std::string& id, Type type);
~WindowTypeShelfItem() override;
static gfx::ImageSkia GetIcon(Type type) {
static const SkColor kColors[] = {
SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorCYAN,
};
const int kIconSize = 128;
SkBitmap icon;
icon.allocN32Pixels(kIconSize, kIconSize);
icon.eraseColor(kColors[static_cast<int>(type) % base::size(kColors)]);
return gfx::ImageSkia::CreateFrom1xBitmap(icon);
}
// The text below is not localized as this is an example code.
static std::string GetTitle(Type type) {
switch (type) {
case TOPLEVEL_WINDOW:
return "Create Window";
case NON_RESIZABLE_WINDOW:
return "Create Non-Resizable Window";
case LOCK_SCREEN:
return "Lock Screen";
case WIDGETS_WINDOW:
return "Show Example Widgets";
case EXAMPLES_WINDOW:
return "Open Views Examples Window";
default:
return "Unknown window type.";
}
}
// The text below is not localized as this is an example code.
static std::string GetDetails(Type type) {
// Assigns details only to some types so that we see both one-line
// and two-line results.
switch (type) {
case WIDGETS_WINDOW:
return "Creates a window to show example widgets";
case EXAMPLES_WINDOW:
return "Creates a window to show views example.";
default:
return std::string();
}
}
static void ActivateItem(Type type, int event_flags) {
switch (type) {
case TOPLEVEL_WINDOW: {
ToplevelWindow::CreateParams params;
params.can_resize = true;
ToplevelWindow::CreateToplevelWindow(params);
break;
}
case NON_RESIZABLE_WINDOW: {
ToplevelWindow::CreateToplevelWindow(ToplevelWindow::CreateParams());
break;
}
case LOCK_SCREEN: {
Shell::Get()->session_controller()->LockScreen();
break;
}
case WIDGETS_WINDOW: {
CreateWidgetsWindow();
break;
}
case EXAMPLES_WINDOW: {
views::examples::ShowExamplesWindow(base::DoNothing());
break;
}
default:
break;
}
}
Type type() const { return type_; }
private:
Type type_;
DISALLOW_COPY_AND_ASSIGN(WindowTypeShelfItem);
};
WindowTypeShelfItem::WindowTypeShelfItem(const std::string& id, Type type)
: AppListItem(id), type_(type) {
std::string title(GetTitle(type));
SetIcon(ash::AppListConfigType::kShared, GetIcon(type));
SetName(title);
}
WindowTypeShelfItem::~WindowTypeShelfItem() = default;
// ExampleSearchResult is an app list search result. It provides what icon to
// show, what should title and details text look like. It also carries the
// matching window launch type so that AppListViewDelegate knows how to open
// it.
class ExampleSearchResult : public SearchResult {
public:
ExampleSearchResult(WindowTypeShelfItem::Type type,
const base::string16& query)
: type_(type) {
SetIcon(WindowTypeShelfItem::GetIcon(type_));
base::string16 title =
base::UTF8ToUTF16(WindowTypeShelfItem::GetTitle(type_));
set_title(title);
if (query.empty()) {
set_is_recommendation(true);
SetChipIcon(WindowTypeShelfItem::GetIcon(type_));
} else {
Tags title_tags;
// Highlight matching parts in title with bold.
// Note the following is not a proper way to handle i18n string.
title = base::i18n::ToLower(title);
const size_t match_len = query.length();
size_t match_start = title.find(query);
while (match_start != base::string16::npos) {
title_tags.push_back(
Tag(Tag::MATCH, match_start, match_start + match_len));
match_start = title.find(query, match_start + match_len);
}
set_title_tags(title_tags);
}
base::string16 details =
base::UTF8ToUTF16(WindowTypeShelfItem::GetDetails(type_));
set_details(details);
Tags details_tags;
details_tags.push_back(Tag(Tag::DIM, 0, details.length()));
set_details_tags(details_tags);
}
WindowTypeShelfItem::Type type() const { return type_; }
private:
WindowTypeShelfItem::Type type_;
DISALLOW_COPY_AND_ASSIGN(ExampleSearchResult);
};
ExampleAppListClient::ExampleAppListClient(AppListControllerImpl* controller)
: controller_(controller) {
controller_->SetClient(this);
PopulateApps();
}
ExampleAppListClient::~ExampleAppListClient() {
controller_->SetClient(nullptr);
}
void ExampleAppListClient::PopulateApps() {
for (int i = 0; i < static_cast<int>(WindowTypeShelfItem::LAST_TYPE); ++i) {
WindowTypeShelfItem::Type type = static_cast<WindowTypeShelfItem::Type>(i);
const std::string id = base::NumberToString(i);
auto app = std::make_unique<WindowTypeShelfItem>(id, type);
controller_->AddItem(app->CloneMetadata());
apps_.emplace_back(std::move(app));
}
}
void ExampleAppListClient::StartSearch(const base::string16& trimmed_query) {
base::string16 query;
query = base::i18n::ToLower(trimmed_query);
search_results_.clear();
std::vector<std::unique_ptr<ash::SearchResultMetadata>> result_data;
for (int i = 0; i < static_cast<int>(WindowTypeShelfItem::LAST_TYPE); ++i) {
WindowTypeShelfItem::Type type = static_cast<WindowTypeShelfItem::Type>(i);
const base::string16 title =
base::UTF8ToUTF16(WindowTypeShelfItem::GetTitle(type));
if (query.empty() || base::i18n::StringSearchIgnoringCaseAndAccents(
query, title, nullptr, nullptr)) {
search_results_.emplace_back(
std::make_unique<ExampleSearchResult>(type, query));
result_data.emplace_back(search_results_.back()->CloneMetadata());
}
}
controller_->PublishSearchResults(std::move(result_data));
}
void ExampleAppListClient::OpenSearchResult(
const std::string& result_id,
int event_flags,
ash::AppListLaunchedFrom launched_from,
ash::AppListLaunchType launch_type,
int suggestion_index,
bool launch_as_default) {
auto it = std::find_if(
search_results_.begin(), search_results_.end(),
[&result_id](const std::unique_ptr<ExampleSearchResult>& result) {
return result->id() == result_id;
});
if (it == search_results_.end())
return;
WindowTypeShelfItem::ActivateItem((*it)->type(), event_flags);
}
void ExampleAppListClient::ActivateItem(int profile_id,
const std::string& id,
int event_flags) {
auto it =
std::find_if(apps_.begin(), apps_.end(),
[&id](const std::unique_ptr<WindowTypeShelfItem>& app) {
return app->id() == id;
});
if (it == apps_.end())
return;
WindowTypeShelfItem::ActivateItem((*it)->type(), event_flags);
}
} // namespace shell
} // namespace ash
// Copyright 2019 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.
#ifndef ASH_SHELL_EXAMPLE_APP_LIST_CLIENT_H_
#define ASH_SHELL_EXAMPLE_APP_LIST_CLIENT_H_
#include <memory>
#include <string>
#include <vector>
#include "ash/app_list/test/test_app_list_client.h"
#include "base/macros.h"
namespace ash {
class AppListControllerImpl;
namespace shell {
class WindowTypeShelfItem;
class ExampleSearchResult;
class ExampleAppListClient : public TestAppListClient {
public:
explicit ExampleAppListClient(AppListControllerImpl* controller);
~ExampleAppListClient() override;
private:
void PopulateApps();
// TestAppListClient:
void StartSearch(const base::string16& trimmed_query) override;
void OpenSearchResult(const std::string& result_id,
int event_flags,
ash::AppListLaunchedFrom launched_from,
ash::AppListLaunchType launch_type,
int suggestion_index,
bool launch_as_default) override;
void ActivateItem(int profile_id,
const std::string& id,
int event_flags) override;
AppListControllerImpl* controller_;
std::vector<std::unique_ptr<WindowTypeShelfItem>> apps_;
std::vector<std::unique_ptr<ExampleSearchResult>> search_results_;
DISALLOW_COPY_AND_ASSIGN(ExampleAppListClient);
};
} // namespace shell
} // namespace ash
#endif // ASH_SHELL_EXAMPLE_APP_LIST_CLIENT_H_
// Copyright (c) 2012 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.
#ifndef ASH_SHELL_EXAMPLE_FACTORY_H_
#define ASH_SHELL_EXAMPLE_FACTORY_H_
namespace views {
class View;
}
namespace ash {
class AppListViewDelegate;
namespace shell {
void CreatePointyBubble(views::View* anchor_view);
void CreateLockScreen();
// Creates a window showing samples of commonly used widgets.
void CreateWidgetsWindow();
AppListViewDelegate* CreateAppListViewDelegate();
} // namespace shell
} // namespace ash
#endif // ASH_SHELL_EXAMPLE_FACTORY_H_
// Copyright 2017 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 "ash/shell/example_session_controller_client.h"
#include "ash/shell.h"
#include "ash/shell/example_factory.h"
#include "base/check_op.h"
namespace ash {
namespace shell {
namespace {
ExampleSessionControllerClient* instance = nullptr;
} // namespace
ExampleSessionControllerClient::ExampleSessionControllerClient(
SessionControllerImpl* controller,
TestPrefServiceProvider* prefs_provider)
: TestSessionControllerClient(controller, prefs_provider) {
DCHECK_EQ(instance, nullptr);
DCHECK(controller);
instance = this;
}
ExampleSessionControllerClient::~ExampleSessionControllerClient() {
DCHECK_EQ(instance, this);
instance = nullptr;
}
// static
ExampleSessionControllerClient* ExampleSessionControllerClient::Get() {
return instance;
}
void ExampleSessionControllerClient::Initialize() {
// Initialize and bind with the session controller.
InitializeAndSetClient();
// ash_shell has 2 users.
CreatePredefinedUserSessions(2);
}
void ExampleSessionControllerClient::RequestLockScreen() {
TestSessionControllerClient::RequestLockScreen();
CreateLockScreen();
Shell::Get()->UpdateShelfVisibility();
}
void ExampleSessionControllerClient::UnlockScreen() {
TestSessionControllerClient::UnlockScreen();
Shell::Get()->UpdateShelfVisibility();
}
void ExampleSessionControllerClient::RequestSignOut() {
DCHECK(quit_closure_);
std::move(quit_closure_).Run();
}
} // namespace shell
} // namespace ash
// Copyright 2017 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.
#ifndef ASH_SHELL_EXAMPLE_SESSION_CONTROLLER_CLIENT_H_
#define ASH_SHELL_EXAMPLE_SESSION_CONTROLLER_CLIENT_H_
#include <utility>
#include "ash/session/test_session_controller_client.h"
#include "base/callback.h"
#include "base/macros.h"
namespace ash {
class SessionControllerImpl;
namespace shell {
class ExampleSessionControllerClient : public TestSessionControllerClient {
public:
ExampleSessionControllerClient(SessionControllerImpl* controller,
TestPrefServiceProvider* prefs_provider);
~ExampleSessionControllerClient() override;
static ExampleSessionControllerClient* Get();
void Initialize();
void set_quit_closure(base::OnceClosure quit_closure) {
quit_closure_ = std::move(quit_closure);
}
// TestSessionControllerClient
void RequestLockScreen() override;
void UnlockScreen() override;
void RequestSignOut() override;
private:
base::OnceClosure quit_closure_;
DISALLOW_COPY_AND_ASSIGN(ExampleSessionControllerClient);
};
} // namespace shell
} // namespace ash
#endif // ASH_SHELL_EXAMPLE_SESSION_CONTROLLER_CLIENT_H_
// Copyright (c) 2012 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 "ash/public/cpp/shell_window_ids.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shell.h"
#include "ash/shell/example_factory.h"
#include "ash/shell/example_session_controller_client.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/font_list.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/text_utils.h"
#include "ui/views/controls/button/md_text_button.h"
#include "ui/views/controls/label.h"
#include "ui/views/corewm/tooltip_controller.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
namespace ash {
namespace shell {
class LockView : public views::WidgetDelegateView,
public views::ButtonListener {
public:
LockView() : text_(new views::Label(base::ASCIIToUTF16("LOCKED!"))) {
text_->SetEnabledColor(SK_ColorRED);
AddChildView(text_);
unlock_button_ = AddChildView(
views::MdTextButton::Create(this, base::ASCIIToUTF16("Unlock")));
}
~LockView() override = default;
// Overridden from views::View:
gfx::Size CalculatePreferredSize() const override {
return gfx::Size(500, 400);
}
private:
// Overridden from views::View:
void OnPaint(gfx::Canvas* canvas) override {
canvas->FillRect(GetLocalBounds(), SK_ColorYELLOW);
}
void Layout() override {
gfx::Rect bounds = GetLocalBounds();
gfx::Size ts = text_->GetPreferredSize();
text_->SetBoundsRect(gfx::Rect((bounds.width() - ts.width()) / 2,
(bounds.height() - ts.height()) / 2,
ts.width(), ts.height()));
gfx::Size ps = unlock_button_->GetPreferredSize();
bounds.set_y(bounds.bottom() - ps.height() - 5);
bounds.set_x((bounds.width() - ps.width()) / 2);
bounds.set_size(ps);
unlock_button_->SetBoundsRect(bounds);
}
void ViewHierarchyChanged(
const views::ViewHierarchyChangedDetails& details) override {
if (details.is_add && details.child == this)
unlock_button_->RequestFocus();
}
// Overridden from views::WidgetDelegateView:
void WindowClosing() override {
ExampleSessionControllerClient::Get()->UnlockScreen();
}
// Overridden from views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override {
DCHECK(sender == unlock_button_);
GetWidget()->Close();
}
views::Label* text_;
views::Button* unlock_button_;
DISALLOW_COPY_AND_ASSIGN(LockView);
};
void CreateLockScreen() {
LockView* lock_view = new LockView;
views::Widget* widget = new views::Widget;
views::Widget::InitParams params(
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
gfx::Size ps = lock_view->GetPreferredSize();
gfx::Size root_window_size = Shell::GetPrimaryRootWindow()->bounds().size();
params.bounds = gfx::Rect((root_window_size.width() - ps.width()) / 2,
(root_window_size.height() - ps.height()) / 2,
ps.width(), ps.height());
params.delegate = lock_view;
params.parent = Shell::GetContainer(Shell::GetPrimaryRootWindow(),
kShellWindowId_LockScreenContainer);
widget->Init(std::move(params));
widget->Show();
widget->GetNativeView()->SetName("LockView");
widget->GetNativeView()->Focus();
// TODO: it shouldn't be necessary to invoke UpdateTooltip() here.
Shell::Get()->tooltip_controller()->UpdateTooltip(widget->GetNativeView());
}
} // namespace shell
} // namespace ash
// Copyright (c) 2012 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 "ash/shell/shell_delegate_impl.h"
#include <memory>
#include "ash/accessibility/default_accessibility_delegate.h"
#include "ash/test_screenshot_delegate.h"
#include "ash/wm/gestures/back_gesture/test_back_gesture_contextual_nudge_delegate.h"
namespace ash {
namespace shell {
ShellDelegateImpl::ShellDelegateImpl() = default;
ShellDelegateImpl::~ShellDelegateImpl() = default;
bool ShellDelegateImpl::CanShowWindowForUser(const aura::Window* window) const {
return true;
}
std::unique_ptr<ash::ScreenshotDelegate>
ShellDelegateImpl::CreateScreenshotDelegate() {
return std::make_unique<TestScreenshotDelegate>();
}
AccessibilityDelegate* ShellDelegateImpl::CreateAccessibilityDelegate() {
return new DefaultAccessibilityDelegate;
}
std::unique_ptr<BackGestureContextualNudgeDelegate>
ShellDelegateImpl::CreateBackGestureContextualNudgeDelegate(
BackGestureContextualNudgeController* controller) {
return std::make_unique<TestBackGestureContextualNudgeDelegate>(controller);
}
bool ShellDelegateImpl::CanGoBack(gfx::NativeWindow window) const {
return true;
}
void ShellDelegateImpl::BindNavigableContentsFactory(
mojo::PendingReceiver<content::mojom::NavigableContentsFactory> receiver) {}
void ShellDelegateImpl::BindMultiDeviceSetup(
mojo::PendingReceiver<chromeos::multidevice_setup::mojom::MultiDeviceSetup>
receiver) {}
} // namespace shell
} // namespace ash
// Copyright (c) 2012 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.
#ifndef ASH_SHELL_SHELL_DELEGATE_IMPL_H_
#define ASH_SHELL_SHELL_DELEGATE_IMPL_H_
#include <memory>
#include <string>
#include "ash/shell_delegate.h"
#include "base/macros.h"
namespace ash {
namespace shell {
class ShellDelegateImpl : public ShellDelegate {
public:
ShellDelegateImpl();
~ShellDelegateImpl() override;
// ShellDelegate:
bool CanShowWindowForUser(const aura::Window* window) const override;
std::unique_ptr<ScreenshotDelegate> CreateScreenshotDelegate() override;
AccessibilityDelegate* CreateAccessibilityDelegate() override;
std::unique_ptr<BackGestureContextualNudgeDelegate>
CreateBackGestureContextualNudgeDelegate(
BackGestureContextualNudgeController* controller) override;
bool CanGoBack(gfx::NativeWindow window) const override;
void BindNavigableContentsFactory(
mojo::PendingReceiver<content::mojom::NavigableContentsFactory> receiver)
override;
void BindMultiDeviceSetup(
mojo::PendingReceiver<
chromeos::multidevice_setup::mojom::MultiDeviceSetup> receiver)
override;
private:
DISALLOW_COPY_AND_ASSIGN(ShellDelegateImpl);
};
} // namespace shell
} // namespace ash
#endif // ASH_SHELL_SHELL_DELEGATE_IMPL_H_
// Copyright 2017 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 "ash/shell/shell_views_delegate.h"
#include "ash/shell.h"
namespace ash {
namespace shell {
ShellViewsDelegate::ShellViewsDelegate() = default;
ShellViewsDelegate::~ShellViewsDelegate() = default;
std::unique_ptr<views::NonClientFrameView>
ShellViewsDelegate::CreateDefaultNonClientFrameView(views::Widget* widget) {
return ash::Shell::Get()->CreateDefaultNonClientFrameView(widget);
}
void ShellViewsDelegate::OnBeforeWidgetInit(
views::Widget::InitParams* params,
views::internal::NativeWidgetDelegate* delegate) {
if (params->opacity == views::Widget::InitParams::WindowOpacity::kInferred)
params->opacity = views::Widget::InitParams::WindowOpacity::kTranslucent;
if (params->native_widget)
return;
if (!params->parent && !params->context && !params->child)
params->context = Shell::GetPrimaryRootWindow();
}
} // namespace shell
} // namespace ash
// Copyright 2017 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.
#ifndef ASH_SHELL_SHELL_VIEWS_DELEGATE_H_
#define ASH_SHELL_SHELL_VIEWS_DELEGATE_H_
#include "ui/views/test/test_views_delegate.h"
namespace ash {
namespace shell {
class ShellViewsDelegate : public views::TestViewsDelegate {
public:
ShellViewsDelegate();
~ShellViewsDelegate() override;
// views::TestViewsDelegate:
std::unique_ptr<views::NonClientFrameView> CreateDefaultNonClientFrameView(
views::Widget* widget) override;
void OnBeforeWidgetInit(
views::Widget::InitParams* params,
views::internal::NativeWidgetDelegate* delegate) override;
private:
DISALLOW_COPY_AND_ASSIGN(ShellViewsDelegate);
};
} // namespace shell
} // namespace ash
#endif // ASH_SHELL_SHELL_VIEWS_DELEGATE_H_
// Copyright (c) 2012 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 "ash/shell.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/gfx/canvas.h"
#include "ui/views/controls/button/checkbox.h"
#include "ui/views/controls/button/md_text_button.h"
#include "ui/views/controls/button/radio_button.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
namespace {
// Default window position.
const int kWindowLeft = 170;
const int kWindowTop = 200;
// Default window size.
const int kWindowWidth = 400;
const int kWindowHeight = 400;
// A window showing samples of commonly used widgets.
class WidgetsWindow : public views::WidgetDelegateView {
public:
WidgetsWindow();
~WidgetsWindow() override;
// Overridden from views::View:
void OnPaint(gfx::Canvas* canvas) override;
void Layout() override;
gfx::Size CalculatePreferredSize() const override;
// Overridden from views::WidgetDelegate:
bool CanResize() const override;
private:
views::LabelButton* button_;
views::LabelButton* disabled_button_;
views::Checkbox* checkbox_;
views::Checkbox* checkbox_disabled_;
views::Checkbox* checkbox_checked_;
views::Checkbox* checkbox_checked_disabled_;
views::RadioButton* radio_button_;
views::RadioButton* radio_button_disabled_;
views::RadioButton* radio_button_selected_;
views::RadioButton* radio_button_selected_disabled_;
};
WidgetsWindow::WidgetsWindow()
: checkbox_(new views::Checkbox(base::ASCIIToUTF16("Checkbox"))),
checkbox_disabled_(
new views::Checkbox(base::ASCIIToUTF16("Checkbox disabled"))),
checkbox_checked_(
new views::Checkbox(base::ASCIIToUTF16("Checkbox checked"))),
checkbox_checked_disabled_(
new views::Checkbox(base::ASCIIToUTF16("Checkbox checked disabled"))),
radio_button_(
new views::RadioButton(base::ASCIIToUTF16("Radio button"), 0)),
radio_button_disabled_(
new views::RadioButton(base::ASCIIToUTF16("Radio button disabled"),
0)),
radio_button_selected_(
new views::RadioButton(base::ASCIIToUTF16("Radio button selected"),
0)),
radio_button_selected_disabled_(new views::RadioButton(
base::ASCIIToUTF16("Radio button selected disabled"),
1)) {
SetTitle(base::ASCIIToUTF16("Examples: Widgets"));
button_ = AddChildView(
views::MdTextButton::Create(nullptr, base::ASCIIToUTF16("Button")));
disabled_button_ = AddChildView(views::MdTextButton::Create(
nullptr, base::ASCIIToUTF16("Disabled button")));
disabled_button_->SetEnabled(false);
AddChildView(checkbox_);
checkbox_disabled_->SetEnabled(false);
AddChildView(checkbox_disabled_);
checkbox_checked_->SetChecked(true);
AddChildView(checkbox_checked_);
checkbox_checked_disabled_->SetChecked(true);
checkbox_checked_disabled_->SetEnabled(false);
AddChildView(checkbox_checked_disabled_);
AddChildView(radio_button_);
radio_button_disabled_->SetEnabled(false);
AddChildView(radio_button_disabled_);
radio_button_selected_->SetChecked(true);
AddChildView(radio_button_selected_);
radio_button_selected_disabled_->SetChecked(true);
radio_button_selected_disabled_->SetEnabled(false);
AddChildView(radio_button_selected_disabled_);
}
WidgetsWindow::~WidgetsWindow() = default;
void WidgetsWindow::OnPaint(gfx::Canvas* canvas) {
canvas->FillRect(GetLocalBounds(), SK_ColorWHITE);
}
void WidgetsWindow::Layout() {
const int kVerticalPad = 5;
int left = 5;
int top = kVerticalPad;
for (auto* view : children()) {
gfx::Size preferred = view->GetPreferredSize();
view->SetBounds(left, top, preferred.width(), preferred.height());
top += preferred.height() + kVerticalPad;
}
}
gfx::Size WidgetsWindow::CalculatePreferredSize() const {
return gfx::Size(kWindowWidth, kWindowHeight);
}
bool WidgetsWindow::CanResize() const {
return true;
}
} // namespace
namespace ash {
namespace shell {
void CreateWidgetsWindow() {
views::Widget* widget = views::Widget::CreateWindowWithContext(
new WidgetsWindow, Shell::GetPrimaryRootWindow(),
gfx::Rect(kWindowLeft, kWindowTop, kWindowWidth, kWindowHeight));
widget->GetNativeView()->SetName("WidgetsWindow");
widget->Show();
}
} // namespace shell
} // namespace ash
This diff is collapsed.
// Copyright (c) 2012 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.
#ifndef ASH_SHELL_WINDOW_TYPE_LAUNCHER_H_
#define ASH_SHELL_WINDOW_TYPE_LAUNCHER_H_
#include <memory>
#include "base/callback_forward.h"
#include "base/macros.h"
#include "ui/views/context_menu_controller.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/menu/menu_delegate.h"
#include "ui/views/widget/widget_delegate.h"
namespace views {
class MenuRunner;
}
namespace ash {
namespace shell {
// Creates a Widget to host WindowTypeLauncher. |show_views_examples_callback|
// is Run() when the user clicks on the views examples button. This should
// be bound to either views::examples::ShowExamplesWindow() or
// views::examples::ShowExamplesWindowWithContent().
// |create_embedded_browser_callback| is Run when user clicks the "embedded
// browser" button.
void InitWindowTypeLauncher(
base::RepeatingClosure show_views_examples_callback,
base::RepeatingClosure create_embedded_browser_callback);
// The contents view/delegate of a window that shows some buttons that create
// various window types.
class WindowTypeLauncher : public views::WidgetDelegateView,
public views::ButtonListener,
public views::MenuDelegate,
public views::ContextMenuController {
public:
WindowTypeLauncher(base::RepeatingClosure show_views_examples_callback,
base::RepeatingClosure create_embedded_browser_callback);
~WindowTypeLauncher() override;
private:
typedef std::pair<aura::Window*, gfx::Rect> WindowAndBoundsPair;
enum MenuCommands {
COMMAND_NEW_WINDOW = 1,
COMMAND_TOGGLE_FULLSCREEN = 3,
};
// Overridden from views::View:
void OnPaint(gfx::Canvas* canvas) override;
bool OnMousePressed(const ui::MouseEvent& event) override;
// Overridden from views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// Overridden from views::MenuDelegate:
void ExecuteCommand(int id, int event_flags) override;
// Override from views::ContextMenuController:
void ShowContextMenuForViewImpl(views::View* source,
const gfx::Point& point,
ui::MenuSourceType source_type) override;
views::Button* create_button_;
views::Button* create_nonresizable_button_;
views::Button* bubble_button_;
views::Button* lock_button_;
views::Button* widgets_button_;
views::Button* system_modal_button_;
views::Button* window_modal_button_;
views::Button* child_modal_button_;
views::Button* transient_button_;
views::Button* examples_button_;
views::Button* show_hide_window_button_;
views::Button* show_web_notification_;
views::Button* embedded_browser_button_;
std::unique_ptr<views::MenuRunner> menu_runner_;
base::RepeatingClosure show_views_examples_callback_;
base::RepeatingClosure create_embedded_browser_callback_;
DISALLOW_COPY_AND_ASSIGN(WindowTypeLauncher);
};
} // namespace shell
} // namespace ash
#endif // ASH_SHELL_WINDOW_TYPE_LAUNCHER_H_
// Copyright (c) 2012 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 "ash/shell/window_watcher.h"
#include <memory>
#include <utility>
#include "ash/public/cpp/shelf_item.h"
#include "ash/public/cpp/shelf_model.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/public/cpp/window_properties.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/shell.h"
#include "ash/shell/window_watcher_shelf_item_delegate.h"
#include "ash/wm/desks/desks_util.h"
#include "ash/wm/window_util.h"
#include "base/strings/string_number_conversions.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/aura/window.h"
namespace ash {
namespace shell {
namespace {
} // namespace
class WindowWatcher::WorkspaceWindowWatcher : public aura::WindowObserver {
public:
explicit WorkspaceWindowWatcher(WindowWatcher* watcher) : watcher_(watcher) {}
~WorkspaceWindowWatcher() override = default;
void OnWindowAdded(aura::Window* new_window) override {
new_window->AddObserver(watcher_);
}
void OnWillRemoveWindow(aura::Window* window) override {
DCHECK(window->children().empty());
window->RemoveObserver(watcher_);
}
void RootWindowAdded(aura::Window* root) {
// The shelf is globally observing all active and inactive desks containers.
for (aura::Window* container : desks_util::GetDesksContainers(root)) {
container->AddObserver(watcher_);
for (aura::Window* window : container->children())
watcher_->OnWindowAdded(window);
}
}
void RootWindowRemoved(aura::Window* root) {
for (aura::Window* container : desks_util::GetDesksContainers(root)) {
container->RemoveObserver(watcher_);
for (aura::Window* window : container->children())
watcher_->OnWillRemoveWindow(window);
}
}
private:
WindowWatcher* watcher_;
DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowWatcher);
};
WindowWatcher::WindowWatcher() {
Shell::Get()->AddShellObserver(this);
workspace_window_watcher_ = std::make_unique<WorkspaceWindowWatcher>(this);
for (aura::Window* root : Shell::GetAllRootWindows())
workspace_window_watcher_->RootWindowAdded(root);
}
WindowWatcher::~WindowWatcher() {
for (aura::Window* root : Shell::GetAllRootWindows())
workspace_window_watcher_->RootWindowRemoved(root);
Shell::Get()->RemoveShellObserver(this);
}
aura::Window* WindowWatcher::GetWindowByID(const ShelfID& id) {
IDToWindow::const_iterator i = id_to_window_.find(id);
return i != id_to_window_.end() ? i->second : NULL;
}
// aura::WindowObserver overrides:
void WindowWatcher::OnWindowAdded(aura::Window* new_window) {
if (!window_util::IsWindowUserPositionable(new_window))
return;
ShelfModel* model = ShelfModel::Get();
ShelfItem item;
item.type = TYPE_APP;
static int shelf_id = 0;
item.id = ShelfID(base::NumberToString(shelf_id++));
id_to_window_[item.id] = new_window;
SkBitmap icon_bitmap;
icon_bitmap.allocN32Pixels(16, 16);
constexpr SkColor colors[] = {SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE};
icon_bitmap.eraseColor(colors[shelf_id % 3]);
item.image = gfx::ImageSkia(gfx::ImageSkiaRep(icon_bitmap, 1.0f));
item.title = base::NumberToString16(shelf_id);
model->Add(item);
model->SetShelfItemDelegate(
item.id, std::make_unique<WindowWatcherShelfItemDelegate>(item.id, this));
new_window->SetProperty(kShelfIDKey, item.id.Serialize());
}
void WindowWatcher::OnWillRemoveWindow(aura::Window* window) {
for (IDToWindow::iterator i = id_to_window_.begin(); i != id_to_window_.end();
++i) {
if (i->second == window) {
ShelfModel* model = ShelfModel::Get();
int index = model->ItemIndexByID(i->first);
DCHECK_NE(-1, index);
model->RemoveItemAt(index);
id_to_window_.erase(i);
break;
}
}
}
void WindowWatcher::OnRootWindowAdded(aura::Window* root_window) {
workspace_window_watcher_->RootWindowAdded(root_window);
}
} // namespace shell
} // namespace ash
// Copyright (c) 2012 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.
#ifndef ASH_SHELL_WINDOW_WATCHER_H_
#define ASH_SHELL_WINDOW_WATCHER_H_
#include <stdint.h>
#include <map>
#include <memory>
#include "ash/public/cpp/shelf_types.h"
#include "ash/shell_observer.h"
#include "base/macros.h"
#include "ui/aura/window_observer.h"
namespace ash {
namespace shell {
// WindowWatcher is responsible for listening for newly created windows and
// creating items on the Shelf for them.
class WindowWatcher : public aura::WindowObserver, public ShellObserver {
public:
WindowWatcher();
~WindowWatcher() override;
aura::Window* GetWindowByID(const ShelfID& id);
// aura::WindowObserver overrides:
void OnWindowAdded(aura::Window* new_window) override;
void OnWillRemoveWindow(aura::Window* window) override;
// ShellObserver:
void OnRootWindowAdded(aura::Window* root_window) override;
private:
class WorkspaceWindowWatcher;
typedef std::map<ShelfID, aura::Window*> IDToWindow;
// Maps from window to the id we gave it.
IDToWindow id_to_window_;
std::unique_ptr<WorkspaceWindowWatcher> workspace_window_watcher_;
DISALLOW_COPY_AND_ASSIGN(WindowWatcher);
};
} // namespace shell
} // namespace ash
#endif // ASH_SHELL_WINDOW_WATCHER_H_
// 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 "ash/shell/window_watcher_shelf_item_delegate.h"
#include <utility>
#include "ash/shell/window_watcher.h"
#include "ash/wm/window_util.h"
#include "ui/aura/window.h"
namespace ash {
namespace shell {
WindowWatcherShelfItemDelegate::WindowWatcherShelfItemDelegate(
ShelfID id,
WindowWatcher* watcher)
: ShelfItemDelegate(id), watcher_(watcher) {
DCHECK(!id.IsNull());
DCHECK(watcher_);
}
WindowWatcherShelfItemDelegate::~WindowWatcherShelfItemDelegate() = default;
void WindowWatcherShelfItemDelegate::ItemSelected(
std::unique_ptr<ui::Event> event,
int64_t display_id,
ShelfLaunchSource source,
ItemSelectedCallback callback,
const ItemFilterPredicate& filter_predicate) {
aura::Window* window = watcher_->GetWindowByID(shelf_id());
window->Show();
wm::ActivateWindow(window);
std::move(callback).Run(SHELF_ACTION_WINDOW_ACTIVATED, {});
}
void WindowWatcherShelfItemDelegate::ExecuteCommand(bool from_context_menu,
int64_t command_id,
int32_t event_flags,
int64_t display_id) {
// This delegate does not show custom context or application menu items.
NOTIMPLEMENTED();
}
void WindowWatcherShelfItemDelegate::Close() {}
} // namespace shell
} // namespace ash
// 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.
#ifndef ASH_SHELL_WINDOW_WATCHER_SHELF_ITEM_DELEGATE_H_
#define ASH_SHELL_WINDOW_WATCHER_SHELF_ITEM_DELEGATE_H_
#include "ash/public/cpp/shelf_item.h"
#include "ash/public/cpp/shelf_item_delegate.h"
#include "base/compiler_specific.h"
#include "base/macros.h"
namespace ash {
namespace shell {
class WindowWatcher;
// ShelfItemDelegate implementation used by WindowWatcher.
class WindowWatcherShelfItemDelegate : public ShelfItemDelegate {
public:
WindowWatcherShelfItemDelegate(ShelfID id, WindowWatcher* watcher);
~WindowWatcherShelfItemDelegate() override;
// ShelfItemDelegate:
void ItemSelected(std::unique_ptr<ui::Event> event,
int64_t display_id,
ShelfLaunchSource source,
ItemSelectedCallback callback,
const ItemFilterPredicate& filter_predicate) override;
void ExecuteCommand(bool from_context_menu,
int64_t command_id,
int32_t event_flags,
int64_t display_id) override;
void Close() override;
private:
WindowWatcher* watcher_;
DISALLOW_COPY_AND_ASSIGN(WindowWatcherShelfItemDelegate);
};
} // namespace shell
} // namespace ash
#endif // ASH_SHELL_WINDOW_WATCHER_SHELF_ITEM_DELEGATE_H_
......@@ -19,11 +19,11 @@
#include "ash/public/cpp/test/test_new_window_delegate.h"
#include "ash/session/test_session_controller_client.h"
#include "ash/shell.h"
#include "ash/shell/toplevel_window.h"
#include "ash/shell_init_params.h"
#include "ash/system/model/system_tray_model.h"
#include "ash/system/screen_layout_observer.h"
#include "ash/test/ash_test_views_delegate.h"
#include "ash/test/toplevel_window.h"
#include "ash/test_shell_delegate.h"
#include "ash/wallpaper/wallpaper_controller_impl.h"
#include "ash/wm/overview/overview_controller.h"
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/shell/toplevel_window.h"
#include "ash/test/toplevel_window.h"
#include "ash/shell.h"
#include "ash/wm/window_positioner.h"
......@@ -24,7 +24,7 @@ struct SavedState {
// The last window state in ash_shell. We don't bother deleting
// this on shutdown.
SavedState* saved_state = NULL;
SavedState* saved_state = nullptr;
} // namespace
......@@ -46,7 +46,7 @@ views::Widget* ToplevelWindow::CreateToplevelWindow(
// static
void ToplevelWindow::ClearSavedStateForTest() {
delete saved_state;
saved_state = NULL;
saved_state = nullptr;
}
ToplevelWindow::ToplevelWindow(const CreateParams& params)
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SHELL_TOPLEVEL_WINDOW_H_
#define ASH_SHELL_TOPLEVEL_WINDOW_H_
#ifndef ASH_TEST_TOPLEVEL_WINDOW_H_
#define ASH_TEST_TOPLEVEL_WINDOW_H_
#include "base/macros.h"
#include "ui/views/widget/widget_delegate.h"
......@@ -48,4 +48,4 @@ class ToplevelWindow : public views::WidgetDelegateView {
} // namespace shell
} // namespace ash
#endif // ASH_SHELL_TOPLEVEL_WINDOW_H_
#endif // ASH_TEST_TOPLEVEL_WINDOW_H_
......@@ -8,8 +8,8 @@
#include "ash/public/cpp/shelf_config.h"
#include "ash/shell.h"
#include "ash/shell/toplevel_window.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/toplevel_window.h"
#include "ash/test_shell_delegate.h"
#include "ash/wm/window_positioner.h"
#include "ash/wm/window_state.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment