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

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

Issue 2641733002: Initial patch set to implement improved touch support for screen magnification (Closed)
Patch Set: Created 3 years, 11 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
« no previous file with comments | « no previous file | chrome/app/generated_resources.grd » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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
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
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 changing zoom level by touch or not.
268 bool is_changing_zoom_level_by_touch_;
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_changing_zoom_level_by_touch_(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
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::kEnableTouchSupportInScreenMagnification)) {
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_changing_zoom_level_by_touch_) {
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 &&
yoshiki 2017/01/19 06:30:20 As talked offline, could you check if this logic w
yawano 2017/01/19 06:45:55 I've tested this and we get gesture end event and
yawano 2017/01/19 07:54:25 Done.
yoshiki 2017/01/20 05:26:33 If "we get gesture end event and begin event when
yawano 2017/02/06 06:49:04 Removed is_performing_pinch_gesture_ flag. We can
717 details.touch_points() == 3) {
718 // Set this flag to prevent scrolling while user is zooming.
719 is_changing_zoom_level_by_touch_ = true;
720 event->SetHandled();
721 } else if (details.type() == ui::ET_GESTURE_PINCH_END &&
722 details.touch_points() == 3) {
723 is_changing_zoom_level_by_touch_ = false;
724 event->SetHandled();
725 } else if (details.type() == ui::ET_GESTURE_PINCH_UPDATE &&
726 details.touch_points() == 3) {
727 float scale = GetScale() * details.scale();
728
729 if (scale < kMinMagnifiedScaleThreshold) {
730 scale = kMinMagnifiedScaleThreshold;
731 } else if (scale > kMaxMagnifiedScaleThreshold) {
732 scale = kMaxMagnifiedScaleThreshold;
733 }
734
735 point_of_interest_ = event->root_location();
736 SetScale(scale, false);
737 event->SetHandled();
738 }
739 }
740
693 void MagnificationControllerImpl::MoveMagnifierWindowFollowPoint( 741 void MagnificationControllerImpl::MoveMagnifierWindowFollowPoint(
694 const gfx::Point& point, 742 const gfx::Point& point,
695 int x_panning_margin, 743 int x_panning_margin,
696 int y_panning_margin, 744 int y_panning_margin,
697 int x_target_margin, 745 int x_target_margin,
698 int y_target_margin) { 746 int y_target_margin) {
699 DCHECK(root_window_); 747 DCHECK(root_window_);
700 bool start_zoom = false; 748 bool start_zoom = false;
701 749
702 const gfx::Rect window_rect = GetViewportRect(); 750 const gfx::Rect window_rect = GetViewportRect();
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 905
858 //////////////////////////////////////////////////////////////////////////////// 906 ////////////////////////////////////////////////////////////////////////////////
859 // MagnificationController: 907 // MagnificationController:
860 908
861 // static 909 // static
862 MagnificationController* MagnificationController::CreateInstance() { 910 MagnificationController* MagnificationController::CreateInstance() {
863 return new MagnificationControllerImpl(); 911 return new MagnificationControllerImpl();
864 } 912 }
865 913
866 } // namespace ash 914 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | chrome/app/generated_resources.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698