Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: ui/aura/window.cc

Issue 7976020: Wires up mouse capture code for aura. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix aura build Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/aura/window.h ('k') | ui/aura/window_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/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;
23
22 Window::Window(WindowDelegate* delegate) 24 Window::Window(WindowDelegate* delegate)
23 : delegate_(delegate), 25 : delegate_(delegate),
24 visibility_(VISIBILITY_HIDDEN), 26 visibility_(VISIBILITY_HIDDEN),
25 parent_(NULL), 27 parent_(NULL),
26 id_(-1), 28 id_(-1),
27 user_data_(NULL) { 29 user_data_(NULL) {
28 } 30 }
29 31
30 Window::~Window() { 32 Window::~Window() {
31 // Let the delegate know we're in the processing of destroying. 33 // Let the delegate know we're in the processing of destroying.
32 if (delegate_) 34 if (delegate_)
33 delegate_->OnWindowDestroying(); 35 delegate_->OnWindowDestroying();
34 36
35 // Update the FocusManager in case we were focused. This must be done before 37 // Let the root know so that it can remove any references to us.
36 // we are removed from the hierarchy otherwise we won't be able to find the 38 RootWindow* root = GetRoot();
37 // FocusManager. 39 if (root)
38 internal::FocusManager* focus_manager = GetFocusManager(); 40 root->WindowDestroying(this);
39 if (focus_manager && focus_manager->focused_window() == this)
40 focus_manager->SetFocusedWindow(NULL);
41 41
42 // Then destroy the children. 42 // Then destroy the children.
43 while (!children_.empty()) { 43 while (!children_.empty()) {
44 Window* child = children_[0]; 44 Window* child = children_[0];
45 delete child; 45 delete child;
46 // Deleting the child so remove it from out children_ list. 46 // Deleting the child so remove it from out children_ list.
47 DCHECK(std::find(children_.begin(), children_.end(), child) == 47 DCHECK(std::find(children_.begin(), children_.end(), child) ==
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.
(...skipping 12 matching lines...) Expand all
63 } 63 }
64 64
65 void Window::SetVisibility(Visibility visibility) { 65 void Window::SetVisibility(Visibility visibility) {
66 if (visibility_ == visibility) 66 if (visibility_ == visibility)
67 return; 67 return;
68 68
69 visibility_ = visibility; 69 visibility_ = visibility;
70 layer_->set_visible(visibility_ != VISIBILITY_HIDDEN); 70 layer_->set_visible(visibility_ != VISIBILITY_HIDDEN);
71 if (layer_->visible()) 71 if (layer_->visible())
72 SchedulePaint(); 72 SchedulePaint();
73 if (visibility_ != VISIBILITY_SHOWN)
74 ReleaseCapture();
73 } 75 }
74 76
75 void Window::SetLayoutManager(LayoutManager* layout_manager) { 77 void Window::SetLayoutManager(LayoutManager* layout_manager) {
76 layout_manager_.reset(layout_manager); 78 layout_manager_.reset(layout_manager);
77 } 79 }
78 80
79 void Window::SetBounds(const gfx::Rect& bounds, int anim_ms) { 81 void Window::SetBounds(const gfx::Rect& bounds, int anim_ms) {
80 // TODO: support anim_ms 82 // TODO: support anim_ms
81 // TODO: funnel this through the Desktop. 83 // TODO: funnel this through the Desktop.
82 bool was_move = bounds_.size() == bounds.size(); 84 bool was_move = bounds_.size() == bounds.size();
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 return handler; 194 return handler;
193 } 195 }
194 } 196 }
195 return delegate_ ? this : NULL; 197 return delegate_ ? this : NULL;
196 } 198 }
197 199
198 internal::FocusManager* Window::GetFocusManager() { 200 internal::FocusManager* Window::GetFocusManager() {
199 return parent_ ? parent_->GetFocusManager() : NULL; 201 return parent_ ? parent_->GetFocusManager() : NULL;
200 } 202 }
201 203
204 void Window::SetCapture() {
205 if (visibility_ != VISIBILITY_SHOWN)
206 return;
207
208 RootWindow* root = GetRoot();
209 if (!root)
210 return;
211
212 root->SetCapture(this);
213 }
214
215 void Window::ReleaseCapture() {
216 RootWindow* root = GetRoot();
217 if (!root)
218 return;
219
220 root->ReleaseCapture(this);
221 }
222
223 bool Window::HasCapture() {
224 RootWindow* root = GetRoot();
225 return root && root->capture_window() == this;
226 }
227
228 internal::RootWindow* Window::GetRoot() {
229 return parent_ ? parent_->GetRoot() : NULL;
230 }
231
202 void Window::SchedulePaint() { 232 void Window::SchedulePaint() {
203 SchedulePaintInRect(gfx::Rect(0, 0, bounds_.width(), bounds_.height())); 233 SchedulePaintInRect(gfx::Rect(0, 0, bounds_.width(), bounds_.height()));
204 } 234 }
205 235
206 void Window::OnPaintLayer(gfx::Canvas* canvas) { 236 void Window::OnPaintLayer(gfx::Canvas* canvas) {
207 delegate_->OnPaint(canvas); 237 delegate_->OnPaint(canvas);
208 } 238 }
209 239
210 } // namespace aura 240 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/window.h ('k') | ui/aura/window_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698