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

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

Issue 1157553003: Center the focus of the text input in magnifier screen. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remvoe MagnifierAnimationWaiter from unittest code, etc. Created 5 years, 6 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/magnification_controller.h" 5 #include "ash/magnifier/magnification_controller.h"
6 6
7 #include "ash/accelerators/accelerator_controller.h" 7 #include "ash/accelerators/accelerator_controller.h"
8 #include "ash/accessibility_delegate.h" 8 #include "ash/accessibility_delegate.h"
9 #include "ash/ash_switches.h" 9 #include "ash/ash_switches.h"
10 #include "ash/display/root_window_transformers.h" 10 #include "ash/display/root_window_transformers.h"
11 #include "ash/host/ash_window_tree_host.h" 11 #include "ash/host/ash_window_tree_host.h"
12 #include "ash/host/root_window_transformer.h" 12 #include "ash/host/root_window_transformer.h"
13 #include "ash/root_window_controller.h" 13 #include "ash/root_window_controller.h"
14 #include "ash/screen_util.h" 14 #include "ash/screen_util.h"
15 #include "ash/shell.h" 15 #include "ash/shell.h"
16 #include "ash/system/tray/system_tray_delegate.h" 16 #include "ash/system/tray/system_tray_delegate.h"
17 #include "base/command_line.h" 17 #include "base/command_line.h"
18 #include "base/synchronization/waitable_event.h" 18 #include "base/synchronization/waitable_event.h"
19 #include "base/timer/timer.h"
19 #include "ui/aura/client/aura_constants.h" 20 #include "ui/aura/client/aura_constants.h"
20 #include "ui/aura/client/cursor_client.h" 21 #include "ui/aura/client/cursor_client.h"
21 #include "ui/aura/window.h" 22 #include "ui/aura/window.h"
22 #include "ui/aura/window_tree_host.h" 23 #include "ui/aura/window_tree_host.h"
23 #include "ui/base/ime/input_method.h" 24 #include "ui/base/ime/input_method.h"
24 #include "ui/base/ime/input_method_observer.h" 25 #include "ui/base/ime/input_method_observer.h"
25 #include "ui/base/ime/text_input_client.h" 26 #include "ui/base/ime/text_input_client.h"
26 #include "ui/compositor/dip_util.h" 27 #include "ui/compositor/dip_util.h"
27 #include "ui/compositor/layer.h" 28 #include "ui/compositor/layer.h"
28 #include "ui/compositor/layer_animation_observer.h" 29 #include "ui/compositor/layer_animation_observer.h"
(...skipping 11 matching lines...) Expand all
40 namespace { 41 namespace {
41 42
42 const float kMaxMagnifiedScale = 4.0f; 43 const float kMaxMagnifiedScale = 4.0f;
43 const float kMaxMagnifiedScaleThreshold = 4.0f; 44 const float kMaxMagnifiedScaleThreshold = 4.0f;
44 const float kMinMagnifiedScaleThreshold = 1.1f; 45 const float kMinMagnifiedScaleThreshold = 1.1f;
45 const float kNonMagnifiedScale = 1.0f; 46 const float kNonMagnifiedScale = 1.0f;
46 47
47 const float kInitialMagnifiedScale = 2.0f; 48 const float kInitialMagnifiedScale = 2.0f;
48 const float kScrollScaleChangeFactor = 0.05f; 49 const float kScrollScaleChangeFactor = 0.05f;
49 50
51 // Default animation parameters for redrawing the magnification window.
52 const gfx::Tween::Type kDefaultAnimationTweenType = gfx::Tween::EASE_OUT;
53 const int kDefaultAnimationDurationInMs = 100;
54
55 // Use linear transformation to make the magnifier window move smoothly
56 // to center the focus when user types in a text input field.
57 const gfx::Tween::Type kCenterCaretAnimationTweenType = gfx::Tween::LINEAR;
58
59 // The delay of the timer for moving magnifier window for centering the text
60 // input focus.
61 const int kMoveMagnifierDelayInMs = 5;
62
50 // Threadshold of panning. If the cursor moves to within pixels (in DIP) of 63 // Threadshold of panning. If the cursor moves to within pixels (in DIP) of
51 // |kPanningMergin| from the edge, the view-port moves. 64 // |kCursorPanningMargin| from the edge, the view-port moves.
52 const int kPanningMergin = 100; 65 const int kCursorPanningMargin = 100;
53 66
54 // Gives a little panning margin for following caret, so that we will move the 67 // Threadshold of panning. If the caret moves to within pixels (in DIP) of
55 // view-port before the caret is completely out of sight. 68 // |kCaretPanningMargin| from the edge, the view-port moves.
56 const int kCaretPanningMargin = 10; 69 const int kCaretPanningMargin = 50;
57 70
58 void MoveCursorTo(aura::WindowTreeHost* host, const gfx::Point& root_location) { 71 void MoveCursorTo(aura::WindowTreeHost* host, const gfx::Point& root_location) {
59 gfx::Point3F host_location_3f(root_location); 72 gfx::Point3F host_location_3f(root_location);
60 host->GetRootTransform().TransformPoint(&host_location_3f); 73 host->GetRootTransform().TransformPoint(&host_location_3f);
61 host->MoveCursorToHostLocation( 74 host->MoveCursorToHostLocation(
62 gfx::ToCeiledPoint(host_location_3f.AsPointF())); 75 gfx::ToCeiledPoint(host_location_3f.AsPointF()));
63 } 76 }
64 77
65 } // namespace 78 } // namespace
66 79
67 namespace ash { 80 namespace ash {
68 81
69 //////////////////////////////////////////////////////////////////////////////// 82 ////////////////////////////////////////////////////////////////////////////////
70 // MagnificationControllerImpl: 83 // MagnificationControllerImpl:
71 84
72 class MagnificationControllerImpl : virtual public MagnificationController, 85 class MagnificationControllerImpl : virtual public MagnificationController,
73 public ui::EventHandler, 86 public ui::EventHandler,
74 public ui::ImplicitAnimationObserver, 87 public ui::ImplicitAnimationObserver,
75 public aura::WindowObserver, 88 public aura::WindowObserver,
76 public ui::InputMethodObserver { 89 public ui::InputMethodObserver {
77 public: 90 public:
78 MagnificationControllerImpl(); 91 MagnificationControllerImpl();
79 ~MagnificationControllerImpl() override; 92 ~MagnificationControllerImpl() override;
80 93
81 // MagnificationController overrides: 94 // MagnificationController overrides:
82 void SetEnabled(bool enabled) override; 95 void SetEnabled(bool enabled) override;
83 bool IsEnabled() const override; 96 bool IsEnabled() const override;
97 void SetKeepFocusCentered(bool keep_focus_centered) override;
98 bool KeepFocusCentered() const override;
84 void SetScale(float scale, bool animate) override; 99 void SetScale(float scale, bool animate) override;
85 float GetScale() const override { return scale_; } 100 float GetScale() const override { return scale_; }
86 void MoveWindow(int x, int y, bool animate) override; 101 void MoveWindow(int x, int y, bool animate) override;
87 void MoveWindow(const gfx::Point& point, bool animate) override; 102 void MoveWindow(const gfx::Point& point, bool animate) override;
88 gfx::Point GetWindowPosition() const override { 103 gfx::Point GetWindowPosition() const override {
89 return gfx::ToFlooredPoint(origin_); 104 return gfx::ToFlooredPoint(origin_);
90 } 105 }
91 void SetScrollDirection(ScrollDirection direction) override; 106 void SetScrollDirection(ScrollDirection direction) override;
92 gfx::Rect GetViewportRect() const override; 107 gfx::Rect GetViewportRect() const override;
93 void HandleFocusedNodeChanged( 108 void HandleFocusedNodeChanged(
(...skipping 17 matching lines...) Expand all
111 void OnWindowDestroying(aura::Window* root_window) override; 126 void OnWindowDestroying(aura::Window* root_window) override;
112 void OnWindowBoundsChanged(aura::Window* window, 127 void OnWindowBoundsChanged(aura::Window* window,
113 const gfx::Rect& old_bounds, 128 const gfx::Rect& old_bounds,
114 const gfx::Rect& new_bounds) override; 129 const gfx::Rect& new_bounds) override;
115 130
116 // Redraws the magnification window with the given origin position and the 131 // Redraws the magnification window with the given origin position and the
117 // given scale. Returns true if the window is changed; otherwise, false. 132 // given scale. Returns true if the window is changed; otherwise, false.
118 // These methods should be called internally just after the scale and/or 133 // These methods should be called internally just after the scale and/or
119 // the position are changed to redraw the window. 134 // the position are changed to redraw the window.
120 bool Redraw(const gfx::PointF& position, float scale, bool animate); 135 bool Redraw(const gfx::PointF& position, float scale, bool animate);
121 bool RedrawDIP(const gfx::PointF& position, float scale, bool animate); 136
137 // Redraws the magnification window with the given origin position in dip and
138 // the given scale. Returns true if the window is changed; otherwise, false.
139 // The last two parameters specify the animation duration and tween type.
140 // If |animation_in_ms| is zero, there will be no animation, and |tween_type|
141 // will be ignored.
142 bool RedrawDIP(const gfx::PointF& position_in_dip,
143 float scale,
144 int animation_in_ms,
145 gfx::Tween::Type tween_type);
122 146
123 // 1) If the screen is scrolling (i.e. animating) and should scroll further, 147 // 1) If the screen is scrolling (i.e. animating) and should scroll further,
124 // it does nothing. 148 // it does nothing.
125 // 2) If the screen is scrolling (i.e. animating) and the direction is NONE, 149 // 2) If the screen is scrolling (i.e. animating) and the direction is NONE,
126 // it stops the scrolling animation. 150 // it stops the scrolling animation.
127 // 3) If the direction is set to value other than NONE, it starts the 151 // 3) If the direction is set to value other than NONE, it starts the
128 // scrolling/ animation towards that direction. 152 // scrolling/ animation towards that direction.
129 void StartOrStopScrollIfNecessary(); 153 void StartOrStopScrollIfNecessary();
130 154
131 // Redraw with the given zoom scale keeping the mouse cursor location. In 155 // Redraw with the given zoom scale keeping the mouse cursor location. In
(...skipping 27 matching lines...) Expand all
159 // |x_panning_margin| and |y_pannin_margin| to the edge of the visible 183 // |x_panning_margin| and |y_pannin_margin| to the edge of the visible
160 // window region. The view port will be moved so that the |point| will be 184 // window region. The view port will be moved so that the |point| will be
161 // moved to the point where it has |x_target_margin| and |y_target_margin| 185 // moved to the point where it has |x_target_margin| and |y_target_margin|
162 // to the edge of the visible region. 186 // to the edge of the visible region.
163 void MoveMagnifierWindowFollowPoint(const gfx::Point& point, 187 void MoveMagnifierWindowFollowPoint(const gfx::Point& point,
164 int x_panning_margin, 188 int x_panning_margin,
165 int y_panning_margin, 189 int y_panning_margin,
166 int x_target_margin, 190 int x_target_margin,
167 int y_target_margin); 191 int y_target_margin);
168 192
193 // Moves the view port to center |point| in magnifier screen.
194 void MoveMagnifierWindowCenterPoint(const gfx::Point& point);
195
169 // Moves the viewport so that |rect| is fully visible. If |rect| is larger 196 // Moves the viewport so that |rect| is fully visible. If |rect| is larger
170 // than the viewport horizontally or vertically, the viewport will be moved 197 // than the viewport horizontally or vertically, the viewport will be moved
171 // to center the |rect| in that dimension. 198 // to center the |rect| in that dimension.
172 void MoveMagnifierWindowFollowRect(const gfx::Rect& rect); 199 void MoveMagnifierWindowFollowRect(const gfx::Rect& rect);
173 200
201 // Invoked when |move_magnifier_timer_| fires to move the magnifier window to
202 // follow the caret.
203 void OnMoveMagnifierTimer();
204
174 // ui::InputMethodObserver: 205 // ui::InputMethodObserver:
175 void OnTextInputTypeChanged(const ui::TextInputClient* client) override {} 206 void OnTextInputTypeChanged(const ui::TextInputClient* client) override {}
176 void OnFocus() override {} 207 void OnFocus() override {}
177 void OnBlur() override {} 208 void OnBlur() override {}
178 void OnTextInputStateChanged(const ui::TextInputClient* client) override {} 209 void OnTextInputStateChanged(const ui::TextInputClient* client) override {}
179 void OnInputMethodDestroyed(const ui::InputMethod* input_method) override {} 210 void OnInputMethodDestroyed(const ui::InputMethod* input_method) override {}
180 void OnShowImeIfNeeded() override {} 211 void OnShowImeIfNeeded() override {}
181 void OnCaretBoundsChanged(const ui::TextInputClient* client) override; 212 void OnCaretBoundsChanged(const ui::TextInputClient* client) override;
182 213
183 // Target root window. This must not be NULL. 214 // Target root window. This must not be NULL.
184 aura::Window* root_window_; 215 aura::Window* root_window_;
185 216
186 // True if the magnified window is currently animating a change. Otherwise, 217 // True if the magnified window is currently animating a change. Otherwise,
187 // false. 218 // false.
188 bool is_on_animation_; 219 bool is_on_animation_;
189 220
190 bool is_enabled_; 221 bool is_enabled_;
191 222
223 bool keep_focus_centered_;
224
192 // True if the cursor needs to move the given position after the animation 225 // True if the cursor needs to move the given position after the animation
193 // will be finished. When using this, set |position_after_animation_| as well. 226 // will be finished. When using this, set |position_after_animation_| as well.
194 bool move_cursor_after_animation_; 227 bool move_cursor_after_animation_;
195 // Stores the position of cursor to be moved after animation. 228 // Stores the position of cursor to be moved after animation.
196 gfx::Point position_after_animation_; 229 gfx::Point position_after_animation_;
197 230
198 // Stores the last mouse cursor (or last touched) location. This value is 231 // Stores the last mouse cursor (or last touched) location. This value is
199 // used on zooming to keep this location visible. 232 // used on zooming to keep this location visible.
200 gfx::Point point_of_interest_; 233 gfx::Point point_of_interest_;
201 234
202 // Current scale, origin (left-top) position of the magnification window. 235 // Current scale, origin (left-top) position of the magnification window.
203 float scale_; 236 float scale_;
204 gfx::PointF origin_; 237 gfx::PointF origin_;
205 238
206 ScrollDirection scroll_direction_; 239 ScrollDirection scroll_direction_;
207 240
208 ui::InputMethod* input_method_; // Not owned. 241 ui::InputMethod* input_method_; // Not owned.
209 242
243 // Timer for moving magnifier window when it fires.
244 base::OneShotTimer<MagnificationControllerImpl> move_magnifier_timer_;
245
246 // Most recent caret position in |root_window_| coordinates.
247 gfx::Point caret_point_;
248
210 DISALLOW_COPY_AND_ASSIGN(MagnificationControllerImpl); 249 DISALLOW_COPY_AND_ASSIGN(MagnificationControllerImpl);
211 }; 250 };
212 251
213 //////////////////////////////////////////////////////////////////////////////// 252 ////////////////////////////////////////////////////////////////////////////////
214 // MagnificationControllerImpl: 253 // MagnificationControllerImpl:
215 254
216 MagnificationControllerImpl::MagnificationControllerImpl() 255 MagnificationControllerImpl::MagnificationControllerImpl()
217 : root_window_(Shell::GetPrimaryRootWindow()), 256 : root_window_(Shell::GetPrimaryRootWindow()),
218 is_on_animation_(false), 257 is_on_animation_(false),
219 is_enabled_(false), 258 is_enabled_(false),
259 keep_focus_centered_(false),
220 move_cursor_after_animation_(false), 260 move_cursor_after_animation_(false),
221 scale_(kNonMagnifiedScale), 261 scale_(kNonMagnifiedScale),
222 scroll_direction_(SCROLL_NONE), 262 scroll_direction_(SCROLL_NONE),
223 input_method_(NULL) { 263 input_method_(NULL) {
224 Shell::GetInstance()->AddPreTargetHandler(this); 264 Shell::GetInstance()->AddPreTargetHandler(this);
225 root_window_->AddObserver(this); 265 root_window_->AddObserver(this);
226 point_of_interest_ = root_window_->bounds().CenterPoint(); 266 point_of_interest_ = root_window_->bounds().CenterPoint();
227 } 267 }
228 268
229 MagnificationControllerImpl::~MagnificationControllerImpl() { 269 MagnificationControllerImpl::~MagnificationControllerImpl() {
(...skipping 11 matching lines...) Expand all
241 281
242 // mouse_in_root is invalid value when the cursor is hidden. 282 // mouse_in_root is invalid value when the cursor is hidden.
243 if (!root_window_->bounds().Contains(mouse_in_root)) 283 if (!root_window_->bounds().Contains(mouse_in_root))
244 mouse_in_root = root_window_->bounds().CenterPoint(); 284 mouse_in_root = root_window_->bounds().CenterPoint();
245 285
246 const gfx::PointF origin = 286 const gfx::PointF origin =
247 gfx::PointF(mouse_in_root.x() - 287 gfx::PointF(mouse_in_root.x() -
248 (scale_ / scale) * (mouse_in_root.x() - origin_.x()), 288 (scale_ / scale) * (mouse_in_root.x() - origin_.x()),
249 mouse_in_root.y() - 289 mouse_in_root.y() -
250 (scale_ / scale) * (mouse_in_root.y() - origin_.y())); 290 (scale_ / scale) * (mouse_in_root.y() - origin_.y()));
251 bool changed = RedrawDIP(origin, scale, animate); 291 bool changed = RedrawDIP(origin, scale,
292 animate ? kDefaultAnimationDurationInMs : 0,
293 kDefaultAnimationTweenType);
252 if (changed) 294 if (changed)
253 AfterAnimationMoveCursorTo(mouse_in_root); 295 AfterAnimationMoveCursorTo(mouse_in_root);
254 } 296 }
255 297
256 bool MagnificationControllerImpl::Redraw(const gfx::PointF& position, 298 bool MagnificationControllerImpl::Redraw(const gfx::PointF& position,
257 float scale, 299 float scale,
258 bool animate) { 300 bool animate) {
259 const gfx::PointF position_in_dip = 301 const gfx::PointF position_in_dip =
260 ui::ConvertPointToDIP(root_window_->layer(), position); 302 ui::ConvertPointToDIP(root_window_->layer(), position);
261 return RedrawDIP(position_in_dip, scale, animate); 303 return RedrawDIP(position_in_dip, scale,
304 animate ? kDefaultAnimationDurationInMs : 0,
305 kDefaultAnimationTweenType);
262 } 306 }
263 307
264 bool MagnificationControllerImpl::RedrawDIP(const gfx::PointF& position_in_dip, 308 bool MagnificationControllerImpl::RedrawDIP(const gfx::PointF& position_in_dip,
265 float scale, 309 float scale,
266 bool animate) { 310 int duration_in_ms,
311 gfx::Tween::Type tween_type) {
267 DCHECK(root_window_); 312 DCHECK(root_window_);
268 313
269 float x = position_in_dip.x(); 314 float x = position_in_dip.x();
270 float y = position_in_dip.y(); 315 float y = position_in_dip.y();
271 316
272 ValidateScale(&scale); 317 ValidateScale(&scale);
273 318
274 if (x < 0) 319 if (x < 0)
275 x = 0; 320 x = 0;
276 if (y < 0) 321 if (y < 0)
(...skipping 24 matching lines...) Expand all
301 // Flips the signs intentionally to convert them from the position of the 346 // Flips the signs intentionally to convert them from the position of the
302 // magnification window. 347 // magnification window.
303 transform.Scale(scale_, scale_); 348 transform.Scale(scale_, scale_);
304 transform.Translate(-origin_.x(), -origin_.y()); 349 transform.Translate(-origin_.x(), -origin_.y());
305 350
306 ui::ScopedLayerAnimationSettings settings( 351 ui::ScopedLayerAnimationSettings settings(
307 root_window_->layer()->GetAnimator()); 352 root_window_->layer()->GetAnimator());
308 settings.AddObserver(this); 353 settings.AddObserver(this);
309 settings.SetPreemptionStrategy( 354 settings.SetPreemptionStrategy(
310 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 355 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
311 settings.SetTweenType(gfx::Tween::EASE_OUT); 356 settings.SetTweenType(tween_type);
312 settings.SetTransitionDuration( 357 settings.SetTransitionDuration(
313 base::TimeDelta::FromMilliseconds(animate ? 100 : 0)); 358 base::TimeDelta::FromMilliseconds(duration_in_ms));
314 359
315 gfx::Display display = 360 gfx::Display display =
316 Shell::GetScreen()->GetDisplayNearestWindow(root_window_); 361 Shell::GetScreen()->GetDisplayNearestWindow(root_window_);
317 scoped_ptr<RootWindowTransformer> transformer( 362 scoped_ptr<RootWindowTransformer> transformer(
318 CreateRootWindowTransformerForDisplay(root_window_, display)); 363 CreateRootWindowTransformerForDisplay(root_window_, display));
319 GetRootWindowController(root_window_)->ash_host()->SetRootWindowTransformer( 364 GetRootWindowController(root_window_)->ash_host()->SetRootWindowTransformer(
320 transformer.Pass()); 365 transformer.Pass());
321 366
322 if (animate) 367 if (duration_in_ms > 0)
323 is_on_animation_ = true; 368 is_on_animation_ = true;
324 369
325 return true; 370 return true;
326 } 371 }
327 372
328 void MagnificationControllerImpl::StartOrStopScrollIfNecessary() { 373 void MagnificationControllerImpl::StartOrStopScrollIfNecessary() {
329 // This value controls the scrolling speed. 374 // This value controls the scrolling speed.
330 const int kMoveOffset = 40; 375 const int kMoveOffset = 40;
331 if (is_on_animation_) { 376 if (is_on_animation_) {
332 if (scroll_direction_ == SCROLL_NONE) 377 if (scroll_direction_ == SCROLL_NONE)
(...skipping 12 matching lines...) Expand all
345 case SCROLL_RIGHT: 390 case SCROLL_RIGHT:
346 new_origin.Offset(kMoveOffset, 0); 391 new_origin.Offset(kMoveOffset, 0);
347 break; 392 break;
348 case SCROLL_UP: 393 case SCROLL_UP:
349 new_origin.Offset(0, -kMoveOffset); 394 new_origin.Offset(0, -kMoveOffset);
350 break; 395 break;
351 case SCROLL_DOWN: 396 case SCROLL_DOWN:
352 new_origin.Offset(0, kMoveOffset); 397 new_origin.Offset(0, kMoveOffset);
353 break; 398 break;
354 } 399 }
355 RedrawDIP(new_origin, scale_, true); 400 RedrawDIP(new_origin, scale_, kDefaultAnimationDurationInMs,
401 kDefaultAnimationTweenType);
356 } 402 }
357 403
358 void MagnificationControllerImpl::OnMouseMove(const gfx::Point& location) { 404 void MagnificationControllerImpl::OnMouseMove(const gfx::Point& location) {
359 DCHECK(root_window_); 405 DCHECK(root_window_);
360 406
361 gfx::Point mouse(location); 407 gfx::Point mouse(location);
362 int margin = kPanningMergin / scale_; // No need to consider DPI. 408 int margin = kCursorPanningMargin / scale_; // No need to consider DPI.
363 MoveMagnifierWindowFollowPoint(mouse, margin, margin, margin, margin); 409 MoveMagnifierWindowFollowPoint(mouse, margin, margin, margin, margin);
364 } 410 }
365 411
366 gfx::Rect MagnificationControllerImpl::GetViewportRect() const { 412 gfx::Rect MagnificationControllerImpl::GetViewportRect() const {
367 return gfx::ToEnclosingRect(GetWindowRectDIP(scale_)); 413 return gfx::ToEnclosingRect(GetWindowRectDIP(scale_));
368 } 414 }
369 415
370 void MagnificationControllerImpl::HandleFocusedNodeChanged( 416 void MagnificationControllerImpl::HandleFocusedNodeChanged(
371 bool is_editable_node, 417 bool is_editable_node,
372 const gfx::Rect& node_bounds_in_screen) { 418 const gfx::Rect& node_bounds_in_screen) {
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 609
564 RedrawKeepingMousePosition(kNonMagnifiedScale, true); 610 RedrawKeepingMousePosition(kNonMagnifiedScale, true);
565 is_enabled_ = enabled; 611 is_enabled_ = enabled;
566 } 612 }
567 } 613 }
568 614
569 bool MagnificationControllerImpl::IsEnabled() const { 615 bool MagnificationControllerImpl::IsEnabled() const {
570 return is_enabled_; 616 return is_enabled_;
571 } 617 }
572 618
619 void MagnificationControllerImpl::SetKeepFocusCentered(
620 bool keep_focus_centered) {
621 keep_focus_centered_ = keep_focus_centered;
622 }
623
624 bool MagnificationControllerImpl::KeepFocusCentered() const {
625 return keep_focus_centered_;
626 }
627
573 //////////////////////////////////////////////////////////////////////////////// 628 ////////////////////////////////////////////////////////////////////////////////
574 // MagnificationControllerImpl: aura::EventFilter implementation 629 // MagnificationControllerImpl: aura::EventFilter implementation
575 630
576 void MagnificationControllerImpl::OnMouseEvent(ui::MouseEvent* event) { 631 void MagnificationControllerImpl::OnMouseEvent(ui::MouseEvent* event) {
577 aura::Window* target = static_cast<aura::Window*>(event->target()); 632 aura::Window* target = static_cast<aura::Window*>(event->target());
578 aura::Window* current_root = target->GetRootWindow(); 633 aura::Window* current_root = target->GetRootWindow();
579 gfx::Rect root_bounds = current_root->bounds(); 634 gfx::Rect root_bounds = current_root->bounds();
580 635
581 if (root_bounds.Contains(event->root_location())) { 636 if (root_bounds.Contains(event->root_location())) {
582 // This must be before |SwitchTargetRootWindow()|. 637 // This must be before |SwitchTargetRootWindow()|.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 // Panning up. 710 // Panning up.
656 y_diff = point.y() - (top + y_target_margin); 711 y_diff = point.y() - (top + y_target_margin);
657 start_zoom = true; 712 start_zoom = true;
658 } else if (bottom - y_panning_margin < point.y()) { 713 } else if (bottom - y_panning_margin < point.y()) {
659 // Panning down. 714 // Panning down.
660 y_diff = point.y() - (bottom - y_target_margin); 715 y_diff = point.y() - (bottom - y_target_margin);
661 start_zoom = true; 716 start_zoom = true;
662 } 717 }
663 int y = top + y_diff; 718 int y = top + y_diff;
664 if (start_zoom && !is_on_animation_) { 719 if (start_zoom && !is_on_animation_) {
665 // No animation on panning. 720 bool ret = RedrawDIP(gfx::Point(x, y), scale_,
666 bool animate = false; 721 0, // No animation on panning.
667 bool ret = RedrawDIP(gfx::Point(x, y), scale_, animate); 722 kDefaultAnimationTweenType);
668 723
669 if (ret) { 724 if (ret) {
670 // If the magnified region is moved, hides the mouse cursor and moves it. 725 // If the magnified region is moved, hides the mouse cursor and moves it.
671 if (x_diff != 0 || y_diff != 0) 726 if (x_diff != 0 || y_diff != 0)
672 MoveCursorTo(root_window_->GetHost(), point); 727 MoveCursorTo(root_window_->GetHost(), point);
673 } 728 }
674 } 729 }
675 } 730 }
676 731
732 void MagnificationControllerImpl::MoveMagnifierWindowCenterPoint(
733 const gfx::Point& point) {
734 DCHECK(root_window_);
735
736 const gfx::Rect window_rect = GetViewportRect();
737 if (point == window_rect.CenterPoint())
738 return;
739
740 if (!is_on_animation_) {
741 // With animation on panning.
742 RedrawDIP(window_rect.origin() + (point - window_rect.CenterPoint()),
743 scale_, kDefaultAnimationDurationInMs,
744 kCenterCaretAnimationTweenType);
745 }
746 }
747
677 void MagnificationControllerImpl::MoveMagnifierWindowFollowRect( 748 void MagnificationControllerImpl::MoveMagnifierWindowFollowRect(
678 const gfx::Rect& rect) { 749 const gfx::Rect& rect) {
679 DCHECK(root_window_); 750 DCHECK(root_window_);
680 bool should_pan = false; 751 bool should_pan = false;
681 752
682 const gfx::Rect viewport_rect = GetViewportRect(); 753 const gfx::Rect viewport_rect = GetViewportRect();
683 const int left = viewport_rect.x(); 754 const int left = viewport_rect.x();
684 const int right = viewport_rect.right(); 755 const int right = viewport_rect.right();
685 const gfx::Point rect_center = rect.CenterPoint(); 756 const gfx::Point rect_center = rect.CenterPoint();
686 const gfx::Point window_center = viewport_rect.CenterPoint(); 757 const gfx::Point window_center = viewport_rect.CenterPoint();
(...skipping 13 matching lines...) Expand all
700 // Panning vertically. 771 // Panning vertically.
701 y = rect_center.y() - viewport_rect.height() / 2; 772 y = rect_center.y() - viewport_rect.height() / 2;
702 should_pan = true; 773 should_pan = true;
703 } 774 }
704 775
705 if (should_pan) { 776 if (should_pan) {
706 if (is_on_animation_) { 777 if (is_on_animation_) {
707 root_window_->layer()->GetAnimator()->StopAnimating(); 778 root_window_->layer()->GetAnimator()->StopAnimating();
708 is_on_animation_ = false; 779 is_on_animation_ = false;
709 } 780 }
710 RedrawDIP(gfx::Point(x, y), scale_, false); // No animation on panning. 781 RedrawDIP(gfx::Point(x, y), scale_,
782 0, // No animation on panning.
783 kDefaultAnimationTweenType);
711 } 784 }
712 } 785 }
713 786
787 void MagnificationControllerImpl::OnMoveMagnifierTimer() {
788 MoveMagnifierWindowCenterPoint(caret_point_);
789 }
790
714 void MagnificationControllerImpl::OnCaretBoundsChanged( 791 void MagnificationControllerImpl::OnCaretBoundsChanged(
715 const ui::TextInputClient* client) { 792 const ui::TextInputClient* client) {
716 // caret bounds in screen coordinates. 793 // caret bounds in screen coordinates.
717 const gfx::Rect caret_bounds = client->GetCaretBounds(); 794 const gfx::Rect caret_bounds = client->GetCaretBounds();
718 // Note: OnCaretBoundsChanged could be fired OnTextInputTypeChanged during 795 // Note: OnCaretBoundsChanged could be fired OnTextInputTypeChanged during
719 // which the caret position is not set a meaning position, and we do not 796 // which the caret position is not set a meaning position, and we do not
720 // need to adjust the view port position based on the bogus caret position. 797 // need to adjust the view port position based on the bogus caret position.
721 // This is only a transition period, the caret position will be fixed upon 798 // This is only a transition period, the caret position will be fixed upon
722 // focusing right after. 799 // focusing right after.
723 if (caret_bounds.width() == 0 && caret_bounds.height() == 0) 800 if (caret_bounds.width() == 0 && caret_bounds.height() == 0)
724 return; 801 return;
725 802
726 gfx::Point caret_origin = caret_bounds.origin(); 803 caret_point_ = caret_bounds.CenterPoint();
727 // caret_origin in |root_window_| coordinates. 804 // |caret_point_| in |root_window_| coordinates.
728 wm::ConvertPointFromScreen(root_window_, &caret_origin); 805 wm::ConvertPointFromScreen(root_window_, &caret_point_);
729 806
730 // Visible window_rect in |root_window_| coordinates. 807 // If the feature for centering the text input focus is disabled, the
731 const gfx::Rect visible_window_rect = GetViewportRect(); 808 // magnifier window will be moved to follow the focus with a panning margin.
809 if (!KeepFocusCentered()) {
810 // Visible window_rect in |root_window_| coordinates.
811 const gfx::Rect visible_window_rect = GetViewportRect();
812 const int panning_margin = kCaretPanningMargin / scale_;
813 MoveMagnifierWindowFollowPoint(caret_point_,
814 panning_margin,
815 panning_margin,
816 visible_window_rect.width() / 2,
817 visible_window_rect.height() / 2);
818 return;
819 }
732 820
733 const int panning_margin = kCaretPanningMargin / scale_; 821 // Move the magnifier window to center the focus with a little delay.
734 MoveMagnifierWindowFollowPoint(caret_origin, panning_margin, panning_margin, 822 // In Gmail compose window, when user types a blank space, it will insert
735 visible_window_rect.width() / 2, 823 // a non-breaking space(NBSP). NBSP will be replaced with a blank space
736 visible_window_rect.height() / 2); 824 // character when user types a non-blank space character later, which causes
825 // OnCaretBoundsChanged be called twice. The first call moves the caret back
826 // to the character position just before NBSP, replaces the NBSP with blank
827 // space plus the new character, then the second call will move caret to the
828 // position after the new character. In order to avoid the magnifier window
829 // being moved back and forth with these two OnCaretBoundsChanged events, we
830 // defer moving magnifier window until the |move_magnifier_timer_| fires,
831 // when the caret settles eventually.
832 move_magnifier_timer_.Stop();
833 move_magnifier_timer_.Start(
834 FROM_HERE, base::TimeDelta::FromMilliseconds(kMoveMagnifierDelayInMs),
835 this, &MagnificationControllerImpl::OnMoveMagnifierTimer);
737 } 836 }
738 837
739 //////////////////////////////////////////////////////////////////////////////// 838 ////////////////////////////////////////////////////////////////////////////////
740 // MagnificationController: 839 // MagnificationController:
741 840
742 // static 841 // static
743 MagnificationController* MagnificationController::CreateInstance() { 842 MagnificationController* MagnificationController::CreateInstance() {
744 return new MagnificationControllerImpl(); 843 return new MagnificationControllerImpl();
745 } 844 }
746 845
747 } // namespace ash 846 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698