Chromium Code Reviews| 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 #include "ui/views/view.h" | 5 #include "ui/views/view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "third_party/skia/include/core/SkRect.h" | 15 #include "third_party/skia/include/core/SkRect.h" |
| 16 #include "ui/base/accessibility/accessibility_types.h" | 16 #include "ui/base/accessibility/accessibility_types.h" |
| 17 #include "ui/base/dragdrop/drag_drop_types.h" | 17 #include "ui/base/dragdrop/drag_drop_types.h" |
| 18 #include "ui/compositor/compositor.h" | 18 #include "ui/compositor/compositor.h" |
| 19 #include "ui/compositor/layer.h" | 19 #include "ui/compositor/layer.h" |
| 20 #include "ui/compositor/layer_animator.h" | 20 #include "ui/compositor/layer_animator.h" |
| 21 #include "ui/gfx/canvas.h" | 21 #include "ui/gfx/canvas.h" |
| 22 #include "ui/gfx/interpolated_transform.h" | 22 #include "ui/gfx/interpolated_transform.h" |
| 23 #include "ui/gfx/path.h" | 23 #include "ui/gfx/path.h" |
| 24 #include "ui/gfx/point3.h" | 24 #include "ui/gfx/point3.h" |
| 25 #include "ui/gfx/transform.h" | 25 #include "ui/gfx/transform.h" |
| 26 #include "ui/views/background.h" | 26 #include "ui/views/background.h" |
| 27 #include "ui/views/context_menu_controller.h" | 27 #include "ui/views/context_menu_controller.h" |
| 28 #include "ui/views/drag_controller.h" | 28 #include "ui/views/drag_controller.h" |
| 29 #include "ui/views/layout/layout_manager.h" | 29 #include "ui/views/layout/layout_manager.h" |
| 30 #include "ui/views/view_constants.h" | |
| 30 #include "ui/views/views_delegate.h" | 31 #include "ui/views/views_delegate.h" |
| 31 #include "ui/views/widget/native_widget_private.h" | 32 #include "ui/views/widget/native_widget_private.h" |
| 32 #include "ui/views/widget/root_view.h" | 33 #include "ui/views/widget/root_view.h" |
| 33 #include "ui/views/widget/tooltip_manager.h" | 34 #include "ui/views/widget/tooltip_manager.h" |
| 34 #include "ui/views/widget/widget.h" | 35 #include "ui/views/widget/widget.h" |
| 35 | 36 |
| 36 #if defined(OS_WIN) | 37 #if defined(OS_WIN) |
| 37 #include "base/win/scoped_gdi_object.h" | 38 #include "base/win/scoped_gdi_object.h" |
| 38 #include "ui/views/accessibility/native_view_accessibility_win.h" | 39 #include "ui/views/accessibility/native_view_accessibility_win.h" |
| 39 #endif | 40 #endif |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 }; | 74 }; |
| 74 | 75 |
| 75 // Returns the top view in |view|'s hierarchy. | 76 // Returns the top view in |view|'s hierarchy. |
| 76 const views::View* GetHierarchyRoot(const views::View* view) { | 77 const views::View* GetHierarchyRoot(const views::View* view) { |
| 77 const views::View* root = view; | 78 const views::View* root = view; |
| 78 while (root && root->parent()) | 79 while (root && root->parent()) |
| 79 root = root->parent(); | 80 root = root->parent(); |
| 80 return root; | 81 return root; |
| 81 } | 82 } |
| 82 | 83 |
| 84 // Returns the percentage of |rect1|'s area that is covered by |rect2|. | |
| 85 float PercentCoveredBy(const gfx::Rect& rect1, const gfx::Rect& rect2) { | |
| 86 gfx::Rect intersection(rect1.Intersect(rect2)); | |
| 87 float intersectionArea = intersection.width() * intersection.height(); | |
| 88 float rect1Area = rect1.width() * rect1.height(); | |
| 89 return intersectionArea / rect1Area; | |
| 90 } | |
|
sadrul
2012/07/16 22:16:14
I think this is fine ... but perhaps you could use
tdanderson
2012/07/17 19:07:07
Done.
| |
| 91 | |
| 92 int DistanceToInterval(int pos, int start, int end) { | |
| 93 if (pos < start) | |
| 94 return start - pos; | |
| 95 if (pos > end) | |
| 96 return end - pos; | |
| 97 return 0; | |
| 98 } | |
| 99 | |
| 100 int DistanceSquaredFromCenterLineToPoint(const gfx::Point& point, | |
|
sadrul
2012/07/16 22:16:14
document
tdanderson
2012/07/17 19:07:07
Done.
| |
| 101 const gfx::Rect& targetRect) { | |
| 102 gfx::Point centerPoint = targetRect.CenterPoint(); | |
| 103 int xdist = centerPoint.x() - point.x(); | |
| 104 int ydist = centerPoint.y() - point.y(); | |
| 105 | |
| 106 if (targetRect.width() > targetRect.height()) | |
|
sadrul
2012/07/16 22:16:14
braces
rjkroege
2012/07/16 23:35:48
Note how WebKit != Chrome. :-)
tdanderson
2012/07/17 19:07:07
Done.
tdanderson
2012/07/17 19:07:07
Done.
| |
| 107 xdist = DistanceToInterval(point.x(), | |
| 108 targetRect.x() + (targetRect.height() / 2), | |
| 109 targetRect.right() - (targetRect.height() / 2)); | |
| 110 else | |
| 111 ydist = DistanceToInterval(point.y(), | |
| 112 targetRect.y() + (targetRect.width() / 2), | |
| 113 targetRect.bottom() - (targetRect.width() / 2)); | |
| 114 | |
| 115 return (xdist * xdist) + (ydist * ydist); | |
| 116 } | |
| 117 | |
| 83 } // namespace | 118 } // namespace |
| 84 | 119 |
| 85 namespace views { | 120 namespace views { |
| 86 | 121 |
| 87 // static | 122 // static |
| 88 ViewsDelegate* ViewsDelegate::views_delegate = NULL; | 123 ViewsDelegate* ViewsDelegate::views_delegate = NULL; |
| 89 | 124 |
| 90 // static | 125 // static |
| 91 const char View::kViewClassName[] = "views/View"; | 126 const char View::kViewClassName[] = "views/View"; |
| 92 | 127 |
| (...skipping 1170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1263 DCHECK_EQ(parent_layer, layer()->parent()); | 1298 DCHECK_EQ(parent_layer, layer()->parent()); |
| 1264 parent_layer->StackAtTop(layer()); | 1299 parent_layer->StackAtTop(layer()); |
| 1265 } else { | 1300 } else { |
| 1266 for (Views::const_iterator i(children_.begin()); i != children_.end(); ++i) | 1301 for (Views::const_iterator i(children_.begin()); i != children_.end(); ++i) |
| 1267 (*i)->ReorderChildLayers(parent_layer); | 1302 (*i)->ReorderChildLayers(parent_layer); |
| 1268 } | 1303 } |
| 1269 } | 1304 } |
| 1270 | 1305 |
| 1271 // Input ----------------------------------------------------------------------- | 1306 // Input ----------------------------------------------------------------------- |
| 1272 | 1307 |
| 1308 void View::FindClosestOverlappedRect(const gfx::Rect& touchRect, | |
|
rjkroege
2012/07/16 23:35:48
This routine could conceivably explore many views.
tdanderson
2012/07/17 19:07:07
I tried to cut down the number of views explored a
| |
| 1309 gfx::Rect& closestOverlappedRect) { | |
| 1310 for (int i = child_count() - 1; i >= 0; --i) { | |
| 1311 View* child = child_at(i); | |
| 1312 | |
| 1313 if (!child->visible()) | |
| 1314 continue; | |
| 1315 | |
| 1316 gfx::Rect childRect(child->GetScreenBounds()); | |
|
sadrul
2012/07/16 22:16:14
child_rect etc.
Why ScreenBounds?
tdanderson
2012/07/17 19:07:07
It seems easiest to have everything in a common co
sadrul
2012/07/17 19:26:45
This sounds reasonable. Make sure the doc for the
tdanderson
2012/07/18 22:35:42
Done.
| |
| 1317 if (!childRect.Intersects(touchRect)) | |
| 1318 continue; | |
| 1319 | |
| 1320 if (PercentCoveredBy(childRect, touchRect) >= kFuzzingOverlapPercentage) { | |
| 1321 if (closestOverlappedRect.IsEmpty()) { | |
| 1322 closestOverlappedRect = childRect; | |
| 1323 } else { | |
| 1324 gfx::Point touchCenter(touchRect.CenterPoint()); | |
| 1325 int bestDistSoFar = DistanceSquaredFromCenterLineToPoint( | |
| 1326 touchCenter, | |
| 1327 closestOverlappedRect); | |
| 1328 int curDist = DistanceSquaredFromCenterLineToPoint(touchCenter, | |
| 1329 childRect); | |
| 1330 | |
| 1331 if (curDist < bestDistSoFar) | |
| 1332 closestOverlappedRect = childRect; | |
| 1333 } | |
| 1334 } | |
| 1335 | |
| 1336 child->FindClosestOverlappedRect(touchRect, closestOverlappedRect); | |
| 1337 } | |
|
sadrul
2012/07/16 22:16:14
indent is off.
tdanderson
2012/07/17 19:07:07
Done.
| |
| 1338 } | |
| 1339 | |
| 1273 bool View::HasHitTestMask() const { | 1340 bool View::HasHitTestMask() const { |
| 1274 return false; | 1341 return false; |
| 1275 } | 1342 } |
| 1276 | 1343 |
| 1277 void View::GetHitTestMask(gfx::Path* mask) const { | 1344 void View::GetHitTestMask(gfx::Path* mask) const { |
| 1278 DCHECK(mask); | 1345 DCHECK(mask); |
| 1279 } | 1346 } |
| 1280 | 1347 |
| 1281 // Focus ----------------------------------------------------------------------- | 1348 // Focus ----------------------------------------------------------------------- |
| 1282 | 1349 |
| (...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2105 gfx::Point widget_location(event.location()); | 2172 gfx::Point widget_location(event.location()); |
| 2106 ConvertPointToWidget(this, &widget_location); | 2173 ConvertPointToWidget(this, &widget_location); |
| 2107 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations); | 2174 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations); |
| 2108 return true; | 2175 return true; |
| 2109 #else | 2176 #else |
| 2110 return false; | 2177 return false; |
| 2111 #endif // !defined(OS_MACOSX) | 2178 #endif // !defined(OS_MACOSX) |
| 2112 } | 2179 } |
| 2113 | 2180 |
| 2114 } // namespace views | 2181 } // namespace views |
| OLD | NEW |