Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / ash / wm / workspace / workspace_event_handler.cc
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/metrics/user_metrics_recorder.h"
8 #include "ash/shell.h"
9 #include "ash/touch/touch_uma.h"
10 #include "ash/wm/window_state.h"
11 #include "ui/aura/window.h"
12 #include "ui/aura/window_delegate.h"
13 #include "ui/base/hit_test.h"
14
15 namespace ash {
16 namespace internal {
17
18 WorkspaceEventHandler::WorkspaceEventHandler() {
19 }
20
21 WorkspaceEventHandler::~WorkspaceEventHandler() {
22 }
23
24 void WorkspaceEventHandler::OnMouseEvent(ui::MouseEvent* event) {
25   if (event->handled())
26     return;
27   aura::Window* target = static_cast<aura::Window*>(event->target());
28   switch (event->type()) {
29     case ui::ET_MOUSE_MOVED: {
30       int component =
31           target->delegate()->GetNonClientComponent(event->location());
32       multi_window_resize_controller_.Show(target, component,
33                                            event->location());
34       break;
35     }
36     case ui::ET_MOUSE_ENTERED:
37       break;
38     case ui::ET_MOUSE_CAPTURE_CHANGED:
39     case ui::ET_MOUSE_EXITED:
40       break;
41     case ui::ET_MOUSE_PRESSED: {
42       wm::WindowState* target_state = wm::GetWindowState(target);
43       if (event->flags() & ui::EF_IS_DOUBLE_CLICK &&
44           event->IsOnlyLeftMouseButton() &&
45           target->delegate()->GetNonClientComponent(event->location()) ==
46           HTCAPTION) {
47         ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction(
48             ash::UMA_TOGGLE_MAXIMIZE_CAPTION_CLICK);
49         target_state->OnWMEvent(wm::TOGGLE_MAXIMIZE_CAPTION);
50         event->StopPropagation();
51       }
52       multi_window_resize_controller_.Hide();
53       HandleVerticalResizeDoubleClick(target_state, event);
54       break;
55     }
56     default:
57       break;
58   }
59 }
60
61 void WorkspaceEventHandler::OnGestureEvent(ui::GestureEvent* event) {
62   if (event->handled())
63     return;
64   aura::Window* target = static_cast<aura::Window*>(event->target());
65   if (event->type() == ui::ET_GESTURE_TAP &&
66       target->delegate()->GetNonClientComponent(event->location()) ==
67       HTCAPTION) {
68     if (event->details().tap_count() == 2) {
69       ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction(
70           ash::UMA_TOGGLE_MAXIMIZE_CAPTION_GESTURE);
71       // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice each time
72       // TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP is counted once.
73       TouchUMA::GetInstance()->RecordGestureAction(
74           TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP);
75       wm::GetWindowState(target)->OnWMEvent(wm::TOGGLE_MAXIMIZE_CAPTION);
76       event->StopPropagation();
77       return;
78     } else {
79       // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice for each tap.
80       TouchUMA::GetInstance()->RecordGestureAction(
81           TouchUMA::GESTURE_FRAMEVIEW_TAP);
82     }
83   }
84 }
85
86 void WorkspaceEventHandler::HandleVerticalResizeDoubleClick(
87     wm::WindowState* target_state,
88     ui::MouseEvent* event) {
89   aura::Window* target = target_state->window();
90   if (event->flags() & ui::EF_IS_DOUBLE_CLICK) {
91     int component =
92         target->delegate()->GetNonClientComponent(event->location());
93     if (component == HTBOTTOM || component == HTTOP) {
94       Shell::GetInstance()->metrics()->RecordUserMetricsAction(
95           UMA_TOGGLE_SINGLE_AXIS_MAXIMIZE_BORDER_CLICK);
96       target_state->OnWMEvent(wm::TOGGLE_VERTICAL_MAXIMIZE);
97       event->StopPropagation();
98     } else if (component == HTLEFT || component == HTRIGHT) {
99       Shell::GetInstance()->metrics()->RecordUserMetricsAction(
100           UMA_TOGGLE_SINGLE_AXIS_MAXIMIZE_BORDER_CLICK);
101       target_state->OnWMEvent(wm::TOGGLE_HORIZONTAL_MAXIMIZE);
102       event->StopPropagation();
103     }
104   }
105 }
106
107 }  // namespace internal
108 }  // namespace ash