OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. | 5 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. |
6 | 6 |
7 #include "ui/views/view.h" | 7 #include "ui/views/view.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 // static | 156 // static |
157 const char View::kViewClassName[] = "views/View"; | 157 const char View::kViewClassName[] = "views/View"; |
158 | 158 |
159 //////////////////////////////////////////////////////////////////////////////// | 159 //////////////////////////////////////////////////////////////////////////////// |
160 // View, public: | 160 // View, public: |
161 | 161 |
162 // Creation and lifetime ------------------------------------------------------- | 162 // Creation and lifetime ------------------------------------------------------- |
163 | 163 |
164 View::View() | 164 View::View() |
165 : owned_by_client_(false), | 165 : owned_by_client_(false), |
| 166 weak_ptr_factory_(this), |
166 id_(0), | 167 id_(0), |
167 group_(-1), | 168 group_(-1), |
168 parent_(NULL), | 169 parent_(NULL), |
169 visible_(true), | 170 visible_(true), |
170 enabled_(true), | 171 enabled_(true), |
171 notify_enter_exit_on_child_(false), | 172 notify_enter_exit_on_child_(false), |
172 registered_for_visible_bounds_notification_(false), | 173 registered_for_visible_bounds_notification_(false), |
173 clip_insets_(0, 0, 0, 0), | 174 clip_insets_(0, 0, 0, 0), |
174 needs_layout_(true), | 175 needs_layout_(true), |
175 focus_border_(FocusBorder::CreateDashedFocusBorder()), | 176 focus_border_(FocusBorder::CreateDashedFocusBorder()), |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 child->needs_layout_ = false; | 590 child->needs_layout_ = false; |
590 child->Layout(); | 591 child->Layout(); |
591 } | 592 } |
592 } | 593 } |
593 } | 594 } |
594 | 595 |
595 void View::InvalidateLayout() { | 596 void View::InvalidateLayout() { |
596 // Always invalidate up. This is needed to handle the case of us already being | 597 // Always invalidate up. This is needed to handle the case of us already being |
597 // valid, but not our parent. | 598 // valid, but not our parent. |
598 needs_layout_ = true; | 599 needs_layout_ = true; |
599 if (parent_) | 600 // Schedule a layout |
600 parent_->InvalidateLayout(); | 601 base::MessageLoop::current()->PostTask( |
| 602 FROM_HERE, |
| 603 base::Bind(&View::LayoutIfNeeded, |
| 604 weak_ptr_factory_.GetWeakPtr())); |
601 } | 605 } |
602 | 606 |
603 LayoutManager* View::GetLayoutManager() const { | 607 LayoutManager* View::GetLayoutManager() const { |
604 return layout_manager_.get(); | 608 return layout_manager_.get(); |
605 } | 609 } |
606 | 610 |
607 void View::SetLayoutManager(LayoutManager* layout_manager) { | 611 void View::SetLayoutManager(LayoutManager* layout_manager) { |
608 if (layout_manager_.get()) | 612 if (layout_manager_.get()) |
609 layout_manager_->Uninstalled(this); | 613 layout_manager_->Uninstalled(this); |
610 | 614 |
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1244 int View::GetLineScrollIncrement(ScrollView* scroll_view, | 1248 int View::GetLineScrollIncrement(ScrollView* scroll_view, |
1245 bool is_horizontal, bool is_positive) { | 1249 bool is_horizontal, bool is_positive) { |
1246 return 0; | 1250 return 0; |
1247 } | 1251 } |
1248 | 1252 |
1249 //////////////////////////////////////////////////////////////////////////////// | 1253 //////////////////////////////////////////////////////////////////////////////// |
1250 // View, protected: | 1254 // View, protected: |
1251 | 1255 |
1252 // Size and disposition -------------------------------------------------------- | 1256 // Size and disposition -------------------------------------------------------- |
1253 | 1257 |
1254 void View::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 1258 void View::ChildPreferredSizeChanged(View* child) { |
| 1259 if (layout_manager_) |
| 1260 layout_manager_->OnChildPreferredSizeChanged(this, child); |
1255 } | 1261 } |
1256 | 1262 |
1257 void View::PreferredSizeChanged() { | 1263 void View::PreferredSizeChanged() { |
1258 InvalidateLayout(); | 1264 InvalidateLayout(); |
1259 if (parent_) | 1265 if (parent_) |
1260 parent_->ChildPreferredSizeChanged(this); | 1266 parent_->ChildPreferredSizeChanged(this); |
1261 } | 1267 } |
1262 | 1268 |
1263 bool View::NeedsNotificationWhenVisibleBoundsChange() const { | 1269 bool View::NeedsNotificationWhenVisibleBoundsChange() const { |
1264 return false; | 1270 return false; |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1815 } | 1821 } |
1816 | 1822 |
1817 void View::PropagateNativeThemeChanged(const ui::NativeTheme* theme) { | 1823 void View::PropagateNativeThemeChanged(const ui::NativeTheme* theme) { |
1818 for (int i = 0, count = child_count(); i < count; ++i) | 1824 for (int i = 0, count = child_count(); i < count; ++i) |
1819 child_at(i)->PropagateNativeThemeChanged(theme); | 1825 child_at(i)->PropagateNativeThemeChanged(theme); |
1820 OnNativeThemeChanged(theme); | 1826 OnNativeThemeChanged(theme); |
1821 } | 1827 } |
1822 | 1828 |
1823 // Size and disposition -------------------------------------------------------- | 1829 // Size and disposition -------------------------------------------------------- |
1824 | 1830 |
| 1831 void View::LayoutIfNeeded() { |
| 1832 if (needs_layout_) |
| 1833 Layout(); |
| 1834 } |
| 1835 |
1825 void View::PropagateVisibilityNotifications(View* start, bool is_visible) { | 1836 void View::PropagateVisibilityNotifications(View* start, bool is_visible) { |
1826 for (int i = 0, count = child_count(); i < count; ++i) | 1837 for (int i = 0, count = child_count(); i < count; ++i) |
1827 child_at(i)->PropagateVisibilityNotifications(start, is_visible); | 1838 child_at(i)->PropagateVisibilityNotifications(start, is_visible); |
1828 VisibilityChangedImpl(start, is_visible); | 1839 VisibilityChangedImpl(start, is_visible); |
1829 } | 1840 } |
1830 | 1841 |
1831 void View::VisibilityChangedImpl(View* starting_from, bool is_visible) { | 1842 void View::VisibilityChangedImpl(View* starting_from, bool is_visible) { |
1832 VisibilityChanged(starting_from, is_visible); | 1843 VisibilityChanged(starting_from, is_visible); |
1833 } | 1844 } |
1834 | 1845 |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2298 ConvertPointToWidget(this, &widget_location); | 2309 ConvertPointToWidget(this, &widget_location); |
2299 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations, | 2310 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations, |
2300 source); | 2311 source); |
2301 return true; | 2312 return true; |
2302 #else | 2313 #else |
2303 return false; | 2314 return false; |
2304 #endif // !defined(OS_MACOSX) | 2315 #endif // !defined(OS_MACOSX) |
2305 } | 2316 } |
2306 | 2317 |
2307 } // namespace views | 2318 } // namespace views |
OLD | NEW |