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

Side by Side Diff: aura/window.cc

Issue 7791030: Proper MouseEvent targeting. Adds a Window method that locates a Window for a given point. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' 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 | « aura/window.h ('k') | 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 "aura/window.h" 5 #include "aura/window.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "aura/desktop.h" 9 #include "aura/desktop.h"
10 #include "aura/window_delegate.h" 10 #include "aura/window_delegate.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "ui/gfx/canvas_skia.h" 12 #include "ui/gfx/canvas_skia.h"
13 #include "ui/gfx/compositor/compositor.h" 13 #include "ui/gfx/compositor/compositor.h"
14 #include "ui/gfx/compositor/layer.h" 14 #include "ui/gfx/compositor/layer.h"
15 15
16 namespace aura { 16 namespace aura {
17 17
18 Window::Window(WindowDelegate* delegate) 18 Window::Window(WindowDelegate* delegate)
19 : delegate_(delegate), 19 : delegate_(delegate),
20 visibility_(VISIBILITY_HIDDEN), 20 visibility_(VISIBILITY_HIDDEN),
21 needs_paint_all_(true), 21 needs_paint_all_(true),
22 parent_(NULL), 22 parent_(NULL),
23 id_(-1) { 23 id_(-1) {
24 } 24 }
25 25
26 Window::~Window() { 26 Window::~Window() {
27 if (delegate_)
28 delegate_->OnWindowDestroyed();
29 if (parent_)
30 parent_->RemoveChild(this);
27 } 31 }
28 32
29 void Window::Init() { 33 void Window::Init() {
30 layer_.reset(new ui::Layer(Desktop::GetInstance()->compositor())); 34 layer_.reset(new ui::Layer(Desktop::GetInstance()->compositor()));
31 } 35 }
32 36
33 void Window::SetVisibility(Visibility visibility) { 37 void Window::SetVisibility(Visibility visibility) {
34 if (visibility_ == visibility) 38 if (visibility_ == visibility)
35 return; 39 return;
36 40
(...skipping 26 matching lines...) Expand all
63 if (parent) 67 if (parent)
64 parent->AddChild(this); 68 parent->AddChild(this);
65 else 69 else
66 Desktop::GetInstance()->window()->AddChild(this); 70 Desktop::GetInstance()->window()->AddChild(this);
67 } 71 }
68 72
69 void Window::DrawTree() { 73 void Window::DrawTree() {
70 UpdateLayerCanvas(); 74 UpdateLayerCanvas();
71 Draw(); 75 Draw();
72 76
73 // First pass updates the layer bitmaps.
74 for (Windows::iterator i = children_.begin(); i != children_.end(); ++i) 77 for (Windows::iterator i = children_.begin(); i != children_.end(); ++i)
75 (*i)->DrawTree(); 78 (*i)->DrawTree();
76 } 79 }
77 80
78 void Window::AddChild(Window* child) { 81 void Window::AddChild(Window* child) {
79 DCHECK(std::find(children_.begin(), children_.end(), child) == 82 DCHECK(std::find(children_.begin(), children_.end(), child) ==
80 children_.end()); 83 children_.end());
81 child->parent_ = this; 84 child->parent_ = this;
82 layer_->Add(child->layer_.get()); 85 layer_->Add(child->layer_.get());
83 children_.push_back(child); 86 children_.push_back(child);
84 } 87 }
85 88
86 void Window::RemoveChild(Window* child) { 89 void Window::RemoveChild(Window* child) {
87 Windows::iterator i = std::find(children_.begin(), children_.end(), child); 90 Windows::iterator i = std::find(children_.begin(), children_.end(), child);
88 DCHECK(i != children_.end()); 91 DCHECK(i != children_.end());
89 child->parent_ = NULL; 92 child->parent_ = NULL;
90 layer_->Remove(child->layer_.get()); 93 layer_->Remove(child->layer_.get());
91 children_.erase(i); 94 children_.erase(i);
92 } 95 }
93 96
97 // static
98 void Window::ConvertPointToWindow(Window* source,
99 Window* target,
100 gfx::Point* point) {
101 ui::Layer::ConvertPointToLayer(source->layer(), target->layer(), point);
102 }
103
94 bool Window::OnMouseEvent(const MouseEvent& event) { 104 bool Window::OnMouseEvent(const MouseEvent& event) {
95 return true; 105 return true;
96 } 106 }
97 107
108 bool Window::HitTest(const gfx::Point& point) {
109 gfx::Rect local_bounds(gfx::Point(), bounds().size());
110 // TODO(beng): hittest masks.
111 return local_bounds.Contains(point);
112 }
113
114 Window* Window::GetEventHandlerForPoint(const gfx::Point& point) {
115 Windows::const_reverse_iterator i = children_.rbegin();
116 for (; i != children_.rend(); ++i) {
117 Window* child = *i;
118 if (child->visibility() == Window::VISIBILITY_HIDDEN)
119 continue;
120 gfx::Point point_in_child_coords(point);
121 Window::ConvertPointToWindow(this, child, &point_in_child_coords);
122 if (child->HitTest(point_in_child_coords))
123 return child->GetEventHandlerForPoint(point_in_child_coords);
124 }
125 return this;
126 }
127
98 void Window::UpdateLayerCanvas() { 128 void Window::UpdateLayerCanvas() {
99 if (needs_paint_all_) { 129 if (needs_paint_all_) {
100 needs_paint_all_ = false; 130 needs_paint_all_ = false;
101 dirty_rect_ = gfx::Rect(0, 0, bounds().width(), bounds().height()); 131 dirty_rect_ = gfx::Rect(0, 0, bounds().width(), bounds().height());
102 } 132 }
103 gfx::Rect dirty_rect = dirty_rect_.Intersect( 133 gfx::Rect dirty_rect = dirty_rect_.Intersect(
104 gfx::Rect(0, 0, bounds().width(), bounds().height())); 134 gfx::Rect(0, 0, bounds().width(), bounds().height()));
105 dirty_rect_.SetRect(0, 0, 0, 0); 135 dirty_rect_.SetRect(0, 0, 0, 0);
106 if (dirty_rect.IsEmpty()) 136 if (dirty_rect.IsEmpty())
107 return; 137 return;
108 if (delegate_) { 138 if (delegate_) {
109 scoped_ptr<gfx::Canvas> canvas(gfx::Canvas::CreateCanvas( 139 scoped_ptr<gfx::Canvas> canvas(gfx::Canvas::CreateCanvas(
110 dirty_rect.width(), dirty_rect.height(), false)); 140 dirty_rect.width(), dirty_rect.height(), false));
111 canvas->TranslateInt(dirty_rect.x(), dirty_rect.y()); 141 canvas->TranslateInt(dirty_rect.x(), dirty_rect.y());
112 delegate_->OnPaint(canvas.get()); 142 delegate_->OnPaint(canvas.get());
113 SetCanvas(*canvas->AsCanvasSkia(), bounds().origin()); 143 SetCanvas(*canvas->AsCanvasSkia(), bounds().origin());
114 } 144 }
115 } 145 }
116 146
117 void Window::Draw() { 147 void Window::Draw() {
118 if (visibility_ != VISIBILITY_HIDDEN) 148 if (visibility_ != VISIBILITY_HIDDEN)
119 layer_->Draw(); 149 layer_->Draw();
120 } 150 }
121 151
122 } // namespace aura 152 } // namespace aura
OLDNEW
« no previous file with comments | « aura/window.h ('k') | aura/window_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698