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

Side by Side Diff: views/view.cc

Issue 7057014: Variety of tweaks to View API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 7 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 | « views/view.h ('k') | views/widget/root_view.cc » ('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 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 } 92 }
93 93
94 // Creation and lifetime ------------------------------------------------------- 94 // Creation and lifetime -------------------------------------------------------
95 95
96 View::View() 96 View::View()
97 : enabled_(true), 97 : enabled_(true),
98 id_(0), 98 id_(0),
99 group_(-1), 99 group_(-1),
100 focusable_(false), 100 focusable_(false),
101 accessibility_focusable_(false), 101 accessibility_focusable_(false),
102 is_parent_owned_(true), 102 parent_owned_(true),
103 parent_(NULL), 103 parent_(NULL),
104 is_visible_(true), 104 visible_(true),
105 registered_for_visible_bounds_notification_(false), 105 registered_for_visible_bounds_notification_(false),
106 clip_x_(0.0), 106 clip_x_(0.0),
107 clip_y_(0.0), 107 clip_y_(0.0),
108 needs_layout_(true), 108 needs_layout_(true),
109 flip_canvas_on_paint_for_rtl_ui_(false), 109 flip_canvas_on_paint_for_rtl_ui_(false),
110 #if !defined(COMPOSITOR_2) 110 #if !defined(COMPOSITOR_2)
111 texture_id_(0), // TODO(sadrul): 0 can be a valid texture id. 111 texture_id_(0), // TODO(sadrul): 0 can be a valid texture id.
112 #endif 112 #endif
113 texture_needs_updating_(true), 113 texture_needs_updating_(true),
114 accelerator_registration_delayed_(false), 114 accelerator_registration_delayed_(false),
115 accelerator_focus_manager_(NULL), 115 accelerator_focus_manager_(NULL),
116 registered_accelerator_count_(0), 116 registered_accelerator_count_(0),
117 next_focusable_view_(NULL), 117 next_focusable_view_(NULL),
118 previous_focusable_view_(NULL), 118 previous_focusable_view_(NULL),
119 context_menu_controller_(NULL), 119 context_menu_controller_(NULL),
120 drag_controller_(NULL) { 120 drag_controller_(NULL) {
121 } 121 }
122 122
123 View::~View() { 123 View::~View() {
124 if (parent_) 124 if (parent_)
125 parent_->RemoveChildView(this); 125 parent_->RemoveChildView(this);
126 126
127 int c = static_cast<int>(children_.size()); 127 int c = static_cast<int>(children_.size());
128 while (--c >= 0) { 128 while (--c >= 0) {
129 children_[c]->SetParent(NULL); 129 children_[c]->parent_ = NULL;
130 if (children_[c]->IsParentOwned()) 130 if (children_[c]->parent_owned())
131 delete children_[c]; 131 delete children_[c];
132 } 132 }
133 133
134 #if defined(OS_WIN) 134 #if defined(OS_WIN)
135 if (native_view_accessibility_win_.get()) 135 if (native_view_accessibility_win_.get())
136 native_view_accessibility_win_->set_view(NULL); 136 native_view_accessibility_win_->set_view(NULL);
137 #endif 137 #endif
138 } 138 }
139 139
140 // Tree operations ------------------------------------------------------------- 140 // Tree operations -------------------------------------------------------------
141 141
142 const Widget* View::GetWidget() const { 142 const Widget* View::GetWidget() const {
143 // The root view holds a reference to this view hierarchy's Widget. 143 // The root view holds a reference to this view hierarchy's Widget.
144 return parent_ ? parent_->GetWidget() : NULL; 144 return parent_ ? parent_->GetWidget() : NULL;
145 } 145 }
146 146
147 Widget* View::GetWidget() { 147 Widget* View::GetWidget() {
148 return const_cast<Widget*>(const_cast<const View*>(this)->GetWidget()); 148 return const_cast<Widget*>(const_cast<const View*>(this)->GetWidget());
149 } 149 }
150 150
151 const Window* View::GetWindow() const {
152 const Widget* widget = GetWidget();
153 return widget ? widget->GetContainingWindow() : NULL;
154 }
155
156 Window* View::GetWindow() {
157 return const_cast<Window*>(const_cast<const View*>(this)->GetWindow());
158 }
159
151 void View::AddChildView(View* view) { 160 void View::AddChildView(View* view) {
152 AddChildViewAt(view, child_count()); 161 AddChildViewAt(view, child_count());
153 } 162 }
154 163
155 void View::AddChildViewAt(View* view, int index) { 164 void View::AddChildViewAt(View* view, int index) {
156 CHECK(view != this) << "You cannot add a view as its own child"; 165 CHECK(view != this) << "You cannot add a view as its own child";
157 166
158 // Remove the view from its current parent if any. 167 // Remove the view from its current parent if any.
159 if (view->parent()) 168 if (view->parent())
160 view->parent()->RemoveChildView(view); 169 view->parent()->RemoveChildView(view);
161 170
162 // Sets the prev/next focus views. 171 // Sets the prev/next focus views.
163 InitFocusSiblings(view, index); 172 InitFocusSiblings(view, index);
164 173
165 // Let's insert the view. 174 // Let's insert the view.
166 children_.insert(children_.begin() + index, view); 175 children_.insert(children_.begin() + index, view);
167 view->SetParent(this); 176 view->parent_ = this;
168 177
169 for (View* p = this; p; p = p->parent()) 178 for (View* p = this; p; p = p->parent())
170 p->ViewHierarchyChangedImpl(false, true, this, view); 179 p->ViewHierarchyChangedImpl(false, true, this, view);
171 180
172 view->PropagateAddNotifications(this, view); 181 view->PropagateAddNotifications(this, view);
173 UpdateTooltip(); 182 UpdateTooltip();
174 if (GetWidget()) 183 if (GetWidget())
175 RegisterChildrenForVisibleBoundsNotification(view); 184 RegisterChildrenForVisibleBoundsNotification(view);
176 185
177 if (layout_manager_.get()) 186 if (layout_manager_.get())
(...skipping 28 matching lines...) Expand all
206 return false; 215 return false;
207 } 216 }
208 217
209 int View::GetIndexOf(const View* view) const { 218 int View::GetIndexOf(const View* view) const {
210 ViewVector::const_iterator it = std::find(children_.begin(), children_.end(), 219 ViewVector::const_iterator it = std::find(children_.begin(), children_.end(),
211 view); 220 view);
212 return it != children_.end() ? it - children_.begin() : -1; 221 return it != children_.end() ? it - children_.begin() : -1;
213 } 222 }
214 223
215 // TODO(beng): remove 224 // TODO(beng): remove
216 const Window* View::GetWindow() const {
217 const Widget* widget = GetWidget();
218 return widget ? widget->GetContainingWindow() : NULL;
219 }
220
221 // TODO(beng): remove
222 Window* View::GetWindow() {
223 return const_cast<Window*>(const_cast<const View*>(this)->GetWindow());
224 }
225
226 // TODO(beng): remove
227 bool View::ContainsNativeView(gfx::NativeView native_view) const { 225 bool View::ContainsNativeView(gfx::NativeView native_view) const {
228 for (int i = 0, count = child_count(); i < count; ++i) { 226 for (int i = 0, count = child_count(); i < count; ++i) {
229 if (GetChildViewAt(i)->ContainsNativeView(native_view)) 227 if (GetChildViewAt(i)->ContainsNativeView(native_view))
230 return true; 228 return true;
231 } 229 }
232 return false; 230 return false;
233 } 231 }
234 232
235 // Size and disposition -------------------------------------------------------- 233 // Size and disposition --------------------------------------------------------
236 234
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 gfx::Size View::GetMinimumSize() { 343 gfx::Size View::GetMinimumSize() {
346 return GetPreferredSize(); 344 return GetPreferredSize();
347 } 345 }
348 346
349 int View::GetHeightForWidth(int w) { 347 int View::GetHeightForWidth(int w) {
350 if (layout_manager_.get()) 348 if (layout_manager_.get())
351 return layout_manager_->GetPreferredHeightForWidth(this, w); 349 return layout_manager_->GetPreferredHeightForWidth(this, w);
352 return GetPreferredSize().height(); 350 return GetPreferredSize().height();
353 } 351 }
354 352
355 void View::SetVisible(bool flag) {
356 if (flag != is_visible_) {
357 // If the tab is currently visible, schedule paint to
358 // refresh parent
359 if (IsVisible())
360 SchedulePaint();
361 else
362 ResetTexture();
363
364 is_visible_ = flag;
365
366 // This notifies all sub-views recursively.
367 PropagateVisibilityNotifications(this, flag);
368
369 // If we are newly visible, schedule paint.
370 if (IsVisible())
371 SchedulePaint();
372 }
373 }
374
375 bool View::IsVisible() const {
376 return is_visible_;
377 }
378
379 bool View::IsVisibleInRootView() const {
380 return IsVisible() && parent() ? parent()->IsVisibleInRootView() : false;
381 }
382
383 void View::SetEnabled(bool state) {
384 if (enabled_ != state) {
385 enabled_ = state;
386 SchedulePaint();
387 }
388 }
389
390 bool View::IsEnabled() const {
391 return enabled_;
392 }
393
394 // Transformations ------------------------------------------------------------- 353 // Transformations -------------------------------------------------------------
395 354
396 const ui::Transform& View::GetTransform() const { 355 const ui::Transform& View::GetTransform() const {
397 static const ui::Transform* no_op = new ui::Transform; 356 static const ui::Transform* no_op = new ui::Transform;
398 if (transform_.get()) 357 if (transform_.get())
399 return *transform_.get(); 358 return *transform_.get();
400 return *no_op; 359 return *no_op;
401 } 360 }
402 361
403 void View::SetTransform(const ui::Transform& transform) { 362 void View::SetTransform(const ui::Transform& transform) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 if (layout_manager_.get()) 446 if (layout_manager_.get())
488 layout_manager_->Uninstalled(this); 447 layout_manager_->Uninstalled(this);
489 448
490 layout_manager_.reset(layout_manager); 449 layout_manager_.reset(layout_manager);
491 if (layout_manager_.get()) 450 if (layout_manager_.get())
492 layout_manager_->Installed(this); 451 layout_manager_->Installed(this);
493 } 452 }
494 453
495 // Attributes ------------------------------------------------------------------ 454 // Attributes ------------------------------------------------------------------
496 455
456 void View::SetVisible(bool flag) {
457 if (flag != visible_) {
458 // If the tab is currently visible, schedule paint to
459 // refresh parent
460 if (visible())
461 SchedulePaint();
462 else
463 ResetTexture();
464
465 visible_ = flag;
466
467 // This notifies all sub-views recursively.
468 PropagateVisibilityNotifications(this, flag);
469
470 // If we are newly visible, schedule paint.
471 if (visible())
472 SchedulePaint();
473 }
474 }
475
476 bool View::IsVisibleInRootView() const {
477 return visible() && parent() ? parent()->IsVisibleInRootView() : false;
478 }
479
480 bool View::IsEnabled() const {
481 return enabled_;
482 }
483
484 void View::SetEnabled(bool enabled) {
485 if (enabled_ != enabled) {
486 enabled_ = enabled;
487 SchedulePaint();
488 }
489 }
490
497 std::string View::GetClassName() const { 491 std::string View::GetClassName() const {
498 return kViewClassName; 492 return kViewClassName;
499 } 493 }
500 494
501 View* View::GetAncestorWithClassName(const std::string& name) { 495 View* View::GetAncestorWithClassName(const std::string& name) {
502 for (View* view = this; view; view = view->parent()) { 496 for (View* view = this; view; view = view->parent()) {
503 if (view->GetClassName() == name) 497 if (view->GetClassName() == name)
504 return view; 498 return view;
505 } 499 }
506 return NULL; 500 return NULL;
507 } 501 }
508 502
509 const View* View::GetViewByID(int id) const { 503 const View* View::GetViewByID(int id) const {
510 if (id == id_) 504 if (id == id_)
511 return const_cast<View*>(this); 505 return const_cast<View*>(this);
512 506
513 for (int i = 0, count = child_count(); i < count; ++i) { 507 for (int i = 0, count = child_count(); i < count; ++i) {
514 const View* view = GetChildViewAt(i)->GetViewByID(id); 508 const View* view = GetChildViewAt(i)->GetViewByID(id);
515 if (view) 509 if (view)
516 return view; 510 return view;
517 } 511 }
518 return NULL; 512 return NULL;
519 } 513 }
520 514
521 View* View::GetViewByID(int id) { 515 View* View::GetViewByID(int id) {
522 return const_cast<View*>(const_cast<const View*>(this)->GetViewByID(id)); 516 return const_cast<View*>(const_cast<const View*>(this)->GetViewByID(id));
523 } 517 }
524 518
525 void View::SetID(int id) { 519 void View::set_group(int group) {
526 id_ = id; 520 DCHECK(group_ == -1 || group_ == group);
527 } 521 group_ = group;
528
529 int View::GetID() const {
530 return id_;
531 }
532
533 void View::SetGroup(int gid) {
534 // Don't change the group id once it's set.
535 DCHECK(group_ == -1 || group_ == gid);
536 group_ = gid;
537 }
538
539 int View::GetGroup() const {
540 return group_;
541 } 522 }
542 523
543 bool View::IsGroupFocusTraversable() const { 524 bool View::IsGroupFocusTraversable() const {
544 return true; 525 return true;
545 } 526 }
546 527
547 void View::GetViewsWithGroup(int group_id, std::vector<View*>* out) { 528 void View::GetViewsInGroup(int group, std::vector<View*>* out) {
548 if (group_ == group_id) 529 if (group_ == group)
549 out->push_back(this); 530 out->push_back(this);
550 531
551 for (int i = 0, count = child_count(); i < count; ++i) 532 for (int i = 0, count = child_count(); i < count; ++i)
552 GetChildViewAt(i)->GetViewsWithGroup(group_id, out); 533 GetChildViewAt(i)->GetViewsInGroup(group, out);
553 } 534 }
554 535
555 View* View::GetSelectedViewForGroup(int group_id) { 536 View* View::GetSelectedViewForGroup(int group) {
556 std::vector<View*> views; 537 std::vector<View*> views;
557 GetWidget()->GetRootView()->GetViewsWithGroup(group_id, &views); 538 GetWidget()->GetRootView()->GetViewsInGroup(group, &views);
558 return views.empty() ? NULL : views[0]; 539 return views.empty() ? NULL : views[0];
559 } 540 }
560 541
561 // Coordinate conversion ------------------------------------------------------- 542 // Coordinate conversion -------------------------------------------------------
562 543
563 // static 544 // static
564 void View::ConvertPointToView(const View* src, 545 void View::ConvertPointToView(const View* src,
565 const View* dst, 546 const View* dst,
566 gfx::Point* point) { 547 gfx::Point* point) {
567 ConvertPointToView(src, dst, point, true); 548 ConvertPointToView(src, dst, point, true);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 return x_rect; 586 return x_rect;
606 } 587 }
607 588
608 // Painting -------------------------------------------------------------------- 589 // Painting --------------------------------------------------------------------
609 590
610 void View::SchedulePaint() { 591 void View::SchedulePaint() {
611 SchedulePaintInRect(GetLocalBounds()); 592 SchedulePaintInRect(GetLocalBounds());
612 } 593 }
613 594
614 void View::SchedulePaintInRect(const gfx::Rect& rect) { 595 void View::SchedulePaintInRect(const gfx::Rect& rect) {
615 if (!IsVisible()) 596 if (!visible())
616 return; 597 return;
617 598
618 if (parent_) { 599 if (parent_) {
619 // Translate the requested paint rect to the parent's coordinate system 600 // Translate the requested paint rect to the parent's coordinate system
620 // then pass this notification up to the parent. 601 // then pass this notification up to the parent.
621 gfx::Rect paint_rect = ConvertRectToParent(rect); 602 gfx::Rect paint_rect = ConvertRectToParent(rect);
622 paint_rect.Offset(GetMirroredPosition()); 603 paint_rect.Offset(GetMirroredPosition());
623 parent_->SchedulePaintInRect(paint_rect); 604 parent_->SchedulePaintInRect(paint_rect);
624 } 605 }
625 } 606 }
626 607
627 void View::Paint(gfx::Canvas* canvas) { 608 void View::Paint(gfx::Canvas* canvas) {
628 if (!IsVisible()) 609 if (!visible())
629 return; 610 return;
630 611
631 ScopedCanvas scoped_canvas(NULL); 612 ScopedCanvas scoped_canvas(NULL);
632 scoped_ptr<gfx::Canvas> texture_canvas; 613 scoped_ptr<gfx::Canvas> texture_canvas;
633 gfx::Rect texture_rect; 614 gfx::Rect texture_rect;
634 615
635 #if !defined(COMPOSITOR_2) 616 #if !defined(COMPOSITOR_2)
636 if (use_acceleration_when_possible && 617 if (use_acceleration_when_possible &&
637 transform_.get() && transform_->HasChange()) { 618 transform_.get() && transform_->HasChange()) {
638 // This view has a transformation. So this maintains its own canvas. 619 // This view has a transformation. So this maintains its own canvas.
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 use_acceleration_when_possible = use; 720 use_acceleration_when_possible = use;
740 } 721 }
741 722
742 // Input ----------------------------------------------------------------------- 723 // Input -----------------------------------------------------------------------
743 724
744 View* View::GetEventHandlerForPoint(const gfx::Point& point) { 725 View* View::GetEventHandlerForPoint(const gfx::Point& point) {
745 // Walk the child Views recursively looking for the View that most 726 // Walk the child Views recursively looking for the View that most
746 // tightly encloses the specified point. 727 // tightly encloses the specified point.
747 for (int i = child_count() - 1; i >= 0; --i) { 728 for (int i = child_count() - 1; i >= 0; --i) {
748 View* child = GetChildViewAt(i); 729 View* child = GetChildViewAt(i);
749 if (!child->IsVisible()) 730 if (!child->visible())
750 continue; 731 continue;
751 732
752 gfx::Point point_in_child_coords(point); 733 gfx::Point point_in_child_coords(point);
753 View::ConvertPointToView(this, child, &point_in_child_coords); 734 View::ConvertPointToView(this, child, &point_in_child_coords);
754 if (child->HitTest(point_in_child_coords)) 735 if (child->HitTest(point_in_child_coords))
755 return child->GetEventHandlerForPoint(point_in_child_coords); 736 return child->GetEventHandlerForPoint(point_in_child_coords);
756 } 737 }
757 return this; 738 return this;
758 } 739 }
759 740
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 891
911 View* View::GetPreviousFocusableView() { 892 View* View::GetPreviousFocusableView() {
912 return previous_focusable_view_; 893 return previous_focusable_view_;
913 } 894 }
914 895
915 void View::SetNextFocusableView(View* view) { 896 void View::SetNextFocusableView(View* view) {
916 view->previous_focusable_view_ = this; 897 view->previous_focusable_view_ = this;
917 next_focusable_view_ = view; 898 next_focusable_view_ = view;
918 } 899 }
919 900
920 void View::SetFocusable(bool focusable) {
921 focusable_ = focusable;
922 }
923
924 bool View::IsFocusableInRootView() const { 901 bool View::IsFocusableInRootView() const {
925 return IsFocusable() && IsVisibleInRootView(); 902 return IsFocusable() && IsVisibleInRootView();
926 } 903 }
927 904
928 bool View::IsAccessibilityFocusableInRootView() const { 905 bool View::IsAccessibilityFocusableInRootView() const {
929 return (focusable_ || accessibility_focusable_) && IsEnabled() && 906 return (focusable_ || accessibility_focusable_) && IsEnabled() &&
930 IsVisibleInRootView(); 907 IsVisibleInRootView();
931 } 908 }
932 909
933 void View::set_accessibility_focusable(bool accessibility_focusable) { 910 void View::set_accessibility_focusable(bool accessibility_focusable) {
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 1120
1144 for (int i = 0, count = child_count(); i < count; ++i) { 1121 for (int i = 0, count = child_count(); i < count; ++i) {
1145 View* child = GetChildViewAt(i); 1122 View* child = GetChildViewAt(i);
1146 child->PaintComposite(compositor); 1123 child->PaintComposite(compositor);
1147 } 1124 }
1148 1125
1149 compositor->RestoreTransform(); 1126 compositor->RestoreTransform();
1150 } 1127 }
1151 #else 1128 #else
1152 void View::PaintComposite() { 1129 void View::PaintComposite() {
1153 if (!IsVisible()) 1130 if (!visible())
1154 return; 1131 return;
1155 1132
1156 if (texture_.get()) { 1133 if (texture_.get()) {
1157 // TODO: if dirty_region doesn't itersect bounds, return. 1134 // TODO: if dirty_region doesn't itersect bounds, return.
1158 ui::Transform transform; 1135 ui::Transform transform;
1159 GetTransformRelativeTo(NULL, &transform); 1136 GetTransformRelativeTo(NULL, &transform);
1160 texture_->Draw(transform); 1137 texture_->Draw(transform);
1161 } 1138 }
1162 1139
1163 for (int i = 0, count = child_count(); i < count; ++i) 1140 for (int i = 0, count = child_count(); i < count; ++i)
1164 GetChildViewAt(i)->PaintComposite(); 1141 GetChildViewAt(i)->PaintComposite();
1165 } 1142 }
1166 1143
1167 void View::PaintToTexture(const gfx::Rect& dirty_region) { 1144 void View::PaintToTexture(const gfx::Rect& dirty_region) {
1168 if (!IsVisible()) 1145 if (!visible())
1169 return; 1146 return;
1170 1147
1171 if (ShouldPaintToTexture() && texture_needs_updating_) { 1148 if (ShouldPaintToTexture() && texture_needs_updating_) {
1172 texture_clip_rect_ = dirty_region; 1149 texture_clip_rect_ = dirty_region;
1173 Paint(NULL); 1150 Paint(NULL);
1174 texture_clip_rect_.SetRect(0, 0, 0, 0); 1151 texture_clip_rect_.SetRect(0, 0, 0, 0);
1175 } else { 1152 } else {
1176 // Forward to all children as a descendant may be dirty and have a texture. 1153 // Forward to all children as a descendant may be dirty and have a texture.
1177 for (int i = child_count() - 1; i >= 0; --i) { 1154 for (int i = child_count() - 1; i >= 0; --i) {
1178 View* child_view = GetChildViewAt(i); 1155 View* child_view = GetChildViewAt(i);
(...skipping 26 matching lines...) Expand all
1205 return false; 1182 return false;
1206 } 1183 }
1207 1184
1208 void View::GetHitTestMask(gfx::Path* mask) const { 1185 void View::GetHitTestMask(gfx::Path* mask) const {
1209 DCHECK(mask); 1186 DCHECK(mask);
1210 } 1187 }
1211 1188
1212 // Focus ----------------------------------------------------------------------- 1189 // Focus -----------------------------------------------------------------------
1213 1190
1214 bool View::IsFocusable() const { 1191 bool View::IsFocusable() const {
1215 return focusable_ && IsEnabled() && IsVisible(); 1192 return focusable_ && IsEnabled() && visible();
1216 } 1193 }
1217 1194
1218 void View::OnFocus() { 1195 void View::OnFocus() {
1219 // TODO(beng): Investigate whether it's possible for us to move this to 1196 // TODO(beng): Investigate whether it's possible for us to move this to
1220 // Focus(). 1197 // Focus().
1221 // By default, we clear the native focus. This ensures that no visible native 1198 // By default, we clear the native focus. This ensures that no visible native
1222 // view as the focus and that we still receive keyboard inputs. 1199 // view as the focus and that we still receive keyboard inputs.
1223 FocusManager* focus_manager = GetFocusManager(); 1200 FocusManager* focus_manager = GetFocusManager();
1224 if (focus_manager) 1201 if (focus_manager)
1225 focus_manager->ClearNativeFocus(); 1202 focus_manager->ClearNativeFocus();
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1312 if (prev_focusable) 1289 if (prev_focusable)
1313 prev_focusable->next_focusable_view_ = next_focusable; 1290 prev_focusable->next_focusable_view_ = next_focusable;
1314 if (next_focusable) 1291 if (next_focusable)
1315 next_focusable->previous_focusable_view_ = prev_focusable; 1292 next_focusable->previous_focusable_view_ = prev_focusable;
1316 } 1293 }
1317 1294
1318 if (GetWidget()) 1295 if (GetWidget())
1319 UnregisterChildrenForVisibleBoundsNotification(view); 1296 UnregisterChildrenForVisibleBoundsNotification(view);
1320 view->ResetTexture(); 1297 view->ResetTexture();
1321 view->PropagateRemoveNotifications(this); 1298 view->PropagateRemoveNotifications(this);
1322 view->SetParent(NULL); 1299 view->parent_ = NULL;
1323 1300
1324 if (delete_removed_view && view->IsParentOwned()) 1301 if (delete_removed_view && view->parent_owned())
1325 view_to_be_deleted.reset(view); 1302 view_to_be_deleted.reset(view);
1326 1303
1327 children_.erase(i); 1304 children_.erase(i);
1328 } 1305 }
1329 1306
1330 if (update_tool_tip) 1307 if (update_tool_tip)
1331 UpdateTooltip(); 1308 UpdateTooltip();
1332 1309
1333 if (layout_manager_.get()) 1310 if (layout_manager_.get())
1334 layout_manager_->ViewRemoved(this, view); 1311 layout_manager_->ViewRemoved(this, view);
1335 } 1312 }
1336 1313
1337 void View::SetParent(View* parent) {
1338 if (parent != parent_)
1339 parent_ = parent;
1340 }
1341
1342 void View::PropagateRemoveNotifications(View* parent) { 1314 void View::PropagateRemoveNotifications(View* parent) {
1343 for (int i = 0, count = child_count(); i < count; ++i) 1315 for (int i = 0, count = child_count(); i < count; ++i)
1344 GetChildViewAt(i)->PropagateRemoveNotifications(parent); 1316 GetChildViewAt(i)->PropagateRemoveNotifications(parent);
1345 1317
1346 for (View* v = this; v; v = v->parent()) 1318 for (View* v = this; v; v = v->parent())
1347 v->ViewHierarchyChangedImpl(true, false, parent, this); 1319 v->ViewHierarchyChangedImpl(true, false, parent, this);
1348 } 1320 }
1349 1321
1350 void View::PropagateAddNotifications(View* parent, View* child) { 1322 void View::PropagateAddNotifications(View* parent, View* child) {
1351 for (int i = 0, count = child_count(); i < count; ++i) 1323 for (int i = 0, count = child_count(); i < count; ++i)
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1403 UnregisterAccelerators(true); 1375 UnregisterAccelerators(true);
1404 VisibilityChanged(starting_from, is_visible); 1376 VisibilityChanged(starting_from, is_visible);
1405 } 1377 }
1406 1378
1407 void View::BoundsChanged(const gfx::Rect& previous_bounds) { 1379 void View::BoundsChanged(const gfx::Rect& previous_bounds) {
1408 #if !defined(COMPOSITOR_2) 1380 #if !defined(COMPOSITOR_2)
1409 if (canvas_.get()) 1381 if (canvas_.get())
1410 canvas_.reset(gfx::Canvas::CreateCanvas(width(), height(), false)); 1382 canvas_.reset(gfx::Canvas::CreateCanvas(width(), height(), false));
1411 #endif 1383 #endif
1412 1384
1413 if (IsVisible()) { 1385 if (visible()) {
1414 if (parent_) { 1386 if (parent_) {
1415 // Paint the old bounds. 1387 // Paint the old bounds.
1416 if (base::i18n::IsRTL()) { 1388 if (base::i18n::IsRTL()) {
1417 gfx::Rect paint_rect = previous_bounds; 1389 gfx::Rect paint_rect = previous_bounds;
1418 paint_rect.set_x(parent()->GetMirroredXForRect(paint_rect)); 1390 paint_rect.set_x(parent()->GetMirroredXForRect(paint_rect));
1419 parent_->SchedulePaintInRect(paint_rect); 1391 parent_->SchedulePaintInRect(paint_rect);
1420 } else { 1392 } else {
1421 parent_->SchedulePaintInRect(previous_bounds); 1393 parent_->SchedulePaintInRect(previous_bounds);
1422 } 1394 }
1423 1395
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
1851 result.append(GetChildViewAt(i)->PrintViewGraph(false)); 1823 result.append(GetChildViewAt(i)->PrintViewGraph(false));
1852 1824
1853 if (first) 1825 if (first)
1854 result.append("}\n"); 1826 result.append("}\n");
1855 1827
1856 return result; 1828 return result;
1857 } 1829 }
1858 #endif 1830 #endif
1859 1831
1860 } // namespace views 1832 } // namespace views
OLDNEW
« no previous file with comments | « views/view.h ('k') | views/widget/root_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698