Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: components/mus/example/common/mus_views_init.cc

Issue 1407073002: Adds GetDisplays() to WindowManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge 2 trunk Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/mus/example/common/mus_views_init.h" 5 #include "components/mus/example/common/mus_views_init.h"
6 6
7 #include "components/mus/public/cpp/view_tree_connection.h" 7 #include "components/mus/public/cpp/view_tree_connection.h"
8 #include "components/mus/public/interfaces/view_tree.mojom.h" 8 #include "components/mus/public/interfaces/view_tree.mojom.h"
9 #include "components/mus/public/interfaces/window_manager.mojom.h" 9 #include "components/mus/public/interfaces/window_manager.mojom.h"
10 #include "mojo/application/public/cpp/application_connection.h" 10 #include "mojo/application/public/cpp/application_connection.h"
11 #include "mojo/application/public/cpp/application_impl.h" 11 #include "mojo/application/public/cpp/application_impl.h"
12 #include "ui/views/mus/aura_init.h" 12 #include "mojo/converters/geometry/geometry_type_converters.h"
13 #include "mojo/converters/network/network_type_converters.h"
14 #include "ui/gfx/display.h"
15 #include "ui/gfx/geometry/point_conversions.h"
16 #include "ui/gfx/geometry/rect.h"
13 #include "ui/views/mus/native_widget_view_manager.h" 17 #include "ui/views/mus/native_widget_view_manager.h"
14 18
15 MUSViewsInit::MUSViewsInit(mojo::ApplicationImpl* app) : app_(app) {} 19 namespace mojo {
20
21 gfx::Display::Rotation GFXRotationFromMojomRotation(
22 mus::mojom::Rotation input) {
23 switch (input) {
24 case mus::mojom::ROTATION_VALUE_0:
25 return gfx::Display::ROTATE_0;
26 case mus::mojom::ROTATION_VALUE_90:
27 return gfx::Display::ROTATE_90;
28 case mus::mojom::ROTATION_VALUE_180:
29 return gfx::Display::ROTATE_180;
30 case mus::mojom::ROTATION_VALUE_270:
31 return gfx::Display::ROTATE_270;
32 }
33 return gfx::Display::ROTATE_0;
34 }
35
36 template <>
37 struct TypeConverter<gfx::Display, mus::mojom::DisplayPtr> {
38 static gfx::Display Convert(const mus::mojom::DisplayPtr& input) {
39 gfx::Display result;
40 result.set_id(input->id);
41 result.SetScaleAndBounds(input->device_pixel_ratio,
42 input->bounds.To<gfx::Rect>());
43 gfx::Rect work_area(
44 gfx::ToFlooredPoint(gfx::ScalePoint(
45 gfx::Point(input->work_area->x, input->work_area->y),
46 1.0f / input->device_pixel_ratio)),
47 gfx::ScaleToFlooredSize(
48 gfx::Size(input->work_area->width, input->work_area->height),
49 1.0f / input->device_pixel_ratio));
50 result.set_work_area(work_area);
51 result.set_rotation(GFXRotationFromMojomRotation(input->rotation));
52 return result;
53 }
54 };
55
56 } // namespace mojo
57
58 namespace {
59
60 std::vector<gfx::Display> GetDisplaysFromWindowManager(
61 mojo::ApplicationImpl* app) {
62 mus::mojom::WindowManagerPtr window_manager;
63 app->ConnectToService(mojo::URLRequest::From(std::string("mojo:example_wm")),
64 &window_manager);
65 std::vector<gfx::Display> displays;
66 window_manager->GetDisplays(
67 [&displays](mojo::Array<mus::mojom::DisplayPtr> mojom_displays) {
68 displays = mojom_displays.To<std::vector<gfx::Display>>();
69 });
70 CHECK(window_manager.WaitForIncomingResponse());
71 return displays;
72 }
73 }
74
75 MUSViewsInit::MUSViewsInit(mojo::ApplicationImpl* app)
76 : app_(app),
77 aura_init_(app,
78 "example_resources.pak",
79 GetDisplaysFromWindowManager(app)) {}
16 80
17 MUSViewsInit::~MUSViewsInit() {} 81 MUSViewsInit::~MUSViewsInit() {}
18 82
19 mus::View* MUSViewsInit::CreateWindow() { 83 mus::View* MUSViewsInit::CreateWindow() {
20 mus::mojom::WindowManagerPtr wm; 84 mus::mojom::WindowManagerPtr wm;
21 mojo::URLRequestPtr request(mojo::URLRequest::New()); 85 mojo::URLRequestPtr request(mojo::URLRequest::New());
22 request->url = "mojo:example_wm"; 86 request->url = "mojo:example_wm";
23 app_->ConnectToService(request.Pass(), &wm); 87 app_->ConnectToService(request.Pass(), &wm);
24 mojo::ViewTreeClientPtr view_tree_client; 88 mojo::ViewTreeClientPtr view_tree_client;
25 mojo::InterfaceRequest<mojo::ViewTreeClient> view_tree_client_request = 89 mojo::InterfaceRequest<mojo::ViewTreeClient> view_tree_client_request =
(...skipping 11 matching lines...) Expand all
37 views::internal::NativeWidgetDelegate* delegate) { 101 views::internal::NativeWidgetDelegate* delegate) {
38 return new views::NativeWidgetViewManager(delegate, app_->shell(), 102 return new views::NativeWidgetViewManager(delegate, app_->shell(),
39 CreateWindow()); 103 CreateWindow());
40 } 104 }
41 105
42 void MUSViewsInit::OnBeforeWidgetInit( 106 void MUSViewsInit::OnBeforeWidgetInit(
43 views::Widget::InitParams* params, 107 views::Widget::InitParams* params,
44 views::internal::NativeWidgetDelegate* delegate) {} 108 views::internal::NativeWidgetDelegate* delegate) {}
45 109
46 void MUSViewsInit::OnEmbed(mus::View* root) { 110 void MUSViewsInit::OnEmbed(mus::View* root) {
47 if (!aura_init_) {
48 aura_init_.reset(
49 new views::AuraInit(root, app_->shell(), "example_resources.pak"));
50 }
51 } 111 }
52 112
53 void MUSViewsInit::OnConnectionLost(mus::ViewTreeConnection* connection) {} 113 void MUSViewsInit::OnConnectionLost(mus::ViewTreeConnection* connection) {}
54 114
55 #if defined(OS_WIN) 115 #if defined(OS_WIN)
56 HICON MUSViewsInit::GetSmallWindowIcon() const { 116 HICON MUSViewsInit::GetSmallWindowIcon() const {
57 return nullptr; 117 return nullptr;
58 } 118 }
59 #endif 119 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698