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/magnification_controller.h" | 5 #include "ash/magnifier/magnification_controller.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "ash/common/accelerators/accelerator_controller.h" | 10 #include "ash/common/accelerators/accelerator_controller.h" |
11 #include "ash/common/accessibility_delegate.h" | 11 #include "ash/common/accessibility_delegate.h" |
12 #include "ash/common/system/tray/system_tray_delegate.h" | 12 #include "ash/common/system/tray/system_tray_delegate.h" |
13 #include "ash/common/wm_shell.h" | 13 #include "ash/common/wm_shell.h" |
14 #include "ash/display/root_window_transformers.h" | 14 #include "ash/display/root_window_transformers.h" |
15 #include "ash/host/ash_window_tree_host.h" | 15 #include "ash/host/ash_window_tree_host.h" |
16 #include "ash/host/root_window_transformer.h" | 16 #include "ash/host/root_window_transformer.h" |
17 #include "ash/root_window_controller.h" | 17 #include "ash/root_window_controller.h" |
18 #include "ash/screen_util.h" | 18 #include "ash/screen_util.h" |
19 #include "ash/shell.h" | 19 #include "ash/shell.h" |
20 #include "base/command_line.h" | 20 #include "base/command_line.h" |
21 #include "base/synchronization/waitable_event.h" | 21 #include "base/synchronization/waitable_event.h" |
22 #include "base/timer/timer.h" | 22 #include "base/timer/timer.h" |
| 23 #include "chromeos/chromeos_switches.h" |
23 #include "ui/aura/client/cursor_client.h" | 24 #include "ui/aura/client/cursor_client.h" |
24 #include "ui/aura/window.h" | 25 #include "ui/aura/window.h" |
25 #include "ui/aura/window_tree_host.h" | 26 #include "ui/aura/window_tree_host.h" |
26 #include "ui/base/ime/input_method.h" | 27 #include "ui/base/ime/input_method.h" |
27 #include "ui/base/ime/input_method_observer.h" | 28 #include "ui/base/ime/input_method_observer.h" |
28 #include "ui/base/ime/text_input_client.h" | 29 #include "ui/base/ime/text_input_client.h" |
29 #include "ui/compositor/dip_util.h" | 30 #include "ui/compositor/dip_util.h" |
30 #include "ui/compositor/layer.h" | 31 #include "ui/compositor/layer.h" |
31 #include "ui/compositor/layer_animation_observer.h" | 32 #include "ui/compositor/layer_animation_observer.h" |
32 #include "ui/compositor/scoped_layer_animation_settings.h" | 33 #include "ui/compositor/scoped_layer_animation_settings.h" |
33 #include "ui/display/display.h" | 34 #include "ui/display/display.h" |
34 #include "ui/display/screen.h" | 35 #include "ui/display/screen.h" |
35 #include "ui/events/event.h" | 36 #include "ui/events/event.h" |
36 #include "ui/events/event_handler.h" | 37 #include "ui/events/event_handler.h" |
| 38 #include "ui/events/gesture_event_details.h" |
37 #include "ui/gfx/geometry/point3_f.h" | 39 #include "ui/gfx/geometry/point3_f.h" |
38 #include "ui/gfx/geometry/point_conversions.h" | 40 #include "ui/gfx/geometry/point_conversions.h" |
39 #include "ui/gfx/geometry/point_f.h" | 41 #include "ui/gfx/geometry/point_f.h" |
40 #include "ui/gfx/geometry/rect_conversions.h" | 42 #include "ui/gfx/geometry/rect_conversions.h" |
41 #include "ui/wm/core/compound_event_filter.h" | 43 #include "ui/wm/core/compound_event_filter.h" |
42 #include "ui/wm/core/coordinate_conversion.h" | 44 #include "ui/wm/core/coordinate_conversion.h" |
43 | 45 |
44 namespace { | 46 namespace { |
45 | 47 |
46 const float kMaxMagnifiedScale = 4.0f; | 48 const float kMaxMagnifiedScale = 4.0f; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 // Returns the size of the root window. | 186 // Returns the size of the root window. |
185 gfx::Size GetHostSizeDIP() const; | 187 gfx::Size GetHostSizeDIP() const; |
186 | 188 |
187 // Correct the given scale value if necessary. | 189 // Correct the given scale value if necessary. |
188 void ValidateScale(float* scale); | 190 void ValidateScale(float* scale); |
189 | 191 |
190 // ui::EventHandler overrides: | 192 // ui::EventHandler overrides: |
191 void OnMouseEvent(ui::MouseEvent* event) override; | 193 void OnMouseEvent(ui::MouseEvent* event) override; |
192 void OnScrollEvent(ui::ScrollEvent* event) override; | 194 void OnScrollEvent(ui::ScrollEvent* event) override; |
193 void OnTouchEvent(ui::TouchEvent* event) override; | 195 void OnTouchEvent(ui::TouchEvent* event) override; |
| 196 void OnGestureEvent(ui::GestureEvent* event) override; |
194 | 197 |
195 // Moves the view port when |point| is located within | 198 // Moves the view port when |point| is located within |
196 // |x_panning_margin| and |y_pannin_margin| to the edge of the visible | 199 // |x_panning_margin| and |y_pannin_margin| to the edge of the visible |
197 // window region. The view port will be moved so that the |point| will be | 200 // window region. The view port will be moved so that the |point| will be |
198 // moved to the point where it has |x_target_margin| and |y_target_margin| | 201 // moved to the point where it has |x_target_margin| and |y_target_margin| |
199 // to the edge of the visible region. | 202 // to the edge of the visible region. |
200 void MoveMagnifierWindowFollowPoint(const gfx::Point& point, | 203 void MoveMagnifierWindowFollowPoint(const gfx::Point& point, |
201 int x_panning_margin, | 204 int x_panning_margin, |
202 int y_panning_margin, | 205 int y_panning_margin, |
203 int x_target_margin, | 206 int x_target_margin, |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 void MagnificationControllerImpl::OnTouchEvent(ui::TouchEvent* event) { | 686 void MagnificationControllerImpl::OnTouchEvent(ui::TouchEvent* event) { |
684 aura::Window* target = static_cast<aura::Window*>(event->target()); | 687 aura::Window* target = static_cast<aura::Window*>(event->target()); |
685 aura::Window* current_root = target->GetRootWindow(); | 688 aura::Window* current_root = target->GetRootWindow(); |
686 if (current_root == root_window_) { | 689 if (current_root == root_window_) { |
687 gfx::Rect root_bounds = current_root->bounds(); | 690 gfx::Rect root_bounds = current_root->bounds(); |
688 if (root_bounds.Contains(event->root_location())) | 691 if (root_bounds.Contains(event->root_location())) |
689 point_of_interest_ = event->root_location(); | 692 point_of_interest_ = event->root_location(); |
690 } | 693 } |
691 } | 694 } |
692 | 695 |
| 696 void MagnificationControllerImpl::OnGestureEvent(ui::GestureEvent* event) { |
| 697 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 698 chromeos::switches::kEnableTouchSupportForScreenMagnifier)) { |
| 699 return; |
| 700 } |
| 701 |
| 702 const ui::GestureEventDetails& details = event->details(); |
| 703 if (details.type() == ui::ET_GESTURE_SCROLL_UPDATE && |
| 704 details.touch_points() == 2) { |
| 705 gfx::Rect viewport_rect_in_dip = GetViewportRect(); |
| 706 viewport_rect_in_dip.Offset(-details.scroll_x(), -details.scroll_y()); |
| 707 gfx::Rect viewport_rect_in_pixel = |
| 708 ui::ConvertRectToPixel(root_window_->layer(), viewport_rect_in_dip); |
| 709 MoveWindow(viewport_rect_in_pixel.origin(), false); |
| 710 event->SetHandled(); |
| 711 } else if (details.type() == ui::ET_GESTURE_PINCH_UPDATE && |
| 712 details.touch_points() == 3) { |
| 713 float scale = GetScale() * details.scale(); |
| 714 scale = std::max(scale, kMinMagnifiedScaleThreshold); |
| 715 scale = std::min(scale, kMaxMagnifiedScaleThreshold); |
| 716 |
| 717 point_of_interest_ = event->root_location(); |
| 718 SetScale(scale, false); |
| 719 event->SetHandled(); |
| 720 } |
| 721 } |
| 722 |
693 void MagnificationControllerImpl::MoveMagnifierWindowFollowPoint( | 723 void MagnificationControllerImpl::MoveMagnifierWindowFollowPoint( |
694 const gfx::Point& point, | 724 const gfx::Point& point, |
695 int x_panning_margin, | 725 int x_panning_margin, |
696 int y_panning_margin, | 726 int y_panning_margin, |
697 int x_target_margin, | 727 int x_target_margin, |
698 int y_target_margin) { | 728 int y_target_margin) { |
699 DCHECK(root_window_); | 729 DCHECK(root_window_); |
700 bool start_zoom = false; | 730 bool start_zoom = false; |
701 | 731 |
702 const gfx::Rect window_rect = GetViewportRect(); | 732 const gfx::Rect window_rect = GetViewportRect(); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
857 | 887 |
858 //////////////////////////////////////////////////////////////////////////////// | 888 //////////////////////////////////////////////////////////////////////////////// |
859 // MagnificationController: | 889 // MagnificationController: |
860 | 890 |
861 // static | 891 // static |
862 MagnificationController* MagnificationController::CreateInstance() { | 892 MagnificationController* MagnificationController::CreateInstance() { |
863 return new MagnificationControllerImpl(); | 893 return new MagnificationControllerImpl(); |
864 } | 894 } |
865 | 895 |
866 } // namespace ash | 896 } // namespace ash |
OLD | NEW |