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/focus_manager.h" | 13 #include "ui/aura/focus_manager.h" |
| 13 #include "ui/aura/layout_manager.h" | 14 #include "ui/aura/layout_manager.h" |
| 14 #include "ui/aura/window_delegate.h" | 15 #include "ui/aura/window_delegate.h" |
| 15 #include "ui/aura/window_manager.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 Window::Window(WindowDelegate* delegate) | 22 Window::Window(WindowDelegate* delegate) |
| 23 : delegate_(delegate), | 23 : delegate_(delegate), |
| 24 visibility_(VISIBILITY_HIDDEN), | 24 visibility_(VISIBILITY_HIDDEN), |
| 25 parent_(NULL), | 25 parent_(NULL), |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 48 children_.end()); | 48 children_.end()); |
| 49 } | 49 } |
| 50 // And let the delegate do any post cleanup. | 50 // And let the delegate do any post cleanup. |
| 51 if (delegate_) | 51 if (delegate_) |
| 52 delegate_->OnWindowDestroyed(); | 52 delegate_->OnWindowDestroyed(); |
| 53 if (parent_) | 53 if (parent_) |
| 54 parent_->RemoveChild(this); | 54 parent_->RemoveChild(this); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void Window::Init() { | 57 void Window::Init() { |
| 58 layer_.reset(new ui::Layer(Desktop::GetInstance()->compositor())); | 58 ui::Layer::TextureParam param = ui::Layer::LAYER_HAS_NO_TEXTURE; |
| 59 if (delegate_) | |
| 60 param = ui::Layer::LAYER_HAS_TEXTURE; | |
| 61 layer_.reset(new ui::Layer(Desktop::GetInstance()->compositor(), param)); | |
| 59 layer_->set_delegate(this); | 62 layer_->set_delegate(this); |
| 60 } | 63 } |
| 61 | 64 |
| 62 void Window::SetVisibility(Visibility visibility) { | 65 void Window::SetVisibility(Visibility visibility) { |
| 63 if (visibility_ == visibility) | 66 if (visibility_ == visibility) |
| 64 return; | 67 return; |
| 65 | 68 |
| 66 visibility_ = visibility; | 69 visibility_ = visibility; |
| 67 layer_->set_visible(visibility_ != VISIBILITY_HIDDEN); | 70 layer_->set_visible(visibility_ != VISIBILITY_HIDDEN); |
| 68 if (layer_->visible()) | 71 if (layer_->visible()) |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 99 // particular if we're animating the size then the underlying Texture is going | 102 // particular if we're animating the size then the underlying Texture is going |
| 100 // to be unhappy if we try to set a texture on a size bigger than the size of | 103 // to be unhappy if we try to set a texture on a size bigger than the size of |
| 101 // the texture. | 104 // the texture. |
| 102 layer_->SetCanvas(canvas, origin); | 105 layer_->SetCanvas(canvas, origin); |
| 103 } | 106 } |
| 104 | 107 |
| 105 void Window::SetParent(Window* parent) { | 108 void Window::SetParent(Window* parent) { |
| 106 if (parent) | 109 if (parent) |
| 107 parent->AddChild(this); | 110 parent->AddChild(this); |
| 108 else | 111 else |
| 109 Desktop::GetInstance()->window()->AddChild(this); | 112 Desktop::GetInstance()->toplevel_window_container()->AddChild(this); |
| 110 } | 113 } |
| 111 | 114 |
| 112 bool Window::IsTopLevelWindowContainer() const { | 115 bool Window::IsToplevelWindowContainer() const { |
| 113 return false; | 116 return false; |
| 114 } | 117 } |
| 115 | 118 |
| 116 void Window::MoveChildToFront(Window* child) { | 119 void Window::MoveChildToFront(Window* child) { |
| 117 DCHECK_EQ(child->parent(), this); | 120 DCHECK_EQ(child->parent(), this); |
| 118 const Windows::iterator i(std::find(children_.begin(), children_.end(), | 121 const Windows::iterator i(std::find(children_.begin(), children_.end(), |
| 119 child)); | 122 child)); |
| 120 DCHECK(i != children_.end()); | 123 DCHECK(i != children_.end()); |
| 121 children_.erase(i); | 124 children_.erase(i); |
| 122 | 125 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 141 children_.erase(i); | 144 children_.erase(i); |
| 142 } | 145 } |
| 143 | 146 |
| 144 // static | 147 // static |
| 145 void Window::ConvertPointToWindow(Window* source, | 148 void Window::ConvertPointToWindow(Window* source, |
| 146 Window* target, | 149 Window* target, |
| 147 gfx::Point* point) { | 150 gfx::Point* point) { |
| 148 ui::Layer::ConvertPointToLayer(source->layer(), target->layer(), point); | 151 ui::Layer::ConvertPointToLayer(source->layer(), target->layer(), point); |
| 149 } | 152 } |
| 150 | 153 |
| 154 void Window::SetEventFilter(EventFilter* event_filter) { | |
| 155 event_filter_.reset(event_filter); | |
| 156 } | |
| 157 | |
| 151 bool Window::OnMouseEvent(MouseEvent* event) { | 158 bool Window::OnMouseEvent(MouseEvent* event) { |
| 152 if (!window_manager_.get()) | 159 if (!parent_) |
| 153 window_manager_.reset(new WindowManager(this)); | 160 return false; |
| 154 return window_manager_->OnMouseEvent(event) || delegate_->OnMouseEvent(event); | 161 if (!parent_->event_filter_.get()) |
| 162 parent_->SetEventFilter(new EventFilter(parent_)); | |
| 163 return parent_->event_filter_->OnMouseEvent(this, event) || | |
| 164 delegate_->OnMouseEvent(event); | |
| 155 } | 165 } |
| 156 | 166 |
| 157 bool Window::OnKeyEvent(KeyEvent* event) { | 167 bool Window::OnKeyEvent(KeyEvent* event) { |
| 158 return delegate_->OnKeyEvent(event); | 168 return delegate_->OnKeyEvent(event); |
| 159 } | 169 } |
| 160 | 170 |
| 161 bool Window::HitTest(const gfx::Point& point) { | 171 bool Window::HitTest(const gfx::Point& point) { |
| 162 gfx::Rect local_bounds(gfx::Point(), bounds().size()); | 172 gfx::Rect local_bounds(gfx::Point(), bounds().size()); |
| 163 // TODO(beng): hittest masks. | 173 // TODO(beng): hittest masks. |
| 164 return local_bounds.Contains(point); | 174 return local_bounds.Contains(point); |
| 165 } | 175 } |
| 166 | 176 |
| 167 Window* Window::GetEventHandlerForPoint(const gfx::Point& point) { | 177 Window* Window::GetEventHandlerForPoint(const gfx::Point& point) { |
| 168 Windows::const_reverse_iterator i = children_.rbegin(); | 178 Windows::const_reverse_iterator i = children_.rbegin(); |
| 169 for (; i != children_.rend(); ++i) { | 179 for (; i != children_.rend(); ++i) { |
| 170 Window* child = *i; | 180 Window* child = *i; |
| 171 if (child->visibility() == Window::VISIBILITY_HIDDEN) | 181 if (child->visibility() == Window::VISIBILITY_HIDDEN) |
| 172 continue; | 182 continue; |
| 173 gfx::Point point_in_child_coords(point); | 183 gfx::Point point_in_child_coords(point); |
| 174 Window::ConvertPointToWindow(this, child, &point_in_child_coords); | 184 Window::ConvertPointToWindow(this, child, &point_in_child_coords); |
| 175 if (child->HitTest(point_in_child_coords)) | 185 if (child->HitTest(point_in_child_coords)) { |
| 176 return child->GetEventHandlerForPoint(point_in_child_coords); | 186 Window* handler = child->GetEventHandlerForPoint(point_in_child_coords); |
| 187 if (handler) | |
| 188 return handler; | |
| 189 } | |
| 177 } | 190 } |
| 178 return this; | 191 return delegate_ ? this : NULL; |
| 179 } | 192 } |
| 180 | 193 |
| 181 internal::FocusManager* Window::GetFocusManager() { | 194 internal::FocusManager* Window::GetFocusManager() { |
| 182 return parent_ ? parent_->GetFocusManager() : NULL; | 195 return parent_ ? parent_->GetFocusManager() : NULL; |
| 183 } | 196 } |
| 184 | 197 |
| 185 void Window::SchedulePaint() { | 198 void Window::SchedulePaint() { |
| 186 SchedulePaintInRect(gfx::Rect(0, 0, bounds_.width(), bounds_.height())); | 199 SchedulePaintInRect(gfx::Rect(0, 0, bounds_.width(), bounds_.height())); |
| 187 } | 200 } |
| 188 | 201 |
| 189 void Window::OnPaintLayer(gfx::Canvas* canvas) { | 202 void Window::OnPaintLayer(gfx::Canvas* canvas) { |
| 190 if (delegate_) | 203 delegate_->OnPaint(canvas); |
|
oshima
2011/09/20 05:29:28
no delegate means no texture means no paint reques
| |
| 191 delegate_->OnPaint(canvas); | |
| 192 } | 204 } |
| 193 | 205 |
| 194 } // namespace aura | 206 } // namespace aura |
| OLD | NEW |