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

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

Issue 114643003: Use a single ToplevelWindowEventHandler for the ash::Shell (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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
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 "ash/wm/workspace/workspace_event_handler.h" 5 #include "ash/wm/workspace/workspace_event_handler.h"
6 6
7 #include "ash/screen_ash.h" 7 #include "ash/screen_ash.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "ash/shell_delegate.h" 9 #include "ash/shell_delegate.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
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 destroyed_(NULL) {
60 } 58 }
61 59
62 WorkspaceEventHandler::~WorkspaceEventHandler() { 60 WorkspaceEventHandler::~WorkspaceEventHandler() {
63 if (destroyed_)
64 *destroyed_ = true;
65 } 61 }
66 62
67 void WorkspaceEventHandler::OnMouseEvent(ui::MouseEvent* event) { 63 void WorkspaceEventHandler::OnMouseEvent(ui::MouseEvent* event) {
68 aura::Window* target = static_cast<aura::Window*>(event->target()); 64 aura::Window* target = static_cast<aura::Window*>(event->target());
69 switch (event->type()) { 65 switch (event->type()) {
70 case ui::ET_MOUSE_MOVED: { 66 case ui::ET_MOUSE_MOVED: {
71 int component = 67 int component =
72 target->delegate()->GetNonClientComponent(event->location()); 68 target->delegate()->GetNonClientComponent(event->location());
73 multi_window_resize_controller_.Show(target, component, 69 multi_window_resize_controller_.Show(target, component,
74 event->location()); 70 event->location());
75 break; 71 break;
76 } 72 }
77 case ui::ET_MOUSE_ENTERED: 73 case ui::ET_MOUSE_ENTERED:
78 break; 74 break;
79 case ui::ET_MOUSE_CAPTURE_CHANGED: 75 case ui::ET_MOUSE_CAPTURE_CHANGED:
80 case ui::ET_MOUSE_EXITED: 76 case ui::ET_MOUSE_EXITED:
81 break; 77 break;
82 case ui::ET_MOUSE_PRESSED: { 78 case ui::ET_MOUSE_PRESSED: {
83 // Maximize behavior is implemented as post-target handling so the target 79 // Maximize behavior is implemented as post-target handling so the target
84 // can cancel it. 80 // can cancel it.
85 if (ui::EventCanceledDefaultHandling(*event)) { 81 if (ui::EventCanceledDefaultHandling(*event))
86 ToplevelWindowEventHandler::OnMouseEvent(event);
87 return; 82 return;
88 }
89 wm::WindowState* target_state = wm::GetWindowState(target); 83 wm::WindowState* target_state = wm::GetWindowState(target);
90 if (event->flags() & ui::EF_IS_DOUBLE_CLICK && 84 if (event->flags() & ui::EF_IS_DOUBLE_CLICK &&
91 event->IsOnlyLeftMouseButton() && 85 event->IsOnlyLeftMouseButton() &&
92 target->delegate()->GetNonClientComponent(event->location()) == 86 target->delegate()->GetNonClientComponent(event->location()) ==
93 HTCAPTION) { 87 HTCAPTION) {
94 bool destroyed = false;
95 destroyed_ = &destroyed;
96 ash::Shell::GetInstance()->delegate()->RecordUserMetricsAction( 88 ash::Shell::GetInstance()->delegate()->RecordUserMetricsAction(
97 ash::UMA_TOGGLE_MAXIMIZE_CAPTION_CLICK); 89 ash::UMA_TOGGLE_MAXIMIZE_CAPTION_CLICK);
98 ToggleMaximizedState(target_state); 90 ToggleMaximizedState(target_state);
99 if (destroyed) 91 event->StopPropagation();
100 return;
101 destroyed_ = NULL;
102 } 92 }
103 multi_window_resize_controller_.Hide(); 93 multi_window_resize_controller_.Hide();
104 HandleVerticalResizeDoubleClick(target_state, event); 94 HandleVerticalResizeDoubleClick(target_state, event);
105 break; 95 break;
106 } 96 }
107 default: 97 default:
108 break; 98 break;
109 } 99 }
110 ToplevelWindowEventHandler::OnMouseEvent(event);
111 } 100 }
112 101
113 void WorkspaceEventHandler::OnGestureEvent(ui::GestureEvent* event) { 102 void WorkspaceEventHandler::OnGestureEvent(ui::GestureEvent* event) {
114 aura::Window* target = static_cast<aura::Window*>(event->target()); 103 aura::Window* target = static_cast<aura::Window*>(event->target());
115 if (event->type() == ui::ET_GESTURE_TAP && 104 if (event->type() == ui::ET_GESTURE_TAP &&
116 target->delegate()->GetNonClientComponent(event->location()) == 105 target->delegate()->GetNonClientComponent(event->location()) ==
117 HTCAPTION) { 106 HTCAPTION) {
118 if (event->details().tap_count() == 2) { 107 if (event->details().tap_count() == 2) {
119 ash::Shell::GetInstance()->delegate()->RecordUserMetricsAction( 108 ash::Shell::GetInstance()->delegate()->RecordUserMetricsAction(
120 ash::UMA_TOGGLE_MAXIMIZE_CAPTION_GESTURE); 109 ash::UMA_TOGGLE_MAXIMIZE_CAPTION_GESTURE);
121 // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice each time 110 // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice each time
122 // TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP is counted once. 111 // TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP is counted once.
123 TouchUMA::GetInstance()->RecordGestureAction( 112 TouchUMA::GetInstance()->RecordGestureAction(
124 TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP); 113 TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP);
125 // |this| may be destroyed from here.
126 ToggleMaximizedState(wm::GetWindowState(target)); 114 ToggleMaximizedState(wm::GetWindowState(target));
127 event->StopPropagation(); 115 event->StopPropagation();
128 return; 116 return;
129 } else { 117 } else {
130 // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice for each tap. 118 // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice for each tap.
131 TouchUMA::GetInstance()->RecordGestureAction( 119 TouchUMA::GetInstance()->RecordGestureAction(
132 TouchUMA::GESTURE_FRAMEVIEW_TAP); 120 TouchUMA::GESTURE_FRAMEVIEW_TAP);
133 } 121 }
134 } 122 }
135 ToplevelWindowEventHandler::OnGestureEvent(event);
136 } 123 }
137 124
138 void WorkspaceEventHandler::HandleVerticalResizeDoubleClick( 125 void WorkspaceEventHandler::HandleVerticalResizeDoubleClick(
139 wm::WindowState* target_state, 126 wm::WindowState* target_state,
140 ui::MouseEvent* event) { 127 ui::MouseEvent* event) {
141 aura::Window* target = target_state->window(); 128 aura::Window* target = target_state->window();
142 gfx::Rect max_size(target->delegate()->GetMaximumSize()); 129 gfx::Rect max_size(target->delegate()->GetMaximumSize());
143 if (event->flags() & ui::EF_IS_DOUBLE_CLICK && !target_state->IsMaximized()) { 130 if (event->flags() & ui::EF_IS_DOUBLE_CLICK && !target_state->IsMaximized()) {
144 int component = 131 int component =
145 target->delegate()->GetNonClientComponent(event->location()); 132 target->delegate()->GetNonClientComponent(event->location());
146 gfx::Rect work_area = Shell::GetScreen()->GetDisplayNearestWindow( 133 gfx::Rect work_area = Shell::GetScreen()->GetDisplayNearestWindow(
147 target).work_area(); 134 target).work_area();
148 if (component == HTBOTTOM || component == HTTOP) { 135 if (component == HTBOTTOM || component == HTTOP) {
149 // Don't maximize vertically if the window has a max height defined. 136 // Don't maximize vertically if the window has a max height defined.
150 if (max_size.height() != 0) 137 if (max_size.height() != 0)
151 return; 138 return;
152 if (target_state->HasRestoreBounds() && 139 if (target_state->HasRestoreBounds() &&
153 (target->bounds().height() == work_area.height() && 140 (target->bounds().height() == work_area.height() &&
154 target->bounds().y() == work_area.y())) { 141 target->bounds().y() == work_area.y())) {
155 SingleAxisUnmaximize(target_state, 142 SingleAxisUnmaximize(target_state,
156 target_state->GetRestoreBoundsInScreen()); 143 target_state->GetRestoreBoundsInScreen());
144 event->StopPropagation();
157 } else { 145 } else {
158 gfx::Point origin = target->bounds().origin(); 146 gfx::Point origin = target->bounds().origin();
159 wm::ConvertPointToScreen(target->parent(), &origin); 147 wm::ConvertPointToScreen(target->parent(), &origin);
160 SingleAxisMaximize(target_state, 148 SingleAxisMaximize(target_state,
161 gfx::Rect(origin.x(), 149 gfx::Rect(origin.x(),
162 work_area.y(), 150 work_area.y(),
163 target->bounds().width(), 151 target->bounds().width(),
164 work_area.height())); 152 work_area.height()));
153 event->StopPropagation();
165 } 154 }
166 } else if (component == HTLEFT || component == HTRIGHT) { 155 } else if (component == HTLEFT || component == HTRIGHT) {
167 // Don't maximize horizontally if the window has a max width defined. 156 // Don't maximize horizontally if the window has a max width defined.
168 if (max_size.width() != 0) 157 if (max_size.width() != 0)
169 return; 158 return;
170 if (target_state->HasRestoreBounds() && 159 if (target_state->HasRestoreBounds() &&
171 (target->bounds().width() == work_area.width() && 160 (target->bounds().width() == work_area.width() &&
172 target->bounds().x() == work_area.x())) { 161 target->bounds().x() == work_area.x())) {
173 SingleAxisUnmaximize(target_state, 162 SingleAxisUnmaximize(target_state,
174 target_state->GetRestoreBoundsInScreen()); 163 target_state->GetRestoreBoundsInScreen());
164 event->StopPropagation();
175 } else { 165 } else {
176 gfx::Point origin = target->bounds().origin(); 166 gfx::Point origin = target->bounds().origin();
177 wm::ConvertPointToScreen(target->parent(), &origin); 167 wm::ConvertPointToScreen(target->parent(), &origin);
178 SingleAxisMaximize(target_state, 168 SingleAxisMaximize(target_state,
179 gfx::Rect(work_area.x(), 169 gfx::Rect(work_area.x(),
180 origin.y(), 170 origin.y(),
181 work_area.width(), 171 work_area.width(),
182 target->bounds().height())); 172 target->bounds().height()));
173 event->StopPropagation();
183 } 174 }
184 } 175 }
185 } 176 }
186 } 177 }
187 178
188 } // namespace internal 179 } // namespace internal
189 } // namespace ash 180 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698