| 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/event.h" | 11 #include "ui/aura/event.h" |
| 12 #include "ui/aura/event_filter.h" | 12 #include "ui/aura/event_filter.h" |
| 13 #include "ui/aura/layout_manager.h" | 13 #include "ui/aura/layout_manager.h" |
| 14 #include "ui/aura/window_delegate.h" | 14 #include "ui/aura/window_delegate.h" |
| 15 #include "ui/base/animation/multi_animation.h" | 15 #include "ui/base/animation/multi_animation.h" |
| 16 #include "ui/gfx/canvas_skia.h" | 16 #include "ui/gfx/canvas_skia.h" |
| 17 #include "ui/gfx/compositor/compositor.h" | 17 #include "ui/gfx/compositor/compositor.h" |
| 18 #include "ui/gfx/compositor/layer.h" | 18 #include "ui/gfx/compositor/layer.h" |
| 19 | 19 |
| 20 namespace aura { | 20 namespace aura { |
| 21 | 21 |
| 22 using internal::RootWindow; | 22 using internal::RootWindow; |
| 23 | 23 |
| 24 Window::Window(WindowDelegate* delegate) | 24 Window::Window(WindowDelegate* delegate) |
| 25 : delegate_(delegate), | 25 : delegate_(delegate), |
| 26 visible_(false), | |
| 27 parent_(NULL), | 26 parent_(NULL), |
| 28 id_(-1), | 27 id_(-1), |
| 29 user_data_(NULL), | 28 user_data_(NULL), |
| 30 consumes_events_(false) { | 29 consumes_events_(false) { |
| 31 } | 30 } |
| 32 | 31 |
| 33 Window::~Window() { | 32 Window::~Window() { |
| 34 // Let the delegate know we're in the processing of destroying. | 33 // Let the delegate know we're in the processing of destroying. |
| 35 if (delegate_) | 34 if (delegate_) |
| 36 delegate_->OnWindowDestroying(); | 35 delegate_->OnWindowDestroying(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 53 delegate_->OnWindowDestroyed(); | 52 delegate_->OnWindowDestroyed(); |
| 54 if (parent_) | 53 if (parent_) |
| 55 parent_->RemoveChild(this); | 54 parent_->RemoveChild(this); |
| 56 } | 55 } |
| 57 | 56 |
| 58 void Window::Init() { | 57 void Window::Init() { |
| 59 ui::Layer::LayerType type = ui::Layer::LAYER_HAS_NO_TEXTURE; | 58 ui::Layer::LayerType type = ui::Layer::LAYER_HAS_NO_TEXTURE; |
| 60 if (delegate_) | 59 if (delegate_) |
| 61 type = ui::Layer::LAYER_HAS_TEXTURE; | 60 type = ui::Layer::LAYER_HAS_TEXTURE; |
| 62 layer_.reset(new ui::Layer(Desktop::GetInstance()->compositor(), type)); | 61 layer_.reset(new ui::Layer(Desktop::GetInstance()->compositor(), type)); |
| 62 // Windows (and therefore the layer) should initially be hidden. |
| 63 // TODO: when we distinguish control (child) windows, they should be initially |
| 64 // visible. |
| 65 layer_->SetVisible(false); |
| 63 layer_->set_delegate(this); | 66 layer_->set_delegate(this); |
| 64 } | 67 } |
| 65 | 68 |
| 66 void Window::Show() { | 69 void Window::Show() { |
| 67 SetVisible(true); | 70 SetVisible(true); |
| 68 } | 71 } |
| 69 | 72 |
| 70 void Window::Hide() { | 73 void Window::Hide() { |
| 71 SetVisible(false); | 74 SetVisible(false); |
| 72 ReleaseCapture(); | 75 ReleaseCapture(); |
| 73 if (Desktop::GetInstance()->active_window() == this || | 76 if (Desktop::GetInstance()->active_window() == this || |
| 74 !Desktop::GetInstance()->active_window()) { | 77 !Desktop::GetInstance()->active_window()) { |
| 75 Desktop::GetInstance()->ActivateTopmostWindow(); | 78 Desktop::GetInstance()->ActivateTopmostWindow(); |
| 76 } | 79 } |
| 77 } | 80 } |
| 78 | 81 |
| 82 bool Window::IsVisible() const { |
| 83 return layer_->IsDrawn(); |
| 84 } |
| 85 |
| 79 void Window::SetLayoutManager(LayoutManager* layout_manager) { | 86 void Window::SetLayoutManager(LayoutManager* layout_manager) { |
| 80 layout_manager_.reset(layout_manager); | 87 layout_manager_.reset(layout_manager); |
| 81 } | 88 } |
| 82 | 89 |
| 83 void Window::SetBounds(const gfx::Rect& new_bounds) { | 90 void Window::SetBounds(const gfx::Rect& new_bounds) { |
| 84 // TODO: funnel this through the Desktop. | 91 // TODO: funnel this through the Desktop. |
| 85 gfx::Rect old_bounds = bounds(); | 92 gfx::Rect old_bounds = bounds(); |
| 86 bool was_move = old_bounds.size() == new_bounds.size(); | 93 bool was_move = old_bounds.size() == new_bounds.size(); |
| 87 layer_->SetBounds(new_bounds); | 94 layer_->SetBounds(new_bounds); |
| 88 | 95 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 bool Window::HitTest(const gfx::Point& point) { | 205 bool Window::HitTest(const gfx::Point& point) { |
| 199 gfx::Rect local_bounds(gfx::Point(), bounds().size()); | 206 gfx::Rect local_bounds(gfx::Point(), bounds().size()); |
| 200 // TODO(beng): hittest masks. | 207 // TODO(beng): hittest masks. |
| 201 return local_bounds.Contains(point); | 208 return local_bounds.Contains(point); |
| 202 } | 209 } |
| 203 | 210 |
| 204 Window* Window::GetEventHandlerForPoint(const gfx::Point& point) { | 211 Window* Window::GetEventHandlerForPoint(const gfx::Point& point) { |
| 205 Windows::const_reverse_iterator i = children_.rbegin(); | 212 Windows::const_reverse_iterator i = children_.rbegin(); |
| 206 for (; i != children_.rend(); ++i) { | 213 for (; i != children_.rend(); ++i) { |
| 207 Window* child = *i; | 214 Window* child = *i; |
| 208 if (!child->visible()) | 215 if (!child->IsVisible()) |
| 209 continue; | 216 continue; |
| 210 gfx::Point point_in_child_coords(point); | 217 gfx::Point point_in_child_coords(point); |
| 211 Window::ConvertPointToWindow(this, child, &point_in_child_coords); | 218 Window::ConvertPointToWindow(this, child, &point_in_child_coords); |
| 212 if (child->HitTest(point_in_child_coords)) { | 219 if (child->HitTest(point_in_child_coords)) { |
| 213 Window* handler = child->GetEventHandlerForPoint(point_in_child_coords); | 220 Window* handler = child->GetEventHandlerForPoint(point_in_child_coords); |
| 214 if (handler && handler->delegate()) | 221 if (handler && handler->delegate()) |
| 215 return handler; | 222 return handler; |
| 216 } | 223 } |
| 217 if (child->consumes_events_ && !child->children().empty()) | 224 if (child->consumes_events_ && !child->children().empty()) |
| 218 return NULL; | 225 return NULL; |
| 219 } | 226 } |
| 220 return delegate_ ? this : NULL; | 227 return delegate_ ? this : NULL; |
| 221 } | 228 } |
| 222 | 229 |
| 223 internal::FocusManager* Window::GetFocusManager() { | 230 internal::FocusManager* Window::GetFocusManager() { |
| 224 return parent_ ? parent_->GetFocusManager() : NULL; | 231 return parent_ ? parent_->GetFocusManager() : NULL; |
| 225 } | 232 } |
| 226 | 233 |
| 227 void Window::SetCapture() { | 234 void Window::SetCapture() { |
| 228 if (!visible_) | 235 if (!IsVisible()) |
| 229 return; | 236 return; |
| 230 | 237 |
| 231 RootWindow* root = GetRoot(); | 238 RootWindow* root = GetRoot(); |
| 232 if (!root) | 239 if (!root) |
| 233 return; | 240 return; |
| 234 | 241 |
| 235 root->SetCapture(this); | 242 root->SetCapture(this); |
| 236 } | 243 } |
| 237 | 244 |
| 238 void Window::ReleaseCapture() { | 245 void Window::ReleaseCapture() { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 255 ui::MultiAnimation* multi_animation = new ui::MultiAnimation(parts); | 262 ui::MultiAnimation* multi_animation = new ui::MultiAnimation(parts); |
| 256 multi_animation->set_continuous(false); | 263 multi_animation->set_continuous(false); |
| 257 return multi_animation; | 264 return multi_animation; |
| 258 } | 265 } |
| 259 | 266 |
| 260 internal::RootWindow* Window::GetRoot() { | 267 internal::RootWindow* Window::GetRoot() { |
| 261 return parent_ ? parent_->GetRoot() : NULL; | 268 return parent_ ? parent_->GetRoot() : NULL; |
| 262 } | 269 } |
| 263 | 270 |
| 264 void Window::SetVisible(bool visible) { | 271 void Window::SetVisible(bool visible) { |
| 265 if (visible_ == visible) | 272 bool was_visible = IsVisible(); |
| 266 return; | 273 layer_->SetVisible(visible); |
| 267 | 274 bool is_visible = IsVisible(); |
| 268 visible_ = visible; | 275 if (was_visible != is_visible) |
| 269 layer_->SetVisible(visible_); | 276 SchedulePaint(); |
| 270 SchedulePaint(); | |
| 271 } | 277 } |
| 272 | 278 |
| 273 void Window::SchedulePaint() { | 279 void Window::SchedulePaint() { |
| 274 SchedulePaintInRect(gfx::Rect(0, 0, bounds().width(), bounds().height())); | 280 SchedulePaintInRect(gfx::Rect(0, 0, bounds().width(), bounds().height())); |
| 275 } | 281 } |
| 276 | 282 |
| 277 void Window::OnPaintLayer(gfx::Canvas* canvas) { | 283 void Window::OnPaintLayer(gfx::Canvas* canvas) { |
| 278 delegate_->OnPaint(canvas); | 284 delegate_->OnPaint(canvas); |
| 279 } | 285 } |
| 280 | 286 |
| 281 } // namespace aura | 287 } // namespace aura |
| OLD | NEW |