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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 }; | 149 }; |
150 | 150 |
151 } // namespace internal | 151 } // namespace internal |
152 | 152 |
153 // static | 153 // static |
154 ViewsDelegate* ViewsDelegate::views_delegate = NULL; | 154 ViewsDelegate* ViewsDelegate::views_delegate = NULL; |
155 | 155 |
156 // static | 156 // static |
157 const char View::kViewClassName[] = "views/View"; | 157 const char View::kViewClassName[] = "views/View"; |
158 | 158 |
| 159 ScopedMaybeLayout::ScopedMaybeLayout(views::View* view) : view_(view) { |
| 160 view_->InvalidateLayout(); |
| 161 } |
| 162 |
| 163 ScopedMaybeLayout::~ScopedMaybeLayout() { |
| 164 if (view_->needs_layout_) |
| 165 view_->Layout(); |
| 166 } |
| 167 |
159 //////////////////////////////////////////////////////////////////////////////// | 168 //////////////////////////////////////////////////////////////////////////////// |
160 // View, public: | 169 // View, public: |
161 | 170 |
162 // Creation and lifetime ------------------------------------------------------- | 171 // Creation and lifetime ------------------------------------------------------- |
163 | 172 |
164 View::View() | 173 View::View() |
165 : owned_by_client_(false), | 174 : owned_by_client_(false), |
166 id_(0), | 175 id_(0), |
167 group_(-1), | 176 group_(-1), |
168 parent_(NULL), | 177 parent_(NULL), |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 child->needs_layout_ = false; | 598 child->needs_layout_ = false; |
590 child->Layout(); | 599 child->Layout(); |
591 } | 600 } |
592 } | 601 } |
593 } | 602 } |
594 | 603 |
595 void View::InvalidateLayout() { | 604 void View::InvalidateLayout() { |
596 // Always invalidate up. This is needed to handle the case of us already being | 605 // Always invalidate up. This is needed to handle the case of us already being |
597 // valid, but not our parent. | 606 // valid, but not our parent. |
598 needs_layout_ = true; | 607 needs_layout_ = true; |
599 if (parent_) | 608 // if (parent_) |
600 parent_->InvalidateLayout(); | 609 // parent_->InvalidateLayout(); |
601 } | 610 } |
602 | 611 |
603 LayoutManager* View::GetLayoutManager() const { | 612 LayoutManager* View::GetLayoutManager() const { |
604 return layout_manager_.get(); | 613 return layout_manager_.get(); |
605 } | 614 } |
606 | 615 |
607 void View::SetLayoutManager(LayoutManager* layout_manager) { | 616 void View::SetLayoutManager(LayoutManager* layout_manager) { |
608 if (layout_manager_.get()) | 617 if (layout_manager_.get()) |
609 layout_manager_->Uninstalled(this); | 618 layout_manager_->Uninstalled(this); |
610 | 619 |
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1244 int View::GetLineScrollIncrement(ScrollView* scroll_view, | 1253 int View::GetLineScrollIncrement(ScrollView* scroll_view, |
1245 bool is_horizontal, bool is_positive) { | 1254 bool is_horizontal, bool is_positive) { |
1246 return 0; | 1255 return 0; |
1247 } | 1256 } |
1248 | 1257 |
1249 //////////////////////////////////////////////////////////////////////////////// | 1258 //////////////////////////////////////////////////////////////////////////////// |
1250 // View, protected: | 1259 // View, protected: |
1251 | 1260 |
1252 // Size and disposition -------------------------------------------------------- | 1261 // Size and disposition -------------------------------------------------------- |
1253 | 1262 |
1254 void View::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 1263 void View::ChildPreferredSizeChanged(View* child) { |
| 1264 if (layout_manager_) |
| 1265 layout_manager_->OnChildPreferredSizeChanged(this, child); |
1255 } | 1266 } |
1256 | 1267 |
1257 void View::PreferredSizeChanged() { | 1268 void View::PreferredSizeChanged() { |
1258 InvalidateLayout(); | 1269 ScopedMaybeLayout layout(this); |
| 1270 // InvalidateLayout(); |
1259 if (parent_) | 1271 if (parent_) |
1260 parent_->ChildPreferredSizeChanged(this); | 1272 parent_->ChildPreferredSizeChanged(this); |
| 1273 // if (needs_layout_) |
| 1274 // Layout(); |
1261 } | 1275 } |
1262 | 1276 |
1263 bool View::NeedsNotificationWhenVisibleBoundsChange() const { | 1277 bool View::NeedsNotificationWhenVisibleBoundsChange() const { |
1264 return false; | 1278 return false; |
1265 } | 1279 } |
1266 | 1280 |
1267 void View::OnVisibleBoundsChanged() { | 1281 void View::OnVisibleBoundsChanged() { |
1268 } | 1282 } |
1269 | 1283 |
1270 // Tree operations ------------------------------------------------------------- | 1284 // Tree operations ------------------------------------------------------------- |
(...skipping 1027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2298 ConvertPointToWidget(this, &widget_location); | 2312 ConvertPointToWidget(this, &widget_location); |
2299 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations, | 2313 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations, |
2300 source); | 2314 source); |
2301 return true; | 2315 return true; |
2302 #else | 2316 #else |
2303 return false; | 2317 return false; |
2304 #endif // !defined(OS_MACOSX) | 2318 #endif // !defined(OS_MACOSX) |
2305 } | 2319 } |
2306 | 2320 |
2307 } // namespace views | 2321 } // namespace views |
OLD | NEW |