1 // Copyright 2018 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef ASH_MAGNIFIER_MAGNIFIER_UTILS_H_ 6 #define ASH_MAGNIFIER_MAGNIFIER_UTILS_H_ 7 8 #include "ash/ash_export.h" 9 #include "base/time/time.h" 10 11 namespace aura { 12 class Window; 13 } 14 15 namespace ui { 16 class InputMethod; 17 } 18 19 namespace ash { 20 namespace magnifier_utils { 21 22 // Factor of magnification scale. For example, when this value is 1.189, scale 23 // value will be changed x1.000, x1.189, x1.414, x1.681, x2.000, ... 24 // Note: this value is 2.0 ^ (1 / 4). 25 constexpr float kMagnificationScaleFactor = 1.18920712f; 26 27 // When magnifier wants to make visible a rect that's wider than the viewport, 28 // we want to align the left edge of the rect to the left edge of the viewport. 29 // In a right-to-left language, such as Hebrew, we'll want to align the right 30 // edge of the rect with the right edge of the viewport. This way, the user can 31 // see the maximum amount of useful information in the rect, assuming the 32 // information begins at that edge (e.g. an omnibox entry). We also want to 33 // include a bit of padding beyond that edge of the rect, to provide more 34 // context about what's around the rect to the user. |kLeftEdgeContextPadding| 35 // defines how much padding to include in the viewport. 36 // TODO(accessibility): Add support for right-to-left languages. 37 constexpr int kLeftEdgeContextPadding = 32; 38 39 // The duration of time to ignore caret update after the last move magnifier to 40 // rect call. Prevents jumping magnifier viewport to caret when user is 41 // navigating through other things, but which happen to cause text/caret 42 // updates (e.g. the omnibox results). Try keep under one frame buffer length 43 // (~16ms assuming 60hz screen updates), however most importantly keep it short, 44 // so e.g. when user focuses an element, and then starts typing, the viewport 45 // quickly moves to the caret position. 46 constexpr base::TimeDelta kPauseCaretUpdateDuration = 47 base::TimeDelta::FromMilliseconds(15); 48 49 // Calculates the new scale if it were to be adjusted exponentially by the 50 // given |linear_offset|. This allows linear changes in scroll offset 51 // to have exponential changes on the scale, so that as the user zooms in, 52 // they appear to zoom faster through higher resolutions. This also has the 53 // effect that whether the user moves their fingers quickly or slowly on 54 // the trackpad (changing the number of events fired), the resulting zoom 55 // will only depend on the distance their fingers traveled. 56 // |linear_offset| should generally be between 0 and 1, to result in a set 57 // scale between |min_scale| and |max_scale|. 58 // The resulting scale should be an exponential of the form 59 // y = M * x ^ 2 + c, where y is the resulting scale, M is the scale range which 60 // is the difference between |max_scale| and |min_scale|, and c is the 61 // |min_scale|. This creates a mapping from |linear_offset| in (0, 1) to a scale 62 // in [min_scale, max_scale]. 63 float ASH_EXPORT GetScaleFromScroll(float linear_offset, 64 float current_scale, 65 float min_scale, 66 float max_scale); 67 68 // Converts the |current_range| to an integral index such that 69 // `current_scale = kMagnificationScaleFactor ^ index`, increments it by 70 // |delta_index| and converts it back to a scale value in the range between 71 // |min_scale| and |max_scale|. 72 float ASH_EXPORT GetNextMagnifierScaleValue(int delta_index, 73 float current_scale, 74 float min_scale, 75 float max_scale); 76 77 // Returns the active InputMethod, or that associated with |root_window|. 78 ui::InputMethod* GetInputMethod(aura::Window* root_window); 79 80 } // namespace magnifier_utils 81 } // namespace ash 82 83 #endif // ASH_MAGNIFIER_MAGNIFIER_UTILS_H_ 84