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