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

Side by Side Diff: ui/aura/test/event_generator.cc

Issue 8273040: Minimum size for aura window (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressd comment Created 9 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « ui/aura/test/event_generator.h ('k') | ui/aura/test/test_window_delegate.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/aura/test/event_generator.h"
6
7 #include "ui/aura/desktop.h"
8 #include "ui/aura/event.h"
9
10 namespace {
11
12 gfx::Point CenterOfWindowInDesktopCoordinate(aura::Window* window) {
13 gfx::Point center = window->bounds().CenterPoint();
14 aura::Desktop* desktop = aura::Desktop::GetInstance();
15 aura::Window::ConvertPointToWindow(
16 window->parent(), desktop->window(), &center);
17 return center;
18 }
19
20 } // namespace
21
22 namespace aura {
23 namespace test {
24
25 EventGenerator::EventGenerator() : flags_(0) {
26 }
27
28 EventGenerator::EventGenerator(const gfx::Point& point)
29 : flags_(0),
30 current_location_(point) {
31 }
32
33 EventGenerator::EventGenerator(Window* window)
34 : flags_(0),
35 current_location_(CenterOfWindowInDesktopCoordinate(window)) {
36 }
37
38 EventGenerator::~EventGenerator() {
39 }
40
41 void EventGenerator::ClickLeftButton() {
42 PressLeftButton();
43 ReleaseLeftButton();
44 }
45
46 void EventGenerator::PressLeftButton() {
47 if ((flags_ & ui::EF_LEFT_BUTTON_DOWN) == 0) {
48 flags_ |= ui::EF_LEFT_BUTTON_DOWN;
49 Dispatch(MouseEvent(ui::ET_MOUSE_PRESSED, current_location_, flags_));
50 }
51 }
52
53 void EventGenerator::ReleaseLeftButton() {
54 if (flags_ & ui::EF_LEFT_BUTTON_DOWN) {
55 flags_ ^= ui::EF_LEFT_BUTTON_DOWN;
56 Dispatch(MouseEvent(ui::ET_MOUSE_RELEASED, current_location_, 0));
57 }
58 }
59
60 void EventGenerator::MoveMouseTo(const gfx::Point& point) {
61 if (flags_ & ui::EF_LEFT_BUTTON_DOWN ) {
62 Dispatch(MouseEvent(
63 ui::ET_MOUSE_DRAGGED, current_location_.Middle(point), flags_));
64 Dispatch(MouseEvent(ui::ET_MOUSE_DRAGGED, point, flags_));
65 } else {
66 Dispatch(MouseEvent(
67 ui::ET_MOUSE_MOVED, current_location_.Middle(point), flags_));
68 Dispatch(MouseEvent(ui::ET_MOUSE_MOVED, point, flags_));
69 }
70 current_location_ = point;
71 }
72
73 void EventGenerator::DragMouseTo(const gfx::Point& point) {
74 PressLeftButton();
75 MoveMouseTo(point);
76 ReleaseLeftButton();
77 }
78
79 void EventGenerator::Dispatch(const Event& event) {
80 switch (event.type()) {
81 case ui::ET_KEY_PRESSED:
82 case ui::ET_KEY_RELEASED:
83 aura::Desktop::GetInstance()->OnKeyEvent(
84 *static_cast<const KeyEvent*>(&event));
85 break;
86 case ui::ET_MOUSE_PRESSED:
87 case ui::ET_MOUSE_DRAGGED:
88 case ui::ET_MOUSE_RELEASED:
89 case ui::ET_MOUSE_MOVED:
90 case ui::ET_MOUSE_ENTERED:
91 case ui::ET_MOUSE_EXITED:
92 case ui::ET_MOUSEWHEEL:
93 aura::Desktop::GetInstance()->OnMouseEvent(
94 *static_cast<const MouseEvent*>(&event));
95 break;
96 default:
97 NOTIMPLEMENTED();
98 break;
99 }
100 }
101
102 void EventGenerator::MoveMouseToCenterOf(Window* window) {
103 MoveMouseTo(CenterOfWindowInDesktopCoordinate(window));
104 }
105
106 } // namespace test
107 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/test/event_generator.h ('k') | ui/aura/test/test_window_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698