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

Side by Side Diff: ui/aura/mus/window_tree_host_mus.cc

Issue 2823903005: Extracts parameters to WindowTreeHostMus into structure (Closed)
Patch Set: move constructor Created 3 years, 8 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
« no previous file with comments | « ui/aura/mus/window_tree_host_mus.h ('k') | ui/aura/mus/window_tree_host_mus_init_params.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ui/aura/mus/window_tree_host_mus.h" 5 #include "ui/aura/mus/window_tree_host_mus.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "ui/aura/env.h" 8 #include "ui/aura/env.h"
9 #include "ui/aura/mus/input_method_mus.h" 9 #include "ui/aura/mus/input_method_mus.h"
10 #include "ui/aura/mus/window_port_mus.h" 10 #include "ui/aura/mus/window_port_mus.h"
11 #include "ui/aura/mus/window_tree_client.h" 11 #include "ui/aura/mus/window_tree_client.h"
12 #include "ui/aura/mus/window_tree_host_mus_delegate.h" 12 #include "ui/aura/mus/window_tree_host_mus_delegate.h"
13 #include "ui/aura/mus/window_tree_host_mus_init_params.h"
13 #include "ui/aura/window.h" 14 #include "ui/aura/window.h"
14 #include "ui/aura/window_event_dispatcher.h" 15 #include "ui/aura/window_event_dispatcher.h"
15 #include "ui/base/class_property.h" 16 #include "ui/base/class_property.h"
16 #include "ui/display/display.h" 17 #include "ui/display/display.h"
17 #include "ui/display/screen.h" 18 #include "ui/display/screen.h"
18 #include "ui/events/event.h" 19 #include "ui/events/event.h"
19 #include "ui/platform_window/stub/stub_window.h" 20 #include "ui/platform_window/stub/stub_window.h"
20 21
21 DECLARE_UI_CLASS_PROPERTY_TYPE(aura::WindowTreeHostMus*); 22 DECLARE_UI_CLASS_PROPERTY_TYPE(aura::WindowTreeHostMus*);
22 23
23 namespace aura { 24 namespace aura {
24 25
25 namespace { 26 namespace {
26 27
27 DEFINE_UI_CLASS_PROPERTY_KEY( 28 DEFINE_UI_CLASS_PROPERTY_KEY(
28 WindowTreeHostMus*, kWindowTreeHostMusKey, nullptr); 29 WindowTreeHostMus*, kWindowTreeHostMusKey, nullptr);
29 30
30 static uint32_t accelerated_widget_count = 1; 31 static uint32_t accelerated_widget_count = 1;
31 32
32 bool IsUsingTestContext() { 33 bool IsUsingTestContext() {
33 return aura::Env::GetInstance()->context_factory()->DoesCreateTestContexts(); 34 return aura::Env::GetInstance()->context_factory()->DoesCreateTestContexts();
34 } 35 }
35 36
36 } // namespace 37 } // namespace
37 38
38 //////////////////////////////////////////////////////////////////////////////// 39 ////////////////////////////////////////////////////////////////////////////////
39 // WindowTreeHostMus, public: 40 // WindowTreeHostMus, public:
40 41
41 WindowTreeHostMus::WindowTreeHostMus( 42 WindowTreeHostMus::WindowTreeHostMus(WindowTreeHostMusInitParams init_params)
42 std::unique_ptr<WindowPortMus> window_port, 43 : WindowTreeHostPlatform(std::move(init_params.window_port)),
43 WindowTreeClient* window_tree_client, 44 display_id_(init_params.display_id),
44 int64_t display_id, 45 delegate_(init_params.window_tree_client) {
45 const cc::FrameSinkId& frame_sink_id,
46 const std::map<std::string, std::vector<uint8_t>>* properties)
47 : WindowTreeHostPlatform(std::move(window_port)),
48 display_id_(display_id),
49 delegate_(window_tree_client) {
50 window()->SetProperty(kWindowTreeHostMusKey, this); 46 window()->SetProperty(kWindowTreeHostMusKey, this);
51 // TODO(sky): find a cleaner way to set this! Better solution is to likely 47 // TODO(sky): find a cleaner way to set this! Better solution is to likely
52 // have constructor take aura::Window. 48 // have constructor take aura::Window.
53 WindowPortMus* window_mus = WindowPortMus::Get(window()); 49 WindowPortMus* window_mus = WindowPortMus::Get(window());
54 window_mus->window_ = window(); 50 window_mus->window_ = window();
55 if (properties) { 51 // Apply the properties before initializing the window, that way the server
56 // Apply the properties before initializing the window, that way the 52 // seems them at the time the window is created.
57 // server seems them at the time the window is created. 53 for (auto& pair : init_params.properties)
58 for (auto& pair : *properties) 54 window_mus->SetPropertyFromServer(pair.first, &pair.second);
59 window_mus->SetPropertyFromServer(pair.first, &pair.second);
60 }
61 // TODO(fsamuel): Once the display compositor is decoupled from the browser 55 // TODO(fsamuel): Once the display compositor is decoupled from the browser
62 // process then ui::Compositor will not a cc::FrameSinkId. 56 // process then ui::Compositor will not a cc::FrameSinkId.
63 CreateCompositor(frame_sink_id); 57 CreateCompositor(init_params.frame_sink_id);
64 gfx::AcceleratedWidget accelerated_widget; 58 gfx::AcceleratedWidget accelerated_widget;
65 if (IsUsingTestContext()) { 59 if (IsUsingTestContext()) {
66 accelerated_widget = gfx::kNullAcceleratedWidget; 60 accelerated_widget = gfx::kNullAcceleratedWidget;
67 } else { 61 } else {
68 // We need accelerated widget numbers to be different for each 62 // We need accelerated widget numbers to be different for each
69 // window and fit in the smallest sizeof(AcceleratedWidget) uint32_t 63 // window and fit in the smallest sizeof(AcceleratedWidget) uint32_t
70 // has this property. 64 // has this property.
71 #if defined(OS_WIN) || defined(OS_ANDROID) 65 #if defined(OS_WIN) || defined(OS_ANDROID)
72 accelerated_widget = 66 accelerated_widget =
73 reinterpret_cast<gfx::AcceleratedWidget>(accelerated_widget_count++); 67 reinterpret_cast<gfx::AcceleratedWidget>(accelerated_widget_count++);
74 #else 68 #else
75 accelerated_widget = 69 accelerated_widget =
76 static_cast<gfx::AcceleratedWidget>(accelerated_widget_count++); 70 static_cast<gfx::AcceleratedWidget>(accelerated_widget_count++);
77 #endif 71 #endif
78 } 72 }
79 OnAcceleratedWidgetAvailable(accelerated_widget, 73 OnAcceleratedWidgetAvailable(accelerated_widget,
80 GetDisplay().device_scale_factor()); 74 GetDisplay().device_scale_factor());
81 75
82 delegate_->OnWindowTreeHostCreated(this); 76 delegate_->OnWindowTreeHostCreated(this);
83 77
84 SetPlatformWindow(base::MakeUnique<ui::StubWindow>( 78 // Do not advertise accelerated widget; already set manually.
85 this, 79 const bool use_default_accelerated_widget = false;
86 false)); // Do not advertise accelerated widget; already set manually. 80 SetPlatformWindow(
81 base::MakeUnique<ui::StubWindow>(this, use_default_accelerated_widget));
87 82
88 input_method_ = base::MakeUnique<InputMethodMus>(this, window()); 83 input_method_ = base::MakeUnique<InputMethodMus>(this, window());
89 input_method_->Init(window_tree_client->connector()); 84 input_method_->Init(init_params.window_tree_client->connector());
90 SetSharedInputMethod(input_method_.get()); 85 SetSharedInputMethod(input_method_.get());
91 86
92 compositor()->SetHostHasTransparentBackground(true); 87 compositor()->SetHostHasTransparentBackground(true);
93 88
94 // Mus windows are assumed hidden. 89 // Mus windows are assumed hidden.
95 compositor()->SetVisible(false); 90 compositor()->SetVisible(false);
96 91
97 if (frame_sink_id.is_valid()) 92 if (init_params.frame_sink_id.is_valid())
98 window_mus->SetFrameSinkIdFromServer(frame_sink_id); 93 window_mus->SetFrameSinkIdFromServer(init_params.frame_sink_id);
99 } 94 }
100 95
101 // Pass |properties| to CreateWindowPortForTopLevel() so that |properties|
102 // are passed to the server *and* pass |properties| to the WindowTreeHostMus
103 // constructor (above) which applies the properties to the Window. Some of the
104 // properties may be server specific and not applied to the Window.
105 WindowTreeHostMus::WindowTreeHostMus(
106 WindowTreeClient* window_tree_client,
107 const cc::FrameSinkId& frame_sink_id,
108 const std::map<std::string, std::vector<uint8_t>>* properties)
109 : WindowTreeHostMus(
110 static_cast<WindowTreeHostMusDelegate*>(window_tree_client)
111 ->CreateWindowPortForTopLevel(properties),
112 window_tree_client,
113 display::Screen::GetScreen()->GetPrimaryDisplay().id(),
114 frame_sink_id,
115 properties) {}
116
117 WindowTreeHostMus::~WindowTreeHostMus() { 96 WindowTreeHostMus::~WindowTreeHostMus() {
118 DestroyCompositor(); 97 DestroyCompositor();
119 DestroyDispatcher(); 98 DestroyDispatcher();
120 } 99 }
121 100
122 // static 101 // static
123 WindowTreeHostMus* WindowTreeHostMus::ForWindow(aura::Window* window) { 102 WindowTreeHostMus* WindowTreeHostMus::ForWindow(aura::Window* window) {
124 if (!window) 103 if (!window)
125 return nullptr; 104 return nullptr;
126 105
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 void WindowTreeHostMus::MoveCursorToScreenLocationInPixels( 203 void WindowTreeHostMus::MoveCursorToScreenLocationInPixels(
225 const gfx::Point& location_in_pixels) { 204 const gfx::Point& location_in_pixels) {
226 // TODO: this needs to message the server http://crbug.com/693340. Setting 205 // TODO: this needs to message the server http://crbug.com/693340. Setting
227 // the location is really only appropriate in tests, outside of tests this 206 // the location is really only appropriate in tests, outside of tests this
228 // value is ignored. 207 // value is ignored.
229 NOTIMPLEMENTED(); 208 NOTIMPLEMENTED();
230 Env::GetInstance()->set_last_mouse_location(location_in_pixels); 209 Env::GetInstance()->set_last_mouse_location(location_in_pixels);
231 } 210 }
232 211
233 } // namespace aura 212 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/mus/window_tree_host_mus.h ('k') | ui/aura/mus/window_tree_host_mus_init_params.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698