OLD | NEW |
---|---|
1 // Copyright (c) 2012 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/views/widget/native_widget_aura.h" | 5 #include "ui/views/widget/desktop_android/desktop_native_widget_android.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/run_loop.h" | |
8 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
9 #include "third_party/skia/include/core/SkRegion.h" | 10 #include "third_party/skia/include/core/SkRegion.h" |
10 #include "ui/aura/client/aura_constants.h" | 11 #include "ui/aura/client/aura_constants.h" |
11 #include "ui/aura/client/cursor_client.h" | 12 #include "ui/aura/client/cursor_client.h" |
13 #include "ui/aura/client/default_capture_client.h" | |
12 #include "ui/aura/client/focus_client.h" | 14 #include "ui/aura/client/focus_client.h" |
13 #include "ui/aura/client/screen_position_client.h" | 15 #include "ui/aura/client/screen_position_client.h" |
14 #include "ui/aura/client/window_tree_client.h" | 16 #include "ui/aura/client/window_tree_client.h" |
15 #include "ui/aura/env.h" | 17 #include "ui/aura/env.h" |
16 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
17 #include "ui/aura/window_event_dispatcher.h" | 19 #include "ui/aura/window_event_dispatcher.h" |
18 #include "ui/aura/window_observer.h" | 20 #include "ui/aura/window_observer.h" |
19 #include "ui/aura/window_tree_host.h" | 21 #include "ui/aura/window_tree_host.h" |
20 #include "ui/base/dragdrop/os_exchange_data.h" | 22 #include "ui/base/dragdrop/os_exchange_data.h" |
21 #include "ui/base/ui_base_types.h" | 23 #include "ui/base/ui_base_types.h" |
22 #include "ui/compositor/layer.h" | 24 #include "ui/compositor/layer.h" |
23 #include "ui/events/event.h" | 25 #include "ui/events/event.h" |
24 #include "ui/gfx/canvas.h" | 26 #include "ui/gfx/canvas.h" |
25 #include "ui/gfx/font_list.h" | 27 #include "ui/gfx/font_list.h" |
26 #include "ui/gfx/screen.h" | 28 #include "ui/gfx/screen.h" |
27 #include "ui/native_theme/native_theme_aura.h" | 29 #include "ui/native_theme/native_theme_aura.h" |
28 #include "ui/views/drag_utils.h" | 30 #include "ui/views/drag_utils.h" |
29 #include "ui/views/views_delegate.h" | 31 #include "ui/views/views_delegate.h" |
30 #include "ui/views/widget/drop_helper.h" | 32 #include "ui/views/widget/desktop_android/android_focus_rules.h" |
33 #include "ui/views/widget/native_widget_aura.h" | |
31 #include "ui/views/widget/native_widget_delegate.h" | 34 #include "ui/views/widget/native_widget_delegate.h" |
32 #include "ui/views/widget/root_view.h" | 35 #include "ui/views/widget/root_view.h" |
33 #include "ui/views/widget/tooltip_manager_aura.h" | 36 #include "ui/views/widget/tooltip_manager_aura.h" |
34 #include "ui/views/widget/widget_aura_utils.h" | 37 #include "ui/views/widget/widget_aura_utils.h" |
35 #include "ui/views/widget/widget_delegate.h" | 38 #include "ui/views/widget/widget_delegate.h" |
36 #include "ui/views/widget/window_reorderer.h" | 39 #include "ui/views/widget/window_reorderer.h" |
40 #include "ui/wm/core/default_activation_client.h" | |
41 #include "ui/wm/core/default_screen_position_client.h" | |
42 #include "ui/wm/core/focus_controller.h" | |
37 #include "ui/wm/core/shadow_types.h" | 43 #include "ui/wm/core/shadow_types.h" |
38 #include "ui/wm/core/window_animations.h" | 44 #include "ui/wm/core/window_animations.h" |
39 #include "ui/wm/core/window_util.h" | 45 #include "ui/wm/core/window_util.h" |
40 #include "ui/wm/public/activation_client.h" | 46 #include "ui/wm/public/activation_client.h" |
47 #include "ui/wm/public/dispatcher_client.h" | |
41 #include "ui/wm/public/drag_drop_client.h" | 48 #include "ui/wm/public/drag_drop_client.h" |
42 #include "ui/wm/public/window_move_client.h" | 49 #include "ui/wm/public/window_move_client.h" |
43 #include "ui/wm/public/window_types.h" | 50 #include "ui/wm/public/window_types.h" |
44 | 51 |
45 #if defined(OS_WIN) | 52 // TODO(bshe): Most of the code is copied from DesktopNativeWidgetAura. There |
mfomitchev
2015/11/11 22:40:32
DesktopNativeWidgetAura or NativeWidgetAura?
bshe
2015/11/12 16:19:40
Updated comment.
| |
46 #include "base/win/scoped_gdi_object.h" | 53 // will be more differences overtime. For upstreaming purpose, keep the change |
47 #include "base/win/win_util.h" | 54 // minimal. |
48 #include "ui/base/l10n/l10n_util_win.h" | 55 namespace { |
49 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_win.h" | |
50 #endif | |
51 | 56 |
52 #if defined(USE_X11) && !defined(OS_CHROMEOS) | 57 class DesktopNativeWidgetAndroidWindowTreeClient |
53 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" | 58 : public aura::client::WindowTreeClient { |
54 #endif | 59 public: |
60 explicit DesktopNativeWidgetAndroidWindowTreeClient(aura::Window* root_window) | |
61 : root_window_(root_window) { | |
62 aura::client::SetWindowTreeClient(root_window_, this); | |
63 } | |
64 ~DesktopNativeWidgetAndroidWindowTreeClient() override { | |
65 aura::client::SetWindowTreeClient(root_window_, NULL); | |
66 } | |
55 | 67 |
56 #if !defined(OS_CHROMEOS) | 68 // Overridden from client::WindowTreeClient: |
57 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 69 aura::Window* GetDefaultParent(aura::Window* context, |
58 #include "ui/views/widget/desktop_aura/desktop_window_tree_host.h" | 70 aura::Window* window, |
59 #endif | 71 const gfx::Rect& bounds) override { |
72 return root_window_; | |
73 } | |
74 | |
75 private: | |
76 aura::Window* root_window_; | |
77 | |
78 DISALLOW_COPY_AND_ASSIGN(DesktopNativeWidgetAndroidWindowTreeClient); | |
79 }; | |
80 | |
81 // TODO(bshe|jonross): Get rid of nested message loop once crbug.com/523680 is | |
82 // fiexed. | |
83 class AndroidDispatcherClient : public aura::client::DispatcherClient { | |
84 public: | |
85 AndroidDispatcherClient() : dispatcher_(nullptr) {} | |
86 ~AndroidDispatcherClient() override {} | |
87 | |
88 base::MessagePumpDispatcher* dispatcher() { return dispatcher_; } | |
89 | |
90 // aura::client::DispatcherClient: | |
91 void PrepareNestedLoopClosures(base::MessagePumpDispatcher* dispatcher, | |
92 base::Closure* run_closure, | |
93 base::Closure* quit_closure) override { | |
94 scoped_ptr<base::RunLoop> run_loop(new base::RunLoop()); | |
95 *quit_closure = run_loop->QuitClosure(); | |
96 *run_closure = | |
97 base::Bind(&AndroidDispatcherClient::RunNestedDispatcher, | |
98 base::Unretained(this), base::Passed(&run_loop), dispatcher); | |
99 } | |
100 | |
101 private: | |
102 void RunNestedDispatcher(scoped_ptr<base::RunLoop> run_loop, | |
103 base::MessagePumpDispatcher* dispatcher) { | |
104 base::AutoReset<base::MessagePumpDispatcher*> reset_dispatcher(&dispatcher_, | |
105 dispatcher); | |
106 base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); | |
107 base::MessageLoop::ScopedNestableTaskAllower allow(loop); | |
108 run_loop->Run(); | |
109 } | |
110 | |
111 base::MessagePumpDispatcher* dispatcher_; | |
112 | |
113 DISALLOW_COPY_AND_ASSIGN(AndroidDispatcherClient); | |
114 }; | |
115 | |
116 } // namespace | |
60 | 117 |
61 namespace views { | 118 namespace views { |
62 | 119 |
63 namespace { | 120 //////////////////////////////////////////////////////////////////////////////// |
121 // DesktopNativeWidgetAndroid, public | |
64 | 122 |
65 void SetRestoreBounds(aura::Window* window, const gfx::Rect& bounds) { | 123 DesktopNativeWidgetAndroid::DesktopNativeWidgetAndroid( |
66 window->SetProperty(aura::client::kRestoreBoundsKey, new gfx::Rect(bounds)); | 124 internal::NativeWidgetDelegate* delegate) |
67 } | |
68 | |
69 } // namespace | |
70 | |
71 //////////////////////////////////////////////////////////////////////////////// | |
72 // NativeWidgetAura, public: | |
73 | |
74 NativeWidgetAura::NativeWidgetAura(internal::NativeWidgetDelegate* delegate) | |
75 : delegate_(delegate), | 125 : delegate_(delegate), |
76 window_(new aura::Window(this)), | 126 window_(new aura::Window(this)), |
77 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), | 127 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), |
78 destroying_(false), | 128 destroying_(false), |
79 cursor_(gfx::kNullCursor), | 129 cursor_(gfx::kNullCursor), |
80 saved_window_state_(ui::SHOW_STATE_DEFAULT), | 130 saved_window_state_(ui::SHOW_STATE_DEFAULT), |
81 close_widget_factory_(this) { | 131 close_widget_factory_(this) { |
82 aura::client::SetFocusChangeObserver(window_, this); | 132 aura::client::SetFocusChangeObserver(window_, this); |
83 aura::client::SetActivationChangeObserver(window_, this); | 133 aura::client::SetActivationChangeObserver(window_, this); |
84 } | 134 } |
85 | 135 |
86 // static | 136 //////////////////////////////////////////////////////////////////////////////// |
87 void NativeWidgetAura::RegisterNativeWidgetForWindow( | 137 // DesktopNativeWidgetAndroid, DesktopNativeWidgetAndroid implementation: |
mfomitchev
2015/11/11 22:40:32
This header doesn't make much sense to me. The pre
bshe
2015/11/12 16:19:40
Sorry. It is probably a search and replace error.
| |
88 internal::NativeWidgetPrivate* native_widget, | |
89 aura::Window* window) { | |
90 window->set_user_data(native_widget); | |
91 } | |
92 | 138 |
93 //////////////////////////////////////////////////////////////////////////////// | 139 void DesktopNativeWidgetAndroid::InitNativeWidget( |
94 // NativeWidgetAura, internal::NativeWidgetPrivate implementation: | 140 const Widget::InitParams& params) { |
141 ownership_ = params.ownership; | |
142 NativeWidgetAura::RegisterNativeWidgetForWindow(this, window_); | |
95 | 143 |
96 void NativeWidgetAura::InitNativeWidget(const Widget::InitParams& params) { | 144 window_->SetType(GetAuraWindowTypeForWidgetType(params.type)); |
97 // Aura needs to know which desktop (Ash or regular) will manage this widget. | 145 window_->Init(params.layer_type); |
98 // See Widget::InitParams::context for details. | 146 wm::SetShadowType(window_, wm::SHADOW_TYPE_NONE); |
99 DCHECK(params.parent || params.context); | 147 window_->Show(); |
100 | 148 |
101 ownership_ = params.ownership; | 149 // TODO(bshe): Get rid of the hard coded size. Tracked in crbug.com/551923. |
150 host_.reset(aura::WindowTreeHost::Create(gfx::Rect(0, 0, 800, 600))); | |
151 host_->InitHost(); | |
152 host_->AddObserver(this); | |
102 | 153 |
103 RegisterNativeWidgetForWindow(this, window_); | 154 window_tree_client_.reset( |
104 window_->SetType(GetAuraWindowTypeForWidgetType(params.type)); | 155 new DesktopNativeWidgetAndroidWindowTreeClient(host_->window())); |
105 window_->SetProperty(aura::client::kShowStateKey, params.show_state); | 156 |
106 if (params.type == Widget::InitParams::TYPE_BUBBLE) | 157 focus_client_.reset(new wm::FocusController(new AndroidFocusRules)); |
107 aura::client::SetHideOnDeactivate(window_, true); | 158 aura::client::SetFocusClient(host_->window(), focus_client_.get()); |
108 window_->SetTransparent( | 159 host_->window()->AddPreTargetHandler(focus_client_.get()); |
109 params.opacity == Widget::InitParams::TRANSLUCENT_WINDOW); | 160 |
110 window_->Init(params.layer_type); | 161 new wm::DefaultActivationClient(host_->window()); |
111 if (params.shadow_type == Widget::InitParams::SHADOW_TYPE_NONE) | 162 |
112 SetShadowType(window_, wm::SHADOW_TYPE_NONE); | 163 capture_client_.reset( |
113 else if (params.shadow_type == Widget::InitParams::SHADOW_TYPE_DROP) | 164 new aura::client::DefaultCaptureClient(host_->window())); |
114 SetShadowType(window_, wm::SHADOW_TYPE_RECTANGULAR); | 165 |
115 if (params.type == Widget::InitParams::TYPE_CONTROL) | 166 screen_position_client_.reset(new wm::DefaultScreenPositionClient); |
116 window_->Show(); | 167 aura::client::SetScreenPositionClient(host_->window(), |
168 screen_position_client_.get()); | |
169 dispatcher_client_.reset(new AndroidDispatcherClient); | |
170 aura::client::SetDispatcherClient(host_->window(), dispatcher_client_.get()); | |
117 | 171 |
118 delegate_->OnNativeWidgetCreated(false); | 172 delegate_->OnNativeWidgetCreated(false); |
119 | 173 |
120 gfx::Rect window_bounds = params.bounds; | |
121 gfx::NativeView parent = params.parent; | |
122 gfx::NativeView context = params.context; | |
123 if (!params.child) { | |
124 // Set up the transient child before the window is added. This way the | |
125 // LayoutManager knows the window has a transient parent. | |
126 if (parent && parent->type() != ui::wm::WINDOW_TYPE_UNKNOWN) { | |
127 wm::AddTransientChild(parent, window_); | |
128 if (!context) | |
129 context = parent; | |
130 parent = NULL; | |
131 } | |
132 // SetAlwaysOnTop before SetParent so that always-on-top container is used. | |
133 SetAlwaysOnTop(params.keep_on_top); | |
134 // Make sure we have a real |window_bounds|. | |
135 if (parent && window_bounds == gfx::Rect()) { | |
136 // If a parent is specified but no bounds are given, | |
137 // use the origin of the parent's display so that the widget | |
138 // will be added to the same display as the parent. | |
139 gfx::Rect bounds = gfx::Screen::GetScreenFor(parent)-> | |
140 GetDisplayNearestWindow(parent).bounds(); | |
141 window_bounds.set_origin(bounds.origin()); | |
142 } | |
143 } | |
144 | |
145 // Set properties before adding to the parent so that its layout manager sees | |
146 // the correct values. | |
147 OnSizeConstraintsChanged(); | |
148 | |
149 if (parent) { | |
150 parent->AddChild(window_); | |
151 } else { | |
152 aura::client::ParentWindowWithContext( | |
153 window_, context->GetRootWindow(), window_bounds); | |
154 } | |
155 | |
156 // Start observing property changes. | |
157 window_->AddObserver(this); | |
158 | |
159 // Wait to set the bounds until we have a parent. That way we can know our | |
160 // true state/bounds (the LayoutManager may enforce a particular | |
161 // state/bounds). | |
162 if (IsMaximized()) | |
163 SetRestoreBounds(window_, window_bounds); | |
164 else | |
165 SetBounds(window_bounds); | |
166 window_->set_ignore_events(!params.accept_events); | |
167 DCHECK(GetWidget()->GetRootView()); | 174 DCHECK(GetWidget()->GetRootView()); |
168 if (params.type != Widget::InitParams::TYPE_TOOLTIP) | 175 if (params.type != Widget::InitParams::TYPE_TOOLTIP) |
169 tooltip_manager_.reset(new views::TooltipManagerAura(GetWidget())); | 176 tooltip_manager_.reset(new views::TooltipManagerAura(GetWidget())); |
170 | 177 |
171 drop_helper_.reset(new DropHelper(GetWidget()->GetRootView())); | |
172 if (params.type != Widget::InitParams::TYPE_TOOLTIP && | 178 if (params.type != Widget::InitParams::TYPE_TOOLTIP && |
173 params.type != Widget::InitParams::TYPE_POPUP) { | 179 params.type != Widget::InitParams::TYPE_POPUP) { |
174 aura::client::SetDragDropDelegate(window_, this); | 180 aura::client::SetDragDropDelegate(window_, this); |
175 } | 181 } |
176 | 182 |
177 aura::client::SetActivationDelegate(window_, this); | 183 aura::client::SetActivationDelegate(window_, this); |
178 | 184 |
179 window_reorderer_.reset(new WindowReorderer(window_, | 185 host_->window()->AddChild(window_); |
180 GetWidget()->GetRootView())); | 186 window_reorderer_.reset( |
181 } | 187 new WindowReorderer(window_, GetWidget()->GetRootView())); |
182 | 188 |
183 NonClientFrameView* NativeWidgetAura::CreateNonClientFrameView() { | 189 // TODO(bshe): figure out how to add cursor manager, drag drop client and all |
184 return NULL; | 190 // the necessary parts that exists in desktop_native_widget_aura. |
185 } | 191 } |
186 | 192 |
187 bool NativeWidgetAura::ShouldUseNativeFrame() const { | 193 NonClientFrameView* DesktopNativeWidgetAndroid::CreateNonClientFrameView() { |
194 NOTIMPLEMENTED(); | |
195 return nullptr; | |
196 } | |
197 | |
198 bool DesktopNativeWidgetAndroid::ShouldUseNativeFrame() const { | |
188 // There is only one frame type for aura. | 199 // There is only one frame type for aura. |
189 return false; | 200 return false; |
190 } | 201 } |
191 | 202 |
192 bool NativeWidgetAura::ShouldWindowContentsBeTransparent() const { | 203 bool DesktopNativeWidgetAndroid::ShouldWindowContentsBeTransparent() const { |
204 NOTIMPLEMENTED(); | |
193 return false; | 205 return false; |
194 } | 206 } |
195 | 207 |
196 void NativeWidgetAura::FrameTypeChanged() { | 208 void DesktopNativeWidgetAndroid::FrameTypeChanged() { |
197 // This is called when the Theme has changed; forward the event to the root | 209 NOTIMPLEMENTED(); |
198 // widget. | 210 } |
199 GetWidget()->ThemeChanged(); | 211 |
200 GetWidget()->GetRootView()->SchedulePaint(); | 212 Widget* DesktopNativeWidgetAndroid::GetWidget() { |
201 } | |
202 | |
203 Widget* NativeWidgetAura::GetWidget() { | |
204 return delegate_->AsWidget(); | 213 return delegate_->AsWidget(); |
205 } | 214 } |
206 | 215 |
207 const Widget* NativeWidgetAura::GetWidget() const { | 216 const Widget* DesktopNativeWidgetAndroid::GetWidget() const { |
208 return delegate_->AsWidget(); | 217 return delegate_->AsWidget(); |
209 } | 218 } |
210 | 219 |
211 gfx::NativeView NativeWidgetAura::GetNativeView() const { | 220 gfx::NativeView DesktopNativeWidgetAndroid::GetNativeView() const { |
212 return window_; | 221 return window_; |
213 } | 222 } |
214 | 223 |
215 gfx::NativeWindow NativeWidgetAura::GetNativeWindow() const { | 224 gfx::NativeWindow DesktopNativeWidgetAndroid::GetNativeWindow() const { |
216 return window_; | 225 return window_; |
217 } | 226 } |
218 | 227 |
219 Widget* NativeWidgetAura::GetTopLevelWidget() { | 228 Widget* DesktopNativeWidgetAndroid::GetTopLevelWidget() { |
220 NativeWidgetPrivate* native_widget = GetTopLevelNativeWidget(GetNativeView()); | 229 return GetWidget(); |
221 return native_widget ? native_widget->GetWidget() : NULL; | 230 } |
222 } | 231 |
223 | 232 const ui::Compositor* DesktopNativeWidgetAndroid::GetCompositor() const { |
224 const ui::Compositor* NativeWidgetAura::GetCompositor() const { | 233 return host_->compositor(); |
225 return window_ ? window_->layer()->GetCompositor() : NULL; | 234 } |
226 } | 235 |
227 | 236 const ui::Layer* DesktopNativeWidgetAndroid::GetLayer() const { |
228 const ui::Layer* NativeWidgetAura::GetLayer() const { | 237 return GetNativeWindow()->layer(); |
229 return window_ ? window_->layer() : NULL; | 238 } |
230 } | 239 |
231 | 240 void DesktopNativeWidgetAndroid::ReorderNativeViews() { |
232 void NativeWidgetAura::ReorderNativeViews() { | |
233 window_reorderer_->ReorderChildWindows(); | 241 window_reorderer_->ReorderChildWindows(); |
234 } | 242 } |
235 | 243 |
236 void NativeWidgetAura::ViewRemoved(View* view) { | 244 void DesktopNativeWidgetAndroid::ViewRemoved(View* view) { |
237 DCHECK(drop_helper_.get() != NULL); | 245 // TODO: Implement drag and drop. crbug.com/554029. |
mfomitchev
2015/11/11 22:40:32
TODO(bshe)
bshe
2015/11/12 16:19:40
Done.
| |
238 drop_helper_->ResetTargetViewIfEquals(view); | 246 NOTIMPLEMENTED(); |
239 } | 247 } |
240 | 248 |
241 void NativeWidgetAura::SetNativeWindowProperty(const char* name, void* value) { | 249 void DesktopNativeWidgetAndroid::SetNativeWindowProperty(const char* name, |
242 if (window_) | 250 void* value) { |
243 window_->SetNativeWindowProperty(name, value); | 251 GetNativeWindow()->SetNativeWindowProperty(name, value); |
244 } | 252 } |
245 | 253 |
246 void* NativeWidgetAura::GetNativeWindowProperty(const char* name) const { | 254 void* DesktopNativeWidgetAndroid::GetNativeWindowProperty( |
247 return window_ ? window_->GetNativeWindowProperty(name) : NULL; | 255 const char* name) const { |
248 } | 256 return GetNativeWindow()->GetNativeWindowProperty(name); |
249 | 257 } |
250 TooltipManager* NativeWidgetAura::GetTooltipManager() const { | 258 |
259 TooltipManager* DesktopNativeWidgetAndroid::GetTooltipManager() const { | |
251 return tooltip_manager_.get(); | 260 return tooltip_manager_.get(); |
252 } | 261 } |
253 | 262 |
254 void NativeWidgetAura::SetCapture() { | 263 void DesktopNativeWidgetAndroid::SetCapture() { |
255 if (window_) | 264 GetNativeWindow()->SetCapture(); |
256 window_->SetCapture(); | 265 } |
257 } | 266 |
258 | 267 void DesktopNativeWidgetAndroid::ReleaseCapture() { |
259 void NativeWidgetAura::ReleaseCapture() { | 268 GetNativeWindow()->ReleaseCapture(); |
260 if (window_) | 269 } |
261 window_->ReleaseCapture(); | 270 |
262 } | 271 bool DesktopNativeWidgetAndroid::HasCapture() const { |
263 | 272 return GetNativeWindow()->HasCapture(); |
264 bool NativeWidgetAura::HasCapture() const { | 273 } |
265 return window_ && window_->HasCapture(); | 274 |
266 } | 275 ui::InputMethod* DesktopNativeWidgetAndroid::GetInputMethod() { |
267 | 276 return host_->GetInputMethod(); |
268 ui::InputMethod* NativeWidgetAura::GetInputMethod() { | 277 } |
269 if (!window_) | 278 |
270 return nullptr; | 279 void DesktopNativeWidgetAndroid::CenterWindow(const gfx::Size& size) { |
271 aura::Window* root_window = window_->GetRootWindow(); | 280 // TODO(bshe): Implement this. See crbug.com/554208. |
272 return root_window ? root_window->GetHost()->GetInputMethod() : nullptr; | 281 NOTIMPLEMENTED(); |
273 } | 282 } |
274 | 283 |
275 void NativeWidgetAura::CenterWindow(const gfx::Size& size) { | 284 void DesktopNativeWidgetAndroid::GetWindowPlacement( |
276 if (!window_) | |
277 return; | |
278 | |
279 gfx::Rect parent_bounds(window_->parent()->GetBoundsInRootWindow()); | |
280 // When centering window, we take the intersection of the host and | |
281 // the parent. We assume the root window represents the visible | |
282 // rect of a single screen. | |
283 gfx::Rect work_area = gfx::Screen::GetScreenFor(window_)-> | |
284 GetDisplayNearestWindow(window_).work_area(); | |
285 | |
286 aura::client::ScreenPositionClient* screen_position_client = | |
287 aura::client::GetScreenPositionClient(window_->GetRootWindow()); | |
288 if (screen_position_client) { | |
289 gfx::Point origin = work_area.origin(); | |
290 screen_position_client->ConvertPointFromScreen(window_->GetRootWindow(), | |
291 &origin); | |
292 work_area.set_origin(origin); | |
293 } | |
294 | |
295 parent_bounds.Intersect(work_area); | |
296 | |
297 // If |window_|'s transient parent's bounds are big enough to fit it, then we | |
298 // center it with respect to the transient parent. | |
299 if (wm::GetTransientParent(window_)) { | |
300 gfx::Rect transient_parent_rect = | |
301 wm::GetTransientParent(window_)->GetBoundsInRootWindow(); | |
302 transient_parent_rect.Intersect(work_area); | |
303 if (transient_parent_rect.height() >= size.height() && | |
304 transient_parent_rect.width() >= size.width()) | |
305 parent_bounds = transient_parent_rect; | |
306 } | |
307 | |
308 gfx::Rect window_bounds( | |
309 parent_bounds.x() + (parent_bounds.width() - size.width()) / 2, | |
310 parent_bounds.y() + (parent_bounds.height() - size.height()) / 2, | |
311 size.width(), | |
312 size.height()); | |
313 // Don't size the window bigger than the parent, otherwise the user may not be | |
314 // able to close or move it. | |
315 window_bounds.AdjustToFit(parent_bounds); | |
316 | |
317 // Convert the bounds back relative to the parent. | |
318 gfx::Point origin = window_bounds.origin(); | |
319 aura::Window::ConvertPointToTarget(window_->GetRootWindow(), | |
320 window_->parent(), &origin); | |
321 window_bounds.set_origin(origin); | |
322 window_->SetBounds(window_bounds); | |
323 } | |
324 | |
325 void NativeWidgetAura::GetWindowPlacement( | |
326 gfx::Rect* bounds, | 285 gfx::Rect* bounds, |
327 ui::WindowShowState* show_state) const { | 286 ui::WindowShowState* show_state) const { |
328 // The interface specifies returning restored bounds, not current bounds. | 287 // TODO(bshe): Implement this. See crbug.com/554208. |
329 *bounds = GetRestoredBounds(); | 288 NOTIMPLEMENTED(); |
330 *show_state = window_ ? window_->GetProperty(aura::client::kShowStateKey) : | 289 } |
331 ui::SHOW_STATE_DEFAULT; | 290 |
332 } | 291 bool DesktopNativeWidgetAndroid::SetWindowTitle(const base::string16& title) { |
333 | 292 if (GetNativeWindow()->title() == title) |
334 bool NativeWidgetAura::SetWindowTitle(const base::string16& title) { | |
335 if (!window_) | |
336 return false; | 293 return false; |
337 if (window_->title() == title) | 294 GetNativeWindow()->SetTitle(title); |
338 return false; | |
339 window_->SetTitle(title); | |
340 return true; | 295 return true; |
341 } | 296 } |
342 | 297 |
343 void NativeWidgetAura::SetWindowIcons(const gfx::ImageSkia& window_icon, | 298 void DesktopNativeWidgetAndroid::SetWindowIcons( |
344 const gfx::ImageSkia& app_icon) { | 299 const gfx::ImageSkia& window_icon, |
345 // Aura doesn't have window icons. | 300 const gfx::ImageSkia& app_icon) { |
346 } | 301 // TODO(bshe): Implement this. See crbug.com/554208. |
mfomitchev
2015/11/11 22:40:32
Does this window icon functionality really fall un
bshe
2015/11/12 16:19:40
Done.
| |
347 | 302 NOTIMPLEMENTED(); |
348 void NativeWidgetAura::InitModalType(ui::ModalType modal_type) { | 303 } |
304 | |
305 void DesktopNativeWidgetAndroid::InitModalType(ui::ModalType modal_type) { | |
349 if (modal_type != ui::MODAL_TYPE_NONE) | 306 if (modal_type != ui::MODAL_TYPE_NONE) |
mfomitchev
2015/11/11 22:40:32
Perhaps this should just be NOTIMPLEMENTED()? Havi
bshe
2015/11/12 16:19:40
Done.
| |
350 window_->SetProperty(aura::client::kModalKey, modal_type); | 307 window_->SetProperty(aura::client::kModalKey, modal_type); |
351 } | 308 } |
352 | 309 |
353 gfx::Rect NativeWidgetAura::GetWindowBoundsInScreen() const { | 310 gfx::Rect DesktopNativeWidgetAndroid::GetWindowBoundsInScreen() const { |
354 return window_ ? window_->GetBoundsInScreen() : gfx::Rect(); | 311 return GetNativeWindow()->GetBoundsInScreen(); |
355 } | 312 } |
356 | 313 |
357 gfx::Rect NativeWidgetAura::GetClientAreaBoundsInScreen() const { | 314 gfx::Rect DesktopNativeWidgetAndroid::GetClientAreaBoundsInScreen() const { |
358 // View-to-screen coordinate system transformations depend on this returning | 315 // View-to-screen coordinate system transformations depend on this returning |
359 // the full window bounds, for example View::ConvertPointToScreen(). | 316 // the full window bounds, for example View::ConvertPointToScreen(). |
360 return window_ ? window_->GetBoundsInScreen() : gfx::Rect(); | 317 return GetNativeWindow()->GetBoundsInScreen(); |
361 } | 318 } |
362 | 319 |
363 gfx::Rect NativeWidgetAura::GetRestoredBounds() const { | 320 gfx::Rect DesktopNativeWidgetAndroid::GetRestoredBounds() const { |
364 if (!window_) | 321 // TODO(bshe): Implement this. See crbug.com/554208. |
365 return gfx::Rect(); | 322 NOTIMPLEMENTED(); |
366 | 323 return gfx::Rect(); |
367 // Restored bounds should only be relevant if the window is minimized, | 324 } |
368 // maximized, fullscreen or docked. However, in some places the code expects | 325 |
369 // GetRestoredBounds() to return the current window bounds if the window is | 326 void DesktopNativeWidgetAndroid::SetBounds(const gfx::Rect& bounds) { |
370 // not in either state. | 327 host_->SetBounds(bounds); |
mfomitchev
2015/11/11 22:40:33
Presumably, we'd need to resize the SurfaceView to
bshe
2015/11/12 16:19:40
Added a TODO.
| |
371 if (IsMinimized() || IsMaximized() || IsFullscreen()) { | 328 } |
372 // Restore bounds are in screen coordinates, no need to convert. | 329 |
373 gfx::Rect* restore_bounds = | 330 void DesktopNativeWidgetAndroid::SetSize(const gfx::Size& size) { |
374 window_->GetProperty(aura::client::kRestoreBoundsKey); | 331 gfx::Rect bounds = host_->GetBounds(); |
375 if (restore_bounds) | 332 SetBounds(gfx::Rect(bounds.origin(), size)); |
376 return *restore_bounds; | 333 } |
377 } | 334 |
378 gfx::Rect bounds = window_->GetBoundsInScreen(); | 335 void DesktopNativeWidgetAndroid::StackAbove(gfx::NativeView native_view) { |
379 if (IsDocked()) { | 336 // TODO(bshe): Implements window stacking logic. See crbug.com/554047 |
380 // Restore bounds are in screen coordinates, no need to convert. | 337 NOTIMPLEMENTED(); |
381 gfx::Rect* restore_bounds = | 338 } |
382 window_->GetProperty(aura::client::kRestoreBoundsKey); | 339 |
383 // Use current window horizontal offset origin in order to preserve docked | 340 void DesktopNativeWidgetAndroid::StackAtTop() { |
384 // alignment but preserve restored size and vertical offset for the time | 341 // TODO(bshe): Implements window stacking logic. See crbug.com/554047 |
385 // when the |window_| gets undocked. | 342 NOTIMPLEMENTED(); |
386 if (restore_bounds) { | 343 } |
387 bounds.set_size(restore_bounds->size()); | 344 |
388 bounds.set_y(restore_bounds->y()); | 345 void DesktopNativeWidgetAndroid::StackBelow(gfx::NativeView native_view) { |
389 } | 346 // TODO(bshe): Implements window stacking logic. See crbug.com/554047 |
390 } | 347 NOTIMPLEMENTED(); |
391 return bounds; | 348 } |
392 } | 349 |
393 | 350 void DesktopNativeWidgetAndroid::SetShape(SkRegion* region) { |
394 void NativeWidgetAura::SetBounds(const gfx::Rect& bounds) { | 351 GetNativeWindow()->layer()->SetAlphaShape(make_scoped_ptr(region)); |
395 if (!window_) | 352 } |
396 return; | 353 |
397 | 354 void DesktopNativeWidgetAndroid::Close() { |
398 aura::Window* root = window_->GetRootWindow(); | 355 // TODO(bshe): This might not be right. See crbug.com/554259. |
399 if (root) { | 356 DCHECK(ownership_ == Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET); |
400 aura::client::ScreenPositionClient* screen_position_client = | 357 GetNativeWindow()->SuppressPaint(); |
401 aura::client::GetScreenPositionClient(root); | 358 Hide(); |
402 if (screen_position_client) { | 359 GetNativeWindow()->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_NONE); |
403 gfx::Display dst_display = | |
404 gfx::Screen::GetScreenFor(window_)->GetDisplayMatching(bounds); | |
405 screen_position_client->SetBounds(window_, bounds, dst_display); | |
406 return; | |
407 } | |
408 } | |
409 window_->SetBounds(bounds); | |
410 } | |
411 | |
412 void NativeWidgetAura::SetSize(const gfx::Size& size) { | |
413 if (window_) | |
414 window_->SetBounds(gfx::Rect(window_->bounds().origin(), size)); | |
415 } | |
416 | |
417 void NativeWidgetAura::StackAbove(gfx::NativeView native_view) { | |
418 if (window_ && window_->parent() && | |
419 window_->parent() == native_view->parent()) | |
420 window_->parent()->StackChildAbove(window_, native_view); | |
421 } | |
422 | |
423 void NativeWidgetAura::StackAtTop() { | |
424 if (window_) | |
425 window_->parent()->StackChildAtTop(window_); | |
426 } | |
427 | |
428 void NativeWidgetAura::StackBelow(gfx::NativeView native_view) { | |
429 if (window_ && window_->parent() && | |
430 window_->parent() == native_view->parent()) | |
431 window_->parent()->StackChildBelow(window_, native_view); | |
432 } | |
433 | |
434 void NativeWidgetAura::SetShape(SkRegion* region) { | |
435 if (window_) | |
436 window_->layer()->SetAlphaShape(make_scoped_ptr(region)); | |
437 else | |
438 delete region; | |
439 } | |
440 | |
441 void NativeWidgetAura::Close() { | |
442 // |window_| may already be deleted by parent window. This can happen | |
443 // when this widget is child widget or has transient parent | |
444 // and ownership is WIDGET_OWNS_NATIVE_WIDGET. | |
445 DCHECK(window_ || | |
446 ownership_ == Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET); | |
447 if (window_) { | |
448 window_->SuppressPaint(); | |
449 Hide(); | |
450 window_->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_NONE); | |
451 } | |
452 | 360 |
453 if (!close_widget_factory_.HasWeakPtrs()) { | 361 if (!close_widget_factory_.HasWeakPtrs()) { |
454 base::MessageLoop::current()->PostTask( | 362 base::MessageLoop::current()->PostTask( |
455 FROM_HERE, | 363 FROM_HERE, base::Bind(&DesktopNativeWidgetAndroid::CloseNow, |
456 base::Bind(&NativeWidgetAura::CloseNow, | 364 close_widget_factory_.GetWeakPtr())); |
457 close_widget_factory_.GetWeakPtr())); | |
458 } | 365 } |
459 } | 366 } |
460 | 367 |
461 void NativeWidgetAura::CloseNow() { | 368 void DesktopNativeWidgetAndroid::CloseNow() { |
369 // TODO(bshe): This might not be right. See crbug.com/554259. | |
370 host_->RemoveObserver(this); | |
371 host_.reset(); | |
462 delete window_; | 372 delete window_; |
463 } | 373 } |
464 | 374 |
465 void NativeWidgetAura::Show() { | 375 void DesktopNativeWidgetAndroid::Show() { |
466 ShowWithWindowState(ui::SHOW_STATE_NORMAL); | 376 ShowWithWindowState(ui::SHOW_STATE_NORMAL); |
467 } | 377 } |
468 | 378 |
469 void NativeWidgetAura::Hide() { | 379 void DesktopNativeWidgetAndroid::Hide() { |
470 if (window_) | 380 host_->Hide(); |
471 window_->Hide(); | 381 GetNativeWindow()->Hide(); |
472 } | 382 } |
473 | 383 |
474 void NativeWidgetAura::ShowMaximizedWithBounds( | 384 void DesktopNativeWidgetAndroid::ShowMaximizedWithBounds( |
475 const gfx::Rect& restored_bounds) { | 385 const gfx::Rect& restored_bounds) { |
476 SetRestoreBounds(window_, restored_bounds); | 386 NOTIMPLEMENTED(); |
477 ShowWithWindowState(ui::SHOW_STATE_MAXIMIZED); | 387 } |
478 } | 388 |
479 | 389 void DesktopNativeWidgetAndroid::ShowWithWindowState( |
480 void NativeWidgetAura::ShowWithWindowState(ui::WindowShowState state) { | 390 ui::WindowShowState state) { |
481 if (!window_) | 391 NOTIMPLEMENTED(); |
482 return; | 392 } |
483 | 393 |
484 if (state == ui::SHOW_STATE_MAXIMIZED || state == ui::SHOW_STATE_FULLSCREEN || | 394 bool DesktopNativeWidgetAndroid::IsVisible() const { |
485 state == ui::SHOW_STATE_DOCKED) { | 395 return GetNativeWindow()->IsVisible(); |
486 window_->SetProperty(aura::client::kShowStateKey, state); | 396 } |
487 } | 397 |
488 window_->Show(); | 398 void DesktopNativeWidgetAndroid::Activate() { |
489 if (delegate_->CanActivate()) { | 399 aura::client::GetActivationClient(host_->window()) |
490 if (state != ui::SHOW_STATE_INACTIVE) | 400 ->ActivateWindow(GetNativeWindow()); |
491 Activate(); | 401 } |
492 // SetInitialFocus() should be always be called, even for | 402 |
493 // SHOW_STATE_INACTIVE. If the window has to stay inactive, the method will | 403 void DesktopNativeWidgetAndroid::Deactivate() { |
494 // do the right thing. | 404 aura::client::GetActivationClient(host_->window()) |
495 SetInitialFocus(state); | 405 ->DeactivateWindow(GetNativeWindow()); |
496 } | 406 } |
497 } | 407 |
498 | 408 bool DesktopNativeWidgetAndroid::IsActive() const { |
499 bool NativeWidgetAura::IsVisible() const { | 409 return wm::IsActiveWindow(GetNativeWindow()); |
500 return window_ && window_->IsVisible(); | 410 } |
501 } | 411 |
502 | 412 void DesktopNativeWidgetAndroid::SetAlwaysOnTop(bool on_top) { |
503 void NativeWidgetAura::Activate() { | 413 GetNativeWindow()->SetProperty(aura::client::kAlwaysOnTopKey, on_top); |
504 if (!window_) | 414 } |
505 return; | 415 |
506 | 416 bool DesktopNativeWidgetAndroid::IsAlwaysOnTop() const { |
507 // We don't necessarily have a root window yet. This can happen with | 417 return GetNativeWindow()->GetProperty(aura::client::kAlwaysOnTopKey); |
508 // constrained windows. | 418 } |
509 if (window_->GetRootWindow()) { | 419 |
510 aura::client::GetActivationClient(window_->GetRootWindow())->ActivateWindow( | 420 void DesktopNativeWidgetAndroid::SetVisibleOnAllWorkspaces( |
511 window_); | 421 bool always_visible) { |
512 } | 422 // TODO(bshe): Implement this. See crbug.com/554208. |
513 if (window_->GetProperty(aura::client::kDrawAttentionKey)) | 423 NOTIMPLEMENTED(); |
514 window_->SetProperty(aura::client::kDrawAttentionKey, false); | 424 } |
515 } | 425 |
516 | 426 void DesktopNativeWidgetAndroid::Maximize() { |
517 void NativeWidgetAura::Deactivate() { | 427 GetNativeWindow()->SetProperty(aura::client::kShowStateKey, |
mfomitchev
2015/11/11 22:40:33
Windows sizing functionality should be NOTIMPLEMEN
bshe
2015/11/12 16:19:40
Done.
| |
518 if (!window_) | 428 ui::SHOW_STATE_MAXIMIZED); |
519 return; | 429 } |
520 aura::client::GetActivationClient(window_->GetRootWindow())->DeactivateWindow( | 430 |
521 window_); | 431 void DesktopNativeWidgetAndroid::Minimize() { |
522 } | 432 GetNativeWindow()->SetProperty(aura::client::kShowStateKey, |
523 | 433 ui::SHOW_STATE_MINIMIZED); |
524 bool NativeWidgetAura::IsActive() const { | 434 } |
525 return window_ && wm::IsActiveWindow(window_); | 435 |
526 } | 436 bool DesktopNativeWidgetAndroid::IsMaximized() const { |
527 | 437 return GetNativeWindow()->GetProperty(aura::client::kShowStateKey) == |
528 void NativeWidgetAura::SetAlwaysOnTop(bool on_top) { | 438 ui::SHOW_STATE_MAXIMIZED; |
529 if (window_) | 439 } |
530 window_->SetProperty(aura::client::kAlwaysOnTopKey, on_top); | 440 |
531 } | 441 bool DesktopNativeWidgetAndroid::IsMinimized() const { |
532 | 442 return GetNativeWindow()->GetProperty(aura::client::kShowStateKey) == |
533 bool NativeWidgetAura::IsAlwaysOnTop() const { | 443 ui::SHOW_STATE_MINIMIZED; |
534 return window_ && window_->GetProperty(aura::client::kAlwaysOnTopKey); | 444 } |
535 } | 445 |
536 | 446 void DesktopNativeWidgetAndroid::Restore() { |
537 void NativeWidgetAura::SetVisibleOnAllWorkspaces(bool always_visible) { | 447 GetNativeWindow()->SetProperty(aura::client::kShowStateKey, |
538 // Not implemented on chromeos or for child widgets. | 448 ui::SHOW_STATE_NORMAL); |
539 } | 449 } |
540 | 450 |
541 void NativeWidgetAura::Maximize() { | 451 void DesktopNativeWidgetAndroid::SetFullscreen(bool fullscreen) { |
542 if (window_) | 452 if (IsFullscreen() == fullscreen) |
543 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | |
544 } | |
545 | |
546 void NativeWidgetAura::Minimize() { | |
547 if (window_) | |
548 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); | |
549 } | |
550 | |
551 bool NativeWidgetAura::IsMaximized() const { | |
552 return window_ && window_->GetProperty(aura::client::kShowStateKey) == | |
553 ui::SHOW_STATE_MAXIMIZED; | |
554 } | |
555 | |
556 bool NativeWidgetAura::IsMinimized() const { | |
557 return window_ && window_->GetProperty(aura::client::kShowStateKey) == | |
558 ui::SHOW_STATE_MINIMIZED; | |
559 } | |
560 | |
561 void NativeWidgetAura::Restore() { | |
562 if (window_) | |
563 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | |
564 } | |
565 | |
566 void NativeWidgetAura::SetFullscreen(bool fullscreen) { | |
567 if (!window_ || IsFullscreen() == fullscreen) | |
568 return; // Nothing to do. | 453 return; // Nothing to do. |
569 | 454 |
570 // Save window state before entering full screen so that it could restored | 455 // Save window state before entering full screen so that it could restored |
571 // when exiting full screen. | 456 // when exiting full screen. |
572 if (fullscreen) | 457 if (fullscreen) { |
573 saved_window_state_ = window_->GetProperty(aura::client::kShowStateKey); | 458 saved_window_state_ = |
574 | 459 GetNativeWindow()->GetProperty(aura::client::kShowStateKey); |
575 window_->SetProperty( | 460 } |
461 | |
462 GetNativeWindow()->SetProperty( | |
576 aura::client::kShowStateKey, | 463 aura::client::kShowStateKey, |
577 fullscreen ? ui::SHOW_STATE_FULLSCREEN : saved_window_state_); | 464 fullscreen ? ui::SHOW_STATE_FULLSCREEN : saved_window_state_); |
578 } | 465 } |
579 | 466 |
580 bool NativeWidgetAura::IsFullscreen() const { | 467 bool DesktopNativeWidgetAndroid::IsFullscreen() const { |
581 return window_ && window_->GetProperty(aura::client::kShowStateKey) == | 468 return GetNativeWindow()->GetProperty(aura::client::kShowStateKey) == |
582 ui::SHOW_STATE_FULLSCREEN; | 469 ui::SHOW_STATE_FULLSCREEN; |
583 } | 470 } |
584 | 471 |
585 void NativeWidgetAura::SetOpacity(unsigned char opacity) { | 472 void DesktopNativeWidgetAndroid::SetOpacity(unsigned char opacity) { |
586 if (window_) | 473 GetNativeWindow()->layer()->SetOpacity(opacity / 255.0); |
587 window_->layer()->SetOpacity(opacity / 255.0); | 474 } |
588 } | 475 |
589 | 476 void DesktopNativeWidgetAndroid::SetUseDragFrame(bool use_drag_frame) { |
590 void NativeWidgetAura::SetUseDragFrame(bool use_drag_frame) { | 477 NOTIMPLEMENTED(); |
591 NOTIMPLEMENTED(); | 478 } |
592 } | 479 |
593 | 480 void DesktopNativeWidgetAndroid::FlashFrame(bool flash) { |
594 void NativeWidgetAura::FlashFrame(bool flash) { | 481 NOTIMPLEMENTED(); |
595 if (window_) | 482 } |
596 window_->SetProperty(aura::client::kDrawAttentionKey, flash); | 483 |
597 } | 484 void DesktopNativeWidgetAndroid::RunShellDrag( |
598 | 485 View* view, |
599 void NativeWidgetAura::RunShellDrag(View* view, | 486 const ui::OSExchangeData& data, |
600 const ui::OSExchangeData& data, | 487 const gfx::Point& location, |
601 const gfx::Point& location, | 488 int operation, |
602 int operation, | 489 ui::DragDropTypes::DragEventSource source) { |
603 ui::DragDropTypes::DragEventSource source) { | 490 NOTIMPLEMENTED(); |
604 if (window_) | 491 } |
605 views::RunShellDrag(window_, data, location, operation, source); | 492 |
606 } | 493 void DesktopNativeWidgetAndroid::SchedulePaintInRect(const gfx::Rect& rect) { |
607 | 494 GetNativeWindow()->SchedulePaintInRect(rect); |
608 void NativeWidgetAura::SchedulePaintInRect(const gfx::Rect& rect) { | 495 } |
609 if (window_) | 496 |
610 window_->SchedulePaintInRect(rect); | 497 void DesktopNativeWidgetAndroid::SetCursor(gfx::NativeCursor cursor) { |
611 } | |
612 | |
613 void NativeWidgetAura::SetCursor(gfx::NativeCursor cursor) { | |
614 cursor_ = cursor; | 498 cursor_ = cursor; |
615 aura::client::CursorClient* cursor_client = | 499 aura::client::CursorClient* cursor_client = |
616 aura::client::GetCursorClient(window_->GetRootWindow()); | 500 aura::client::GetCursorClient(host_->window()); |
617 if (cursor_client) | 501 if (cursor_client) |
618 cursor_client->SetCursor(cursor); | 502 cursor_client->SetCursor(cursor); |
619 } | 503 } |
620 | 504 |
621 bool NativeWidgetAura::IsMouseEventsEnabled() const { | 505 bool DesktopNativeWidgetAndroid::IsMouseEventsEnabled() const { |
622 if (!window_) | |
623 return false; | |
624 aura::client::CursorClient* cursor_client = | 506 aura::client::CursorClient* cursor_client = |
625 aura::client::GetCursorClient(window_->GetRootWindow()); | 507 aura::client::GetCursorClient(host_->window()); |
626 return cursor_client ? cursor_client->IsMouseEventsEnabled() : true; | 508 return cursor_client ? cursor_client->IsMouseEventsEnabled() : true; |
627 } | 509 } |
628 | 510 |
629 void NativeWidgetAura::ClearNativeFocus() { | 511 void DesktopNativeWidgetAndroid::ClearNativeFocus() { |
630 aura::client::FocusClient* client = aura::client::GetFocusClient(window_); | 512 aura::client::FocusClient* client = aura::client::GetFocusClient(window_); |
631 if (window_ && client && window_->Contains(client->GetFocusedWindow())) | 513 if (client && window_->Contains(client->GetFocusedWindow())) |
632 client->ResetFocusWithinActiveWindow(window_); | 514 client->ResetFocusWithinActiveWindow(window_); |
633 } | 515 } |
634 | 516 |
635 gfx::Rect NativeWidgetAura::GetWorkAreaBoundsInScreen() const { | 517 gfx::Rect DesktopNativeWidgetAndroid::GetWorkAreaBoundsInScreen() const { |
636 if (!window_) | 518 return gfx::Screen::GetScreenFor(window_) |
637 return gfx::Rect(); | 519 ->GetDisplayNearestWindow(window_) |
638 return gfx::Screen::GetScreenFor(window_)-> | 520 .work_area(); |
639 GetDisplayNearestWindow(window_).work_area(); | 521 } |
640 } | 522 |
641 | 523 Widget::MoveLoopResult DesktopNativeWidgetAndroid::RunMoveLoop( |
642 Widget::MoveLoopResult NativeWidgetAura::RunMoveLoop( | |
643 const gfx::Vector2d& drag_offset, | 524 const gfx::Vector2d& drag_offset, |
mfomitchev
2015/11/11 22:40:32
Perhaps just make this NOTIMPLEMENTED()?
bshe
2015/11/12 16:19:40
Done.
| |
644 Widget::MoveLoopSource source, | 525 Widget::MoveLoopSource source, |
645 Widget::MoveLoopEscapeBehavior escape_behavior) { | 526 Widget::MoveLoopEscapeBehavior escape_behavior) { |
646 // |escape_behavior| is only needed on windows when running the native message | 527 // |escape_behavior| is only needed on windows when running the native message |
647 // loop. | 528 // loop. |
648 if (!window_ || !window_->GetRootWindow()) | |
649 return Widget::MOVE_LOOP_CANCELED; | |
650 aura::client::WindowMoveClient* move_client = | 529 aura::client::WindowMoveClient* move_client = |
651 aura::client::GetWindowMoveClient(window_->GetRootWindow()); | 530 aura::client::GetWindowMoveClient(host_->window()); |
652 if (!move_client) | 531 if (!move_client) |
653 return Widget::MOVE_LOOP_CANCELED; | 532 return Widget::MOVE_LOOP_CANCELED; |
654 | 533 |
655 SetCapture(); | 534 SetCapture(); |
656 aura::client::WindowMoveSource window_move_source = | 535 aura::client::WindowMoveSource window_move_source = |
657 source == Widget::MOVE_LOOP_SOURCE_MOUSE ? | 536 source == Widget::MOVE_LOOP_SOURCE_MOUSE |
658 aura::client::WINDOW_MOVE_SOURCE_MOUSE : | 537 ? aura::client::WINDOW_MOVE_SOURCE_MOUSE |
659 aura::client::WINDOW_MOVE_SOURCE_TOUCH; | 538 : aura::client::WINDOW_MOVE_SOURCE_TOUCH; |
660 if (move_client->RunMoveLoop(window_, drag_offset, window_move_source) == | 539 if (move_client->RunMoveLoop(window_, drag_offset, window_move_source) == |
661 aura::client::MOVE_SUCCESSFUL) { | 540 aura::client::MOVE_SUCCESSFUL) { |
662 return Widget::MOVE_LOOP_SUCCESSFUL; | 541 return Widget::MOVE_LOOP_SUCCESSFUL; |
663 } | 542 } |
664 return Widget::MOVE_LOOP_CANCELED; | 543 return Widget::MOVE_LOOP_CANCELED; |
665 } | 544 } |
666 | 545 |
667 void NativeWidgetAura::EndMoveLoop() { | 546 void DesktopNativeWidgetAndroid::EndMoveLoop() { |
668 if (!window_ || !window_->GetRootWindow()) | |
669 return; | |
670 aura::client::WindowMoveClient* move_client = | 547 aura::client::WindowMoveClient* move_client = |
671 aura::client::GetWindowMoveClient(window_->GetRootWindow()); | 548 aura::client::GetWindowMoveClient(host_->window()); |
672 if (move_client) | 549 if (move_client) |
673 move_client->EndMoveLoop(); | 550 move_client->EndMoveLoop(); |
674 } | 551 } |
675 | 552 |
676 void NativeWidgetAura::SetVisibilityChangedAnimationsEnabled(bool value) { | 553 void DesktopNativeWidgetAndroid::SetVisibilityChangedAnimationsEnabled( |
677 if (window_) | 554 bool value) { |
678 window_->SetProperty(aura::client::kAnimationsDisabledKey, !value); | 555 GetNativeWindow()->SetProperty(aura::client::kAnimationsDisabledKey, !value); |
679 } | 556 } |
680 | 557 |
681 void NativeWidgetAura::SetVisibilityAnimationDuration( | 558 void DesktopNativeWidgetAndroid::SetVisibilityAnimationDuration( |
682 const base::TimeDelta& duration) { | 559 const base::TimeDelta& duration) { |
683 wm::SetWindowVisibilityAnimationDuration(window_, duration); | 560 wm::SetWindowVisibilityAnimationDuration(GetNativeWindow(), duration); |
684 } | 561 } |
685 | 562 |
686 void NativeWidgetAura::SetVisibilityAnimationTransition( | 563 void DesktopNativeWidgetAndroid::SetVisibilityAnimationTransition( |
687 Widget::VisibilityTransition transition) { | 564 Widget::VisibilityTransition transition) { |
688 wm::WindowVisibilityAnimationTransition wm_transition = wm::ANIMATE_NONE; | 565 wm::WindowVisibilityAnimationTransition wm_transition = wm::ANIMATE_NONE; |
689 switch (transition) { | 566 switch (transition) { |
690 case Widget::ANIMATE_SHOW: | 567 case Widget::ANIMATE_SHOW: |
691 wm_transition = wm::ANIMATE_SHOW; | 568 wm_transition = wm::ANIMATE_SHOW; |
692 break; | 569 break; |
693 case Widget::ANIMATE_HIDE: | 570 case Widget::ANIMATE_HIDE: |
694 wm_transition = wm::ANIMATE_HIDE; | 571 wm_transition = wm::ANIMATE_HIDE; |
695 break; | 572 break; |
696 case Widget::ANIMATE_BOTH: | 573 case Widget::ANIMATE_BOTH: |
697 wm_transition = wm::ANIMATE_BOTH; | 574 wm_transition = wm::ANIMATE_BOTH; |
698 break; | 575 break; |
699 case Widget::ANIMATE_NONE: | 576 case Widget::ANIMATE_NONE: |
700 wm_transition = wm::ANIMATE_NONE; | 577 wm_transition = wm::ANIMATE_NONE; |
701 break; | 578 break; |
702 } | 579 } |
703 wm::SetWindowVisibilityAnimationTransition(window_, wm_transition); | 580 wm::SetWindowVisibilityAnimationTransition(GetNativeWindow(), wm_transition); |
704 } | 581 } |
705 | 582 |
706 ui::NativeTheme* NativeWidgetAura::GetNativeTheme() const { | 583 ui::NativeTheme* DesktopNativeWidgetAndroid::GetNativeTheme() const { |
707 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | |
708 return DesktopWindowTreeHost::GetNativeTheme(window_); | |
709 #else | |
710 return ui::NativeThemeAura::instance(); | 584 return ui::NativeThemeAura::instance(); |
711 #endif | |
712 } | 585 } |
713 | 586 |
714 void NativeWidgetAura::OnRootViewLayout() { | 587 void DesktopNativeWidgetAndroid::OnRootViewLayout() { |
588 NOTIMPLEMENTED(); | |
715 } | 589 } |
716 | 590 |
717 bool NativeWidgetAura::IsTranslucentWindowOpacitySupported() const { | 591 bool DesktopNativeWidgetAndroid::IsTranslucentWindowOpacitySupported() const { |
718 return true; | 592 return true; |
719 } | 593 } |
720 | 594 |
721 void NativeWidgetAura::OnSizeConstraintsChanged() { | 595 void DesktopNativeWidgetAndroid::OnSizeConstraintsChanged() { |
722 window_->SetProperty(aura::client::kCanMaximizeKey, | 596 window_->SetProperty(aura::client::kCanMaximizeKey, |
723 GetWidget()->widget_delegate()->CanMaximize()); | 597 GetWidget()->widget_delegate()->CanMaximize()); |
724 window_->SetProperty(aura::client::kCanMinimizeKey, | 598 window_->SetProperty(aura::client::kCanMinimizeKey, |
725 GetWidget()->widget_delegate()->CanMinimize()); | 599 GetWidget()->widget_delegate()->CanMinimize()); |
726 window_->SetProperty(aura::client::kCanResizeKey, | 600 window_->SetProperty(aura::client::kCanResizeKey, |
727 GetWidget()->widget_delegate()->CanResize()); | 601 GetWidget()->widget_delegate()->CanResize()); |
728 } | 602 } |
729 | 603 |
730 void NativeWidgetAura::RepostNativeEvent(gfx::NativeEvent native_event) { | 604 void DesktopNativeWidgetAndroid::RepostNativeEvent( |
605 gfx::NativeEvent native_event) { | |
731 OnEvent(native_event); | 606 OnEvent(native_event); |
732 } | 607 } |
733 | 608 |
734 //////////////////////////////////////////////////////////////////////////////// | 609 //////////////////////////////////////////////////////////////////////////////// |
735 // NativeWidgetAura, aura::WindowDelegate implementation: | 610 // DesktopNativeWidgetAndroid, aura::WindowDelegate implementation: |
736 | 611 |
737 gfx::Size NativeWidgetAura::GetMinimumSize() const { | 612 gfx::Size DesktopNativeWidgetAndroid::GetMinimumSize() const { |
738 return delegate_->GetMinimumSize(); | 613 return delegate_->GetMinimumSize(); |
739 } | 614 } |
740 | 615 |
741 gfx::Size NativeWidgetAura::GetMaximumSize() const { | 616 gfx::Size DesktopNativeWidgetAndroid::GetMaximumSize() const { |
742 // If a window have a maximum size, the window should not be | 617 // If a window have a maximum size, the window should not be |
743 // maximizable. | 618 // maximizable. |
744 DCHECK(delegate_->GetMaximumSize().IsEmpty() || | 619 DCHECK(delegate_->GetMaximumSize().IsEmpty() || |
745 !window_->GetProperty(aura::client::kCanMaximizeKey)); | 620 !window_->GetProperty(aura::client::kCanMaximizeKey)); |
746 return delegate_->GetMaximumSize(); | 621 return delegate_->GetMaximumSize(); |
747 } | 622 } |
748 | 623 |
749 void NativeWidgetAura::OnBoundsChanged(const gfx::Rect& old_bounds, | 624 void DesktopNativeWidgetAndroid::OnBoundsChanged(const gfx::Rect& old_bounds, |
750 const gfx::Rect& new_bounds) { | 625 const gfx::Rect& new_bounds) { |
751 // Assume that if the old bounds was completely empty a move happened. This | 626 // Assume that if the old bounds was completely empty a move happened. This |
752 // handles the case of a maximize animation acquiring the layer (acquiring a | 627 // handles the case of a maximize animation acquiring the layer (acquiring a |
753 // layer results in clearing the bounds). | 628 // layer results in clearing the bounds). |
754 if (old_bounds.origin() != new_bounds.origin() || | 629 if (old_bounds.origin() != new_bounds.origin() || |
755 (old_bounds == gfx::Rect(0, 0, 0, 0) && !new_bounds.IsEmpty())) { | 630 (old_bounds == gfx::Rect(0, 0, 0, 0) && !new_bounds.IsEmpty())) { |
756 delegate_->OnNativeWidgetMove(); | 631 delegate_->OnNativeWidgetMove(); |
757 } | 632 } |
758 if (old_bounds.size() != new_bounds.size()) | 633 if (old_bounds.size() != new_bounds.size()) |
759 delegate_->OnNativeWidgetSizeChanged(new_bounds.size()); | 634 delegate_->OnNativeWidgetSizeChanged(new_bounds.size()); |
760 } | 635 } |
761 | 636 |
762 gfx::NativeCursor NativeWidgetAura::GetCursor(const gfx::Point& point) { | 637 gfx::NativeCursor DesktopNativeWidgetAndroid::GetCursor( |
638 const gfx::Point& point) { | |
763 return cursor_; | 639 return cursor_; |
764 } | 640 } |
765 | 641 |
766 int NativeWidgetAura::GetNonClientComponent(const gfx::Point& point) const { | 642 int DesktopNativeWidgetAndroid::GetNonClientComponent( |
643 const gfx::Point& point) const { | |
767 return delegate_->GetNonClientComponent(point); | 644 return delegate_->GetNonClientComponent(point); |
768 } | 645 } |
769 | 646 |
770 bool NativeWidgetAura::ShouldDescendIntoChildForEventHandling( | 647 bool DesktopNativeWidgetAndroid::ShouldDescendIntoChildForEventHandling( |
771 aura::Window* child, | 648 aura::Window* child, |
772 const gfx::Point& location) { | 649 const gfx::Point& location) { |
773 views::WidgetDelegate* widget_delegate = GetWidget()->widget_delegate(); | 650 views::WidgetDelegate* widget_delegate = GetWidget()->widget_delegate(); |
774 if (widget_delegate && | 651 if (widget_delegate && |
775 !widget_delegate->ShouldDescendIntoChildForEventHandling(child, location)) | 652 !widget_delegate->ShouldDescendIntoChildForEventHandling(child, location)) |
776 return false; | 653 return false; |
777 | 654 |
778 // Don't descend into |child| if there is a view with a Layer that contains | 655 // Don't descend into |child| if there is a view with a Layer that contains |
779 // the point and is stacked above |child|s layer. | 656 // the point and is stacked above |child|s layer. |
780 typedef std::vector<ui::Layer*> Layers; | 657 typedef std::vector<ui::Layer*> Layers; |
781 const Layers& root_layers(delegate_->GetRootLayers()); | 658 const Layers& root_layers(delegate_->GetRootLayers()); |
782 if (root_layers.empty()) | 659 if (root_layers.empty()) |
(...skipping 12 matching lines...) Loading... | |
795 Layers::const_iterator root_layer_iter( | 672 Layers::const_iterator root_layer_iter( |
796 std::find(window_->layer()->children().begin(), | 673 std::find(window_->layer()->children().begin(), |
797 window_->layer()->children().end(), layer)); | 674 window_->layer()->children().end(), layer)); |
798 if (root_layer_iter > child_layer_iter) | 675 if (root_layer_iter > child_layer_iter) |
799 return false; | 676 return false; |
800 } | 677 } |
801 } | 678 } |
802 return true; | 679 return true; |
803 } | 680 } |
804 | 681 |
805 bool NativeWidgetAura::CanFocus() { | 682 bool DesktopNativeWidgetAndroid::CanFocus() { |
806 return ShouldActivate(); | 683 return ShouldActivate(); |
807 } | 684 } |
808 | 685 |
809 void NativeWidgetAura::OnCaptureLost() { | 686 void DesktopNativeWidgetAndroid::OnCaptureLost() { |
810 delegate_->OnMouseCaptureLost(); | 687 delegate_->OnMouseCaptureLost(); |
811 } | 688 } |
812 | 689 |
813 void NativeWidgetAura::OnPaint(const ui::PaintContext& context) { | 690 void DesktopNativeWidgetAndroid::OnPaint(const ui::PaintContext& context) { |
814 delegate_->OnNativeWidgetPaint(context); | 691 delegate_->OnNativeWidgetPaint(context); |
815 } | 692 } |
816 | 693 |
817 void NativeWidgetAura::OnDeviceScaleFactorChanged(float device_scale_factor) { | 694 void DesktopNativeWidgetAndroid::OnDeviceScaleFactorChanged( |
695 float device_scale_factor) { | |
818 GetWidget()->DeviceScaleFactorChanged(device_scale_factor); | 696 GetWidget()->DeviceScaleFactorChanged(device_scale_factor); |
819 } | 697 } |
820 | 698 |
821 void NativeWidgetAura::OnWindowDestroying(aura::Window* window) { | 699 void DesktopNativeWidgetAndroid::OnWindowDestroying(aura::Window* window) { |
822 window_->RemoveObserver(this); | |
823 delegate_->OnNativeWidgetDestroying(); | 700 delegate_->OnNativeWidgetDestroying(); |
824 | 701 |
825 // If the aura::Window is destroyed, we can no longer show tooltips. | 702 // If the aura::Window is destroyed, we can no longer show tooltips. |
826 tooltip_manager_.reset(); | 703 tooltip_manager_.reset(); |
827 } | 704 } |
828 | 705 |
829 void NativeWidgetAura::OnWindowDestroyed(aura::Window* window) { | 706 void DesktopNativeWidgetAndroid::OnWindowDestroyed(aura::Window* window) { |
830 window_ = NULL; | 707 window_ = NULL; |
831 delegate_->OnNativeWidgetDestroyed(); | 708 delegate_->OnNativeWidgetDestroyed(); |
832 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) | 709 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) |
833 delete this; | 710 delete this; |
834 } | 711 } |
835 | 712 |
836 void NativeWidgetAura::OnWindowTargetVisibilityChanged(bool visible) { | 713 void DesktopNativeWidgetAndroid::OnWindowTargetVisibilityChanged(bool visible) { |
837 delegate_->OnNativeWidgetVisibilityChanged(visible); | 714 delegate_->OnNativeWidgetVisibilityChanged(visible); |
838 } | 715 } |
839 | 716 |
840 bool NativeWidgetAura::HasHitTestMask() const { | 717 bool DesktopNativeWidgetAndroid::HasHitTestMask() const { |
841 return delegate_->HasHitTestMask(); | 718 return delegate_->HasHitTestMask(); |
842 } | 719 } |
843 | 720 |
844 void NativeWidgetAura::GetHitTestMask(gfx::Path* mask) const { | 721 void DesktopNativeWidgetAndroid::GetHitTestMask(gfx::Path* mask) const { |
845 DCHECK(mask); | 722 DCHECK(mask); |
846 delegate_->GetHitTestMask(mask); | 723 delegate_->GetHitTestMask(mask); |
847 } | 724 } |
848 | 725 |
849 //////////////////////////////////////////////////////////////////////////////// | 726 //////////////////////////////////////////////////////////////////////////////// |
850 // NativeWidgetAura, aura::WindowObserver implementation: | 727 // DesktopNativeWidgetAndroid, ui::EventHandler implementation: |
851 | 728 |
852 void NativeWidgetAura::OnWindowPropertyChanged(aura::Window* window, | 729 void DesktopNativeWidgetAndroid::OnKeyEvent(ui::KeyEvent* event) { |
853 const void* key, | |
854 intptr_t old) { | |
855 if (key == aura::client::kShowStateKey) | |
856 delegate_->OnNativeWidgetWindowShowStateChanged(); | |
857 } | |
858 | |
859 //////////////////////////////////////////////////////////////////////////////// | |
860 // NativeWidgetAura, ui::EventHandler implementation: | |
861 | |
862 void NativeWidgetAura::OnKeyEvent(ui::KeyEvent* event) { | |
863 DCHECK(window_); | 730 DCHECK(window_); |
864 // Renderer may send a key event back to us if the key event wasn't handled, | 731 // Renderer may send a key event back to us if the key event wasn't handled, |
865 // and the window may be invisible by that time. | 732 // and the window may be invisible by that time. |
866 if (!window_->IsVisible()) | 733 if (!window_->IsVisible()) |
867 return; | 734 return; |
868 | 735 |
869 FocusManager* focus_manager = GetWidget()->GetFocusManager(); | 736 FocusManager* focus_manager = GetWidget()->GetFocusManager(); |
870 delegate_->OnKeyEvent(event); | 737 delegate_->OnKeyEvent(event); |
871 if (!event->handled() && focus_manager) | 738 if (!event->handled() && focus_manager) |
872 focus_manager->OnKeyEvent(*event); | 739 focus_manager->OnKeyEvent(*event); |
873 event->SetHandled(); | 740 event->SetHandled(); |
874 } | 741 } |
875 | 742 |
876 void NativeWidgetAura::OnMouseEvent(ui::MouseEvent* event) { | 743 void DesktopNativeWidgetAndroid::OnMouseEvent(ui::MouseEvent* event) { |
877 DCHECK(window_); | 744 DCHECK(window_); |
878 DCHECK(window_->IsVisible()); | 745 DCHECK(window_->IsVisible()); |
879 if (event->type() == ui::ET_MOUSEWHEEL) { | 746 if (event->type() == ui::ET_MOUSEWHEEL) { |
880 delegate_->OnMouseEvent(event); | 747 delegate_->OnMouseEvent(event); |
881 if (event->handled()) | 748 if (event->handled()) |
882 return; | 749 return; |
883 } | 750 } |
884 | 751 |
885 if (tooltip_manager_.get()) | 752 if (tooltip_manager_.get()) |
886 tooltip_manager_->UpdateTooltip(); | 753 tooltip_manager_->UpdateTooltip(); |
887 TooltipManagerAura::UpdateTooltipManagerForCapture(GetWidget()); | 754 TooltipManagerAura::UpdateTooltipManagerForCapture(GetWidget()); |
888 delegate_->OnMouseEvent(event); | 755 delegate_->OnMouseEvent(event); |
889 } | 756 } |
890 | 757 |
891 void NativeWidgetAura::OnScrollEvent(ui::ScrollEvent* event) { | 758 void DesktopNativeWidgetAndroid::OnScrollEvent(ui::ScrollEvent* event) { |
892 delegate_->OnScrollEvent(event); | 759 delegate_->OnScrollEvent(event); |
893 } | 760 } |
894 | 761 |
895 void NativeWidgetAura::OnGestureEvent(ui::GestureEvent* event) { | 762 void DesktopNativeWidgetAndroid::OnGestureEvent(ui::GestureEvent* event) { |
896 DCHECK(window_); | 763 DCHECK(window_); |
897 DCHECK(window_->IsVisible() || event->IsEndingEvent()); | 764 DCHECK(window_->IsVisible() || event->IsEndingEvent()); |
898 delegate_->OnGestureEvent(event); | 765 delegate_->OnGestureEvent(event); |
899 } | 766 } |
900 | 767 |
901 //////////////////////////////////////////////////////////////////////////////// | 768 //////////////////////////////////////////////////////////////////////////////// |
902 // NativeWidgetAura, aura::client::ActivationDelegate implementation: | 769 // DesktopNativeWidgetAndroid, aura::client::ActivationDelegate implementation: |
903 | 770 |
904 bool NativeWidgetAura::ShouldActivate() const { | 771 bool DesktopNativeWidgetAndroid::ShouldActivate() const { |
905 return delegate_->CanActivate(); | 772 return delegate_->CanActivate(); |
906 } | 773 } |
907 | 774 |
908 //////////////////////////////////////////////////////////////////////////////// | 775 //////////////////////////////////////////////////////////////////////////////// |
909 // NativeWidgetAura, aura::client::ActivationChangeObserver implementation: | 776 // DesktopNativeWidgetAndroid, aura::client::ActivationChangeObserver |
777 // implementation: | |
910 | 778 |
911 void NativeWidgetAura::OnWindowActivated( | 779 void DesktopNativeWidgetAndroid::OnWindowActivated( |
912 aura::client::ActivationChangeObserver::ActivationReason, | 780 aura::client::ActivationChangeObserver::ActivationReason, |
913 aura::Window* gained_active, | 781 aura::Window* gained_active, |
914 aura::Window* lost_active) { | 782 aura::Window* lost_active) { |
915 DCHECK(window_ == gained_active || window_ == lost_active); | 783 DCHECK(window_ == gained_active || window_ == lost_active); |
916 if (GetWidget()->GetFocusManager()) { | 784 if (GetWidget()->GetFocusManager()) { |
917 if (window_ == gained_active) | 785 if (window_ == gained_active) |
918 GetWidget()->GetFocusManager()->RestoreFocusedView(); | 786 GetWidget()->GetFocusManager()->RestoreFocusedView(); |
919 else if (window_ == lost_active) | 787 else if (window_ == lost_active) |
920 GetWidget()->GetFocusManager()->StoreFocusedView(true); | 788 GetWidget()->GetFocusManager()->StoreFocusedView(true); |
921 } | 789 } |
922 delegate_->OnNativeWidgetActivationChanged(window_ == gained_active); | 790 delegate_->OnNativeWidgetActivationChanged(window_ == gained_active); |
923 } | 791 } |
924 | 792 |
925 //////////////////////////////////////////////////////////////////////////////// | 793 //////////////////////////////////////////////////////////////////////////////// |
926 // NativeWidgetAura, aura::client::FocusChangeObserver: | 794 // DesktopNativeWidgetAndroid, aura::client::FocusChangeObserver: |
927 | 795 |
928 void NativeWidgetAura::OnWindowFocused(aura::Window* gained_focus, | 796 void DesktopNativeWidgetAndroid::OnWindowFocused(aura::Window* gained_focus, |
929 aura::Window* lost_focus) { | 797 aura::Window* lost_focus) { |
930 if (window_ == gained_focus) | 798 if (window_ == gained_focus) |
931 delegate_->OnNativeFocus(); | 799 delegate_->OnNativeFocus(); |
932 else if (window_ == lost_focus) | 800 else if (window_ == lost_focus) |
933 delegate_->OnNativeBlur(); | 801 delegate_->OnNativeBlur(); |
934 } | 802 } |
935 | 803 |
936 //////////////////////////////////////////////////////////////////////////////// | 804 //////////////////////////////////////////////////////////////////////////////// |
937 // NativeWidgetAura, aura::WindowDragDropDelegate implementation: | 805 // DesktopNativeWidgetAndroid, aura::WindowDragDropDelegate implementation: |
938 | 806 |
939 void NativeWidgetAura::OnDragEntered(const ui::DropTargetEvent& event) { | 807 void DesktopNativeWidgetAndroid::OnDragEntered( |
940 DCHECK(drop_helper_.get() != NULL); | 808 const ui::DropTargetEvent& event) { |
941 last_drop_operation_ = drop_helper_->OnDragOver(event.data(), | 809 // TODO: Implement drag and drop. crbug.com/554029. |
942 event.location(), event.source_operations()); | 810 NOTIMPLEMENTED(); |
943 } | 811 } |
944 | 812 |
945 int NativeWidgetAura::OnDragUpdated(const ui::DropTargetEvent& event) { | 813 int DesktopNativeWidgetAndroid::OnDragUpdated( |
946 DCHECK(drop_helper_.get() != NULL); | 814 const ui::DropTargetEvent& event) { |
947 last_drop_operation_ = drop_helper_->OnDragOver(event.data(), | 815 // TODO: Implement drag and drop. crbug.com/554029. |
948 event.location(), event.source_operations()); | 816 NOTIMPLEMENTED(); |
949 return last_drop_operation_; | 817 return 0; |
950 } | 818 } |
951 | 819 |
952 void NativeWidgetAura::OnDragExited() { | 820 void DesktopNativeWidgetAndroid::OnDragExited() { |
953 DCHECK(drop_helper_.get() != NULL); | 821 // TODO: Implement drag and drop. crbug.com/554029. |
954 drop_helper_->OnDragExit(); | 822 NOTIMPLEMENTED(); |
955 } | 823 } |
956 | 824 |
957 int NativeWidgetAura::OnPerformDrop(const ui::DropTargetEvent& event) { | 825 int DesktopNativeWidgetAndroid::OnPerformDrop( |
958 DCHECK(drop_helper_.get() != NULL); | 826 const ui::DropTargetEvent& event) { |
959 return drop_helper_->OnDrop(event.data(), event.location(), | 827 // TODO: Implement drag and drop. crbug.com/554029. |
960 last_drop_operation_); | 828 NOTIMPLEMENTED(); |
829 return 0; | |
961 } | 830 } |
962 | 831 |
963 //////////////////////////////////////////////////////////////////////////////// | 832 //////////////////////////////////////////////////////////////////////////////// |
964 // NativeWidgetAura, protected: | 833 // DesktopNativeWidgetAndroid, aura::WindowTreeHostObserver implementation: |
965 | 834 |
966 NativeWidgetAura::~NativeWidgetAura() { | 835 void DesktopNativeWidgetAndroid::OnHostCloseRequested( |
836 const aura::WindowTreeHost* host) { | |
837 GetWidget()->Close(); | |
838 } | |
839 | |
840 void DesktopNativeWidgetAndroid::OnHostResized( | |
841 const aura::WindowTreeHost* host) { | |
842 gfx::Rect new_bounds = gfx::Rect(host_->window()->bounds().size()); | |
843 GetNativeWindow()->SetBounds(new_bounds); | |
844 delegate_->OnNativeWidgetSizeChanged(new_bounds.size()); | |
845 } | |
846 | |
847 void DesktopNativeWidgetAndroid::OnHostMoved(const aura::WindowTreeHost* host, | |
848 const gfx::Point& new_origin) { | |
849 TRACE_EVENT1("views", "DesktopNativeWidgetAndroid::OnHostMoved", "new_origin", | |
850 new_origin.ToString()); | |
851 | |
852 delegate_->OnNativeWidgetMove(); | |
853 } | |
854 | |
855 //////////////////////////////////////////////////////////////////////////////// | |
856 // DesktopNativeWidgetAndroid, protected: | |
857 | |
858 DesktopNativeWidgetAndroid::~DesktopNativeWidgetAndroid() { | |
967 destroying_ = true; | 859 destroying_ = true; |
968 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) | 860 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) |
969 delete delegate_; | 861 delete delegate_; |
970 else | 862 else |
971 CloseNow(); | 863 CloseNow(); |
972 } | 864 } |
973 | 865 |
974 //////////////////////////////////////////////////////////////////////////////// | 866 //////////////////////////////////////////////////////////////////////////////// |
975 // NativeWidgetAura, private: | 867 // DesktopNativeWidgetAndroid, private: |
976 | 868 |
977 bool NativeWidgetAura::IsDocked() const { | 869 bool DesktopNativeWidgetAndroid::IsDocked() const { |
978 return window_ && | 870 NOTIMPLEMENTED(); |
979 window_->GetProperty(aura::client::kShowStateKey) == | 871 return false; |
980 ui::SHOW_STATE_DOCKED; | |
981 } | 872 } |
982 | 873 |
983 void NativeWidgetAura::SetInitialFocus(ui::WindowShowState show_state) { | 874 void DesktopNativeWidgetAndroid::SetInitialFocus( |
875 ui::WindowShowState show_state) { | |
984 // The window does not get keyboard messages unless we focus it. | 876 // The window does not get keyboard messages unless we focus it. |
985 if (!GetWidget()->SetInitialFocus(show_state)) | 877 if (!GetWidget()->SetInitialFocus(show_state)) |
986 window_->Focus(); | 878 window_->Focus(); |
987 } | 879 } |
988 | 880 |
989 //////////////////////////////////////////////////////////////////////////////// | |
990 // Widget, public: | |
991 | |
992 namespace { | |
993 #if defined(OS_WIN) || (defined(USE_X11) && !defined(OS_CHROMEOS)) | |
994 void CloseWindow(aura::Window* window) { | |
995 if (window) { | |
996 Widget* widget = Widget::GetWidgetForNativeView(window); | |
997 if (widget && widget->is_secondary_widget()) | |
998 // To avoid the delay in shutdown caused by using Close which may wait | |
999 // for animations, use CloseNow. Because this is only used on secondary | |
1000 // widgets it seems relatively safe to skip the extra processing of | |
1001 // Close. | |
1002 widget->CloseNow(); | |
1003 } | |
1004 } | |
1005 #endif | |
1006 | |
1007 #if defined(OS_WIN) | |
1008 BOOL CALLBACK WindowCallbackProc(HWND hwnd, LPARAM lParam) { | |
1009 aura::Window* root_window = | |
1010 DesktopWindowTreeHostWin::GetContentWindowForHWND(hwnd); | |
1011 CloseWindow(root_window); | |
1012 return TRUE; | |
1013 } | |
1014 #endif | |
1015 } // namespace | |
1016 | |
1017 // static | |
1018 void Widget::CloseAllSecondaryWidgets() { | |
1019 #if defined(OS_WIN) | |
1020 EnumThreadWindows(GetCurrentThreadId(), WindowCallbackProc, 0); | |
1021 #endif | |
1022 | |
1023 #if defined(USE_X11) && !defined(OS_CHROMEOS) | |
1024 DesktopWindowTreeHostX11::CleanUpWindowList(CloseWindow); | |
1025 #endif | |
1026 } | |
1027 | |
1028 bool Widget::ConvertRect(const Widget* source, | |
1029 const Widget* target, | |
1030 gfx::Rect* rect) { | |
1031 return false; | |
1032 } | |
1033 | |
1034 namespace internal { | |
1035 | |
1036 //////////////////////////////////////////////////////////////////////////////// | |
1037 // internal::NativeWidgetPrivate, public: | |
1038 | |
1039 // static | |
1040 NativeWidgetPrivate* NativeWidgetPrivate::CreateNativeWidget( | |
1041 internal::NativeWidgetDelegate* delegate) { | |
1042 return new NativeWidgetAura(delegate); | |
1043 } | |
1044 | |
1045 // static | |
1046 NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeView( | |
1047 gfx::NativeView native_view) { | |
1048 // Cast must match type supplied to RegisterNativeWidgetForWindow(). | |
1049 return reinterpret_cast<NativeWidgetPrivate*>(native_view->user_data()); | |
1050 } | |
1051 | |
1052 // static | |
1053 NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeWindow( | |
1054 gfx::NativeWindow native_window) { | |
1055 // Cast must match type supplied to RegisterNativeWidgetForWindow(). | |
1056 return reinterpret_cast<NativeWidgetPrivate*>(native_window->user_data()); | |
1057 } | |
1058 | |
1059 // static | |
1060 NativeWidgetPrivate* NativeWidgetPrivate::GetTopLevelNativeWidget( | |
1061 gfx::NativeView native_view) { | |
1062 aura::Window* window = native_view; | |
1063 NativeWidgetPrivate* top_level_native_widget = NULL; | |
1064 while (window) { | |
1065 NativeWidgetPrivate* native_widget = GetNativeWidgetForNativeView(window); | |
1066 if (native_widget) | |
1067 top_level_native_widget = native_widget; | |
1068 window = window->parent(); | |
1069 } | |
1070 return top_level_native_widget; | |
1071 } | |
1072 | |
1073 // static | |
1074 void NativeWidgetPrivate::GetAllChildWidgets(gfx::NativeView native_view, | |
1075 Widget::Widgets* children) { | |
1076 { | |
1077 // Code expects widget for |native_view| to be added to |children|. | |
1078 NativeWidgetPrivate* native_widget = static_cast<NativeWidgetPrivate*>( | |
1079 GetNativeWidgetForNativeView(native_view)); | |
1080 if (native_widget && native_widget->GetWidget()) | |
1081 children->insert(native_widget->GetWidget()); | |
1082 } | |
1083 | |
1084 const aura::Window::Windows& child_windows = native_view->children(); | |
1085 for (aura::Window::Windows::const_iterator i = child_windows.begin(); | |
1086 i != child_windows.end(); ++i) { | |
1087 GetAllChildWidgets((*i), children); | |
1088 } | |
1089 } | |
1090 | |
1091 // static | |
1092 void NativeWidgetPrivate::GetAllOwnedWidgets(gfx::NativeView native_view, | |
1093 Widget::Widgets* owned) { | |
1094 // Add all owned widgets. | |
1095 for (aura::Window* transient_child : wm::GetTransientChildren(native_view)) { | |
1096 NativeWidgetPrivate* native_widget = static_cast<NativeWidgetPrivate*>( | |
1097 GetNativeWidgetForNativeView(transient_child)); | |
1098 if (native_widget && native_widget->GetWidget()) | |
1099 owned->insert(native_widget->GetWidget()); | |
1100 GetAllOwnedWidgets(transient_child, owned); | |
1101 } | |
1102 | |
1103 // Add all child windows. | |
1104 for (aura::Window* child : native_view->children()) | |
1105 GetAllChildWidgets(child, owned); | |
1106 } | |
1107 | |
1108 // static | |
1109 void NativeWidgetPrivate::ReparentNativeView(gfx::NativeView native_view, | |
1110 gfx::NativeView new_parent) { | |
1111 DCHECK(native_view != new_parent); | |
1112 | |
1113 gfx::NativeView previous_parent = native_view->parent(); | |
1114 if (previous_parent == new_parent) | |
1115 return; | |
1116 | |
1117 Widget::Widgets widgets; | |
1118 GetAllChildWidgets(native_view, &widgets); | |
1119 | |
1120 // First notify all the widgets that they are being disassociated | |
1121 // from their previous parent. | |
1122 for (Widget::Widgets::iterator it = widgets.begin(); | |
1123 it != widgets.end(); ++it) { | |
1124 (*it)->NotifyNativeViewHierarchyWillChange(); | |
1125 } | |
1126 | |
1127 if (new_parent) { | |
1128 new_parent->AddChild(native_view); | |
1129 } else { | |
1130 // The following looks weird, but it's the equivalent of what aura has | |
1131 // always done. (The previous behaviour of aura::Window::SetParent() used | |
1132 // NULL as a special value that meant ask the WindowTreeClient where things | |
1133 // should go.) | |
1134 // | |
1135 // This probably isn't strictly correct, but its an invariant that a Window | |
1136 // in use will be attached to a RootWindow, so we can't just call | |
1137 // RemoveChild here. The only possible thing that could assign a RootWindow | |
1138 // in this case is the stacking client of the current RootWindow. This | |
1139 // matches our previous behaviour; the global stacking client would almost | |
1140 // always reattach the window to the same RootWindow. | |
1141 aura::Window* root_window = native_view->GetRootWindow(); | |
1142 aura::client::ParentWindowWithContext( | |
1143 native_view, root_window, root_window->GetBoundsInScreen()); | |
1144 } | |
1145 | |
1146 // And now, notify them that they have a brand new parent. | |
1147 for (Widget::Widgets::iterator it = widgets.begin(); | |
1148 it != widgets.end(); ++it) { | |
1149 (*it)->NotifyNativeViewHierarchyChanged(); | |
1150 } | |
1151 } | |
1152 | |
1153 // static | |
1154 bool NativeWidgetPrivate::IsMouseButtonDown() { | |
1155 return aura::Env::GetInstance()->IsMouseButtonDown(); | |
1156 } | |
1157 | |
1158 // static | |
1159 gfx::FontList NativeWidgetPrivate::GetWindowTitleFontList() { | |
1160 #if defined(OS_WIN) | |
1161 NONCLIENTMETRICS_XP ncm; | |
1162 base::win::GetNonClientMetrics(&ncm); | |
1163 l10n_util::AdjustUIFont(&(ncm.lfCaptionFont)); | |
1164 base::win::ScopedHFONT caption_font(CreateFontIndirect(&(ncm.lfCaptionFont))); | |
1165 return gfx::FontList(gfx::Font(caption_font)); | |
1166 #else | |
1167 return gfx::FontList(); | |
1168 #endif | |
1169 } | |
1170 | |
1171 } // namespace internal | |
1172 } // namespace views | 881 } // namespace views |
OLD | NEW |