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