Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(207)

Side by Side Diff: ui/views/view.cc

Issue 1411833006: Refactoring to make adding ink drop animations easier (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactor ink drop animations (comments in c/b/ui/views/) Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 23 matching lines...) Expand all
75 const int kDefaultVerticalDragThreshold = 8; 76 const int kDefaultVerticalDragThreshold = 8;
76 77
77 // Returns the top view in |view|'s hierarchy. 78 // Returns the top view in |view|'s hierarchy.
78 const View* GetHierarchyRoot(const View* view) { 79 const View* GetHierarchyRoot(const View* view) {
79 const View* root = view; 80 const View* root = view;
80 while (root && root->parent()) 81 while (root && root->parent())
81 root = root->parent(); 82 root = root->parent();
82 return root; 83 return root;
83 } 84 }
84 85
86 // A stub InkDropDelegate implementation that always exists and does nothing.
87 // A real InkDropDelegate descendant can be returned by a View's descendant via
88 // GetInkDropDelegate().
89 class InkDropDelegateStub : public InkDropDelegate {
90 public:
91 InkDropDelegateStub() {}
92 ~InkDropDelegateStub() override {}
93
94 // InkDropDelegate:
95 void SetInkDropSize(int large_size,
96 int large_corner_radius,
97 int small_size,
98 int small_corner_radius) override {}
99 void OnLayout() override {}
100 void OnAction(InkDropState state) override {}
101
102 private:
103 DISALLOW_COPY_AND_ASSIGN(InkDropDelegateStub);
104 };
105
106 static InkDropDelegateStub ink_drop_delegate_stub;
107
85 } // namespace 108 } // namespace
86 109
87 // static 110 // static
88 const char View::kViewClassName[] = "View"; 111 const char View::kViewClassName[] = "View";
89 112
90 //////////////////////////////////////////////////////////////////////////////// 113 ////////////////////////////////////////////////////////////////////////////////
91 // View, public: 114 // View, public:
92 115
93 // Creation and lifetime ------------------------------------------------------- 116 // Creation and lifetime -------------------------------------------------------
94 117
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 // just propagate the Layout() call down the hierarchy, so whoever receives 535 // just propagate the Layout() call down the hierarchy, so whoever receives
513 // the call can take appropriate action. 536 // the call can take appropriate action.
514 for (int i = 0, count = child_count(); i < count; ++i) { 537 for (int i = 0, count = child_count(); i < count; ++i) {
515 View* child = child_at(i); 538 View* child = child_at(i);
516 if (child->needs_layout_ || !layout_manager_.get()) { 539 if (child->needs_layout_ || !layout_manager_.get()) {
517 TRACE_EVENT1("views", "View::Layout", "class", child->GetClassName()); 540 TRACE_EVENT1("views", "View::Layout", "class", child->GetClassName());
518 child->needs_layout_ = false; 541 child->needs_layout_ = false;
519 child->Layout(); 542 child->Layout();
520 } 543 }
521 } 544 }
545
546 GetInkDropDelegate()->OnLayout();
522 } 547 }
523 548
524 void View::InvalidateLayout() { 549 void View::InvalidateLayout() {
525 // Always invalidate up. This is needed to handle the case of us already being 550 // Always invalidate up. This is needed to handle the case of us already being
526 // valid, but not our parent. 551 // valid, but not our parent.
527 needs_layout_ = true; 552 needs_layout_ = true;
528 if (parent_) 553 if (parent_)
529 parent_->InvalidateLayout(); 554 parent_->InvalidateLayout();
530 } 555 }
531 556
(...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after
1258 } 1283 }
1259 1284
1260 void View::OnDragExited() { 1285 void View::OnDragExited() {
1261 } 1286 }
1262 1287
1263 int View::OnPerformDrop(const ui::DropTargetEvent& event) { 1288 int View::OnPerformDrop(const ui::DropTargetEvent& event) {
1264 return ui::DragDropTypes::DRAG_NONE; 1289 return ui::DragDropTypes::DRAG_NONE;
1265 } 1290 }
1266 1291
1267 void View::OnDragDone() { 1292 void View::OnDragDone() {
1293 GetInkDropDelegate()->OnAction(InkDropState::HIDDEN);
1268 } 1294 }
1269 1295
1270 // static 1296 // static
1271 bool View::ExceededDragThreshold(const gfx::Vector2d& delta) { 1297 bool View::ExceededDragThreshold(const gfx::Vector2d& delta) {
1272 return (abs(delta.x()) > GetHorizontalDragThreshold() || 1298 return (abs(delta.x()) > GetHorizontalDragThreshold() ||
1273 abs(delta.y()) > GetVerticalDragThreshold()); 1299 abs(delta.y()) > GetVerticalDragThreshold());
1274 } 1300 }
1275 1301
1276 // Accessibility---------------------------------------------------------------- 1302 // Accessibility----------------------------------------------------------------
1277 1303
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1523 // Iterate backwards through the children so that a child with a layer 1549 // Iterate backwards through the children so that a child with a layer
1524 // which is further to the back is stacked above one which is further to 1550 // which is further to the back is stacked above one which is further to
1525 // the front. 1551 // the front.
1526 for (Views::reverse_iterator it(children_.rbegin()); 1552 for (Views::reverse_iterator it(children_.rbegin());
1527 it != children_.rend(); ++it) { 1553 it != children_.rend(); ++it) {
1528 (*it)->ReorderChildLayers(parent_layer); 1554 (*it)->ReorderChildLayers(parent_layer);
1529 } 1555 }
1530 } 1556 }
1531 } 1557 }
1532 1558
1559 // Animations ----------------------------------------------------------------
1560
1561 InkDropDelegate* View::GetInkDropDelegate() const {
1562 return &ink_drop_delegate_stub;
1563 }
1564
1533 // Input ----------------------------------------------------------------------- 1565 // Input -----------------------------------------------------------------------
1534 1566
1535 View::DragInfo* View::GetDragInfo() { 1567 View::DragInfo* View::GetDragInfo() {
1536 return parent_ ? parent_->GetDragInfo() : NULL; 1568 return parent_ ? parent_->GetDragInfo() : NULL;
1537 } 1569 }
1538 1570
1539 // Focus ----------------------------------------------------------------------- 1571 // Focus -----------------------------------------------------------------------
1540 1572
1541 void View::OnFocus() { 1573 void View::OnFocus() {
1542 // TODO(beng): Investigate whether it's possible for us to move this to 1574 // 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
2365 // Message the RootView to do the drag and drop. That way if we're removed 2397 // Message the RootView to do the drag and drop. That way if we're removed
2366 // the RootView can detect it and avoid calling us back. 2398 // the RootView can detect it and avoid calling us back.
2367 gfx::Point widget_location(event.location()); 2399 gfx::Point widget_location(event.location());
2368 ConvertPointToWidget(this, &widget_location); 2400 ConvertPointToWidget(this, &widget_location);
2369 widget->RunShellDrag(this, data, widget_location, drag_operations, source); 2401 widget->RunShellDrag(this, data, widget_location, drag_operations, source);
2370 // WARNING: we may have been deleted. 2402 // WARNING: we may have been deleted.
2371 return true; 2403 return true;
2372 } 2404 }
2373 2405
2374 } // namespace views 2406 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698