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

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

Issue 2470963002: Makes it possible for clients to directly create WindowTreeHostMus (Closed)
Patch Set: nuke comment Created 4 years, 1 month 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_delegate.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_host_mus_delegate.h" 12 #include "ui/aura/mus/window_tree_host_mus_delegate.h"
12 #include "ui/aura/window.h" 13 #include "ui/aura/window.h"
13 #include "ui/aura/window_event_dispatcher.h" 14 #include "ui/aura/window_event_dispatcher.h"
14 #include "ui/aura/window_observer.h"
15 #include "ui/display/display.h" 15 #include "ui/display/display.h"
16 #include "ui/display/screen.h" 16 #include "ui/display/screen.h"
17 #include "ui/events/event.h" 17 #include "ui/events/event.h"
18 #include "ui/platform_window/stub/stub_window.h" 18 #include "ui/platform_window/stub/stub_window.h"
19 19
20 namespace aura { 20 namespace aura {
21 21
22 namespace { 22 namespace {
23 static uint32_t accelerated_widget_count = 1; 23 static uint32_t accelerated_widget_count = 1;
24 24
25 bool IsUsingTestContext() { 25 bool IsUsingTestContext() {
26 return aura::Env::GetInstance()->context_factory()->DoesCreateTestContexts(); 26 return aura::Env::GetInstance()->context_factory()->DoesCreateTestContexts();
27 } 27 }
28 28
29 } // namespace 29 } // namespace
30 30
31 class WindowTreeHostMus::ContentWindowObserver : public WindowObserver {
32 public:
33 ContentWindowObserver(WindowTreeHostMus* window_tree_host_mus, Window* window)
34 : window_tree_host_mus_(window_tree_host_mus), window_(window) {
35 window_->AddObserver(this);
36 }
37 ~ContentWindowObserver() override { window_->RemoveObserver(this); }
38
39 // WindowObserver:
40 void OnWindowDestroyed(Window* window) override {
41 window_tree_host_mus_->ContentWindowDestroyed();
42 }
43
44 private:
45 WindowTreeHostMus* window_tree_host_mus_;
46 Window* window_;
47
48 DISALLOW_COPY_AND_ASSIGN(ContentWindowObserver);
49 };
50
51 //////////////////////////////////////////////////////////////////////////////// 31 ////////////////////////////////////////////////////////////////////////////////
52 // WindowTreeHostMus, public: 32 // WindowTreeHostMus, public:
53 33
54 WindowTreeHostMus::WindowTreeHostMus(std::unique_ptr<WindowPortMus> window_port, 34 WindowTreeHostMus::WindowTreeHostMus(std::unique_ptr<WindowPortMus> window_port,
55 WindowTreeHostMusDelegate* delegate, 35 WindowTreeHostMusDelegate* delegate,
56 RootWindowType root_window_type, 36 int64_t display_id)
57 int64_t display_id,
58 Window* content_window)
59 : WindowTreeHostPlatform(std::move(window_port)), 37 : WindowTreeHostPlatform(std::move(window_port)),
60 display_id_(display_id), 38 display_id_(display_id),
61 root_window_type_(root_window_type), 39 delegate_(delegate) {
62 delegate_(delegate),
63 content_window_(content_window) {
64 gfx::AcceleratedWidget accelerated_widget; 40 gfx::AcceleratedWidget accelerated_widget;
65 if (IsUsingTestContext()) { 41 if (IsUsingTestContext()) {
66 accelerated_widget = gfx::kNullAcceleratedWidget; 42 accelerated_widget = gfx::kNullAcceleratedWidget;
67 } else { 43 } else {
68 // We need accelerated widget numbers to be different for each 44 // We need accelerated widget numbers to be different for each
69 // window and fit in the smallest sizeof(AcceleratedWidget) uint32_t 45 // window and fit in the smallest sizeof(AcceleratedWidget) uint32_t
70 // has this property. 46 // has this property.
71 #if defined(OS_WIN) || defined(OS_ANDROID) 47 #if defined(OS_WIN) || defined(OS_ANDROID)
72 accelerated_widget = 48 accelerated_widget =
73 reinterpret_cast<gfx::AcceleratedWidget>(accelerated_widget_count++); 49 reinterpret_cast<gfx::AcceleratedWidget>(accelerated_widget_count++);
74 #else 50 #else
75 accelerated_widget = 51 accelerated_widget =
76 static_cast<gfx::AcceleratedWidget>(accelerated_widget_count++); 52 static_cast<gfx::AcceleratedWidget>(accelerated_widget_count++);
77 #endif 53 #endif
78 } 54 }
79 // TODO(markdittmer): Use correct device-scale-factor from |window|. 55 // TODO(markdittmer): Use correct device-scale-factor from |window|.
80 OnAcceleratedWidgetAvailable(accelerated_widget, 1.f); 56 OnAcceleratedWidgetAvailable(accelerated_widget, 1.f);
81 57
58 delegate_->OnWindowTreeHostCreated(this);
59
82 SetPlatformWindow(base::MakeUnique<ui::StubWindow>( 60 SetPlatformWindow(base::MakeUnique<ui::StubWindow>(
83 this, 61 this,
84 false)); // Do not advertise accelerated widget; already set manually. 62 false)); // Do not advertise accelerated widget; already set manually.
85 63
86 if (content_window_) { 64 input_method_ = base::MakeUnique<InputMethodMus>(this, window());
87 window()->AddChild(content_window_);
88 window()->SetBounds(gfx::Rect(content_window_->bounds().size()));
89 content_window_observer_ =
90 base::MakeUnique<ContentWindowObserver>(this, content_window_);
91 } else {
92 // Initialize the stub platform window bounds to those of the ui::Window.
93 platform_window()->SetBounds(window()->bounds());
94 }
95
96 input_method_ = base::MakeUnique<InputMethodMus>(
97 this, content_window_ ? content_window_ : window());
98 65
99 // TODO: hook up to compositor correctly. 66 // TODO: hook up to compositor correctly.
100 // compositor()->SetWindow(window); 67 // compositor()->SetWindow(window);
101 68
102 compositor()->SetHostHasTransparentBackground(true); 69 compositor()->SetHostHasTransparentBackground(true);
103 70
104 // Mus windows are assumed hidden. 71 // Mus windows are assumed hidden.
105 compositor()->SetVisible(false); 72 compositor()->SetVisible(false);
106 } 73 }
107 74
75 WindowTreeHostMus::WindowTreeHostMus(WindowTreeClient* window_tree_client)
76 : WindowTreeHostMus(
77 static_cast<WindowTreeHostMusDelegate*>(window_tree_client)
78 ->CreateWindowPortForTopLevel(),
79 window_tree_client,
80 display::Screen::GetScreen()->GetPrimaryDisplay().id()) {}
81
108 WindowTreeHostMus::~WindowTreeHostMus() { 82 WindowTreeHostMus::~WindowTreeHostMus() {
109 DestroyCompositor(); 83 DestroyCompositor();
110 DestroyDispatcher(); 84 DestroyDispatcher();
111 } 85 }
112 86
113 void WindowTreeHostMus::SetBoundsFromServer(const gfx::Rect& bounds) { 87 void WindowTreeHostMus::SetBoundsFromServer(const gfx::Rect& bounds) {
114 base::AutoReset<bool> resetter(&in_set_bounds_from_server_, true); 88 base::AutoReset<bool> resetter(&in_set_bounds_from_server_, true);
115 SetBounds(bounds); 89 SetBounds(bounds);
116 } 90 }
117 91
118 display::Display WindowTreeHostMus::GetDisplay() const { 92 display::Display WindowTreeHostMus::GetDisplay() const {
119 for (const display::Display& display : 93 for (const display::Display& display :
120 display::Screen::GetScreen()->GetAllDisplays()) { 94 display::Screen::GetScreen()->GetAllDisplays()) {
121 if (display.id() == display_id_) 95 if (display.id() == display_id_)
122 return display; 96 return display;
123 } 97 }
124 return display::Display(); 98 return display::Display();
125 } 99 }
126 100
127 Window* WindowTreeHostMus::GetWindowWithServerWindow() {
128 return content_window_ ? content_window_ : window();
129 }
130
131 void WindowTreeHostMus::ContentWindowDestroyed() {
132 delete this;
133 }
134
135 void WindowTreeHostMus::ShowImpl() { 101 void WindowTreeHostMus::ShowImpl() {
136 WindowTreeHostPlatform::ShowImpl(); 102 WindowTreeHostPlatform::ShowImpl();
137 window()->Show(); 103 window()->Show();
138 if (content_window_)
139 content_window_->Show();
140 } 104 }
141 105
142 void WindowTreeHostMus::HideImpl() { 106 void WindowTreeHostMus::HideImpl() {
143 WindowTreeHostPlatform::HideImpl(); 107 WindowTreeHostPlatform::HideImpl();
144 window()->Hide(); 108 window()->Hide();
145 if (content_window_)
146 content_window_->Hide();
147 } 109 }
148 110
149 void WindowTreeHostMus::SetBounds(const gfx::Rect& bounds) { 111 void WindowTreeHostMus::SetBounds(const gfx::Rect& bounds) {
150 gfx::Rect adjusted_bounds(bounds); 112 if (!in_set_bounds_from_server_)
151 if (!in_set_bounds_from_server_) { 113 delegate_->OnWindowTreeHostBoundsWillChange(this, bounds);
152 delegate_->SetRootWindowBounds(GetWindowWithServerWindow(), 114 WindowTreeHostPlatform::SetBounds(bounds);
153 &adjusted_bounds);
154 }
155 WindowTreeHostPlatform::SetBounds(adjusted_bounds);
156 if (content_window_)
157 content_window_->SetBounds(adjusted_bounds);
158 }
159
160 gfx::Rect WindowTreeHostMus::GetBounds() const {
161 // TODO(sky): this is wrong, root windows need to be told their location
162 // relative to the display.
163 const display::Display display(GetDisplay());
164 const gfx::Vector2d origin(origin_offset_ +
165 display.bounds().OffsetFromOrigin());
166 return gfx::Rect(gfx::Point(origin.x(), origin.y()),
167 WindowTreeHostPlatform::GetBounds().size());
168 }
169
170 gfx::Point WindowTreeHostMus::GetLocationOnNativeScreen() const {
171 // TODO(sky): this is wrong, root windows need to be told their location
172 // relative to the display.
173 return gfx::Point(origin_offset_.x(), origin_offset_.y());
174 } 115 }
175 116
176 void WindowTreeHostMus::DispatchEvent(ui::Event* event) { 117 void WindowTreeHostMus::DispatchEvent(ui::Event* event) {
177 DCHECK(!event->IsKeyEvent()); 118 DCHECK(!event->IsKeyEvent());
178 WindowTreeHostPlatform::DispatchEvent(event); 119 WindowTreeHostPlatform::DispatchEvent(event);
179 } 120 }
180 121
181 void WindowTreeHostMus::OnClosed() { 122 void WindowTreeHostMus::OnClosed() {
182 } 123 }
183 124
184 void WindowTreeHostMus::OnActivationChanged(bool active) { 125 void WindowTreeHostMus::OnActivationChanged(bool active) {
185 if (active) 126 if (active)
186 GetInputMethod()->OnFocus(); 127 GetInputMethod()->OnFocus();
187 else 128 else
188 GetInputMethod()->OnBlur(); 129 GetInputMethod()->OnBlur();
189 WindowTreeHostPlatform::OnActivationChanged(active); 130 WindowTreeHostPlatform::OnActivationChanged(active);
190 } 131 }
191 132
192 void WindowTreeHostMus::OnCloseRequest() { 133 void WindowTreeHostMus::OnCloseRequest() {
193 OnHostCloseRequested(); 134 OnHostCloseRequested();
194 } 135 }
195 136
196 gfx::ICCProfile WindowTreeHostMus::GetICCProfileForCurrentDisplay() { 137 gfx::ICCProfile WindowTreeHostMus::GetICCProfileForCurrentDisplay() {
197 // TODO: This should read the profile from mus. crbug.com/647510 138 // TODO: This should read the profile from mus. crbug.com/647510
198 return gfx::ICCProfile(); 139 return gfx::ICCProfile();
199 } 140 }
200 141
201 } // namespace aura 142 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/mus/window_tree_host_mus.h ('k') | ui/aura/mus/window_tree_host_mus_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698