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 21 matching lines...) Expand all Loading... |
32 #include "ui/gfx/geometry/point3_f.h" | 32 #include "ui/gfx/geometry/point3_f.h" |
33 #include "ui/gfx/geometry/point_conversions.h" | 33 #include "ui/gfx/geometry/point_conversions.h" |
34 #include "ui/gfx/interpolated_transform.h" | 34 #include "ui/gfx/interpolated_transform.h" |
35 #include "ui/gfx/path.h" | 35 #include "ui/gfx/path.h" |
36 #include "ui/gfx/scoped_canvas.h" | 36 #include "ui/gfx/scoped_canvas.h" |
37 #include "ui/gfx/screen.h" | 37 #include "ui/gfx/screen.h" |
38 #include "ui/gfx/skia_util.h" | 38 #include "ui/gfx/skia_util.h" |
39 #include "ui/gfx/transform.h" | 39 #include "ui/gfx/transform.h" |
40 #include "ui/native_theme/native_theme.h" | 40 #include "ui/native_theme/native_theme.h" |
41 #include "ui/views/accessibility/native_view_accessibility.h" | 41 #include "ui/views/accessibility/native_view_accessibility.h" |
| 42 #include "ui/views/animation/ink_drop_delegate.h" |
42 #include "ui/views/background.h" | 43 #include "ui/views/background.h" |
43 #include "ui/views/border.h" | 44 #include "ui/views/border.h" |
44 #include "ui/views/context_menu_controller.h" | 45 #include "ui/views/context_menu_controller.h" |
45 #include "ui/views/drag_controller.h" | 46 #include "ui/views/drag_controller.h" |
46 #include "ui/views/focus/view_storage.h" | 47 #include "ui/views/focus/view_storage.h" |
47 #include "ui/views/layout/layout_manager.h" | 48 #include "ui/views/layout/layout_manager.h" |
48 #include "ui/views/views_delegate.h" | 49 #include "ui/views/views_delegate.h" |
49 #include "ui/views/widget/native_widget_private.h" | 50 #include "ui/views/widget/native_widget_private.h" |
50 #include "ui/views/widget/root_view.h" | 51 #include "ui/views/widget/root_view.h" |
51 #include "ui/views/widget/tooltip_manager.h" | 52 #include "ui/views/widget/tooltip_manager.h" |
(...skipping 22 matching lines...) Expand all Loading... |
74 const int kDefaultVerticalDragThreshold = 8; | 75 const int kDefaultVerticalDragThreshold = 8; |
75 | 76 |
76 // Returns the top view in |view|'s hierarchy. | 77 // Returns the top view in |view|'s hierarchy. |
77 const View* GetHierarchyRoot(const View* view) { | 78 const View* GetHierarchyRoot(const View* view) { |
78 const View* root = view; | 79 const View* root = view; |
79 while (root && root->parent()) | 80 while (root && root->parent()) |
80 root = root->parent(); | 81 root = root->parent(); |
81 return root; | 82 return root; |
82 } | 83 } |
83 | 84 |
| 85 // A stub InkDropDelegate implementation that always exists and does nothing. |
| 86 // A real InkDropDelegate descendant can be returned by a View's descendant via |
| 87 // GetInkDropDelegate(). |
| 88 class InkDropDelegateStub : public InkDropDelegate { |
| 89 public: |
| 90 InkDropDelegateStub() {} |
| 91 ~InkDropDelegateStub() override {} |
| 92 |
| 93 // InkDropDelegate: |
| 94 void SetInkDropSize(int large_size, |
| 95 int large_corner_radius, |
| 96 int small_size, |
| 97 int small_corner_radius) override {} |
| 98 void OnLayout() override {} |
| 99 void OnAction(InkDropState state) override {} |
| 100 |
| 101 private: |
| 102 DISALLOW_COPY_AND_ASSIGN(InkDropDelegateStub); |
| 103 }; |
| 104 |
| 105 static InkDropDelegateStub ink_drop_delegate_stub; |
| 106 |
84 } // namespace | 107 } // namespace |
85 | 108 |
86 // static | 109 // static |
87 const char View::kViewClassName[] = "View"; | 110 const char View::kViewClassName[] = "View"; |
88 | 111 |
89 //////////////////////////////////////////////////////////////////////////////// | 112 //////////////////////////////////////////////////////////////////////////////// |
90 // View, public: | 113 // View, public: |
91 | 114 |
92 // Creation and lifetime ------------------------------------------------------- | 115 // Creation and lifetime ------------------------------------------------------- |
93 | 116 |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 // just propagate the Layout() call down the hierarchy, so whoever receives | 534 // just propagate the Layout() call down the hierarchy, so whoever receives |
512 // the call can take appropriate action. | 535 // the call can take appropriate action. |
513 for (int i = 0, count = child_count(); i < count; ++i) { | 536 for (int i = 0, count = child_count(); i < count; ++i) { |
514 View* child = child_at(i); | 537 View* child = child_at(i); |
515 if (child->needs_layout_ || !layout_manager_.get()) { | 538 if (child->needs_layout_ || !layout_manager_.get()) { |
516 TRACE_EVENT1("views", "View::Layout", "class", child->GetClassName()); | 539 TRACE_EVENT1("views", "View::Layout", "class", child->GetClassName()); |
517 child->needs_layout_ = false; | 540 child->needs_layout_ = false; |
518 child->Layout(); | 541 child->Layout(); |
519 } | 542 } |
520 } | 543 } |
| 544 |
| 545 GetInkDropDelegate()->OnLayout(); |
521 } | 546 } |
522 | 547 |
523 void View::InvalidateLayout() { | 548 void View::InvalidateLayout() { |
524 // Always invalidate up. This is needed to handle the case of us already being | 549 // Always invalidate up. This is needed to handle the case of us already being |
525 // valid, but not our parent. | 550 // valid, but not our parent. |
526 needs_layout_ = true; | 551 needs_layout_ = true; |
527 if (parent_) | 552 if (parent_) |
528 parent_->InvalidateLayout(); | 553 parent_->InvalidateLayout(); |
529 } | 554 } |
530 | 555 |
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1247 } | 1272 } |
1248 | 1273 |
1249 void View::OnDragExited() { | 1274 void View::OnDragExited() { |
1250 } | 1275 } |
1251 | 1276 |
1252 int View::OnPerformDrop(const ui::DropTargetEvent& event) { | 1277 int View::OnPerformDrop(const ui::DropTargetEvent& event) { |
1253 return ui::DragDropTypes::DRAG_NONE; | 1278 return ui::DragDropTypes::DRAG_NONE; |
1254 } | 1279 } |
1255 | 1280 |
1256 void View::OnDragDone() { | 1281 void View::OnDragDone() { |
| 1282 GetInkDropDelegate()->OnAction(InkDropState::HIDDEN); |
1257 } | 1283 } |
1258 | 1284 |
1259 // static | 1285 // static |
1260 bool View::ExceededDragThreshold(const gfx::Vector2d& delta) { | 1286 bool View::ExceededDragThreshold(const gfx::Vector2d& delta) { |
1261 return (abs(delta.x()) > GetHorizontalDragThreshold() || | 1287 return (abs(delta.x()) > GetHorizontalDragThreshold() || |
1262 abs(delta.y()) > GetVerticalDragThreshold()); | 1288 abs(delta.y()) > GetVerticalDragThreshold()); |
1263 } | 1289 } |
1264 | 1290 |
1265 // Accessibility---------------------------------------------------------------- | 1291 // Accessibility---------------------------------------------------------------- |
1266 | 1292 |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1512 // Iterate backwards through the children so that a child with a layer | 1538 // Iterate backwards through the children so that a child with a layer |
1513 // which is further to the back is stacked above one which is further to | 1539 // which is further to the back is stacked above one which is further to |
1514 // the front. | 1540 // the front. |
1515 for (Views::reverse_iterator it(children_.rbegin()); | 1541 for (Views::reverse_iterator it(children_.rbegin()); |
1516 it != children_.rend(); ++it) { | 1542 it != children_.rend(); ++it) { |
1517 (*it)->ReorderChildLayers(parent_layer); | 1543 (*it)->ReorderChildLayers(parent_layer); |
1518 } | 1544 } |
1519 } | 1545 } |
1520 } | 1546 } |
1521 | 1547 |
| 1548 // Animations ---------------------------------------------------------------- |
| 1549 |
| 1550 InkDropDelegate* View::GetInkDropDelegate() const { |
| 1551 return &ink_drop_delegate_stub; |
| 1552 } |
| 1553 |
1522 // Input ----------------------------------------------------------------------- | 1554 // Input ----------------------------------------------------------------------- |
1523 | 1555 |
1524 View::DragInfo* View::GetDragInfo() { | 1556 View::DragInfo* View::GetDragInfo() { |
1525 return parent_ ? parent_->GetDragInfo() : NULL; | 1557 return parent_ ? parent_->GetDragInfo() : NULL; |
1526 } | 1558 } |
1527 | 1559 |
1528 // Focus ----------------------------------------------------------------------- | 1560 // Focus ----------------------------------------------------------------------- |
1529 | 1561 |
1530 void View::OnFocus() { | 1562 void View::OnFocus() { |
1531 // TODO(beng): Investigate whether it's possible for us to move this to | 1563 // TODO(beng): Investigate whether it's possible for us to move this to |
(...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2354 // Message the RootView to do the drag and drop. That way if we're removed | 2386 // Message the RootView to do the drag and drop. That way if we're removed |
2355 // the RootView can detect it and avoid calling us back. | 2387 // the RootView can detect it and avoid calling us back. |
2356 gfx::Point widget_location(event.location()); | 2388 gfx::Point widget_location(event.location()); |
2357 ConvertPointToWidget(this, &widget_location); | 2389 ConvertPointToWidget(this, &widget_location); |
2358 widget->RunShellDrag(this, data, widget_location, drag_operations, source); | 2390 widget->RunShellDrag(this, data, widget_location, drag_operations, source); |
2359 // WARNING: we may have been deleted. | 2391 // WARNING: we may have been deleted. |
2360 return true; | 2392 return true; |
2361 } | 2393 } |
2362 | 2394 |
2363 } // namespace views | 2395 } // namespace views |
OLD | NEW |