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

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

Issue 2456623002: Fixes to WindowTreeHostMus (Closed)
Patch Set: merge 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_host_mus_delegate.h"
11 #include "ui/aura/window.h" 12 #include "ui/aura/window.h"
12 #include "ui/aura/window_event_dispatcher.h" 13 #include "ui/aura/window_event_dispatcher.h"
13 #include "ui/aura/window_observer.h" 14 #include "ui/aura/window_observer.h"
15 #include "ui/display/display.h"
16 #include "ui/display/screen.h"
14 #include "ui/events/event.h" 17 #include "ui/events/event.h"
15 #include "ui/platform_window/stub/stub_window.h" 18 #include "ui/platform_window/stub/stub_window.h"
16 19
17 namespace aura { 20 namespace aura {
18 21
19 namespace { 22 namespace {
20 static uint32_t accelerated_widget_count = 1; 23 static uint32_t accelerated_widget_count = 1;
21 24
22 bool IsUsingTestContext() { 25 bool IsUsingTestContext() {
23 return aura::Env::GetInstance()->context_factory()->DoesCreateTestContexts(); 26 return aura::Env::GetInstance()->context_factory()->DoesCreateTestContexts();
24 } 27 }
25 28
26 } // namespace 29 } // namespace
27 30
28 class WindowTreeHostMus::ContentWindowObserver : public WindowObserver { 31 class WindowTreeHostMus::ContentWindowObserver : public WindowObserver {
29 public: 32 public:
30 ContentWindowObserver(WindowTreeHostMus* window_tree_host_mus, Window* window) 33 ContentWindowObserver(WindowTreeHostMus* window_tree_host_mus, Window* window)
31 : window_tree_host_mus_(window_tree_host_mus), window_(window) { 34 : window_tree_host_mus_(window_tree_host_mus), window_(window) {
32 window_->AddObserver(this); 35 window_->AddObserver(this);
33 } 36 }
34 ~ContentWindowObserver() override { window_->RemoveObserver(this); } 37 ~ContentWindowObserver() override { window_->RemoveObserver(this); }
35 38
36 // WindowObserver: 39 // WindowObserver:
37 void OnWindowDestroyed(Window* window) override { 40 void OnWindowDestroyed(Window* window) override {
38 window_tree_host_mus_->ContentWindowDestroyed(); 41 window_tree_host_mus_->ContentWindowDestroyed();
39 } 42 }
40 void OnWindowBoundsChanged(Window* window,
41 const gfx::Rect& old_bounds,
42 const gfx::Rect& new_bounds) override {
43 if (old_bounds.size() != new_bounds.size())
44 window_tree_host_mus_->ContentWindowResized();
45 }
46 void OnWindowVisibilityChanging(Window* window, bool visible) override {
47 window_tree_host_mus_->ContentWindowVisibilityChanging(visible);
48 }
49 43
50 private: 44 private:
51 WindowTreeHostMus* window_tree_host_mus_; 45 WindowTreeHostMus* window_tree_host_mus_;
52 Window* window_; 46 Window* window_;
53 47
54 DISALLOW_COPY_AND_ASSIGN(ContentWindowObserver); 48 DISALLOW_COPY_AND_ASSIGN(ContentWindowObserver);
55 }; 49 };
56 50
57 //////////////////////////////////////////////////////////////////////////////// 51 ////////////////////////////////////////////////////////////////////////////////
58 // WindowTreeHostMus, public: 52 // WindowTreeHostMus, public:
59 53
60 WindowTreeHostMus::WindowTreeHostMus(std::unique_ptr<WindowPortMus> window_port, 54 WindowTreeHostMus::WindowTreeHostMus(std::unique_ptr<WindowPortMus> window_port,
55 WindowTreeHostMusDelegate* delegate,
56 RootWindowType root_window_type,
57 int64_t display_id,
61 Window* content_window) 58 Window* content_window)
62 : WindowTreeHostPlatform(std::move(window_port)), 59 : WindowTreeHostPlatform(std::move(window_port)),
60 display_id_(display_id),
61 root_window_type_(root_window_type),
62 delegate_(delegate),
63 content_window_(content_window) { 63 content_window_(content_window) {
64 gfx::AcceleratedWidget accelerated_widget; 64 gfx::AcceleratedWidget accelerated_widget;
65 if (IsUsingTestContext()) { 65 if (IsUsingTestContext()) {
66 accelerated_widget = gfx::kNullAcceleratedWidget; 66 accelerated_widget = gfx::kNullAcceleratedWidget;
67 } else { 67 } else {
68 // We need accelerated widget numbers to be different for each 68 // We need accelerated widget numbers to be different for each
69 // window and fit in the smallest sizeof(AcceleratedWidget) uint32_t 69 // window and fit in the smallest sizeof(AcceleratedWidget) uint32_t
70 // has this property. 70 // has this property.
71 #if defined(OS_WIN) || defined(OS_ANDROID) 71 #if defined(OS_WIN) || defined(OS_ANDROID)
72 accelerated_widget = 72 accelerated_widget =
(...skipping 16 matching lines...) Expand all
89 content_window_observer_ = 89 content_window_observer_ =
90 base::MakeUnique<ContentWindowObserver>(this, content_window_); 90 base::MakeUnique<ContentWindowObserver>(this, content_window_);
91 } else { 91 } else {
92 // Initialize the stub platform window bounds to those of the ui::Window. 92 // Initialize the stub platform window bounds to those of the ui::Window.
93 platform_window()->SetBounds(window()->bounds()); 93 platform_window()->SetBounds(window()->bounds());
94 } 94 }
95 95
96 input_method_ = base::MakeUnique<InputMethodMus>( 96 input_method_ = base::MakeUnique<InputMethodMus>(
97 this, content_window_ ? content_window_ : window()); 97 this, content_window_ ? content_window_ : window());
98 98
99 // TODO: resolve 99 // TODO: hook up to compositor correctly.
100 // compositor()->SetWindow(window); 100 // compositor()->SetWindow(window);
101 101
102 compositor()->SetHostHasTransparentBackground(true); 102 compositor()->SetHostHasTransparentBackground(true);
103
104 // Mus windows are assumed hidden.
105 compositor()->SetVisible(false);
103 } 106 }
104 107
105 WindowTreeHostMus::~WindowTreeHostMus() { 108 WindowTreeHostMus::~WindowTreeHostMus() {
106 DestroyCompositor(); 109 DestroyCompositor();
107 DestroyDispatcher(); 110 DestroyDispatcher();
108 } 111 }
109 112
113 void WindowTreeHostMus::SetBoundsFromServer(const gfx::Rect& bounds) {
114 base::AutoReset<bool> resetter(&in_set_bounds_from_server_, true);
115 SetBounds(bounds);
116 }
117
118 display::Display WindowTreeHostMus::GetDisplay() const {
119 for (const display::Display& display :
120 display::Screen::GetScreen()->GetAllDisplays()) {
121 if (display.id() == display_id_)
122 return display;
123 }
124 return display::Display();
125 }
126
127 Window* WindowTreeHostMus::GetWindowWithServerWindow() {
128 return content_window_ ? content_window_ : window();
129 }
130
110 void WindowTreeHostMus::ContentWindowDestroyed() { 131 void WindowTreeHostMus::ContentWindowDestroyed() {
111 delete this; 132 delete this;
112 } 133 }
113 134
114 void WindowTreeHostMus::ContentWindowResized() { 135 void WindowTreeHostMus::ShowImpl() {
115 window()->SetBounds(gfx::Rect(content_window_->bounds().size())); 136 WindowTreeHostPlatform::ShowImpl();
137 window()->Show();
138 if (content_window_)
139 content_window_->Show();
116 } 140 }
117 141
118 void WindowTreeHostMus::ContentWindowVisibilityChanging(bool visible) { 142 void WindowTreeHostMus::HideImpl() {
119 if (visible) 143 WindowTreeHostPlatform::HideImpl();
120 window()->Show(); 144 window()->Hide();
121 else 145 if (content_window_)
122 window()->Hide(); 146 content_window_->Hide();
147 }
148
149 void WindowTreeHostMus::SetBounds(const gfx::Rect& bounds) {
150 gfx::Rect adjusted_bounds(bounds);
151 if (!in_set_bounds_from_server_) {
152 delegate_->SetRootWindowBounds(GetWindowWithServerWindow(),
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());
123 } 174 }
124 175
125 void WindowTreeHostMus::DispatchEvent(ui::Event* event) { 176 void WindowTreeHostMus::DispatchEvent(ui::Event* event) {
126 DCHECK(!event->IsKeyEvent()); 177 DCHECK(!event->IsKeyEvent());
127 WindowTreeHostPlatform::DispatchEvent(event); 178 WindowTreeHostPlatform::DispatchEvent(event);
128 } 179 }
129 180
130 void WindowTreeHostMus::OnClosed() { 181 void WindowTreeHostMus::OnClosed() {
131 // TODO: figure out if needed.
132 /*
133 if (native_widget_)
134 native_widget_->OnPlatformWindowClosed();
135 */
136 } 182 }
137 183
138 void WindowTreeHostMus::OnActivationChanged(bool active) { 184 void WindowTreeHostMus::OnActivationChanged(bool active) {
139 if (active) 185 if (active)
140 GetInputMethod()->OnFocus(); 186 GetInputMethod()->OnFocus();
141 else 187 else
142 GetInputMethod()->OnBlur(); 188 GetInputMethod()->OnBlur();
143 // TODO: figure out if needed.
144 /*
145 if (native_widget_)
146 native_widget_->OnActivationChanged(active);
147 */
148 WindowTreeHostPlatform::OnActivationChanged(active); 189 WindowTreeHostPlatform::OnActivationChanged(active);
149 } 190 }
150 191
151 void WindowTreeHostMus::OnCloseRequest() { 192 void WindowTreeHostMus::OnCloseRequest() {
152 OnHostCloseRequested(); 193 OnHostCloseRequested();
153 } 194 }
154 195
155 gfx::ICCProfile WindowTreeHostMus::GetICCProfileForCurrentDisplay() { 196 gfx::ICCProfile WindowTreeHostMus::GetICCProfileForCurrentDisplay() {
156 // TODO: This should read the profile from mus. crbug.com/647510 197 // TODO: This should read the profile from mus. crbug.com/647510
157 return gfx::ICCProfile(); 198 return gfx::ICCProfile();
158 } 199 }
159 200
160 } // namespace aura 201 } // 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