Commit 71513a8f authored by Jun Mukai's avatar Jun Mukai Committed by Commit Bot

Allow views_example with target_os="chromeos"

This CL introduces specific views_delegate implementation and
screen, a window tree host, and some aura clients to make the
views_examples working with target_os="chromeos".

Bug: 1106480
Test: manually checking views_examples
Change-Id: I25a8fc26d35e91452bd1bcee98f4b3bcecbd5021
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2304098
Commit-Queue: Jun Mukai <mukai@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarAllen Bauer <kylixrd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#789967}
parent 0b3510c3
...@@ -169,6 +169,13 @@ source_set("views_examples_proc") { ...@@ -169,6 +169,13 @@ source_set("views_examples_proc") {
if (use_x11) { if (use_x11) {
deps += [ "//ui/gfx/x" ] deps += [ "//ui/gfx/x" ]
} }
if (is_chromeos) {
sources += [
"examples_views_delegate_chromeos.cc",
"examples_views_delegate_chromeos.h",
]
deps += [ "//ui/wm:test_support" ]
}
} }
executable("views_examples") { executable("views_examples") {
......
...@@ -11,3 +11,12 @@ include_rules = [ ...@@ -11,3 +11,12 @@ include_rules = [
"+ui/snapshot", # Enable Skia Gold testing "+ui/snapshot", # Enable Skia Gold testing
"+ui/views_content_client", "+ui/views_content_client",
] ]
specific_include_rules = {
"examples_main_proc.cc": [
"+ui/wm/core/wm_state.h",
],
"examples_views_delegate_chromeos.cc": [
"+ui/wm/test/wm_test_helper.h",
],
}
...@@ -52,6 +52,10 @@ ...@@ -52,6 +52,10 @@
#include "ui/wm/core/wm_state.h" #include "ui/wm/core/wm_state.h"
#endif #endif
#if defined(OS_CHROMEOS)
#include "ui/views/examples/examples_views_delegate_chromeos.h"
#endif
#if BUILDFLAG(ENABLE_DESKTOP_AURA) #if BUILDFLAG(ENABLE_DESKTOP_AURA)
#include "ui/views/widget/desktop_aura/desktop_screen.h" #include "ui/views/widget/desktop_aura/desktop_screen.h"
#endif #endif
...@@ -154,10 +158,14 @@ ExamplesExitCode ExamplesMainProc(bool under_test) { ...@@ -154,10 +158,14 @@ ExamplesExitCode ExamplesMainProc(bool under_test) {
ExamplesExitCode compare_result = ExamplesExitCode::kSucceeded; ExamplesExitCode compare_result = ExamplesExitCode::kSucceeded;
{ {
#if defined(OS_CHROMEOS)
ExamplesViewsDelegateChromeOS views_delegate;
#else
views::DesktopTestViewsDelegate views_delegate; views::DesktopTestViewsDelegate views_delegate;
#if defined(USE_AURA) #if defined(USE_AURA)
wm::WMState wm_state; wm::WMState wm_state;
#endif #endif
#endif
#if BUILDFLAG(ENABLE_DESKTOP_AURA) #if BUILDFLAG(ENABLE_DESKTOP_AURA)
std::unique_ptr<display::Screen> desktop_screen = std::unique_ptr<display::Screen> desktop_screen =
base::WrapUnique(views::CreateDesktopScreen()); base::WrapUnique(views::CreateDesktopScreen());
......
// Copyright (c) 2020 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 "ui/views/examples/examples_views_delegate_chromeos.h"
#include "ui/views/examples/examples_window.h"
#include "ui/wm/test/wm_test_helper.h"
namespace views {
namespace examples {
namespace {
constexpr gfx::Size kDefaultSize(1024, 768);
} // namespace
ExamplesViewsDelegateChromeOS::ExamplesViewsDelegateChromeOS()
: observer_(this) {}
ExamplesViewsDelegateChromeOS::~ExamplesViewsDelegateChromeOS() = default;
void ExamplesViewsDelegateChromeOS::OnBeforeWidgetInit(
Widget::InitParams* params,
internal::NativeWidgetDelegate* delegate) {
views::TestViewsDelegate::OnBeforeWidgetInit(params, delegate);
if (!params->parent && !params->context) {
DCHECK(!wm_helper_);
wm_helper_ = std::make_unique<wm::WMTestHelper>(kDefaultSize);
wm_helper_->host()->Show();
observer_.Add(wm_helper_->host());
params->context = wm_helper_->host()->window();
}
}
void ExamplesViewsDelegateChromeOS::OnHostCloseRequested(
aura::WindowTreeHost* host) {
Widget* widget = GetExamplesWidget();
if (widget) {
observer_.Remove(host);
widget->Close();
}
}
} // namespace examples
} // namespace views
// Copyright (c) 2020 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 UI_VIEWS_EXAMPLES_EXAMPLES_VIEWS_DELEGATE_CHROMEOS_H_
#define UI_VIEWS_EXAMPLES_EXAMPLES_VIEWS_DELEGATE_CHROMEOS_H_
#include <memory>
#include "base/scoped_observer.h"
#include "ui/aura/window_tree_host.h"
#include "ui/aura/window_tree_host_observer.h"
#include "ui/views/test/desktop_test_views_delegate.h"
namespace wm {
class WMTestHelper;
}
namespace views {
namespace examples {
class ExamplesViewsDelegateChromeOS : public DesktopTestViewsDelegate,
public aura::WindowTreeHostObserver {
public:
ExamplesViewsDelegateChromeOS();
~ExamplesViewsDelegateChromeOS() override;
private:
// ViewsDelegate:
void OnBeforeWidgetInit(Widget::InitParams* params,
internal::NativeWidgetDelegate* delegate) override;
// aura::WindowTreeHostObserver:
void OnHostCloseRequested(aura::WindowTreeHost* host) override;
ScopedObserver<aura::WindowTreeHost, aura::WindowTreeHostObserver> observer_;
std::unique_ptr<wm::WMTestHelper> wm_helper_;
};
} // namespace examples
} // namespace views
#endif // UI_VIEWS_EXAMPLES_EXAMPLES_VIEWS_DELEGATE_CHROMEOS_H_
...@@ -207,6 +207,12 @@ class ExamplesWindowContents : public WidgetDelegateView, ...@@ -207,6 +207,12 @@ class ExamplesWindowContents : public WidgetDelegateView,
// static // static
ExamplesWindowContents* ExamplesWindowContents::instance_ = nullptr; ExamplesWindowContents* ExamplesWindowContents::instance_ = nullptr;
Widget* GetExamplesWidget() {
return ExamplesWindowContents::instance()
? ExamplesWindowContents::instance()->GetWidget()
: nullptr;
}
void ShowExamplesWindow(base::OnceClosure on_close, void ShowExamplesWindow(base::OnceClosure on_close,
ExampleVector examples, ExampleVector examples,
gfx::NativeWindow window_context) { gfx::NativeWindow window_context) {
......
...@@ -17,10 +17,15 @@ ...@@ -17,10 +17,15 @@
#include "ui/views/examples/views_examples_export.h" #include "ui/views/examples/views_examples_export.h"
namespace views { namespace views {
class Widget;
namespace examples { namespace examples {
VIEWS_EXAMPLES_EXPORT extern const char kExamplesWidgetName[]; VIEWS_EXAMPLES_EXPORT extern const char kExamplesWidgetName[];
// Returns the current widget.
VIEWS_EXAMPLES_EXPORT Widget* GetExamplesWidget();
// Shows a window with the views examples in it. |extra_examples| contains any // Shows a window with the views examples in it. |extra_examples| contains any
// additional examples to add. |window_context| is used to determine where the // additional examples to add. |window_context| is used to determine where the
// window should be created (see |Widget::InitParams::context| for details). // window should be created (see |Widget::InitParams::context| for details).
......
...@@ -20,7 +20,9 @@ ViewsContentClientMainPartsAura::~ViewsContentClientMainPartsAura() { ...@@ -20,7 +20,9 @@ ViewsContentClientMainPartsAura::~ViewsContentClientMainPartsAura() {
void ViewsContentClientMainPartsAura::ToolkitInitialized() { void ViewsContentClientMainPartsAura::ToolkitInitialized() {
ViewsContentClientMainParts::ToolkitInitialized(); ViewsContentClientMainParts::ToolkitInitialized();
#if !defined(OS_CHROMEOS)
wm_state_ = std::make_unique<::wm::WMState>(); wm_state_ = std::make_unique<::wm::WMState>();
#endif
} }
void ViewsContentClientMainPartsAura::PostMainMessageLoopRun() { void ViewsContentClientMainPartsAura::PostMainMessageLoopRun() {
......
...@@ -43,7 +43,7 @@ void ViewsContentClientMainPartsChromeOS::PreMainMessageLoopRun() { ...@@ -43,7 +43,7 @@ void ViewsContentClientMainPartsChromeOS::PreMainMessageLoopRun() {
ViewsContentClientMainPartsAura::PreMainMessageLoopRun(); ViewsContentClientMainPartsAura::PreMainMessageLoopRun();
// Set up basic pieces of views::corewm. // Set up basic pieces of views::corewm.
wm_test_helper_ = std::make_unique<wm::WMTestHelper>(gfx::Size(800, 600)); wm_test_helper_ = std::make_unique<wm::WMTestHelper>(gfx::Size(1024, 768));
// Ensure the X window gets mapped. // Ensure the X window gets mapped.
wm_test_helper_->host()->Show(); wm_test_helper_->host()->Show();
......
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