| 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/window.h" | 5 #include "ui/aura/window.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "ui/aura/desktop.h" | 11 #include "ui/aura/desktop.h" |
| 12 #include "ui/aura/desktop_delegate.h" | 12 #include "ui/aura/desktop_delegate.h" |
| 13 #include "ui/aura/event.h" | 13 #include "ui/aura/event.h" |
| 14 #include "ui/aura/event_filter.h" | 14 #include "ui/aura/event_filter.h" |
| 15 #include "ui/aura/layout_manager.h" | 15 #include "ui/aura/layout_manager.h" |
| 16 #include "ui/aura/window_delegate.h" | 16 #include "ui/aura/window_delegate.h" |
| 17 #include "ui/aura/window_observer.h" | 17 #include "ui/aura/window_observer.h" |
| 18 #include "ui/aura/window_types.h" | 18 #include "ui/aura/window_types.h" |
| 19 #include "ui/base/animation/multi_animation.h" | 19 #include "ui/base/animation/multi_animation.h" |
| 20 #include "ui/gfx/canvas_skia.h" | 20 #include "ui/gfx/canvas_skia.h" |
| 21 #include "ui/gfx/compositor/compositor.h" | 21 #include "ui/gfx/compositor/compositor.h" |
| 22 #include "ui/gfx/screen.h" | 22 #include "ui/gfx/screen.h" |
| 23 | 23 |
| 24 namespace aura { | 24 namespace aura { |
| 25 | 25 |
| 26 Window::Window(WindowDelegate* delegate) | 26 Window::Window(WindowDelegate* delegate) |
| 27 : type_(WINDOW_TYPE_UNKNOWN), | 27 : type_(WINDOW_TYPE_UNKNOWN), |
| 28 delegate_(delegate), | 28 delegate_(delegate), |
| 29 show_state_(ui::SHOW_STATE_NORMAL), | |
| 30 parent_(NULL), | 29 parent_(NULL), |
| 31 transient_parent_(NULL), | 30 transient_parent_(NULL), |
| 32 id_(-1), | 31 id_(-1), |
| 33 user_data_(NULL), | 32 user_data_(NULL), |
| 34 stops_event_propagation_(false) { | 33 stops_event_propagation_(false) { |
| 35 } | 34 } |
| 36 | 35 |
| 37 Window::~Window() { | 36 Window::~Window() { |
| 38 // Let the delegate know we're in the processing of destroying. | 37 // Let the delegate know we're in the processing of destroying. |
| 39 if (delegate_) | 38 if (delegate_) |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 if (Desktop::GetInstance()->active_window() == this || | 92 if (Desktop::GetInstance()->active_window() == this || |
| 94 !Desktop::GetInstance()->active_window()) { | 93 !Desktop::GetInstance()->active_window()) { |
| 95 Desktop::GetInstance()->ActivateTopmostWindow(); | 94 Desktop::GetInstance()->ActivateTopmostWindow(); |
| 96 } | 95 } |
| 97 } | 96 } |
| 98 | 97 |
| 99 bool Window::IsVisible() const { | 98 bool Window::IsVisible() const { |
| 100 return layer_->IsDrawn(); | 99 return layer_->IsDrawn(); |
| 101 } | 100 } |
| 102 | 101 |
| 103 void Window::Maximize() { | |
| 104 // The desktop size may have changed, so make sure the window is maximized to | |
| 105 // the correct size even if it's already maximized. | |
| 106 gfx::Rect rect = gfx::Screen::GetMonitorWorkAreaNearestWindow(this); | |
| 107 if (UpdateShowStateAndRestoreBounds(ui::SHOW_STATE_MAXIMIZED) || | |
| 108 rect != bounds()) | |
| 109 SetBoundsInternal(rect); | |
| 110 } | |
| 111 | |
| 112 void Window::Fullscreen() { | |
| 113 // The desktop size may have changed, so make sure the window is fullscreen to | |
| 114 // the correct size even if it's already fullscreen. | |
| 115 gfx::Rect rect = gfx::Screen::GetMonitorAreaNearestWindow(this); | |
| 116 if (UpdateShowStateAndRestoreBounds(ui::SHOW_STATE_FULLSCREEN) || | |
| 117 rect != bounds()) | |
| 118 SetBoundsInternal(rect); | |
| 119 } | |
| 120 | |
| 121 void Window::Restore() { | |
| 122 if (show_state_ != ui::SHOW_STATE_NORMAL) { | |
| 123 show_state_ = ui::SHOW_STATE_NORMAL; | |
| 124 SetBoundsInternal(restore_bounds_); | |
| 125 restore_bounds_.SetRect(0, 0, 0, 0); | |
| 126 } | |
| 127 } | |
| 128 | |
| 129 gfx::Rect Window::GetScreenBounds() const { | 102 gfx::Rect Window::GetScreenBounds() const { |
| 130 const gfx::Rect local_bounds = bounds(); | 103 const gfx::Rect local_bounds = bounds(); |
| 131 gfx::Point origin = local_bounds.origin(); | 104 gfx::Point origin = local_bounds.origin(); |
| 132 Window::ConvertPointToWindow(parent_, | 105 Window::ConvertPointToWindow(parent_, |
| 133 aura::Desktop::GetInstance(), | 106 aura::Desktop::GetInstance(), |
| 134 &origin); | 107 &origin); |
| 135 return gfx::Rect(origin, local_bounds.size()); | 108 return gfx::Rect(origin, local_bounds.size()); |
| 136 } | 109 } |
| 137 | 110 |
| 138 void Window::Activate() { | 111 void Window::Activate() { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 158 | 131 |
| 159 void Window::SetTransform(const ui::Transform& transform) { | 132 void Window::SetTransform(const ui::Transform& transform) { |
| 160 layer()->SetTransform(transform); | 133 layer()->SetTransform(transform); |
| 161 } | 134 } |
| 162 | 135 |
| 163 void Window::SetLayoutManager(LayoutManager* layout_manager) { | 136 void Window::SetLayoutManager(LayoutManager* layout_manager) { |
| 164 layout_manager_.reset(layout_manager); | 137 layout_manager_.reset(layout_manager); |
| 165 } | 138 } |
| 166 | 139 |
| 167 void Window::SetBounds(const gfx::Rect& new_bounds) { | 140 void Window::SetBounds(const gfx::Rect& new_bounds) { |
| 168 gfx::Rect adjusted_bounds = new_bounds; | |
| 169 if (parent_ && parent_->layout_manager()) | 141 if (parent_ && parent_->layout_manager()) |
| 170 parent_->layout_manager()->CalculateBoundsForChild(this, &adjusted_bounds); | 142 parent_->layout_manager()->SetChildBounds(this, new_bounds); |
| 171 | 143 else |
| 172 if (show_state_ == ui::SHOW_STATE_MAXIMIZED || | 144 SetBoundsInternal(new_bounds); |
| 173 show_state_ == ui::SHOW_STATE_FULLSCREEN) { | |
| 174 restore_bounds_ = adjusted_bounds; | |
| 175 return; | |
| 176 } | |
| 177 SetBoundsInternal(adjusted_bounds); | |
| 178 } | 145 } |
| 179 | 146 |
| 180 gfx::Rect Window::GetTargetBounds() const { | 147 gfx::Rect Window::GetTargetBounds() const { |
| 181 return layer_->GetTargetBounds(); | 148 return layer_->GetTargetBounds(); |
| 182 } | 149 } |
| 183 | 150 |
| 184 const gfx::Rect& Window::bounds() const { | 151 const gfx::Rect& Window::bounds() const { |
| 185 return layer_->bounds(); | 152 return layer_->bounds(); |
| 186 } | 153 } |
| 187 | 154 |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 } | 366 } |
| 400 | 367 |
| 401 Window* Window::GetToplevelWindow() { | 368 Window* Window::GetToplevelWindow() { |
| 402 Window* window = this; | 369 Window* window = this; |
| 403 while (window && window->parent() && | 370 while (window && window->parent() && |
| 404 !window->parent()->AsToplevelWindowContainer()) | 371 !window->parent()->AsToplevelWindowContainer()) |
| 405 window = window->parent(); | 372 window = window->parent(); |
| 406 return window && window->parent() ? window : NULL; | 373 return window && window->parent() ? window : NULL; |
| 407 } | 374 } |
| 408 | 375 |
| 409 bool Window::IsOrContainsFullscreenWindow() const { | |
| 410 if (delegate_) | |
| 411 return IsVisible() && show_state_ == ui::SHOW_STATE_FULLSCREEN; | |
| 412 | |
| 413 for (Windows::const_iterator it = children_.begin(); | |
| 414 it != children_.end(); ++it) { | |
| 415 if ((*it)->IsOrContainsFullscreenWindow()) | |
| 416 return true; | |
| 417 } | |
| 418 return false; | |
| 419 } | |
| 420 | |
| 421 void Window::SetProperty(const char* name, void* value) { | 376 void Window::SetProperty(const char* name, void* value) { |
| 377 void* old = GetProperty(name); |
| 422 if (value) | 378 if (value) |
| 423 prop_map_[name] = value; | 379 prop_map_[name] = value; |
| 424 else | 380 else |
| 425 prop_map_.erase(name); | 381 prop_map_.erase(name); |
| 382 FOR_EACH_OBSERVER(WindowObserver, observers_, |
| 383 OnPropertyChanged(this, name, old)); |
| 384 } |
| 385 |
| 386 void Window::SetIntProperty(const char* name, int value) { |
| 387 SetProperty(name, reinterpret_cast<void*>(value)); |
| 426 } | 388 } |
| 427 | 389 |
| 428 void* Window::GetProperty(const char* name) const { | 390 void* Window::GetProperty(const char* name) const { |
| 429 std::map<const char*, void*>::const_iterator iter = prop_map_.find(name); | 391 std::map<const char*, void*>::const_iterator iter = prop_map_.find(name); |
| 430 if (iter == prop_map_.end()) | 392 if (iter == prop_map_.end()) |
| 431 return NULL; | 393 return NULL; |
| 432 return iter->second; | 394 return iter->second; |
| 433 } | 395 } |
| 434 | 396 |
| 397 int Window::GetIntProperty(const char* name) const { |
| 398 return static_cast<int>(reinterpret_cast<intptr_t>( |
| 399 GetProperty(name))); |
| 400 } |
| 401 |
| 435 Desktop* Window::GetDesktop() { | 402 Desktop* Window::GetDesktop() { |
| 436 return parent_ ? parent_->GetDesktop() : NULL; | 403 return parent_ ? parent_->GetDesktop() : NULL; |
| 437 } | 404 } |
| 438 | 405 |
| 439 void Window::SetBoundsInternal(const gfx::Rect& new_bounds) { | 406 void Window::SetBoundsInternal(const gfx::Rect& new_bounds) { |
| 440 const gfx::Rect old_bounds = bounds(); | 407 const gfx::Rect old_bounds = bounds(); |
| 441 if (old_bounds == new_bounds) | 408 if (old_bounds == new_bounds) |
| 442 return; | 409 return; |
| 443 | 410 |
| 444 bool was_move = old_bounds.size() == new_bounds.size(); | 411 bool was_move = old_bounds.size() == new_bounds.size(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 475 } | 442 } |
| 476 | 443 |
| 477 void Window::SchedulePaint() { | 444 void Window::SchedulePaint() { |
| 478 SchedulePaintInRect(gfx::Rect(0, 0, bounds().width(), bounds().height())); | 445 SchedulePaintInRect(gfx::Rect(0, 0, bounds().width(), bounds().height())); |
| 479 } | 446 } |
| 480 | 447 |
| 481 bool Window::StopsEventPropagation() const { | 448 bool Window::StopsEventPropagation() const { |
| 482 return stops_event_propagation_ && !children_.empty(); | 449 return stops_event_propagation_ && !children_.empty(); |
| 483 } | 450 } |
| 484 | 451 |
| 485 bool Window::UpdateShowStateAndRestoreBounds( | |
| 486 ui::WindowShowState new_show_state) { | |
| 487 if (show_state_ == new_show_state) | |
| 488 return false; | |
| 489 show_state_ = new_show_state; | |
| 490 if (restore_bounds_.IsEmpty()) | |
| 491 restore_bounds_ = bounds(); | |
| 492 return true; | |
| 493 } | |
| 494 | |
| 495 Window* Window::GetWindowForPoint(const gfx::Point& local_point, | 452 Window* Window::GetWindowForPoint(const gfx::Point& local_point, |
| 496 bool return_tightest, | 453 bool return_tightest, |
| 497 bool for_event_handling) { | 454 bool for_event_handling) { |
| 498 if (!IsVisible()) | 455 if (!IsVisible()) |
| 499 return NULL; | 456 return NULL; |
| 500 | 457 |
| 501 if ((for_event_handling && !HitTest(local_point)) || | 458 if ((for_event_handling && !HitTest(local_point)) || |
| 502 (!for_event_handling && !ContainsPoint(local_point))) | 459 (!for_event_handling && !ContainsPoint(local_point))) |
| 503 return NULL; | 460 return NULL; |
| 504 | 461 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 528 | 485 |
| 529 void Window::OnPaintLayer(gfx::Canvas* canvas) { | 486 void Window::OnPaintLayer(gfx::Canvas* canvas) { |
| 530 delegate_->OnPaint(canvas); | 487 delegate_->OnPaint(canvas); |
| 531 } | 488 } |
| 532 | 489 |
| 533 void Window::OnLayerAnimationEnded( | 490 void Window::OnLayerAnimationEnded( |
| 534 const ui::LayerAnimationSequence* animation) { | 491 const ui::LayerAnimationSequence* animation) { |
| 535 } | 492 } |
| 536 | 493 |
| 537 } // namespace aura | 494 } // namespace aura |
| OLD | NEW |