OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/native_widget_aura.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "third_party/skia/include/core/SkRegion.h" | 9 #include "third_party/skia/include/core/SkRegion.h" |
10 #include "ui/aura/client/activation_client.h" | 10 #include "ui/aura/client/activation_client.h" |
11 #include "ui/aura/client/aura_constants.h" | 11 #include "ui/aura/client/aura_constants.h" |
12 #include "ui/aura/client/dispatcher_client.h" | |
13 #include "ui/aura/client/drag_drop_client.h" | 12 #include "ui/aura/client/drag_drop_client.h" |
14 #include "ui/aura/client/window_move_client.h" | 13 #include "ui/aura/client/window_move_client.h" |
15 #include "ui/aura/client/window_types.h" | 14 #include "ui/aura/client/window_types.h" |
16 #include "ui/aura/desktop/desktop_activation_client.h" | |
17 #include "ui/aura/desktop/desktop_dispatcher_client.h" | |
18 #include "ui/aura/desktop/desktop_root_window_event_filter.h" | |
19 #include "ui/aura/env.h" | 15 #include "ui/aura/env.h" |
20 #include "ui/aura/event.h" | 16 #include "ui/aura/event.h" |
21 #include "ui/aura/root_window.h" | 17 #include "ui/aura/root_window.h" |
22 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
23 #include "ui/aura/window_observer.h" | 19 #include "ui/aura/window_observer.h" |
24 #include "ui/base/dragdrop/os_exchange_data.h" | 20 #include "ui/base/dragdrop/os_exchange_data.h" |
25 #include "ui/base/ui_base_types.h" | 21 #include "ui/base/ui_base_types.h" |
26 #include "ui/gfx/canvas.h" | 22 #include "ui/gfx/canvas.h" |
27 #include "ui/gfx/compositor/layer.h" | 23 #include "ui/gfx/compositor/layer.h" |
28 #include "ui/gfx/font.h" | 24 #include "ui/gfx/font.h" |
29 #include "ui/gfx/screen.h" | 25 #include "ui/gfx/screen.h" |
30 #include "ui/views/drag_utils.h" | 26 #include "ui/views/drag_utils.h" |
31 #include "ui/views/ime/input_method_bridge.h" | 27 #include "ui/views/ime/input_method_bridge.h" |
32 #include "ui/views/widget/drop_helper.h" | 28 #include "ui/views/widget/drop_helper.h" |
33 #include "ui/views/widget/native_widget_delegate.h" | 29 #include "ui/views/widget/native_widget_delegate.h" |
30 #include "ui/views/widget/desktop_native_widget_helper_aura.h" | |
34 #include "ui/views/widget/root_view.h" | 31 #include "ui/views/widget/root_view.h" |
35 #include "ui/views/widget/tooltip_manager_aura.h" | 32 #include "ui/views/widget/tooltip_manager_aura.h" |
36 #include "ui/views/widget/widget_delegate.h" | 33 #include "ui/views/widget/widget_delegate.h" |
37 | 34 |
38 #if defined(OS_WIN) | 35 #if defined(OS_WIN) |
39 #include "base/win/scoped_gdi_object.h" | 36 #include "base/win/scoped_gdi_object.h" |
40 #include "base/win/win_util.h" | 37 #include "base/win/win_util.h" |
41 #include "ui/base/l10n/l10n_util_win.h" | 38 #include "ui/base/l10n/l10n_util_win.h" |
42 #endif | 39 #endif |
43 | 40 |
44 #if defined(ENABLE_DIP) | 41 #if defined(ENABLE_DIP) |
45 #include "ui/aura/monitor.h" | 42 #include "ui/aura/monitor.h" |
46 #include "ui/aura/monitor_manager.h" | 43 #include "ui/aura/monitor_manager.h" |
47 #endif | 44 #endif |
48 | 45 |
49 namespace views { | 46 namespace views { |
50 | 47 |
51 bool NativeWidgetAura::g_aura_desktop_hax = false; | |
52 | |
53 namespace { | 48 namespace { |
54 | 49 |
55 aura::client::WindowType GetAuraWindowTypeForWidgetType( | 50 aura::client::WindowType GetAuraWindowTypeForWidgetType( |
56 Widget::InitParams::Type type) { | 51 Widget::InitParams::Type type) { |
57 switch (type) { | 52 switch (type) { |
58 case Widget::InitParams::TYPE_WINDOW: | 53 case Widget::InitParams::TYPE_WINDOW: |
59 return aura::client::WINDOW_TYPE_NORMAL; | 54 return aura::client::WINDOW_TYPE_NORMAL; |
60 case Widget::InitParams::TYPE_PANEL: | 55 case Widget::InitParams::TYPE_PANEL: |
61 return aura::client::WINDOW_TYPE_PANEL; | 56 return aura::client::WINDOW_TYPE_PANEL; |
62 case Widget::InitParams::TYPE_CONTROL: | 57 case Widget::InitParams::TYPE_CONTROL: |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 NativeWidgetAura* host_; | 127 NativeWidgetAura* host_; |
133 | 128 |
134 DISALLOW_COPY_AND_ASSIGN(ActiveWindowObserver); | 129 DISALLOW_COPY_AND_ASSIGN(ActiveWindowObserver); |
135 }; | 130 }; |
136 | 131 |
137 //////////////////////////////////////////////////////////////////////////////// | 132 //////////////////////////////////////////////////////////////////////////////// |
138 // NativeWidgetAura, public: | 133 // NativeWidgetAura, public: |
139 | 134 |
140 NativeWidgetAura::NativeWidgetAura(internal::NativeWidgetDelegate* delegate) | 135 NativeWidgetAura::NativeWidgetAura(internal::NativeWidgetDelegate* delegate) |
141 : delegate_(delegate), | 136 : delegate_(delegate), |
142 root_window_(NULL), | 137 #if defined(USE_ASH) |
Ben Goodger (Google)
2012/04/17 15:42:55
views is not allowed to know about ash.
instead, t
| |
138 desktop_helper_(NULL), | |
139 #else | |
140 ALLOW_THIS_IN_INITIALIZER_LIST(desktop_helper_( | |
141 new views::DesktopNatitveWidgetHelperAura(this))), | |
142 #endif | |
143 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))), | 143 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))), |
144 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), | 144 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), |
145 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), | 145 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), |
146 can_activate_(true), | 146 can_activate_(true), |
147 cursor_(gfx::kNullCursor), | 147 cursor_(gfx::kNullCursor), |
148 saved_window_state_(ui::SHOW_STATE_DEFAULT) { | 148 saved_window_state_(ui::SHOW_STATE_DEFAULT) { |
149 } | 149 } |
150 | 150 |
151 NativeWidgetAura::~NativeWidgetAura() { | 151 NativeWidgetAura::~NativeWidgetAura() { |
152 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) | 152 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) |
(...skipping 13 matching lines...) Expand all Loading... | |
166 #else | 166 #else |
167 return gfx::Font(); | 167 return gfx::Font(); |
168 #endif | 168 #endif |
169 } | 169 } |
170 | 170 |
171 //////////////////////////////////////////////////////////////////////////////// | 171 //////////////////////////////////////////////////////////////////////////////// |
172 // NativeWidgetAura, internal::NativeWidgetPrivate implementation: | 172 // NativeWidgetAura, internal::NativeWidgetPrivate implementation: |
173 | 173 |
174 void NativeWidgetAura::InitNativeWidget(const Widget::InitParams& params) { | 174 void NativeWidgetAura::InitNativeWidget(const Widget::InitParams& params) { |
175 ownership_ = params.ownership; | 175 ownership_ = params.ownership; |
176 // TODO(erg): What kind of windows do we want to have their own root windows? | |
177 if (g_aura_desktop_hax) { | |
178 gfx::Rect bounds = params.bounds; | |
179 if (bounds.IsEmpty()) { | |
180 // We must pass some non-zero value when we initialize a RootWindow. This | |
181 // will probably be SetBounds()ed soon. | |
182 bounds.set_size(gfx::Size(100, 100)); | |
183 } | |
184 root_window_.reset(new aura::RootWindow(bounds)); | |
185 root_window_->SetEventFilter( | |
186 new aura::DesktopRootWindowEventFilter(root_window_.get())); | |
187 root_window_->AddRootWindowObserver(this); | |
188 | 176 |
189 aura::client::SetActivationClient( | 177 if (desktop_helper_.get()) |
190 root_window_.get(), | 178 desktop_helper_->PreInitialize(params); |
191 new aura::DesktopActivationClient(root_window_.get())); | |
192 aura::client::SetDispatcherClient(root_window_.get(), | |
193 new aura::DesktopDispatcherClient); | |
194 } | |
195 | 179 |
196 window_->set_user_data(this); | 180 window_->set_user_data(this); |
197 window_->SetType(GetAuraWindowTypeForWidgetType(params.type)); | 181 window_->SetType(GetAuraWindowTypeForWidgetType(params.type)); |
198 window_->SetProperty(aura::client::kShowStateKey, params.show_state); | 182 window_->SetProperty(aura::client::kShowStateKey, params.show_state); |
199 if (params.type == Widget::InitParams::TYPE_BUBBLE) | 183 if (params.type == Widget::InitParams::TYPE_BUBBLE) |
200 aura::client::SetHideOnDeactivate(window_, true); | 184 aura::client::SetHideOnDeactivate(window_, true); |
201 window_->SetTransparent(params.transparent); | 185 window_->SetTransparent(params.transparent); |
202 window_->Init(params.layer_type); | 186 window_->Init(params.layer_type); |
203 if (params.type == Widget::InitParams::TYPE_CONTROL) | 187 if (params.type == Widget::InitParams::TYPE_CONTROL) |
204 window_->Show(); | 188 window_->Show(); |
205 | 189 |
206 delegate_->OnNativeWidgetCreated(); | 190 delegate_->OnNativeWidgetCreated(); |
207 if (root_window_.get()) { | 191 if (desktop_helper_.get() && desktop_helper_->root_window()) { |
208 window_->SetParent(root_window_.get()); | 192 window_->SetParent(desktop_helper_->root_window()); |
209 } else if (params.child) { | 193 } else if (params.child) { |
210 window_->SetParent(params.GetParent()); | 194 window_->SetParent(params.GetParent()); |
211 } else { | 195 } else { |
212 // Set up the transient child before the window is added. This way the | 196 // Set up the transient child before the window is added. This way the |
213 // LayoutManager knows the window has a transient parent. | 197 // LayoutManager knows the window has a transient parent. |
214 gfx::NativeView parent = params.GetParent(); | 198 gfx::NativeView parent = params.GetParent(); |
215 if (parent && parent->type() != aura::client::WINDOW_TYPE_UNKNOWN) { | 199 if (parent && parent->type() != aura::client::WINDOW_TYPE_UNKNOWN) { |
216 parent->AddTransientChild(window_); | 200 parent->AddTransientChild(window_); |
217 | 201 |
218 // TODO(erg): The StackingClient interface implies that there is only a | 202 // TODO(erg): The StackingClient interface implies that there is only a |
219 // single root window. Solving this would require setting a stacking | 203 // single root window. Solving this would require setting a stacking |
220 // client per root window instead. For now, we hax our way around this by | 204 // client per root window instead. For now, we hax our way around this by |
221 // forcing the parent to be the root window instead of passing NULL as | 205 // forcing the parent to be the root window instead of passing NULL as |
222 // the parent which will dispatch to the stacking client. | 206 // the parent which will dispatch to the stacking client. |
223 if (g_aura_desktop_hax) | 207 if (desktop_helper_.get()) |
224 parent = parent->GetRootWindow(); | 208 parent = parent->GetRootWindow(); |
225 else | 209 else |
226 parent = NULL; | 210 parent = NULL; |
227 } | 211 } |
228 // SetAlwaysOnTop before SetParent so that always-on-top container is used. | 212 // SetAlwaysOnTop before SetParent so that always-on-top container is used. |
229 SetAlwaysOnTop(params.keep_on_top); | 213 SetAlwaysOnTop(params.keep_on_top); |
230 window_->SetParent(parent); | 214 window_->SetParent(parent); |
231 } | 215 } |
232 | 216 |
233 // Wait to set the bounds until we have a parent. That way we can know our | 217 // Wait to set the bounds until we have a parent. That way we can know our |
(...skipping 12 matching lines...) Expand all Loading... | |
246 #endif // !defined(OS_MACOSX) | 230 #endif // !defined(OS_MACOSX) |
247 | 231 |
248 drop_helper_.reset(new DropHelper(GetWidget()->GetRootView())); | 232 drop_helper_.reset(new DropHelper(GetWidget()->GetRootView())); |
249 if (params.type != Widget::InitParams::TYPE_TOOLTIP && | 233 if (params.type != Widget::InitParams::TYPE_TOOLTIP && |
250 params.type != Widget::InitParams::TYPE_POPUP) { | 234 params.type != Widget::InitParams::TYPE_POPUP) { |
251 aura::client::SetDragDropDelegate(window_, this); | 235 aura::client::SetDragDropDelegate(window_, this); |
252 } | 236 } |
253 | 237 |
254 aura::client::SetActivationDelegate(window_, this); | 238 aura::client::SetActivationDelegate(window_, this); |
255 | 239 |
256 if (root_window_.get()) | 240 // TODO(erg): Move this somewhere else? |
257 root_window_->ShowRootWindow(); | 241 if (desktop_helper_.get()) |
242 desktop_helper_->ShowRootWindow(); | |
258 } | 243 } |
259 | 244 |
260 NonClientFrameView* NativeWidgetAura::CreateNonClientFrameView() { | 245 NonClientFrameView* NativeWidgetAura::CreateNonClientFrameView() { |
261 return NULL; | 246 return NULL; |
262 } | 247 } |
263 | 248 |
264 void NativeWidgetAura::UpdateFrameAfterFrameChange() { | 249 void NativeWidgetAura::UpdateFrameAfterFrameChange() { |
265 } | 250 } |
266 | 251 |
267 bool NativeWidgetAura::ShouldUseNativeFrame() const { | 252 bool NativeWidgetAura::ShouldUseNativeFrame() const { |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
464 return ConvertRectFromMonitor( | 449 return ConvertRectFromMonitor( |
465 restore_bounds ? *restore_bounds : window_->bounds()); | 450 restore_bounds ? *restore_bounds : window_->bounds()); |
466 #else | 451 #else |
467 return restore_bounds ? *restore_bounds : window_->bounds(); | 452 return restore_bounds ? *restore_bounds : window_->bounds(); |
468 #endif | 453 #endif |
469 } | 454 } |
470 | 455 |
471 void NativeWidgetAura::SetBounds(const gfx::Rect& in_bounds) { | 456 void NativeWidgetAura::SetBounds(const gfx::Rect& in_bounds) { |
472 gfx::Rect bounds = in_bounds; | 457 gfx::Rect bounds = in_bounds; |
473 | 458 |
474 if (root_window_.get() && !bounds.IsEmpty()) { | 459 if (desktop_helper_.get()) |
475 root_window_->SetHostBounds(bounds); | 460 bounds = desktop_helper_->ModifyAndSetBounds(bounds); |
476 bounds.set_x(0); | |
477 bounds.set_y(0); | |
478 } | |
479 #if defined(ENABLE_DIP) | 461 #if defined(ENABLE_DIP) |
480 bounds = ConvertRectToMonitor(bounds); | 462 bounds = ConvertRectToMonitor(bounds); |
481 #endif | 463 #endif |
482 window_->SetBounds(bounds); | 464 window_->SetBounds(bounds); |
483 } | 465 } |
484 | 466 |
485 void NativeWidgetAura::SetSize(const gfx::Size& size) { | 467 void NativeWidgetAura::SetSize(const gfx::Size& size) { |
486 #if defined(ENABLE_DIP) | 468 #if defined(ENABLE_DIP) |
487 gfx::Size monitor_size = ConvertSizeToMonitor(size); | 469 gfx::Size monitor_size = ConvertSizeToMonitor(size); |
488 window_->SetBounds(gfx::Rect(window_->bounds().origin(), monitor_size)); | 470 window_->SetBounds(gfx::Rect(window_->bounds().origin(), monitor_size)); |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
866 delegate_->OnNativeWidgetDestroyed(); | 848 delegate_->OnNativeWidgetDestroyed(); |
867 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) | 849 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) |
868 delete this; | 850 delete this; |
869 } | 851 } |
870 | 852 |
871 void NativeWidgetAura::OnWindowVisibilityChanged(bool visible) { | 853 void NativeWidgetAura::OnWindowVisibilityChanged(bool visible) { |
872 delegate_->OnNativeWidgetVisibilityChanged(visible); | 854 delegate_->OnNativeWidgetVisibilityChanged(visible); |
873 } | 855 } |
874 | 856 |
875 //////////////////////////////////////////////////////////////////////////////// | 857 //////////////////////////////////////////////////////////////////////////////// |
876 // NativeWidgetAura, aura::RootWindowObserver implementation: | |
877 | |
878 void NativeWidgetAura::OnRootWindowResized(const aura::RootWindow* root, | |
879 const gfx::Size& old_size) { | |
880 // This case can only happen if we have our own aura::RootWindow*. When that | |
881 // happens, our main window should be at the origin and sized to the | |
882 // RootWindow. | |
883 DCHECK_EQ(root, root_window_.get()); | |
884 SetBounds(gfx::Rect(root->GetHostSize())); | |
885 } | |
886 | |
887 void NativeWidgetAura::OnRootWindowHostClosed(const aura::RootWindow* root) { | |
888 DCHECK_EQ(root, root_window_.get()); | |
889 GetWidget()->Close(); | |
890 } | |
891 | |
892 //////////////////////////////////////////////////////////////////////////////// | |
893 // NativeWidgetAura, aura::ActivationDelegate implementation: | 858 // NativeWidgetAura, aura::ActivationDelegate implementation: |
894 | 859 |
895 bool NativeWidgetAura::ShouldActivate(const aura::Event* event) { | 860 bool NativeWidgetAura::ShouldActivate(const aura::Event* event) { |
896 return can_activate_ && delegate_->CanActivate(); | 861 return can_activate_ && delegate_->CanActivate(); |
897 } | 862 } |
898 | 863 |
899 void NativeWidgetAura::OnActivated() { | 864 void NativeWidgetAura::OnActivated() { |
900 if (GetWidget()->HasFocusManager()) | 865 if (GetWidget()->HasFocusManager()) |
901 GetWidget()->GetFocusManager()->RestoreFocusedView(); | 866 GetWidget()->GetFocusManager()->RestoreFocusedView(); |
902 delegate_->OnNativeWidgetActivationChanged(true); | 867 delegate_->OnNativeWidgetActivationChanged(true); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1085 } | 1050 } |
1086 } | 1051 } |
1087 | 1052 |
1088 // static | 1053 // static |
1089 bool NativeWidgetPrivate::IsMouseButtonDown() { | 1054 bool NativeWidgetPrivate::IsMouseButtonDown() { |
1090 return aura::Env::GetInstance()->is_mouse_button_down(); | 1055 return aura::Env::GetInstance()->is_mouse_button_down(); |
1091 } | 1056 } |
1092 | 1057 |
1093 } // namespace internal | 1058 } // namespace internal |
1094 } // namespace views | 1059 } // namespace views |
OLD | NEW |