| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/aura/root_window.h" | 5 #include "ui/aura/root_window.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 explicit DefaultStackingClient(RootWindow* root_window) | 59 explicit DefaultStackingClient(RootWindow* root_window) |
| 60 : root_window_(root_window) {} | 60 : root_window_(root_window) {} |
| 61 virtual ~DefaultStackingClient() {} | 61 virtual ~DefaultStackingClient() {} |
| 62 | 62 |
| 63 private: | 63 private: |
| 64 | 64 |
| 65 // Overridden from StackingClient: | 65 // Overridden from StackingClient: |
| 66 virtual void AddChildToDefaultParent(Window* window) OVERRIDE { | 66 virtual void AddChildToDefaultParent(Window* window) OVERRIDE { |
| 67 root_window_->AddChild(window); | 67 root_window_->AddChild(window); |
| 68 } | 68 } |
| 69 virtual bool CanActivateWindow(Window* window) const OVERRIDE { | |
| 70 return window->parent() == root_window_; | |
| 71 } | |
| 72 virtual Window* GetTopmostWindowToActivate(Window* ignore) const OVERRIDE { | |
| 73 Window::Windows::const_reverse_iterator i; | |
| 74 for (i = root_window_->children().rbegin(); | |
| 75 i != root_window_->children().rend(); | |
| 76 ++i) { | |
| 77 if (*i == ignore) | |
| 78 continue; | |
| 79 return *i; | |
| 80 } | |
| 81 return NULL; | |
| 82 } | |
| 83 | 69 |
| 84 RootWindow* root_window_; | 70 RootWindow* root_window_; |
| 85 | 71 |
| 86 DISALLOW_COPY_AND_ASSIGN(DefaultStackingClient); | 72 DISALLOW_COPY_AND_ASSIGN(DefaultStackingClient); |
| 87 }; | 73 }; |
| 88 | 74 |
| 89 typedef std::vector<EventFilter*> EventFilters; | 75 typedef std::vector<EventFilter*> EventFilters; |
| 90 | 76 |
| 91 void GetEventFiltersToNotify(Window* target, EventFilters* filters) { | 77 void GetEventFiltersToNotify(Window* target, EventFilters* filters) { |
| 92 Window* window = target->parent(); | 78 Window* window = target->parent(); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 SetBounds(gfx::Rect(bounds.size())); | 223 SetBounds(gfx::Rect(bounds.size())); |
| 238 FOR_EACH_OBSERVER(RootWindowObserver, observers_, | 224 FOR_EACH_OBSERVER(RootWindowObserver, observers_, |
| 239 OnRootWindowResized(bounds.size())); | 225 OnRootWindowResized(bounds.size())); |
| 240 } | 226 } |
| 241 | 227 |
| 242 void RootWindow::OnNativeScreenResized(const gfx::Size& size) { | 228 void RootWindow::OnNativeScreenResized(const gfx::Size& size) { |
| 243 if (use_fullscreen_host_window_) | 229 if (use_fullscreen_host_window_) |
| 244 SetHostSize(size); | 230 SetHostSize(size); |
| 245 } | 231 } |
| 246 | 232 |
| 247 void RootWindow::SetActiveWindow(Window* window, Window* to_focus) { | |
| 248 if (!window) | |
| 249 return; | |
| 250 // The stacking client may impose rules on what window configurations can be | |
| 251 // activated or deactivated. | |
| 252 if (!stacking_client_->CanActivateWindow(window)) | |
| 253 return; | |
| 254 // The window may not be activate-able. | |
| 255 if (!window->CanActivate()) | |
| 256 return; | |
| 257 // Nothing may actually have changed. | |
| 258 if (active_window_ == window) | |
| 259 return; | |
| 260 | |
| 261 Window* old_active = active_window_; | |
| 262 active_window_ = window; | |
| 263 // Invoke OnLostActive after we've changed the active window. That way if the | |
| 264 // delegate queries for active state it doesn't think the window is still | |
| 265 // active. | |
| 266 if (old_active && old_active->delegate()) | |
| 267 old_active->delegate()->OnLostActive(); | |
| 268 if (active_window_) { | |
| 269 active_window_->parent()->StackChildAtTop(active_window_); | |
| 270 if (active_window_->delegate()) | |
| 271 active_window_->delegate()->OnActivated(); | |
| 272 active_window_->GetFocusManager()->SetFocusedWindow( | |
| 273 to_focus ? to_focus : active_window_); | |
| 274 } | |
| 275 FOR_EACH_OBSERVER(RootWindowObserver, observers_, | |
| 276 OnActiveWindowChanged(active_window_)); | |
| 277 } | |
| 278 | |
| 279 void RootWindow::ActivateTopmostWindow() { | |
| 280 SetActiveWindow(stacking_client_->GetTopmostWindowToActivate(NULL), NULL); | |
| 281 } | |
| 282 | |
| 283 void RootWindow::Deactivate(Window* window) { | |
| 284 // The stacking client may impose rules on what window configurations can be | |
| 285 // activated or deactivated. | |
| 286 if (!window || !stacking_client_->CanActivateWindow(window)) | |
| 287 return; | |
| 288 if (active_window_ != window) | |
| 289 return; | |
| 290 | |
| 291 Window* to_activate = stacking_client_->GetTopmostWindowToActivate(window); | |
| 292 if (to_activate) | |
| 293 SetActiveWindow(to_activate, NULL); | |
| 294 } | |
| 295 | |
| 296 void RootWindow::WindowInitialized(Window* window) { | 233 void RootWindow::WindowInitialized(Window* window) { |
| 297 FOR_EACH_OBSERVER(RootWindowObserver, observers_, | 234 FOR_EACH_OBSERVER(RootWindowObserver, observers_, |
| 298 OnWindowInitialized(window)); | 235 OnWindowInitialized(window)); |
| 299 } | 236 } |
| 300 | 237 |
| 301 void RootWindow::WindowDestroying(Window* window) { | 238 void RootWindow::WindowDestroying(Window* window) { |
| 302 // Update the focused window state if the window was focused. | 239 // Update the focused window state if the window was focused. |
| 303 if (focused_window_ == window) | 240 if (focused_window_ == window) |
| 304 SetFocusedWindow(NULL); | 241 SetFocusedWindow(NULL); |
| 305 | 242 |
| 306 // When a window is being destroyed it's likely that the WindowDelegate won't | 243 // When a window is being destroyed it's likely that the WindowDelegate won't |
| 307 // want events, so we reset the mouse_pressed_handler_ and capture_window_ and | 244 // want events, so we reset the mouse_pressed_handler_ and capture_window_ and |
| 308 // don't sent it release/capture lost events. | 245 // don't sent it release/capture lost events. |
| 309 if (mouse_pressed_handler_ == window) | 246 if (mouse_pressed_handler_ == window) |
| 310 mouse_pressed_handler_ = NULL; | 247 mouse_pressed_handler_ = NULL; |
| 311 if (mouse_moved_handler_ == window) | 248 if (mouse_moved_handler_ == window) |
| 312 mouse_moved_handler_ = NULL; | 249 mouse_moved_handler_ = NULL; |
| 313 if (capture_window_ == window) | 250 if (capture_window_ == window) |
| 314 capture_window_ = NULL; | 251 capture_window_ = NULL; |
| 315 if (touch_event_handler_ == window) | 252 if (touch_event_handler_ == window) |
| 316 touch_event_handler_ = NULL; | 253 touch_event_handler_ = NULL; |
| 317 | |
| 318 if (in_destructor_ || window != active_window_) | |
| 319 return; | |
| 320 | |
| 321 // Reset active_window_ before invoking SetActiveWindow so that we don't | |
| 322 // attempt to notify it while running its destructor. | |
| 323 active_window_ = NULL; | |
| 324 SetActiveWindow(stacking_client_->GetTopmostWindowToActivate(window), NULL); | |
| 325 } | 254 } |
| 326 | 255 |
| 327 MessageLoop::Dispatcher* RootWindow::GetDispatcher() { | 256 MessageLoop::Dispatcher* RootWindow::GetDispatcher() { |
| 328 return host_.get(); | 257 return host_.get(); |
| 329 } | 258 } |
| 330 | 259 |
| 331 void RootWindow::AddObserver(RootWindowObserver* observer) { | 260 void RootWindow::AddRootWindowObserver(RootWindowObserver* observer) { |
| 332 observers_.AddObserver(observer); | 261 observers_.AddObserver(observer); |
| 333 } | 262 } |
| 334 | 263 |
| 335 void RootWindow::RemoveObserver(RootWindowObserver* observer) { | 264 void RootWindow::RemoveRootWindowObserver(RootWindowObserver* observer) { |
| 336 observers_.RemoveObserver(observer); | 265 observers_.RemoveObserver(observer); |
| 337 } | 266 } |
| 338 | 267 |
| 339 bool RootWindow::IsMouseButtonDown() const { | 268 bool RootWindow::IsMouseButtonDown() const { |
| 340 return mouse_button_flags_ != 0; | 269 return mouse_button_flags_ != 0; |
| 341 } | 270 } |
| 342 | 271 |
| 343 void RootWindow::PostNativeEvent(const base::NativeEvent& native_event) { | 272 void RootWindow::PostNativeEvent(const base::NativeEvent& native_event) { |
| 344 host_->PostNativeEvent(native_event); | 273 host_->PostNativeEvent(native_event); |
| 345 } | 274 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 | 324 |
| 396 //////////////////////////////////////////////////////////////////////////////// | 325 //////////////////////////////////////////////////////////////////////////////// |
| 397 // RootWindow, private: | 326 // RootWindow, private: |
| 398 | 327 |
| 399 RootWindow::RootWindow() | 328 RootWindow::RootWindow() |
| 400 : Window(NULL), | 329 : Window(NULL), |
| 401 host_(aura::RootWindowHost::Create(GetInitialHostWindowBounds())), | 330 host_(aura::RootWindowHost::Create(GetInitialHostWindowBounds())), |
| 402 ALLOW_THIS_IN_INITIALIZER_LIST( | 331 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 403 stacking_client_(new DefaultStackingClient(this))), | 332 stacking_client_(new DefaultStackingClient(this))), |
| 404 ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_factory_(this)), | 333 ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_factory_(this)), |
| 405 active_window_(NULL), | |
| 406 mouse_button_flags_(0), | 334 mouse_button_flags_(0), |
| 407 last_cursor_(kCursorNull), | 335 last_cursor_(kCursorNull), |
| 408 in_destructor_(false), | |
| 409 screen_(new ScreenAura), | 336 screen_(new ScreenAura), |
| 410 capture_window_(NULL), | 337 capture_window_(NULL), |
| 411 mouse_pressed_handler_(NULL), | 338 mouse_pressed_handler_(NULL), |
| 412 mouse_moved_handler_(NULL), | 339 mouse_moved_handler_(NULL), |
| 413 focused_window_(NULL), | 340 focused_window_(NULL), |
| 414 touch_event_handler_(NULL) { | 341 touch_event_handler_(NULL) { |
| 415 SetName("RootWindow"); | 342 SetName("RootWindow"); |
| 416 gfx::Screen::SetInstance(screen_); | 343 gfx::Screen::SetInstance(screen_); |
| 417 host_->SetRootWindow(this); | 344 host_->SetRootWindow(this); |
| 418 last_mouse_location_ = host_->QueryMouseLocation(); | 345 last_mouse_location_ = host_->QueryMouseLocation(); |
| 419 | 346 |
| 420 if (ui::Compositor::compositor_factory()) { | 347 if (ui::Compositor::compositor_factory()) { |
| 421 compositor_ = (*ui::Compositor::compositor_factory())(this); | 348 compositor_ = (*ui::Compositor::compositor_factory())(this); |
| 422 } else { | 349 } else { |
| 423 #ifdef USE_WEBKIT_COMPOSITOR | 350 #ifdef USE_WEBKIT_COMPOSITOR |
| 424 ui::CompositorCC::Initialize(false); | 351 ui::CompositorCC::Initialize(false); |
| 425 #endif | 352 #endif |
| 426 compositor_ = ui::Compositor::Create(this, host_->GetAcceleratedWidget(), | 353 compositor_ = ui::Compositor::Create(this, host_->GetAcceleratedWidget(), |
| 427 host_->GetSize()); | 354 host_->GetSize()); |
| 428 } | 355 } |
| 429 DCHECK(compositor_.get()); | 356 DCHECK(compositor_.get()); |
| 430 } | 357 } |
| 431 | 358 |
| 432 RootWindow::~RootWindow() { | 359 RootWindow::~RootWindow() { |
| 433 in_destructor_ = true; | |
| 434 // Make sure to destroy the compositor before terminating so that state is | 360 // Make sure to destroy the compositor before terminating so that state is |
| 435 // cleared and we don't hit asserts. | 361 // cleared and we don't hit asserts. |
| 436 compositor_ = NULL; | 362 compositor_ = NULL; |
| 437 #ifdef USE_WEBKIT_COMPOSITOR | 363 #ifdef USE_WEBKIT_COMPOSITOR |
| 438 if (!ui::Compositor::compositor_factory()) | 364 if (!ui::Compositor::compositor_factory()) |
| 439 ui::CompositorCC::Terminate(); | 365 ui::CompositorCC::Terminate(); |
| 440 #endif | 366 #endif |
| 441 if (instance_ == this) | 367 if (instance_ == this) |
| 442 instance_ = NULL; | 368 instance_ = NULL; |
| 443 } | 369 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 void RootWindow::SetFocusedWindow(Window* focused_window) { | 493 void RootWindow::SetFocusedWindow(Window* focused_window) { |
| 568 if (focused_window == focused_window_ || | 494 if (focused_window == focused_window_ || |
| 569 (focused_window && !focused_window->CanFocus())) { | 495 (focused_window && !focused_window->CanFocus())) { |
| 570 return; | 496 return; |
| 571 } | 497 } |
| 572 if (focused_window_ && focused_window_->delegate()) | 498 if (focused_window_ && focused_window_->delegate()) |
| 573 focused_window_->delegate()->OnBlur(); | 499 focused_window_->delegate()->OnBlur(); |
| 574 focused_window_ = focused_window; | 500 focused_window_ = focused_window; |
| 575 if (focused_window_ && focused_window_->delegate()) | 501 if (focused_window_ && focused_window_->delegate()) |
| 576 focused_window_->delegate()->OnFocus(); | 502 focused_window_->delegate()->OnFocus(); |
| 503 if (focused_window_) { |
| 504 FOR_EACH_OBSERVER(RootWindowObserver, observers_, |
| 505 OnWindowFocused(focused_window_)); |
| 506 } |
| 577 } | 507 } |
| 578 | 508 |
| 579 Window* RootWindow::GetFocusedWindow() { | 509 Window* RootWindow::GetFocusedWindow() { |
| 580 return focused_window_; | 510 return focused_window_; |
| 581 } | 511 } |
| 582 | 512 |
| 583 bool RootWindow::IsFocusedWindow(const Window* window) const { | 513 bool RootWindow::IsFocusedWindow(const Window* window) const { |
| 584 return focused_window_ == window; | 514 return focused_window_ == window; |
| 585 } | 515 } |
| 586 | 516 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 605 base::StringToInt(parts[1], &parsed_height) && parsed_height > 0) { | 535 base::StringToInt(parts[1], &parsed_height) && parsed_height > 0) { |
| 606 bounds.set_size(gfx::Size(parsed_width, parsed_height)); | 536 bounds.set_size(gfx::Size(parsed_width, parsed_height)); |
| 607 } else if (use_fullscreen_host_window_) { | 537 } else if (use_fullscreen_host_window_) { |
| 608 bounds = gfx::Rect(RootWindowHost::GetNativeScreenSize()); | 538 bounds = gfx::Rect(RootWindowHost::GetNativeScreenSize()); |
| 609 } | 539 } |
| 610 | 540 |
| 611 return bounds; | 541 return bounds; |
| 612 } | 542 } |
| 613 | 543 |
| 614 } // namespace aura | 544 } // namespace aura |
| OLD | NEW |