| 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/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 // Thickness of the outline around magnifying glass border in DIP. | 27 // Thickness of the outline around magnifying glass border in DIP. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 57 aura::Window* GetCurrentRootWindow() { | 54 aura::Window* GetCurrentRootWindow() { |
| 58 aura::Window::Windows root_windows = ash::Shell::GetAllRootWindows(); | 55 aura::Window::Windows root_windows = ash::Shell::GetAllRootWindows(); |
| 59 for (aura::Window* root_window : root_windows) { | 56 for (aura::Window* root_window : root_windows) { |
| 60 if (root_window->ContainsPointInRoot( | 57 if (root_window->ContainsPointInRoot( |
| 61 root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot())) | 58 root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot())) |
| 62 return root_window; | 59 return root_window; |
| 63 } | 60 } |
| 64 return nullptr; | 61 return nullptr; |
| 65 } | 62 } |
| 66 | 63 |
| 67 // Returns true if the event should be processed normally, ie, the stylus is | |
| 68 // over the palette icon or widget. | |
| 69 bool ShouldSkipEventFiltering(const gfx::Point& point) { | |
| 70 #if defined(OS_CHROMEOS) | |
| 71 return PaletteContainsPointInScreen(point); | |
| 72 #else | |
| 73 return false; | |
| 74 #endif | |
| 75 } | |
| 76 | |
| 77 } // namespace | 64 } // namespace |
| 78 | 65 |
| 79 // The content mask provides a clipping layer for the magnification window so we | 66 // The content mask provides a clipping layer for the magnification window so we |
| 80 // can show a circular magnifier. | 67 // can show a circular magnifier. |
| 81 class PartialMagnificationController::ContentMask : public ui::LayerDelegate { | 68 class PartialMagnificationController::ContentMask : public ui::LayerDelegate { |
| 82 public: | 69 public: |
| 83 // If |stroke| is true, the circle will be a stroke. This is useful if we wish | 70 // If |stroke| is true, the circle will be a stroke. This is useful if we wish |
| 84 // to clip a border. | 71 // to clip a border. |
| 85 ContentMask(bool stroke, gfx::Size mask_bounds) | 72 ContentMask(bool stroke, gfx::Size mask_bounds) |
| 86 : layer_(ui::LAYER_TEXTURED), stroke_(stroke) { | 73 : layer_(ui::LAYER_TEXTURED), stroke_(stroke) { |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 | 234 |
| 248 if (pointer_details.pointer_type != ui::EventPointerType::POINTER_TYPE_PEN) | 235 if (pointer_details.pointer_type != ui::EventPointerType::POINTER_TYPE_PEN) |
| 249 return; | 236 return; |
| 250 | 237 |
| 251 // Compute the event location in screen space. | 238 // Compute the event location in screen space. |
| 252 aura::Window* target = static_cast<aura::Window*>(event->target()); | 239 aura::Window* target = static_cast<aura::Window*>(event->target()); |
| 253 aura::Window* event_root = target->GetRootWindow(); | 240 aura::Window* event_root = target->GetRootWindow(); |
| 254 gfx::Point screen_point = event->root_location(); | 241 gfx::Point screen_point = event->root_location(); |
| 255 wm::ConvertPointToScreen(event_root, &screen_point); | 242 wm::ConvertPointToScreen(event_root, &screen_point); |
| 256 | 243 |
| 244 // If the stylus is pressed on the palette icon or widget, do not activate. |
| 257 if (event->type() == ui::ET_MOUSE_PRESSED && | 245 if (event->type() == ui::ET_MOUSE_PRESSED && |
| 258 !ShouldSkipEventFiltering(screen_point)) { | 246 !PaletteContainsPointInScreen(screen_point)) { |
| 259 SetActive(true); | 247 SetActive(true); |
| 260 } | 248 } |
| 261 | 249 |
| 262 if (event->type() == ui::ET_MOUSE_RELEASED) | 250 if (event->type() == ui::ET_MOUSE_RELEASED) |
| 263 SetActive(false); | 251 SetActive(false); |
| 264 | 252 |
| 265 if (!is_active_) | 253 if (!is_active_) |
| 266 return; | 254 return; |
| 267 | 255 |
| 268 // If the previous root window was detached host_widget_ will be null; | 256 // If the previous root window was detached host_widget_ will be null; |
| 269 // reconstruct it. We also need to change the root window if the cursor has | 257 // reconstruct it. We also need to change the root window if the cursor has |
| 270 // crossed display boundries. | 258 // crossed display boundries. |
| 271 SwitchTargetRootWindowIfNeeded(GetCurrentRootWindow()); | 259 SwitchTargetRootWindowIfNeeded(GetCurrentRootWindow()); |
| 272 | 260 |
| 273 // If that failed for any reason return. | 261 // If that failed for any reason return. |
| 274 if (!host_widget_) { | 262 if (!host_widget_) { |
| 275 SetActive(false); | 263 SetActive(false); |
| 276 return; | 264 return; |
| 277 } | 265 } |
| 278 | 266 |
| 279 // Remap point from where it was captured to the display it is actually on. | 267 // Remap point from where it was captured to the display it is actually on. |
| 280 gfx::Point point = event->root_location(); | 268 gfx::Point point = event->root_location(); |
| 281 aura::Window::ConvertPointToTarget( | 269 aura::Window::ConvertPointToTarget( |
| 282 event_root, host_widget_->GetNativeView()->GetRootWindow(), &point); | 270 event_root, host_widget_->GetNativeView()->GetRootWindow(), &point); |
| 283 host_widget_->SetBounds(GetBounds(point)); | 271 host_widget_->SetBounds(GetBounds(point)); |
| 284 | 272 |
| 285 if (!ShouldSkipEventFiltering(screen_point)) | 273 // If the stylus is over the palette icon or widget, do not consume the event. |
| 274 if (!PaletteContainsPointInScreen(screen_point)) |
| 286 event->StopPropagation(); | 275 event->StopPropagation(); |
| 287 } | 276 } |
| 288 | 277 |
| 289 void PartialMagnificationController::CreateMagnifierWindow( | 278 void PartialMagnificationController::CreateMagnifierWindow( |
| 290 aura::Window* root_window) { | 279 aura::Window* root_window) { |
| 291 if (host_widget_ || !root_window) | 280 if (host_widget_ || !root_window) |
| 292 return; | 281 return; |
| 293 | 282 |
| 294 root_window->AddObserver(this); | 283 root_window->AddObserver(this); |
| 295 | 284 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 | 332 |
| 344 void PartialMagnificationController::RemoveZoomWidgetObservers() { | 333 void PartialMagnificationController::RemoveZoomWidgetObservers() { |
| 345 DCHECK(host_widget_); | 334 DCHECK(host_widget_); |
| 346 host_widget_->RemoveObserver(this); | 335 host_widget_->RemoveObserver(this); |
| 347 aura::Window* root_window = host_widget_->GetNativeView()->GetRootWindow(); | 336 aura::Window* root_window = host_widget_->GetNativeView()->GetRootWindow(); |
| 348 DCHECK(root_window); | 337 DCHECK(root_window); |
| 349 root_window->RemoveObserver(this); | 338 root_window->RemoveObserver(this); |
| 350 } | 339 } |
| 351 | 340 |
| 352 } // namespace ash | 341 } // namespace ash |
| OLD | NEW |