| 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. |
| 6 |
| 5 #include "ui/views/view.h" | 7 #include "ui/views/view.h" |
| 6 | 8 |
| 7 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <cmath> |
| 8 | 11 |
| 9 #include "base/debug/trace_event.h" | 12 #include "base/debug/trace_event.h" |
| 10 #include "base/logging.h" | 13 #include "base/logging.h" |
| 11 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
| 13 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
| 14 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
| 15 #include "third_party/skia/include/core/SkRect.h" | 18 #include "third_party/skia/include/core/SkRect.h" |
| 16 #include "ui/base/accessibility/accessibility_types.h" | 19 #include "ui/base/accessibility/accessibility_types.h" |
| 17 #include "ui/base/dragdrop/drag_drop_types.h" | 20 #include "ui/base/dragdrop/drag_drop_types.h" |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 gfx::Rect View::GetVisibleBounds() const { | 328 gfx::Rect View::GetVisibleBounds() const { |
| 326 if (!IsDrawn()) | 329 if (!IsDrawn()) |
| 327 return gfx::Rect(); | 330 return gfx::Rect(); |
| 328 gfx::Rect vis_bounds(GetLocalBounds()); | 331 gfx::Rect vis_bounds(GetLocalBounds()); |
| 329 gfx::Rect ancestor_bounds; | 332 gfx::Rect ancestor_bounds; |
| 330 const View* view = this; | 333 const View* view = this; |
| 331 gfx::Transform transform; | 334 gfx::Transform transform; |
| 332 | 335 |
| 333 while (view != NULL && !vis_bounds.IsEmpty()) { | 336 while (view != NULL && !vis_bounds.IsEmpty()) { |
| 334 transform.ConcatTransform(view->GetTransform()); | 337 transform.ConcatTransform(view->GetTransform()); |
| 335 transform.ConcatTranslate(static_cast<float>(view->GetMirroredX()), | 338 gfx::Transform translation; |
| 336 static_cast<float>(view->y())); | 339 translation.Translate(static_cast<float>(view->GetMirroredX()), |
| 340 static_cast<float>(view->y())); |
| 341 transform.ConcatTransform(translation); |
| 337 | 342 |
| 338 vis_bounds = view->ConvertRectToParent(vis_bounds); | 343 vis_bounds = view->ConvertRectToParent(vis_bounds); |
| 339 const View* ancestor = view->parent_; | 344 const View* ancestor = view->parent_; |
| 340 if (ancestor != NULL) { | 345 if (ancestor != NULL) { |
| 341 ancestor_bounds.SetRect(0, 0, ancestor->width(), ancestor->height()); | 346 ancestor_bounds.SetRect(0, 0, ancestor->width(), ancestor->height()); |
| 342 vis_bounds.Intersect(ancestor_bounds); | 347 vis_bounds.Intersect(ancestor_bounds); |
| 343 } else if (!view->GetWidget()) { | 348 } else if (!view->GetWidget()) { |
| 344 // If the view has no Widget, we're not visible. Return an empty rect. | 349 // If the view has no Widget, we're not visible. Return an empty rect. |
| 345 return gfx::Rect(); | 350 return gfx::Rect(); |
| 346 } | 351 } |
| (...skipping 1078 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1425 | 1430 |
| 1426 base::snprintf(bounds_buffer, | 1431 base::snprintf(bounds_buffer, |
| 1427 arraysize(bounds_buffer), | 1432 arraysize(bounds_buffer), |
| 1428 "\\n bounds: (%d, %d), (%dx%d)", | 1433 "\\n bounds: (%d, %d), (%dx%d)", |
| 1429 bounds().x(), | 1434 bounds().x(), |
| 1430 bounds().y(), | 1435 bounds().y(), |
| 1431 bounds().width(), | 1436 bounds().width(), |
| 1432 bounds().height()); | 1437 bounds().height()); |
| 1433 result.append(bounds_buffer); | 1438 result.append(bounds_buffer); |
| 1434 | 1439 |
| 1435 if (!GetTransform().IsIdentity()) { | 1440 gfx::DecomposedTransform decomp; |
| 1436 gfx::Point translation; | 1441 if (!GetTransform().IsIdentity() && |
| 1437 float rotation; | 1442 gfx::DecomposeTransform(&decomp, GetTransform())) { |
| 1438 gfx::Point3F scale; | 1443 base::snprintf(bounds_buffer, |
| 1439 if (ui::InterpolatedTransform::FactorTRS(GetTransform(), | 1444 arraysize(bounds_buffer), |
| 1440 &translation, | 1445 "\\n translation: (%f, %f)", |
| 1441 &rotation, | 1446 decomp.translate[0], |
| 1442 &scale)) { | 1447 decomp.translate[1]); |
| 1443 if (!translation.IsOrigin()) { | 1448 result.append(bounds_buffer); |
| 1444 base::snprintf(bounds_buffer, | |
| 1445 arraysize(bounds_buffer), | |
| 1446 "\\n translation: (%d, %d)", | |
| 1447 translation.x(), | |
| 1448 translation.y()); | |
| 1449 result.append(bounds_buffer); | |
| 1450 } | |
| 1451 | 1449 |
| 1452 if (fabs(rotation) > 1e-5) { | 1450 base::snprintf(bounds_buffer, |
| 1453 base::snprintf(bounds_buffer, | 1451 arraysize(bounds_buffer), |
| 1454 arraysize(bounds_buffer), | 1452 "\\n rotation: %3.2f", |
| 1455 "\\n rotation: %3.2f", rotation); | 1453 std::acos(decomp.quaternion[3]) * 360.0 / M_PI); |
| 1456 result.append(bounds_buffer); | 1454 result.append(bounds_buffer); |
| 1457 } | |
| 1458 | 1455 |
| 1459 if (!gfx::ToFlooredPoint(scale.AsPointF()).IsOrigin()) { | 1456 base::snprintf(bounds_buffer, |
| 1460 base::snprintf(bounds_buffer, | 1457 arraysize(bounds_buffer), |
| 1461 arraysize(bounds_buffer), | 1458 "\\n scale: (%2.4f, %2.4f)", |
| 1462 "\\n scale: (%2.4f, %2.4f)", | 1459 decomp.scale[0], |
| 1463 scale.x(), | 1460 decomp.scale[1]); |
| 1464 scale.y()); | 1461 result.append(bounds_buffer); |
| 1465 result.append(bounds_buffer); | |
| 1466 } | |
| 1467 } | |
| 1468 } | 1462 } |
| 1469 | 1463 |
| 1470 result.append("\""); | 1464 result.append("\""); |
| 1471 if (!parent_) | 1465 if (!parent_) |
| 1472 result.append(", shape=box"); | 1466 result.append(", shape=box"); |
| 1473 if (layer()) { | 1467 if (layer()) { |
| 1474 if (layer()->texture()) | 1468 if (layer()->texture()) |
| 1475 result.append(", color=green"); | 1469 result.append(", color=green"); |
| 1476 else | 1470 else |
| 1477 result.append(", color=red"); | 1471 result.append(", color=red"); |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1791 } | 1785 } |
| 1792 | 1786 |
| 1793 // Transformations ------------------------------------------------------------- | 1787 // Transformations ------------------------------------------------------------- |
| 1794 | 1788 |
| 1795 bool View::GetTransformRelativeTo(const View* ancestor, | 1789 bool View::GetTransformRelativeTo(const View* ancestor, |
| 1796 gfx::Transform* transform) const { | 1790 gfx::Transform* transform) const { |
| 1797 const View* p = this; | 1791 const View* p = this; |
| 1798 | 1792 |
| 1799 while (p && p != ancestor) { | 1793 while (p && p != ancestor) { |
| 1800 transform->ConcatTransform(p->GetTransform()); | 1794 transform->ConcatTransform(p->GetTransform()); |
| 1801 transform->ConcatTranslate(static_cast<float>(p->GetMirroredX()), | 1795 gfx::Transform translation; |
| 1802 static_cast<float>(p->y())); | 1796 translation.Translate(static_cast<float>(p->GetMirroredX()), |
| 1797 static_cast<float>(p->y())); |
| 1798 transform->ConcatTransform(translation); |
| 1803 | 1799 |
| 1804 p = p->parent_; | 1800 p = p->parent_; |
| 1805 } | 1801 } |
| 1806 | 1802 |
| 1807 return p == ancestor; | 1803 return p == ancestor; |
| 1808 } | 1804 } |
| 1809 | 1805 |
| 1810 // Coordinate conversion ------------------------------------------------------- | 1806 // Coordinate conversion ------------------------------------------------------- |
| 1811 | 1807 |
| 1812 bool View::ConvertPointForAncestor(const View* ancestor, | 1808 bool View::ConvertPointForAncestor(const View* ancestor, |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2156 ConvertPointToWidget(this, &widget_location); | 2152 ConvertPointToWidget(this, &widget_location); |
| 2157 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations, | 2153 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations, |
| 2158 source); | 2154 source); |
| 2159 return true; | 2155 return true; |
| 2160 #else | 2156 #else |
| 2161 return false; | 2157 return false; |
| 2162 #endif // !defined(OS_MACOSX) | 2158 #endif // !defined(OS_MACOSX) |
| 2163 } | 2159 } |
| 2164 | 2160 |
| 2165 } // namespace views | 2161 } // namespace views |
| OLD | NEW |