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

Side by Side Diff: chrome/test/base/interactive_test_utils_mac.mm

Issue 1747803003: MacViews: Implement Tab Dragging (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix review issues. Created 4 years, 6 months 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 #include "chrome/test/base/interactive_test_utils.h" 5 #include "chrome/test/base/interactive_test_utils.h"
6 6
7 #include <Carbon/Carbon.h> 7 #include <Carbon/Carbon.h>
8 #import <Cocoa/Cocoa.h> 8 #import <Cocoa/Cocoa.h>
9 9
10 #include "base/message_loop/message_loop.h"
11 #include "chrome/app/chrome_command_ids.h" 10 #include "chrome/app/chrome_command_ids.h"
12 #import "ui/base/test/windowed_nsnotification_observer.h" 11 #import "ui/base/test/windowed_nsnotification_observer.h"
12 #include "ui/gfx/animation/tween.h"
13 13
14 namespace ui_test_utils { 14 namespace ui_test_utils {
15 15
16 namespace {
17
18 // Runs a list of drag and drop |operations| on a single RunLoop.
19 //
20 // We need to execute drag and drop operations as a batch, so the nested
21 // RunMoveLoop()'s RunLoop is cancelled before the top-level one from which we
22 // post the simulated events, otherwise we'll deadlock.
23 class OperationRunner {
24 public:
25 static void Run(const std::list<DragAndDropOperation>& operations) {
26 OperationRunner runner(operations);
27 base::RunLoop run_loop;
28 runner.quit_closure_ = run_loop.QuitClosure();
29 base::MessageLoop::current()->PostTask(
30 FROM_HERE,
31 base::Bind(&OperationRunner::Next, base::Unretained(&runner)));
32 run_loop.Run();
33 }
34
35 private:
36 explicit OperationRunner(const std::list<DragAndDropOperation>& operations)
37 : operations_(operations) {}
38
39 void Next() {
40 if (operations_.empty()) {
41 base::MessageLoop::current()->PostTask(FROM_HERE, quit_closure_);
42 return;
43 }
44
45 const DragAndDropOperation op = operations_.front();
46 operations_.pop_front();
47 auto next = base::Bind(&OperationRunner::Next, base::Unretained(this));
48 switch (op.type()) {
49 case DragAndDropOperation::Type::Move:
50 ui_controls::SendMouseMoveNotifyWhenDone(op.point().x(), op.point().y(),
51 next);
52 break;
53
54 case DragAndDropOperation::Type::MouseDown:
55 ui_controls::SendMouseEventsNotifyWhenDone(ui_controls::LEFT,
56 ui_controls::DOWN, next);
57 break;
58
59 case DragAndDropOperation::Type::MouseUp:
60 ui_controls::SendMouseEventsNotifyWhenDone(ui_controls::LEFT,
61 ui_controls::UP, next);
62 break;
63 }
64 }
65
66 ~OperationRunner() { DCHECK(operations_.empty()); }
67
68 base::Closure quit_closure_;
69 std::list<DragAndDropOperation> operations_;
70
71 DISALLOW_COPY_AND_ASSIGN(OperationRunner);
72 };
73
74 } // namespace
75
76 // static
77 DragAndDropOperation DragAndDropOperation::Move(const gfx::Point& p) {
78 return DragAndDropOperation(Type::Move, p);
79 }
80
81 // static
82 DragAndDropOperation DragAndDropOperation::MouseDown() {
83 return DragAndDropOperation(Type::MouseDown, gfx::Point());
84 }
85
86 // static
87 DragAndDropOperation DragAndDropOperation::MouseUp() {
88 return DragAndDropOperation(Type::MouseUp, gfx::Point());
89 }
90
91 void DragAndDropSequence(const std::list<DragAndDropOperation>& operations) {
92 OperationRunner::Run(operations);
93 }
94
95 void DragAndDrop(const gfx::Point& from, const gfx::Point& to, int steps) {
96 DCHECK_GE(steps, 1);
97 std::list<DragAndDropOperation> operations;
98 operations.push_back(DragAndDropOperation::Move(from));
99 operations.push_back(DragAndDropOperation::MouseDown());
100
101 for (int i = 1; i <= steps; ++i) {
102 const double progress = static_cast<double>(i) / steps;
103 operations.push_back(DragAndDropOperation::Move(
104 gfx::Point(gfx::Tween::IntValueBetween(progress, from.x(), to.x()),
105 gfx::Tween::IntValueBetween(progress, from.y(), to.y()))));
106 }
107
108 operations.push_back(DragAndDropOperation::MouseUp());
109 DragAndDropSequence(operations);
110 }
111
16 void HideNativeWindow(gfx::NativeWindow window) { 112 void HideNativeWindow(gfx::NativeWindow window) {
17 [window orderOut:nil]; 113 [window orderOut:nil];
18 } 114 }
19 115
20 bool ShowAndFocusNativeWindow(gfx::NativeWindow window) { 116 bool ShowAndFocusNativeWindow(gfx::NativeWindow window) {
21 // Make sure an unbundled program can get the input focus. 117 // Make sure an unbundled program can get the input focus.
22 ProcessSerialNumber psn = { 0, kCurrentProcess }; 118 ProcessSerialNumber psn = { 0, kCurrentProcess };
23 TransformProcessType(&psn,kProcessTransformToForegroundApplication); 119 TransformProcessType(&psn,kProcessTransformToForegroundApplication);
24 SetFrontProcess(&psn); 120 SetFrontProcess(&psn);
25 121
(...skipping 12 matching lines...) Expand all
38 // events are sent via ui_test_utils::SendKeyPressSync. 134 // events are sent via ui_test_utils::SendKeyPressSync.
39 BOOL notification_observed = [async_waiter wait]; 135 BOOL notification_observed = [async_waiter wait];
40 base::RunLoop().RunUntilIdle(); // There may be other events queued. Flush. 136 base::RunLoop().RunUntilIdle(); // There may be other events queued. Flush.
41 NSMenu* file_menu = [[[NSApp mainMenu] itemWithTag:IDC_FILE_MENU] submenu]; 137 NSMenu* file_menu = [[[NSApp mainMenu] itemWithTag:IDC_FILE_MENU] submenu];
42 [[file_menu delegate] menuNeedsUpdate:file_menu]; 138 [[file_menu delegate] menuNeedsUpdate:file_menu];
43 139
44 return !async_waiter || notification_observed; 140 return !async_waiter || notification_observed;
45 } 141 }
46 142
47 } // namespace ui_test_utils 143 } // namespace ui_test_utils
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698