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 1356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1367 *layer_parent = layer(); | 1367 *layer_parent = layer(); |
1368 return gfx::Vector2d(); | 1368 return gfx::Vector2d(); |
1369 } | 1369 } |
1370 if (!parent_) | 1370 if (!parent_) |
1371 return gfx::Vector2d(); | 1371 return gfx::Vector2d(); |
1372 | 1372 |
1373 return gfx::Vector2d(GetMirroredX(), y()) + | 1373 return gfx::Vector2d(GetMirroredX(), y()) + |
1374 parent_->CalculateOffsetToAncestorWithLayer(layer_parent); | 1374 parent_->CalculateOffsetToAncestorWithLayer(layer_parent); |
1375 } | 1375 } |
1376 | 1376 |
| 1377 void View::UpdateParentLayer() { |
| 1378 if (!layer()) |
| 1379 return; |
| 1380 |
| 1381 ui::Layer* parent_layer = NULL; |
| 1382 gfx::Vector2d offset(GetMirroredX(), y()); |
| 1383 |
| 1384 if (parent_) |
| 1385 offset += parent_->CalculateOffsetToAncestorWithLayer(&parent_layer); |
| 1386 |
| 1387 ReparentLayer(offset, parent_layer); |
| 1388 } |
| 1389 |
1377 void View::MoveLayerToParent(ui::Layer* parent_layer, | 1390 void View::MoveLayerToParent(ui::Layer* parent_layer, |
1378 const gfx::Point& point) { | 1391 const gfx::Point& point) { |
1379 gfx::Point local_point(point); | 1392 gfx::Point local_point(point); |
1380 if (parent_layer != layer()) | 1393 if (parent_layer != layer()) |
1381 local_point.Offset(GetMirroredX(), y()); | 1394 local_point.Offset(GetMirroredX(), y()); |
1382 if (layer() && parent_layer != layer()) { | 1395 if (layer() && parent_layer != layer()) { |
1383 parent_layer->Add(layer()); | 1396 parent_layer->Add(layer()); |
1384 SetLayerBounds(gfx::Rect(local_point.x(), local_point.y(), | 1397 SetLayerBounds(gfx::Rect(local_point.x(), local_point.y(), |
1385 width(), height())); | 1398 width(), height())); |
1386 } else { | 1399 } else { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1432 | 1445 |
1433 base::Closure View::PrepareForLayerBoundsChange() { | 1446 base::Closure View::PrepareForLayerBoundsChange() { |
1434 return base::Closure(); | 1447 return base::Closure(); |
1435 } | 1448 } |
1436 | 1449 |
1437 void View::ReorderLayers() { | 1450 void View::ReorderLayers() { |
1438 View* v = this; | 1451 View* v = this; |
1439 while (v && !v->layer()) | 1452 while (v && !v->layer()) |
1440 v = v->parent(); | 1453 v = v->parent(); |
1441 | 1454 |
1442 // Forward to widget in case we're in a NativeWidgetAura. | |
1443 if (!v) { | 1455 if (!v) { |
1444 if (GetWidget()) | 1456 Widget* widget = GetWidget(); |
1445 GetWidget()->ReorderLayers(); | 1457 if (widget) { |
| 1458 ui::Layer* layer = widget->GetLayer(); |
| 1459 if (layer) |
| 1460 widget->GetRootView()->ReorderChildLayers(layer); |
| 1461 } |
1446 } else { | 1462 } else { |
1447 for (Views::const_iterator i(v->children_.begin()); | 1463 v->ReorderChildLayers(v->layer()); |
1448 i != v->children_.end(); | |
1449 ++i) | |
1450 (*i)->ReorderChildLayers(v->layer()); | |
1451 } | 1464 } |
1452 } | 1465 } |
1453 | 1466 |
1454 void View::ReorderChildLayers(ui::Layer* parent_layer) { | 1467 void View::ReorderChildLayers(ui::Layer* parent_layer) { |
1455 if (layer()) { | 1468 if (layer() && layer() != parent_layer) { |
1456 DCHECK_EQ(parent_layer, layer()->parent()); | 1469 DCHECK_EQ(parent_layer, layer()->parent()); |
1457 parent_layer->StackAtTop(layer()); | 1470 parent_layer->StackAtTop(layer()); |
1458 } else { | 1471 } else { |
1459 for (Views::const_iterator i(children_.begin()); i != children_.end(); ++i) | 1472 for (Views::const_iterator i(children_.begin()); i != children_.end(); ++i) |
1460 (*i)->ReorderChildLayers(parent_layer); | 1473 (*i)->ReorderChildLayers(parent_layer); |
1461 } | 1474 } |
1462 } | 1475 } |
1463 | 1476 |
1464 // Input ----------------------------------------------------------------------- | 1477 // Input ----------------------------------------------------------------------- |
1465 | 1478 |
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2013 void View::UpdateParentLayers() { | 2026 void View::UpdateParentLayers() { |
2014 // Attach all top-level un-parented layers. | 2027 // Attach all top-level un-parented layers. |
2015 if (layer() && !layer()->parent()) { | 2028 if (layer() && !layer()->parent()) { |
2016 UpdateParentLayer(); | 2029 UpdateParentLayer(); |
2017 } else { | 2030 } else { |
2018 for (int i = 0, count = child_count(); i < count; ++i) | 2031 for (int i = 0, count = child_count(); i < count; ++i) |
2019 child_at(i)->UpdateParentLayers(); | 2032 child_at(i)->UpdateParentLayers(); |
2020 } | 2033 } |
2021 } | 2034 } |
2022 | 2035 |
2023 void View::UpdateParentLayer() { | |
2024 if (!layer()) | |
2025 return; | |
2026 | |
2027 ui::Layer* parent_layer = NULL; | |
2028 gfx::Vector2d offset(GetMirroredX(), y()); | |
2029 | |
2030 // TODO(sad): The NULL check here for parent_ essentially is to check if this | |
2031 // is the RootView. Instead of doing this, this function should be made | |
2032 // virtual and overridden from the RootView. | |
2033 if (parent_) | |
2034 offset += parent_->CalculateOffsetToAncestorWithLayer(&parent_layer); | |
2035 else if (!parent_ && GetWidget()) | |
2036 offset += GetWidget()->CalculateOffsetToAncestorWithLayer(&parent_layer); | |
2037 | |
2038 ReparentLayer(offset, parent_layer); | |
2039 } | |
2040 | |
2041 void View::OrphanLayers() { | 2036 void View::OrphanLayers() { |
2042 if (layer()) { | 2037 if (layer()) { |
2043 if (layer()->parent()) | 2038 if (layer()->parent()) |
2044 layer()->parent()->Remove(layer()); | 2039 layer()->parent()->Remove(layer()); |
2045 | 2040 |
2046 // The layer belonging to this View has already been orphaned. It is not | 2041 // The layer belonging to this View has already been orphaned. It is not |
2047 // necessary to orphan the child layers. | 2042 // necessary to orphan the child layers. |
2048 return; | 2043 return; |
2049 } | 2044 } |
2050 for (int i = 0, count = child_count(); i < count; ++i) | 2045 for (int i = 0, count = child_count(); i < count; ++i) |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2298 ConvertPointToWidget(this, &widget_location); | 2293 ConvertPointToWidget(this, &widget_location); |
2299 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations, | 2294 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations, |
2300 source); | 2295 source); |
2301 return true; | 2296 return true; |
2302 #else | 2297 #else |
2303 return false; | 2298 return false; |
2304 #endif // !defined(OS_MACOSX) | 2299 #endif // !defined(OS_MACOSX) |
2305 } | 2300 } |
2306 | 2301 |
2307 } // namespace views | 2302 } // namespace views |
OLD | NEW |