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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
254 // Timer for moving magnifier window when it fires. | 257 // Timer for moving magnifier window when it fires. |
255 base::OneShotTimer move_magnifier_timer_; | 258 base::OneShotTimer move_magnifier_timer_; |
256 | 259 |
257 // Most recent caret position in |root_window_| coordinates. | 260 // Most recent caret position in |root_window_| coordinates. |
258 gfx::Point caret_point_; | 261 gfx::Point caret_point_; |
259 | 262 |
260 // Flag for disabling moving magnifier delay. It can only be true in testing | 263 // Flag for disabling moving magnifier delay. It can only be true in testing |
261 // mode. | 264 // mode. |
262 bool disable_move_magnifier_delay_; | 265 bool disable_move_magnifier_delay_; |
263 | 266 |
267 // Flag whether user is currently performing pinch gesture or not. | |
268 bool is_performing_pinch_gesture_; | |
269 | |
264 DISALLOW_COPY_AND_ASSIGN(MagnificationControllerImpl); | 270 DISALLOW_COPY_AND_ASSIGN(MagnificationControllerImpl); |
265 }; | 271 }; |
266 | 272 |
267 //////////////////////////////////////////////////////////////////////////////// | 273 //////////////////////////////////////////////////////////////////////////////// |
268 // MagnificationControllerImpl: | 274 // MagnificationControllerImpl: |
269 | 275 |
270 MagnificationControllerImpl::MagnificationControllerImpl() | 276 MagnificationControllerImpl::MagnificationControllerImpl() |
271 : root_window_(Shell::GetPrimaryRootWindow()), | 277 : root_window_(Shell::GetPrimaryRootWindow()), |
272 is_on_animation_(false), | 278 is_on_animation_(false), |
273 is_enabled_(false), | 279 is_enabled_(false), |
274 keep_focus_centered_(false), | 280 keep_focus_centered_(false), |
275 move_cursor_after_animation_(false), | 281 move_cursor_after_animation_(false), |
276 scale_(kNonMagnifiedScale), | 282 scale_(kNonMagnifiedScale), |
277 scroll_direction_(SCROLL_NONE), | 283 scroll_direction_(SCROLL_NONE), |
278 disable_move_magnifier_delay_(false) { | 284 disable_move_magnifier_delay_(false), |
285 is_performing_pinch_gesture_(false) { | |
279 Shell::GetInstance()->AddPreTargetHandler(this); | 286 Shell::GetInstance()->AddPreTargetHandler(this); |
280 root_window_->AddObserver(this); | 287 root_window_->AddObserver(this); |
281 point_of_interest_ = root_window_->bounds().CenterPoint(); | 288 point_of_interest_ = root_window_->bounds().CenterPoint(); |
282 } | 289 } |
283 | 290 |
284 MagnificationControllerImpl::~MagnificationControllerImpl() { | 291 MagnificationControllerImpl::~MagnificationControllerImpl() { |
285 ui::InputMethod* input_method = GetInputMethod(root_window_); | 292 ui::InputMethod* input_method = GetInputMethod(root_window_); |
286 if (input_method) | 293 if (input_method) |
287 input_method->RemoveObserver(this); | 294 input_method->RemoveObserver(this); |
288 | 295 |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
683 void MagnificationControllerImpl::OnTouchEvent(ui::TouchEvent* event) { | 690 void MagnificationControllerImpl::OnTouchEvent(ui::TouchEvent* event) { |
684 aura::Window* target = static_cast<aura::Window*>(event->target()); | 691 aura::Window* target = static_cast<aura::Window*>(event->target()); |
685 aura::Window* current_root = target->GetRootWindow(); | 692 aura::Window* current_root = target->GetRootWindow(); |
686 if (current_root == root_window_) { | 693 if (current_root == root_window_) { |
687 gfx::Rect root_bounds = current_root->bounds(); | 694 gfx::Rect root_bounds = current_root->bounds(); |
688 if (root_bounds.Contains(event->root_location())) | 695 if (root_bounds.Contains(event->root_location())) |
689 point_of_interest_ = event->root_location(); | 696 point_of_interest_ = event->root_location(); |
690 } | 697 } |
691 } | 698 } |
692 | 699 |
700 void MagnificationControllerImpl::OnGestureEvent(ui::GestureEvent* event) { | |
701 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
702 chromeos::switches::kEnableTouchSupportForScreenMagnification)) { | |
703 return; | |
704 } | |
705 | |
706 const ui::GestureEventDetails& details = event->details(); | |
707 if (details.type() == ui::ET_GESTURE_SCROLL_UPDATE && | |
708 details.touch_points() == 2 && !is_performing_pinch_gesture_) { | |
709 gfx::Rect viewport_rect_in_dip = GetViewportRect(); | |
710 viewport_rect_in_dip.Offset(details.scroll_x() * -1, | |
711 details.scroll_y() * -1); | |
712 const gfx::Rect& viewport_rect_in_pixel = | |
713 ui::ConvertRectToPixel(root_window_->layer(), viewport_rect_in_dip); | |
714 MoveWindow(viewport_rect_in_pixel.origin(), false); | |
715 event->SetHandled(); | |
716 } else if (details.type() == ui::ET_GESTURE_PINCH_BEGIN) { | |
717 // Set this flag to prevent scrolling while user is changing zoom level. | |
718 is_performing_pinch_gesture_ = true; | |
719 event->SetHandled(); | |
720 } else if (details.type() == ui::ET_GESTURE_PINCH_END) { | |
721 is_performing_pinch_gesture_ = false; | |
722 event->SetHandled(); | |
723 } else if (details.type() == ui::ET_GESTURE_PINCH_UPDATE && | |
724 details.touch_points() == 3) { | |
725 float scale = GetScale() * details.scale(); | |
726 | |
727 if (scale < kMinMagnifiedScaleThreshold) { | |
728 scale = kMinMagnifiedScaleThreshold; | |
729 } else if (scale > kMaxMagnifiedScaleThreshold) { | |
730 scale = kMaxMagnifiedScaleThreshold; | |
731 } | |
732 | |
733 point_of_interest_ = event->root_location(); | |
yoshiki
2017/01/20 05:26:33
Should we move the mouse cursor to the point of in
yawano
2017/02/06 06:49:04
I don't think we need to do it. IIUC, the mouse cu
yoshiki
2017/02/06 17:22:07
Thank you for explanation. Then, ok.
| |
734 SetScale(scale, false); | |
735 event->SetHandled(); | |
736 } | |
737 } | |
738 | |
693 void MagnificationControllerImpl::MoveMagnifierWindowFollowPoint( | 739 void MagnificationControllerImpl::MoveMagnifierWindowFollowPoint( |
694 const gfx::Point& point, | 740 const gfx::Point& point, |
695 int x_panning_margin, | 741 int x_panning_margin, |
696 int y_panning_margin, | 742 int y_panning_margin, |
697 int x_target_margin, | 743 int x_target_margin, |
698 int y_target_margin) { | 744 int y_target_margin) { |
699 DCHECK(root_window_); | 745 DCHECK(root_window_); |
700 bool start_zoom = false; | 746 bool start_zoom = false; |
701 | 747 |
702 const gfx::Rect window_rect = GetViewportRect(); | 748 const gfx::Rect window_rect = GetViewportRect(); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
857 | 903 |
858 //////////////////////////////////////////////////////////////////////////////// | 904 //////////////////////////////////////////////////////////////////////////////// |
859 // MagnificationController: | 905 // MagnificationController: |
860 | 906 |
861 // static | 907 // static |
862 MagnificationController* MagnificationController::CreateInstance() { | 908 MagnificationController* MagnificationController::CreateInstance() { |
863 return new MagnificationControllerImpl(); | 909 return new MagnificationControllerImpl(); |
864 } | 910 } |
865 | 911 |
866 } // namespace ash | 912 } // namespace ash |
OLD | NEW |