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

Side by Side Diff: views/view.cc

Issue 6452011: Rework tree APIs to reflect Google style and more const-correctness.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 10 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
« views/view.h ('K') | « views/view.h ('k') | views/views.gyp » ('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 "views/view.h" 5 #include "views/view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #ifndef NDEBUG
9 #include <iostream>
10 #endif
11 8
12 #include "base/logging.h" 9 #include "base/logging.h"
13 #include "base/message_loop.h" 10 #include "base/message_loop.h"
14 #include "base/scoped_ptr.h" 11 #include "base/scoped_ptr.h"
15 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
16 #include "third_party/skia/include/core/SkShader.h" 13 #include "third_party/skia/include/core/SkShader.h"
17 #include "ui/base/dragdrop/drag_drop_types.h" 14 #include "ui/base/dragdrop/drag_drop_types.h"
18 #include "ui/gfx/canvas_skia.h" 15 #include "ui/gfx/canvas_skia.h"
19 #include "ui/gfx/path.h" 16 #include "ui/gfx/path.h"
20 #include "views/background.h" 17 #include "views/background.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 next_focusable_view_(NULL), 71 next_focusable_view_(NULL),
75 previous_focusable_view_(NULL), 72 previous_focusable_view_(NULL),
76 context_menu_controller_(NULL), 73 context_menu_controller_(NULL),
77 drag_controller_(NULL) { 74 drag_controller_(NULL) {
78 } 75 }
79 76
80 View::~View() { 77 View::~View() {
81 if (parent_) 78 if (parent_)
82 parent_->RemoveChildView(this); 79 parent_->RemoveChildView(this);
83 80
84 int c = static_cast<int>(child_views_.size()); 81 int c = static_cast<int>(children_.size());
sky 2011/02/08 19:11:54 If we're going to use size_t every where, we shoul
85 while (--c >= 0) { 82 while (--c >= 0) {
86 child_views_[c]->SetParent(NULL); 83 children_[c]->SetParent(NULL);
87 if (child_views_[c]->IsParentOwned()) 84 if (children_[c]->IsParentOwned())
88 delete child_views_[c]; 85 delete children_[c];
89 } 86 }
90 87
91 #if defined(OS_WIN) 88 #if defined(OS_WIN)
92 if (view_accessibility_.get()) 89 if (view_accessibility_.get())
93 view_accessibility_->set_view(NULL); 90 view_accessibility_->set_view(NULL);
94 #endif 91 #endif
95 } 92 }
96 93
97 // Tree operations ------------------------------------------------------------- 94 // Tree operations -------------------------------------------------------------
98 95
99 void View::AddChildView(View* v) { 96 const Widget* View::GetWidget() const {
100 AddChildView(static_cast<int>(child_views_.size()), v);
101 }
102
103 void View::AddChildView(int index, View* v) {
104 CHECK(v != this) << "You cannot add a view as its own child";
105
106 // Remove the view from its current parent if any.
107 if (v->GetParent())
108 v->GetParent()->RemoveChildView(v);
109
110 // Sets the prev/next focus views.
111 InitFocusSiblings(v, index);
112
113 // Let's insert the view.
114 child_views_.insert(child_views_.begin() + index, v);
115 v->SetParent(this);
116
117 for (View* p = this; p; p = p->GetParent())
118 p->ViewHierarchyChangedImpl(false, true, this, v);
119
120 v->PropagateAddNotifications(this, v);
121 UpdateTooltip();
122 RootView* root = GetRootView();
123 if (root)
124 RegisterChildrenForVisibleBoundsNotification(root, v);
125
126 if (layout_manager_.get())
127 layout_manager_->ViewAdded(this, v);
128 }
129
130 View* View::GetChildViewAt(int index) const {
131 return index < GetChildViewCount() ? child_views_[index] : NULL;
132 }
133
134 void View::RemoveChildView(View* a_view) {
135 DoRemoveChildView(a_view, true, true, false);
136 }
137
138 void View::RemoveAllChildViews(bool delete_views) {
139 ViewList::iterator iter;
140 while ((iter = child_views_.begin()) != child_views_.end()) {
141 DoRemoveChildView(*iter, false, false, delete_views);
142 }
143 UpdateTooltip();
144 }
145
146 int View::GetChildViewCount() const {
147 return static_cast<int>(child_views_.size());
148 }
149
150 bool View::HasChildView(View* a_view) {
151 return find(child_views_.begin(),
152 child_views_.end(),
153 a_view) != child_views_.end();
154 }
155
156 Widget* View::GetWidget() const {
157 // The root view holds a reference to this view hierarchy's Widget. 97 // The root view holds a reference to this view hierarchy's Widget.
158 return parent_ ? parent_->GetWidget() : NULL; 98 return parent_ ? parent_->GetWidget() : NULL;
159 } 99 }
160 100
161 Window* View::GetWindow() const { 101 Widget* View::GetWidget() {
162 Widget* widget = GetWidget(); 102 return const_cast<Widget*>(const_cast<const View*>(this)->GetWidget());
103 }
104
105 void View::AddChildView(View* view) {
106 AddChildViewAt(view, child_count());
107 }
108
109 void View::AddChildViewAt(View* view, size_t index) {
110 CHECK(view != this) << "You cannot add a view as its own child";
111
112 // Remove the view from its current parent if any.
113 if (view->parent())
114 view->parent()->RemoveChildView(view);
115
116 // Sets the prev/next focus views.
117 InitFocusSiblings(view, index);
118
119 // Let's insert the view.
120 children_.insert(children_.begin() + index, view);
121 view->SetParent(this);
122
123 for (View* p = this; p; p = p->parent())
124 p->ViewHierarchyChangedImpl(false, true, this, view);
125
126 view->PropagateAddNotifications(this, view);
127 UpdateTooltip();
128 RootView* root = GetRootView();
129 if (root)
130 RegisterChildrenForVisibleBoundsNotification(root, view);
131
132 if (layout_manager_.get())
133 layout_manager_->ViewAdded(this, view);
134 }
135
136 void View::RemoveChildView(View* view) {
137 DoRemoveChildView(view, true, true, false);
138 }
139
140 void View::RemoveAllChildViews(bool delete_views) {
141 ViewVector::iterator iter;
142 while ((iter = children_.begin()) != children_.end())
143 DoRemoveChildView(*iter, false, false, delete_views);
144 UpdateTooltip();
145 }
146
147 const View* View::GetChildViewAt(size_t index) const {
148 return index < child_count() ? children_[index] : NULL;
149 }
150
151 View* View::GetChildViewAt(size_t index) {
152 return
153 const_cast<View*>(const_cast<const View*>(this)->GetChildViewAt(index));
154 }
155
156 bool View::Contains(const View* view) const {
157 const View* child = view;
158 while (child) {
159 if (child == this)
160 return true;
161 child = child->parent();
162 }
163 return false;
164 }
165
166 size_t View::GetIndexOf(const View* view) const {
167 ViewVector::const_iterator it = std::find(children_.begin(), children_.end(),
168 view);
169 return it != children_.end() ? it - children_.begin() : -1;
170 }
171
172 // TODO(beng): remove
173 const Window* View::GetWindow() const {
174 const Widget* widget = GetWidget();
163 return widget ? widget->GetWindow() : NULL; 175 return widget ? widget->GetWindow() : NULL;
164 } 176 }
165 177
178 // TODO(beng): remove
179 Window* View::GetWindow() {
180 return const_cast<Window*>(const_cast<const View*>(this)->GetWindow());
181 }
182
183 // TODO(beng): remove
166 bool View::ContainsNativeView(gfx::NativeView native_view) const { 184 bool View::ContainsNativeView(gfx::NativeView native_view) const {
167 for (int i = 0, count = GetChildViewCount(); i < count; ++i) { 185 for (int i = 0, count = child_count(); i < count; ++i) {
168 if (GetChildViewAt(i)->ContainsNativeView(native_view)) 186 if (GetChildViewAt(i)->ContainsNativeView(native_view))
169 return true; 187 return true;
170 } 188 }
171 return false; 189 return false;
172 } 190 }
173 191
174 // Get the containing RootView 192 // TODO(beng): remove
175 RootView* View::GetRootView() { 193 RootView* View::GetRootView() {
176 Widget* widget = GetWidget(); 194 Widget* widget = GetWidget();
177 return widget ? widget->GetRootView() : NULL; 195 return widget ? widget->GetRootView() : NULL;
178 } 196 }
179 197
180 int View::GetChildIndex(const View* v) const {
181 for (int i = 0, count = GetChildViewCount(); i < count; i++) {
182 if (v == GetChildViewAt(i))
183 return i;
184 }
185 return -1;
186 }
187
188 bool View::IsParentOf(View* v) const {
189 DCHECK(v);
190 View* parent = v->GetParent();
191 while (parent) {
192 if (this == parent)
193 return true;
194 parent = parent->GetParent();
195 }
196 return false;
197 }
198
199 #ifndef NDEBUG 198 #ifndef NDEBUG
sky 2011/02/08 19:11:54 Nuke this.
200 void View::PrintViewHierarchy() {
201 PrintViewHierarchyImp(0);
202 }
203
204 void View::PrintFocusHierarchy() {
205 PrintFocusHierarchyImp(0);
206 }
207 #endif 199 #endif
208 200
209 // Size and disposition -------------------------------------------------------- 201 // Size and disposition --------------------------------------------------------
210 202
211 void View::SetBounds(int x, int y, int width, int height) { 203 void View::SetBounds(int x, int y, int width, int height) {
212 SetBoundsRect(gfx::Rect(x, y, std::max(0, width), std::max(0, height))); 204 SetBoundsRect(gfx::Rect(x, y, std::max(0, width), std::max(0, height)));
213 } 205 }
214 206
215 void View::SetBoundsRect(const gfx::Rect& bounds) { 207 void View::SetBoundsRect(const gfx::Rect& bounds) {
216 if (bounds == bounds_) { 208 if (bounds == bounds_) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 return gfx::Rect(); 274 return gfx::Rect();
283 gfx::Rect vis_bounds(0, 0, width(), height()); 275 gfx::Rect vis_bounds(0, 0, width(), height());
284 gfx::Rect ancestor_bounds; 276 gfx::Rect ancestor_bounds;
285 View* view = this; 277 View* view = this;
286 int root_x = 0; 278 int root_x = 0;
287 int root_y = 0; 279 int root_y = 0;
288 while (view != NULL && !vis_bounds.IsEmpty()) { 280 while (view != NULL && !vis_bounds.IsEmpty()) {
289 root_x += view->GetMirroredX(); 281 root_x += view->GetMirroredX();
290 root_y += view->y(); 282 root_y += view->y();
291 vis_bounds.Offset(view->GetMirroredX(), view->y()); 283 vis_bounds.Offset(view->GetMirroredX(), view->y());
292 View* ancestor = view->GetParent(); 284 View* ancestor = view->parent();
293 if (ancestor != NULL) { 285 if (ancestor != NULL) {
294 ancestor_bounds.SetRect(0, 0, ancestor->width(), 286 ancestor_bounds.SetRect(0, 0, ancestor->width(),
295 ancestor->height()); 287 ancestor->height());
296 vis_bounds = vis_bounds.Intersect(ancestor_bounds); 288 vis_bounds = vis_bounds.Intersect(ancestor_bounds);
297 } else if (!view->GetWidget()) { 289 } else if (!view->GetWidget()) {
298 // If the view has no Widget, we're not visible. Return an empty rect. 290 // If the view has no Widget, we're not visible. Return an empty rect.
299 return gfx::Rect(); 291 return gfx::Rect();
300 } 292 }
301 view = ancestor; 293 view = ancestor;
302 } 294 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 333
342 void View::SetVisible(bool flag) { 334 void View::SetVisible(bool flag) {
343 if (flag != is_visible_) { 335 if (flag != is_visible_) {
344 // If the tab is currently visible, schedule paint to 336 // If the tab is currently visible, schedule paint to
345 // refresh parent 337 // refresh parent
346 if (IsVisible()) 338 if (IsVisible())
347 SchedulePaint(); 339 SchedulePaint();
348 340
349 is_visible_ = flag; 341 is_visible_ = flag;
350 342
351 // This notifies all subviews recursively. 343 // This notifies all sub-views recursively.
352 PropagateVisibilityNotifications(this, flag); 344 PropagateVisibilityNotifications(this, flag);
353 345
354 // If we are newly visible, schedule paint. 346 // If we are newly visible, schedule paint.
355 if (IsVisible()) 347 if (IsVisible())
356 SchedulePaint(); 348 SchedulePaint();
357 } 349 }
358 } 350 }
359 351
360 bool View::IsVisibleInRootView() const { 352 bool View::IsVisibleInRootView() const {
361 View* parent = GetParent(); 353 return IsVisible() && parent() ? parent()->IsVisibleInRootView() : false;
362 if (IsVisible() && parent)
363 return parent->IsVisibleInRootView();
364 else
365 return false;
366 } 354 }
367 355
368 void View::SetEnabled(bool state) { 356 void View::SetEnabled(bool state) {
369 if (enabled_ != state) { 357 if (enabled_ != state) {
370 enabled_ = state; 358 enabled_ = state;
371 SchedulePaint(); 359 SchedulePaint();
372 } 360 }
373 } 361 }
374 362
375 bool View::IsEnabled() const { 363 bool View::IsEnabled() const {
376 return enabled_; 364 return enabled_;
377 } 365 }
378 366
379 // RTL positioning ------------------------------------------------------------- 367 // RTL positioning -------------------------------------------------------------
380 368
381 gfx::Rect View::GetMirroredBounds() const { 369 gfx::Rect View::GetMirroredBounds() const {
382 gfx::Rect bounds(bounds_); 370 gfx::Rect bounds(bounds_);
383 bounds.set_x(GetMirroredX()); 371 bounds.set_x(GetMirroredX());
384 return bounds; 372 return bounds;
385 } 373 }
386 374
387 gfx::Point View::GetMirroredPosition() const { 375 gfx::Point View::GetMirroredPosition() const {
388 return gfx::Point(GetMirroredX(), y()); 376 return gfx::Point(GetMirroredX(), y());
389 } 377 }
390 378
391 int View::GetMirroredX() const { 379 int View::GetMirroredX() const {
392 View* parent = GetParent(); 380 return parent() ? parent()->GetMirroredXForRect(bounds_) : x();
393 return parent ? parent->GetMirroredXForRect(bounds_) : x();
394 } 381 }
395 382
396 int View::GetMirroredXForRect(const gfx::Rect& bounds) const { 383 int View::GetMirroredXForRect(const gfx::Rect& bounds) const {
397 return base::i18n::IsRTL() ? 384 return base::i18n::IsRTL() ?
398 (width() - bounds.x() - bounds.width()) : bounds.x(); 385 (width() - bounds.x() - bounds.width()) : bounds.x();
399 } 386 }
400 387
401 int View::GetMirroredXInView(int x) const { 388 int View::GetMirroredXInView(int x) const {
402 return base::i18n::IsRTL() ? width() - x : x; 389 return base::i18n::IsRTL() ? width() - x : x;
403 } 390 }
(...skipping 12 matching lines...) Expand all
416 layout_manager_->Layout(this); 403 layout_manager_->Layout(this);
417 SchedulePaint(); 404 SchedulePaint();
418 } 405 }
419 406
420 // Make sure to propagate the Layout() call to any children that haven't 407 // Make sure to propagate the Layout() call to any children that haven't
421 // received it yet through the layout manager and need to be laid out. This 408 // received it yet through the layout manager and need to be laid out. This
422 // is needed for the case when the child requires a layout but its bounds 409 // is needed for the case when the child requires a layout but its bounds
423 // weren't changed by the layout manager. If there is no layout manager, we 410 // weren't changed by the layout manager. If there is no layout manager, we
424 // just propagate the Layout() call down the hierarchy, so whoever receives 411 // just propagate the Layout() call down the hierarchy, so whoever receives
425 // the call can take appropriate action. 412 // the call can take appropriate action.
426 for (int i = 0, count = GetChildViewCount(); i < count; ++i) { 413 for (int i = 0, count = child_count(); i < count; ++i) {
427 View* child = GetChildViewAt(i); 414 View* child = GetChildViewAt(i);
428 if (child->needs_layout_ || !layout_manager_.get()) { 415 if (child->needs_layout_ || !layout_manager_.get()) {
429 child->needs_layout_ = false; 416 child->needs_layout_ = false;
430 child->Layout(); 417 child->Layout();
431 } 418 }
432 } 419 }
433 } 420 }
434 421
435 void View::InvalidateLayout() { 422 void View::InvalidateLayout() {
436 // Always invalidate up. This is needed to handle the case of us already being 423 // Always invalidate up. This is needed to handle the case of us already being
(...skipping 16 matching lines...) Expand all
453 layout_manager_->Installed(this); 440 layout_manager_->Installed(this);
454 } 441 }
455 442
456 // Attributes ------------------------------------------------------------------ 443 // Attributes ------------------------------------------------------------------
457 444
458 std::string View::GetClassName() const { 445 std::string View::GetClassName() const {
459 return kViewClassName; 446 return kViewClassName;
460 } 447 }
461 448
462 View* View::GetAncestorWithClassName(const std::string& name) { 449 View* View::GetAncestorWithClassName(const std::string& name) {
463 for (View* view = this; view; view = view->GetParent()) { 450 for (View* view = this; view; view = view->parent()) {
464 if (view->GetClassName() == name) 451 if (view->GetClassName() == name)
465 return view; 452 return view;
466 } 453 }
467 return NULL; 454 return NULL;
468 } 455 }
469 456
470 View* View::GetViewByID(int id) const { 457 const View* View::GetViewByID(int id) const {
471 if (id == id_) 458 if (id == id_)
472 return const_cast<View*>(this); 459 return const_cast<View*>(this);
473 460
474 for (int i = 0, count = GetChildViewCount(); i < count; ++i) { 461 for (int i = 0, count = child_count(); i < count; ++i) {
475 View* child = GetChildViewAt(i); 462 const View* view = GetChildViewAt(i)->GetViewByID(id);
476 View* view = child->GetViewByID(id);
477 if (view) 463 if (view)
478 return view; 464 return view;
479 } 465 }
480 return NULL; 466 return NULL;
481 } 467 }
482 468
469 View* View::GetViewByID(int id) {
470 return const_cast<View*>(const_cast<const View*>(this)->GetViewByID(id));
471 }
472
483 void View::SetID(int id) { 473 void View::SetID(int id) {
484 id_ = id; 474 id_ = id;
485 } 475 }
486 476
487 int View::GetID() const { 477 int View::GetID() const {
488 return id_; 478 return id_;
489 } 479 }
490 480
491 void View::SetGroup(int gid) { 481 void View::SetGroup(int gid) {
492 // Don't change the group id once it's set. 482 // Don't change the group id once it's set.
493 DCHECK(group_ == -1 || group_ == gid); 483 DCHECK(group_ == -1 || group_ == gid);
494 group_ = gid; 484 group_ = gid;
495 } 485 }
496 486
497 int View::GetGroup() const { 487 int View::GetGroup() const {
498 return group_; 488 return group_;
499 } 489 }
500 490
501 void View::GetViewsWithGroup(int group_id, std::vector<View*>* out) { 491 void View::GetViewsWithGroup(int group_id, std::vector<View*>* out) {
502 if (group_ == group_id) 492 if (group_ == group_id)
503 out->push_back(this); 493 out->push_back(this);
504 494
505 for (int i = 0, count = GetChildViewCount(); i < count; ++i) 495 for (int i = 0, count = child_count(); i < count; ++i)
506 GetChildViewAt(i)->GetViewsWithGroup(group_id, out); 496 GetChildViewAt(i)->GetViewsWithGroup(group_id, out);
507 } 497 }
508 498
509 View* View::GetSelectedViewForGroup(int group_id) { 499 View* View::GetSelectedViewForGroup(int group_id) {
510 std::vector<View*> views; 500 std::vector<View*> views;
511 GetRootView()->GetViewsWithGroup(group_id, &views); 501 GetRootView()->GetViewsWithGroup(group_id, &views);
512 if (views.size() > 0) 502 if (views.size() > 0)
513 return views[0]; 503 return views[0];
514 else 504 else
515 return NULL; 505 return NULL;
516 } 506 }
517 507
518 // Coordinate conversion ------------------------------------------------------- 508 // Coordinate conversion -------------------------------------------------------
519 509
520 // static 510 // static
521 void View::ConvertPointToView(const View* src, 511 void View::ConvertPointToView(const View* src,
522 const View* dst, 512 const View* dst,
523 gfx::Point* point) { 513 gfx::Point* point) {
524 ConvertPointToView(src, dst, point, true); 514 ConvertPointToView(src, dst, point, true);
525 } 515 }
526 516
527 // static 517 // static
528 void View::ConvertPointToWidget(const View* src, gfx::Point* p) { 518 void View::ConvertPointToWidget(const View* src, gfx::Point* p) {
529 DCHECK(src); 519 DCHECK(src);
530 DCHECK(p); 520 DCHECK(p);
531 521
532 gfx::Point offset; 522 gfx::Point offset;
533 for (const View* v = src; v; v = v->GetParent()) { 523 for (const View* v = src; v; v = v->parent()) {
534 offset.set_x(offset.x() + v->GetMirroredX()); 524 offset.set_x(offset.x() + v->GetMirroredX());
535 offset.set_y(offset.y() + v->y()); 525 offset.set_y(offset.y() + v->y());
536 } 526 }
537 p->SetPoint(p->x() + offset.x(), p->y() + offset.y()); 527 p->SetPoint(p->x() + offset.x(), p->y() + offset.y());
538 } 528 }
539 529
540 // static 530 // static
541 void View::ConvertPointFromWidget(const View* dest, gfx::Point* p) { 531 void View::ConvertPointFromWidget(const View* dest, gfx::Point* p) {
542 gfx::Point t; 532 gfx::Point t;
543 ConvertPointToWidget(dest, &t); 533 ConvertPointToWidget(dest, &t);
544 p->SetPoint(p->x() - t.x(), p->y() - t.y()); 534 p->SetPoint(p->x() - t.x(), p->y() - t.y());
545 } 535 }
546 536
547 // static 537 // static
548 void View::ConvertPointToScreen(const View* src, gfx::Point* p) { 538 void View::ConvertPointToScreen(const View* src, gfx::Point* p) {
549 DCHECK(src); 539 DCHECK(src);
550 DCHECK(p); 540 DCHECK(p);
551 541
552 // If the view is not connected to a tree, there's nothing we can do. 542 // If the view is not connected to a tree, there's nothing we can do.
553 Widget* widget = src->GetWidget(); 543 const Widget* widget = src->GetWidget();
554 if (widget) { 544 if (widget) {
555 ConvertPointToWidget(src, p); 545 ConvertPointToWidget(src, p);
556 gfx::Rect r; 546 gfx::Rect r;
557 widget->GetBounds(&r, false); 547 widget->GetBounds(&r, false);
558 p->SetPoint(p->x() + r.x(), p->y() + r.y()); 548 p->SetPoint(p->x() + r.x(), p->y() + r.y());
559 } 549 }
560 } 550 }
561 551
562 // Painting -------------------------------------------------------------------- 552 // Painting --------------------------------------------------------------------
563 553
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 586
597 void View::PaintFocusBorder(gfx::Canvas* canvas) { 587 void View::PaintFocusBorder(gfx::Canvas* canvas) {
598 if (HasFocus() && (IsFocusable() || IsAccessibilityFocusableInRootView())) 588 if (HasFocus() && (IsFocusable() || IsAccessibilityFocusableInRootView()))
599 canvas->DrawFocusRect(0, 0, width(), height()); 589 canvas->DrawFocusRect(0, 0, width(), height());
600 } 590 }
601 591
602 void View::PaintNow() { 592 void View::PaintNow() {
603 if (!IsVisible()) 593 if (!IsVisible())
604 return; 594 return;
605 595
606 View* view = GetParent(); 596 if (parent())
607 if (view) 597 parent()->PaintNow();
608 view->PaintNow();
609 } 598 }
610 599
611 void View::ProcessPaint(gfx::Canvas* canvas) { 600 void View::ProcessPaint(gfx::Canvas* canvas) {
612 if (!IsVisible()) 601 if (!IsVisible())
613 return; 602 return;
614 603
615 // We're going to modify the canvas, save it's state first. 604 // We're going to modify the canvas, save it's state first.
616 canvas->Save(); 605 canvas->Save();
617 606
618 // Paint this View and its children, setting the clip rect to the bounds 607 // Paint this View and its children, setting the clip rect to the bounds
(...skipping 24 matching lines...) Expand all
643 canvas->Restore(); 632 canvas->Restore();
644 633
645 PaintChildren(canvas); 634 PaintChildren(canvas);
646 } 635 }
647 636
648 // Restore the canvas's original transform. 637 // Restore the canvas's original transform.
649 canvas->Restore(); 638 canvas->Restore();
650 } 639 }
651 640
652 void View::PaintChildren(gfx::Canvas* canvas) { 641 void View::PaintChildren(gfx::Canvas* canvas) {
653 for (int i = 0, count = GetChildViewCount(); i < count; ++i) { 642 for (int i = 0, count = child_count(); i < count; ++i) {
654 View* child = GetChildViewAt(i); 643 View* child = GetChildViewAt(i);
655 if (!child) { 644 if (!child) {
656 NOTREACHED() << "Should not have a NULL child View for index in bounds"; 645 NOTREACHED() << "Should not have a NULL child View for index in bounds";
657 continue; 646 continue;
658 } 647 }
659 child->ProcessPaint(canvas); 648 child->ProcessPaint(canvas);
660 } 649 }
661 } 650 }
662 651
663 ThemeProvider* View::GetThemeProvider() const { 652 ThemeProvider* View::GetThemeProvider() const {
664 Widget* widget = GetWidget(); 653 const Widget* widget = GetWidget();
665 return widget ? widget->GetThemeProvider() : NULL; 654 return widget ? widget->GetThemeProvider() : NULL;
666 } 655 }
667 656
668 // Input ----------------------------------------------------------------------- 657 // Input -----------------------------------------------------------------------
669 658
670 View* View::GetViewForPoint(const gfx::Point& point) { 659 View* View::GetViewForPoint(const gfx::Point& point) {
671 // Walk the child Views recursively looking for the View that most 660 // Walk the child Views recursively looking for the View that most
672 // tightly encloses the specified point. 661 // tightly encloses the specified point.
673 for (int i = GetChildViewCount() - 1; i >= 0; --i) { 662 for (int i = child_count() - 1; i >= 0; --i) {
sky 2011/02/08 19:11:54 Don't you need a static_cast? And again, we should
674 View* child = GetChildViewAt(i); 663 View* child = GetChildViewAt(i);
675 if (!child->IsVisible()) 664 if (!child->IsVisible())
676 continue; 665 continue;
677 666
678 gfx::Point point_in_child_coords(point); 667 gfx::Point point_in_child_coords(point);
679 View::ConvertPointToView(this, child, &point_in_child_coords); 668 View::ConvertPointToView(this, child, &point_in_child_coords);
680 if (child->HitTest(point_in_child_coords)) 669 if (child->HitTest(point_in_child_coords))
681 return child->GetViewForPoint(point_in_child_coords); 670 return child->GetViewForPoint(point_in_child_coords);
682 } 671 }
683 return this; 672 return this;
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 FocusManager* focus_manager = GetFocusManager(); 801 FocusManager* focus_manager = GetFocusManager();
813 if (focus_manager) 802 if (focus_manager)
814 return focus_manager->GetFocusedView() == this; 803 return focus_manager->GetFocusedView() == this;
815 return false; 804 return false;
816 } 805 }
817 806
818 View* View::GetNextFocusableView() { 807 View* View::GetNextFocusableView() {
819 return next_focusable_view_; 808 return next_focusable_view_;
820 } 809 }
821 810
811 const View* View::GetNextFocusableView() const {
812 return next_focusable_view_;
813 }
814
822 View* View::GetPreviousFocusableView() { 815 View* View::GetPreviousFocusableView() {
823 return previous_focusable_view_; 816 return previous_focusable_view_;
824 } 817 }
825 818
826 void View::SetNextFocusableView(View* view) { 819 void View::SetNextFocusableView(View* view) {
827 view->previous_focusable_view_ = this; 820 view->previous_focusable_view_ = this;
828 next_focusable_view_ = view; 821 next_focusable_view_ = view;
829 } 822 }
830 823
831 void View::SetFocusable(bool focusable) { 824 void View::SetFocusable(bool focusable) {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 return AccessibilityTypes::ROLE_CLIENT; 941 return AccessibilityTypes::ROLE_CLIENT;
949 } 942 }
950 943
951 void View::SetAccessibleName(const string16& name) { 944 void View::SetAccessibleName(const string16& name) {
952 accessible_name_ = name; 945 accessible_name_ = name;
953 } 946 }
954 947
955 // Scrolling ------------------------------------------------------------------- 948 // Scrolling -------------------------------------------------------------------
956 949
957 void View::ScrollRectToVisible(const gfx::Rect& rect) { 950 void View::ScrollRectToVisible(const gfx::Rect& rect) {
958 View* parent = GetParent();
959
960 // We must take RTL UI mirroring into account when adjusting the position of 951 // We must take RTL UI mirroring into account when adjusting the position of
961 // the region. 952 // the region.
962 if (parent) { 953 if (parent()) {
963 gfx::Rect scroll_rect(rect); 954 gfx::Rect scroll_rect(rect);
964 scroll_rect.Offset(GetMirroredX(), y()); 955 scroll_rect.Offset(GetMirroredX(), y());
965 parent->ScrollRectToVisible(scroll_rect); 956 parent()->ScrollRectToVisible(scroll_rect);
966 } 957 }
967 } 958 }
968 959
969 int View::GetPageScrollIncrement(ScrollView* scroll_view, 960 int View::GetPageScrollIncrement(ScrollView* scroll_view,
970 bool is_horizontal, bool is_positive) { 961 bool is_horizontal, bool is_positive) {
971 return 0; 962 return 0;
972 } 963 }
973 964
974 int View::GetLineScrollIncrement(ScrollView* scroll_view, 965 int View::GetLineScrollIncrement(ScrollView* scroll_view,
975 bool is_horizontal, bool is_positive) { 966 bool is_horizontal, bool is_positive) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 RegisterPendingAccelerators(); 1018 RegisterPendingAccelerators();
1028 accelerator_registration_delayed_ = false; 1019 accelerator_registration_delayed_ = false;
1029 } 1020 }
1030 } 1021 }
1031 } 1022 }
1032 1023
1033 // Painting -------------------------------------------------------------------- 1024 // Painting --------------------------------------------------------------------
1034 1025
1035 #ifndef NDEBUG 1026 #ifndef NDEBUG
1036 bool View::IsProcessingPaint() const { 1027 bool View::IsProcessingPaint() const {
1037 return GetParent() && GetParent()->IsProcessingPaint(); 1028 return parent() && parent()->IsProcessingPaint();
1038 } 1029 }
1039 #endif 1030 #endif
1040 1031
1041 // Input ----------------------------------------------------------------------- 1032 // Input -----------------------------------------------------------------------
1042 1033
1043 bool View::HasHitTestMask() const { 1034 bool View::HasHitTestMask() const {
1044 return false; 1035 return false;
1045 } 1036 }
1046 1037
1047 void View::GetHitTestMask(gfx::Path* mask) const { 1038 void View::GetHitTestMask(gfx::Path* mask) const {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1114 start_pt = gfx::Point(); 1105 start_pt = gfx::Point();
1115 } 1106 }
1116 1107
1117 void View::DragInfo::PossibleDrag(const gfx::Point& p) { 1108 void View::DragInfo::PossibleDrag(const gfx::Point& p) {
1118 possible_drag = true; 1109 possible_drag = true;
1119 start_pt = p; 1110 start_pt = p;
1120 } 1111 }
1121 1112
1122 // Tree operations ------------------------------------------------------------- 1113 // Tree operations -------------------------------------------------------------
1123 1114
1124 void View::DoRemoveChildView(View* a_view, 1115 void View::DoRemoveChildView(View* view,
1125 bool update_focus_cycle, 1116 bool update_focus_cycle,
1126 bool update_tool_tip, 1117 bool update_tool_tip,
1127 bool delete_removed_view) { 1118 bool delete_removed_view) {
1128 #ifndef NDEBUG 1119 #ifndef NDEBUG
1129 DCHECK(!IsProcessingPaint()) << "Should not be removing a child view " << 1120 DCHECK(!IsProcessingPaint()) << "Should not be removing a child view " <<
1130 "during a paint, this will seriously " << 1121 "during a paint, this will seriously " <<
1131 "mess things up!"; 1122 "mess things up!";
1132 #endif 1123 #endif
1133 DCHECK(a_view); 1124 DCHECK(view);
1134 const ViewList::iterator i = find(child_views_.begin(), 1125 const ViewVector::iterator i = find(children_.begin(), children_.end(), view);
1135 child_views_.end(),
1136 a_view);
1137 scoped_ptr<View> view_to_be_deleted; 1126 scoped_ptr<View> view_to_be_deleted;
1138 if (i != child_views_.end()) { 1127 if (i != children_.end()) {
1139 if (update_focus_cycle) { 1128 if (update_focus_cycle) {
1140 // Let's remove the view from the focus traversal. 1129 // Let's remove the view from the focus traversal.
1141 View* next_focusable = a_view->next_focusable_view_; 1130 View* next_focusable = view->next_focusable_view_;
1142 View* prev_focusable = a_view->previous_focusable_view_; 1131 View* prev_focusable = view->previous_focusable_view_;
1143 if (prev_focusable) 1132 if (prev_focusable)
1144 prev_focusable->next_focusable_view_ = next_focusable; 1133 prev_focusable->next_focusable_view_ = next_focusable;
1145 if (next_focusable) 1134 if (next_focusable)
1146 next_focusable->previous_focusable_view_ = prev_focusable; 1135 next_focusable->previous_focusable_view_ = prev_focusable;
1147 } 1136 }
1148 1137
1149 RootView* root = GetRootView(); 1138 RootView* root = GetRootView();
1150 if (root) 1139 if (root)
1151 UnregisterChildrenForVisibleBoundsNotification(root, a_view); 1140 UnregisterChildrenForVisibleBoundsNotification(root, view);
1152 a_view->PropagateRemoveNotifications(this); 1141 view->PropagateRemoveNotifications(this);
1153 a_view->SetParent(NULL); 1142 view->SetParent(NULL);
1154 1143
1155 if (delete_removed_view && a_view->IsParentOwned()) 1144 if (delete_removed_view && view->IsParentOwned())
1156 view_to_be_deleted.reset(a_view); 1145 view_to_be_deleted.reset(view);
1157 1146
1158 child_views_.erase(i); 1147 children_.erase(i);
1159 } 1148 }
1160 1149
1161 if (update_tool_tip) 1150 if (update_tool_tip)
1162 UpdateTooltip(); 1151 UpdateTooltip();
1163 1152
1164 if (layout_manager_.get()) 1153 if (layout_manager_.get())
1165 layout_manager_->ViewRemoved(this, a_view); 1154 layout_manager_->ViewRemoved(this, view);
1166 } 1155 }
1167 1156
1168 void View::SetParent(View* parent) { 1157 void View::SetParent(View* parent) {
1169 if (parent != parent_) 1158 if (parent != parent_)
1170 parent_ = parent; 1159 parent_ = parent;
1171 } 1160 }
1172 1161
1173 void View::PropagateRemoveNotifications(View* parent) { 1162 void View::PropagateRemoveNotifications(View* parent) {
1174 for (int i = 0, count = GetChildViewCount(); i < count; ++i) 1163 for (int i = 0, count = child_count(); i < count; ++i)
sky 2011/02/08 19:11:54 size_t
1175 GetChildViewAt(i)->PropagateRemoveNotifications(parent); 1164 GetChildViewAt(i)->PropagateRemoveNotifications(parent);
1176 1165
1177 for (View* v = this; v; v = v->GetParent()) 1166 for (View* v = this; v; v = v->parent())
1178 v->ViewHierarchyChangedImpl(true, false, parent, this); 1167 v->ViewHierarchyChangedImpl(true, false, parent, this);
1179 } 1168 }
1180 1169
1181 void View::PropagateAddNotifications(View* parent, View* child) { 1170 void View::PropagateAddNotifications(View* parent, View* child) {
1182 for (int i = 0, count = GetChildViewCount(); i < count; ++i) 1171 for (int i = 0, count = child_count(); i < count; ++i)
sky 2011/02/08 19:11:54 size_t
1183 GetChildViewAt(i)->PropagateAddNotifications(parent, child); 1172 GetChildViewAt(i)->PropagateAddNotifications(parent, child);
1184 ViewHierarchyChangedImpl(true, true, parent, child); 1173 ViewHierarchyChangedImpl(true, true, parent, child);
1185 } 1174 }
1186 1175
1187 void View::PropagateNativeViewHierarchyChanged(bool attached, 1176 void View::PropagateNativeViewHierarchyChanged(bool attached,
1188 gfx::NativeView native_view, 1177 gfx::NativeView native_view,
1189 RootView* root_view) { 1178 RootView* root_view) {
1190 for (int i = 0, count = GetChildViewCount(); i < count; ++i) 1179 for (int i = 0, count = child_count(); i < count; ++i)
sky 2011/02/08 19:11:54 size_t
1191 GetChildViewAt(i)->PropagateNativeViewHierarchyChanged(attached, 1180 GetChildViewAt(i)->PropagateNativeViewHierarchyChanged(attached,
1192 native_view, 1181 native_view,
1193 root_view); 1182 root_view);
1194 NativeViewHierarchyChanged(attached, native_view, root_view); 1183 NativeViewHierarchyChanged(attached, native_view, root_view);
1195 } 1184 }
1196 1185
1197 void View::ViewHierarchyChangedImpl(bool register_accelerators, 1186 void View::ViewHierarchyChangedImpl(bool register_accelerators,
1198 bool is_add, 1187 bool is_add,
1199 View* parent, 1188 View* parent,
1200 View* child) { 1189 View* child) {
(...skipping 11 matching lines...) Expand all
1212 } else { 1201 } else {
1213 if (child == this) 1202 if (child == this)
1214 UnregisterAccelerators(true); 1203 UnregisterAccelerators(true);
1215 } 1204 }
1216 } 1205 }
1217 1206
1218 ViewHierarchyChanged(is_add, parent, child); 1207 ViewHierarchyChanged(is_add, parent, child);
1219 parent->needs_layout_ = true; 1208 parent->needs_layout_ = true;
1220 } 1209 }
1221 1210
1222 #ifndef NDEBUG
1223 void View::PrintViewHierarchyImp(int indent) {
1224 std::wostringstream buf;
1225 int ind = indent;
1226 while (ind-- > 0)
1227 buf << L' ';
1228 buf << UTF8ToWide(GetClassName());
1229 buf << L' ';
1230 buf << GetID();
1231 buf << L' ';
1232 buf << bounds_.x() << L"," << bounds_.y() << L",";
1233 buf << bounds_.right() << L"," << bounds_.bottom();
1234 buf << L' ';
1235 buf << this;
1236
1237 VLOG(1) << buf.str();
1238 std::cout << buf.str() << std::endl;
1239
1240 for (int i = 0, count = GetChildViewCount(); i < count; ++i)
1241 GetChildViewAt(i)->PrintViewHierarchyImp(indent + 2);
1242 }
1243
1244 void View::PrintFocusHierarchyImp(int indent) {
1245 std::wostringstream buf;
1246 int ind = indent;
1247 while (ind-- > 0)
1248 buf << L' ';
1249 buf << UTF8ToWide(GetClassName());
1250 buf << L' ';
1251 buf << GetID();
1252 buf << L' ';
1253 buf << GetClassName().c_str();
1254 buf << L' ';
1255 buf << this;
1256
1257 VLOG(1) << buf.str();
1258 std::cout << buf.str() << std::endl;
1259
1260 if (GetChildViewCount() > 0)
1261 GetChildViewAt(0)->PrintFocusHierarchyImp(indent + 2);
1262
1263 View* v = GetNextFocusableView();
1264 if (v)
1265 v->PrintFocusHierarchyImp(indent);
1266 }
1267 #endif
1268
1269 // Size and disposition -------------------------------------------------------- 1211 // Size and disposition --------------------------------------------------------
1270 1212
1271 void View::PropagateVisibilityNotifications(View* start, bool is_visible) { 1213 void View::PropagateVisibilityNotifications(View* start, bool is_visible) {
1272 for (int i = 0, count = GetChildViewCount(); i < count; ++i) 1214 for (int i = 0, count = child_count(); i < count; ++i)
sky 2011/02/08 19:11:54 size_t
1273 GetChildViewAt(i)->PropagateVisibilityNotifications(start, is_visible); 1215 GetChildViewAt(i)->PropagateVisibilityNotifications(start, is_visible);
1274 VisibilityChangedImpl(start, is_visible); 1216 VisibilityChangedImpl(start, is_visible);
1275 } 1217 }
1276 1218
1277 void View::VisibilityChangedImpl(View* starting_from, bool is_visible) { 1219 void View::VisibilityChangedImpl(View* starting_from, bool is_visible) {
1278 if (is_visible) 1220 if (is_visible)
1279 RegisterPendingAccelerators(); 1221 RegisterPendingAccelerators();
1280 else 1222 else
1281 UnregisterAccelerators(true); 1223 UnregisterAccelerators(true);
1282 VisibilityChanged(starting_from, is_visible); 1224 VisibilityChanged(starting_from, is_visible);
1283 } 1225 }
1284 1226
1285 // static 1227 // static
1286 void View::RegisterChildrenForVisibleBoundsNotification( 1228 void View::RegisterChildrenForVisibleBoundsNotification(
1287 RootView* root, View* view) { 1229 RootView* root, View* view) {
1288 DCHECK(root && view); 1230 DCHECK(root && view);
1289 if (view->GetNotifyWhenVisibleBoundsInRootChanges()) 1231 if (view->GetNotifyWhenVisibleBoundsInRootChanges())
1290 root->RegisterViewForVisibleBoundsNotification(view); 1232 root->RegisterViewForVisibleBoundsNotification(view);
1291 for (int i = 0; i < view->GetChildViewCount(); ++i) 1233 for (size_t i = 0; i < view->child_count(); ++i)
sky 2011/02/08 19:11:54 size_t
1292 RegisterChildrenForVisibleBoundsNotification(root, view->GetChildViewAt(i)); 1234 RegisterChildrenForVisibleBoundsNotification(root, view->GetChildViewAt(i));
1293 } 1235 }
1294 1236
1295 // static 1237 // static
1296 void View::UnregisterChildrenForVisibleBoundsNotification( 1238 void View::UnregisterChildrenForVisibleBoundsNotification(
1297 RootView* root, View* view) { 1239 RootView* root, View* view) {
1298 DCHECK(root && view); 1240 DCHECK(root && view);
1299 if (view->GetNotifyWhenVisibleBoundsInRootChanges()) 1241 if (view->GetNotifyWhenVisibleBoundsInRootChanges())
1300 root->UnregisterViewForVisibleBoundsNotification(view); 1242 root->UnregisterViewForVisibleBoundsNotification(view);
1301 for (int i = 0; i < view->GetChildViewCount(); ++i) 1243 for (size_t i = 0; i < view->child_count(); ++i)
sky 2011/02/08 19:11:54 size_t
1302 UnregisterChildrenForVisibleBoundsNotification(root, 1244 UnregisterChildrenForVisibleBoundsNotification(root,
1303 view->GetChildViewAt(i)); 1245 view->GetChildViewAt(i));
1304 } 1246 }
1305 1247
1306 void View::AddDescendantToNotify(View* view) { 1248 void View::AddDescendantToNotify(View* view) {
1307 DCHECK(view); 1249 DCHECK(view);
1308 if (!descendants_to_notify_.get()) 1250 if (!descendants_to_notify_.get())
1309 descendants_to_notify_.reset(new ViewList()); 1251 descendants_to_notify_.reset(new ViewVector);
1310 descendants_to_notify_->push_back(view); 1252 descendants_to_notify_->push_back(view);
1311 } 1253 }
1312 1254
1313 void View::RemoveDescendantToNotify(View* view) { 1255 void View::RemoveDescendantToNotify(View* view) {
1314 DCHECK(view && descendants_to_notify_.get()); 1256 DCHECK(view && descendants_to_notify_.get());
1315 ViewList::iterator i = find(descendants_to_notify_->begin(), 1257 ViewVector::iterator i = find(descendants_to_notify_->begin(),
1316 descendants_to_notify_->end(), 1258 descendants_to_notify_->end(),
1317 view); 1259 view);
1318 DCHECK(i != descendants_to_notify_->end()); 1260 DCHECK(i != descendants_to_notify_->end());
1319 descendants_to_notify_->erase(i); 1261 descendants_to_notify_->erase(i);
1320 if (descendants_to_notify_->empty()) 1262 if (descendants_to_notify_->empty())
1321 descendants_to_notify_.reset(); 1263 descendants_to_notify_.reset();
1322 } 1264 }
1323 1265
1324 // Coordinate conversion ------------------------------------------------------- 1266 // Coordinate conversion -------------------------------------------------------
1325 1267
1326 // static 1268 // static
1327 void View::ConvertPointToView(const View* src, 1269 void View::ConvertPointToView(const View* src,
1328 const View* dst, 1270 const View* dst,
1329 gfx::Point* point, 1271 gfx::Point* point,
1330 bool try_other_direction) { 1272 bool try_other_direction) {
1331 // src can be NULL 1273 // src can be NULL
1332 DCHECK(dst); 1274 DCHECK(dst);
1333 DCHECK(point); 1275 DCHECK(point);
1334 1276
1335 const View* v; 1277 const View* v;
1336 gfx::Point offset; 1278 gfx::Point offset;
1337 1279
1338 for (v = dst; v && v != src; v = v->GetParent()) 1280 for (v = dst; v && v != src; v = v->parent())
1339 offset.SetPoint(offset.x() + v->GetMirroredX(), offset.y() + v->y()); 1281 offset.SetPoint(offset.x() + v->GetMirroredX(), offset.y() + v->y());
1340 1282
1341 // The source was not found. The caller wants a conversion 1283 // The source was not found. The caller wants a conversion
1342 // from a view to a transitive parent. 1284 // from a view to a transitive parent.
1343 if (src && v == NULL && try_other_direction) { 1285 if (src && v == NULL && try_other_direction) {
1344 gfx::Point p; 1286 gfx::Point p;
1345 // note: try_other_direction is force to FALSE so we don't 1287 // note: try_other_direction is force to FALSE so we don't
1346 // end up in an infinite recursion should both src and dst 1288 // end up in an infinite recursion should both src and dst
1347 // are not parented. 1289 // are not parented.
1348 ConvertPointToView(dst, src, &p, false); 1290 ConvertPointToView(dst, src, &p, false);
1349 // since the src and dst are inverted, p should also be negated 1291 // since the src and dst are inverted, p should also be negated
1350 point->SetPoint(point->x() - p.x(), point->y() - p.y()); 1292 point->SetPoint(point->x() - p.x(), point->y() - p.y());
1351 } else { 1293 } else {
1352 point->SetPoint(point->x() - offset.x(), point->y() - offset.y()); 1294 point->SetPoint(point->x() - offset.x(), point->y() - offset.y());
1353 1295
1354 // If src is NULL, sp is in the screen coordinate system 1296 // If src is NULL, sp is in the screen coordinate system
1355 if (src == NULL) { 1297 if (src == NULL) {
1356 Widget* widget = dst->GetWidget(); 1298 const Widget* widget = dst->GetWidget();
1357 if (widget) { 1299 if (widget) {
1358 gfx::Rect b; 1300 gfx::Rect b;
1359 widget->GetBounds(&b, false); 1301 widget->GetBounds(&b, false);
1360 point->SetPoint(point->x() - b.x(), point->y() - b.y()); 1302 point->SetPoint(point->x() - b.x(), point->y() - b.y());
1361 } 1303 }
1362 } 1304 }
1363 } 1305 }
1364 } 1306 }
1365 1307
1366 // Input ----------------------------------------------------------------------- 1308 // Input -----------------------------------------------------------------------
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1486 if (!leave_data_intact) { 1428 if (!leave_data_intact) {
1487 accelerators_->clear(); 1429 accelerators_->clear();
1488 accelerators_.reset(); 1430 accelerators_.reset();
1489 } 1431 }
1490 registered_accelerator_count_ = 0; 1432 registered_accelerator_count_ = 0;
1491 } 1433 }
1492 } 1434 }
1493 1435
1494 // Focus ----------------------------------------------------------------------- 1436 // Focus -----------------------------------------------------------------------
1495 1437
1496 void View::InitFocusSiblings(View* v, int index) { 1438 void View::InitFocusSiblings(View* v, int index) {
sky 2011/02/08 19:11:54 Can this take a size_t now? Maybe in the next pass
1497 int child_count = static_cast<int>(child_views_.size()); 1439 int child_count = static_cast<int>(children_.size());
sky 2011/02/08 19:11:54 no cast.
1498 1440
1499 if (child_count == 0) { 1441 if (child_count == 0) {
1500 v->next_focusable_view_ = NULL; 1442 v->next_focusable_view_ = NULL;
1501 v->previous_focusable_view_ = NULL; 1443 v->previous_focusable_view_ = NULL;
1502 } else { 1444 } else {
1503 if (index == child_count) { 1445 if (index == child_count) {
1504 // We are inserting at the end, but the end of the child list may not be 1446 // We are inserting at the end, but the end of the child list may not be
1505 // the last focusable element. Let's try to find an element with no next 1447 // the last focusable element. Let's try to find an element with no next
1506 // focusable element to link to. 1448 // focusable element to link to.
1507 View* last_focusable_view = NULL; 1449 View* last_focusable_view = NULL;
1508 for (std::vector<View*>::iterator iter = child_views_.begin(); 1450 for (std::vector<View*>::iterator iter = children_.begin();
1509 iter != child_views_.end(); ++iter) { 1451 iter != children_.end(); ++iter) {
1510 if (!(*iter)->next_focusable_view_) { 1452 if (!(*iter)->next_focusable_view_) {
1511 last_focusable_view = *iter; 1453 last_focusable_view = *iter;
1512 break; 1454 break;
1513 } 1455 }
1514 } 1456 }
1515 if (last_focusable_view == NULL) { 1457 if (last_focusable_view == NULL) {
1516 // Hum... there is a cycle in the focus list. Let's just insert ourself 1458 // Hum... there is a cycle in the focus list. Let's just insert ourself
1517 // after the last child. 1459 // after the last child.
1518 View* prev = child_views_[index - 1]; 1460 View* prev = children_[index - 1];
1519 v->previous_focusable_view_ = prev; 1461 v->previous_focusable_view_ = prev;
1520 v->next_focusable_view_ = prev->next_focusable_view_; 1462 v->next_focusable_view_ = prev->next_focusable_view_;
1521 prev->next_focusable_view_->previous_focusable_view_ = v; 1463 prev->next_focusable_view_->previous_focusable_view_ = v;
1522 prev->next_focusable_view_ = v; 1464 prev->next_focusable_view_ = v;
1523 } else { 1465 } else {
1524 last_focusable_view->next_focusable_view_ = v; 1466 last_focusable_view->next_focusable_view_ = v;
1525 v->next_focusable_view_ = NULL; 1467 v->next_focusable_view_ = NULL;
1526 v->previous_focusable_view_ = last_focusable_view; 1468 v->previous_focusable_view_ = last_focusable_view;
1527 } 1469 }
1528 } else { 1470 } else {
1529 View* prev = child_views_[index]->GetPreviousFocusableView(); 1471 View* prev = children_[index]->GetPreviousFocusableView();
1530 v->previous_focusable_view_ = prev; 1472 v->previous_focusable_view_ = prev;
1531 v->next_focusable_view_ = child_views_[index]; 1473 v->next_focusable_view_ = children_[index];
1532 if (prev) 1474 if (prev)
1533 prev->next_focusable_view_ = v; 1475 prev->next_focusable_view_ = v;
1534 child_views_[index]->previous_focusable_view_ = v; 1476 children_[index]->previous_focusable_view_ = v;
1535 } 1477 }
1536 } 1478 }
1537 } 1479 }
1538 1480
1539 // System events --------------------------------------------------------------- 1481 // System events ---------------------------------------------------------------
1540 1482
1541 void View::PropagateThemeChanged() { 1483 void View::PropagateThemeChanged() {
1542 for (int i = GetChildViewCount() - 1; i >= 0; --i) 1484 for (int i = child_count() - 1; i >= 0; --i)
sky 2011/02/08 19:11:54 size_t
1543 GetChildViewAt(i)->PropagateThemeChanged(); 1485 GetChildViewAt(i)->PropagateThemeChanged();
1544 OnThemeChanged(); 1486 OnThemeChanged();
1545 } 1487 }
1546 1488
1547 void View::PropagateLocaleChanged() { 1489 void View::PropagateLocaleChanged() {
1548 for (int i = GetChildViewCount() - 1; i >= 0; --i) 1490 for (int i = child_count() - 1; i >= 0; --i)
sky 2011/02/08 19:11:54 size_t
1549 GetChildViewAt(i)->PropagateLocaleChanged(); 1491 GetChildViewAt(i)->PropagateLocaleChanged();
1550 OnLocaleChanged(); 1492 OnLocaleChanged();
1551 } 1493 }
1552 1494
1553 // Tooltips -------------------------------------------------------------------- 1495 // Tooltips --------------------------------------------------------------------
1554 1496
1555 void View::UpdateTooltip() { 1497 void View::UpdateTooltip() {
1556 Widget* widget = GetWidget(); 1498 Widget* widget = GetWidget();
1557 if (widget && widget->GetTooltipManager()) 1499 if (widget && widget->GetTooltipManager())
1558 widget->GetTooltipManager()->UpdateTooltip(); 1500 widget->GetTooltipManager()->UpdateTooltip();
1559 } 1501 }
1560 1502
1561 // Drag and drop --------------------------------------------------------------- 1503 // Drag and drop ---------------------------------------------------------------
1562 1504
1563 void View::DoDrag(const MouseEvent& e, const gfx::Point& press_pt) { 1505 void View::DoDrag(const MouseEvent& e, const gfx::Point& press_pt) {
1564 int drag_operations = GetDragOperations(press_pt); 1506 int drag_operations = GetDragOperations(press_pt);
1565 if (drag_operations == ui::DragDropTypes::DRAG_NONE) 1507 if (drag_operations == ui::DragDropTypes::DRAG_NONE)
1566 return; 1508 return;
1567 1509
1568 OSExchangeData data; 1510 OSExchangeData data;
1569 WriteDragData(press_pt, &data); 1511 WriteDragData(press_pt, &data);
1570 1512
1571 // Message the RootView to do the drag and drop. That way if we're removed 1513 // Message the RootView to do the drag and drop. That way if we're removed
1572 // the RootView can detect it and avoid calling us back. 1514 // the RootView can detect it and avoid calling us back.
1573 RootView* root_view = GetRootView(); 1515 RootView* root_view = GetRootView();
1574 root_view->StartDragForViewFromMouseEvent(this, data, drag_operations); 1516 root_view->StartDragForViewFromMouseEvent(this, data, drag_operations);
1575 } 1517 }
1576 1518
1577 } // namespace views 1519 } // namespace views
OLDNEW
« views/view.h ('K') | « views/view.h ('k') | views/views.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698