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

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

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

Powered by Google App Engine
This is Rietveld 408576698