summaryrefslogtreecommitdiffstats
path: root/ash/display/event_transformation_handler.cc
diff options
context:
space:
mode:
authordnicoara@chromium.org <dnicoara@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-23 14:34:40 +0000
committerdnicoara@chromium.org <dnicoara@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-23 14:34:40 +0000
commitca287a8ec21f2461db11ce6a5c2eff51227d12d2 (patch)
treea138c81ee8dccd1d5552e6c10f342d2bdb284f4d /ash/display/event_transformation_handler.cc
parenta01c3ecb9dfbb9683ac7ea76b857b3ad810f1b14 (diff)
downloadchromium_src-ca287a8ec21f2461db11ce6a5c2eff51227d12d2.zip
chromium_src-ca287a8ec21f2461db11ce6a5c2eff51227d12d2.tar.gz
chromium_src-ca287a8ec21f2461db11ce6a5c2eff51227d12d2.tar.bz2
Move GetMirroredDisplayAreaRatioMap() out of ui::DisplayConfigurator
Rather than caching this information early on, compute the ratios when needed. This change is also required in order to extract the touchscreen configuration logic from ui/display. BUG=381326 Review URL: https://codereview.chromium.org/335883003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@279105 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/display/event_transformation_handler.cc')
-rw-r--r--ash/display/event_transformation_handler.cc67
1 files changed, 60 insertions, 7 deletions
diff --git a/ash/display/event_transformation_handler.cc b/ash/display/event_transformation_handler.cc
index ef545fc..cd9961a 100644
--- a/ash/display/event_transformation_handler.cc
+++ b/ash/display/event_transformation_handler.cc
@@ -6,6 +6,8 @@
#include <cmath>
+#include "ash/display/display_info.h"
+#include "ash/display/display_manager.h"
#include "ash/shell.h"
#include "ash/wm/coordinate_conversion.h"
#include "ash/wm/window_util.h"
@@ -25,7 +27,63 @@ namespace {
// Boost factor for non-integrated displays.
const float kBoostForNonIntegrated = 1.20f;
+
+#if defined(OS_CHROMEOS)
+gfx::Size GetNativeModeSize(const DisplayInfo& info) {
+ const std::vector<DisplayMode>& modes = info.display_modes();
+ for (size_t i = 0; i < modes.size(); ++i) {
+ if (modes[i].native)
+ return modes[i].size;
+ }
+
+ return gfx::Size();
+}
+
+float GetMirroredDisplayAreaRatio(const gfx::Size& current_size,
+ const gfx::Size& native_size) {
+ float area_ratio = 1.0f;
+
+ if (current_size.IsEmpty() || native_size.IsEmpty())
+ return area_ratio;
+
+ float width_ratio = static_cast<float>(current_size.width()) /
+ static_cast<float>(native_size.width());
+ float height_ratio = static_cast<float>(current_size.height()) /
+ static_cast<float>(native_size.height());
+
+ area_ratio = width_ratio * height_ratio;
+ return area_ratio;
+}
+
+// Key of the map is the touch display's id, and the value of the map is the
+// touch display's area ratio in mirror mode defined as:
+// mirror_mode_area / native_mode_area.
+// This is used for scaling touch event's radius when the touch display is in
+// mirror mode: new_touch_radius = sqrt(area_ratio) * old_touch_radius
+std::map<int, float> GetMirroredDisplayAreaRatioMap() {
+ std::map<int, float> area_ratios;
+ DisplayManager* display_manager =
+ ash::Shell::GetInstance()->display_manager();
+ const std::vector<gfx::Display>& displays = display_manager->displays();
+ for (size_t i = 0; i < displays.size(); ++i) {
+ const DisplayInfo& info = display_manager->GetDisplayInfo(
+ displays[i].id());
+ const gfx::Size current_size = info.size_in_pixel();
+ const gfx::Size native_size = GetNativeModeSize(info);
+
+ if (info.touch_support() == gfx::Display::TOUCH_SUPPORT_AVAILABLE &&
+ current_size != native_size &&
+ info.is_aspect_preserving_scaling()) {
+ area_ratios[info.touch_device_id()] = GetMirroredDisplayAreaRatio(
+ current_size, native_size);
+ }
+ }
+
+ return area_ratios;
}
+#endif // defined(OS_CHROMEOS)
+
+} // namespace
EventTransformationHandler::EventTransformationHandler()
: transformation_mode_(TRANSFORM_AUTO) {
@@ -59,19 +117,14 @@ void EventTransformationHandler::OnScrollEvent(ui::ScrollEvent* event) {
// the sqrt of
// (mirror_width * mirror_height) / (native_width * native_height)
void EventTransformationHandler::OnTouchEvent(ui::TouchEvent* event) {
- using ui::DisplayConfigurator;
- DisplayConfigurator* display_configurator =
- ash::Shell::GetInstance()->display_configurator();
-
// Check display_configurator's output_state instead of checking
// DisplayManager::IsMirrored() because the compositor based mirroring
// won't cause the scaling issue.
- if (display_configurator->display_state() !=
+ if (ash::Shell::GetInstance()->display_configurator()->display_state() !=
ui::MULTIPLE_DISPLAY_STATE_DUAL_MIRROR)
return;
- const std::map<int, float>& area_ratio_map =
- display_configurator->GetMirroredDisplayAreaRatioMap();
+ const std::map<int, float> area_ratio_map = GetMirroredDisplayAreaRatioMap();
// TODO(miletus): When there are more than 1 touchscreen (e.g. Link connected
// to an external touchscreen), the correct way to do is to have a way