| 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 "ui/aura/desktop.h" | 10 #include "ui/aura/desktop.h" |
| 11 #include "ui/aura/desktop_delegate.h" | 11 #include "ui/aura/desktop_delegate.h" |
| 12 #include "ui/aura/event.h" | 12 #include "ui/aura/event.h" |
| 13 #include "ui/aura/event_filter.h" | 13 #include "ui/aura/event_filter.h" |
| 14 #include "ui/aura/layout_manager.h" | 14 #include "ui/aura/layout_manager.h" |
| 15 #include "ui/aura/window_delegate.h" | 15 #include "ui/aura/window_delegate.h" |
| 16 #include "ui/aura/window_observer.h" |
| 16 #include "ui/aura/window_types.h" | 17 #include "ui/aura/window_types.h" |
| 17 #include "ui/base/animation/multi_animation.h" | 18 #include "ui/base/animation/multi_animation.h" |
| 18 #include "ui/gfx/canvas_skia.h" | 19 #include "ui/gfx/canvas_skia.h" |
| 19 #include "ui/gfx/compositor/compositor.h" | 20 #include "ui/gfx/compositor/compositor.h" |
| 20 #include "ui/gfx/compositor/layer.h" | 21 #include "ui/gfx/compositor/layer.h" |
| 21 #include "ui/gfx/screen.h" | 22 #include "ui/gfx/screen.h" |
| 22 | 23 |
| 23 namespace aura { | 24 namespace aura { |
| 24 | 25 |
| 25 using internal::RootWindow; | 26 using internal::RootWindow; |
| 26 | 27 |
| 27 Window::Window(WindowDelegate* delegate) | 28 Window::Window(WindowDelegate* delegate) |
| 28 : type_(kWindowType_Toplevel), | 29 : type_(kWindowType_Toplevel), |
| 29 delegate_(delegate), | 30 delegate_(delegate), |
| 30 show_state_(ui::SHOW_STATE_NORMAL), | 31 show_state_(ui::SHOW_STATE_NORMAL), |
| 31 parent_(NULL), | 32 parent_(NULL), |
| 32 id_(-1), | 33 id_(-1), |
| 33 user_data_(NULL), | 34 user_data_(NULL), |
| 34 stops_event_propagation_(false) { | 35 stops_event_propagation_(false) { |
| 35 } | 36 } |
| 36 | 37 |
| 37 Window::~Window() { | 38 Window::~Window() { |
| 39 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowClosing(this)); |
| 40 |
| 38 // Let the delegate know we're in the processing of destroying. | 41 // Let the delegate know we're in the processing of destroying. |
| 39 if (delegate_) | 42 if (delegate_) |
| 40 delegate_->OnWindowDestroying(); | 43 delegate_->OnWindowDestroying(); |
| 41 | 44 |
| 42 // Let the root know so that it can remove any references to us. | 45 // Let the root know so that it can remove any references to us. |
| 43 RootWindow* root = GetRoot(); | 46 RootWindow* root = GetRoot(); |
| 44 if (root) | 47 if (root) |
| 45 root->WindowDestroying(this); | 48 root->WindowDestroying(this); |
| 46 | 49 |
| 47 // Then destroy the children. | 50 // Then destroy the children. |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 if (!parent_->event_filter_.get()) | 255 if (!parent_->event_filter_.get()) |
| 253 parent_->SetEventFilter(new EventFilter(parent_)); | 256 parent_->SetEventFilter(new EventFilter(parent_)); |
| 254 return parent_->event_filter_->OnMouseEvent(this, event) || | 257 return parent_->event_filter_->OnMouseEvent(this, event) || |
| 255 delegate_->OnMouseEvent(event); | 258 delegate_->OnMouseEvent(event); |
| 256 } | 259 } |
| 257 | 260 |
| 258 bool Window::OnKeyEvent(KeyEvent* event) { | 261 bool Window::OnKeyEvent(KeyEvent* event) { |
| 259 return IsVisible() && delegate_->OnKeyEvent(event); | 262 return IsVisible() && delegate_->OnKeyEvent(event); |
| 260 } | 263 } |
| 261 | 264 |
| 265 void Window::AddObserver(WindowObserver* observer) { |
| 266 observers_.AddObserver(observer); |
| 267 } |
| 268 |
| 269 void Window::RemoveObserver(WindowObserver* observer) { |
| 270 observers_.RemoveObserver(observer); |
| 271 } |
| 272 |
| 262 bool Window::HitTest(const gfx::Point& point) { | 273 bool Window::HitTest(const gfx::Point& point) { |
| 263 gfx::Rect local_bounds(gfx::Point(), bounds().size()); | 274 gfx::Rect local_bounds(gfx::Point(), bounds().size()); |
| 264 // TODO(beng): hittest masks. | 275 // TODO(beng): hittest masks. |
| 265 return local_bounds.Contains(point); | 276 return local_bounds.Contains(point); |
| 266 } | 277 } |
| 267 | 278 |
| 268 Window* Window::GetEventHandlerForPoint(const gfx::Point& point) { | 279 Window* Window::GetEventHandlerForPoint(const gfx::Point& point) { |
| 269 Windows::const_reverse_iterator i = children_.rbegin(); | 280 Windows::const_reverse_iterator i = children_.rbegin(); |
| 270 for (; i != children_.rend(); ++i) { | 281 for (; i != children_.rend(); ++i) { |
| 271 Window* child = *i; | 282 Window* child = *i; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 | 375 |
| 365 void Window::SetVisible(bool visible) { | 376 void Window::SetVisible(bool visible) { |
| 366 bool was_visible = IsVisible(); | 377 bool was_visible = IsVisible(); |
| 367 layer_->SetVisible(visible); | 378 layer_->SetVisible(visible); |
| 368 bool is_visible = IsVisible(); | 379 bool is_visible = IsVisible(); |
| 369 if (was_visible != is_visible) { | 380 if (was_visible != is_visible) { |
| 370 SchedulePaint(); | 381 SchedulePaint(); |
| 371 if (delegate_) | 382 if (delegate_) |
| 372 delegate_->OnWindowVisibilityChanged(is_visible); | 383 delegate_->OnWindowVisibilityChanged(is_visible); |
| 373 } | 384 } |
| 385 |
| 386 FOR_EACH_OBSERVER(WindowObserver, observers_, |
| 387 OnWindowVisibilityChanged(this)); |
| 374 } | 388 } |
| 375 | 389 |
| 376 void Window::SchedulePaint() { | 390 void Window::SchedulePaint() { |
| 377 SchedulePaintInRect(gfx::Rect(0, 0, bounds().width(), bounds().height())); | 391 SchedulePaintInRect(gfx::Rect(0, 0, bounds().width(), bounds().height())); |
| 378 } | 392 } |
| 379 | 393 |
| 380 bool Window::StopsEventPropagation() const { | 394 bool Window::StopsEventPropagation() const { |
| 381 return stops_event_propagation_ && !children_.empty(); | 395 return stops_event_propagation_ && !children_.empty(); |
| 382 } | 396 } |
| 383 | 397 |
| 384 bool Window::UpdateShowStateAndRestoreBounds( | 398 bool Window::UpdateShowStateAndRestoreBounds( |
| 385 ui::WindowShowState new_show_state) { | 399 ui::WindowShowState new_show_state) { |
| 386 if (show_state_ == new_show_state) | 400 if (show_state_ == new_show_state) |
| 387 return false; | 401 return false; |
| 388 show_state_ = new_show_state; | 402 show_state_ = new_show_state; |
| 389 if (restore_bounds_.IsEmpty()) | 403 if (restore_bounds_.IsEmpty()) |
| 390 restore_bounds_ = bounds(); | 404 restore_bounds_ = bounds(); |
| 391 return true; | 405 return true; |
| 392 } | 406 } |
| 393 | 407 |
| 394 void Window::OnPaintLayer(gfx::Canvas* canvas) { | 408 void Window::OnPaintLayer(gfx::Canvas* canvas) { |
| 395 delegate_->OnPaint(canvas); | 409 delegate_->OnPaint(canvas); |
| 396 } | 410 } |
| 397 | 411 |
| 398 } // namespace aura | 412 } // namespace aura |
| OLD | NEW |