| OLD | NEW |
| 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 "ash/wm/workspace/workspace_event_handler.h" | 5 #include "ash/wm/workspace/workspace_event_handler.h" |
| 6 | 6 |
| 7 #include "ash/metrics/user_metrics_recorder.h" | 7 #include "ash/metrics/user_metrics_recorder.h" |
| 8 #include "ash/screen_ash.h" | 8 #include "ash/screen_ash.h" |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/touch/touch_uma.h" | 10 #include "ash/touch/touch_uma.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 } | 47 } |
| 48 } else if (window_state->CanMaximize()) { | 48 } else if (window_state->CanMaximize()) { |
| 49 window_state->Maximize(); | 49 window_state->Maximize(); |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 | 52 |
| 53 } // namespace | 53 } // namespace |
| 54 | 54 |
| 55 namespace internal { | 55 namespace internal { |
| 56 | 56 |
| 57 WorkspaceEventHandler::WorkspaceEventHandler(aura::Window* owner) | 57 WorkspaceEventHandler::WorkspaceEventHandler() { |
| 58 : ToplevelWindowEventHandler(owner) { | |
| 59 } | 58 } |
| 60 | 59 |
| 61 WorkspaceEventHandler::~WorkspaceEventHandler() { | 60 WorkspaceEventHandler::~WorkspaceEventHandler() { |
| 62 } | 61 } |
| 63 | 62 |
| 64 void WorkspaceEventHandler::OnMouseEvent(ui::MouseEvent* event) { | 63 void WorkspaceEventHandler::OnMouseEvent(ui::MouseEvent* event) { |
| 65 aura::Window* target = static_cast<aura::Window*>(event->target()); | 64 aura::Window* target = static_cast<aura::Window*>(event->target()); |
| 66 switch (event->type()) { | 65 switch (event->type()) { |
| 67 case ui::ET_MOUSE_MOVED: { | 66 case ui::ET_MOUSE_MOVED: { |
| 68 int component = | 67 int component = |
| 69 target->delegate()->GetNonClientComponent(event->location()); | 68 target->delegate()->GetNonClientComponent(event->location()); |
| 70 multi_window_resize_controller_.Show(target, component, | 69 multi_window_resize_controller_.Show(target, component, |
| 71 event->location()); | 70 event->location()); |
| 72 break; | 71 break; |
| 73 } | 72 } |
| 74 case ui::ET_MOUSE_ENTERED: | 73 case ui::ET_MOUSE_ENTERED: |
| 75 break; | 74 break; |
| 76 case ui::ET_MOUSE_CAPTURE_CHANGED: | 75 case ui::ET_MOUSE_CAPTURE_CHANGED: |
| 77 case ui::ET_MOUSE_EXITED: | 76 case ui::ET_MOUSE_EXITED: |
| 78 break; | 77 break; |
| 79 case ui::ET_MOUSE_PRESSED: { | 78 case ui::ET_MOUSE_PRESSED: { |
| 80 // Maximize behavior is implemented as post-target handling so the target | 79 // Maximize behavior is implemented as post-target handling so the target |
| 81 // can cancel it. | 80 // can cancel it. |
| 82 if (ui::EventCanceledDefaultHandling(*event)) { | 81 if (ui::EventCanceledDefaultHandling(*event)) |
| 83 ToplevelWindowEventHandler::OnMouseEvent(event); | |
| 84 return; | 82 return; |
| 85 } | |
| 86 wm::WindowState* target_state = wm::GetWindowState(target); | 83 wm::WindowState* target_state = wm::GetWindowState(target); |
| 87 if (event->flags() & ui::EF_IS_DOUBLE_CLICK && | 84 if (event->flags() & ui::EF_IS_DOUBLE_CLICK && |
| 88 event->IsOnlyLeftMouseButton() && | 85 event->IsOnlyLeftMouseButton() && |
| 89 target->delegate()->GetNonClientComponent(event->location()) == | 86 target->delegate()->GetNonClientComponent(event->location()) == |
| 90 HTCAPTION) { | 87 HTCAPTION) { |
| 91 ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction( | 88 ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction( |
| 92 ash::UMA_TOGGLE_MAXIMIZE_CAPTION_CLICK); | 89 ash::UMA_TOGGLE_MAXIMIZE_CAPTION_CLICK); |
| 93 ToggleMaximizedState(target_state); | 90 ToggleMaximizedState(target_state); |
| 91 event->StopPropagation(); |
| 94 } | 92 } |
| 95 multi_window_resize_controller_.Hide(); | 93 multi_window_resize_controller_.Hide(); |
| 96 HandleVerticalResizeDoubleClick(target_state, event); | 94 HandleVerticalResizeDoubleClick(target_state, event); |
| 97 break; | 95 break; |
| 98 } | 96 } |
| 99 default: | 97 default: |
| 100 break; | 98 break; |
| 101 } | 99 } |
| 102 ToplevelWindowEventHandler::OnMouseEvent(event); | |
| 103 } | 100 } |
| 104 | 101 |
| 105 void WorkspaceEventHandler::OnGestureEvent(ui::GestureEvent* event) { | 102 void WorkspaceEventHandler::OnGestureEvent(ui::GestureEvent* event) { |
| 106 aura::Window* target = static_cast<aura::Window*>(event->target()); | 103 aura::Window* target = static_cast<aura::Window*>(event->target()); |
| 107 if (event->type() == ui::ET_GESTURE_TAP && | 104 if (event->type() == ui::ET_GESTURE_TAP && |
| 108 target->delegate()->GetNonClientComponent(event->location()) == | 105 target->delegate()->GetNonClientComponent(event->location()) == |
| 109 HTCAPTION) { | 106 HTCAPTION) { |
| 110 if (event->details().tap_count() == 2) { | 107 if (event->details().tap_count() == 2) { |
| 111 ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction( | 108 ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction( |
| 112 ash::UMA_TOGGLE_MAXIMIZE_CAPTION_GESTURE); | 109 ash::UMA_TOGGLE_MAXIMIZE_CAPTION_GESTURE); |
| 113 // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice each time | 110 // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice each time |
| 114 // TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP is counted once. | 111 // TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP is counted once. |
| 115 TouchUMA::GetInstance()->RecordGestureAction( | 112 TouchUMA::GetInstance()->RecordGestureAction( |
| 116 TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP); | 113 TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP); |
| 117 ToggleMaximizedState(wm::GetWindowState(target)); | 114 ToggleMaximizedState(wm::GetWindowState(target)); |
| 118 event->StopPropagation(); | 115 event->StopPropagation(); |
| 119 return; | 116 return; |
| 120 } else { | 117 } else { |
| 121 // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice for each tap. | 118 // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice for each tap. |
| 122 TouchUMA::GetInstance()->RecordGestureAction( | 119 TouchUMA::GetInstance()->RecordGestureAction( |
| 123 TouchUMA::GESTURE_FRAMEVIEW_TAP); | 120 TouchUMA::GESTURE_FRAMEVIEW_TAP); |
| 124 } | 121 } |
| 125 } | 122 } |
| 126 ToplevelWindowEventHandler::OnGestureEvent(event); | |
| 127 } | 123 } |
| 128 | 124 |
| 129 void WorkspaceEventHandler::HandleVerticalResizeDoubleClick( | 125 void WorkspaceEventHandler::HandleVerticalResizeDoubleClick( |
| 130 wm::WindowState* target_state, | 126 wm::WindowState* target_state, |
| 131 ui::MouseEvent* event) { | 127 ui::MouseEvent* event) { |
| 132 aura::Window* target = target_state->window(); | 128 aura::Window* target = target_state->window(); |
| 133 gfx::Rect max_size(target->delegate()->GetMaximumSize()); | 129 gfx::Rect max_size(target->delegate()->GetMaximumSize()); |
| 134 if (event->flags() & ui::EF_IS_DOUBLE_CLICK && !target_state->IsMaximized()) { | 130 if (event->flags() & ui::EF_IS_DOUBLE_CLICK && !target_state->IsMaximized()) { |
| 135 int component = | 131 int component = |
| 136 target->delegate()->GetNonClientComponent(event->location()); | 132 target->delegate()->GetNonClientComponent(event->location()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 147 target_state->GetRestoreBoundsInScreen()); | 143 target_state->GetRestoreBoundsInScreen()); |
| 148 } else { | 144 } else { |
| 149 gfx::Point origin = target->bounds().origin(); | 145 gfx::Point origin = target->bounds().origin(); |
| 150 wm::ConvertPointToScreen(target->parent(), &origin); | 146 wm::ConvertPointToScreen(target->parent(), &origin); |
| 151 SingleAxisMaximize(target_state, | 147 SingleAxisMaximize(target_state, |
| 152 gfx::Rect(origin.x(), | 148 gfx::Rect(origin.x(), |
| 153 work_area.y(), | 149 work_area.y(), |
| 154 target->bounds().width(), | 150 target->bounds().width(), |
| 155 work_area.height())); | 151 work_area.height())); |
| 156 } | 152 } |
| 153 event->StopPropagation(); |
| 157 } else if (component == HTLEFT || component == HTRIGHT) { | 154 } else if (component == HTLEFT || component == HTRIGHT) { |
| 158 // Don't maximize horizontally if the window has a max width defined. | 155 // Don't maximize horizontally if the window has a max width defined. |
| 159 if (max_size.width() != 0) | 156 if (max_size.width() != 0) |
| 160 return; | 157 return; |
| 161 if (target_state->HasRestoreBounds() && | 158 if (target_state->HasRestoreBounds() && |
| 162 (target->bounds().width() == work_area.width() && | 159 (target->bounds().width() == work_area.width() && |
| 163 target->bounds().x() == work_area.x())) { | 160 target->bounds().x() == work_area.x())) { |
| 164 SingleAxisUnmaximize(target_state, | 161 SingleAxisUnmaximize(target_state, |
| 165 target_state->GetRestoreBoundsInScreen()); | 162 target_state->GetRestoreBoundsInScreen()); |
| 166 } else { | 163 } else { |
| 167 gfx::Point origin = target->bounds().origin(); | 164 gfx::Point origin = target->bounds().origin(); |
| 168 wm::ConvertPointToScreen(target->parent(), &origin); | 165 wm::ConvertPointToScreen(target->parent(), &origin); |
| 169 SingleAxisMaximize(target_state, | 166 SingleAxisMaximize(target_state, |
| 170 gfx::Rect(work_area.x(), | 167 gfx::Rect(work_area.x(), |
| 171 origin.y(), | 168 origin.y(), |
| 172 work_area.width(), | 169 work_area.width(), |
| 173 target->bounds().height())); | 170 target->bounds().height())); |
| 174 } | 171 } |
| 172 event->StopPropagation(); |
| 175 } | 173 } |
| 176 } | 174 } |
| 177 } | 175 } |
| 178 | 176 |
| 179 } // namespace internal | 177 } // namespace internal |
| 180 } // namespace ash | 178 } // namespace ash |
| OLD | NEW |