diff options
author | sky <sky@chromium.org> | 2015-06-18 17:55:20 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-19 00:56:49 +0000 |
commit | f760367972c3f3fb5143e7cea5bd6fc29ec3a0a9 (patch) | |
tree | 27193718b69445158806ae2bc3086cec8f2e3c76 /ui/mojo | |
parent | 0e90449a7c9bd8f051fce4988a8cccd6c1c64661 (diff) | |
download | chromium_src-f760367972c3f3fb5143e7cea5bd6fc29ec3a0a9.zip chromium_src-f760367972c3f3fb5143e7cea5bd6fc29ec3a0a9.tar.gz chromium_src-f760367972c3f3fb5143e7cea5bd6fc29ec3a0a9.tar.bz2 |
Fixes crash on android when clicking on non-blink
The crash happened because we weren't setting a
GestureConfiguration. Without setting one we try to use the system
one, which requires JNI.
HTMLViewer has code for doing this. There was some overlap with
existing code so I refactored and combined.
BUG=501387
TEST=none
R=fsamuel@chromium.org
Review URL: https://codereview.chromium.org/1193733002
Cr-Commit-Position: refs/heads/master@{#335184}
Diffstat (limited to 'ui/mojo')
-rw-r--r-- | ui/mojo/init/BUILD.gn | 24 | ||||
-rw-r--r-- | ui/mojo/init/DEPS | 4 | ||||
-rw-r--r-- | ui/mojo/init/screen_mojo.cc | 67 | ||||
-rw-r--r-- | ui/mojo/init/screen_mojo.h | 44 | ||||
-rw-r--r-- | ui/mojo/init/ui_init.cc | 59 | ||||
-rw-r--r-- | ui/mojo/init/ui_init.h | 43 |
6 files changed, 241 insertions, 0 deletions
diff --git a/ui/mojo/init/BUILD.gn b/ui/mojo/init/BUILD.gn new file mode 100644 index 0000000..e6745ad --- /dev/null +++ b/ui/mojo/init/BUILD.gn @@ -0,0 +1,24 @@ +# Copyright 2014 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +source_set("init") { + sources = [ + "screen_mojo.cc", + "screen_mojo.h", + "ui_init.cc", + "ui_init.h", + ] + + deps = [ + "//base", + "//ui/gfx/geometry", + ] + + if (is_android) { + deps += [ + "//ui/events:gesture_detection", + "//ui/gfx", + ] + } +} diff --git a/ui/mojo/init/DEPS b/ui/mojo/init/DEPS new file mode 100644 index 0000000..e419b31 --- /dev/null +++ b/ui/mojo/init/DEPS @@ -0,0 +1,4 @@ +include_rules = [ + "+ui/events/gesture_detection", + "+ui/gfx", +] diff --git a/ui/mojo/init/screen_mojo.cc b/ui/mojo/init/screen_mojo.cc new file mode 100644 index 0000000..1ed0d41 --- /dev/null +++ b/ui/mojo/init/screen_mojo.cc @@ -0,0 +1,67 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/mojo/init/screen_mojo.h" + +namespace ui { +namespace mojo { + +ScreenMojo::ScreenMojo(const gfx::Size& screen_size_in_pixels, + float device_pixel_ratio) + : screen_size_in_pixels_(screen_size_in_pixels), + device_pixel_ratio_(device_pixel_ratio) { + static int64 synthesized_display_id = 2000; + display_.set_id(synthesized_display_id++); + display_.SetScaleAndBounds(device_pixel_ratio, + gfx::Rect(screen_size_in_pixels)); +} + +gfx::Point ScreenMojo::GetCursorScreenPoint() { + return gfx::Point(); +} + +gfx::NativeWindow ScreenMojo::GetWindowUnderCursor() { + NOTIMPLEMENTED(); + return nullptr; +} + +gfx::NativeWindow ScreenMojo::GetWindowAtScreenPoint(const gfx::Point& point) { + NOTIMPLEMENTED(); + return nullptr; +} + +gfx::Display ScreenMojo::GetPrimaryDisplay() const { + return display_; +} + +gfx::Display ScreenMojo::GetDisplayNearestWindow(gfx::NativeView view) const { + return GetPrimaryDisplay(); +} + +gfx::Display ScreenMojo::GetDisplayNearestPoint(const gfx::Point& point) const { + return GetPrimaryDisplay(); +} + +int ScreenMojo::GetNumDisplays() const { + return 1; +} + +std::vector<gfx::Display> ScreenMojo::GetAllDisplays() const { + return std::vector<gfx::Display>(1, GetPrimaryDisplay()); +} + +gfx::Display ScreenMojo::GetDisplayMatching(const gfx::Rect& match_rect) const { + return GetPrimaryDisplay(); +} + +void ScreenMojo::AddObserver(gfx::DisplayObserver* observer) { + // TODO: add support for display changes. +} + +void ScreenMojo::RemoveObserver(gfx::DisplayObserver* observer) { + // TODO: add support for display changes. +} + +} // namespace mojo +} // namespace ui diff --git a/ui/mojo/init/screen_mojo.h b/ui/mojo/init/screen_mojo.h new file mode 100644 index 0000000..db7f48f --- /dev/null +++ b/ui/mojo/init/screen_mojo.h @@ -0,0 +1,44 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_MOJO_INIT_SCREEN_MOJO_H_ +#define UI_MOJO_INIT_SCREEN_MOJO_H_ + +#include "ui/gfx/display.h" +#include "ui/gfx/geometry/size.h" +#include "ui/gfx/screen.h" + +namespace ui { +namespace mojo { + +class ScreenMojo : public gfx::Screen { + public: + ScreenMojo(const gfx::Size& screen_size_in_pixels, float device_pixel_ratio); + + // gfx::Screen: + gfx::Point GetCursorScreenPoint() override; + gfx::NativeWindow GetWindowUnderCursor() override; + gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override; + gfx::Display GetPrimaryDisplay() const override; + gfx::Display GetDisplayNearestWindow(gfx::NativeView view) const override; + gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const override; + int GetNumDisplays() const override; + std::vector<gfx::Display> GetAllDisplays() const override; + gfx::Display GetDisplayMatching(const gfx::Rect& match_rect) const override; + void AddObserver(gfx::DisplayObserver* observer) override; + void RemoveObserver(gfx::DisplayObserver* observer) override; + + private: + const gfx::Size screen_size_in_pixels_; + const float device_pixel_ratio_; + + gfx::Display display_; + + DISALLOW_COPY_AND_ASSIGN(ScreenMojo); +}; + +} // namespace mojo +} // namespace ui + +#endif // UI_MOJO_INIT_SCREEN_MOJO_H_ diff --git a/ui/mojo/init/ui_init.cc b/ui/mojo/init/ui_init.cc new file mode 100644 index 0000000..937112e --- /dev/null +++ b/ui/mojo/init/ui_init.cc @@ -0,0 +1,59 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/mojo/init/ui_init.h" + +#include "base/memory/singleton.h" +#include "ui/mojo/init/screen_mojo.h" + +#if defined(OS_ANDROID) +#include "ui/events/gesture_detection/gesture_configuration.h" +#endif + +namespace ui { +namespace mojo { + +#if defined(OS_ANDROID) +// TODO(sky): this needs to come from system. +class GestureConfigurationMojo : public ui::GestureConfiguration { + public: + GestureConfigurationMojo() : GestureConfiguration() { + set_double_tap_enabled(false); + set_double_tap_timeout_in_ms(semi_long_press_time_in_ms()); + set_gesture_begin_end_types_enabled(true); + set_min_gesture_bounds_length(default_radius()); + set_min_pinch_update_span_delta(0); + set_min_scaling_touch_major(default_radius() * 2); + set_velocity_tracker_strategy( + ui::VelocityTracker::Strategy::LSQ2_RESTRICTED); + set_span_slop(max_touch_move_in_pixels_for_click() * 2); + set_swipe_enabled(true); + set_two_finger_tap_enabled(true); + } + + ~GestureConfigurationMojo() override {} + + private: + DISALLOW_COPY_AND_ASSIGN(GestureConfigurationMojo); +}; +#endif + +UIInit::UIInit(const gfx::Size& screen_size_in_pixels, float device_pixel_ratio) + : screen_(new ScreenMojo(screen_size_in_pixels, device_pixel_ratio)) { + gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); +#if defined(OS_ANDROID) + gesture_configuration_.reset(new GestureConfigurationMojo); + ui::GestureConfiguration::SetInstance(gesture_configuration_.get()); +#endif +} + +UIInit::~UIInit() { + gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, nullptr); +#if defined(OS_ANDROID) + ui::GestureConfiguration::SetInstance(nullptr); +#endif +} + +} // namespace mojo +} // namespace ui diff --git a/ui/mojo/init/ui_init.h b/ui/mojo/init/ui_init.h new file mode 100644 index 0000000..eeaebc6 --- /dev/null +++ b/ui/mojo/init/ui_init.h @@ -0,0 +1,43 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_MOJO_INIT_UI_INIT_H_ +#define UI_MOJO_INIT_UI_INIT_H_ + +#include "base/basictypes.h" +#include "base/callback_forward.h" +#include "base/memory/scoped_ptr.h" + +namespace gfx { +class Screen; +class Size; +} + +namespace ui { +class GestureConfiguration; + +namespace mojo { + +class GestureConfigurationMojo; + +// UIInit configures any state needed by apps that make use of ui classes (not +// including aura). +class UIInit { + public: + UIInit(const gfx::Size& screen_size_in_pixels, float device_pixel_ratio); + ~UIInit(); + + private: + scoped_ptr<gfx::Screen> screen_; +#if defined(OS_ANDROID) + scoped_ptr<GestureConfigurationMojo> gesture_configuration_; +#endif + + DISALLOW_COPY_AND_ASSIGN(UIInit); +}; + +} // namespace mojo +} // namespace ui + +#endif // UI_MOJO_INIT_UI_INIT_H_ |