Chromium Code Reviews| 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/focus_manager.h" | 13 #include "ui/aura/focus_manager.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/base/animation/multi_animation.h" | 16 #include "ui/base/animation/multi_animation.h" |
| 17 #include "ui/gfx/canvas_skia.h" | 17 #include "ui/gfx/canvas_skia.h" |
| 18 #include "ui/gfx/compositor/compositor.h" | 18 #include "ui/gfx/compositor/compositor.h" |
| 19 #include "ui/gfx/compositor/layer.h" | 19 #include "ui/gfx/compositor/layer.h" |
| 20 | 20 |
| 21 namespace aura { | 21 namespace aura { |
| 22 | 22 |
| 23 using internal::RootWindow; | 23 using internal::RootWindow; |
| 24 | 24 |
| 25 Window::Window(WindowDelegate* delegate) | 25 Window::Window(WindowDelegate* delegate) |
| 26 : delegate_(delegate), | 26 : delegate_(delegate), |
| 27 visible_(false), | |
| 28 parent_(NULL), | 27 parent_(NULL), |
| 29 id_(-1), | 28 id_(-1), |
| 30 user_data_(NULL) { | 29 user_data_(NULL) { |
| 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(); |
| 37 | 36 |
| (...skipping 15 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 therefor the layer) should initially be hidden. | |
| 63 layer_->SetVisible(false); | |
|
Ben Goodger (Google)
2011/10/05 01:44:09
therefore
also, I think we should make control-ty
| |
| 63 layer_->set_delegate(this); | 64 layer_->set_delegate(this); |
| 64 } | 65 } |
| 65 | 66 |
| 66 void Window::Show() { | 67 void Window::Show() { |
| 67 SetVisible(true); | 68 SetVisible(true); |
| 68 } | 69 } |
| 69 | 70 |
| 70 void Window::Hide() { | 71 void Window::Hide() { |
| 71 SetVisible(false); | 72 SetVisible(false); |
| 72 ReleaseCapture(); | 73 ReleaseCapture(); |
| 73 if (Desktop::GetInstance()->active_window() == this || | 74 if (Desktop::GetInstance()->active_window() == this || |
| 74 !Desktop::GetInstance()->active_window()) { | 75 !Desktop::GetInstance()->active_window()) { |
| 75 Desktop::GetInstance()->ActivateTopmostWindow(); | 76 Desktop::GetInstance()->ActivateTopmostWindow(); |
| 76 } | 77 } |
| 77 } | 78 } |
| 78 | 79 |
| 80 bool Window::IsVisible() const { | |
| 81 return layer_->IsDrawn(); | |
| 82 } | |
| 83 | |
| 79 void Window::SetLayoutManager(LayoutManager* layout_manager) { | 84 void Window::SetLayoutManager(LayoutManager* layout_manager) { |
| 80 layout_manager_.reset(layout_manager); | 85 layout_manager_.reset(layout_manager); |
| 81 } | 86 } |
| 82 | 87 |
| 83 void Window::SetBounds(const gfx::Rect& new_bounds) { | 88 void Window::SetBounds(const gfx::Rect& new_bounds) { |
| 84 // TODO: funnel this through the Desktop. | 89 // TODO: funnel this through the Desktop. |
| 85 gfx::Rect old_bounds = bounds(); | 90 gfx::Rect old_bounds = bounds(); |
| 86 bool was_move = old_bounds.size() == new_bounds.size(); | 91 bool was_move = old_bounds.size() == new_bounds.size(); |
| 87 layer_->SetBounds(new_bounds); | 92 layer_->SetBounds(new_bounds); |
| 88 | 93 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 bool Window::HitTest(const gfx::Point& point) { | 203 bool Window::HitTest(const gfx::Point& point) { |
| 199 gfx::Rect local_bounds(gfx::Point(), bounds().size()); | 204 gfx::Rect local_bounds(gfx::Point(), bounds().size()); |
| 200 // TODO(beng): hittest masks. | 205 // TODO(beng): hittest masks. |
| 201 return local_bounds.Contains(point); | 206 return local_bounds.Contains(point); |
| 202 } | 207 } |
| 203 | 208 |
| 204 Window* Window::GetEventHandlerForPoint(const gfx::Point& point) { | 209 Window* Window::GetEventHandlerForPoint(const gfx::Point& point) { |
| 205 Windows::const_reverse_iterator i = children_.rbegin(); | 210 Windows::const_reverse_iterator i = children_.rbegin(); |
| 206 for (; i != children_.rend(); ++i) { | 211 for (; i != children_.rend(); ++i) { |
| 207 Window* child = *i; | 212 Window* child = *i; |
| 208 if (!child->visible()) | 213 if (!child->IsVisible()) |
| 209 continue; | 214 continue; |
| 210 gfx::Point point_in_child_coords(point); | 215 gfx::Point point_in_child_coords(point); |
| 211 Window::ConvertPointToWindow(this, child, &point_in_child_coords); | 216 Window::ConvertPointToWindow(this, child, &point_in_child_coords); |
| 212 if (child->HitTest(point_in_child_coords)) { | 217 if (child->HitTest(point_in_child_coords)) { |
| 213 Window* handler = child->GetEventHandlerForPoint(point_in_child_coords); | 218 Window* handler = child->GetEventHandlerForPoint(point_in_child_coords); |
| 214 if (handler && handler->delegate()) | 219 if (handler && handler->delegate()) |
| 215 return handler; | 220 return handler; |
| 216 } | 221 } |
| 217 } | 222 } |
| 218 return delegate_ ? this : NULL; | 223 return delegate_ ? this : NULL; |
| 219 } | 224 } |
| 220 | 225 |
| 221 internal::FocusManager* Window::GetFocusManager() { | 226 internal::FocusManager* Window::GetFocusManager() { |
| 222 return parent_ ? parent_->GetFocusManager() : NULL; | 227 return parent_ ? parent_->GetFocusManager() : NULL; |
| 223 } | 228 } |
| 224 | 229 |
| 225 void Window::SetCapture() { | 230 void Window::SetCapture() { |
| 226 if (!visible_) | 231 if (!IsVisible()) |
| 227 return; | 232 return; |
| 228 | 233 |
| 229 RootWindow* root = GetRoot(); | 234 RootWindow* root = GetRoot(); |
| 230 if (!root) | 235 if (!root) |
| 231 return; | 236 return; |
| 232 | 237 |
| 233 root->SetCapture(this); | 238 root->SetCapture(this); |
| 234 } | 239 } |
| 235 | 240 |
| 236 void Window::ReleaseCapture() { | 241 void Window::ReleaseCapture() { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 253 ui::MultiAnimation* multi_animation = new ui::MultiAnimation(parts); | 258 ui::MultiAnimation* multi_animation = new ui::MultiAnimation(parts); |
| 254 multi_animation->set_continuous(false); | 259 multi_animation->set_continuous(false); |
| 255 return multi_animation; | 260 return multi_animation; |
| 256 } | 261 } |
| 257 | 262 |
| 258 internal::RootWindow* Window::GetRoot() { | 263 internal::RootWindow* Window::GetRoot() { |
| 259 return parent_ ? parent_->GetRoot() : NULL; | 264 return parent_ ? parent_->GetRoot() : NULL; |
| 260 } | 265 } |
| 261 | 266 |
| 262 void Window::SetVisible(bool visible) { | 267 void Window::SetVisible(bool visible) { |
| 263 if (visible_ == visible) | 268 bool was_visible = IsVisible(); |
| 264 return; | 269 layer_->SetVisible(visible); |
| 265 | 270 bool is_visible = IsVisible(); |
| 266 visible_ = visible; | 271 if (was_visible != is_visible) |
| 267 layer_->SetVisible(visible_); | 272 SchedulePaint(); |
| 268 SchedulePaint(); | |
| 269 } | 273 } |
| 270 | 274 |
| 271 void Window::SchedulePaint() { | 275 void Window::SchedulePaint() { |
| 272 SchedulePaintInRect(gfx::Rect(0, 0, bounds().width(), bounds().height())); | 276 SchedulePaintInRect(gfx::Rect(0, 0, bounds().width(), bounds().height())); |
| 273 } | 277 } |
| 274 | 278 |
| 275 void Window::OnPaintLayer(gfx::Canvas* canvas) { | 279 void Window::OnPaintLayer(gfx::Canvas* canvas) { |
| 276 delegate_->OnPaint(canvas); | 280 delegate_->OnPaint(canvas); |
| 277 } | 281 } |
| 278 | 282 |
| 279 } // namespace aura | 283 } // namespace aura |
| OLD | NEW |