| 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/desktop_native_widget_helper_aura.h" | 5 #include "ui/views/widget/desktop_native_widget_helper_aura.h" |
| 6 | 6 |
| 7 #include "ui/aura/client/dispatcher_client.h" | 7 #include "ui/aura/client/dispatcher_client.h" |
| 8 #include "ui/aura/client/screen_position_client.h" | 8 #include "ui/aura/client/screen_position_client.h" |
| 9 #include "ui/aura/desktop/desktop_activation_client.h" | 9 #include "ui/aura/desktop/desktop_activation_client.h" |
| 10 #include "ui/aura/desktop/desktop_cursor_client.h" | 10 #include "ui/aura/desktop/desktop_cursor_client.h" |
| 11 #include "ui/aura/desktop/desktop_dispatcher_client.h" | 11 #include "ui/aura/desktop/desktop_dispatcher_client.h" |
| 12 #include "ui/aura/focus_manager.h" | 12 #include "ui/aura/focus_manager.h" |
| 13 #include "ui/aura/root_window.h" | 13 #include "ui/aura/root_window.h" |
| 14 #include "ui/aura/shared/compound_event_filter.h" | 14 #include "ui/aura/shared/compound_event_filter.h" |
| 15 #include "ui/aura/shared/input_method_event_filter.h" | 15 #include "ui/aura/shared/input_method_event_filter.h" |
| 16 #include "ui/aura/shared/root_window_capture_client.h" | 16 #include "ui/aura/shared/root_window_capture_client.h" |
| 17 #include "ui/aura/window_property.h" | 17 #include "ui/aura/window_property.h" |
| 18 #include "ui/views/widget/native_widget_aura.h" | 18 #include "ui/views/widget/native_widget_aura.h" |
| 19 | 19 |
| 20 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
| 21 #include "ui/base/win/hwnd_subclass.h" | 21 #include "ui/base/win/hwnd_subclass.h" |
| 22 #include "ui/views/widget/widget_message_filter.h" | 22 #include "ui/views/widget/widget_message_filter.h" |
| 23 #elif defined(USE_X11) | 23 #elif defined(USE_X11) |
| 24 #include "ui/views/widget/x11_desktop_handler.h" | 24 #include "ui/views/widget/x11_desktop_handler.h" |
| 25 #include "ui/views/widget/x11_desktop_window_move_client.h" |
| 25 #include "ui/views/widget/x11_window_event_filter.h" | 26 #include "ui/views/widget/x11_window_event_filter.h" |
| 26 #endif | 27 #endif |
| 27 | 28 |
| 28 DECLARE_WINDOW_PROPERTY_TYPE(aura::Window*); | 29 DECLARE_WINDOW_PROPERTY_TYPE(aura::Window*); |
| 29 | 30 |
| 30 namespace views { | 31 namespace views { |
| 31 | 32 |
| 32 DEFINE_WINDOW_PROPERTY_KEY( | 33 DEFINE_WINDOW_PROPERTY_KEY( |
| 33 aura::Window*, kViewsWindowForRootWindow, NULL); | 34 aura::Window*, kViewsWindowForRootWindow, NULL); |
| 34 | 35 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 root->SetHostBounds(bounds); | 85 root->SetHostBounds(bounds); |
| 85 window->SetBounds(gfx::Rect(bounds.size())); | 86 window->SetBounds(gfx::Rect(bounds.size())); |
| 86 } | 87 } |
| 87 }; | 88 }; |
| 88 | 89 |
| 89 } // namespace | 90 } // namespace |
| 90 | 91 |
| 91 DesktopNativeWidgetHelperAura::DesktopNativeWidgetHelperAura( | 92 DesktopNativeWidgetHelperAura::DesktopNativeWidgetHelperAura( |
| 92 NativeWidgetAura* widget) | 93 NativeWidgetAura* widget) |
| 93 : widget_(widget), | 94 : widget_(widget), |
| 95 window_(NULL), |
| 94 root_window_event_filter_(NULL), | 96 root_window_event_filter_(NULL), |
| 95 is_embedded_window_(false) { | 97 is_embedded_window_(false) { |
| 96 } | 98 } |
| 97 | 99 |
| 98 DesktopNativeWidgetHelperAura::~DesktopNativeWidgetHelperAura() { | 100 DesktopNativeWidgetHelperAura::~DesktopNativeWidgetHelperAura() { |
| 101 if (window_) |
| 102 window_->RemoveObserver(this); |
| 103 |
| 99 if (root_window_event_filter_) { | 104 if (root_window_event_filter_) { |
| 100 #if defined(USE_X11) | 105 #if defined(USE_X11) |
| 106 root_window_event_filter_->RemoveFilter(x11_window_move_client_.get()); |
| 101 root_window_event_filter_->RemoveFilter(x11_window_event_filter_.get()); | 107 root_window_event_filter_->RemoveFilter(x11_window_event_filter_.get()); |
| 102 #endif | 108 #endif |
| 103 | 109 |
| 104 root_window_event_filter_->RemoveFilter(input_method_filter_.get()); | 110 root_window_event_filter_->RemoveFilter(input_method_filter_.get()); |
| 105 } | 111 } |
| 106 } | 112 } |
| 107 | 113 |
| 108 // static | 114 // static |
| 109 aura::Window* DesktopNativeWidgetHelperAura::GetViewsWindowForRootWindow( | 115 aura::Window* DesktopNativeWidgetHelperAura::GetViewsWindowForRootWindow( |
| 110 aura::RootWindow* root) { | 116 aura::RootWindow* root) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 | 177 |
| 172 #if defined(USE_X11) | 178 #if defined(USE_X11) |
| 173 x11_window_event_filter_.reset( | 179 x11_window_event_filter_.reset( |
| 174 new X11WindowEventFilter(root_window_.get(), activation_client, widget_)); | 180 new X11WindowEventFilter(root_window_.get(), activation_client, widget_)); |
| 175 x11_window_event_filter_->SetUseHostWindowBorders(false); | 181 x11_window_event_filter_->SetUseHostWindowBorders(false); |
| 176 root_window_event_filter_->AddFilter(x11_window_event_filter_.get()); | 182 root_window_event_filter_->AddFilter(x11_window_event_filter_.get()); |
| 177 #endif | 183 #endif |
| 178 | 184 |
| 179 root_window_->AddRootWindowObserver(this); | 185 root_window_->AddRootWindowObserver(this); |
| 180 | 186 |
| 187 window_ = window; |
| 188 window_->AddObserver(this); |
| 189 |
| 181 aura::client::SetActivationClient(root_window_.get(), activation_client); | 190 aura::client::SetActivationClient(root_window_.get(), activation_client); |
| 182 aura::client::SetDispatcherClient(root_window_.get(), | 191 aura::client::SetDispatcherClient(root_window_.get(), |
| 183 new aura::DesktopDispatcherClient); | 192 new aura::DesktopDispatcherClient); |
| 193 #if defined(USE_X11) |
| 194 // TODO(ben): A window implementation of this will need to be written. |
| 195 x11_window_move_client_.reset(new X11DesktopWindowMoveClient); |
| 196 root_window_event_filter_->AddFilter(x11_window_move_client_.get()); |
| 197 aura::client::SetWindowMoveClient(root_window_.get(), |
| 198 x11_window_move_client_.get()); |
| 199 #endif |
| 184 | 200 |
| 185 position_client_.reset(new DesktopScreenPositionClient()); | 201 position_client_.reset(new DesktopScreenPositionClient()); |
| 186 aura::client::SetScreenPositionClient(root_window_.get(), | 202 aura::client::SetScreenPositionClient(root_window_.get(), |
| 187 position_client_.get()); | 203 position_client_.get()); |
| 188 } | 204 } |
| 189 | 205 |
| 190 void DesktopNativeWidgetHelperAura::PostInitialize() { | 206 void DesktopNativeWidgetHelperAura::PostInitialize() { |
| 191 #if defined(OS_WIN) | 207 #if defined(OS_WIN) |
| 192 DCHECK(root_window_->GetAcceleratedWidget()); | 208 DCHECK(root_window_->GetAcceleratedWidget()); |
| 193 hwnd_message_filter_.reset(new WidgetMessageFilter(root_window_.get(), | 209 hwnd_message_filter_.reset(new WidgetMessageFilter(root_window_.get(), |
| 194 widget_->GetWidget())); | 210 widget_->GetWidget())); |
| 195 ui::HWNDSubclass::AddFilterToTarget(root_window_->GetAcceleratedWidget(), | 211 ui::HWNDSubclass::AddFilterToTarget(root_window_->GetAcceleratedWidget(), |
| 196 hwnd_message_filter_.get()); | 212 hwnd_message_filter_.get()); |
| 197 #endif | 213 #endif |
| 198 } | 214 } |
| 199 | 215 |
| 200 void DesktopNativeWidgetHelperAura::ShowRootWindow() { | |
| 201 if (root_window_.get()) | |
| 202 root_window_->ShowRootWindow(); | |
| 203 } | |
| 204 | |
| 205 aura::RootWindow* DesktopNativeWidgetHelperAura::GetRootWindow() { | 216 aura::RootWindow* DesktopNativeWidgetHelperAura::GetRootWindow() { |
| 206 return root_window_.get(); | 217 return root_window_.get(); |
| 207 } | 218 } |
| 208 | 219 |
| 209 gfx::Rect DesktopNativeWidgetHelperAura::ModifyAndSetBounds( | 220 gfx::Rect DesktopNativeWidgetHelperAura::ModifyAndSetBounds( |
| 210 const gfx::Rect& bounds) { | 221 const gfx::Rect& bounds) { |
| 211 gfx::Rect out_bounds = bounds; | 222 gfx::Rect out_bounds = bounds; |
| 212 if (root_window_.get() && !out_bounds.IsEmpty()) { | 223 if (root_window_.get() && !out_bounds.IsEmpty()) { |
| 213 // TODO(scottmg): This avoids the AdjustWindowRect that ash wants to | 224 // TODO(scottmg): This avoids the AdjustWindowRect that ash wants to |
| 214 // adjust the top level on Windows. | 225 // adjust the top level on Windows. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 225 widget_->GetNativeWindow()->GetRootWindow()->GetRootWindow(); | 236 widget_->GetNativeWindow()->GetRootWindow()->GetRootWindow(); |
| 226 gfx::Point point = root->GetHostOrigin(); | 237 gfx::Point point = root->GetHostOrigin(); |
| 227 out_bounds.set_x(out_bounds.x() - point.x()); | 238 out_bounds.set_x(out_bounds.x() - point.x()); |
| 228 out_bounds.set_y(out_bounds.y() - point.y()); | 239 out_bounds.set_y(out_bounds.y() - point.y()); |
| 229 } | 240 } |
| 230 | 241 |
| 231 return out_bounds; | 242 return out_bounds; |
| 232 } | 243 } |
| 233 | 244 |
| 234 //////////////////////////////////////////////////////////////////////////////// | 245 //////////////////////////////////////////////////////////////////////////////// |
| 246 // DesktopNativeWidgetHelperAura, aura::WindowObserver implementation: |
| 247 void DesktopNativeWidgetHelperAura::OnWindowVisibilityChanged( |
| 248 aura::Window* window, |
| 249 bool visible) { |
| 250 DCHECK_EQ(window, window_); |
| 251 |
| 252 // Since we're trying to hide the main window, hide the OS level root as well. |
| 253 if (visible) |
| 254 root_window_->ShowRootWindow(); |
| 255 else |
| 256 root_window_->HideRootWindow(); |
| 257 } |
| 258 |
| 259 //////////////////////////////////////////////////////////////////////////////// |
| 235 // DesktopNativeWidgetHelperAura, aura::RootWindowObserver implementation: | 260 // DesktopNativeWidgetHelperAura, aura::RootWindowObserver implementation: |
| 236 | 261 |
| 237 void DesktopNativeWidgetHelperAura::OnRootWindowResized( | 262 void DesktopNativeWidgetHelperAura::OnRootWindowResized( |
| 238 const aura::RootWindow* root, | 263 const aura::RootWindow* root, |
| 239 const gfx::Size& old_size) { | 264 const gfx::Size& old_size) { |
| 240 DCHECK_EQ(root, root_window_.get()); | 265 DCHECK_EQ(root, root_window_.get()); |
| 241 widget_->SetBounds(gfx::Rect(root->GetHostOrigin(), | 266 widget_->SetBounds(gfx::Rect(root->GetHostOrigin(), |
| 242 root->GetHostSize())); | 267 root->GetHostSize())); |
| 243 } | 268 } |
| 244 | 269 |
| 245 void DesktopNativeWidgetHelperAura::OnRootWindowHostClosed( | 270 void DesktopNativeWidgetHelperAura::OnRootWindowHostClosed( |
| 246 const aura::RootWindow* root) { | 271 const aura::RootWindow* root) { |
| 247 DCHECK_EQ(root, root_window_.get()); | 272 DCHECK_EQ(root, root_window_.get()); |
| 248 widget_->GetWidget()->Close(); | 273 widget_->GetWidget()->Close(); |
| 249 } | 274 } |
| 250 | 275 |
| 276 void DesktopNativeWidgetHelperAura::OnRootWindowMoved( |
| 277 const aura::RootWindow* root, |
| 278 const gfx::Point& new_origin) { |
| 279 widget_->GetWidget()->OnNativeWidgetMove(); |
| 280 } |
| 281 |
| 251 } // namespace views | 282 } // namespace views |
| OLD | NEW |