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

Side by Side Diff: ash/wm/workspace/workspace_event_handler.cc

Issue 2285703003: Moves WorkspaceEventHandler to ash/common (Closed)
Patch Set: merge to tip of tree Created 4 years, 3 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ash/wm/workspace/workspace_event_handler.h"
6
7 #include "ash/aura/wm_window_aura.h"
8 #include "ash/common/wm/window_state.h"
9 #include "ash/common/wm/wm_event.h"
10 #include "ash/common/wm_shell.h"
11 #include "ash/common/wm_window.h"
12 #include "ash/wm/window_state_aura.h"
13 #include "ui/aura/window.h"
14 #include "ui/aura/window_delegate.h"
15 #include "ui/base/hit_test.h"
16 #include "ui/events/event.h"
17
18 namespace ash {
19
20 WorkspaceEventHandler::WorkspaceEventHandler() : click_component_(HTNOWHERE) {}
21
22 WorkspaceEventHandler::~WorkspaceEventHandler() {}
23
24 void WorkspaceEventHandler::OnMouseEvent(ui::MouseEvent* event) {
25 aura::Window* target = static_cast<aura::Window*>(event->target());
26 if (event->type() == ui::ET_MOUSE_PRESSED && event->IsOnlyLeftMouseButton() &&
27 ((event->flags() & (ui::EF_IS_DOUBLE_CLICK | ui::EF_IS_TRIPLE_CLICK)) ==
28 0)) {
29 click_component_ =
30 target->delegate()->GetNonClientComponent(event->location());
31 }
32
33 if (event->handled())
34 return;
35
36 switch (event->type()) {
37 case ui::ET_MOUSE_MOVED: {
38 int component =
39 target->delegate()->GetNonClientComponent(event->location());
40 multi_window_resize_controller_.Show(WmWindowAura::Get(target), component,
41 event->location());
42 break;
43 }
44 case ui::ET_MOUSE_ENTERED:
45 break;
46 case ui::ET_MOUSE_CAPTURE_CHANGED:
47 case ui::ET_MOUSE_EXITED:
48 break;
49 case ui::ET_MOUSE_PRESSED: {
50 wm::WindowState* target_state = wm::GetWindowState(target);
51
52 if (event->IsOnlyLeftMouseButton()) {
53 if (event->flags() & ui::EF_IS_DOUBLE_CLICK) {
54 int component =
55 target->delegate()->GetNonClientComponent(event->location());
56 if (component == HTCAPTION && component == click_component_) {
57 WmShell::Get()->RecordUserMetricsAction(
58 UMA_TOGGLE_MAXIMIZE_CAPTION_CLICK);
59 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION);
60 target_state->OnWMEvent(&wm_event);
61 event->StopPropagation();
62 }
63 click_component_ = HTNOWHERE;
64 }
65 } else {
66 click_component_ = HTNOWHERE;
67 }
68
69 HandleVerticalResizeDoubleClick(target_state, event);
70 break;
71 }
72 default:
73 break;
74 }
75 }
76
77 void WorkspaceEventHandler::OnGestureEvent(ui::GestureEvent* event) {
78 if (event->handled() || event->type() != ui::ET_GESTURE_TAP)
79 return;
80
81 aura::Window* target = static_cast<aura::Window*>(event->target());
82 int previous_target_component = click_component_;
83 click_component_ =
84 target->delegate()->GetNonClientComponent(event->location());
85
86 if (click_component_ != HTCAPTION)
87 return;
88
89 if (event->details().tap_count() != 2) {
90 WmShell::Get()->RecordGestureAction(GESTURE_FRAMEVIEW_TAP);
91 return;
92 }
93
94 if (click_component_ == previous_target_component) {
95 WmShell::Get()->RecordUserMetricsAction(
96 UMA_TOGGLE_MAXIMIZE_CAPTION_GESTURE);
97 WmShell::Get()->RecordGestureAction(GESTURE_MAXIMIZE_DOUBLETAP);
98 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION);
99 wm::GetWindowState(target)->OnWMEvent(&wm_event);
100 event->StopPropagation();
101 }
102 click_component_ = HTNOWHERE;
103 }
104
105 void WorkspaceEventHandler::HandleVerticalResizeDoubleClick(
106 wm::WindowState* target_state,
107 ui::MouseEvent* event) {
108 WmWindow* target = target_state->window();
109 if (event->flags() & ui::EF_IS_DOUBLE_CLICK) {
110 int component = target->GetNonClientComponent(event->location());
111 if (component == HTBOTTOM || component == HTTOP) {
112 WmShell::Get()->RecordUserMetricsAction(
113 UMA_TOGGLE_SINGLE_AXIS_MAXIMIZE_BORDER_CLICK);
114 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE);
115 target_state->OnWMEvent(&wm_event);
116 event->StopPropagation();
117 } else if (component == HTLEFT || component == HTRIGHT) {
118 WmShell::Get()->RecordUserMetricsAction(
119 UMA_TOGGLE_SINGLE_AXIS_MAXIMIZE_BORDER_CLICK);
120 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE);
121 target_state->OnWMEvent(&wm_event);
122 event->StopPropagation();
123 }
124 }
125 }
126
127 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698