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

Side by Side Diff: ash/magnifier/partial_magnification_controller.cc

Issue 2303963002: cros/ash: If the partial magnifier is active, do not consume input events if over palette views. (Closed)
Patch Set: Address comments 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
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/magnifier/partial_magnification_controller.h" 5 #include "ash/magnifier/partial_magnification_controller.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ui/aura/window_event_dispatcher.h" 8 #include "ui/aura/window_event_dispatcher.h"
9 #include "ui/aura/window_tree_host.h" 9 #include "ui/aura/window_tree_host.h"
10 #include "ui/compositor/layer.h" 10 #include "ui/compositor/layer.h"
11 #include "ui/compositor/paint_recorder.h" 11 #include "ui/compositor/paint_recorder.h"
12 #include "ui/events/event.h" 12 #include "ui/events/event.h"
13 #include "ui/events/event_constants.h" 13 #include "ui/events/event_constants.h"
14 #include "ui/views/widget/widget.h" 14 #include "ui/views/widget/widget.h"
15 #include "ui/wm/core/coordinate_conversion.h" 15 #include "ui/wm/core/coordinate_conversion.h"
16 16
17 #if defined(OS_CHROMEOS)
18 #include "ash/common/system/chromeos/palette/palette_utils.h"
19 #endif
20
17 namespace ash { 21 namespace ash {
18 namespace { 22 namespace {
19 23
20 // Ratio of magnifier scale. 24 // Ratio of magnifier scale.
21 const float kMagnificationScale = 2.f; 25 const float kMagnificationScale = 2.f;
22 // Radius of the magnifying glass in DIP. 26 // Radius of the magnifying glass in DIP.
23 const int kMagnifierRadius = 200; 27 const int kMagnifierRadius = 200;
24 // Size of the border around the magnifying glass in DIP. 28 // Size of the border around the magnifying glass in DIP.
25 const int kBorderSize = 10; 29 const int kBorderSize = 10;
26 // Inset on the zoom filter. 30 // Inset on the zoom filter.
(...skipping 20 matching lines...) Expand all
47 aura::Window* GetCurrentRootWindow() { 51 aura::Window* GetCurrentRootWindow() {
48 aura::Window::Windows root_windows = ash::Shell::GetAllRootWindows(); 52 aura::Window::Windows root_windows = ash::Shell::GetAllRootWindows();
49 for (aura::Window* root_window : root_windows) { 53 for (aura::Window* root_window : root_windows) {
50 if (root_window->ContainsPointInRoot( 54 if (root_window->ContainsPointInRoot(
51 root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot())) 55 root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot()))
52 return root_window; 56 return root_window;
53 } 57 }
54 return nullptr; 58 return nullptr;
55 } 59 }
56 60
61 // Returns true if the event should be processed normally, ie, the stylus is
62 // over the palette icon or widget.
63 bool ShouldSkipEventFiltering(const gfx::Point& point) {
64 #if defined(OS_CHROMEOS)
jdufault 2016/09/02 20:22:32 I'm leaning towards making this entire file cros o
James Cook 2016/09/06 16:16:32 That's fine with me.
65 return PaletteContainsPointInScreen(point);
66 #else
67 return false;
68 #endif
69 }
70
57 } // namespace 71 } // namespace
58 72
59 // The content mask provides a clipping layer for the magnification window so we 73 // The content mask provides a clipping layer for the magnification window so we
60 // can show a circular magnifier. 74 // can show a circular magnifier.
61 class PartialMagnificationController::ContentMask : public ui::LayerDelegate { 75 class PartialMagnificationController::ContentMask : public ui::LayerDelegate {
62 public: 76 public:
63 // If |stroke| is true, the circle will be a stroke. This is useful if we wish 77 // If |stroke| is true, the circle will be a stroke. This is useful if we wish
64 // to clip a border. 78 // to clip a border.
65 ContentMask(bool stroke, gfx::Size mask_bounds) 79 ContentMask(bool stroke, gfx::Size mask_bounds)
66 : layer_(ui::LAYER_TEXTURED), stroke_(stroke) { 80 : layer_(ui::LAYER_TEXTURED), stroke_(stroke) {
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 185
172 void PartialMagnificationController::OnLocatedEvent( 186 void PartialMagnificationController::OnLocatedEvent(
173 ui::LocatedEvent* event, 187 ui::LocatedEvent* event,
174 const ui::PointerDetails& pointer_details) { 188 const ui::PointerDetails& pointer_details) {
175 if (!is_enabled_) 189 if (!is_enabled_)
176 return; 190 return;
177 191
178 if (pointer_details.pointer_type != ui::EventPointerType::POINTER_TYPE_PEN) 192 if (pointer_details.pointer_type != ui::EventPointerType::POINTER_TYPE_PEN)
179 return; 193 return;
180 194
181 if (event->type() == ui::ET_MOUSE_PRESSED) 195 // Compute the event location in screen space.
196 aura::Window* target = static_cast<aura::Window*>(event->target());
197 aura::Window* event_root = target->GetRootWindow();
198 gfx::Point screen_point = event->root_location();
199 wm::ConvertPointToScreen(event_root, &screen_point);
200
201 if (event->type() == ui::ET_MOUSE_PRESSED &&
202 !ShouldSkipEventFiltering(screen_point)) {
182 SetActive(true); 203 SetActive(true);
204 }
183 205
184 if (event->type() == ui::ET_MOUSE_RELEASED) 206 if (event->type() == ui::ET_MOUSE_RELEASED)
185 SetActive(false); 207 SetActive(false);
186 208
187 if (!is_active_) 209 if (!is_active_)
188 return; 210 return;
189 211
190 // If the previous root window was detached host_widget_ will be null; 212 // If the previous root window was detached host_widget_ will be null;
191 // reconstruct it. We also need to change the root window if the cursor has 213 // reconstruct it. We also need to change the root window if the cursor has
192 // crossed display boundries. 214 // crossed display boundries.
193 SwitchTargetRootWindowIfNeeded(GetCurrentRootWindow()); 215 SwitchTargetRootWindowIfNeeded(GetCurrentRootWindow());
194 216
195 // If that failed for any reason return. 217 // If that failed for any reason return.
196 if (!host_widget_) { 218 if (!host_widget_) {
197 SetActive(false); 219 SetActive(false);
198 return; 220 return;
199 } 221 }
200 222
223 // Remap point from where it was captured to the display it is actually on.
201 gfx::Point point = event->root_location(); 224 gfx::Point point = event->root_location();
202
203 // Remap point from where it was captured to the display it is actually on.
204 aura::Window* target = static_cast<aura::Window*>(event->target());
205 aura::Window* event_root = target->GetRootWindow();
206 aura::Window::ConvertPointToTarget( 225 aura::Window::ConvertPointToTarget(
207 event_root, host_widget_->GetNativeView()->GetRootWindow(), &point); 226 event_root, host_widget_->GetNativeView()->GetRootWindow(), &point);
208
209 host_widget_->SetBounds(GetBounds(point)); 227 host_widget_->SetBounds(GetBounds(point));
210 228
211 event->StopPropagation(); 229 if (!ShouldSkipEventFiltering(screen_point))
230 event->StopPropagation();
212 } 231 }
213 232
214 void PartialMagnificationController::CreateMagnifierWindow( 233 void PartialMagnificationController::CreateMagnifierWindow(
215 aura::Window* root_window) { 234 aura::Window* root_window) {
216 if (host_widget_ || !root_window) 235 if (host_widget_ || !root_window)
217 return; 236 return;
218 237
219 root_window->AddObserver(this); 238 root_window->AddObserver(this);
220 239
221 gfx::Point mouse( 240 gfx::Point mouse(
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 286
268 void PartialMagnificationController::RemoveZoomWidgetObservers() { 287 void PartialMagnificationController::RemoveZoomWidgetObservers() {
269 DCHECK(host_widget_); 288 DCHECK(host_widget_);
270 host_widget_->RemoveObserver(this); 289 host_widget_->RemoveObserver(this);
271 aura::Window* root_window = host_widget_->GetNativeView()->GetRootWindow(); 290 aura::Window* root_window = host_widget_->GetNativeView()->GetRootWindow();
272 DCHECK(root_window); 291 DCHECK(root_window);
273 root_window->RemoveObserver(this); 292 root_window->RemoveObserver(this);
274 } 293 }
275 294
276 } // namespace ash 295 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698